@extends('admin.layouts.app')
@section('title', 'Invoice ' . $invoiceNo)
@section('content')
<div class="page-head">
    <div>
        <h1 class="page-title">{{ $meta->document_type ?? 'Invoice' }} {{ $invoiceNo }}</h1>
        <div class="page-subtitle">Customer: {{ $summary->customer_name ?: 'Walk-in Customer' }} · Date: {{ $summary->sale_date }} · Status: {{ $meta->sale_status ?? 'Completed' }}</div>
    </div>
    <div class="d-flex gap-2 flex-wrap">
        <a href="{{ route('admin.sales.edit', $invoiceNo) }}" class="btn btn-outline-primary">Edit</a>
        <a target="_blank" href="https://wa.me/{{ preg_replace('/\D+/','',$summary->customer_phone ?? '') }}?text={{ urlencode('Invoice '.$invoiceNo.' amount '.number_format((float)$summary->invoice_grand_total,2)) }}" class="btn btn-outline-success">WhatsApp Share</a>
        <a href="{{ route('admin.sales.index') }}" class="btn btn-light">Back</a>
    </div>
</div>
<div class="stat-grid">
    <div class="stat-card"><div class="label">Grand Total</div><div class="value">{{ number_format((float)$summary->invoice_grand_total,2) }}</div></div>
    <div class="stat-card"><div class="label">Paid</div><div class="value">{{ number_format((float)$summary->paid_amount,2) }}</div></div>
    <div class="stat-card"><div class="label">Due</div><div class="value">{{ number_format((float)$summary->due_amount,2) }}</div></div>
    <div class="stat-card"><div class="label">Payment Method</div><div class="value" style="font-size:20px">{{ $summary->payment_method ?: 'Cash' }}</div></div>
</div>
<div class="row g-3">
<div class="col-lg-8"><div class="card"><div class="table-wrap"><table class="table table-bordered"><thead><tr><th>Product</th><th>Code</th><th>Variant</th><th>Qty</th><th>Price</th><th>Discount</th><th>Total</th></tr></thead><tbody>@foreach($sales as $item)<tr><td>{{ $item->product_name }}</td><td>{{ $item->product_code }}</td><td>{{ $item->variant_label ?: '—' }}</td><td>{{ $item->quantity_sold }}</td><td>{{ number_format((float)$item->selling_price,2) }}</td><td>{{ number_format((float)$item->discount,2) }}</td><td>{{ number_format((float)$item->total_amount,2) }}</td></tr>@endforeach</tbody></table></div></div></div>
<div class="col-lg-4"><div class="card card-body">
<strong>Phone:</strong> {{ $summary->customer_phone ?: '—' }}<br>
<strong>Address:</strong> {{ $summary->customer_address ?: '—' }}<br>
<strong>Subtotal:</strong> {{ number_format((float)$summary->invoice_subtotal,2) }}<br>
<strong>Invoice Discount:</strong> {{ number_format((float)$summary->invoice_discount,2) }}<br>
<strong>Tax:</strong> {{ number_format((float)($meta->tax_amount ?? 0),2) }}<br>
<strong>Coupon:</strong> {{ $meta->coupon_code ?: '—' }} / {{ number_format((float)($meta->coupon_discount ?? 0),2) }}<br>
<strong>Gift Card:</strong> {{ $meta->gift_card_code ?: '—' }} / {{ number_format((float)($meta->gift_card_used ?? 0),2) }}<br>
<strong>Courier:</strong> {{ $meta->courier_partner ?: '—' }}<br>
<strong>Tracking:</strong> {{ $meta->courier_tracking_no ?: '—' }}<br>
<strong>COD / Courier Status:</strong> {{ $meta->courier_status ?: 'Pending' }}<br>
<strong>Bangla Invoice Mode:</strong> {{ $meta->language_mode ?: 'English' }}<br>
@if($payments->count())<hr><strong>Split Payment History</strong>@foreach($payments as $pay)<div>{{ $pay->payment_method }} - {{ number_format($pay->amount,2) }} @if($pay->gateway_name) <small>({{ $pay->gateway_name }} / {{ $pay->gateway_reference }})</small>@endif</div>@endforeach@endif
<form method="POST" action="{{ route('admin.sales.destroy', $invoiceNo) }}" class="mt-3" onsubmit="return confirm('Delete this invoice? Stock will be restored.')">@csrf @method('DELETE')<button class="btn btn-outline-danger">Delete Invoice</button></form>
</div></div></div>
@endsection
