Tax Report

Generated on: {{ now()->format('Y-m-d H:i') }}

@php $totalNet = 0; $totalTax = 0; $totalGross = 0; @endphp @foreach($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; $itemTax = 0; $rate = 0; if ($storedTax > 0) { $itemTax = $storedTax; $rate = ($storedRate > 0) ? $storedRate : ($item->product ? ($item->product->tax_code ?? 18) : 18); } elseif (isset($settings) && $settings->product_tax_enabled) { $rate = $item->product ? ($item->product->tax_code ?? 18) : 18; $itemTax = $itemGross * ($rate / (100 + $rate)); } $rateKey = (string) $rate; $itemNet = $itemGross - $itemTax; 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 if ($orderShipping > 0) { $shippingTax = 0; $shippingNet = $orderShipping; $shippingLabel = 'Shipping'; 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) { $shippingTax = $orderShipping * ($shippingTaxRate / (100 + $shippingTaxRate)); $shippingNet = $orderShipping - $shippingTax; $shippingLabel = 'Shipping (' . (float) $shippingTaxRate . '%)'; } $groups['Shipping'] = [ 'rate' => $shippingLabel, 'net' => $shippingNet, 'tax' => $shippingTax, 'gross' => $orderShipping ]; } ksort($groups); $rowCount = count($groups); if ($rowCount == 0) continue; $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 @endforeach
Date Order No Customer Tax Rate Net Sales (Excl. Tax) Tax (GST) Total Sales
{{ $order->created_at->format('Y-m-d') }} {{ $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) }}
Total ₹{{ number_format($totalNet, 2) }} ₹{{ number_format($totalTax, 2) }} ₹{{ number_format($totalGross, 2) }}