@extends('layouts.app') @section('title','Purchase History') @section('content') @php($uae=fn($t)=>\Illuminate\Support\Carbon::parse($t,'UTC')->setTimezone('Asia/Dubai')->format('d M Y')) @php($keep=fn(array $extra)=>route('sales.history.index',array_filter(array_merge(request()->only(['q','customer_q','from','to','include_void']),$extra),fn($v)=>$v!==null&&$v!=='')))
Sales / Purchase History

Purchase History

{{ $company->name }} โ€” what each customer bought and who bought each product, from posted invoice and return lines

@if($errors->any())@endif
@if(!empty($filters['customer_id']))Customer: {{ $customer ? $customer->name.' ('.$customer->code.')' : 'no visible purchases' }}Clear customer@endif @if(!empty($filters['product_id']))Product: {{ $product ? $product->sku.' ยท '.$product->name : 'no visible sales' }}Clear product@endif
@if(!empty($filters['customer_id']))@endif @if(!empty($filters['product_id']))@endif
Reset
Dates are invoice dates (UAE) and return receipt dates. Amounts are invoice values including VAT, not cash collected.
@forelse($totals as $currency=>$t)
{{ number_format((float)$t['sales'],2) }}
{{ number_format((float)$t['returns'],2) }}
{{ number_format((float)$t['net'],2) }}
{{ \App\Support\StockQuantity::display($t['net_quantity']) }}
@empty
No purchases match these filters within your access.
@endforelse @if($by && $summary->count())

{{ $by==='product'?'Products bought by this customer':'Customers who bought this product' }}

Open a row to see its invoices.
@foreach($summary as $row)@endforeach
{{ $by==='product'?'Product':'Customer' }}Net qtyNet amountLast purchaseInvoice lines
@if($by==='product'){{ $row->sku }}
{{ $row->name }}@else{{ $row->customer_name }}
{{ $row->customer_code }}@endif
{{ \App\Support\StockQuantity::display(number_format((float)$row->quantity,4,'.','')) }}{{ $row->currency }} {{ number_format((float)$row->total,2) }}{{ $row->last_purchase_at ? $uae($row->last_purchase_at) : 'โ€”' }}{{ $row->invoice_lines }}
@endif

Invoice and return lines

{{ $lines->total() }} line(s)
@forelse($lines as $line) @empty@endforelse
DateDocumentCustomerProductQtyUnit priceDiscountNetVATTotal
{{ $uae($line->document_at) }} @if($line->kind==='invoice')Invoice {{ $line->document_number }}@if($line->status==='void') Void@endif @elseReturn {{ $line->document_number }}@endif {{ $line->customer_name }}
{{ $line->customer_code }}
{{ $line->sku_snapshot }}
{{ $line->name_snapshot }}
{{ \App\Support\StockQuantity::display(number_format((float)$line->quantity,4,'.','')) }}{{ number_format((float)$line->gross_unit_price,4) }}{{ $line->discount_amount===null?'โ€”':number_format((float)$line->discount_amount,2) }} {{ number_format((float)$line->taxable_amount,2) }}{{ number_format((float)$line->vat_amount,2) }}{{ $line->currency }} {{ number_format((float)$line->line_total,2) }}
No lines.
{{ $lines->links() }}
@endsection