@if(!empty($img))

@else
 }})
@endif
{{ $product->name }}
{{ $product->sku }}
@forelse($stock_history as $row)
@php
$type = $row['type'] ?? '';
$qty = (float) ($row['quantity_change'] ?? 0);
$abs_qty = abs($qty);
$stock_after = $row['stock'] ?? null;
$row_offset = method_exists($stock_history, 'firstItem') ? (($stock_history->firstItem() ?? 1) - 1) : 0;
$row_no = $total_rows - $row_offset - $loop->index;
// Icon
$icon_html = '';
if ($type === 'sell_transfer') {
$icon_html = '
';
} elseif ($type === 'purchase_transfer') {
$icon_html = '
';
} elseif ($qty > 0) {
$icon_html = '
';
} else {
$icon_html = '
';
}
// Primary label (match screenshot-style)
$type_labels = [
'purchase' => __('purchase.purchase'),
'sell' => __('sale.sale'),
'opening_stock' => __('lang_v1.opening_stock'),
'stock_adjustment' => __('stock_adjustment.stock_adjustment'),
'sell_transfer' => __('lang_v1.stock_transfer'),
'purchase_transfer' => __('lang_v1.stock_transfer'),
'sell_return' => __('lang_v1.sell_return'),
'purchase_return' => __('lang_v1.purchase_return'),
'production_purchase' => 'Manufacturing: ' . __('purchase.purchase'),
'production_sell' => 'Manufacturing: ' . __('sale.sale'),
];
// Prefer server-provided label, then our mapping, then a readable fallback.
$primary = $row['type_label'] ?? ($type_labels[$type] ?? ucwords(str_replace('_', ' ', (string) $type)));
$primary = html_entity_decode((string) $primary, ENT_QUOTES, 'UTF-8');
$who = html_entity_decode((string) ($row['user_name'] ?? ''), ENT_QUOTES, 'UTF-8');
$when = !empty($row['date']) ? \Carbon::parse($row['date'])->format('n/j/Y g:i A') : '';
$loc = html_entity_decode((string) ($row['location_name'] ?? ''), ENT_QUOTES, 'UTF-8');
@endphp
{!! $icon_html !!}
{{ $primary }}:
{{ $abs_qty }}
#{{ $row_no }}
@if(!empty($when)) - {{ $when }} @endif
@if(!empty($who)) - {{ $who }} @endif
@if(!empty($loc)) - {{ $loc }} @endif
Stock
@if(!is_null($stock_after))
{{ $stock_after }}
@else
0
@endif
@empty
@lang('lang_v1.no_stock_history_found')
@endforelse
@if(method_exists($stock_history, 'hasPages') && $stock_history->hasPages())
{{ $stock_history->appends(request()->except('page'))->links() }}
@endif