@vite(['resources/css/app.css', 'resources/js/app.js']) @include('admin.partials.styles') @include('admin.partials.sidebar')

Tax Report

Period:
to
@php $totalNet = 0; $totalTax = 0; $totalGross = 0; @endphp @forelse($orders as $order) @php $groups = []; $orderShipping = $order->shipping_cost ?? 0; // Process Items if ($order->items) { foreach ($order->items as $item) { $itemGross = $item->price * $item->quantity; $storedTax = (float) $item->tax_amount; $storedRate = (float) $item->tax_rate; $rate = 0; $itemTax = 0; if ($storedTax > 0) { // 1. Priority: Stored Historical Data $itemTax = $storedTax; // Use stored rate if valid, else fallback to current product definition $rate = ($storedRate > 0) ? $storedRate : ($item->product ? ($item->product->tax_code ?? 18) : 18); } elseif (isset($settings) && $settings->product_tax_enabled) { // 2. Fallback: Calculation (Back-calculate) $rate = $item->product ? ($item->product->tax_code ?? 18) : 18; $itemTax = $itemGross * ($rate / (100 + $rate)); } $rateKey = (string) $rate; // key for grouping $itemNet = $itemGross - $itemTax; // Add to Group if (!isset($groups[$rateKey])) { $groups[$rateKey] = [ 'rate' => $rate, 'net' => 0, 'tax' => 0, 'gross' => 0 ]; } $groups[$rateKey]['net'] += $itemNet; $groups[$rateKey]['tax'] += $itemTax; $groups[$rateKey]['gross'] += $itemGross; } } // Add Shipping as a group if exists if ($orderShipping > 0) { $shippingTax = 0; $shippingNet = $orderShipping; $shippingLabel = 'Shipping'; // Check stored tax if ($order->shipping_tax_amount > 0) { $shippingTax = $order->shipping_tax_amount; $shippingNet = $orderShipping - $shippingTax; $rate = $order->shipping_tax_rate > 0 ? $order->shipping_tax_rate : 0; $shippingLabel = 'Shipping (' . (float) $rate . '%)'; } elseif (isset($settings) && $settings->shipping_tax_enabled && isset($shippingTaxRate) && $shippingTaxRate > 0) { // Inclusive Tax Calculation: Tax = Gross * (Rate / (100 + Rate)) $shippingTax = $orderShipping * ($shippingTaxRate / (100 + $shippingTaxRate)); $shippingNet = $orderShipping - $shippingTax; $shippingLabel = 'Shipping (' . (float) $shippingTaxRate . '%)'; } $groups['Shipping'] = [ 'rate' => $shippingLabel, 'net' => $shippingNet, 'tax' => $shippingTax, 'gross' => $orderShipping ]; } // Sort groups by rate (numeric) then strings ksort($groups); $rowCount = count($groups); if ($rowCount == 0) continue; // Should not happen for valid orders usually $firstRow = true; @endphp @foreach($groups as $key => $data) @php $totalNet += $data['net']; $totalTax += $data['tax']; $totalGross += $data['gross']; @endphp @if($firstRow) @endif @php $firstRow = false; @endphp @endforeach @empty @endforelse
Date Order No. Customer Tax Rate Net Sales (Excl. Tax) Tax (GST) Total Sales
{{ $order->created_at->format('M d, Y') }} #{{ $order->order_number }} {{ $order->user ? $order->user->name : ($order->name ?: 'Guest') }} {{ is_numeric($data['rate']) ? $data['rate'] . '%' : $data['rate'] }} ₹{{ number_format($data['net'], 2) }} ₹{{ number_format($data['tax'], 2) }} ₹{{ number_format($data['gross'], 2) }}
No tax data found for the selected period.
Total ₹{{ number_format($totalNet, 2) }} ₹{{ number_format($totalTax, 2) }} ₹{{ number_format($totalGross, 2) }}
{{ $orders->links() }}