@php
// Fetch the price that is not the latest in terms of timestamp
$activePrice = $item->product->productPrices()
->where('is_active', 1)
->where('created_at', '<', $item->created_at) // Compare timestamps
->orderBy('created_at', 'desc') // Order by descending timestamp
->first();
@endphp
@if ($activePrice)
₱{{ number_format($activePrice->price, 2, '.', ',') }}
@else
No price available
@endif
@if ($item->product->product_images->isNotEmpty())
@else
Image not found
@endif
@endforeach
@php
// Calculate grand total
$grandTotal = 0;
// Calculate subtotal
foreach ($order->orderItems as $item) {
if ($item->status == 0) {
// Fetch the price based on timestamp comparison
$activePrice = $item->product->productPrices()
->where('is_active', 1)
->where('created_at', '<', $item->created_at) // Compare timestamps
->orderBy('created_at', 'desc') // Order by descending timestamp
->first();
$originalPrice = $activePrice ? $activePrice->price : 0;
$subtotal = $originalPrice * $item->qty;
$grandTotal += $subtotal;
}
}
@endphp
Grand Total: ₱{{ number_format($grandTotal, 2, '.', ',') }}