added report all
This commit is contained in:
@@ -11,16 +11,18 @@ use App\Models\FormMeetingSeminar;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\FormEntertaimentPresentation;
|
||||
use App\Models\FormVehicleRunningCost;
|
||||
use App\Helpers\FormHelper;
|
||||
use App\Models\UserHasCabang;
|
||||
|
||||
class BudgetHelper
|
||||
{
|
||||
public static function getAvailableBudget()
|
||||
public static function getAvailableBudget($cabang_id)
|
||||
{
|
||||
// Get the budget control data
|
||||
$budget = BudgetControl::orderBy('created_at', 'desc')->with(['user', 'cabang'])->get();
|
||||
$budget = BudgetControl::where('cabang_id', $cabang_id)->orderBy('created_at', 'desc')->with(['user', 'cabang'])->get();
|
||||
|
||||
// Initialize an empty array to hold the used budget sums
|
||||
$usedBudget = [];
|
||||
$usedBudget = 0;
|
||||
|
||||
foreach ($budget as $b) {
|
||||
// Get the month and year from the budget
|
||||
@@ -28,38 +30,12 @@ class BudgetHelper
|
||||
$year = $b->periode_year;
|
||||
|
||||
// Add the used budget per model for the specified month and year to the usedBudget array
|
||||
$usedBudget[] = [
|
||||
'FormUpCountry' => FormUpCountry::whereIn('status', ['Approved', 'Closed'])
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year)
|
||||
->sum('approved_total'),
|
||||
|
||||
'FormMeetingSeminar' => FormMeetingSeminar::whereIn('status', ['Approved', 'Closed'])
|
||||
->whereMonth('created_at', '=', date('m', strtotime($month)))
|
||||
->whereYear('created_at', '=', $year)
|
||||
->sum('approved_total'),
|
||||
|
||||
'FormOthers' => FormOthers::whereIn('status', ['Approved', 'Closed'])
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year)
|
||||
->sum('approved_total'),
|
||||
|
||||
'FormEntertaimentPresentation' => FormEntertaimentPresentation::whereIn('status', ['Approved', 'Closed'])
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year)
|
||||
->sum('approved_total'),
|
||||
|
||||
'FormVehicleRunningCost' => FormVehicleRunningCost::whereIn('status', ['Approved', 'Closed'])
|
||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
||||
->whereYear('tanggal', '=', $year)
|
||||
->sum('approved_total')
|
||||
];
|
||||
$users = UserHasCabang::where('cabang_id', $cabang_id)->get();
|
||||
$userIds = $users->pluck('user_id')->toArray();
|
||||
$forms = FormHelper::getFormsByUserIds($userIds, $month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
|
||||
$usedBudget += $forms->sum('approved_total');
|
||||
}
|
||||
|
||||
$usedBudget = array_sum(array_map(function ($b) {
|
||||
return array_sum($b);
|
||||
}, $usedBudget));
|
||||
|
||||
$availableBudget = $budget->sum('amount') - $usedBudget;
|
||||
|
||||
return $availableBudget;
|
||||
|
||||
Reference in New Issue
Block a user