@extends('layouts.app') @section('content')
@if(session('success')) @endif @if(session('error')) @endif
Store & Date
Invoice & Customer
Type & User
Status
@php $row_count = 0; $total_amount = 0; $total_cash = 0; $total_card = 0; $total_credit = 0; $pay_type_filter = $filters['pay_type'] ?? 'all'; $status_filter = $filters['status_filter'] ?? 'all'; @endphp @foreach($invoices as $invoice) @php $bill_amount = (float) ($invoice->total ?? 0); $bill_discount = (float) ($invoice->discount ?? 0); // Some rows store total net already; keep both variants as fallback $netA = $bill_amount; $netB = max($bill_amount - $bill_discount, 0); $net_amount = max($netA, $netB); $pay_cash = (float) ($invoice->paid_cash ?? 0); $pay_card = (float) ($invoice->paid_pos ?? 0); // IMPORTANT: in this POS flow `paid_credit` is the outstanding (unpaid) portion (due), not a paid amount. $outstanding_due = (float) ($invoice->paid_credit ?? 0); $paid_now = $pay_cash + $pay_card; // Derived due fallback for legacy/migrated rows $derived_due_a = max($netA - $paid_now, 0); $derived_due_b = max($netB - $paid_now, 0); $current_due = max($outstanding_due, $derived_due_a, $derived_due_b); // Sum of later customer-balance allocations applied to this invoice $applied_later = (float) ($creditAppliedByInvoice[$invoice->id] ?? 0); // Infer the pre-payment (previous) picture for the status transition display. $previous_paid = max($paid_now - $applied_later, 0); $previous_due = max($current_due + $applied_later, max($net_amount - $previous_paid, 0)); // Determine payment type if ($pay_cash > 0 && $pay_card > 0) { $pay_type_row = 'mixed'; } elseif ($pay_cash > 0) { $pay_type_row = 'cash'; } elseif ($pay_card > 0) { $pay_type_row = 'card'; } else { $pay_type_row = 'none'; } // Skip if doesn't match payment type filter if ($pay_type_filter != 'all' && $pay_type_row != $pay_type_filter) { continue; } // Determine CURRENT status if ($current_due <= 0.0001) { $status = 'paid'; } elseif ($paid_now > 0.0001) { $status = 'partial'; } else { $status = 'due'; } // Determine PREVIOUS status (for later payment transitions) if ($previous_due <= 0.0001) { $previous_status = 'paid'; } elseif ($previous_paid > 0.0001) { $previous_status = 'partial'; } else { $previous_status = 'due'; } // Skip if doesn't match status filter if ($status_filter != 'all' && $status_filter != $status) { continue; } $row_count++; $total_amount += $net_amount; $total_cash += $pay_cash; $total_card += $pay_card; $total_credit += max(0, $current_due); @endphp @endforeach
#   Bill ID Bill Amount Cash Card Status User Customer Sale Time
{{ $row_count }} @php $returnCount = $invoice->returns->count(); $returnTotal = $invoice->returns->reduce(function($carry, $ret){ return $carry + ((float) ($ret->qty ?? 0) * (float) ($ret->price ?? 0)); }, 0); @endphp {{ $invoice->invoice_number }}
{{ $invoice->location->name ?? 'N/A' }} @if($returnCount > 0)
Return: -{{ number_format($returnTotal,2) }}
@endif
{{ number_format($net_amount, 2) }} {{ number_format(min($net_amount, $pay_cash), 2) }} {{ number_format(min($net_amount - min($net_amount, $pay_cash), $pay_card), 2) }} @php $showTransition = ($applied_later > 0.0001) && (isset($previous_status)) && ($previous_status !== $status); @endphp @if($showTransition) {{ ucfirst($previous_status) }} » @endif @if($status == 'paid') Paid @elseif($status == 'partial') Partial @elseif($status == 'due') Due @endif @if($returnCount > 0) @endif {{ $invoice->user->name ?? 'N/A' }} @if($invoice->customer) {{ $invoice->customer->name }} @elseif(empty($invoice->customer_id)) Walk-in Customer @else Unknown @endif {{ $invoice->posted_at ? $invoice->posted_at->format('Y-m-d h:i A') : 'N/A' }}
Total Amount {{ number_format($total_amount, 2) }} - - {{ number_format($total_credit, 2) }}
@endsection