From b66216bb9089c6c2973a720ec3747c7d923bcdb2 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 23 Jan 2026 10:43:20 +0530 Subject: [PATCH] Added invoice pending livewire pages --- app/Livewire/InvoicePending.php | 125 ++++++++++++++++++ .../views/livewire/invoice-pending.blade.php | 45 +++++++ 2 files changed, 170 insertions(+) create mode 100644 app/Livewire/InvoicePending.php create mode 100644 resources/views/livewire/invoice-pending.blade.php diff --git a/app/Livewire/InvoicePending.php b/app/Livewire/InvoicePending.php new file mode 100644 index 0000000..eb3648d --- /dev/null +++ b/app/Livewire/InvoicePending.php @@ -0,0 +1,125 @@ + 'loadInvoiceData', + 'emptyData' => 'loadInvoiceEmptyData', + 'loadData1' => 'exportPendingReason', + ]; + + public function loadInvoiceEmptyData() + { + $this->invoicePending = []; + } + + public function loadInvoiceData($plantId) + { + $this->plantId = $plantId; + + $distributions = InvoiceDataValidation::whereNotNull('distribution_channel_desc') + ->distinct() + ->pluck('distribution_channel_desc') + ->filter(fn ($v) => trim($v) != '') + ->values() + ->toArray(); + + $distributions[] = ''; + + $pendingInvoices = collect(); + + foreach ($distributions as $distribution) { + + $invoices = InvoiceDataValidation::where('plant_id', $plantId) + ->where('distribution_channel_desc', $distribution) + ->select( + 'id', + 'document_number', + 'customer_trade_name', + 'location', + 'remark', + 'created_at', + 'created_by', + 'updated_at', + 'updated_by' + ) + ->get() + ->unique('document_number') + ->filter(fn ($inv) => + !empty($inv->document_number) && + !str_contains($inv->document_number, '-') + ); + + if (trim($distribution) == '') { + $invoices = $invoices->filter(fn ($inv) => + str_starts_with($inv->document_number, '7') + ); + } + + if ($invoices->isEmpty()) { + continue; + } + + $invoiceNumbers = $invoices->pluck('document_number') + ->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n))) + ->toArray(); + + $wentOut = InvoiceOutValidation::whereIn('qr_code', $invoiceNumbers) + ->distinct() + ->pluck('qr_code') + ->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n))) + ->toArray(); + + $pending = $invoices->filter(function ($inv) use ($wentOut) { + $doc = preg_replace('/\s+/', '', strtoupper($inv->document_number)); + return !in_array($doc, $wentOut, true); + }); + + $pendingInvoices = $pendingInvoices->merge($pending); + } + + $plantCode = Plant::find($this->plantId)->code ?? ''; + + $this->invoicePending = $pendingInvoices + ->unique('document_number') + ->map(function ($record) use ($plantCode) { + return [ + 'plant_id' => $plantCode ?? '', + 'document_number' => $record->document_number ?? '', + 'customer_trade_name' => $record->customer_trade_name ?? '', + 'location' => $record->location ?? '', + 'remark' => $record->remark ?? '', + ]; + }) + ->values() + ->toArray(); + } + + public function exportPendingReason() + { + return Excel::download( + new InvoicePendingReasonExport($this->invoicePending), + 'invoice_pending_reason.xlsx' + ); + } + + public function render() + { + return view('livewire.invoice-pending'); + } +} diff --git a/resources/views/livewire/invoice-pending.blade.php b/resources/views/livewire/invoice-pending.blade.php new file mode 100644 index 0000000..be6d1d2 --- /dev/null +++ b/resources/views/livewire/invoice-pending.blade.php @@ -0,0 +1,45 @@ +
+

+ PENDING INVOICE DATA TABLE: +

+
+ + + + + + + + + + + + + @if (empty($invoicePending)) + + + + @else + @forelse ($invoicePending as $index => $locator) + + + + + + + + + @empty + + + + @endforelse + @endif + +
NoPlant CodeDocument NumberCustomer Trade LocationLocationRemark
+ Please select plant to load pending invoice. +
{{ $index + 1 }}{{ $locator['plant_id'] ?? '-' }}{{ $locator['document_number'] ?? '-' }}{{ $locator['customer_trade_name'] ?? '-' }}{{ $locator['location'] ?? '-' }}{{ $locator['remark'] ?? '-' }}
+ No invoice pending records found. +
+
+