whereIn('user_id', $userIds) ->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $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) ->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $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) ->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $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) ->whereMonth('created_at', '=', date('m', strtotime($month))) ->whereYear('created_at', '=', $year); $formOthersQuery = FormOthers::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Others' as type") )->whereIn('user_id', $userIds) ->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); // Use union before fetching the data $forms = $formUpCountryQuery ->union($formVehicleRunningCostQuery) ->union($formEntertaimentPresentationQuery) ->union($formMeetingSeminarQuery) ->union($formOthersQuery) ->get(); return $forms; } public static function getAllForms($month, $year) { $formUpCountryQuery = FormUpCountry::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Up Country' as type") )->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $formVehicleRunningCostQuery = FormVehicleRunningCost::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Vehicle Running Cost' as type") )->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $formEntertaimentPresentationQuery = FormEntertaimentPresentation::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Entertainment Presentation' as type") )->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); $formMeetingSeminarQuery = FormMeetingSeminar::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Meeting Seminar' as type") )->whereMonth('created_at', '=', date('m', strtotime($month))) ->whereYear('created_at', '=', $year); $formOthersQuery = FormOthers::select( 'expense_number', 'user_id', 'total', 'approved_total', 'status', 'account_number', 'created_at', DB::raw("'Others' as type") )->whereMonth('tanggal', '=', date('m', strtotime($month))) ->whereYear('tanggal', '=', $year); // Use union before fetching the data $forms = $formUpCountryQuery ->union($formVehicleRunningCostQuery) ->union($formEntertaimentPresentationQuery) ->union($formMeetingSeminarQuery) ->union($formOthersQuery) ->get(); return $forms; } }