fix beberapa revisi

This commit is contained in:
Jagad R R
2025-01-15 14:50:53 +07:00
parent 1eb6c48276
commit 7abfd74867
26 changed files with 830 additions and 170 deletions
@@ -14,6 +14,7 @@ use App\Models\FormMeetingSeminar;
use App\Models\FormOthers;
use App\Models\FormEntertaimentPresentation;
use App\Models\FormVehicleRunningCost;
use App\Models\UserHasCabang;
class BudgetControlController extends Controller
{
@@ -23,7 +24,30 @@ class BudgetControlController extends Controller
session()->put('redirect_url', route('budget_control'));
// Get the budget control data
$budget = BudgetControl::orderBy('created_at', 'desc')->with(['user', 'cabang'])->get();
// $budget = BudgetControl::orderBy('created_at', 'desc')->with(['user', 'cabang'])->get();
$role = auth()->user()->getRoleNames()[0];
$budget = null;
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
$region_id = auth()->user()->getMyCabangAndRegionId()['region'];
if ($region_id) {
// Get budget controls where the region matches
$budget = BudgetControl::whereHas('cabang', function ($query) use ($region_id) {
$query->where('region_id', $region_id);
})->get();
}
} elseif ($role == 'Area Manager Cabang') {
$cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];
if ($cabang_id) {
// Get budget controls where the cabang matches
$budget = BudgetControl::where('cabang_id', $cabang_id)->get();
}
} else {
// Get all budget controls for other roles
$budget = BudgetControl::all();
}
// Initialize an empty array to hold the used budget sums
$usedBudget = [];