@php $gross = (float) $order->subtotal; $discount = (float) $order->discount_total; $shipping = (float) ($order->shipping_total ?? 0); $taxableAmount = (float) $order->taxable_amount; $vatTotal = (float) $order->vat_total; $invoiceAmount = (float) $order->grand_total; $customer = $order->customer; $salesman = $order->salesman; $vehicle = $salesman?->currentVehicleAssignment?->vehicle; $invoiceDate = $order->created_at?->format('d/m/Y') ?? now()->format('d/m/Y'); $dueDate = $order->due_date?->format('d/m/Y') ?? $invoiceDate; $warehouseParts = array_filter([ $vehicle?->name, $vehicle?->plate_number ? '-'.$vehicle->plate_number : null, ]); $warehouse = $warehouseParts ? trim(implode(' ', $warehouseParts)).($salesman?->name ? ' ('.$salesman->name.')' : '') : ($salesman?->warehouse ?: ($order->catalog?->title ?: 'Van Sales')); $customerName = $customer?->shop_name ?: $order->customer_name_snapshot; $customerAddress = $customer?->address ?: ($customer?->city ?: '-'); $customerPhone = $customer?->phone ?: ($order->customer_phone_snapshot ?: '-'); $customerTrn = $customer?->trn ?: '-'; $branch = $customer?->area?->name ?: ($customer?->city ?: '-'); $companyNameRaw = trim((string) $company->company_name); $companyNameNormalized = strtoupper(preg_replace('/\s+/', ' ', $companyNameRaw)); $companyName = ( $companyNameRaw === '' || str_contains($companyNameNormalized, 'SHIPMENT CATALOG') || ( str_contains($companyNameNormalized, 'WIWU') && ! str_contains($companyNameNormalized, 'L.L.C') ) ) ? 'WIWU INTERNATIONAL TRADING L.L.C' : $companyNameRaw; $companyWebsite = $company->website ?: 'www.wiwu.ae'; $companyEmail = $company->email ?: '[email protected]'; $companyPhone = $company->phone ?: '00971 4220 5050'; $companyPoBox = $company->po_box ?: '96696'; $companyAddress = $company->address ?: '10 Street-2, Frij al Murar, Deira, Dubai-U.A.E'; $companyTrn = $company->trn ?: '104687769000003'; $bankAccountName = $company->bank_account_name ?: 'Wiwu International Trading'; $bankName = $company->bank_name ?: 'Abu Dhabi Commercial Bank'; $bankAccountNumber = $company->bank_account_number ?: '11909848920002'; $bankIban = $company->iban ?: 'AE910030011909848920002'; $bankSwift = $company->swift_code ?: 'ADCBAEAA'; $bankBranch = $company->bank_branch ?: 'Al Majaz Branch, Sharjah'; $contactParts = [ 'Website: '.$companyWebsite, 'Email: '.$companyEmail, 'Tel: '.$companyPhone, ]; $addressParts = [ 'P.O.Box: '.$companyPoBox, $companyAddress, ]; $amountToWords = static function (float $amount): string { if (class_exists('NumberFormatter')) { $formatter = new NumberFormatter('en', NumberFormatter::SPELLOUT); $whole = (int) floor($amount); $fils = (int) round(($amount - $whole) * 100); $words = ucwords( (string) $formatter->format($whole), " \t\r\n\f\v-" ); if ($fils > 0) { $words .= ' And '.ucwords( (string) $formatter->format($fils), " \t\r\n\f\v-" ).' Fils'; } return 'AED '.$words.' Only'; } return 'AED '.number_format($amount, 2).' Only'; }; $itemsPerPage = 8; $pages = $order->items->values()->chunk($itemsPerPage)->values(); if ($pages->isEmpty()) { $pages = collect([collect()]); } $formatQty = static function ($value): string { $number = (float) $value; return abs($number - round($number)) < 0.00001 ? number_format($number, 0) : number_format($number, 2); }; $pageCount = $pages->count(); $shortSinglePage = $pageCount === 1 && $order->items->count() <= 4; $serialNumber = 1; $runningDiscount = 0.0; $runningTaxable = 0.0; $runningVat = 0.0; $runningTotal = 0.0; $printDate = now()->format('d/m/Y H:i:s'); @endphp @foreach($pages as $pageIndex => $pageItems) @php $isLastPage = $pageIndex === $pageCount - 1; $pageQuantity = $pageItems->sum( fn ($item) => (float) $item->qty ); $calculatedDiscount = (float) $pageItems->sum( fn ($item) => (float) $item->discount_amount ); $calculatedTaxable = (float) $pageItems->sum( fn ($item) => (float) $item->taxable_amount ); $calculatedVat = (float) $pageItems->sum( fn ($item) => (float) $item->vat_amount ); $calculatedTotal = (float) $pageItems->sum( fn ($item) => (float) $item->line_total ); if ($isLastPage) { $pageDiscount = $discount - $runningDiscount; $pageTaxable = $taxableAmount - $runningTaxable; $pageVat = $vatTotal - $runningVat; $pageTotal = $invoiceAmount - $runningTotal; } else { $pageDiscount = $calculatedDiscount; $pageTaxable = $calculatedTaxable; $pageVat = $calculatedVat; $pageTotal = $calculatedTotal; $runningDiscount += $pageDiscount; $runningTaxable += $pageTaxable; $runningVat += $pageVat; $runningTotal += $pageTotal; } @endphp
@if($order->status === 'draft')
DRAFT
@endif
@if(!empty($company_logo_data_uri)) @endif
{{ $companyName }}
@if($contactParts)
{{ implode(' | ', $contactParts) }}
@endif @if($addressParts)
{{ implode(', ', $addressParts) }}
@endif
TRN - {{ $companyTrn }}
Tax Invoice
Customer Details :
Name : {{ $customerName ?: '-' }}
Address : {{ $customerAddress }}
Tel No : {{ $customerPhone }}
Customer TRN : {{ $customerTrn }}
Branch : {{ $branch }}
Inv No : {{ $order->order_number }}
Inv Date : {{ $invoiceDate }}
Warehouse : {{ $warehouse }}
Currency : AED @ 1.000
Ref No : -
Due Date : {{ $dueDate }}
Payment Terms : {{ $order->payment_terms ?: 'Due on receipt' }}
Invoice Type : {{ $order->invoice_type === 'on_account' ? 'ON ACCOUNT' : 'CASH' }}
Place Of Supply : {{ $order->place_of_supply ?: 'United Arab Emirates' }}
@foreach($pageItems as $item) @php($serialNumber++) @endforeach
S/N Item Code & Description Qty Rate Discount Taxable Amt VAT Amt {{ number_format((float) $order->vat_rate, 0) }}% Total Amt
{{ $serialNumber }} @if($item->barcode_snapshot) {{ $item->barcode_snapshot }} @endif {{ $item->sku_snapshot }} {{ $item->name_snapshot }} SOURCE: {{ strtoupper(str_replace('_', ' ', $item->fulfillment_source ?: 'van')) }} @if(($item->fulfillment_status ?? '') !== '') ยท {{ strtoupper($item->fulfillment_status) }} @endif @if($item->is_clearance) CLEARANCE @endif {{ $formatQty($item->qty) }} {{ number_format((float) $item->unit_price, 2) }} {{ number_format((float) $item->discount_amount, 2) }} {{ number_format((float) $item->taxable_amount, 2) }} {{ number_format((float) $item->vat_amount, 2) }} {{ number_format( (float) $item->line_total, 2 ) }}
@if($isLastPage && $pageCount > 1) @endif
Page Total {{ $formatQty($pageQuantity) }} {{ number_format($pageDiscount, 2) }} {{ number_format($pageTaxable, 2) }} {{ number_format($pageVat, 2) }} {{ number_format($pageTotal, 2) }}
Total {{ $formatQty($order->items->sum('qty')) }} {{ number_format($discount, 2) }} {{ number_format($taxableAmount, 2) }} {{ number_format($vatTotal, 2) }} {{ number_format($invoiceAmount, 2) }}
@if($isLastPage)
Bank Details :
Account Name : {{ $bankAccountName }}
Bank Name : {{ $bankName }}
Account Number : {{ $bankAccountNumber }}
IBAN : {{ $bankIban }}
SWIFT Code : {{ $bankSwift }}
Branch Name : {{ $bankBranch }}
Gross Total : {{ number_format($gross, 2) }}
Discounts : {{ number_format($discount, 2) }}
Shipping Charges : {{ number_format($shipping, 2) }}
Taxable Amount : {{ number_format($taxableAmount, 2) }}
VAT Total : {{ number_format($vatTotal, 2) }}
Invoice Amount : {{ number_format($invoiceAmount, 2) }}
Amount in Words : {{ $amountToWords($invoiceAmount) }}
@if($order->notes)
Notes: {{ $order->notes }}
@endif
PREPARED BY
{{ $salesman?->name ?: '-' }}
CHECKED BY
AUTHORIZED BY
@endif
@endforeach