Merge pull request 'changed loadData method in invoice data tabele in livewire' (#102) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s

Reviewed-on: #102
This commit was merged in pull request #102.
This commit is contained in:
2025-12-13 09:15:30 +00:00

View File

@@ -83,7 +83,100 @@ class InvoiceDataTable extends Component
// $this->showCapacitorInput = false; // $this->showCapacitorInput = false;
} }
public function loadData($invoiceNumber, $plantId, $onCapFocus) // public function loadData($invoiceNumber, $plantId, $onCapFocus)
// {
// $this->plantId = $plantId;
// $this->invoiceNumber = $invoiceNumber;
// $this->completedInvoice = false;
// $this->isSerial = true;
// $this->onCapFocus = $onCapFocus;
// $this->emptyInvoice = false;
// $this->hasSearched = true;
// $this->materialInvoice = false;
// // $this->showCapacitorInput = false;
// // ->where('serial_number', '!=', '')
// $this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber)
// ->where('plant_id', $plantId)->where('scanned_status', null)
// ->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 ?? '',
// 'scanned_status' => $record->scanned_status ?? '',
// 'panel_box_supplier' => $record->panel_box_supplier ?? '',
// 'panel_box_serial_number' => $record->panel_box_serial_number ?? '',
// 'created_at' => $record->created_at,
// 'operator_id' => $record->operator_id,
// ];
// })
// ->toArray();
// $this->packageCount = 0;
// // Loop through and replace 'code' using related StickerMaster > Item > code
// foreach ($this->invoiceData as &$row) {
// $stickCount = 0;
// $scannedCount = 0;
// // $stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null);
// $row['code'] = StickerMaster::with('item')->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A';
// $curStick = StickerMaster::where('id', $row['sticker_master_id'])->first();
// if ($curStick) {
// if (Str::length($curStick->panel_box_code) > 0) {
// $stickCount++;
// }
// if ($curStick->tube_sticker_motor == 1 || $curStick->tube_sticker_pump == 1 || $curStick->tube_sticker_pumpset == 1) {
// if ($curStick->tube_sticker_motor == 1) {
// $stickCount++;
// }
// if ($curStick->tube_sticker_pump == 1 || ($curStick->tube_sticker_pumpset != 1 && $curStick->tube_sticker_pump != 1 && $curStick->pack_slip_pump == 1)) {
// $stickCount++;
// }
// if ($curStick->tube_sticker_pumpset == 1) {
// $stickCount++;
// }
// } elseif ($curStick->pack_slip_motor == 1 || $curStick->pack_slip_pump == 1 || $curStick->pack_slip_pumpset == 1) {
// if ($curStick->pack_slip_motor == 1) {
// $stickCount++;
// }
// if ($curStick->pack_slip_pump == 1) {
// $stickCount++;
// }
// if ($curStick->pack_slip_pumpset == 1) {
// $stickCount++;
// }
// }
// }
// if ($row['motor_scanned_status'] == 1) {
// $scannedCount++;
// }
// if ($row['pump_scanned_status'] == 1) {
// $scannedCount++;
// }
// if ($row['capacitor_scanned_status'] == 1) {
// $scannedCount++;
// }
// if ($row['scanned_status_set'] == 1) {
// $scannedCount++;
// }
// $this->packageCount += $stickCount - $scannedCount;
// }
// if ($onCapFocus) {
// $this->dispatch('focus-capacitor-input');
// } else {
// $this->dispatch('focus-serial-number');
// }
// }
public function loadData($invoiceNumber, $plantId, $onCapFocus = false)
{ {
$this->plantId = $plantId; $this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber; $this->invoiceNumber = $invoiceNumber;
@@ -93,80 +186,70 @@ class InvoiceDataTable extends Component
$this->emptyInvoice = false; $this->emptyInvoice = false;
$this->hasSearched = true; $this->hasSearched = true;
$this->materialInvoice = false; $this->materialInvoice = false;
// $this->showCapacitorInput = false;
// ->where('serial_number', '!=', '') // Eager load stickerMasterRelation and item
$this->invoiceData = InvoiceValidation::where('invoice_number', $this->invoiceNumber) $invoiceRecords = InvoiceValidation::with('stickerMasterRelation.item')
->where('plant_id', $plantId)->where('scanned_status', null) ->where('invoice_number', $invoiceNumber)
->get() ->where('plant_id', $plantId)
->map(function ($record) { ->whereNull('scanned_status')
return [ ->get();
'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 ?? '',
'scanned_status' => $record->scanned_status ?? '',
'panel_box_supplier' => $record->panel_box_supplier ?? '',
'panel_box_serial_number' => $record->panel_box_serial_number ?? '',
'created_at' => $record->created_at,
'operator_id' => $record->operator_id,
];
})
->toArray();
$this->invoiceData = [];
$this->packageCount = 0; $this->packageCount = 0;
// Loop through and replace 'code' using related StickerMaster > Item > code foreach ($invoiceRecords as $record) {
foreach ($this->invoiceData as &$row) { $sm = $record->stickerMasterRelation;
// Compute code
$rowCode = $sm?->item?->code ?? 'N/A';
$stickCount = 0; $stickCount = 0;
$scannedCount = 0; $scannedCount = 0;
// $stickerMaster = \App\Models\StickerMaster::with('item')->find($row['sticker_master_id'] ?? null); if ($sm) {
$row['code'] = StickerMaster::with('item')->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A'; // Panel box code
$curStick = StickerMaster::where('id', $row['sticker_master_id'])->first(); if (Str::length($sm->panel_box_code) > 0) {
if ($curStick) {
if (Str::length($curStick->panel_box_code) > 0) {
$stickCount++; $stickCount++;
} }
if ($curStick->tube_sticker_motor == 1 || $curStick->tube_sticker_pump == 1 || $curStick->tube_sticker_pumpset == 1) {
if ($curStick->tube_sticker_motor == 1) { // Tube stickers logic
$stickCount++; if ($sm->tube_sticker_motor == 1 || $sm->tube_sticker_pump == 1 || $sm->tube_sticker_pumpset == 1) {
} if ($sm->tube_sticker_motor == 1) $stickCount++;
if ($curStick->tube_sticker_pump == 1 || ($curStick->tube_sticker_pumpset != 1 && $curStick->tube_sticker_pump != 1 && $curStick->pack_slip_pump == 1)) { if ($sm->tube_sticker_pump == 1 || ($sm->tube_sticker_pumpset != 1 && $sm->tube_sticker_pump != 1 && $sm->pack_slip_pump == 1)) $stickCount++;
$stickCount++; if ($sm->tube_sticker_pumpset == 1) $stickCount++;
} }
if ($curStick->tube_sticker_pumpset == 1) { // Pack slip logic (only if tube sticker block didn't apply)
$stickCount++; elseif ($sm->pack_slip_motor == 1 || $sm->pack_slip_pump == 1 || $sm->pack_slip_pumpset == 1) {
} if ($sm->pack_slip_motor == 1) $stickCount++;
} elseif ($curStick->pack_slip_motor == 1 || $curStick->pack_slip_pump == 1 || $curStick->pack_slip_pumpset == 1) { if ($sm->pack_slip_pump == 1) $stickCount++;
if ($curStick->pack_slip_motor == 1) { if ($sm->pack_slip_pumpset == 1) $stickCount++;
$stickCount++;
}
if ($curStick->pack_slip_pump == 1) {
$stickCount++;
}
if ($curStick->pack_slip_pumpset == 1) {
$stickCount++;
}
} }
} }
if ($row['motor_scanned_status'] == 1) { // Count already scanned
$scannedCount++; $scannedCount += ($record->motor_scanned_status == 1) ? 1 : 0;
} $scannedCount += ($record->pump_scanned_status == 1) ? 1 : 0;
if ($row['pump_scanned_status'] == 1) { $scannedCount += ($record->capacitor_scanned_status == 1) ? 1 : 0;
$scannedCount++; $scannedCount += ($record->scanned_status_set == 1) ? 1 : 0;
}
if ($row['capacitor_scanned_status'] == 1) {
$scannedCount++;
}
if ($row['scanned_status_set'] == 1) {
$scannedCount++;
}
$this->packageCount += $stickCount - $scannedCount; // Increment packageCount
$this->packageCount += max($stickCount - $scannedCount, 0);
$this->invoiceData[] = [
'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 ?? '',
'scanned_status' => $record->scanned_status ?? '',
'panel_box_supplier' => $record->panel_box_supplier ?? '',
'panel_box_serial_number' => $record->panel_box_serial_number ?? '',
'created_at' => $record->created_at,
'operator_id' => $record->operator_id,
'code' => $rowCode,
'stickCount' => $stickCount,
];
} }
if ($onCapFocus) { if ($onCapFocus) {