fix some revisi

This commit is contained in:
Jagad R R
2025-01-19 15:11:21 +07:00
parent 1610d83bc6
commit d1085d4b30
2 changed files with 33 additions and 23 deletions
+16 -22
View File
@@ -14,7 +14,9 @@ use App\Models\UserHasCabang;
class FormHelper class FormHelper
{ {
public static function getFormsByUserIds($userIds, $month, $year) { public static function getFormsByUserIds($userIds, $month, $year) {
// Eager load 'user.region' and 'user.cabang' $startDate = date('Y-m-' . env('STARTING_DATE'));
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
$users = Admin::with(['region', 'cabang']) $users = Admin::with(['region', 'cabang'])
->whereIn('id', $userIds) ->whereIn('id', $userIds)
->get(); ->get();
@@ -29,8 +31,7 @@ class FormHelper
'created_at', 'created_at',
DB::raw("'Up Country' as type") DB::raw("'Up Country' as type")
)->whereIn('user_id', $userIds) )->whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formVehicleRunningCostQuery = FormVehicleRunningCost::select( $formVehicleRunningCostQuery = FormVehicleRunningCost::select(
'expense_number', 'expense_number',
@@ -42,8 +43,7 @@ class FormHelper
'created_at', 'created_at',
DB::raw("'Vehicle Running Cost' as type") DB::raw("'Vehicle Running Cost' as type")
)->whereIn('user_id', $userIds) )->whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select( $formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
'expense_number', 'expense_number',
@@ -55,8 +55,7 @@ class FormHelper
'created_at', 'created_at',
DB::raw("'Entertainment Presentation' as type") DB::raw("'Entertainment Presentation' as type")
)->whereIn('user_id', $userIds) )->whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formMeetingSeminarQuery = FormMeetingSeminar::select( $formMeetingSeminarQuery = FormMeetingSeminar::select(
'expense_number', 'expense_number',
@@ -68,8 +67,7 @@ class FormHelper
'created_at', 'created_at',
DB::raw("'Meeting Seminar' as type") DB::raw("'Meeting Seminar' as type")
)->whereIn('user_id', $userIds) )->whereIn('user_id', $userIds)
->whereMonth('created_at', '=', date('m', strtotime($month))) ->whereBetween('created_at', [$startDate, $closingDateNextMonth]);
->whereYear('created_at', '=', $year);
$formOthersQuery = FormOthers::select( $formOthersQuery = FormOthers::select(
'expense_number', 'expense_number',
@@ -81,8 +79,7 @@ class FormHelper
'created_at', 'created_at',
DB::raw("'Others' as type") DB::raw("'Others' as type")
)->whereIn('user_id', $userIds) )->whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
// Use union to combine queries // Use union to combine queries
$forms = $formUpCountryQuery $forms = $formUpCountryQuery
@@ -101,7 +98,9 @@ class FormHelper
} }
public static function getAllForms($month, $year) { public static function getAllForms($month, $year) {
// Get all users with eager loading for 'region' and 'cabang' $startDate = date('Y-m-' . env('STARTING_DATE'));
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
$users = Admin::with(['region', 'cabang']) $users = Admin::with(['region', 'cabang'])
->get(); ->get();
@@ -114,8 +113,7 @@ class FormHelper
'account_number', 'account_number',
'created_at', 'created_at',
DB::raw("'Up Country' as type") DB::raw("'Up Country' as type")
)->whereMonth('tanggal', '=', date('m', strtotime($month))) )->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formVehicleRunningCostQuery = FormVehicleRunningCost::select( $formVehicleRunningCostQuery = FormVehicleRunningCost::select(
'expense_number', 'expense_number',
@@ -126,8 +124,7 @@ class FormHelper
'account_number', 'account_number',
'created_at', 'created_at',
DB::raw("'Vehicle Running Cost' as type") DB::raw("'Vehicle Running Cost' as type")
)->whereMonth('tanggal', '=', date('m', strtotime($month))) )->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select( $formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
'expense_number', 'expense_number',
@@ -138,8 +135,7 @@ class FormHelper
'account_number', 'account_number',
'created_at', 'created_at',
DB::raw("'Entertainment Presentation' as type") DB::raw("'Entertainment Presentation' as type")
)->whereMonth('tanggal', '=', date('m', strtotime($month))) )->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
$formMeetingSeminarQuery = FormMeetingSeminar::select( $formMeetingSeminarQuery = FormMeetingSeminar::select(
'expense_number', 'expense_number',
@@ -150,8 +146,7 @@ class FormHelper
'account_number', 'account_number',
'created_at', 'created_at',
DB::raw("'Meeting Seminar' as type") DB::raw("'Meeting Seminar' as type")
)->whereMonth('created_at', '=', date('m', strtotime($month))) )->whereBetween('created_at', [$startDate, $closingDateNextMonth]);
->whereYear('created_at', '=', $year);
$formOthersQuery = FormOthers::select( $formOthersQuery = FormOthers::select(
'expense_number', 'expense_number',
@@ -162,8 +157,7 @@ class FormHelper
'account_number', 'account_number',
'created_at', 'created_at',
DB::raw("'Others' as type") DB::raw("'Others' as type")
)->whereMonth('tanggal', '=', date('m', strtotime($month))) )->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
->whereYear('tanggal', '=', $year);
// Combine queries using union // Combine queries using union
$forms = $formUpCountryQuery $forms = $formUpCountryQuery
+17 -1
View File
@@ -26,6 +26,12 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a> <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li> </li>
<li class="nav-item">
{{-- periode --}}
<a class="nav-link" href="{{ route('dashboard.index') }}" role="button">
<span class="ml-2 font-weight-bold text-white">Periode: <span id="periode"></span></span>
</a>
</li>
</ul> </ul>
<div class="navbar-center text-white m-auto"> <div class="navbar-center text-white m-auto">
@@ -165,7 +171,7 @@
hour12: false // Use 24-hour format hour12: false // Use 24-hour format
}; };
dateTimeElement.textContent = new Intl.DateTimeFormat('id-ID', options).format(now); dateTimeElement.textContent = new Intl.DateTimeFormat('id-ID', options).format(now) + ' WIB';
} }
// Update the clock every second // Update the clock every second
@@ -226,4 +232,14 @@
}); });
}); });
const periode = document.getElementById('periode');
const date = new Date();
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const month = months[date.getMonth()]; // Get the current month's short name
const nextMonth = months[(date.getMonth() + 1) % 12]; // Get the next month's short name, wrapping around if necessary
const year = date.getFullYear();
periode.textContent = `${month} (12 ${month} - 10 ${nextMonth} ${year})`;
</script> </script>