fix some revisi
This commit is contained in:
+16
-22
@@ -14,7 +14,9 @@ use App\Models\UserHasCabang;
|
||||
class FormHelper
|
||||
{
|
||||
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'])
|
||||
->whereIn('id', $userIds)
|
||||
->get();
|
||||
@@ -29,8 +31,7 @@ class FormHelper
|
||||
'created_at',
|
||||
DB::raw("'Up Country' as type")
|
||||
)->whereIn('user_id', $userIds)
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formVehicleRunningCostQuery = FormVehicleRunningCost::select(
|
||||
'expense_number',
|
||||
@@ -42,8 +43,7 @@ class FormHelper
|
||||
'created_at',
|
||||
DB::raw("'Vehicle Running Cost' as type")
|
||||
)->whereIn('user_id', $userIds)
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
|
||||
'expense_number',
|
||||
@@ -55,8 +55,7 @@ class FormHelper
|
||||
'created_at',
|
||||
DB::raw("'Entertainment Presentation' as type")
|
||||
)->whereIn('user_id', $userIds)
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formMeetingSeminarQuery = FormMeetingSeminar::select(
|
||||
'expense_number',
|
||||
@@ -68,8 +67,7 @@ class FormHelper
|
||||
'created_at',
|
||||
DB::raw("'Meeting Seminar' as type")
|
||||
)->whereIn('user_id', $userIds)
|
||||
->whereMonth('created_at', '=', date('m', strtotime($month)))
|
||||
->whereYear('created_at', '=', $year);
|
||||
->whereBetween('created_at', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formOthersQuery = FormOthers::select(
|
||||
'expense_number',
|
||||
@@ -81,8 +79,7 @@ class FormHelper
|
||||
'created_at',
|
||||
DB::raw("'Others' as type")
|
||||
)->whereIn('user_id', $userIds)
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
// Use union to combine queries
|
||||
$forms = $formUpCountryQuery
|
||||
@@ -101,7 +98,9 @@ class FormHelper
|
||||
}
|
||||
|
||||
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'])
|
||||
->get();
|
||||
|
||||
@@ -114,8 +113,7 @@ class FormHelper
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Up Country' as type")
|
||||
)->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
)->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formVehicleRunningCostQuery = FormVehicleRunningCost::select(
|
||||
'expense_number',
|
||||
@@ -126,8 +124,7 @@ class FormHelper
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Vehicle Running Cost' as type")
|
||||
)->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
)->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
|
||||
'expense_number',
|
||||
@@ -138,8 +135,7 @@ class FormHelper
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Entertainment Presentation' as type")
|
||||
)->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
)->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formMeetingSeminarQuery = FormMeetingSeminar::select(
|
||||
'expense_number',
|
||||
@@ -150,8 +146,7 @@ class FormHelper
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Meeting Seminar' as type")
|
||||
)->whereMonth('created_at', '=', date('m', strtotime($month)))
|
||||
->whereYear('created_at', '=', $year);
|
||||
)->whereBetween('created_at', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
$formOthersQuery = FormOthers::select(
|
||||
'expense_number',
|
||||
@@ -162,8 +157,7 @@ class FormHelper
|
||||
'account_number',
|
||||
'created_at',
|
||||
DB::raw("'Others' as type")
|
||||
)->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year);
|
||||
)->whereBetween('tanggal', [$startDate, $closingDateNextMonth]);
|
||||
|
||||
// Combine queries using union
|
||||
$forms = $formUpCountryQuery
|
||||
|
||||
Reference in New Issue
Block a user