@extends('garage.layouts.app') @section('title', 'Sale '.$sale->sale_number) @section('content')
@php $partsSub = 0.0; $servicesSub = 0.0; $tax = 0.0; foreach (($items ?? []) as $it) { $qty = (float) ($it->quantity ?? 0); $unit = (float) ($it->unit_price ?? 0); $gross = $qty * $unit; $disc = (float) ($it->discount_amount ?? 0); // already applied PKR on item $net = max(0, $gross - $disc); $partsSub += $net; $tax += (float) ($it->tax_amount ?? 0); } foreach (($services ?? []) as $s) { $lt = (float) ($s->line_total ?? 0); if ($lt <= 0) $lt = (float) ($s->hours ?? 0) * (float) ($s->rate ?? 0); $servicesSub += $lt; } $subBefore = $partsSub + $servicesSub; $after = (float) ($sale->grand_total ?? 0) - (float) ($sale->tax_amount ?? 0) - (float) ($sale->freight_amount ?? 0); if ($after < 0) $after = (float) ($sale->subtotal ?? 0); $discApplied = max(0, $subBefore - $after); @endphp

{{ $sale->sale_number }}

{{ $sale->sale_date }} · {{ $sale->status }}

All sales @if(!empty($canReturn)) Record return @endif @if(!empty($sale->journal_voucher_id) || !empty($sale->receipt_voucher_id)) @endif @if(in_array($sale->status, ['draft','held'])) Edit @endif
@csrf @method('DELETE')
@php $salePaySummary = app(\App\Services\GarageRepairOrderSaleInvoiceService::class)->salePaymentSummary($sale); @endphp @if(($sale->sale_kind ?? null) === 'customer_sale' && !($salePaySummary['is_fully_settled'] ?? false)) @if(in_array(($sale->status ?? null), ['held','completed'], true)) @else @endif @elseif(($sale->payment_status ?? 'unpaid') === 'paid' && !empty($sale->receipt_voucher_id)) Gate pass @endif
@if(session('success'))
{{ session('success') }}
@endif
Customer
{{ $sale->customer_name ?? 'Walk-in / cash' }} @if(!empty($sale->customer_ledger_id)) Ledger statement @endif
Vehicle
@if(!empty($sale->vehicle_registration)) {{ $sale->vehicle_registration }} @if(!empty($subLedger) && !empty($subLedger->id)) @endif @if($sale->vehicle_make || $sale->vehicle_model || $sale->vehicle_year)
{{ trim(($sale->vehicle_make ?? '').' '.($sale->vehicle_model ?? '').' '.($sale->vehicle_year ?? '')) }}
@endif @else — @endif
Served by
{{ $sale->served_by_name ?? '—' }}
Sale kind
{{ str_replace('_', ' ', $sale->sale_kind) }}
@if(!empty($hasDocumentServices))
Current reading
@if(!empty($sale->meter_reading)) {{ \App\Support\GarageMeterReading::format($sale->meter_reading) }} km @else — @endif
Next reading
@if(!empty($sale->next_meter_reading)) {{ \App\Support\GarageMeterReading::format($sale->next_meter_reading) }} km @else — @endif
Next service date
@if(!empty($sale->next_service_date)) {{ \Carbon\Carbon::parse($sale->next_service_date)->format('d M Y') }} @else — @endif
@endif @if($sale->comments)
Comments
{{ $sale->comments }}
@endif
@include('garage.partials.vehicle-mileage-history', [ 'mileageTimeline' => $mileageTimeline ?? collect(), 'vehicleOdometer' => $vehicleOdometer ?? null, ])

Lines

@foreach($items as $row) @endforeach
Code Product Qty Price Tax Line total
{{ $row->inventory_code_snapshot ?? '—' }} {{ $row->product_name ?? $row->description ?? '—' }} {{ $row->quantity }} PKR {{ number_format((float) $row->unit_price, 2) }} PKR {{ number_format((float) $row->tax_amount, 2) }} PKR {{ number_format((float) $row->line_total, 2) }}
@if(!empty($services) && count($services))

Services

@foreach($services as $s) @php $svcLine = (float) ($s->line_total ?? 0); if ($svcLine <= 0) $svcLine = (float) ($s->hours ?? 0) * (float) ($s->rate ?? 0); @endphp @endforeach
Service Qty Rate Total
{{ $s->service_name ?? $s->title ?? 'Service' }} {{ number_format((float) ($s->hours ?? 0), 0) }} PKR {{ number_format((float) ($s->rate ?? 0), 2) }} PKR {{ number_format((float) $svcLine, 2) }}
@endif
@php $roAdvance = (float) ($sale->repair_order_advance_amount ?? 0); if ($roAdvance <= 0 && !empty($sale->garage_repair_order_id) && \Illuminate\Support\Facades\Schema::hasColumn('garage_repair_orders', 'advance_amount')) { $roAdvance = (float) (\Illuminate\Support\Facades\DB::table('garage_repair_orders')->where('id', (int) $sale->garage_repair_order_id)->value('advance_amount') ?? 0); } $paidOnSaleShow = (float) ($sale->amount_paid ?? 0); $roBalance = max(0, (float) $sale->grand_total - $roAdvance - $paidOnSaleShow); @endphp @if($roAdvance > 0) @endif @if($paidOnSaleShow > 0) @endif @if($roAdvance > 0 || $paidOnSaleShow > 0) @endif
Parts totalPKR {{ number_format((float) $partsSub, 2) }}
Services totalPKR {{ number_format((float) $servicesSub, 2) }}
SubtotalPKR {{ number_format((float) $subBefore, 2) }}
Discount (applied)PKR {{ number_format((float) $discApplied, 2) }}
After discountPKR {{ number_format((float) $after, 2) }}
TaxPKR {{ number_format((float) ($sale->tax_amount ?? $tax), 2) }}
FreightPKR {{ number_format((float) $sale->freight_amount, 2) }}
Order advance (receipt)PKR {{ number_format($roAdvance, 2) }}
Paid on sale (receipts)PKR {{ number_format($paidOnSaleShow, 2) }}
Balance duePKR {{ number_format($roBalance, 2) }}
TotalPKR {{ number_format((float) $sale->grand_total, 2) }}
@if(!empty($saleReturns) && $saleReturns->count())
Sale returns
@foreach($saleReturns as $sr) @endforeach
Return #DateAmount
{{ $sr->return_number }} {{ $sr->return_date }} {{ number_format($sr->total_amount, 2) }} View
@endif @push('styles') @endpush
@endsection @push('scripts') @endpush