diff --git a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php index c0f43df..8997795 100644 --- a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php +++ b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php @@ -42,25 +42,26 @@ class FormEntertainmentPresentationController extends Controller $now = Carbon::now(); - // Tentukan periode aktif (mulai dan tutup) + // Determine the period if ($now->day >= $startDay) { - $startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); } else { - $startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); } - // Ambil nama bulan dan tahun dari $startDate untuk keperluan BudgetHelper - $periodeMonth = strtolower($startDate->format('F')); // ex: 'august' - $periodeYear = (int) $startDate->format('Y'); // ex: 2025 + // Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate) + $dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay(); - $forms = FormEntertaimentPresentation::whereBetween('tanggal', [$startDate, $closingDate]) + $forms = FormEntertaimentPresentation::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate]) ->orderBy('tanggal', 'desc') ->with('user') ->get(); $availableBudget = null; + $periodeMonth = strtolower($currentPeriodStartDate->format('F')); + $periodeYear = (int) $currentPeriodStartDate->format('Y'); if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') { $region_id = auth()->user()->getMyCabangAndRegionId()['region']; diff --git a/app/Http/Controllers/Forms/FormMeetingSeminarController.php b/app/Http/Controllers/Forms/FormMeetingSeminarController.php index e5e36c1..d397bcb 100644 --- a/app/Http/Controllers/Forms/FormMeetingSeminarController.php +++ b/app/Http/Controllers/Forms/FormMeetingSeminarController.php @@ -43,25 +43,26 @@ class FormMeetingSeminarController extends Controller // Referensi waktu sekarang $now = Carbon::now(); - // Tentukan periode + // Determine the period if ($now->day >= $startDay) { - $startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); } else { - $startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); } - // Ambil bulan dan tahun dari $startDate untuk keperluan budget - $periodeMonth = strtolower($startDate->format('F')); // contoh: 'august' - $periodeYear = (int) $startDate->format('Y'); + // Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate) + $dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay(); - $forms = FormMeetingSeminar::whereBetween('tanggal', [$startDate, $closingDate]) + $forms = FormMeetingSeminar::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate]) ->orderBy('tanggal', 'desc') ->with('user') ->get(); $availableBudget = null; + $periodeMonth = strtolower($currentPeriodStartDate->format('F')); + $periodeYear = (int) $currentPeriodStartDate->format('Y'); if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') { $region_id = auth()->user()->getMyCabangAndRegionId()['region']; diff --git a/app/Http/Controllers/Forms/FormOtherController.php b/app/Http/Controllers/Forms/FormOtherController.php index df38f9b..2c06e9c 100644 --- a/app/Http/Controllers/Forms/FormOtherController.php +++ b/app/Http/Controllers/Forms/FormOtherController.php @@ -37,27 +37,29 @@ class FormOtherController extends Controller $startDay = (int) env('STARTING_DATE', 11); $closingDay = (int) env('CLOSING_DATE', 10); + // Referensi waktu sekarang $now = Carbon::now(); - // Tentukan periode aktif + // Determine the period if ($now->day >= $startDay) { - $startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); } else { - $startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); } - // Periode untuk keperluan budget - $periodeMonth = strtolower($startDate->format('F')); - $periodeYear = (int) $startDate->format('Y'); + // Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate) + $dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay(); - $forms = FormOthers::whereBetween('tanggal', [$startDate, $closingDate]) + $forms = FormOthers::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate]) ->orderBy('tanggal', 'desc') ->with('user') ->get(); $availableBudget = null; + $periodeMonth = strtolower($currentPeriodStartDate->format('F')); + $periodeYear = (int) $currentPeriodStartDate->format('Y'); if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') { $region_id = auth()->user()->getMyCabangAndRegionId()['region']; diff --git a/app/Http/Controllers/Forms/FormUpCountryController.php b/app/Http/Controllers/Forms/FormUpCountryController.php index 62cb89a..baa3204 100644 --- a/app/Http/Controllers/Forms/FormUpCountryController.php +++ b/app/Http/Controllers/Forms/FormUpCountryController.php @@ -45,11 +45,11 @@ class FormUpCountryController extends Controller // Determine the period if ($now->day >= $startDay) { - $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); - $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); } else { - $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); - $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); } // Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate) diff --git a/app/Http/Controllers/Forms/FormVehicleController.php b/app/Http/Controllers/Forms/FormVehicleController.php index fe1f658..31b4100 100644 --- a/app/Http/Controllers/Forms/FormVehicleController.php +++ b/app/Http/Controllers/Forms/FormVehicleController.php @@ -39,27 +39,30 @@ class FormVehicleController extends Controller $role = auth()->user()->getRoleNames()[0]; $startDay = (int) env('STARTING_DATE', 11); $closingDay = (int) env('CLOSING_DATE', 10); + + // Referensi waktu sekarang $now = Carbon::now(); - // Tentukan periode aktif + // Determine the period if ($now->day >= $startDay) { - $startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay(); } else { - $startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); - $closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); + $currentPeriodStartDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay(); + $currentPeriodClosingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay(); } - // Hitung periode untuk keperluan budget - $periodeMonth = strtolower($startDate->format('F')); - $periodeYear = (int) $startDate->format('Y'); + // Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate) + $dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay(); - $forms = FormVehicleRunningCost::whereBetween('tanggal', [$startDate, $closingDate]) + $forms = FormVehicleRunningCost::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate]) ->orderBy('tanggal', 'desc') ->with('user') ->get(); $availableBudget = null; + $periodeMonth = strtolower($currentPeriodStartDate->format('F')); + $periodeYear = (int) $currentPeriodStartDate->format('Y'); if ($role === 'Admin Region' || $role === 'Marketing Operational Manager Region') { $region_id = auth()->user()->getMyCabangAndRegionId()['region']; @@ -133,11 +136,12 @@ class FormVehicleController extends Controller $this->checkAuthorization(auth()->user(), ['forms.vehicle.create']); $request->validate([ 'tanggal' => 'required', - 'liter' => 'required', + 'type' => 'required', + 'liter' => 'nullable|numeric|min:0', 'total' => 'required|numeric|min:1', - 'jarak' => 'required', - 'tipe_bensin' => 'required|in:pertalite,pertamax', - 'nopol' => 'required', + 'jarak' => 'nullable|numeric|min:0', + 'tipe_bensin' => 'nullable|in:pertalite,pertamax', + 'nopol' => 'nullable', 'keterangan' => 'required', 'bukti_total' => ['nullable', 'file', 'max:51200'], ]); @@ -215,11 +219,12 @@ class FormVehicleController extends Controller 'expense_number' => $expense_number, 'user_id' => auth()->user()->id, 'tanggal' => $request->tanggal, - 'liter' => $request->liter, + 'type' => $request->type, + 'liter' => $request->liter ?? 0, 'total' => $request->total, - 'jarak' => $request->jarak, - 'tipe_bensin' => $request->tipe_bensin, - 'nopol' => $request->nopol, + 'jarak' => $request->jarak ?? 0, + 'tipe_bensin' => $request->tipe_bensin ?? '-', + 'nopol' => $request->nopol ?? '-', 'keterangan' => $request->keterangan, 'bukti_total' => $filePaths['bukti_total'] ?? null, 'account_number' => $kategori->account_number, @@ -354,11 +359,12 @@ class FormVehicleController extends Controller // Validasi input $request->validate([ 'tanggal' => 'required', - 'liter' => 'required', + 'type' => 'required', + 'liter' => 'nullable|numeric|min:0', 'total' => 'required|numeric|min:1|max:' . $availableBudget, - 'jarak' => 'required', - 'tipe_bensin' => 'required|in:pertalite,pertamax', - 'nopol' => 'required', + 'jarak' => 'nullable|numeric|min:0', + 'tipe_bensin' => 'nullable|in:pertalite,pertamax', + 'nopol' => 'nullable', 'keterangan' => 'required', 'bukti_total' => ['nullable', 'file', 'max:51200'], ]); @@ -391,11 +397,12 @@ class FormVehicleController extends Controller // Save the form data $form->update([ 'tanggal' => $request->tanggal, - 'liter' => $request->liter, + 'type' => $request->type, + 'liter' => $request->liter ?? 0, 'total' => $request->total, - 'jarak' => $request->jarak, - 'tipe_bensin' => $request->tipe_bensin, - 'nopol' => $request->nopol, + 'jarak' => $request->jarak ?? 0, + 'tipe_bensin' => $request->tipe_bensin ?? '-', + 'nopol' => $request->nopol ?? '-', 'keterangan' => $request->keterangan, 'bukti_total' => $filePaths['bukti_total'] ?? $form->bukti_total, 'account_number' => $kategori->account_number, diff --git a/app/Models/FormVehicleRunningCost.php b/app/Models/FormVehicleRunningCost.php index b86633d..4b5bacc 100644 --- a/app/Models/FormVehicleRunningCost.php +++ b/app/Models/FormVehicleRunningCost.php @@ -23,6 +23,7 @@ class FormVehicleRunningCost extends Model 'keterangan', 'bukti_total', 'account_number', + 'type', 'status', 'approved_at', 'approved2_at', diff --git a/database/migrations/2025_06_19_121458_add_type_to_vehicle_running_cost_forms.php b/database/migrations/2025_06_19_121458_add_type_to_vehicle_running_cost_forms.php new file mode 100644 index 0000000..5ce5a60 --- /dev/null +++ b/database/migrations/2025_06_19_121458_add_type_to_vehicle_running_cost_forms.php @@ -0,0 +1,28 @@ +string('type')->nullable()->default('gasoline')->after('id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('form_vehicle_running_cost', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +}; diff --git a/resources/views/backend/pages/forms/vehicle/create.blade.php b/resources/views/backend/pages/forms/vehicle/create.blade.php index d65794f..b4d65f2 100644 --- a/resources/views/backend/pages/forms/vehicle/create.blade.php +++ b/resources/views/backend/pages/forms/vehicle/create.blade.php @@ -1,7 +1,7 @@ @extends('layouts.app') @section('title') - Dashboard + Dashboard @endsection @section('admin-content') @@ -16,7 +16,6 @@