diff --git a/app/Helpers/FormHelper.php b/app/Helpers/FormHelper.php index d4a97c2..fad819b 100644 --- a/app/Helpers/FormHelper.php +++ b/app/Helpers/FormHelper.php @@ -8,6 +8,7 @@ use App\Models\FormOthers; use App\Models\FormUpCountry; use App\Models\FormVehicleRunningCost; use Illuminate\Support\Facades\DB; +use App\Models\UserHasCabang; class FormHelper { @@ -159,4 +160,25 @@ class FormHelper return $forms; } + + public static function getNominalByFormType($cabang_id, $type, $type_id, $month, $year) { + $users = UserHasCabang::where('cabang_id', $cabang_id)->get(); + $userIds = $users->pluck('user_id')->toArray(); + + if($type == 'Up Country') { + $form = FormUpCountry::select('approved_total')->whereIn('user_id', $userIds)->whereMonth('tanggal', '=', date('m', strtotime($month)))->whereYear('tanggal', '=', $year); + } else if($type == 'Vehicle Running Cost') { + $form = FormVehicleRunningCost::select('approved_total')->whereIn('user_id', $userIds)->whereMonth('tanggal', '=', date('m', strtotime($month)))->whereYear('tanggal', '=', $year); + } else if($type == 'Entertainment') { + $form = FormEntertaimentPresentation::select('approved_total')->whereIn('user_id', $userIds)->whereMonth('tanggal', '=', date('m', strtotime($month)))->whereYear('tanggal', '=', $year); + } else if($type == 'Meeting / Seminar') { + $form = FormMeetingSeminar::select('approved_total')->whereIn('user_id', $userIds)->whereMonth('created_at', '=', date('m', strtotime($month)))->whereYear('created_at', '=', $year); + } else { + $form = FormOthers::select('approved_total')->whereIn('user_id', $userIds)->whereMonth('tanggal', '=', date('m', strtotime($month)))->whereYear('tanggal', '=', $year)->where('kategori_id', $type_id); + } + + + $nominal = $form->sum('approved_total'); + return $nominal; + } } diff --git a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php index a7e78ef..131ea21 100644 --- a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php +++ b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php @@ -34,8 +34,8 @@ class FormEntertainmentPresentationController extends Controller $role = auth()->user()->getRoleNames()[0]; $forms = FormEntertaimentPresentation::whereMonth('tanggal', date('m')) ->whereYear('tanggal', date('Y')) - ->where('tanggal', '<=', date('Y-m-10')) - ->whereRaw('DAY(CURDATE()) <= 10') + ->where('tanggal', '<=', date('Y-m-20')) + ->whereRaw('DAY(CURDATE()) <= 20') ->orderBy('tanggal', 'desc') ->get(); diff --git a/app/Http/Controllers/Forms/FormMeetingSeminarController.php b/app/Http/Controllers/Forms/FormMeetingSeminarController.php index 206504d..6ab796d 100644 --- a/app/Http/Controllers/Forms/FormMeetingSeminarController.php +++ b/app/Http/Controllers/Forms/FormMeetingSeminarController.php @@ -34,8 +34,8 @@ class FormMeetingSeminarController extends Controller $role = auth()->user()->getRoleNames()[0]; $forms = FormMeetingSeminar::whereMonth('created_at', date('m')) ->whereYear('created_at', date('Y')) - ->where('created_at', '<=', date('Y-m-10')) - ->whereRaw('DAY(CURDATE()) <= 10') + ->where('created_at', '<=', date('Y-m-20')) + ->whereRaw('DAY(CURDATE()) <= 20') ->orderBy('created_at', 'desc') ->get(); diff --git a/app/Http/Controllers/Forms/FormOtherController.php b/app/Http/Controllers/Forms/FormOtherController.php index f7700a6..8aa9d54 100644 --- a/app/Http/Controllers/Forms/FormOtherController.php +++ b/app/Http/Controllers/Forms/FormOtherController.php @@ -34,8 +34,8 @@ class FormOtherController extends Controller $role = auth()->user()->getRoleNames()[0]; $forms = FormOthers::whereMonth('tanggal', date('m')) ->whereYear('tanggal', date('Y')) - ->where('tanggal', '<=', date('Y-m-10')) - ->whereRaw('DAY(CURDATE()) <= 10') + ->where('tanggal', '<=', date('Y-m-20')) + ->whereRaw('DAY(CURDATE()) <= 20') ->orderBy('tanggal', 'desc') ->get(); diff --git a/app/Http/Controllers/Forms/FormUpCountryController.php b/app/Http/Controllers/Forms/FormUpCountryController.php index d347167..e8c1b4e 100644 --- a/app/Http/Controllers/Forms/FormUpCountryController.php +++ b/app/Http/Controllers/Forms/FormUpCountryController.php @@ -34,8 +34,8 @@ class FormUpCountryController extends Controller $role = auth()->user()->getRoleNames()[0]; $forms = FormUpCountry::whereMonth('tanggal', date('m')) ->whereYear('tanggal', date('Y')) - ->where('tanggal', '<=', date('Y-m-10')) - ->whereRaw('DAY(CURDATE()) <= 10') + ->where('tanggal', '<=', date('Y-m-20')) + ->whereRaw('DAY(CURDATE()) <= 20') ->orderBy('tanggal', 'desc') ->get(); diff --git a/app/Http/Controllers/Forms/FormVehicleController.php b/app/Http/Controllers/Forms/FormVehicleController.php index 7b53c8d..b2b62a1 100644 --- a/app/Http/Controllers/Forms/FormVehicleController.php +++ b/app/Http/Controllers/Forms/FormVehicleController.php @@ -34,8 +34,8 @@ class FormVehicleController extends Controller $role = auth()->user()->getRoleNames()[0]; $forms = FormVehicleRunningCost::whereMonth('tanggal', date('m')) ->whereYear('tanggal', date('Y')) - ->where('tanggal', '<=', date('Y-m-10')) - ->whereRaw('DAY(CURDATE()) <= 10') + ->where('tanggal', '<=', date('Y-m-20')) + ->whereRaw('DAY(CURDATE()) <= 20') ->orderBy('tanggal', 'desc') ->get();