update revisi
This commit is contained in:
@@ -471,8 +471,8 @@ class ReportController extends Controller
|
||||
|
||||
$availableBudget = 0;
|
||||
|
||||
$month = date('F');
|
||||
$year = date('Y');
|
||||
$month = strtolower(date('F')); // convert to lowercase for DB compatibility
|
||||
$year = (int) date('Y');
|
||||
|
||||
$region_id = auth()->user()->getMyCabangAndRegionId()['region'] ?? null;
|
||||
$cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'] ?? null;
|
||||
@@ -520,27 +520,27 @@ class ReportController extends Controller
|
||||
$cabang = Cabang::where('code', $params['cabang'])->first();
|
||||
if ($cabang) {
|
||||
$userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id')->toArray();
|
||||
$forms = isset($forms) ? $forms->whereIn('user_id', $userIds) : FormHelper::getFormsByUserIds($userIds); // Ensure $forms is updated
|
||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id);
|
||||
$forms = isset($forms)
|
||||
? $forms->whereIn('user_id', $userIds)
|
||||
: FormHelper::getFormsByUserIds($userIds, $month, $year);
|
||||
|
||||
// Ensure lowercase month
|
||||
$availableBudget = BudgetHelper::getAvailableBudget($cabang->id, strtolower($month), (int) $year);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by date range
|
||||
if (isset($params['month']) || isset($params['year'])) {
|
||||
$month = $params['month'] ?? date('F');
|
||||
$year = $params['year'] ?? date('Y');
|
||||
$month = strtolower($params['month'] ?? date('F'));
|
||||
$year = (int) ($params['year'] ?? date('Y'));
|
||||
|
||||
$startOfMonth = Carbon::parse("first day of $month $year")->startOfDay();
|
||||
$endOfMonth = Carbon::parse("last day of $month $year")->endOfDay();
|
||||
|
||||
if (isset($forms)) {
|
||||
// Determine the date column to filter by
|
||||
$dateColumn = Schema::hasColumn('forms', 'tanggal') ? 'tanggal' : 'created_at';
|
||||
|
||||
// Further filter existing forms by the determined date column
|
||||
$forms = $forms->whereBetween($dateColumn, [$startOfMonth, $endOfMonth]);
|
||||
} else {
|
||||
// Rebuild $forms using FormHelper and filter by role
|
||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
||||
if ($region_id) {
|
||||
$users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) {
|
||||
@@ -566,7 +566,7 @@ class ReportController extends Controller
|
||||
} else {
|
||||
$cabangs = Cabang::all();
|
||||
$regions = Region::all();
|
||||
$forms = FormHelper::getAllForms($month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
|
||||
$forms = FormHelper::getAllForms($month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user