@php $i=0;@endphp @foreach ($Students as $Student) @php $dob = date('m-d-Y', strtotime($Student->dob)); $SetAmount = App\Models\SetFee::where('class_id', $Student->class_id) ->where('isCancelled', 0) ->orWhere('isCancelled', null) ->sum('total_amount'); $PayedAmount = App\Models\PayFee::where('student_id', $Student->id) ->where('isCancelled', 0) ->orWhere('isCancelled', null) ->sum('amount'); $Balance = $SetAmount - $PayedAmount; if($Student->DRorCR){ if($Student->DRorCR == 'Dr'){ $Balance +=$Student->openingbalance; } else{ $Balance -=$Student->openingbalance; } } @endphp @if ($Balance > 0)