54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\InvoiceValidation;
|
|
use Livewire\Component;
|
|
|
|
class InvoiceDataTable extends Component
|
|
{
|
|
|
|
public $invoiceData = [];
|
|
|
|
public string $invoiceNumber = '';
|
|
|
|
public bool $hasSearched = false;
|
|
|
|
protected $listeners = ['refreshInvoiceData' => 'loadData'];
|
|
|
|
public function loadData($invoiceNumber)
|
|
{
|
|
$this->invoiceNumber = $invoiceNumber;
|
|
$this->hasSearched = true;
|
|
|
|
$this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber)
|
|
->get()
|
|
->map(function ($record) {
|
|
return [
|
|
'sticker_master_id' => $record->sticker_master_id,
|
|
'serial_number' => $record->serial_number,
|
|
'motor_scanned_status' => $record->motor_scanned_status,
|
|
'pump_scanned_status' => $record->pump_scanned_status,
|
|
'capacitor_scanned_status' => $record->capacitor_scanned_status,
|
|
'scanned_status_set' => $record->scanned_status_set,
|
|
'panel_box_supplier' => $record->panel_box_supplier,
|
|
'panel_box_serial_number' => $record->panel_box_serial_number,
|
|
'scanned_status' => $record->scanned_status,
|
|
];
|
|
})
|
|
|
|
->toArray();
|
|
|
|
//Loop through and replace 'code' using related StickerMaster > Item > code
|
|
foreach ($this->invoiceData as &$row) {
|
|
$stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null);
|
|
$row['code'] = $stickerMaster?->item?->code ?? 'N/A';
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.invoice-data-table');
|
|
}
|
|
}
|