{{-- Include the modal --}} @can('view-budgets')
@if (!$budget->trashed()) @endif @php $totals = ['budget' => 0, 'expense' => 0, 'variance' => 0]; @endphp @foreach ($budget->budgetDetails as $detail) @if ($budget->trashed()) @php $totals['budget'] += round($value, 2); $totals['expense'] += $detail->year_todate_expense; $totals['variance'] += $detail->variance; @endphp @else @php $startingDate = Carbon\Carbon::parse($detail->budget->opening_date)->startOfDay(); $endingDate = Carbon\Carbon::parse($detail->budget->closing_date)->endOfDay(); $expenseSum = 0; $categoryItems = App\Models\FinancialExpenseCategoryItem::where( 'financial_expense_category_id', $detail['financial_expense_category_id'], )->get(); $expenses = App\Models\FinancialExpense::whereIn( 'financial_category_item_id', $categoryItems->pluck('id'), ) ->whereBetween('created_at', [$startingDate, $endingDate]) ->get(); foreach ($expenses as $expense) { if ( $expense->currency_id == App\Models\FinancialCurrency::where('symbol', $currency->symbol)->first() ->id ) { $expenseSum += $expense->amount; } else { $rate = App\Models\FinancialRate::withTrashed()->find($expense->rate_id); if ($rate->base_currency_id == $expense->currency_id) { $expenseSum += $expense->amount * $rate->rate; } else { $expenseSum += $expense->amount / $rate->rate; } } } $variance = round($value, 2) - $expenseSum; $variancePercentage = ($variance / round($value, 2)) * 100; @endphp @php $totals['budget'] += round($value, 2); $totals['expense'] += $expenseSum; $totals['variance'] += $variance; @endphp @endif @if (!$budget->trashed()) @endif @endforeach
loading...
Code Category Budget ({{ $currency->symbol }}) Actual Variance Var %ageActions
{{ $detail->category->sr_code }} {{ $detail->category->name }} @if ($currency->symbol == 'UGX') @php $value = $detail->year_todate_budget; @endphp @else @php $rate = App\Models\FinancialRate::withTrashed() ->where('created_at', '<=', $detail->created_at) ->latest('created_at') ->first(); if ($rate->base_currency_id == $currency->id) { $value = $detail->year_todate_budget / $rate->rate; } else { $value = $detail->year_todate_budget * $rate->rate; } // echo number_format(round($value,2), 2); @endphp @endif {{ $currency->symbol . ' ' . round($value, 2) }} {{ $detail->year_todate_expense }} {{ $detail->variance }} {{ $detail->variance_percentage }}{{ round($expenseSum, 2) }} {{ round($variance, 2) }} {{ round($variancePercentage, 2) }}
@can('analyze-budgets') @livewire('finincials.edit-budget-detail-modal', ['budgetDetail' => $detail, 'actual_expense' => $detail->year_todate_expense ?? round($totals['expense'], 2)], key('edit-budget-details-modal-' . $detail->id)) @endcan
Total {{ round($totals['budget'], 2) }} {{ round($totals['expense'], 2) }} {{ round($totals['variance'], 2) }} @if ($totals['budget'] != 0) {{ round(($totals['variance'] / $totals['budget']) * 100, 2) }} @else N/A @endif
@endcan