@php $item = $getRecord(); $itemId = $item->order_item_id; $currentStatus = $item->current_status; $statusObj = $item->status; $statusName = $statusObj ? $statusObj->status : ''; $statusColor = $statusObj ? $statusObj->color_code : 'label-default'; // Check if item has returns $hasReturns = \DB::table('orders_items_returns') ->where('order_item_id', $itemId) ->exists(); // Check if item has core charge refund entries (only relevant when the // item carries a core charge). Kept fully separate from returns. $hasCoreCharge = ($item->core_charge ?? 0) > 0; $coreChargeCount = 0; $coreChargeBadgeText = ''; if ($hasCoreCharge) { $coreCharges = \DB::table('orders_items_core_charges') ->where('order_item_id', $itemId) ->orderBy('id', 'desc') ->get(); $coreChargeCount = $coreCharges->count(); if ($coreChargeCount > 0) { $latestCore = $coreCharges->first(); $coreStatusLabels = [ 'refunded' => 'Refunded', 'waived' => 'Waived', ]; $coreStateLabel = $coreStatusLabels[$latestCore->status ?? 'refunded'] ?? 'Refunded'; $coreAmount = $latestCore->amount !== null ? '$' . number_format($latestCore->amount, 2) : ''; $coreChargeBadgeText = trim("Core Charge {$coreAmount} - {$coreStateLabel}"); } } $returnCount = 0; $returnBadgeText = ''; $returnTracking = null; if ($hasReturns) { $returns = \DB::table('orders_items_returns') ->where('order_item_id', $itemId) ->orderBy('id', 'desc') ->get(); $returnCount = $returns->count(); if ($returnCount > 0) { $latestReturn = $returns->first(); $statusLabels = [ 'initiated' => 'Initiated', 'label_sent' => 'Label Sent', 'in_transit' => 'In Transit', 'received' => 'Received', ]; $stateLabel = $statusLabels[$latestReturn->return_status ?? 'initiated'] ?? 'Initiated'; $returnBadgeText = "Return - {$stateLabel}"; // Get return tracking from latest entry that has one $returnTracking = $returns->pluck('return_tracking')->filter()->first(); } } @endphp
@if($hasReturns) @else @endif @if($returnTracking) Ret: {{ $returnTracking }} @endif {{-- Core Charge Button - only for items that carry a core charge --}} @if($hasCoreCharge) @if($coreChargeCount > 0) @else @endif @endif {{-- Calculation Log Button - disabled until supplier_prices table is implemented @php $supplierPrices = \DB::table('supplier_prices') ->where('order_item_id', $itemId) ->exists(); @endphp @if($supplierPrices) @endif --}}