added form entertaiment and fix file upload
This commit is contained in:
@@ -68,7 +68,7 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
|
||||
NEXT_CLOUD_URL=https://mkt.tunggal-pharma.com/remote.php/dav/files/user_dev/
|
||||
NEXT_CLOUD_URL=https://mkt.tunggal-pharma.com
|
||||
NEXT_CLOUD_USERNAME=user_dev
|
||||
NEXT_CLOUD_PASSWORD=userdev12345
|
||||
NEXT_CLOUD_PATHPREFIX=""
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Helpers;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class NextCloudHelper
|
||||
{
|
||||
@@ -19,17 +20,78 @@ class NextCloudHelper
|
||||
public static function createFolder($baseUrl, $username, $password, $folderPath)
|
||||
{
|
||||
$client = new Client();
|
||||
$url = rtrim($baseUrl, '/') . "/remote.php/dav/files/{$username}/" . ltrim($folderPath, '/');
|
||||
$folders = explode('/', ltrim($folderPath, '/')); // Split the folder path into an array
|
||||
$currentPath = ''; // Initialize an empty string to build the path progressively
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$currentPath .= '/' . $folder; // Add the current folder to the path
|
||||
|
||||
// Build the URL to create the folder
|
||||
$url = rtrim($baseUrl, '/') . "/mktia/remote.php/dav/files/{$username}" . $currentPath;
|
||||
|
||||
try {
|
||||
// Attempt to create the current folder
|
||||
$response = $client->request('MKCOL', $url, [
|
||||
'auth' => [$username, $password]
|
||||
'auth' => [$username, $password],
|
||||
'verify' => false // Disable SSL verification (only for testing purposes)
|
||||
]);
|
||||
|
||||
// If folder creation is successful, proceed to the next folder
|
||||
if ($response->getStatusCode() === 201) {
|
||||
echo "Folder '$currentPath' created successfully.\n";
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
// Handle errors, such as folder already existing
|
||||
if ($e->getCode() === 409) {
|
||||
echo "Folder '$currentPath' already exists.\n";
|
||||
} else {
|
||||
// For other errors
|
||||
echo "Failed to create folder '$currentPath': " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => 'All folders processed.'
|
||||
];
|
||||
}
|
||||
|
||||
public static function uploadFile($folderPath, $fileObject, $fileName)
|
||||
{
|
||||
$baseUrl = env('NEXT_CLOUD_URL');
|
||||
$username = env('NEXT_CLOUD_USERNAME');
|
||||
$password= env('NEXT_CLOUD_PASSWORD');
|
||||
|
||||
// Ensure the folder exists (or create it)
|
||||
$folderResponse = self::createFolder($baseUrl, $username, $password, $folderPath);
|
||||
|
||||
// Check if folder creation was successful or if it already exists
|
||||
if (!$folderResponse['success']) {
|
||||
return [
|
||||
'success' => false,
|
||||
'status' => $folderResponse['status'],
|
||||
'message' => 'Failed to create folder: ' . $folderResponse['message']
|
||||
];
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
$url = rtrim($baseUrl, '/') . "/mktia/remote.php/dav/files/{$username}/" . ltrim($folderPath, '/') . '/' . $fileName;
|
||||
|
||||
try {
|
||||
// If fileObject is a stream, we can use it directly
|
||||
// If it's raw content, ensure it's being properly passed
|
||||
$response = $client->request('PUT', $url, [
|
||||
'auth' => [$username, $password],
|
||||
'body' => $fileObject, // File content or stream
|
||||
'verify' => false // Disable SSL verification (only for testing purposes)
|
||||
]);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'status' => $response->getStatusCode(),
|
||||
'message' => 'Folder created successfully.'
|
||||
'message' => 'File uploaded successfully.'
|
||||
];
|
||||
} catch (RequestException $e) {
|
||||
return [
|
||||
@@ -41,6 +103,17 @@ class NextCloudHelper
|
||||
}
|
||||
|
||||
|
||||
public static function getFileUrl($filePath)
|
||||
{
|
||||
$baseUrl = env('NEXT_CLOUD_URL');
|
||||
$username = env('NEXT_CLOUD_USERNAME');
|
||||
|
||||
// Build the user-specific WebDAV file URL
|
||||
$relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
|
||||
|
||||
// Return the full accessible URL
|
||||
return rtrim($baseUrl, '/') . '/' . $relativePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user in Nextcloud.
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Forms;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\FormEntertaimentPresentation;
|
||||
use App\Models\Rayon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Region;
|
||||
use App\Models\Cabang;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FormEntertainmentPresentationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.view']);
|
||||
|
||||
$forms = FormEntertaimentPresentation::where('user_id', auth()->user()->id)->get();
|
||||
return view('backend.pages.forms.entertainment.index', [
|
||||
'forms' => $forms
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.create']);
|
||||
|
||||
return view('backend.pages.forms.entertainment.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.create']);
|
||||
|
||||
$request->validate([
|
||||
'tanggal' => 'required',
|
||||
'jenis' => 'required|in:entertainment,presentation,sponsorship',
|
||||
'keterangan' => 'required',
|
||||
'total' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'alamat' => 'required',
|
||||
'nik_or_npwp' => 'required',
|
||||
'bukti1' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
||||
'bukti2' => 'nullable|file|mimes:xlsx,xls,csv',
|
||||
'bukti3' => 'nullable|file|mimes:pdf',
|
||||
]);
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('name', 'Entertainment & Presentation')->first();
|
||||
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/entertainment';
|
||||
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Generate sequence number and expense number
|
||||
$sequence_number = FormEntertaimentPresentation::withTrashed()->where('expense_number', 'like', $region->code . '-' . $cabang->code . '-ETY-' . date('ym') . '%')->count() + 1;
|
||||
$formatted_sequence_number = str_pad($sequence_number, 4, '0', STR_PAD_LEFT);
|
||||
$expense_number = $region->code . '-' . $cabang->code . '-ETY-' . date('ym') . $formatted_sequence_number;
|
||||
|
||||
// Save the form data
|
||||
FormEntertaimentPresentation::create([
|
||||
'expense_number' => $expense_number,
|
||||
'user_id' => auth()->user()->id,
|
||||
'tanggal' => $request->tanggal,
|
||||
'jenis' => $request->jenis,
|
||||
'keterangan' => $request->keterangan,
|
||||
'total' => $request->total,
|
||||
'name' => $request->name,
|
||||
'alamat' => $request->alamat,
|
||||
'nik_or_npwp' => $request->nik_or_npwp,
|
||||
'bukti1' => $filePaths['bukti1'] ?? null,
|
||||
'bukti2' => $filePaths['bukti2'] ?? null,
|
||||
'bukti3' => $filePaths['bukti3'] ?? null,
|
||||
'account_number' => $kategori->account_number,
|
||||
'status' => 'On Progress',
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->route('forms.entertainment');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.edit']);
|
||||
|
||||
$form = FormEntertaimentPresentation::findOrfail($id);
|
||||
return view('backend.pages.forms.entertainment.edit', [
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.edit']);
|
||||
|
||||
$request->validate([
|
||||
'tanggal' => 'required',
|
||||
'jenis' => 'required|in:entertainment,presentation,sponsorship',
|
||||
'keterangan' => 'required',
|
||||
'total' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'alamat' => 'required',
|
||||
'nik_or_npwp' => 'required',
|
||||
'bukti1' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
||||
'bukti2' => 'nullable|file|mimes:xlsx,xls,csv',
|
||||
'bukti3' => 'nullable|file|mimes:pdf',
|
||||
]);
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('name', 'Entertainment & Presentation')->first();
|
||||
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/entertainment/';
|
||||
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
$form = FormEntertaimentPresentation::findOrfail($id);
|
||||
$form->update([
|
||||
'tanggal' => $request->tanggal,
|
||||
'jenis' => $request->jenis,
|
||||
'keterangan' => $request->keterangan,
|
||||
'total' => $request->total,
|
||||
'name' => $request->name,
|
||||
'alamat' => $request->alamat,
|
||||
'nik_or_npwp' => $request->nik_or_npwp,
|
||||
'bukti1' => $filePaths['bukti1'] ?? null,
|
||||
'bukti2' => $filePaths['bukti2'] ?? null,
|
||||
'bukti3' => $filePaths['bukti3'] ?? null,
|
||||
'account_number' => $kategori->account_number,
|
||||
'status' => 'On Progress',
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been updated.');
|
||||
return redirect()->route('forms.entertainment');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.delete']);
|
||||
|
||||
$form = FormEntertaimentPresentation::findOrfail($id);
|
||||
$form->delete();
|
||||
|
||||
session()->flash('success', 'Form has been deleted.');
|
||||
return redirect()->route('forms.entertainment');
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ use App\Models\Region;
|
||||
use App\Models\Cabang;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FormUpCountryController extends Controller
|
||||
{
|
||||
@@ -60,20 +62,42 @@ class FormUpCountryController extends Controller
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/upcountry/';
|
||||
|
||||
// check if folder not exists
|
||||
// if (!Storage::disk('nextcloud')->exists(trim($folderPath, '/'))) {
|
||||
// Storage::disk('nextcloud')->makeDirectory(trim($folderPath, '/'));
|
||||
// }
|
||||
|
||||
// Store files to Nextcloud and collect their paths
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$filePaths['bukti1'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti1'), $request->file('bukti1')->getClientOriginalName());
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$filePaths['bukti2'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti2'), $request->file('bukti2')->getClientOriginalName());
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$filePaths['bukti3'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti3'), $request->file('bukti3')->getClientOriginalName());
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Generate sequence number and expense number
|
||||
@@ -142,20 +166,42 @@ class FormUpCountryController extends Controller
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/upcountry/';
|
||||
|
||||
// check if folder not exists
|
||||
// if (!Storage::disk('nextcloud')->exists(trim($folderPath, '/'))) {
|
||||
// Storage::disk('nextcloud')->makeDirectory(trim($folderPath, '/'));
|
||||
// }
|
||||
|
||||
// Store files to Nextcloud and collect their paths
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$filePaths['bukti1'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti1'), $request->file('bukti1')->getClientOriginalName());
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$filePaths['bukti2'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti2'), $request->file('bukti2')->getClientOriginalName());
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$filePaths['bukti3'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti3'), $request->file('bukti3')->getClientOriginalName());
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
|
||||
@@ -12,6 +12,8 @@ use App\Models\Region;
|
||||
use App\Models\Cabang;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FormVehicleController extends Controller
|
||||
{
|
||||
@@ -56,20 +58,42 @@ class FormVehicleController extends Controller
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/vehicle/';
|
||||
|
||||
// check if folder not exists
|
||||
// if (!Storage::disk('nextcloud')->exists(trim($folderPath, '/'))) {
|
||||
// Storage::disk('nextcloud')->makeDirectory(trim($folderPath, '/'));
|
||||
// }
|
||||
|
||||
// Store files to Nextcloud and collect their paths
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$filePaths['bukti1'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti1'), $request->file('bukti1')->getClientOriginalName());
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$filePaths['bukti2'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti2'), $request->file('bukti2')->getClientOriginalName());
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$filePaths['bukti3'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti3'), $request->file('bukti3')->getClientOriginalName());
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Generate sequence number and expense number
|
||||
@@ -133,20 +157,42 @@ class FormVehicleController extends Controller
|
||||
$filePaths = [];
|
||||
$folderPath = '/expense/' . $region->code . '/' . $cabang->code . '/vehicle/';
|
||||
|
||||
// check if folder not exists
|
||||
// if (!Storage::disk('nextcloud')->exists(trim($folderPath, '/'))) {
|
||||
// Storage::disk('nextcloud')->makeDirectory(trim($folderPath, '/'));
|
||||
// }
|
||||
|
||||
// Store files to Nextcloud and collect their paths
|
||||
if ($request->hasFile('bukti1')) {
|
||||
$filePaths['bukti1'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti1'), $request->file('bukti1')->getClientOriginalName());
|
||||
$bukti1 = $request->file('bukti1');
|
||||
$filename = Str::uuid() . '.' . $bukti1->extension();
|
||||
|
||||
$filePaths['bukti1'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti1->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
if ($request->hasFile('bukti2')) {
|
||||
$filePaths['bukti2'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti2'), $request->file('bukti2')->getClientOriginalName());
|
||||
$bukti2 = $request->file('bukti2');
|
||||
$filename = Str::uuid() . '.' . $bukti2->extension();
|
||||
|
||||
$filePaths['bukti2'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti2->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
if ($request->hasFile('bukti3')) {
|
||||
$filePaths['bukti3'] = Storage::disk('nextcloud')->putFileAs($folderPath, $request->file('bukti3'), $request->file('bukti3')->getClientOriginalName());
|
||||
$bukti3 = $request->file('bukti3');
|
||||
$filename = Str::uuid() . '.' . $bukti3->extension();
|
||||
|
||||
$filePaths['bukti3'] = $folderPath . '/' . $filename;
|
||||
|
||||
NextCloudHelper::uploadFile(
|
||||
$folderPath,
|
||||
$bukti3->getContent(),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
|
||||
@@ -26,4 +26,9 @@ class FormEntertaimentPresentation extends Model
|
||||
'account_number',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Admin');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title')
|
||||
Dashboard
|
||||
@endsection
|
||||
|
||||
@section('admin-content')
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h1>Tambahkan Expense Entertainment & Presentation</h1>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ route('forms.entertainment.store') }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('backend.layouts.partials.messages')
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Tanggal</label>
|
||||
<input type="date" class="form-control" name="tanggal" required value="{{ old('tanggal') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Jenis</label>
|
||||
<select class="form-control form-control-md" name="jenis" required>
|
||||
<option value="">Pilih Jenis</option>
|
||||
<option value="entertainment" {{ old('jenis') == 'entertainment' ? 'selected' : '' }}>Entertainment</option>
|
||||
<option value="presentation" {{ old('jenis') == 'presentation' ? 'selected' : '' }}>Presentation</option>
|
||||
<option value="sponsorship" {{ old('jenis') == 'sponsorship' ? 'selected' : '' }}>Sponsorship</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Nama Penerima</label>
|
||||
<input type="text" class="form-control" name="name" required value="{{ old('name') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Alamat</label>
|
||||
<input type="text" class="form-control" name="alamat" id="alamat" required value="{{ old('alamat') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Keterangan</label>
|
||||
<textarea class="form-control" name="keterangan" required>{{ old('keterangan') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">NPWP / NIK</label>
|
||||
<input type="text" class="form-control" name="nik_or_npwp" id="nik_or_npwp" required value="{{ old('nik_or_npwp') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Total</label>
|
||||
<input type="number" class="form-control" name="total" id="total" required value="{{ old('total') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 1</label>
|
||||
<input type="file" class="form-control" name="bukti1" value="{{ old('bukti1') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 2</label>
|
||||
<input type="file" class="form-control" name="bukti2" value="{{ old('bukti2') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 3</label>
|
||||
<input type="file" class="form-control" name="bukti3" value="{{ old('bukti3') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary ml-2">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,90 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title')
|
||||
Dashboard
|
||||
@endsection
|
||||
|
||||
@section('admin-content')
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h1>Edit Expense Entertainment & Presentation</h1>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ route('forms.entertainment.update', $form->id) }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@include('backend.layouts.partials.messages')
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Tanggal</label>
|
||||
<input type="date" class="form-control" name="tanggal" required value="{{ $form->tanggal }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Jenis</label>
|
||||
<select class="form-control form-control-md" name="jenis" required>
|
||||
<option value="">Pilih Jenis</option>
|
||||
<option value="entertainment" {{ $form->jenis == 'entertainment' ? 'selected' : '' }}>Entertainment</option>
|
||||
<option value="presentation" {{ $form->jenis == 'presentation' ? 'selected' : '' }}>Presentation</option>
|
||||
<option value="sponsorship" {{ $form->jenis == 'sponsorship' ? 'selected' : '' }}>Sponsorship</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Nama Penerima</label>
|
||||
<input type="text" class="form-control" name="name" required value="{{ $form->name }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Alamat</label>
|
||||
<input type="text" class="form-control" name="alamat" id="alamat" required value="{{ $form->alamat }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Keterangan</label>
|
||||
<textarea class="form-control" name="keterangan" required>{{ $form->keterangan }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">NPWP / NIK</label>
|
||||
<input type="text" class="form-control" name="nik_or_npwp" id="nik_or_npwp" required value="{{ $form->nik_or_npwp }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Total</label>
|
||||
<input type="number" class="form-control" name="total" id="total" required value="{{ $form->total }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 1</label>
|
||||
<input type="file" class="form-control" name="bukti1" value="{{ old('bukti1') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 2</label>
|
||||
<input type="file" class="form-control" name="bukti2" value="{{ old('bukti2') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti 3</label>
|
||||
<input type="file" class="form-control" name="bukti3" value="{{ old('bukti3') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary ml-2">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,136 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title')
|
||||
Dashboard
|
||||
@endsection
|
||||
|
||||
@section('admin-content')
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h1>Forms Entertainment & Presentation</h1>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card card-primary card-outline">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title float-left">List Data Forms Entertainment & Presentation</h4>
|
||||
<p class="float-right mb-2">
|
||||
@if (auth()->user()->can('forms.entertainment.create'))
|
||||
<a class="btn btn-primary text-white" href="{{ route('forms.entertainment.create') }}">
|
||||
Add New Expense Entertainment & Presentation
|
||||
</a>
|
||||
@endif
|
||||
</p>
|
||||
<div class="clearfix"></div>
|
||||
<div class="dataTables_wrapper dt-bootstrap4 mt-2">
|
||||
@include('backend.layouts.partials.messages')
|
||||
<table id="dataTable"
|
||||
class="table table-bordered table-striped table-head-fixed dataTable dtr-inline"
|
||||
style="width:100%">
|
||||
<thead class="bg-light text-capitalize">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Nama</th>
|
||||
<th>Tanggal</th>
|
||||
<th>Jenis</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Total</th>
|
||||
<th>Nama Penerima</th>
|
||||
<th>NPWP / NIK</th>
|
||||
<th>Bukti 1</th>
|
||||
<th>Bukti 2</th>
|
||||
<th>Bukti 3</th>
|
||||
<th>Account Number</th>
|
||||
<th>Status</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
use App\Helpers\NextCloudHelper;
|
||||
@endphp
|
||||
@foreach ($forms as $item)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $item->user->name }}</td>
|
||||
<td>{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}</td>
|
||||
<td>{{ $item->jenis }}</td>
|
||||
<td>{{ $item->keterangan }}</td>
|
||||
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
|
||||
<td>{{ $item->name }}</td>
|
||||
<td>{{ $item->nik_or_npwp }}</td>
|
||||
<td>
|
||||
@if ($item->bukti1)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti2)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti2) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti3)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti3) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $item->account_number }}</td>
|
||||
<td>
|
||||
@if ($item->status == 'On Progress')
|
||||
<span class="badge badge-warning text-white">{{ $item->status }}</span>
|
||||
@elseif ($item->status == 'Completed')
|
||||
<span class="badge badge-success text-white">{{ $item->status }}</span>
|
||||
@else
|
||||
<span class="badge badge-danger text-white">{{ $item->status }}</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if (auth()->user()->can('forms.entertainment.edit'))
|
||||
<a href="{{ route('forms.entertainment.edit', $item->id) }}" class="btn btn-warning btn-sm">
|
||||
<i class="fas fa-edit text-white"></i>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if (auth()->user()->can('forms.entertainment.delete'))
|
||||
<form action="{{ route('forms.entertainment.destroy', $item->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger btn-sm">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -57,19 +57,46 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
use App\Helpers\NextCloudHelper;
|
||||
@endphp
|
||||
@foreach ($forms as $item)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $item->user->name }}</td>
|
||||
<td>{{ $item->rayon->code }}</td>
|
||||
<td>{{ $item->tanggal }}</td>
|
||||
<td>{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('D MMMM Y') }}</td>
|
||||
<td>{{ $item->tujuan }}</td>
|
||||
<td>{{ $item->jarak }} km</td>
|
||||
<td>{{ number_format($item->allowance, 0, ',', '.') }}</td>
|
||||
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
|
||||
<td>{{ $item->bukti1 }}</td>
|
||||
<td>{{ $item->bukti2 }}</td>
|
||||
<td>{{ $item->bukti3 }}</td>
|
||||
<td>
|
||||
@if ($item->bukti1)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti2)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti2) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti3)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti3) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $item->account_number }}</td>
|
||||
<td>
|
||||
@if ($item->status == 'On Progress')
|
||||
|
||||
@@ -57,19 +57,46 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
use App\Helpers\NextCloudHelper;
|
||||
@endphp
|
||||
@foreach ($forms as $item)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $item->user->name }}</td>
|
||||
<td>{{ \Carbon\Carbon::parse($item->tanggal)->locale('id')->isoFormat('dddd, D MMMM Y HH:mm:ss') }}</td>
|
||||
<td>{{ $item->liter }}</td>
|
||||
<td>{{ $item->harga }}</td>
|
||||
<td>{{ number_format($item->harga, 0, ',', '.') }}</td>
|
||||
<td>{{ $item->jarak }}</td>
|
||||
<td>{{ $item->tipe_bensin }}</td>
|
||||
<td>{{ $item->nopol }}</td>
|
||||
<td>{{ $item->bukti1 }}</td>
|
||||
<td>{{ $item->bukti2 }}</td>
|
||||
<td>{{ $item->bukti3 }}</td>
|
||||
<td>
|
||||
@if ($item->bukti1)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti2)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti2) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($item->bukti3)
|
||||
<a href="{{ NextCloudHelper::getFileUrl($item->bukti3) }}" target="_blank">
|
||||
Download
|
||||
</a>
|
||||
@else
|
||||
-
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $item->account_number }}</td>
|
||||
<td>
|
||||
@if ($item->status == 'On Progress')
|
||||
|
||||
+15
-9
@@ -13,7 +13,9 @@ use App\Http\Controllers\Master\RayonController;
|
||||
use App\Http\Controllers\Master\CostCentreController;
|
||||
use App\Http\Controllers\Master\CategoryController;
|
||||
use App\Http\Controllers\Forms\FormVehicleController;
|
||||
use App\Http\Controllers\Forms\FormEntertainmentPresentationController;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
|
||||
Auth::routes();
|
||||
|
||||
@@ -80,6 +82,14 @@ Route::middleware(['auth:admin', 'menu'])->group(function () {
|
||||
Route::get('/vehicle-running-cost/edit/{id}', [FormVehicleController::class, 'edit'])->name('forms.vehicle.edit');
|
||||
Route::put('/vehicle-running-cost/update/{id}', [FormVehicleController::class, 'update'])->name('forms.vehicle.update');
|
||||
Route::delete('/vehicle-running-cost/destroy/{id}', [FormVehicleController::class, 'destroy'])->name('forms.vehicle.destroy');
|
||||
|
||||
// Entertainment & Presentation
|
||||
Route::get('/entertainment-presentation', [FormEntertainmentPresentationController::class, 'index'])->name('forms.entertainment');
|
||||
Route::get('/entertainment-presentation/create', [FormEntertainmentPresentationController::class, 'create'])->name('forms.entertainment.create');
|
||||
Route::post('/entertainment-presentation/store', [FormEntertainmentPresentationController::class, 'store'])->name('forms.entertainment.store');
|
||||
Route::get('/entertainment-presentation/edit/{id}', [FormEntertainmentPresentationController::class, 'edit'])->name('forms.entertainment.edit');
|
||||
Route::put('/entertainment-presentation/update/{id}', [FormEntertainmentPresentationController::class, 'update'])->name('forms.entertainment.update');
|
||||
Route::delete('/entertainment-presentation/destroy/{id}', [FormEntertainmentPresentationController::class, 'destroy'])->name('forms.entertainment.destroy');
|
||||
});
|
||||
|
||||
//Menu Role
|
||||
@@ -88,14 +98,10 @@ Route::middleware(['auth:admin', 'menu'])->group(function () {
|
||||
});
|
||||
|
||||
Route::get('/test-nextcloud', function () {
|
||||
$disk = Storage::disk('nextcloud');
|
||||
$folderPath = 'test-directory';
|
||||
$baseUrl = env('NEXT_CLOUD_URL');
|
||||
$adminUsername = env('NEXT_CLOUD_USERNAME');
|
||||
$adminPassword = env('NEXT_CLOUD_PASSWORD');
|
||||
|
||||
// Check if directory exists
|
||||
if (!$disk->exists($folderPath)) {
|
||||
$disk->makeDirectory($folderPath);
|
||||
return "Directory created: $folderPath";
|
||||
}
|
||||
|
||||
return "Directory already exists: $folderPath";
|
||||
$response = NextCloudHelper::createFolder($baseUrl, $adminUsername, $adminPassword, 'test-folder');
|
||||
dd($response);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user