Profitability Report

Filter Options Show Advanced Filters

Sales Channel & Category
Order Search
Date Range
Profit Filters
@if($profitPercentOperator === 'between')
@else @endif
Data Accuracy Filter
Profit Range
Order Options
Supplier Filter
Price Range Filters
Item Search
Credits & Fees
@if($profitMarginOperator === 'between')
@else @endif
Additional Filters
CSV export includes all calculated fields and metrics
@php $highCount = $periodStats['highAccuracy'] ?? 0; $mediumCount = $periodStats['mediumAccuracy'] ?? 0; $lowCount = $periodStats['lowAccuracy'] ?? 0; $accuracyTotal = $highCount + $mediumCount + $lowCount; $accuracyPercent = $accuracyTotal > 0 ? (($highCount * 100) + ($mediumCount * 50)) / $accuracyTotal : 0; $avgGrossProfit = ($periodStats['totalRevenue'] ?? 0) > 0 ? (($periodStats['totalGrossMargin'] ?? 0) / $periodStats['totalRevenue']) * 100 : 0; $totalRevenue = $periodStats['totalRevenue'] ?? 0; // Actual revenue (excludes refunded amounts) $totalGrossRevenue = $periodStats['totalGrossRevenue'] ?? 0; // Gross sales including refunds/cancellations $totalCOGS = $periodStats['totalCOGS'] ?? 0; // Calculate COGS % using actual revenue (money we kept, not refunded amounts) // For refunds/cancellations, revenue = $0 but COGS still incurred $rawCogsPercent = $totalRevenue > 0 ? ($totalCOGS / $totalRevenue) * 100 : 0; // Apply -0.5% adjustment to align with Income Statement (accounts for PS orders etc.) $cogsAdjustment = $periodStats['cogsAdjustmentPercent'] ?? -0.5; $cogsPercent = $rawCogsPercent + $cogsAdjustment; $isLossRateNormalized = $periodStats['isLossRateNormalized'] ?? true; $lossRateAdjustment = $periodStats['lossRateAdjustment'] ?? 0; @endphp

Period Statistics @if(!$ignoreDates && !empty($fromDate) && !empty($toDate)) ({{ \Carbon\Carbon::parse($fromDate)->format('M d') }} - {{ \Carbon\Carbon::parse($toDate)->format('M d, Y') }}) @else (All Time) @endif

{{ number_format($periodStats['uniqueOrders'] ?? 0) }}
Orders
${{ number_format($totalRevenue, 0) }}
Revenue
{{ number_format($avgGrossProfit, 1) }}%
Avg Margin %
{{ $periodStats['positiveCalculatedProfit'] ?? 0 }} / {{ $periodStats['negativeCalculatedProfit'] ?? 0 }}
Profit Split
{{ number_format($cogsPercent, 1) }}% @if(!$isLossRateNormalized) * @endif
COGS % (Adj)
{{ number_format($accuracyPercent, 1) }}%
Data Accuracy
Reference Information

Order Details

@if($this->orders->count() > 0) @foreach($this->orders as $order) @php // Check if own stock $isOwnStock = \App\Models\Note::where('order_id', $order->order_id) ->where(function($q) { $q->whereRaw("LOWER(note) LIKE '%own stock%'") ->orWhereRaw("LOWER(note) LIKE '%our stock%'"); })->exists(); $confidence = $order->confidence_level; $profitClass = $order->gross_profit < 0 ? 'negative-profit' : 'positive-profit'; if($isOwnStock) { $profitClass .= ' own-stock'; } // V2 COGS Calculation: our_buy_price + commission_and_fee + payment_processor_fee - supplier_credits + additional_cost $goodSoldCost = ($order->our_buy_price ?: 0) + ($order->commission_and_fee ?: 0) + ($order->payment_processor_fee ?: 0) - ($order->supplier_credits ?: 0) + ($order->additional_cost ?: 0); // Calculate COGS % - handle refunds/cancellations where revenue is effectively $0 // For Total Loss Refunds (48), Regular Refunds (24,27,34,41,52), Cancellations (7,33,49,51) $refundCancellationStatuses = [7, 24, 27, 33, 34, 41, 48, 49, 51, 52]; if (in_array($order->current_status, $refundCancellationStatuses)) { // For refunds/cancellations, we have $0 revenue, so COGS % is effectively infinite // Show as N/A since dividing by zero is undefined $cogsPercent = null; // Will display as "N/A" $cogsClass = 'text-danger'; } else { // Normal orders: COGS % = (COGS / Revenue) * 100 $cogsPercent = $order->sales_price > 0 ? ($goodSoldCost / $order->sales_price) * 100 : 0; $cogsClass = $cogsPercent >= 100 ? 'text-danger' : ($cogsPercent >= 70 ? 'text-warning' : 'text-success'); } // Calculate comprehensive metrics (for other uses) $amazonAdditionalCost = (strtolower($order->sales_channel) === 'amazon') ? ($order->amazon_additional_cost ?: 0) : 0; $totalCosts = $order->our_buy_price + ($order->commission_and_fee ?: 0) + ($order->channel_advertisement_fee_amount ?: 0) + ($order->payment_processor_fee ?: 0) + ($order->repayment_processor_fees ?: 0) + ($order->additional_cost ?: 0) + $amazonAdditionalCost + ($order->label_cost ?: 0); $totalCredits = ($order->usauto_rebate ?: 0) + ($order->supplier_credits ?: 0) + ($order->carrier_credits ?: 0); $calculatedGrossMargin = $order->sales_price - $totalCosts + $totalCredits; $calculatedGrossProfit = $order->sales_price > 0 ? (($calculatedGrossMargin / $order->sales_price) * 100) : 0; @endphp
Order / Date
#{{ $order->external_order_id }} @if(!empty($order->remarks) && trim($order->remarks) !== 'EXACT_MATCH') @php $flagColor = '#dc3545'; // Default red $flagTitle = htmlspecialchars($order->remarks); if(trim($order->remarks) === 'DATE_PART_MATCH') { $flagColor = '#ffc107'; // Yellow } elseif(trim($order->remarks) === 'NO_SUPPLIER_DATA') { $flagColor = '#dc3545'; // Red } @endphp @endif @if(!empty($order->fee_data_source)) @php $feeDisplay = ''; $feeColor = '#6c757d'; // Default gray $feeTitle = ''; if(trim($order->fee_data_source) === 'Actual') { $feeDisplay = '='; // = sign for actual $feeColor = '#28a745'; // Green $feeTitle = 'Fee Data: Actual'; } elseif(trim($order->fee_data_source) === 'Estimated') { $feeDisplay = '≈'; // ≈ sign for estimated $feeColor = '#ff9800'; // Orange $feeTitle = 'Fee Data: Estimated'; } @endphp @if($feeDisplay) {{ $feeDisplay }} @endif @endif
{{ \Carbon\Carbon::parse($order->date_placed)->format('M d, Y') }}
@php // Determine status badge color $statusColor = '#6c757d'; // Default gray $statusName = $order->status_name ?: 'N/A'; if (in_array($statusName, ['Shipped', 'Local Delivered'])) { $statusColor = '#28a745'; // Green for shipped } elseif (in_array($statusName, ['Ordered', 'Sent to SS', 'Local Ordered'])) { $statusColor = '#007bff'; // Blue for ordered } elseif (in_array($statusName, ['Cancelled', 'Local Cancelled', 'Cancelled - Not Purchased', 'Please Cancel'])) { $statusColor = '#dc3545'; // Red for cancelled } elseif (in_array($statusName, ['Pending Return', 'Return Refunded', 'Local Refunded', 'Total Loss Refund'])) { $statusColor = '#ffc107'; // Yellow for returns } elseif ($statusName === 'Needs Order') { $statusColor = '#6c757d'; // Gray for needs order } @endphp
{{ $statusName }}
Product / Category
{{ $order->partslink }}
{{ $order->category }}
Supplier
{{ $order->supplier ?: 'N/A' }}
Channel / Customer
{{ $order->sales_channel }}
{{ \Illuminate\Support\Str::limit($order->billing_name ?? 'N/A', 25) }}
Sale
${{ number_format($order->sales_price, 2) }}
Cost
${{ number_format($order->our_buy_price, 2) }}
COGS
${{ number_format($goodSoldCost, 2) }}
COGS %
{{ $cogsPercent !== null ? number_format($cogsPercent, 1) . '%' : 'N/A' }}
Gross Profit
{{ $order->gross_profit < 0 ? '-' : '' }}${{ number_format(abs($order->gross_profit), 2) }}
Gross Margin
{{ number_format($order->gross_margin, 1) }}%
@if($isOwnStock) Own Stock @else {{ ucfirst($confidence) }} @endif
@php // Calculate commission and fees for yellow/red boxes $commissionAmount = $order->commission_and_fee ?: ($order->sales_price * ($order->channel_commission / 100)); $categoryDiscountPercentage = $order->category_discount_percentage ?: 0; @endphp
Product Details

Item: {{ $order->item_name }}

Item #: {{ $order->order_item_id }}

Partslink: {{ $order->partslink }}

Supplier: {{ $order->supplier ?: 'N/A' }}

Pricing Breakdown

Sale: ${{ number_format($order->item_sale_price, 2) }} + ${{ number_format($order->item_shipping, 2) }} = ${{ number_format($order->sales_price, 2) }}

Buy: @if($order->usauto_rebate > 0) ${{ number_format($order->supplier_price, 2) }} + ${{ number_format($order->supplier_shipping, 2) }} + ${{ number_format($order->supplier_handling, 2) }} - ${{ number_format($order->usauto_rebate, 2) }} = @else ${{ number_format($order->supplier_price, 2) }} + ${{ number_format($order->supplier_shipping, 2) }} + ${{ number_format($order->supplier_handling, 2) }} = @endif ${{ number_format($order->our_buy_price, 2) }}

@if($order->buy_price_source)

Source: {{ $order->buy_price_source }}

@endif @if($order->our_shipping_source)

Shipping: {{ $order->our_shipping_source }}

@endif
Fees & Commissions

Channel Commission: {{ number_format($order->channel_commission, 2) }}%

@if($order->channel_advertisement_fee_amount > 0)

Advertisement Fee: ${{ number_format($order->channel_advertisement_fee_amount, 2) }}

@endif @php // Local orders are B2B with b2b_delivery_model_id > 1 - don't show category discount for them $isLocalOrder = strtolower($order->sales_channel) === 'b2b' && ($order->b2b_delivery_model_id ?? 0) > 1; @endphp @if($categoryDiscountPercentage > 0 && !$isLocalOrder)

Category Discount: {{ number_format($categoryDiscountPercentage, 2) }}%

@endif @if(strtolower($order->sales_channel) === 'amazon' && ($order->amazon_additional_cost ?? 0) > 0)

Amazon Additional Cost: ${{ number_format($order->amazon_additional_cost, 2) }}

@endif @if($order->additional_cost > 0)

Additional Cost: ${{ number_format($order->additional_cost, 2) }}

@endif @if($order->label_cost > 0)

Label Cost: ${{ number_format($order->label_cost, 2) }}

@endif
Customer Information

Name: {{ $order->billing_name }}

Address: {{ $order->billing_address }}

@if(!empty($order->remarks))

Remarks:
{{ $order->remarks }}

@endif @if(!empty($order->fee_data_source))

Fee Data Source:
{{ trim($order->fee_data_source) === 'Actual' ? '= ' : '≈ ' }}{{ htmlspecialchars($order->fee_data_source) }}
{{ trim($order->fee_data_source) === 'Actual' ? 'Commission and fees are based on actual data' : 'Commission and fees are estimated' }}

@endif
COGS Breakdown (V2)

Our Buy Price: ${{ number_format($order->our_buy_price, 2) }}

Commission & Fee: ${{ number_format($order->commission_and_fee ?: 0, 2) }}

Payment Processor Fee: ${{ number_format($order->payment_processor_fee ?: 0, 2) }}

Additional Cost: +${{ number_format($order->additional_cost ?: 0, 2) }}

@if(($order->supplier_credits ?: 0) > 0)

Supplier Credits: -${{ number_format($order->supplier_credits, 2) }}

@endif

Total COGS: ${{ number_format($goodSoldCost, 2) }}

COGS %: {{ $cogsPercent !== null ? number_format($cogsPercent, 1) . '%' : 'N/A' }}

V2: Buy + Comm + Proc - SupCred + Add

Gross Profit & Margin

Gross Profit: ${{ number_format($order->gross_profit, 2) }}

Gross Margin: {{ number_format($order->gross_margin, 1) }}%

Formula: (Sale - COGS) / Sale × 100

@endforeach @else
No orders found matching the selected filters.
@endif
@if($this->orders->hasPages())
{{ $this->orders->links() }}
@endif