@php $pdfLocale = app()->getLocale(); $isRtl = $pdfLocale === 'ar'; // No colon in Arabic; English keeps colon after summary labels $rtlLabelSuffix = $isRtl ? '' : ':'; @endphp Sale Invoice - {{$sale['Ref']}} @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, '.', ','); } } $sdpPillKeys = ['completed', 'paid', 'pending', 'unpaid', 'partial', 'received', 'ordered']; $statusKey = strtolower($sale['statut']); $sdpStatusPill = in_array($statusKey, $sdpPillKeys, true) ? $statusKey : 'default'; $paymentKey = strtolower($sale['payment_status']); $sdpPaymentPill = in_array($paymentKey, $sdpPillKeys, true) ? $paymentKey : 'default'; @endphp @php $pdfCssPath = public_path('css/pdf.css'); @endphp @if (is_file($pdfCssPath) && is_readable($pdfCssPath)) @endif @php $x = public_path('css/sale_pdf.css'); @endphp @if (is_file($x) && is_readable($x)) @endif
{{ __('pdf.sales_invoice') }}
{{$sale['Ref']}}
{{ __('pdf.date') }}{{ $isRtl ? '' : ':' }} @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}}
{{ __('pdf.invoice_no') }}{{ $isRtl ? '' : ':' }} {{$sale['Ref']}}
{{ __('pdf.status') }}{{ $isRtl ? '' : ':' }} {{$sale['statut']}}
{{ __('pdf.payment') }}{{ $isRtl ? '' : ':' }} {{$sale['payment_status']}}
{{ __('pdf.bill_to') }}
{{$sale['client_name']}}
@if($isRtl) {{-- RTL: value LEFT, label RIGHT (like summary) --}} @if($sale['client_tax']) @endif @else {{-- LTR: label left, value right --}} @if($sale['client_tax']) @endif @endif
{{$sale['client_phone']}}{{ __('pdf.phone') }}{{ $isRtl ? '' : ':' }}
{{$sale['client_email']}}{{ __('pdf.email') }}{{ $isRtl ? '' : ':' }}
{{$sale['client_adr']}}{{ __('pdf.address') }}{{ $isRtl ? '' : ':' }}
{{$sale['client_tax']}}{{ __('pdf.tax_no') }}{{ $isRtl ? '' : ':' }}
{{ __('pdf.phone') }}:{{$sale['client_phone']}}
{{ __('pdf.email') }}:{{$sale['client_email']}}
{{ __('pdf.address') }}:{{$sale['client_adr']}}
{{ __('pdf.tax_no') }}:{{$sale['client_tax']}}
{{ __('pdf.from') }}
{{$setting['CompanyName']}}
@if($isRtl) {{-- RTL: value LEFT, label RIGHT (like summary) --}} @else {{-- LTR: label left, value right --}} @endif
{{$setting['CompanyPhone']}}{{ __('pdf.phone') }}
{{$setting['email']}}{{ __('pdf.email') }}
{{$setting['CompanyAdress']}}{{ __('pdf.address') }}
{{ __('pdf.phone') }}:{{$setting['CompanyPhone']}}
{{ __('pdf.email') }}:{{$setting['email']}}
{{ __('pdf.address') }}:{{$setting['CompanyAdress']}}
@php $rowIndex = 0; @endphp @foreach ($details as $detail) @php $rowIndex++; @endphp @endforeach
{{ __('pdf.product') }} {{ __('pdf.price') }} {{ __('pdf.qty') }} {{ __('pdf.disc') }} {{ __('pdf.tax') }} {{ __('pdf.total') }}
{{$detail['name']}}
{{ __('pdf.code') }} {{$detail['code']}}
@if($detail['is_imei'] && $detail['imei_number'] !==null)
{{ __('pdf.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']; } $discountMethod = $sale['discount_Method'] ?? '2'; $discountValue = (float)$sale['discount']; $manualDiscountAmount = $discountMethod === '1' ? $subtotal * ($discountValue / 100) : min($discountValue, $subtotal); @endphp @if($isRtl) {{-- Arabic: amount LEFT, label RIGHT (no dir=rtl on table) --}} @if(isset($sale['discount_from_points']) && (float)$sale['discount_from_points'] > 0) @endif @else {{-- English: label left, amount right --}} @if(isset($sale['discount_from_points']) && (float)$sale['discount_from_points'] > 0) @endif @endif
{{$symbol}} {{formatPrice($subtotal, 2, $priceFormat)}} {{ __('pdf.subtotal') }}{!! $rtlLabelSuffix !!}
{{$symbol}} {{formatPrice((float)$sale['TaxNet'], 2, $priceFormat)}} {{ __('pdf.order_tax') }}{!! $rtlLabelSuffix !!}
@if($discountMethod === '1')- {{number_format($discountValue, 2)}}% ({{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}})@else - {{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}}@endif {{ __('pdf.discount') }}{!! $rtlLabelSuffix !!}
- {{$symbol}} {{formatPrice((float)$sale['discount_from_points'], 2, $priceFormat)}} {{ __('pdf.discount_from_points') }}{!! $rtlLabelSuffix !!}
{{$symbol}} {{formatPrice((float)$sale['shipping'], 2, $priceFormat)}} {{ __('pdf.shipping') }}{!! $rtlLabelSuffix !!}
{{$symbol}} {{formatPrice((float)$sale['GrandTotal'], 2, $priceFormat)}} {{ __('pdf.total_label') }}{!! $rtlLabelSuffix !!}
{{$symbol}} {{formatPrice((float)$sale['paid_amount'], 2, $priceFormat)}} {{ __('pdf.paid_amount') }}{!! $rtlLabelSuffix !!}
{{$symbol}} {{formatPrice((float)$sale['due'], 2, $priceFormat)}} {{ __('pdf.amount_due') }}{!! $rtlLabelSuffix !!}
{{ __('pdf.subtotal') }} {{$symbol}} {{formatPrice($subtotal, 2, $priceFormat)}}
{{ __('pdf.order_tax') }} {{$symbol}} {{formatPrice((float)$sale['TaxNet'], 2, $priceFormat)}}
{{ __('pdf.discount') }} @if($discountMethod === '1')- {{number_format($discountValue, 2)}}% ({{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}})@else - {{$symbol}} {{formatPrice($manualDiscountAmount, 2, $priceFormat)}}@endif
{{ __('pdf.discount_from_points') }} - {{$symbol}} {{formatPrice((float)$sale['discount_from_points'], 2, $priceFormat)}}
{{ __('pdf.shipping') }} {{$symbol}} {{formatPrice((float)$sale['shipping'], 2, $priceFormat)}}
{{ __('pdf.total_label') }} {{$symbol}} {{formatPrice((float)$sale['GrandTotal'], 2, $priceFormat)}}
{{ __('pdf.paid_amount') }} {{$symbol}} {{formatPrice((float)$sale['paid_amount'], 2, $priceFormat)}}
{{ __('pdf.amount_due') }} {{$symbol}} {{formatPrice((float)$sale['due'], 2, $priceFormat)}}