@extends('garage.layouts.app') @section('title', $glOrders ?? 'Orders') @section('content')

{{ $glOrders ?? 'Orders' }}

Work-in-progress repairs before final invoice

New {{ strtolower($glOrder ?? 'order') }}
@forelse($repairOrders as $r) @php $subCalc = (float) ($r->subtotal_calc ?? 0); $subBeforeStored = isset($r->subtotal_before_discount) ? (float) ($r->subtotal_before_discount ?? 0) : 0.0; // Prefer calculated subtotal (parts + services). Stored values may be legacy/partial. $subBefore = max($subCalc, $subBeforeStored); // After discount: prefer DB column; else derive from grand_total - tax - freight. $afterSub = (float) ($r->subtotal_after_discount ?? $r->subtotal ?? 0); $afterFromGrand = (float) ($r->grand_total ?? 0) - (float) ($r->tax_amount ?? 0) - (float) ($r->freight_amount ?? 0); if ($afterFromGrand >= 0) $afterSub = $afterFromGrand; $discType = (string) ($r->discount_type ?? 'fixed'); $discInput = (float) ($r->discount_amount ?? 0); $discApplied = isset($r->discount_applied_amount) ? (float) ($r->discount_applied_amount ?? 0) : ($discType === 'percentage' ? max(0, min($subBefore, $subBefore * ($discInput / 100))) : max(0, min($subBefore, $discInput))); // If stored applied discount is legacy/partial, bump it up to the calculated value. if ($discType === 'percentage' && $discInput > 0) { $discApplied = max($discApplied, max(0, min($subBefore, $subBefore * ($discInput / 100)))); } // If grand_total suggests a full discount and percent wasn't stored correctly, treat as 100%. $pctDisplay = $discInput; if ($discType === 'percentage' && $pctDisplay <= 0 && $subBefore > 0 && $afterSub == 0) { $pctDisplay = 100; $discApplied = $subBefore; } @endphp @include('garage.partials.index-meter-reading-cell', ['meter' => $r->meter_reading ?? null]) @empty @endforelse
{{ $glOrderNum ?? 'Order #' }} Date Customer Lead Vehicle Meter (km) Subtotal Discount After discount Grand total Status Actions
{{ $r->repair_order_number }} {{ $r->repair_order_date }} @if(!empty($r->customer_ledger_id)) {{ $r->customer_name ?? '—' }} @else {{ $r->customer_name ?? '—' }} @endif {{ $r->lead_employee_name ?? '—' }} @if(!empty($r->vehicle_registration)) {{ $r->vehicle_registration }} @if($r->vehicle_make || $r->vehicle_model) ({{ trim(($r->vehicle_make ?? '').' '.($r->vehicle_model ?? '')) }}) @endif @else — @endif PKR {{ number_format((float) $subBefore, 2) }} @if(($r->discount_type ?? 'fixed') === 'percentage') {{ number_format((float) $pctDisplay, 2) }}% @else PKR {{ number_format((float) ($r->discount_amount ?? 0), 2) }} @endif
PKR {{ number_format((float) $discApplied, 2) }}
PKR {{ number_format((float) $afterSub, 2) }} PKR {{ number_format((float) $r->grand_total, 2) }} {{ str_replace('_',' ', $r->status) }} View @if((int) ($r->active_voucher_count ?? 0) > 0 || (float) ($r->advance_amount ?? 0) > 0) Vouchers @endif Edit @php $hasServices = ((float) ($r->services_sub ?? 0)) > 0; $workOrderId = (int) ($r->work_order_id ?? 0); $jobCardCompleted = $workOrderId > 0 && (string) ($r->work_order_status ?? '') === 'completed'; @endphp @if($hasServices) @if($workOrderId > 0) Job card @else Create job card @endif @if(!empty($r->garage_sale_id)) Invoice @elseif($jobCardCompleted) Make invoice @endif @else @if(!empty($r->garage_sale_id)) Invoice @else Make invoice @endif @endif
No {{ strtolower($glOrders ?? 'orders') }} yet.
@if($repairOrders->hasPages())
{{ $repairOrders->links() }}
@endif
@endsection