update revisi
This commit is contained in:
@@ -10,12 +10,7 @@ use App\Models\BudgetControl;
|
||||
use App\Models\BudgetControlLog;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\FormUpCountry;
|
||||
use App\Models\FormMeetingSeminar;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\FormEntertaimentPresentation;
|
||||
use App\Models\FormVehicleRunningCost;
|
||||
use App\Models\UserHasCabang;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class BudgetControlController extends Controller
|
||||
{
|
||||
@@ -47,10 +42,23 @@ class BudgetControlController extends Controller
|
||||
$budget = BudgetControl::with(['receiver', 'sender', 'cabang'])->get();
|
||||
}
|
||||
|
||||
// Calculate usedBudget and availableBudget for each cabang
|
||||
$budget->map(function ($b) {
|
||||
$b->availableBudget = BudgetHelper::getAvailableBudget($b->cabang_id);
|
||||
// Tentukan periode berdasarkan start dan closing date
|
||||
$startDay = (int) env('STARTING_DATE', 11);
|
||||
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($now->day >= $startDay) {
|
||||
$startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay();
|
||||
} else {
|
||||
$startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay();
|
||||
}
|
||||
|
||||
$periodeMonth = $startDate->month;
|
||||
$periodeYear = $startDate->year;
|
||||
|
||||
// Hitung available budget berdasarkan periode
|
||||
$budget->map(function ($b) use ($periodeMonth, $periodeYear) {
|
||||
$b->availableBudget = BudgetHelper::getAvailableBudget($b->cabang_id, $periodeMonth, $periodeYear);
|
||||
return $b;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user