@extends('layouts.app') @section('title', 'Sale ' . $sale->invoice_no) @section('content') @php $qty = fn ($v) => rtrim(rtrim(number_format((float) $v, 2), '0'), '.'); $method = fn ($key) => $methodNames[$key] ?? ucwords(str_replace('_', ' ', (string) $key)); $paid = (float) ($sale->total_paid ?: $sale->payments->sum('amount')); $change = max(0, $paid - (float) $sale->total_amount); $status = strtolower((string) $sale->payment_status); $cashier = $sale->user?->name ?? $sale->register?->user?->name; @endphp
Back to Sales
@if(auth()->user()->hasPermission('edit_pos_sell')) Edit Sale @endif @if(auth()->user()->hasPermission('delete_pos_sell')) @endif
@if($letterhead['logo']) @else
{{ $letterhead['initials'] }}
@endif
{{ $letterhead['name'] }}
{{ collect([$letterhead['address'], $letterhead['phone'] ? 'Tel: ' . $letterhead['phone'] : null, $letterhead['email']])->filter()->implode(' · ') }} @if($letterhead['tax_number'])
TPIN: {{ $letterhead['tax_number'] }}@endif
Invoice
#{{ $sale->invoice_no }}
{{ ucfirst($status ?: 'unknown') }} @if($sale->is_edited) Edited @endif @if($sale->hasDiscount()) Discounted @endif
Billed to
{{ $sale->customer_name ?: 'Walk-in customer' }}
@if($sale->contact_number)
{{ $sale->contact_number }}
@endif
Date
{{ $sale->created_at->format('d M Y') }}
{{ $sale->created_at->format('H:i') }}
Served by
{{ $cashier ?? '-' }}
Payment
@if($sale->payment_method === 'split' && $sale->payments->isNotEmpty())
Split
@foreach($sale->payments as $payment)
{{ $method($payment->method) }}: {{ formatCurrency($payment->amount) }}
@endforeach @else
{{ $method($sale->payment_method) }}
@endif
@foreach($sale->items as $item) @php $itemBatches = $sale->batches->where('product_id', $item->product_id); @endphp @endforeach
# Product Qty Unit price Amount
{{ $loop->iteration }}
{{ $item->product?->name ?? 'Deleted product' }}
@if($item->product?->sku)SKU {{ $item->product->sku }}@endif @if($itemBatches->isNotEmpty()) Batch {{ \App\Services\BatchStock::describe($itemBatches) }} @endif
{{ $qty($item->quantity) }} {{ formatCurrency($item->price) }} {{ formatCurrency($item->subtotal) }}
Items{{ $qty($sale->items->sum('quantity')) }}
@if($sale->hasDiscount())
Items total{{ formatCurrency($sale->grossAmount()) }}
Discount{{ $sale->discount_percent ? ' (' . rtrim(rtrim(number_format($sale->discount_percent, 2), '0'), '.') . '%)' : '' }} - {{ formatCurrency($sale->discount_amount) }}
Reason: {{ $sale->discount_reason }}
@endif
Total{{ formatCurrency($sale->total_amount) }}
Paid{{ formatCurrency($paid) }}
@if($change > 0.004)
Change given{{ formatCurrency($change) }}
@endif @if((float) $sale->sell_due > 0)
Balance due{{ formatCurrency($sale->sell_due) }}
@endif
@if(setting('receipt_footer'))
{{ setting('receipt_footer') }}
@endif
@if($sale->is_edited && $sale->edit_log) @php $editLog = is_string($sale->edit_log) ? json_decode($sale->edit_log, true) : $sale->edit_log; $paymentText = function ($methodKey, $payments) use ($method) { if ($methodKey === 'split' && !empty($payments)) { return collect($payments)->map(fn ($p) => $method($p['method']) . ': ' . formatCurrency($p['amount']))->implode(', '); } return $method($methodKey); }; @endphp
Changes to this sale
Last edited {{ $sale->edited_at?->format('d M Y, H:i') }}
Original sale
Total{{ formatCurrency($editLog['original_total'] ?? 0) }}
Payment{{ $paymentText($editLog['original_payment_method'] ?? null, $editLog['original_payments'] ?? []) }}
Products{{ count($editLog['original_items'] ?? []) }}
After the change
Total{{ formatCurrency($editLog['new_total'] ?? 0) }}
Payment{{ $paymentText($editLog['new_payment_method'] ?? null, $editLog['new_payments'] ?? []) }}
Products{{ count($editLog['new_items'] ?? []) }}
@if(($editLog['total_change'] ?? 0) != 0)
The total was {{ $editLog['total_change'] > 0 ? 'increased' : 'reduced' }} by {{ formatCurrency(abs($editLog['total_change'])) }}.
@endif @if(isset($editLog['original_items'], $editLog['new_items'])) @php $originalItems = collect($editLog['original_items'])->keyBy('product_id'); $newItems = collect($editLog['new_items'])->keyBy('product_id'); $allProducts = $originalItems->keys()->merge($newItems->keys())->unique(); @endphp
Products changed
@foreach($allProducts as $productId) @php $original = $originalItems->get($productId); $new = $newItems->get($productId); $originalQty = $original['quantity'] ?? $original['original_quantity'] ?? 0; $newQty = $new['quantity'] ?? $new['new_quantity'] ?? 0; $originalPrice = $original['price'] ?? $original['original_price'] ?? 0; $newPrice = $new['price'] ?? $new['new_price'] ?? 0; $changed = $originalQty != $newQty || $originalPrice != $newPrice; @endphp @endforeach
Product Was Now Price was Price now
{{ $original['product_name'] ?? $new['product_name'] ?? 'Unknown' }} {{ $qty($originalQty) }} {{ $qty($newQty) }} {{ formatCurrency($originalPrice) }} {{ formatCurrency($newPrice) }}
@endif @if(!empty($editLog['history']))
Who changed it
@foreach(array_reverse($editLog['history']) as $h)
{{ $h['by'] ?? 'Unknown' }} {{ \Carbon\Carbon::parse($h['at'])->format('d M Y, H:i') }}{{ !empty($h['via']) ? ' · ' . $h['via'] : '' }}
{{ formatCurrency($h['from_total'] ?? 0) }} → {{ formatCurrency($h['to_total'] ?? 0) }}
@if(!empty($h['reason']))
{{ $h['reason'] }}
@endif
@endforeach
@endif
@endif @if(config('brand.full'))

Powered by {{ config('brand.full') }}

@endif
@endsection