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

Real IP Bill Management

@can('real-ip-bill-history') Edit & Delete Log @endcan @can('real-ip-bill-create') Add Real IP Bill @endcan
@if (request('reseller_id') || request('pop_id') || request('status')) Clear @endif
@php // "Billed" grows on its own: amount × months elapsed since the billing month. $grandPerMonth = (float) $bills->sum('amount'); $grandAmount = (float) $bills->sum('total_billable'); $grandPaid = (float) $bills->sum('payments_sum_amount'); // Sum each bill's own clamped remaining so an overpaid bill can't cancel real dues on others. $grandRemaining = (float) $bills->sum('remaining_due'); @endphp {{-- The Total row lives in , above the rows: DataTables never sorts or paginates a header row, and it pins under the sticky header. --}} @foreach ($bills as $item) @php $totalPaid = (float) ($item->payments_sum_amount ?? 0); $billable = $item->total_billable; $remaining = $item->remaining_due; @endphp @endforeach
# Manager POP IP Address Start Date Status Per Month (৳) Billed Till Now (৳) Paid (৳) Due (৳) Action
Total {{ number_format($grandPerMonth, 2) }} {{ number_format($grandAmount, 2) }} {{ number_format($grandPaid, 2) }} {{ number_format($grandRemaining, 2) }}
{{ $item->id }} {{ $item->reseller->name_with_type ?? '—' }} {{ $item->pop->popname ?? '—' }} {{ $item->ip_address }} {{ $item->billing_month ? $item->billing_month->format('d M Y') : '—' }} @if ($item->end_month)
{{ $item->is_stopped ? 'Stopped after' : 'Ends' }} {{ $item->end_month->format('d M Y') }} @else
Recurring @endif @if ($item->description)
{{ $item->description }} @endif
Added by: {{ $item->createdBy->name ?? '—' }}
@include('partials.approval-status', ['item' => $item]) @if ($item->status === 'approved') {{-- Only a stopped bill is truly finished; a running one charges again next month. --}} @if ($billable > 0 && $remaining <= 0) {{ $item->is_stopped ? 'Fully Paid' : 'Up to date' }} @endif @endif @include('partials.approval-comment', ['item' => $item]) {{ number_format($item->amount, 2) }} @if ($billable > 0) {{ number_format($billable, 2) }} {{-- First / last month are charged by days, so this is a month count, not a multiplier. --}}
{{ $item->elapsed_periods }} month(s) (till {{ $item->current_period_label }}) @else — @endif
@if ($totalPaid > 0) {{ number_format($totalPaid, 2) }} @else — @endif @if ($remaining > 0) {{ number_format($remaining, 2) }} @elseif ($billable > 0) Paid @else — @endif {{-- Edit stays available after approval: it is how a running bill gets its End Date set to stop the monthly charge. Touching an approved record needs the extra *-approved permission. --}} @php $isApproved = $item->status === 'approved'; $canEditRow = auth()->user()->can('real-ip-bill-edit') && (!$isApproved || auth()->user()->can('real-ip-bill-edit-approved')); $canDeleteRow = auth()->user()->can('real-ip-bill-delete') && (!$isApproved || auth()->user()->can('real-ip-bill-delete-approved')); @endphp @if ($canEditRow) Edit @endif @can('real-ip-bill-approve') @include('partials.approval-decision-buttons', [ 'item' => $item, 'url' => route('real-ip-bill.approve', $item->id), 'label' => 'Real IP Bill', ]) @endcan @if ($canDeleteRow)
@csrf @method('DELETE')
@endif @if ($item->status === 'approved') @can('real-ip-bill-payment') @if ($remaining > 0) @endif @if ($totalPaid > 0) @endif @endcan @endif @can('real-ip-bill-history') History @endcan
{{-- Pay Modal --}} @can('real-ip-bill-payment') {{-- Payment History Modal --}} @endcan
@endsection @section('ajax') @endsection @include('partials.finance-sticky-table') @include('partials.approve-comment-modal')