@extends('layout.app') @section('content')

Core Rent

@can('core-rent-history') Edit & Delete Log @endcan @can('core-rent-create') Add New @endcan
@if (session('success_message'))
{{ session('success_message') }}
@endif @if (session('error_message'))
{{ session('error_message') }}
@endif
@if (request('reseller_id') || request('pop_id')) Clear @endif
@php // "Billable" grows on its own: rent × periods elapsed since start_date. $grandRentPerPeriod = (float) $coreRents->sum('rent_amount'); $grandRent = (float) $coreRents->sum('total_billable'); $grandPaid = (float) $coreRents->sum('payments_sum_amount'); // Sum each rent's own clamped remaining so an overpaid rent can't cancel real dues on others. $grandRemaining = (float) $coreRents->sum('remaining_due'); @endphp {{-- The Total row lives in , above the rows: a header row is never sorted or paginated with the data, and it pins under the sticky header. --}} @foreach ($coreRents as $item) @php $totalPaid = (float) ($item->payments_sum_amount ?? 0); $billable = $item->total_billable; $remaining = $item->remaining_due; @endphp @endforeach
# Manager POP Title Start Date End Date Status Rent / Period (৳) Billed Till Now (৳) Total Paid (৳) Due (৳) Action
Total {{ number_format($grandRentPerPeriod, 2) }} {{ number_format($grandRent, 2) }} {{ number_format($grandPaid, 2) }} {{ number_format($grandRemaining, 2) }}
{{ $item->id }} {{ $item->reseller->name_with_type ?? '—' }} {{ $item->pop->popname ?? '—' }} {{ $item->title }} @if ($item->location)
{{ $item->location }} @endif
Added by: {{ $item->submittedBy->name ?? ($item->createdBy->name ?? '—') }}
{{ $item->start_date ? $item->start_date->format('d M Y') : '—' }} {{ $item->end_date ? $item->end_date->format('d M Y') : '—' }} @include('partials.approval-status', ['item' => $item]) @include('partials.approval-comment', ['item' => $item]) {{ number_format($item->rent_amount, 2) }}
{{ $item->payment_type }}
@if ($billable > 0) {{ number_format($billable, 2) }} @if ($item->payment_type !== 'one-time') {{-- A monthly rent's first / last month is charged by days, so it shows a month count. --}}
{{ $item->elapsed_periods }}{{ $item->payment_type === 'monthly' ? ' month(s)' : ' ×' }} (till {{ $item->current_period_label }}) @endif @else — @endif
@if ($totalPaid > 0) {{ number_format($totalPaid, 2) }} @else — @endif @if ($remaining > 0) {{ number_format($remaining, 2) }} @elseif ($billable > 0) Paid @else {{-- Nothing billed yet (rejected, or start date not reached) — "Paid" would be misleading. --}} — @endif {{-- Edit stays available after approval: it is how a running rent gets its End Date set to stop the recurring charge. Touching an approved record needs the extra *-approved permission. --}} @php $isApproved = $item->status === 'approved'; $canEditRow = auth()->user()->can('core-rent-edit') && (!$isApproved || auth()->user()->can('core-rent-edit-approved')); $canDeleteRow = auth()->user()->can('core-rent-delete') && (!$isApproved || auth()->user()->can('core-rent-delete-approved')); @endphp @if ($canEditRow) Edit @endif @if ($canDeleteRow)
@csrf @method('DELETE')
@endif @can('core-rent-approve') @include('partials.approval-decision-buttons', [ 'item' => $item, 'url' => route('core-rent.approve', $item->id), 'label' => 'Core Rent', ]) @endcan @if ($item->status === 'approved') @can('core-rent-payment') @if ($totalPaid > 0) @endif @endcan @endif @can('core-rent-history') History @endcan
@can('core-rent-payment') {{-- Pay Modal --}} {{-- Payment History Modal --}} @endcan
@endsection @section('ajax') @endsection @include('partials.finance-sticky-table') @include('partials.approve-comment-modal')