@extends('layouts.app') @section('title', 'Sales Invoice') @section('content')
Download PDF @if(\App\Helpers\PermissionHelper::isSuperUser(auth()->id())) @endif

Your Company Name

123 Business Street
City, State 12345
Phone: (123) 456-7890
Email: info@yourcompany.com

SALES INVOICE

Invoice No: {{ $invoice->invoice_no }}

@if($invoice->customer_invoice)

Customer Invoice: {{ $invoice->customer_invoice }}

@endif

Date: {{ $invoice->invoice_date->format('M d, Y') }}

@if($invoice->payment_due)

Due Date: {{ $invoice->payment_due->format('M d, Y') }}

@endif

Bill To:

{{ $invoice->customer_name ?? ($invoice->customer ? $invoice->customer->name : 'N/A') }}

@if($invoice->customer_email)

{{ $invoice->customer_email }}

@endif @if($invoice->customer_phone)

{{ $invoice->customer_phone }}

@endif @if($invoice->customer_address)

{{ $invoice->customer_address }}

@endif @if($invoice->contact_person)

Contact Person: {{ $invoice->contact_person }}

@endif

Invoice Summary:

Invoice Month: {{ $invoice->invoice_month }}
Status: {{ ucfirst($invoice->status) }}
Payment Status: {{ ucfirst($invoice->payment_status) }}
Paid Amount: BDT {{ number_format($invoice->paid_amount ?? 0, 2) }}
@php // Group items by connection type, maintaining insertion order $groupedItems = []; $connectionTypeOrder = []; $lastConnectionType = null; foreach ($invoice->items as $item) { $connectionTypeName = $item->connectionType ? $item->connectionType->name : 'No Connection Type'; // If this is a new connection type, create a new group if ($connectionTypeName !== $lastConnectionType) { if (!isset($groupedItems[$connectionTypeName])) { $groupedItems[$connectionTypeName] = []; $connectionTypeOrder[] = $connectionTypeName; } $lastConnectionType = $connectionTypeName; } // Add item to current group if (!isset($groupedItems[$connectionTypeName])) { $groupedItems[$connectionTypeName] = []; if (!in_array($connectionTypeName, $connectionTypeOrder)) { $connectionTypeOrder[] = $connectionTypeName; } } $groupedItems[$connectionTypeName][] = $item; } $rowNumber = 1; @endphp @foreach($connectionTypeOrder as $connectionTypeName) @if(isset($groupedItems[$connectionTypeName]) && count($groupedItems[$connectionTypeName]) > 0) @php // Get the first item's note for this connection type (all items should have same note) $connectionTypeNote = null; foreach ($groupedItems[$connectionTypeName] as $item) { if (!empty($item->note)) { $connectionTypeNote = $item->note; break; } } @endphp @foreach($groupedItems[$connectionTypeName] as $item) @php $rowNumber++; @endphp @endforeach @endif @endforeach
# Item Description Unit Quantity Rate VAT % VAT Amount Period Total
Connection Type: {{ $connectionTypeName }}@if($connectionTypeNote) - {{ $connectionTypeNote }}@endif
{{ $rowNumber }} {{ $item->item_name ?? 'Custom Item' }} @if($item->description)
{{ $item->description }} @endif
{{ $item->unit ?? '-' }} {{ number_format($item->quantity, 2) }} BDT {{ number_format($item->rate, 2) }} {{ number_format($item->vat_percentage, 2) }}% BDT {{ number_format($item->total_vat, 2) }} @if($item->from_date && $item->to_date) {{ $item->from_date->format('M d') }} - {{ $item->to_date->format('M d, Y') }} @elseif($item->from_date) From {{ $item->from_date->format('M d, Y') }} @elseif($item->to_date) Until {{ $item->to_date->format('M d, Y') }} @else - @endif BDT {{ number_format($item->total_amount, 2) }}
@if($invoice->discount_amount > 0) @endif
Subtotal: BDT {{ number_format($invoice->invoice_amount + $invoice->discount_amount, 2) }}
Discount ({{ $invoice->discount_type ?? 'Amount' }}): -BDT {{ number_format($invoice->discount_amount, 2) }}
Total Amount: BDT {{ number_format($invoice->invoice_amount, 2) }}
Paid Amount: BDT {{ number_format($invoice->paid_amount ?? 0, 2) }}
Due Amount: BDT {{ number_format($invoice->due_amount, 2) }}
@if($advancePayments->count() > 0)

Advance Payments

@foreach($advancePayments as $index => $advancePayment) @endforeach
# Reference Number Amount Remaining Payment Method Payment Date Status Created By Description
{{ $index + 1 }} {{ $advancePayment->reference_number }} BDT {{ number_format($advancePayment->amount, 2) }} BDT {{ number_format($advancePayment->remaining_amount, 2) }} {{ $advancePayment->payment_method }} {{ $advancePayment->payment_date->format('M d, Y') }} @if($advancePayment->status === 'active') Active @elseif($advancePayment->status === 'used') Used @elseif($advancePayment->status === 'expired') Expired @endif {{ $advancePayment->createdBy->name ?? 'System' }} {{ Str::limit($advancePayment->description, 50) }}
Total Advance Payments: BDT {{ number_format($advancePayments->sum('amount'), 2) }} BDT {{ number_format($advancePayments->sum('remaining_amount'), 2) }}
@endif @if($paymentTransactions->count() > 0)

Payment History

@foreach($paymentTransactions as $index => $transaction) @endforeach
# Transaction Type Payment Method Account Holder Account Name Bank Account Account Number Received By Received Amount Transaction Date
{{ $index + 1 }} {{ ucfirst($transaction->transaction_type) }} {{ $transaction->payment_method ?? 'N/A' }} {{ optional($transaction->accountHolderInfo)->name ?? 'N/A' }} {{ $transaction->bankAccountInfo->account_name ?? 'N/A' }} {{ $transaction->bankAccountInfo->bank_name ?? ($transaction->bank_account ?? 'N/A') }} @if($transaction->bankAccountInfo && $transaction->bankAccountInfo->account_number) {{ $transaction->bankAccountInfo->account_number }} @else N/A @endif {{ $transaction->received_by ?? 'N/A' }} BDT {{ number_format($transaction->amount, 2) }} {{ $transaction->transaction_date->format('M d, Y') }}
Total Payments: BDT {{ number_format($paymentTransactions->where('transaction_type', 'payment')->sum('amount'), 2) }}
@endif @if($invoice->notes)

Notes:

{{ $invoice->notes }}

@endif
@endsection @push('styles') @endpush @push('scripts') @endpush