add where for cut off

This commit is contained in:
Jagad R R
2025-01-12 13:34:35 +07:00
parent 3127b3b5d7
commit 6efaa99220
7 changed files with 90 additions and 30 deletions
@@ -32,7 +32,13 @@ class FormMeetingSeminarController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.meeting.view']);
$role = auth()->user()->getRoleNames()[0];
$forms = FormMeetingSeminar::get();
$forms = FormMeetingSeminar::whereMonth('created_at', date('m'))
->whereYear('created_at', date('Y'))
->where('created_at', '<=', date('Y-m-10'))
->whereRaw('DAY(CURDATE()) <= 10')
->orderBy('created_at', 'desc')
->get();
$availableBudget = null;
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
@@ -59,7 +65,8 @@ class FormMeetingSeminarController extends Controller
}
else if ($role == 'Medical Representatif') {
$forms = $forms->where('user_id', auth()->user()->id);
$availableBudget = BudgetHelper::getAvailableBudget($forms->first()->user->cabang->cabang->id);
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
$availableBudget = BudgetHelper::getAvailableBudget($cabang_id);
}
else {
$forms = $forms;
@@ -175,7 +182,8 @@ class FormMeetingSeminarController extends Controller
];
// Check if the total nominal exceeds the available budget
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget()) {
$cabang_id = UserHasCabang::where('user_id', auth()->user()->id)->first()->cabang_id;
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang_id)) {
session()->flash('error', 'The total nominal exceeds the available budget.');
return redirect()->back();
}
@@ -254,6 +262,7 @@ class FormMeetingSeminarController extends Controller
{
$this->checkAuthorization(auth()->user(), ['forms.meeting.edit']);
$role = auth()->user()->getRoleNames()[0];
$form = FormMeetingSeminar::findOrfail($id);
$request->validate([
'allowance' => 'nullable|numeric',
@@ -264,7 +273,6 @@ class FormMeetingSeminarController extends Controller
'bukti_hotel' => ['nullable', 'file', 'max:51200', new FileType(['php', 'exe', 'js', 'sh', 'bat', 'exe', 'sh', 'php', 'vbs'])],
]);
$form = FormMeetingSeminar::findOrfail($id);
if($form->status != 'On Progress' && $role == 'Medical Representatif') {
session()->flash('error', 'You cannot edit this form because it has been approved or rejected.');
return redirect()->back();
@@ -322,7 +330,8 @@ class FormMeetingSeminarController extends Controller
];
// Check if the total nominal exceeds the available budget
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget()) {
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
if(array_sum($data_nominal) > BudgetHelper::getAvailableBudget($cabang_id)) {
session()->flash('error', 'The total nominal exceeds the available budget.');
return redirect()->back();
}
@@ -356,7 +365,8 @@ class FormMeetingSeminarController extends Controller
];
// Check if the total nominal exceeds the available budget
if(array_sum($approved_data) > BudgetHelper::getAvailableBudget()) {
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
if(array_sum($approved_data) > BudgetHelper::getAvailableBudget($cabang_id)) {
session()->flash('error', 'The total nominal exceeds the available budget.');
return redirect()->back();
}