@php
$pdfLocale = app()->getLocale();
$isRtl = $pdfLocale === 'ar';
$rtlLabelSuffix = $isRtl ? '' : ':';
$symbol = $symbol ?? '';
$priceFormat = $setting['price_format'] ?? null;
if (!function_exists('formatAdjustmentPrice')) {
function formatAdjustmentPrice($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
Inventory Adjustment - {{$adjustment['Ref']}}
@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)
@endif
|
{{ __('pdf.inventory_adjustment') }}
{{$adjustment['Ref']}}
| {{ __('pdf.date') }}{{ $isRtl ? '' : ':' }} |
@php
$dateFormat = $setting['date_format'] ?? 'YYYY-MM-DD';
$dateTime = \Carbon\Carbon::parse($adjustment['date']);
$phpDateFormat = str_replace(['YYYY', 'MM', 'DD'], ['Y', 'm', 'd'], $dateFormat);
// Check if original date string contains time
$hasTime = strpos($adjustment['date'], ' ') !== false && preg_match('/\d{1,2}:\d{2}/', $adjustment['date']);
if ($hasTime) {
$formattedDate = $dateTime->format($phpDateFormat . ' H:i');
// Preserve seconds if they exist
if (preg_match('/:\d{2}:\d{2}/', $adjustment['date'])) {
$formattedDate = $dateTime->format($phpDateFormat . ' H:i:s');
}
} else {
$formattedDate = $dateTime->format($phpDateFormat);
}
@endphp
{{$formattedDate}}
|
| {{ __('pdf.adjustment_no') }}{{ $isRtl ? '' : ':' }} |
{{$adjustment['Ref']}} |
| {{ __('pdf.warehouse') }}{{ $isRtl ? '' : ':' }} |
{{$adjustment['warehouse_name']}} |
|
| {{ __('pdf.product') }} |
{{ __('pdf.quantity') }} |
{{ __('pdf.purchase_cost') }} |
{{ __('pdf.sale_price') }} |
@php
$rowIndex = 0;
$totalQty = 0;
$totalPurchaseCost = 0;
$totalSalePrice = 0;
$pdfDateFormat = $setting['date_format'] ?? 'YYYY-MM-DD';
$phpBatchDateFormat = str_replace(['YYYY', 'MM', 'DD'], ['Y', 'm', 'd'], $pdfDateFormat);
$formatBatchDate = function ($d) use ($phpBatchDateFormat) {
if (empty($d)) return null;
try { return \Carbon\Carbon::parse($d)->format($phpBatchDateFormat); }
catch (\Exception $e) { return (string) $d; }
};
@endphp
@foreach ($details as $detail)
@php
$rowIndex++;
$totalQty += (int)$detail['quantity'];
$linePurchaseCost = (float) ($detail['purchase_cost'] ?? 0);
$lineSalePrice = (float) ($detail['sale_price'] ?? 0);
$totalPurchaseCost += $linePurchaseCost;
$totalSalePrice += $lineSalePrice;
@endphp
|
{{$detail['name']}}
{{ __('pdf.code') }} {{$detail['code']}}
|
{{$detail['quantity']}} {{$detail['unit']}} |
{{$symbol}} {{ formatAdjustmentPrice($linePurchaseCost, 2, $priceFormat) }} |
{{$symbol}} {{ formatAdjustmentPrice($lineSalePrice, 2, $priceFormat) }} |
@if(!empty($detail['is_batch_tracked']) && !empty($detail['batches']))
| {{ __('pdf.batches') }} |
{{ count($detail['batches']) }}
|
| {{ __('pdf.batch_no') }} |
{{ __('pdf.mfg') }} |
{{ __('pdf.exp') }} |
{{ __('pdf.direction') }} |
{{ __('pdf.qty') }} |
@foreach($detail['batches'] as $bIdx => $b)
@php
$expiryStyle = 'background: #f3f4f6; color: #6b7280;';
if (!empty($b['expiry_date'])) {
try {
$expDate = \Carbon\Carbon::parse($b['expiry_date'])->startOfDay();
$today = \Carbon\Carbon::now()->startOfDay();
$diffDays = $today->diffInDays($expDate, false);
if ($diffDays < 0) { $expiryStyle = 'background: #fee2e2; color: #991b1b;'; }
elseif ($diffDays <= 30) { $expiryStyle = 'background: #fef3c7; color: #92400e;'; }
else { $expiryStyle = 'background: #d1fae5; color: #065f46;'; }
} catch (\Exception $e) {}
}
$qtyStr = number_format((float)($b['qty'] ?? 0), 2, '.', '');
$rowBg = $bIdx % 2 === 1 ? '#f8faff' : '#ffffff';
$mfgFormatted = $formatBatchDate($b['mfg_date'] ?? null);
$expFormatted = $formatBatchDate($b['expiry_date'] ?? null);
$direction = (string) ($b['direction'] ?? 'out');
$dirStyle = $direction === 'in'
? 'background: #d1fae5; color: #065f46;'
: 'background: #fee2e2; color: #991b1b;';
$dirArrow = $direction === 'in' ? '↑' : '↓';
@endphp
|
@if(!empty($b['batch_no']))
{{ $b['batch_no'] }}
@else
—
@endif
|
@if($mfgFormatted)
{{ $mfgFormatted }}
@else
—
@endif
|
@if($expFormatted)
{{ $expFormatted }}
@else
—
@endif
|
{{ $dirArrow }} {{ $direction === 'in' ? __('pdf.in') : __('pdf.out') }}
|
{{ $qtyStr }} {{ $detail['unit'] }} |
@endforeach
|
@endif
@endforeach
@php
$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)
| {{$rowIndex}} |
{{ __('pdf.total_items') }}{!! $rtlLabelSuffix !!} |
| {{$symbol}} {{ formatAdjustmentPrice($totalPurchaseCost, 2, $priceFormat) }} |
{{ __('pdf.total_purchase_cost') }}{!! $rtlLabelSuffix !!} |
| {{$symbol}} {{ formatAdjustmentPrice($totalSalePrice, 2, $priceFormat) }} |
{{ __('pdf.total_sale_price') }}{!! $rtlLabelSuffix !!} |
@else
| {{ __('pdf.total_items') }} |
{{$rowIndex}} |
| {{ __('pdf.total_purchase_cost') }} |
{{$symbol}} {{ formatAdjustmentPrice($totalPurchaseCost, 2, $priceFormat) }} |
| {{ __('pdf.total_sale_price') }} |
{{$symbol}} {{ formatAdjustmentPrice($totalSalePrice, 2, $priceFormat) }} |
@endif
|
@if($setting['is_invoice_footer'] && $setting['invoice_footer'] !==null)
{{$setting['invoice_footer']}}
@endif
{{ __('pdf.adjustment_completed') }}