SL# Employee Branch Name Effect Month Total Amount Opening Balance Current Transaction Closing Balance @php $totalOpenningBalance = 0.00; $totalCurrentBalance = 0.00; $totalClosingBalance = 0.00; $indexCounter = 0; @endphp @foreach ($salaryDeductionGroupList as $salaryDeductionList) @php ++$indexCounter; @endphp @foreach ($salaryDeductionList as $index => $salaryDeduction) @php $openingBalance = 0.00; $currentBalance = 0.00; $subTotalClosingBalance = 0.00; $deductionCount = $salaryDeductionList->count(); @endphp @if($index == 0) {{ $indexCounter }} {{ $salaryDeduction->employee->emp_id }} - {{ $salaryDeduction->employee->emp_name_english }} {{ $salaryDeduction->employee->organization->branch->name ?? ''}} @endif {{ date('M Y',strtotime($salaryDeduction->effect_month_date)) ?? ''}} {{ number_format($salaryDeduction->total_amount,2) ?? ''}} @php $openingBalance = $salaryDeduction->total_amount - $salaryDeduction->salaryDeductionReceives->filter(function($item) use($data) { if($item->salary_target_month_date < $data['startDate']){ return true; } return false; })->sum('installment_amount'); $totalOpenningBalance += $openingBalance; @endphp {{ number_format($openingBalance,'2') }} @php $currentBalance = $salaryDeduction->salaryDeductionReceives->filter(function($item) use($data) { if($item->salary_target_month_date >= $data['startDate'] && $item->salary_target_month_date <= $data['endDate']){ return true; } return false; })->sum('installment_amount'); $totalCurrentBalance += $currentBalance; @endphp {{ number_format($currentBalance, 2) }} @php $subTotalClosingBalance = $openingBalance - $currentBalance; $totalClosingBalance += $subTotalClosingBalance; @endphp {{ number_format($subTotalClosingBalance, 2) }} @endforeach @endforeach Total {{ number_format($totalOpenningBalance,2) }} {{ number_format($totalCurrentBalance,2) }} {{ number_format($totalClosingBalance,2) }}