update
This commit is contained in:
@@ -35,7 +35,7 @@ class BudgetHelper
|
|||||||
$users = UserHasCabang::where('cabang_id', $cabang_id)->get();
|
$users = UserHasCabang::where('cabang_id', $cabang_id)->get();
|
||||||
$userIds = $users->pluck('user_id')->toArray();
|
$userIds = $users->pluck('user_id')->toArray();
|
||||||
|
|
||||||
$forms = FormHelper::getFormsByUserIds($userIds, $periode_month, $periode_year)
|
$forms = FormHelper::getTotalAmount($userIds, $periode_month, $periode_year)
|
||||||
->sortByDesc('tanggal')
|
->sortByDesc('tanggal')
|
||||||
->sortByDesc('created_at');
|
->sortByDesc('created_at');
|
||||||
|
|
||||||
|
|||||||
@@ -276,4 +276,91 @@ class FormHelper
|
|||||||
$nominal = $form->sum('approved_total');
|
$nominal = $form->sum('approved_total');
|
||||||
return $nominal;
|
return $nominal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTotalAmount($userIds, $month, $year) {
|
||||||
|
$monthNumber = date('m', strtotime($month . ' 1'));
|
||||||
|
$startDate = "$year-$monthNumber-" . env('STARTING_DATE');
|
||||||
|
|
||||||
|
$nextMonthTimestamp = strtotime("first day of next month", strtotime("$year-$monthNumber-01"));
|
||||||
|
$closingDateNextMonth = date('Y-m-', $nextMonthTimestamp) . env('CLOSING_DATE');
|
||||||
|
|
||||||
|
$users = Admin::with(['region', 'cabang'])
|
||||||
|
->whereIn('id', $userIds)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$formUpCountryQuery = FormUpCountry::select(
|
||||||
|
'expense_number',
|
||||||
|
'user_id',
|
||||||
|
'total',
|
||||||
|
'approved_total',
|
||||||
|
'status',
|
||||||
|
'account_number',
|
||||||
|
'created_at',
|
||||||
|
DB::raw("'Up Country' as type")
|
||||||
|
)->whereIn('user_id', $userIds)
|
||||||
|
->whereBetween('final_approved_at', [$startDate, $closingDateNextMonth]);
|
||||||
|
|
||||||
|
$formVehicleRunningCostQuery = FormVehicleRunningCost::select(
|
||||||
|
'expense_number',
|
||||||
|
'user_id',
|
||||||
|
'total',
|
||||||
|
'approved_total',
|
||||||
|
'status',
|
||||||
|
'account_number',
|
||||||
|
'created_at',
|
||||||
|
DB::raw("'Vehicle Running Cost' as type")
|
||||||
|
)->whereIn('user_id', $userIds)
|
||||||
|
->whereBetween('final_approved_at', [$startDate, $closingDateNextMonth]);
|
||||||
|
|
||||||
|
$formEntertaimentPresentationQuery = FormEntertaimentPresentation::select(
|
||||||
|
'expense_number',
|
||||||
|
'user_id',
|
||||||
|
'total',
|
||||||
|
'approved_total',
|
||||||
|
'status',
|
||||||
|
'account_number',
|
||||||
|
'created_at',
|
||||||
|
DB::raw("'Entertainment Presentation' as type")
|
||||||
|
)->whereIn('user_id', $userIds)
|
||||||
|
->whereBetween('final_approved_at', [$startDate, $closingDateNextMonth]);
|
||||||
|
|
||||||
|
$formMeetingSeminarQuery = FormMeetingSeminar::select(
|
||||||
|
'expense_number',
|
||||||
|
'user_id',
|
||||||
|
'total',
|
||||||
|
'approved_total',
|
||||||
|
'status',
|
||||||
|
'account_number',
|
||||||
|
'created_at',
|
||||||
|
DB::raw("'Meeting Seminar' as type")
|
||||||
|
)->whereIn('user_id', $userIds)
|
||||||
|
->whereBetween('final_approved_at', [$startDate, $closingDateNextMonth]);
|
||||||
|
|
||||||
|
$formOthersQuery = FormOthers::select(
|
||||||
|
'expense_number',
|
||||||
|
'user_id',
|
||||||
|
'total',
|
||||||
|
'approved_total',
|
||||||
|
'status',
|
||||||
|
'account_number',
|
||||||
|
'created_at',
|
||||||
|
DB::raw("'Others' as type")
|
||||||
|
)->whereIn('user_id', $userIds)
|
||||||
|
->whereBetween('final_approved_at', [$startDate, $closingDateNextMonth]);
|
||||||
|
|
||||||
|
// Use union to combine queries
|
||||||
|
$forms = $formUpCountryQuery
|
||||||
|
->union($formVehicleRunningCostQuery)
|
||||||
|
->union($formEntertaimentPresentationQuery)
|
||||||
|
->union($formMeetingSeminarQuery)
|
||||||
|
->union($formOthersQuery)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Return forms with eager loaded user details
|
||||||
|
return $forms->map(function ($form) use ($users) {
|
||||||
|
$user = $users->firstWhere('id', $form->user_id);
|
||||||
|
$form->user = $user;
|
||||||
|
return $form;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class FormEntertainmentPresentationController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
||||||
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay();
|
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->subDay()->startOfDay();
|
||||||
|
|
||||||
$forms = FormEntertaimentPresentation::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
$forms = FormEntertaimentPresentation::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class FormMeetingSeminarController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
||||||
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay();
|
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->subDay()->startOfDay();
|
||||||
|
|
||||||
$forms = FormMeetingSeminar::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
$forms = FormMeetingSeminar::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class FormOtherController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
||||||
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay();
|
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->subDay()->startOfDay();
|
||||||
|
|
||||||
$forms = FormOthers::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
$forms = FormOthers::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class FormUpCountryController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
||||||
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay();
|
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->subDay()->startOfDay();
|
||||||
|
|
||||||
$forms = FormUpCountry::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
$forms = FormUpCountry::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class FormVehicleController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
// Calculate the actual start date for data retrieval (1 month before currentPeriodStartDate)
|
||||||
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->startOfDay();
|
$dataRetrievalStartDate = $currentPeriodStartDate->copy()->subMonth()->subDay()->startOfDay();
|
||||||
|
|
||||||
$forms = FormVehicleRunningCost::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
$forms = FormVehicleRunningCost::whereBetween('tanggal', [$dataRetrievalStartDate, $currentPeriodClosingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
|
|||||||
Reference in New Issue
Block a user