@extends('layouts.app') @section('title', 'Sale Details') @section('content')
Back to Sales

Invoice #{{ $sale->invoice_no }}

@if($sale->is_edited) Edited @endif
Edit Sale
Customer Information

{{ $sale->customer_name ?: 'Walk-in Customer' }}

Transaction Date

{{ $sale->created_at->format('d M, Y') }} {{ $sale->created_at->format('H:i') }}

Payment Details
Status {{ ucfirst($sale->payment_status) }}
Method @if($sale->payment_method === 'split') @if($sale->payments && $sale->payments->count() > 0) @foreach($sale->payments as $payment) {{ ucfirst($payment->method) }}: MWK {{ number_format($payment->amount, 2) }} @endforeach @else Split Payment @endif @else {{ ucfirst(str_replace('_', ' ', $sale->payment_method)) }} @endif
Total Amount

MWK {{ number_format($sale->total_amount, 2) }}

@foreach($sale->items as $item) @endforeach
Product Qty Unit Price Subtotal
{{ $item->product?->name ?? 'Deleted Product' }}
@if(isset($item->product->sku)) SKU: {{ $item->product->sku }} @endif
{{ $item->quantity }} MWK {{ number_format($item->price, 2) }} MWK {{ number_format($item->subtotal, 2) }}
Total MWK {{ number_format($sale->total_amount, 2) }}
@if($sale->is_edited && $sale->edit_log) @php $editLog = is_string($sale->edit_log) ? json_decode($sale->edit_log, true) : $sale->edit_log; @endphp
Modification History
Edited on {{ $sale->edited_at->format('d M, Y H:i') }}
Original Record
Total Amount: MWK {{ number_format($editLog['original_total'], 2) }}
Payment Method: @if($editLog['original_payment_method'] === 'split' && isset($editLog['original_payments']) && count($editLog['original_payments']) > 0) @foreach($editLog['original_payments'] as $payment) {{ ucfirst($payment['method']) }}: MWK {{ number_format($payment['amount'], 2) }} @endforeach @else {{ ucfirst($editLog['original_payment_method']) }} @endif
Items Count: {{ count($editLog['original_items']) }}
Updated Record
New Total: MWK {{ number_format($editLog['new_total'], 2) }}
Payment Method: @if($editLog['new_payment_method'] === 'split' && isset($editLog['new_payments']) && count($editLog['new_payments']) > 0) @foreach($editLog['new_payments'] as $payment) {{ ucfirst($payment['method']) }}: MWK {{ number_format($payment['amount'], 2) }} @endforeach @else {{ ucfirst($editLog['new_payment_method']) }} @endif
Items Count: {{ count($editLog['new_items']) }}
@if($editLog['total_change'] != 0) @endif @if(isset($editLog['original_items']) && isset($editLog['new_items']))
Detailed Item Changes
@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 @foreach($allProducts as $productId) @php $original = $originalItems->get($productId); $new = $newItems->get($productId); $productName = $original['product_name'] ?? $new['product_name'] ?? 'Unknown'; // Handle different possible key names in the log structure $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; $hasChange = $originalQty != $newQty || $originalPrice != $newPrice; @endphp @endforeach
Product Orig. Qty New Qty Orig. Price New Price
{{ $productName }} {{ $originalQty }} {{ $newQty }} MWK {{ number_format($originalPrice, 2) }} MWK {{ number_format($newPrice, 2) }}
@endif
@endif

Generated by EDUC PHARMACY POS

@endsection