@php
$record = $getRecord();
// PERF: relations should be eager-loaded by the page's getTableQuery() (which is true
// on /orders). For pages that share this blade WITHOUT eager-loading them
// (e.g. /old-fulfillment), gracefully lazy-load just the needed relations rather
// than throwing or silently rendering empty.
//
// - /orders: relations are eager-loaded → both `relationLoaded()` checks return true → zero extra queries.
// - /old-fulfillment: relations are not eager-loaded → 2 lazy-load queries per row (same as original behavior pre-optimization).
if (!$record->relationLoaded('assignments')) {
$record->load(['assignments.user', 'assignments.assignedBy']);
}
if (!$record->relationLoaded('departmentAssignments')) {
$record->load(['departmentAssignments.department', 'departmentAssignments.assignedBy']);
}
$assignments = $record->assignments;
$departmentAssignments = $record->departmentAssignments;
$currentUserId = auth()->id();
@endphp
{{-- Source badge --}}
@php
$sourceText = '';
// Check for marketplace indicators
if ($record->source === \App\Models\Order::SOURCE_SELLBRITE && $record->notes->isNotEmpty()) {
$firstNote = $record->notes->first();
if ($firstNote && (str_contains($firstNote->note, '(Go-Parts Amazon)') || str_contains($firstNote->note, '(Amazon.com)'))) {
$sourceText = 'Amazon';
} elseif ($firstNote && (str_contains($firstNote->note, '(Go-Parts eBay)') || str_contains($firstNote->note, '(ebay)'))) {
$sourceText = 'eBay';
}
}
// Check for B2B variants
if (empty($sourceText) && $record->source === \App\Models\Order::SOURCE_B2B && $record->notes->isNotEmpty()) {
foreach ($record->notes as $note) {
if (str_contains($note->note, 'Order placed by customer in B2B Interface')) {
$sourceText = 'B2B (by Customer)';
break;
}
if (str_contains($note->note, 'B2B In-Stock')) {
$sourceText = 'B2B Ship Same Day';
break;
}
}
}
// Default source text
if (empty($sourceText)) {
$sourceText = \App\Models\Order::$sources[$record->source] ?? 'Unknown';
}
@endphp
{{ $sourceText }}
{{-- Duplicate order badge --}}
@php
$openDuplicates = collect();
// This order flagged as having a duplicate
if ($record->duplicates && $record->duplicates->where('status', 'open')->count() > 0) {
foreach ($record->duplicates->where('status', 'open') as $dup) {
$openDuplicates->push($dup->duplicate_order_id);
}
}
// This order IS the duplicate of another
if ($record->duplicatedBy && $record->duplicatedBy->where('status', 'open')->count() > 0) {
foreach ($record->duplicatedBy->where('status', 'open') as $dup) {
$openDuplicates->push($dup->order_id);
}
}
$dupOrderIds = $openDuplicates->unique()->values();
@endphp
@if($dupOrderIds->count() > 0)