@php // Price formatting helper function (shared behavior with other PDFs) $priceFormat = $setting['price_format'] ?? null; function formatPrice($number, $decimals = 2, $priceFormat = null) { $number = (float) $number; $decimals = (int) $decimals; if (empty($priceFormat)) { return number_format($number, $decimals, '.', ','); } switch ($priceFormat) { case 'comma_dot': return number_format($number, $decimals, '.', ','); case 'dot_comma': return number_format($number, $decimals, ',', '.'); case 'space_comma': return number_format($number, $decimals, ',', ' '); default: return number_format($number, $decimals, '.', ','); } } @endphp
@if(!empty($setting['logo']) && file_exists(public_path('images/'.$setting['logo']))) Logo @endif
SALES INVOICE
{{$sale['Ref']}}
Date: @php $dateFormat = $setting['date_format'] ?? 'YYYY-MM-DD'; $dateTime = \Carbon\Carbon::parse($sale['date']); $phpDateFormat = str_replace(['YYYY', 'MM', 'DD'], ['Y', 'm', 'd'], $dateFormat); // Check if original date string contains time $hasTime = strpos($sale['date'], ' ') !== false && preg_match('/\d{1,2}:\d{2}/', $sale['date']); if ($hasTime) { $formattedDate = $dateTime->format($phpDateFormat . ' H:i'); // Preserve seconds if they exist if (preg_match('/:\d{2}:\d{2}/', $sale['date'])) { $formattedDate = $dateTime->format($phpDateFormat . ' H:i:s'); } } else { $formattedDate = $dateTime->format($phpDateFormat); } @endphp {{$formattedDate}}
Invoice #: {{$sale['Ref']}}
Status: @php $statusColors = [ 'completed' => ['bg' => '#d1fae5', 'color' => '#065f46'], 'paid' => ['bg' => '#d1fae5', 'color' => '#065f46'], 'pending' => ['bg' => '#fef3c7', 'color' => '#92400e'], 'unpaid' => ['bg' => '#fef3c7', 'color' => '#92400e'], 'partial' => ['bg' => '#dbeafe', 'color' => '#1e40af'], ]; $statusKey = strtolower($sale['statut']); $statusStyle = $statusColors[$statusKey] ?? ['bg' => '#e5e7eb', 'color' => '#374151']; @endphp {{$sale['statut']}}
Payment: @php $paymentKey = strtolower($sale['payment_status']); $paymentStyle = $statusColors[$paymentKey] ?? ['bg' => '#e5e7eb', 'color' => '#374151']; @endphp {{$sale['payment_status']}}
BILL TO
{{$sale['client_name']}}
Phone: {{$sale['client_phone']}}
Email: {{$sale['client_email']}}
Address: {{$sale['client_adr']}}
@if($sale['client_tax'])
Tax #: {{$sale['client_tax']}}
@endif
FROM
{{$setting['CompanyName']}}
Phone: {{$setting['CompanyPhone']}}
Email: {{$setting['email']}}
Address: {{$setting['CompanyAdress']}}
@php $rowIndex = 0; @endphp @foreach ($details as $detail) @php $rowIndex++; @endphp @endforeach
PRODUCT PRICE QTY DISC TAX TOTAL
{{$detail['name']}}
Code: {{$detail['code']}}
@if($detail['is_imei'] && $detail['imei_number'] !==null)
SN: {{$detail['imei_number']}}
@endif
{{formatPrice((float)$detail['price'], 2, $priceFormat)}} {{$detail['quantity']}} {{$detail['unitSale']}} {{formatPrice((float)$detail['DiscountNet'], 2, $priceFormat)}} {{formatPrice((float)$detail['taxe'], 2, $priceFormat)}} {{formatPrice((float)$detail['total'], 2, $priceFormat)}}
@php // Calculate subtotal from line items $subtotal = 0; foreach ($details as $detail) { $subtotal += (float)$detail['total']; } // Calculate manual discount amount (excluding points) $discountMethod = $sale['discount_Method'] ?? '2'; $discountValue = (float)$sale['discount']; if ($discountMethod === '1') { // Percentage discount $manualDiscountAmount = $subtotal * ($discountValue / 100); } else { // Fixed discount $manualDiscountAmount = min($discountValue, $subtotal); } @endphp @if(isset($sale['discount_from_points']) && (float)$sale['discount_from_points'] > 0) @endif
Subtotal: {{$symbol}} {{formatPrice($subtotal, 2, $priceFormat)}}
Order Tax: {{$symbol}} {{formatPrice((float)$sale['TaxNet'], 2, $priceFormat)}}
Discount: @if($discountMethod === '1') - {{number_format($discountValue, 2)}}% ({{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}}) @else - {{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}} @endif
Discount from Points: - {{$symbol}} {{formatPrice((float)$sale['discount_from_points'], 2, $priceFormat)}}
Shipping: {{$symbol}} {{formatPrice((float)$sale['shipping'], 2, $priceFormat)}}
TOTAL: {{$symbol}} {{formatPrice((float)$sale['GrandTotal'], 2, $priceFormat)}}
Paid Amount: {{$symbol}} {{formatPrice((float)$sale['paid_amount'], 2, $priceFormat)}}
Amount Due: {{$symbol}} {{formatPrice((float)$sale['due'], 2, $priceFormat)}}
@if($setting['is_invoice_footer'] && $setting['invoice_footer'] !==null)

{{$setting['invoice_footer']}}

@endif

Thank you for your business!