@extends('layouts.seller') @section('content') @if(Auth::user()->role_as == 10)
@else
Product Sales Reports
Total Orders
@php $totalProfit = 0; $grandTotal = 0; @endphp @foreach ($completedOrders as $order) @foreach ($order->orderItems as $item) @endforeach @endforeach
Tracking ID Date Completed Total System Share Profit
{{ $order->tracking_no }} {{ $order->created_at->format('d M Y') }} @php // Fetch the latest active price before the order item's created_at timestamp $activePrice = $item->product->product_prices() ->where('is_active', 1) ->where('created_at', '<', $item->created_at) ->orderBy('created_at', 'desc') ->first(); // Calculate subtotal using the fetched active price $originalPrice = $activePrice ? $activePrice->price : 0; $subtotal = $originalPrice * $item->qty; $grandTotal += $subtotal; @endphp ₱{{ number_format($subtotal, 2) }} @php $activePrice = $item->product->product_prices() ->where('is_active', 1) ->where('created_at', '<', $item->created_at) ->orderBy('created_at', 'desc') ->first(); $originalPrice = $activePrice ? $activePrice->price : 0; $revenue = $originalPrice * $item->qty; // Calculate revenue $serviceFee = $revenue * 0.018; // Calculate 1.8% of the revenue @endphp ₱{{ number_format($revenue, 2) }}
({{ number_format($serviceFee, 2) }} as 1.8%)
@php $costPrice = $item->product->cost_price * $item->qty; // Calculate cost price $profit = $revenue - $costPrice; // Calculate profit $percentage = $revenue * 0.018; // Calculate 1.8% of revenue $profit -= $percentage; // Subtract percentage from profit $totalProfit += $profit; // Add profit to total profit @endphp ₱{{ number_format($profit, 2) }}
Grand Total: ₱{{ number_format($grandTotal, 2) }}
Total Profit: ₱{{ number_format($totalProfit, 2) }}
@endif @endsection