@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); } //dd(session('lang')); @endphp @if(session('lang') == 2) {{-- _css_bangla already loaded in via _report_header; only override sizes here --}} @endif {{ $report_title }} - Report
{{ $lang['Fee Register'] }}

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

@php $info_parts = []; if (!empty($student->father)) { $info_parts[] = '' . $lang['Father Name'] . ': ' . $student->father; } if (!empty($student->mobile)) { $info_parts[] = '' . $lang['Mobile'] . ': ' . $student->mobile; } if (!empty($student->address)) { $info_parts[] = '' . $lang['Address'] . ': ' . $student->address; } @endphp @if (count($info_parts) > 0)

{!! implode(' | ', $info_parts) !!}

@endif @php $sw = $session_window ?? null; $monthNamesList = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; @endphp @if($sw)

{{ $lang['Session'] ?? 'Session' }}: {{ $sw['name'] ?? '-' }} | {{ $lang['Years'] ?? 'Years' }}: {{ !empty($sw['years']) ? implode('-', $sw['years']) : '-' }} @if(empty($sw['legacy'])) | {{ $lang['Months'] ?? 'Months' }}: {{ $monthNamesList[$sw['start_month']] ?? '-' }} – {{ $monthNamesList[$sw['end_month']] ?? '-' }} @endif

@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. $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; } // Separate fees into: // - TUITION FEES: the actual Tuition Fee product only (product_id 1 - same identity // check the label rendering below already relies on). NOT "everything in the Monthly // category" - Transport Fee and other recurring items share that category with // Tuition but are not tuition, and used to get mislabeled here as a result. // - OTHER FEES: everything else (admission fee, transport fee, exam fee, etc.) $tuition_fees = collect($fees)->filter(function($item) { return isset($item->product_id) && $item->product_id == 1; })->sortBy([ ['year', 'asc'], ['month', 'asc'], ]); $other_fees = collect($fees)->reject(function($item) { return isset($item->product_id) && $item->product_id == 1; }); // Calculate totals $ttl_tuition_fee = $tuition_fees->sum(function($item) { return floatval($item->amount ?? 0); }); $ttl_other_fee = $other_fees->sum(function($item) { return floatval($item->amount ?? 0); }); $ttl_fee = $ttl_tuition_fee + $ttl_other_fee; // 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; @endphp {{-- Tuition Fees Table (full width) --}}
{{ session('lang') == 2 ? 'টিউশন ফি' : 'TUITION FEES' }}
@if($showFeeActions) @endif @if($tuition_fees->count() > 0) @foreach ($tuition_fees as $item) @php $periodDisplay = ''; if (!empty($item->month)) { $periodDisplay = getMonth($item->month); if (!empty($item->year)) { $periodDisplay .= ' ' . $item->year; } } $feeDate = !empty($item->fees_created) ? (session('lang') == 2 ? bddate($item->fees_created) : date('d M Y', strtotime($item->fees_created))) : '-'; // Tuition fees are from the fees table; find matching order_details to get order_id $tOrderId = DB::table('order_details') ->where('student_id', $item->student_id) ->where('product_id', $item->product_id) ->when(!empty($item->month), fn($q) => $q->where('month', $item->month)) ->when(!empty($item->year), fn($q) => $q->where('year', $item->year)) ->value('order_id'); $tInvId = $tOrderId ? DB::table('orders')->where('id', $tOrderId)->value('inv_id') : null; $tPayRow = ($tOrderId && $item->status == 'Paid') ? DB::table('payments')->where('order_id', $tOrderId)->select('payment_method')->first() : null; $tPm = $tPayRow->payment_method ?? '-'; @endphp @if($showFeeActions) @endif @endforeach @if($showFeeActions)@endif @else @endif
# {{ $lang['Date'] }} {{ session('lang') == 2 ? 'টিউশন ফি' : 'Tuition Fees' }} {{ session('lang') == 2 ? 'সময়কাল' : 'Period' }} {{ session('lang') == 2 ? 'ইনভ আইডি' : 'Inv ID' }} {{ $lang['Amount'] }} {{ session('lang') == 2 ? 'পেমেন্ট' : 'PM' }} {{ $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 {{ $feeDate }} @if ($item->product_id == 1) @php $feeLabel = getMonth($item->month) . (!empty($item->year) ? ' ' . $item->year : ''); @endphp {{ $feeLabel }} {{ $feeLabel }} @else {{ $item->name }} {{ $item->name }} @endif @include('reports._fee_waiver_info') {{ $periodDisplay ?: '-' }} @if($tInvId) {{ session('lang') == 2 ? e2b($tInvId) : $tInvId }} {{ session('lang') == 2 ? e2b($tInvId) : $tInvId }} @else - @endif @if(($settings->update_tuition_on_invoice ?? 'no') === 'yes' && session('user.super_admin') == 'yes' && isset($item->fee_id) && !isset($item->order_id) && $item->status != 'Waived') {{ session('lang') == 2 ? e2b(number_format($item->amount, 0)) : number_format($item->amount, 0) }} @else {{ session('lang') == 2 ? e2b(number_format($item->amount, 0)) : number_format($item->amount, 0) }} @endif {{ $tPm }} {{ session('lang') == 2 ? (['Paid' => 'পেইড', 'Due' => 'বকেয়া', 'Waived' => 'মওকুফ'][$item->status] ?? $item->status) : $item->status }} @include('reports._fee_waiver_action', ['invoiced' => (bool) $tOrderId]) @if($isSuper) @if($item->status == 'Due') @endif @endif
{{ session('lang') == 2 ? 'মোট টিউশন ফি' : 'Total Tuition Fees' }}: {{ session('lang') == 2 ? e2b(number_format($ttl_tuition_fee, 0)) : number_format($ttl_tuition_fee, 0) }}
{{ session('lang') == 2 ? 'কোন টিউশন ফি পাওয়া যায়নি' : 'No tuition fees found' }}
{{-- Other Fees Table (full width) --}}
{{ session('lang') == 2 ? 'অন্যান্য ফি' : 'OTHER FEES' }}
@if($showFeeActions) @endif @if($other_fees->count() > 0) @php // Pre-compute last fee_id per order so discount shows on the last row of each bill $lastFeeIdPerOrder = []; foreach ($other_fees as $_f) { if (!empty($_f->order_id)) { $lastFeeIdPerOrder[$_f->order_id] = $_f->fee_id; } } @endphp @foreach ($other_fees as $item) @php $feeDate = !empty($item->fees_created) ? (session('lang') == 2 ? bddate($item->fees_created) : date('d M Y', strtotime($item->fees_created))) : '-'; $oOrderId = $item->order_id ?? null; $oInvId = $oOrderId ? DB::table('orders')->where('id', $oOrderId)->value('inv_id') : null; $oPayRow = ($oOrderId && $item->status == 'Paid') ? DB::table('payments')->where('order_id', $oOrderId)->select('payment_method')->first() : null; $oPm = $oPayRow->payment_method ?? '-'; // Show discount on the last row of each bill only $oDiscount = 0; if ($oOrderId && !empty($item->order_discount) && floatval($item->order_discount) > 0 && ($lastFeeIdPerOrder[$oOrderId] ?? null) == $item->fee_id) { $oDiscount = floatval($item->order_discount); } @endphp @if($showFeeActions) @endif @endforeach @php // Sum discount once per order (same logic as the per-row display above) $seenDiscountOrders = []; $ttl_other_discount = 0; foreach ($other_fees as $f) { $fOrderId = $f->order_id ?? null; if ($fOrderId && !empty($f->order_discount) && floatval($f->order_discount) > 0 && !in_array($fOrderId, $seenDiscountOrders)) { $ttl_other_discount += floatval($f->order_discount); $seenDiscountOrders[] = $fOrderId; } } $ttl_other_net = $ttl_other_fee - $ttl_other_discount; @endphp @if($showFeeActions)@endif @else @endif
# {{ $lang['Date'] }} {{ $lang['Particular'] }} {{ session('lang') == 2 ? 'সময়কাল' : 'Period' }} {{ session('lang') == 2 ? 'ইনভ আইডি' : 'Inv ID' }} {{ $lang['Amount'] }} {{ session('lang') == 2 ? 'ছাড়' : 'Discount' }} {{ session('lang') == 2 ? 'পেমেন্ট' : 'PM' }} {{ $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 {{ $feeDate }} {{ session('lang') == 2 ? ($item->name2 ?? $item->name) : $item->name }} {{ session('lang') == 2 ? ($item->name2 ?? $item->name) : $item->name }} @include('reports._fee_waiver_info') - @if($oInvId) {{ session('lang') == 2 ? e2b($oInvId) : $oInvId }} {{ session('lang') == 2 ? e2b($oInvId) : $oInvId }} @else - @endif {{ session('lang') == 2 ? e2b(number_format($item->amount, 0)) : number_format($item->amount, 0) }} @if($oDiscount > 0) -{{ session('lang') == 2 ? e2b(number_format($oDiscount, 0)) : number_format($oDiscount, 0) }} @else - @endif {{ $oPm }} {{ session('lang') == 2 ? (['Paid' => 'পেইড', 'Due' => 'বকেয়া', 'Waived' => 'মওকুফ'][$item->status] ?? $item->status) : $item->status }} @include('reports._fee_waiver_action', ['invoiced' => $oOrderId !== null]) @if($isSuper) @if($item->status == 'Due' && $oOrderId === null) @endif @if($oOrderId === null) @endif @endif
{{ session('lang') == 2 ? 'মোট অন্যান্য ফি' : 'Total Other Fees' }}: {{ session('lang') == 2 ? e2b(number_format($ttl_other_fee, 0)) : number_format($ttl_other_fee, 0) }} @if($ttl_other_discount > 0) -{{ session('lang') == 2 ? e2b(number_format($ttl_other_discount, 0)) : number_format($ttl_other_discount, 0) }} @else - @endif
{{ session('lang') == 2 ? 'কোন অন্যান্য ফি পাওয়া যায়নি' : 'No other fees found' }}
{{-- Grand Total Summary --}} @php $ttl_fee_net = $ttl_tuition_fee + ($ttl_other_net ?? $ttl_other_fee); $ttl_fees_display = floatval($ttl_fee_net) + floatval($total_refund) + floatval($ob_crebit); $total_due = $ttl_fees_display - ($total_bill_paid + $ob_debit + $total_return); @endphp
{{ $lang['Total Fees'] }}: {{ session('lang') == 2 ? e2b(number_format($ttl_fees_display, 0)) : number_format($ttl_fees_display, 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) }}
{{-- Invoice List --}} @if(isset($student_invoices) && $student_invoices->count() > 0)
{{ session('lang') == 2 ? 'সকল ইনভয়েস' : 'All Invoices' }} {{ $student_invoices->count() }} {{ session('lang') == 2 ? 'টি' : 'records' }}
@foreach($student_invoices as $inv) @endforeach
# {{ session('lang') == 2 ? 'তারিখ' : 'Date' }} {{ session('lang') == 2 ? 'ইনভ আইডি' : 'Inv ID' }} {{ session('lang') == 2 ? 'সাবটোটাল' : 'Sub Total' }} {{ session('lang') == 2 ? 'ছাড়' : 'Discount' }} {{ session('lang') == 2 ? 'মোট' : 'Net Amount' }} {{ session('lang') == 2 ? 'স্ট্যাটাস' : 'Status' }} {{ session('lang') == 2 ? 'তৈরিকারী' : 'Created By' }}
{{ $loop->iteration }} {{ session('lang') == 2 ? bddate($inv->created_at) : date('d M Y', strtotime($inv->created_at)) }} {{ $inv->inv_id }} {{ number_format($inv->sub_total, 0) }} @if(floatval($inv->discount_amount) > 0) -{{ number_format($inv->discount_amount, 0) }} @else - @endif {{ number_format($inv->total_price, 0) }} {{ session('lang') == 2 ? ($inv->status == 'Paid' ? 'পেইড' : ($inv->status == 'Due' ? 'বকেয়া' : $inv->status)) : $inv->status }} @if(!empty($inv->settled_by_inv_id))
{{ session('lang') == 2 ? 'সেটেলড: ' . e2b($inv->settled_by_inv_id) : 'via #' . $inv->settled_by_inv_id }} @endif
{{ $inv->created_by_name ?? '-' }}
{{ session('lang') == 2 ? 'মোট' : 'Total' }} {{ number_format($student_invoices->sum('sub_total'), 0) }} @if($student_invoices->sum('discount_amount') > 0) -{{ number_format($student_invoices->sum('discount_amount'), 0) }} @else - @endif {{ number_format($student_invoices->sum('total_price'), 0) }}
@endif
{{ session('lang') == 2 ? 'প্রিন্ট' : 'Print' }} {{ $lang['Create Invoice'] }} {{ $lang['Generate Invoice'] }} {{ session('lang') == 2 ? 'ভর্তি ইনভয়েস' : 'Admission Invoice' }} {{ session('lang') == 2 ? 'সকল ছাত্রছাত্রীর তালিকা' : 'All Student List' }}
@if($showFeeActions && $canWaive) @endif @if(($settings->update_tuition_on_invoice ?? 'no') === 'yes' && session('user.super_admin') == 'yes') @endif @if(session('user.super_admin') == 'yes') @endif