Merge pull request 'Added invoice pending livewire pages' (#235) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s

Reviewed-on: #235
This commit was merged in pull request #235.
This commit is contained in:
2026-01-23 05:13:30 +00:00
2 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
<?php
namespace App\Livewire;
use App\Models\InvoiceDataValidation;
use App\Models\InvoiceOutValidation;
use App\Models\PalletValidation;
use Livewire\Component;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\InvoicePendingReasonExport;
use App\Models\Plant;
class InvoicePending extends Component
{
public $plantId;
public $invoicePending = [];
protected $listeners = [
'loadData' => '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');
}
}

View File

@@ -0,0 +1,45 @@
<div class="p-4">
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
PENDING INVOICE DATA TABLE:
</h2>
<div class="overflow-x-auto rounded-lg shadow">
<table class="w-full divide-y divide-gray-200 text-sm text-center">
<thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
<tr>
<th class="border px-4 py-2">No</th>
<th class="border px-4 py-2">Plant Code</th>
<th class="border px-4 py-2">Document Number</th>
<th class="border px-4 py-2">Customer Trade Location</th>
<th class="border px-4 py-2">Location</th>
<th class="border px-4 py-2">Remark</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@if (empty($invoicePending))
<tr>
<td colspan="6" class="px-4 py-4 text-center text-gray-500">
Please select plant to load pending invoice.
</td>
</tr>
@else
@forelse ($invoicePending as $index => $locator)
<tr class="hover:bg-gray-50">
<td class="border px-4 py-2">{{ $index + 1 }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['plant_id'] ?? '-' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['document_number'] ?? '-' }}</td>
<td class="border px-4 py-2">{{ $locator['customer_trade_name'] ?? '-' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['location'] ?? '-' }}</td>
<td class="border px-4 py-2 whitespace-nowrap">{{ $locator['remark'] ?? '-' }}</td>
</tr>
@empty
<tr>
<td colspan="9" class="px-4 py-4 text-center text-gray-500">
No invoice pending records found.
</td>
</tr>
@endforelse
@endif
</tbody>
</table>
</div>
</div>