@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, '.', ','); } } @endphp
@php $logoSrc = null; if (!empty($setting['logo'])) { $logoPath = public_path('images/'.$setting['logo']); if (file_exists($logoPath) && is_readable($logoPath)) { $logoData = @file_get_contents($logoPath); if ($logoData !== false) { $logoB64 = base64_encode($logoData); $logoExt = strtolower(pathinfo($logoPath, PATHINFO_EXTENSION)); $logoMime = $logoExt === 'svg' ? 'image/svg+xml' : (in_array($logoExt, ['png','jpeg','jpg','gif','webp'], true) ? 'image/'.$logoExt : 'image/png'); if ($logoExt === 'jpg') { $logoMime = 'image/jpeg'; } $logoSrc = 'data:'.$logoMime.';base64,'.$logoB64; } } } @endphp @if($logoSrc) Logo @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 ? '' : ':' }} @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']}}
{{ __('pdf.payment') }}{{ $isRtl ? '' : ':' }} @php $paymentKey = strtolower($sale['payment_status']); $paymentStyle = $statusColors[$paymentKey] ?? ['bg' => '#e5e7eb', 'color' => '#374151']; @endphp {{$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); // Arabic: col1=amount (left), col2=label (right). English: col1=label (left), col2=amount (right). $tdAmountLeft = 'padding: 5px 10px; font-size: 8.5pt; font-weight: 600; text-align: left; direction: ltr;'; $tdLabelRight = 'padding: 5px 10px; font-size: 8pt; font-weight: 600; text-align: right; direction: rtl;'; @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)}}
@if($setting['is_invoice_footer'] && $setting['invoice_footer'] !==null)

{{$setting['invoice_footer']}}

@endif

{{ __('pdf.thank_you') }}