add where for cut off
This commit is contained in:
@@ -32,7 +32,13 @@ class FormUpCountryController extends Controller
|
||||
$this->checkAuthorization(auth()->user(), ['forms.country.view']);
|
||||
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$forms = FormUpCountry::get();
|
||||
$forms = FormUpCountry::whereMonth('tanggal', date('m'))
|
||||
->whereYear('tanggal', date('Y'))
|
||||
->where('tanggal', '<=', date('Y-m-10'))
|
||||
->whereRaw('DAY(CURDATE()) <= 10')
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get();
|
||||
|
||||
$availableBudget = null;
|
||||
|
||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
||||
@@ -59,7 +65,9 @@ class FormUpCountryController 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;
|
||||
@@ -199,7 +207,8 @@ class FormUpCountryController 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();
|
||||
}
|
||||
@@ -372,7 +381,8 @@ class FormUpCountryController 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();
|
||||
}
|
||||
@@ -413,7 +423,8 @@ class FormUpCountryController 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user