@include('reports._report_header') @php use App\Models\Setting; $settings = Setting::where('client_id', session('client_id'))->first(); @endphp @php if (!Session::has('lang') || session('lang') == null) { session()->put('lang', 1); } if (session('lang') == 1) { $lang = json_decode(file_get_contents(resource_path('lang/en.json')), true); } elseif (session('lang') == 2) { $lang = json_decode(file_get_contents(resource_path('lang/bn.json')), true); } elseif (session('lang') == 3) { $lang = json_decode(file_get_contents(resource_path('lang/ar.json')), true); } else { $lang = json_decode(file_get_contents(resource_path('lang/en.json')), true); } @endphp @if(session('lang') == 2) @include('reports._css_bangla') @endif {{ $report_title }} - Report
{{ session('lang') == 2 ? 'ভর্তি ও বেতন রেজিস্টার' : 'Admission & Salary Register' }} @if($date_range) {{ session('lang') == 2 ? e2b($date_range) : $date_range }} @endif

{{ $lang['Name'] }}: @if(session('settings.std_id') == 1 && !empty($student->std_id)) {{ session('lang') == 2 ? e2b($student->std_id) : $student->std_id }} - @endif {{ $student->name }} | {{ $lang['Class'] }}: {{ getClass($student->class) }} | {{ $lang['Roll'] }}: {{ session('lang') == 2 ? e2b($student->roll) : $student->roll }}

@if ($student->father != null)

{{ $lang['Father Name'] }}: {{ $student->father }} | {{ $lang['Mobile'] }}: {{ $student->mobile }} | {{ $lang['Address'] }}: {{ $student->address ?? '' }}

@endif @if(session('user.super_admin') == 'yes')

{{ session('lang') == 2 ? 'বেতন (ছাত্র রেকর্ড)' : 'Tuition Fee (student record)' }}:

@endif
@php $ob = 0; $cb = 0; $ob_debit = 0; $ob_crebit = 0; // $date_range is always set by the controller (today's date, for display // only) — an `isset($date_range)` guard here would always be false and // permanently skip the opening-balance lookup, so it's not used. Also // dropped the unconditional `$total_refund = 0` that used to sit here: // it silently overwrote the real refund total the controller computed. $ob = DB::table('customer_accounts') ->where('customer_id', $student->id) ->where('type', 'OB') ->orderBy('id', 'desc') ->first(); if($ob != null){ $ob_date = $ob->created_at; $ob = $ob->current_balance; } if($ob > 0){ $ob_debit = $ob; } if($ob < 0){ $ob_crebit = -(int)$ob; $ob_debit = 0; } $ca = DB::table('customer_accounts') ->where('customer_id', $student->id) ->orderBy('id', 'desc') ->first(); if($ca != null){ $cb = $ca->current_balance; } else { $cb = 0; } // Sort fees by year then month (Jan→Dec) $fees = collect($fees)->sortBy([ ['year', 'asc'], ['month', 'asc'], ]); // Calculate total fees $ttl_fee = 0; foreach ($fees as $item) { $ttl_fee = $ttl_fee + floatval($item->amount); } // Waive-to-0 is open to the same roles as the financial routes; mark-paid and // delete stay super-admin only. $canWaive = in_array(session('user.user_type'), ['Admin', 'Manager', 'Accountant', 'HR Admin', 'Academic Admin']); $isSuper = session('user.super_admin') == 'yes'; $showFeeActions = $canWaive || $isSuper; // Calculate total return if (isset($returns) && $returns != null) { $total_return = $returns->sum(function($i) { return floatval($i->total_price ?? 0); }); } else { $total_return = 0; } @endphp {{-- Grand Total Footer Row --}} {{-- Due Amount Row --}}
{{-- Fees Allocated Table --}}
{{ session('lang') == 2 ? 'ফি বরাদ্দ' : 'FEES ALLOCATED' }}
@if($showFeeActions) @endif @php $ttl_fee = 0; $ttl_electricity = 0; $ttl_food = 0; // Tracks, per invoice (order id), how much of that invoice's // orders.paid_amount has already been assigned to an earlier month // in this loop — so a partial invoice payment is applied to the // earliest month(s) first instead of showing every month on the // invoice as equally "partial". orders.paid_amount (not a sum of // payments.order_detail_id, which isn't reliably populated for // every payment) is the same figure the invoice-preview screen // shows as পেইড, so it's the authoritative "how much of this // invoice is actually collected" source. $lineAllocatedSoFar = []; @endphp @foreach ($fees as $item) @php $ttl_fee = $ttl_fee + floatval($item->amount); $ttl_electricity = $ttl_electricity + floatval($item->electricity ?? 0); $ttl_food = $ttl_food + floatval($item->food_fee ?? 0); // A month marked 'Paid' only means it has been invoiced (see // markFeeMonthPaid) — it may still be on an invoice (order) // that's only partially collected. Find that invoice line and // show the real remaining balance instead of a flat "Paid". $rOrderDetail = null; if (isset($item->fee_id) && !empty($item->month)) { $rOrderDetail = DB::table('order_details as od') ->join('orders as o', 'o.id', '=', 'od.order_id') ->where('od.student_id', $item->student_id) ->where('od.product_id', $item->product_id) ->where('od.year', $item->year) ->where('od.active', 'on') ->where('o.active', 'on') ->select('od.*', 'o.paid_amount as order_paid_amount', 'o.total_bill as order_total_bill') ->get() ->first(function ($line) use ($item) { $m = trim((string) $line->month); if ($m === '') { return false; } [$from, $to] = strpos($m, '-') !== false ? array_map('intval', explode('-', $m, 2)) : [(int) $m, (int) $m]; return (int) $item->month >= min($from, $to) && (int) $item->month <= max($from, $to); }); } $rLineRemaining = null; $item->partial_paid = false; $item->paid_for_month = null; $item->due_for_month = null; if ($rOrderDetail) { $rOrderPaidTotal = (float) $rOrderDetail->order_paid_amount; $rOrderTotalBill = (float) $rOrderDetail->order_total_bill; $rLineRemaining = round($rOrderTotalBill - $rOrderPaidTotal, 2); if ($item->status === 'Paid' && $rLineRemaining > 0.01) { // Allocate the invoice's paid_amount to months in order: // this month gets whatever of the invoice payment is left // after earlier months (lower month number, already // looped) took theirs. $lineKey = $rOrderDetail->order_id; $alreadyUsed = $lineAllocatedSoFar[$lineKey] ?? 0; $monthAmount = (float) $item->amount; $paidForMonth = max(0, min($monthAmount, $rOrderPaidTotal - $alreadyUsed)); $dueForMonth = round($monthAmount - $paidForMonth, 2); $lineAllocatedSoFar[$lineKey] = $alreadyUsed + $paidForMonth; if ($dueForMonth > 0.01) { $item->status = 'Due'; $item->partial_paid = $paidForMonth > 0.01; $item->paid_for_month = $paidForMonth; $item->due_for_month = $dueForMonth; } } } @endphp @if($showFeeActions) @endif @endforeach @if(count($fees) > 0) @if($showFeeActions)@endif @else @endif
# {{ session('lang') == 2 ? 'মাস' : 'Month' }} {{ session('lang') == 2 ? 'বেতন' : 'Salary' }} {{ session('lang') == 2 ? 'বিদ্যুৎ' : 'Electricity' }} {{ session('lang') == 2 ? 'খোরাকি' : 'Food' }} {{ $lang['Status'] }}
@if (session('user.user_type') == 'Admin') {{ session('lang') == 2 ? e2b($loop->iteration) : $loop->iteration }} {{ session('lang') == 2 ? e2b($loop->iteration) : $loop->iteration }} @else {{ session('lang') == 2 ? e2b($loop->iteration) : $loop->iteration }} @endif @if ($item->product_id == 1) {{ getMonth($item->month) }} {{ getMonth($item->month) }} @else {{ session('lang') == 2 ? ($item->name2 ?? $item->name) : $item->name }} {{ session('lang') == 2 ? ($item->name2 ?? $item->name) : $item->name }} @endif @include('reports._fee_waiver_info') @if(($settings->update_tuition_on_invoice ?? 'no') === 'yes' && session('user.super_admin') == 'yes' && isset($item->fee_id) && empty($item->order_id ?? null) && $item->status != 'Waived' && empty($item->original_amount ?? null)) {{ session('lang') == 2 ? e2b(number_format(floatval($item->amount), 0)) : number_format(floatval($item->amount), 0) }} @else {{ session('lang') == 2 ? e2b(number_format(floatval($item->amount), 0)) : number_format(floatval($item->amount), 0) }} @endif {{ session('lang') == 2 ? e2b(number_format($item->electricity ?? 0, 0)) : number_format($item->electricity ?? 0, 0) }} {{ session('lang') == 2 ? e2b(number_format($item->food_fee ?? 0, 0)) : number_format($item->food_fee ?? 0, 0) }} @if($item->partial_paid ?? false) {{ session('lang') == 2 ? 'আংশিক (পেইড ' . e2b(number_format($item->paid_for_month, 0)) . ', বকেয়া ' . e2b(number_format($item->due_for_month, 0)) . ')' : 'Partial (paid ' . number_format($item->paid_for_month, 0) . ', due ' . number_format($item->due_for_month, 0) . ')' }} @else {{ session('lang') == 2 ? (['Paid' => 'পেইড', 'Due' => 'বকেয়া', 'Waived' => 'মওকুফ'][$item->status] ?? $item->status) : $item->status }} @endif @php // Invoice lines carry order_id; allocated monthly rows use the // combined-line lookup already done above for the status badge. $rInvoiced = !empty($item->order_id ?? null) || $rOrderDetail !== null; $rCollectAmount = $item->due_for_month ?? ($rLineRemaining ?? $item->amount); @endphp @include('reports._fee_waiver_action', ['invoiced' => $rInvoiced, 'collectAmount' => $rCollectAmount]) @if($isSuper) @if($item->status == 'Due') ✓ @endif × @endif
{{ session('lang') == 2 ? 'মোট' : 'Total' }}: {{ session('lang') == 2 ? e2b(number_format($ttl_fee, 0)) : number_format($ttl_fee, 0) }} {{ session('lang') == 2 ? e2b(number_format($ttl_electricity, 0)) : number_format($ttl_electricity, 0) }} {{ session('lang') == 2 ? e2b(number_format($ttl_food, 0)) : number_format($ttl_food, 0) }}
{{ session('lang') == 2 ? 'কোন ফি পাওয়া যায়নি' : 'No fees found' }}
{{-- Fees Paid Table --}}
{{ $lang['Fees Paid'] }}
@foreach ($bill_paid as $item) @php $inv = DB::table('orders')->where('id', $item->order_id)->where('active', 'on')->first(); if ($inv == null) { continue; } @endphp @endforeach {{-- Product Returns --}} @if (isset($returns) && $returns != null) @foreach ($returns as $item) @endforeach @else @php $total_return = 0; @endphp @endif @if ($ob > 0) @endif
# {{ $lang['Date'] }} {{ session('lang') == 2 ? 'ইনভয়েস' : $lang['Inv'] }} {{ $lang['P.M'] }} {{ $lang['Amount'] }}
{{ session('lang') == 2 ? e2b($loop->iteration) : $loop->iteration }} @php $date = explode(' ', $item->created_at); echo bd($date[0]); @endphp @if ($item->order_id == '1') {{ session('lang') == 2 ? 'অগ্রিম ' : 'Advance ' }} @endif {{ session('lang') == 2 ? e2b($inv->inv_id) : 'ID-' . $inv->inv_id }} @if ($item->order_id == '1') {{ session('lang') == 2 ? 'অগ্রিম ' : 'Advance ' }} @endif {{ session('lang') == 2 ? e2b($inv->inv_id) : 'ID-' . $inv->inv_id }} @if ($item->payment_method == 'Bank') {{ session('lang') == 2 ? 'ব্যাংক' : $item->payment_method }} {{ session('lang') == 2 ? 'ব্যাংক' : $item->payment_method }} @elseif ($item->payment_method == 'MFS') @php $mfs = DB::table('banks')->where('id', $item->bank_id)->first(); @endphp {{ $mfs->title ?? (session('lang') == 2 ? 'এমএফএস' : $item->payment_method) }} {{ $mfs->title ?? (session('lang') == 2 ? 'এমএফএস' : $item->payment_method) }} @elseif ($item->payment_method == 'Cash') {{ session('lang') == 2 ? 'ক্যাশ' : $item->payment_method }} @else {{ $item->payment_method }} @endif {{ session('lang') == 2 ? e2b(number_format(floatval($item->amount), 0)) : number_format(floatval($item->amount), 0) }}
{{ session('lang') == 2 ? e2b($loop->iteration) : $loop->iteration }} @php $date = explode(' ', $item->created_at); echo bd($date[0]); @endphp R-{{ $item->id }} R-{{ $item->id }} {{ session('lang') == 2 ? 'ফেরত' : 'Return' }} {{ session('lang') == 2 ? e2b(number_format($item->total_price, 0)) : number_format($item->total_price, 0) }}
@php $date = explode(' ', $ob_date); echo bd($date[0]); @endphp {{ $lang['Opening Balance'] }} {{ session('lang') == 2 ? e2b(number_format($ob, 0)) : number_format($ob, 0) }}
{{ $lang['Total Fees Paid'] }}: {{ session('lang') == 2 ? e2b(number_format($total_bill_paid + $ob_debit + $total_return, 0)) : number_format($total_bill_paid + $ob_debit + $total_return, 0) }}
{{ $lang['Total Fees'] }}: {{ session('lang') == 2 ? e2b(number_format(floatval($ttl_fee) + floatval($total_refund) + floatval($ob_crebit), 0)) : number_format(floatval($ttl_fee) + floatval($total_refund) + floatval($ob_crebit), 0) }} {{ $lang['Total Fees Paid'] }}: {{ session('lang') == 2 ? e2b(number_format($total_bill_paid + $ob_debit + $total_return, 0)) : number_format($total_bill_paid + $ob_debit + $total_return, 0) }}
{{ session('lang') == 2 ? 'মোট বকেয়া' : 'Total Due' }}: {{ session('lang') == 2 ? e2b(number_format($total_due, 0)) : number_format($total_due, 0) }}
{{ session('lang') == 2 ? 'প্রিন্ট' : 'Print' }} {{ $lang['Create Invoice'] }} {{ $lang['Generate Invoice'] }} {{ session('lang') == 2 ? 'সকল ছাত্রছাত্রীর তালিকা' : 'All Student List' }}
@if($showFeeActions && $canWaive) @include('reports._fee_waiver_script') @endif @if(($settings->update_tuition_on_invoice ?? 'no') === 'yes' && session('user.super_admin') == 'yes') @endif @if(session('user.super_admin') == 'yes') @endif