@extends('layouts/layoutMaster') @section('title', 'Sales Invoice') @section('vendor-style') @vite('resources/assets/vendor/libs/flatpickr/flatpickr.scss') @endsection @section('page-style') @vite('resources/assets/vendor/scss/pages/app-invoice.scss') @endsection @section('vendor-script') @vite([ 'resources/assets/vendor/libs/moment/moment.js', 'resources/assets/vendor/libs/flatpickr/flatpickr.js', 'resources/assets/vendor/libs/cleavejs/cleave.js', 'resources/assets/vendor/libs/cleavejs/cleave-phone.js' ]) @endsection {{-- @section('page-script') @vite([ 'resources/assets/js/offcanvas-add-payment.js', 'resources/assets/js/offcanvas-send-invoice.js' ]) @endsection --}} @section('content')
Sales Order/Proforma Invoice
@if($dealer) {{ $dealer->name }}

{{ $dealer->office_address }}

{{ $dealer->email }}

{{ $dealer->phone_no }}

@endif
@if($order)
SO Date: {{ $order->so_date }}
SO Number: {{ $order->so_number }}
@endif

@if($order->orderItems->isNotEmpty()) @php $firstItem = $order->orderItems->first(); @endphp @if($firstItem && $firstItem->product && $firstItem->product->company)

Plot No: {{ $firstItem->product->company->billing_address }}

Phone No: {{ $firstItem->product->company->phone }} | Email: {{ $firstItem->product->company->email }}

GST: {{ $firstItem->product->company->gst }} | CIN No: {{ $firstItem->product->company->cin_no }}

@endif @endif
@php $itemIndex = 1; $totalSgst = 0; $totalCgst = 0; $totalIgst = 0; @endphp @foreach($order->orderItems as $item) @php $sgstAmount = 0; $cgstAmount = 0; $igstAmount = 0; $vendorState = $dealer->state ?? null; $companyBillingState = $firstItem->product->company->billing_state ?? null; // Fetch GST rates directly from the material $cgstRate = (float) $item->cgst ?? 0; $sgstRate = (float) $item->sgst ?? 0; $igstRate = (float) $item->igst ?? 0; // {{ dd($cgstRate); }} $itemNetPrice = $item->sales_amt_aft_discount; // $subtotal += $itemNetPrice; if ($vendorState && $companyBillingState) { if ($vendorState == $companyBillingState) { $sgstAmount = ($itemNetPrice * $sgstRate / 100); $cgstAmount = ($itemNetPrice * $cgstRate / 100); $gstType = "CGST ({$cgstRate}%)
SGST ({$sgstRate}%)"; } else { $igstAmount = ($itemNetPrice * $igstRate / 100); $gstType = "IGST ({$igstRate}%)"; } } else { $gstType = "GST data missing"; } // Accumulate totals $totalSgst += $sgstAmount; $totalCgst += $cgstAmount; $totalIgst += $igstAmount; $itemTotal = $itemNetPrice + $sgstAmount + $cgstAmount + $igstAmount; @endphp @endforeach
S.No Details Qty Free Qty Pack Style Sales Rate Sales Amount Discount After Discount GST GST Amount Total
{{ $itemIndex++ }} {{ $item->product->code }}
{{ $item->product->name }}
{{ $item->product->hsn_code }}
{{ $item->product->specification }}
{{ $item->quantity }}
{{ $item->product->uom ? $item->product->uom->name : '' }}
{{ $item->free_qty }}
{{ $item->product->uom ? $item->product->uom->name : '' }}
{{ $item->pack_style1 }} X {{ $item->pack_style2 }} {{ number_format($item->sales_rate, 2) }} {{ number_format($item->sales_amount, 2) }} {{ number_format($item->discount, 2) }} {{ number_format($item->sales_amt_aft_discount, 2) }} {!! $gstType !!} @if ($vendorState == $companyBillingState) SGST: {{ number_format($sgstAmount, 2) }}
CGST: {{ number_format($cgstAmount, 2) }} @else IGST: {{ number_format($igstAmount, 2) }} @endif
{{-- Price: {{ number_format($itemNetPrice, 2) }}
@if ($vendorState == $companyBillingState) SGST: {{ number_format($sgstAmount, 2) }}
CGST: {{ number_format($cgstAmount, 2) }}
@else IGST: {{ number_format($igstAmount, 2) }}
@endif --}} Total: {{ number_format($item->Total, 2) }}

Subtotal:

Discount:

Tax:

Total:

{{ number_format($subtotal, 2) }}

₹00.00

{{ number_format($totalSgst + $totalCgst + $totalIgst, 2) }}

{{ number_format($subtotal + ($totalSgst + $totalCgst + $totalIgst), 2) }}

@php $gstGroups = []; foreach ($order->orderItems as $item) { $itemNetPrice = $item->sales_amt_aft_discount; $sgstRate = (float) $item->sgst ?? 0; $cgstRate = (float) $item->cgst ?? 0; $igstRate = (float) $item->igst ?? 0; $key = "{$sgstRate}_{$cgstRate}_{$igstRate}"; if ($dealer && $firstItem->product->company) { $vendorState = $dealer->state; $companyState = $firstItem->product->company->billing_state; if ($vendorState === $companyState) { $sgstAmount = ($itemNetPrice * $sgstRate / 100); $cgstAmount = ($itemNetPrice * $cgstRate / 100); $igstAmount = 0; } else { $sgstAmount = 0; $cgstAmount = 0; $igstAmount = ($itemNetPrice * $igstRate / 100); } if (!isset($gstGroups[$key])) { $gstGroups[$key] = [ 'sgstAmount' => 0, 'cgstAmount' => 0, 'igstAmount' => 0, 'totalNetPrice' => 0, 'sgstRate' => $sgstRate, 'cgstRate' => $cgstRate, 'igstRate' => $igstRate, ]; } $gstGroups[$key]['totalNetPrice'] += $itemNetPrice; $gstGroups[$key]['sgstAmount'] += $sgstAmount; $gstGroups[$key]['cgstAmount'] += $cgstAmount; $gstGroups[$key]['igstAmount'] += $igstAmount; } } @endphp @foreach($gstGroups as $group) @endforeach
Taxable Value SGST (%) SGST Amount CGST (%) CGST Amount IGST (%) IGST Amount
{{ number_format($group['totalNetPrice'], 2) }} {{ number_format($group['sgstRate'], 2) }} {{ number_format($group['sgstAmount'], 2) }} {{ number_format($group['cgstRate'], 2) }} {{ number_format($group['cgstAmount'], 2) }} {{ number_format($group['igstRate'], 2) }} {{ number_format($group['igstAmount'], 2) }}

Note: It was a pleasure working with you and your team. We hope you will keep us in mind for future freelance projects. Thank You!
@include('_partials/_offcanvas/offcanvas-send-invoice') @include('_partials/_offcanvas/offcanvas-add-payment') @endsection