{{-- DEBUG: File start --}} {{-- DEBUG: Component opened --}}
{{-- DEBUG: Root div opened --}}

Profitability Report

Filter Options Show Advanced Filters

Sales Channel & Category
Order Search
Date Range
Profit Filters
Data Accuracy Filter
Profit Range
Order Options
Supplier Filter
Price Range Filters
Item Search
Credits & Fees
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; $totalCOGS = $periodStats['totalCOGS'] ?? 0; $cogsPercent = $totalRevenue > 0 ? ($totalCOGS / $totalRevenue) * 100 : 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) }}%
COGS %
{{ 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'; } // Calculate COGS using OLD central formula // good_sold_cost = our_buy_price + commission_and_fee + payment_processor_fee + supplier_shipping + supplier_handling - supplier_credits + loss_amount $lossAmount = $order->sales_price * (($order->loss_rate ?: 0) / 100); $goodSoldCost = $order->our_buy_price + ($order->commission_and_fee ?: 0) + ($order->payment_processor_fee ?: 0) + ($order->supplier_shipping ?: 0) + ($order->supplier_handling ?: 0) - ($order->supplier_credits ?: 0) + $lossAmount; // Calculate COGS % $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->sales_price * (($order->loss_rate ?: 0) / 100)) + ($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') }}
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 %
{{ number_format($cogsPercent, 1) }}%
Gross Margin
{{ $order->gross_margin < 0 ? '-' : '' }}${{ number_format(abs($order->gross_margin), 2) }}
Gross Profit
{{ number_format($order->gross_profit, 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

Loss Rate: {{ number_format($order->loss_rate ?: 0, 2) }}%

@if($categoryDiscountPercentage > 0)

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
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

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) }}

Supplier Shipping: ${{ number_format($order->supplier_shipping ?: 0, 2) }}

Supplier Handling: ${{ number_format($order->supplier_handling ?: 0, 2) }}

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

Loss Amount ({{ number_format($order->loss_rate ?: 0, 2) }}%): ${{ number_format($lossAmount, 2) }}


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

COGS %: {{ number_format($cogsPercent, 1) }}%

Gross Profit & Margin

Gross Margin (Standard): ${{ number_format($order->gross_margin, 2) }}

Gross Profit (Standard): {{ number_format($order->gross_profit, 1) }}%

Formula: (Sale - COGS) / Sale × 100


Gross Margin (Calculated): ${{ number_format($calculatedGrossMargin, 2) }}

Gross Profit (Calculated): {{ number_format($calculatedGrossProfit, 1) }}%

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