@php // Group line orders by transaction_id // All items from the same transaction stay in one card $grouped_orders = $line_orders->groupBy('transaction_id'); // Sort grouped orders by most recently updated first $grouped_orders = $grouped_orders->sortByDesc(function($orders, $key) { // Use the transaction updated_at timestamp for sorting return \Carbon\Carbon::parse($orders->first()->updated_at)->timestamp; }); @endphp @forelse($grouped_orders as $transaction_id => $orders) @php $first_order = $orders->first(); @endphp
#{{$first_order->invoice_no}}
{{\Illuminate\Support\Carbon::parse($first_order->created_at)->format('h:i:s A')}} - {{\Illuminate\Support\Carbon::parse($first_order->created_at)->format('D M d')}}
@if($first_order->updated_at && $first_order->updated_at != $first_order->created_at)
Updated: {{\Illuminate\Support\Carbon::parse($first_order->updated_at)->format('h:i A')}}
@endif
@if(!empty($first_order->table_name)) TABLE NO. {{$first_order->table_name}} @else TAKE OUT @endif
ENTREES
@foreach($orders as $order) @php // Check if order was updated (new items added) $isUpdatedOrder = $order->updated_at && $order->created_at && \Carbon\Carbon::parse($order->updated_at)->gt(\Carbon\Carbon::parse($order->created_at)->addSeconds(5)); @endphp @php // Calculate time ago for all items $itemCreated = \Carbon\Carbon::parse($order->item_created_at ?? $order->updated_at ?? $order->created_at); $now = \Carbon\Carbon::now(); $diffInMinutes = $itemCreated->diffInMinutes($now); @endphp
@if($order->is_new_item && $isUpdatedOrder)
NEW ORDER
@endif
@if($diffInMinutes < 1) JUST NOW @elseif($diffInMinutes == 1) 1 MINUTE AGO @else {{ $diffInMinutes }} MINUTES AGO @endif
{{$order->quantity}} x {{$order->product_name}}
@if($order->product_type == 'variable')
{{$order->product_variation_name}} - {{$order->variation_name}}
@endif @if(!empty($order->modifiers) && count($order->modifiers) > 0) @foreach($order->modifiers as $key => $modifier) @if(!empty($modifier->variations))
{{$modifier->variations->name ?? ''}}
@endif @endforeach @endif @if(!empty($order->sell_line_note))
NOTES: {{$order->sell_line_note}}
@endif
@endforeach
Customer: {{$first_order->customer_name}} | @if(!empty($first_order->service_staff_name)) Staff: {{$first_order->service_staff_name}} | @endif Location: {{$first_order->business_location}}
@if($orders_for == 'kitchen') @elseif($orders_for == 'bar') @elseif($orders_for == 'bakery') @elseif($orders_for == 'waiter' && $first_order->res_order_status != 'served') @else @endif
@if($loop->iteration % 4 == 0) @endif @if($loop->iteration % 2 == 0)
@endif @empty

@lang('restaurant.no_orders_found')

@endforelse