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

Product Installment Management

All Payments Excel @can('product-installment-history') Edit & Delete Log @endcan @can('product-installment-create') Add Product @endcan
@if ($errors->any())
The product installment was not saved:
    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
@if (request('manager_id') || request('pop_id') || request('status') || request('product_name')) Clear @endif
@php $grandTotal = (float) $installments->sum('total_amount'); $grandSpeed = (float) $installments->sum('speed_money'); $grandPerInstall = (float) $installments->sum('one_installment_amount'); $grandPaid = (float) $installments->sum('payments_sum_amount'); $grandPaidShown = $grandSpeed + $grandPaid; // paid incl. upfront speed money $grandRemaining = max(0, $grandTotal - $grandPaidShown); // Quantity given per product across the listed (filtered) installments. $grandProducts = $installments->pluck('items')->flatten() ->groupBy(fn ($line) => trim($line->product_name)) ->map(fn ($lines) => $lines->sum('quantity')) ->sortKeys(); @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 ($installments as $item) @php $totalPaid = (float) ($item->payments_sum_amount ?? 0); // Speed money is an upfront payment, so include it in the shown Paid amount. $paidShown = (float) $item->speed_money + $totalPaid; $remaining = max(0, (float) $item->total_amount - $paidShown); @endphp @endforeach
# Manager POP Product Status Installments Total (৳) Speed Money Per Install (৳) Paid (৳) Remaining (৳) Action
Total {{-- Folds to one line while the table is scrolled (the row is sticky, so a long list would cover the rows); opens again at the top or on click. --}} @if ($grandProducts->isNotEmpty()) {{ $grandProducts->count() }} products · {{ $grandProducts->sum() }} qty
@foreach ($grandProducts as $productName => $quantity)
{{ $loop->iteration }}. {{ $productName }} = {{ $quantity }}
@endforeach
@endif
{{ number_format($grandTotal, 2) }} {{ number_format($grandSpeed, 2) }} {{ number_format($grandPerInstall, 2) }} {{ number_format($grandPaidShown, 2) }} {{ number_format($grandRemaining, 2) }}
{{ $item->id }} {{ $item->manager->name_with_type ?? '—' }}
Added by: {{ $item->createdBy->name ?? '—' }}
{{ $item->pop->popname ?? '—' }} {{-- Just what was given: one numbered "Product = Qty" line per product. --}} @forelse ($item->items as $line)
{{ $loop->iteration }}. {{ $line->product_name }} = {{ $line->quantity }}
@empty {{-- Entries from before product lines existed only carry a name. --}} {{ $item->product_name }} @endforelse @if ($item->requisition_id) Requisition ID: {{ $item->requisition_id }} @endif
@include('partials.approval-status', ['item' => $item]) @if ($item->status === 'approved') @if ($totalPaid > 0 && $remaining <= 0) Fully Paid @endif @endif @include('partials.approval-comment', ['item' => $item]) {{ $item->installment_count }} times @if ($item->start_month)
From {{ $item->start_month->format('M Y') }} @endif
{{ number_format($item->total_amount, 2) }} @if ($item->speed_money > 0) {{ number_format($item->speed_money, 2) }} @else — @endif {{ number_format($item->one_installment_amount, 2) }} @if ($paidShown > 0) {{ number_format($paidShown, 2) }} @else — @endif @if ($remaining > 0) {{ number_format($remaining, 2) }} @else Paid @endif {{-- An approved installment stays editable/deletable, but only for a user who also holds the *-approved permission. --}} @php $isApproved = $item->status === 'approved'; $canEditRow = auth()->user()->can('product-installment-edit') && (!$isApproved || auth()->user()->can('product-installment-edit-approved')); $canDeleteRow = auth()->user()->can('product-installment-delete') && (!$isApproved || auth()->user()->can('product-installment-delete-approved')); @endphp @if ($canEditRow) Edit @endif @can('product-installment-approve') @include('partials.approval-decision-buttons', [ 'item' => $item, 'url' => route('product-installment.approve', $item->id), 'label' => 'product installment', ]) @endcan @if ($canDeleteRow)
@csrf @method('DELETE')
@endif @if ($item->status === 'approved') @can('product-installment-payment') @if ($remaining > 0) @endif @if ($totalPaid > 0) @endif @endcan @endif @can('product-installment-history') History @endcan
{{-- Pay Modal --}} @can('product-installment-payment') {{-- Payment History Modal --}} @endcan {{-- Installment Schedule Modal --}}
@endsection @section('ajax') @endsection @include('partials.finance-sticky-table') @include('partials.approve-comment-modal')