@php // Safely get invoice settings with null checks $invoiceSettings = $invoiceSettings ?? new stdClass(); // dd($invoiceSettings); $bankDetails = [ 'bank_name' => $invoiceSettings->bank_name ?? '', 'account_name' => $invoiceSettings->account_name ?? '', 'account_number' => $invoiceSettings->account_number ?? '', 'ifsc_code' => $invoiceSettings->ifsc_code ?? '', ]; $footerText = $invoiceSettings->footer_text ?? ''; // Ensure required variables exist $company_name = $company_name ?? config('app.name', 'Company Name'); $company_logo = $company_logo ?? null; $invoice = $invoice ?? null; $tenant = $tenant ?? null; $items = $items ?? collect(); @endphp @if ($invoice)
{{ strtoupper($invoice->status ?? 'NEW') }}
@endif
@if ($invoice)
{{ ucfirst($invoice->status ?? 'New') }}
INVOICE
{{ t('invoice') }} #: {{ $invoice->invoice_number ?? format_draft_invoice_number() }}
{{ t('date') }}: {{ $invoice->created_at ? $invoice->created_at->format('F j, Y') : date("F j, Y") }}
@foreach ($transactions as $transaction) {{ t('transaction_id') }}: @if ($transaction->type === 'offline') {{ $transaction->metadata['payment_reference'] ?? '-' }} @else {{ $transaction->idempotency_key ?? '-' }} @endif @endforeach
@endif

{{ t('from') }}

{{ $company_name }}
@if (isset($invoiceSettings->company_address) && !empty($invoiceSettings->company_address)) {!! nl2br(e($invoiceSettings->company_address)) !!} @endif
@if ($tenant)

{{ t('bill_to') }}

{{ $tenant->billing_name ?? ($tenant->company_name ?? 'Customer') }}
@if (!empty($tenant->billing_address)) {!! nl2br(e($tenant->billing_address)) !!}@if (!empty($tenant->billing_city)) , @endif
@endif @if (!empty($tenant->billing_city)) {{ $tenant->billing_city }}@if (!empty($tenant->billing_state)) , {{ $tenant->billing_state }} @endif {{ $tenant->billing_zip_code ?? '' }}
@endif @if (!empty($tenant->billing_phone)) {{ $tenant->billing_phone }}
@endif @if (!empty($tenant->billing_email)) {{ $tenant->billing_email }} @endif
@endif
@if ($items && $items->count() > 0) @foreach ($items as $item) @endforeach
{{ t('description') }} {{ t('price') }} {{ t('quantity') }} {{ t('amount') }}
{{ $item->title ?? 'Item' }}
@if (!empty($item->description))
{!! nl2br(e($item->description)) !!}
@endif
{{ $invoice ? $invoice->formatAmount($item->amount ?? 0) : number_format($item->amount ?? 0, 2) }} {{ $item->quantity ?? 1 }} {{ $invoice ? $invoice->formatAmount(($item->amount ?? 0) * ($item->quantity ?? 1)) : number_format(($item->amount ?? 0) * ($item->quantity ?? 1), 2) }}
@endif @if ($invoice)
@php $taxDetails = $invoice->getTaxDetails(); $subtotal = $invoice->subTotal(); $calculatedTaxAmount = 0; // Calculate actual tax amount if needed foreach ($taxDetails as $tax) { $amt = $tax['amount'] ?? 0; if ($amt <= 0 && ($tax['rate'] ?? 0)> 0) { $amt = $subtotal * (($tax['rate'] ?? 0) / 100); } $calculatedTaxAmount += $amt; } $fee = $invoice->fee ?? 0; $calculatedTotal = $subtotal + $calculatedTaxAmount + $fee; @endphp @if (count($taxDetails) > 0) @foreach ($taxDetails as $tax) @endforeach @else @endif @if ($fee > 0) @endif @if (count($creditTransactions) > 0) @endif
{{ t('subtotal') }} {{ $invoice->formatAmount($subtotal) }}
{{ $tax['name'] ?? 'Tax' }} ({{ $tax['formatted_rate'] ?? '0%' }}) {{ ($tax['amount'] ?? 0) <= 0 && ($tax['rate'] ?? 0)> 0 ? $invoice->formatAmount($subtotal * (($tax['rate'] ?? 0) / 100)) : $tax['formatted_amount'] ?? $invoice->formatAmount(0) }}
{{ t('tax ') }}(0%) {{ $invoice->formatAmount(0) }}
{{ t('fee') }} {{ $invoice->formatAmount($fee) }}
{{ t('credit_applied') }} @php $credits = $creditTransactions->sum('amount'); if ($credits > $calculatedTotal) { $credits = $calculatedTotal; } @endphp {{ '- ' . $invoice->formatAmount($credits) }}
{{ $invoice->status == 'paid' ? t('amount_paid') : t('amount_due') }} @php $finalamount = $calculatedTotal - $credits; @endphp {{ $invoice->formatAmount($finalamount) }}
{{ t('total') }} {{ $invoice->formatAmount($calculatedTotal) }}
@endif
@if ($invoice && $invoice->status === 'paid')
{{ t('payment_information') }}
{{ t('paid_on') }} {{ $invoice->paid_at ? $invoice->paid_at->format('F j, Y') : 'N/A' }}
{{ t('payment_received_message') }}
@endif