Merge pull request 'changed logic in invoice data tbale for capacitor issue' (#275) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #275
This commit was merged in pull request #275.
This commit is contained in:
2026-01-29 11:44:07 +00:00
2 changed files with 313 additions and 143 deletions

View File

@@ -19,8 +19,13 @@ class InvoiceDataTable extends Component
protected $paginationTheme = 'tailwind'; protected $paginationTheme = 'tailwind';
public $invoiceData = []; public $invoiceData = [];
// public $invoiceRecords;
public $plantId = 0; public $plantId = 0;
public $package = [];
public $packageCount = 0; public $packageCount = 0;
public string $invoiceNumber = ''; public string $invoiceNumber = '';
@@ -182,79 +187,131 @@ class InvoiceDataTable extends Component
// } // }
// } // }
// public function loadData($invoiceNumber, $plantId, $onCapFocus = false)
// {
// $this->invoiceNumber = $invoiceNumber;
// $this->plantId = $plantId;
// $this->completedInvoice = false;
// $this->isSerial = true;
// $this->onCapFocus = $onCapFocus;
// $this->emptyInvoice = false;
// $this->hasSearched = true;
// $this->materialInvoice = false;
// $this->resetPage();
// $this->packageCount = 0;
// // IMPORTANT: keep scanned rows, otherwise count will not update
// $this->invoiceRecords = InvoiceValidation::with('stickerMasterRelation')
// ->where('invoice_number', $this->invoiceNumber)
// ->where('plant_id', $this->plantId)
// ->get();
// foreach ($this->invoiceRecords as &$row) {
// $stickCount = 0;
// $scannedCount = 0;
// // Get item code
// $row['code'] = StickerMaster::with('item')
// ->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A';
// $curStick = StickerMaster::find($row['sticker_master_id']);
// if ($curStick) {
// /** ---------------- REQUIRED STICKERS ---------------- */
// // PANEL BOX (capacitor)
// if (!empty($curStick->panel_box_code)) {
// $stickCount++;
// // Panel box scan = capacitor_scanned_status
// if ($row['capacitor_scanned_status'] == 1) {
// $scannedCount++;
// }
// }
// // Tube stickers
// if (
// $curStick->tube_sticker_motor == 1 ||
// $curStick->tube_sticker_pump == 1 ||
// $curStick->tube_sticker_pumpset == 1
// ) {
// if ($curStick->tube_sticker_motor == 1) {
// $stickCount++;
// if ($row['motor_scanned_status'] == 1) {
// $scannedCount++;
// }
// }
// if (
// $curStick->tube_sticker_pump == 1 ||
// ($curStick->tube_sticker_pumpset != 1 &&
// $curStick->tube_sticker_pump != 1 &&
// $curStick->pack_slip_pump == 1)
// ) {
// $stickCount++;
// if ($row['pump_scanned_status'] == 1) {
// $scannedCount++;
// }
// }
// if ($curStick->tube_sticker_pumpset == 1) {
// $stickCount++;
// if ($row['scanned_status_set'] == 1) {
// $scannedCount++;
// }
// }
// }
// // Pack slips (only if no tube stickers)
// elseif (
// $curStick->pack_slip_motor == 1 ||
// $curStick->pack_slip_pump == 1 ||
// $curStick->pack_slip_pumpset == 1
// ) {
// if ($curStick->pack_slip_motor == 1) {
// $stickCount++;
// if ($row['motor_scanned_status'] == 1) {
// $scannedCount++;
// }
// }
// if ($curStick->pack_slip_pump == 1) {
// $stickCount++;
// if ($row['pump_scanned_status'] == 1) {
// $scannedCount++;
// }
// }
// if ($curStick->pack_slip_pumpset == 1) {
// $stickCount++;
// if ($row['scanned_status_set'] == 1) {
// $scannedCount++;
// }
// }
// }
// }
// // SAFETY: never go negative
// $this->packageCount += max($stickCount - $scannedCount, 0);
// }
// $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number');
// }
// #[On('refreshInvoiceData')] // #[On('refreshInvoiceData')]
// public function loadData($invoiceNumber, $plantId, $onCapFocus = false)
// {
// $this->invoiceNumber = $invoiceNumber;
// $this->plantId = $plantId;
// $this->completedInvoice = false;
// $this->isSerial = true;
// $this->onCapFocus = $onCapFocus;
// $this->emptyInvoice = false;
// $this->hasSearched = true;
// $this->materialInvoice = false;
// $this->resetPage();
// $this->packageCount = InvoiceValidation::with('stickerMasterRelation')
// ->where('invoice_number', $this->invoiceNumber)
// ->where('plant_id', $this->plantId)
// ->get()
// ->sum(function ($record) {
// $sm = $record->stickerMasterRelation;
// $stickCount = 0;
// $scannedCount = 0;
// if ($sm) {
// // Panel box
// if (strlen($sm->panel_box_code) > 0) $stickCount++;
// // Tube stickers
// if ($sm->tube_sticker_motor || $sm->tube_sticker_pump || $sm->tube_sticker_pumpset) {
// $stickCount += $sm->tube_sticker_motor ? 1 : 0;
// $stickCount += ($sm->tube_sticker_pump || ($sm->tube_sticker_pumpset != 1 && !$sm->tube_sticker_pump && $sm->pack_slip_pump)) ? 1 : 0;
// $stickCount += $sm->tube_sticker_pumpset ? 1 : 0;
// }
// // Pack slips (only if tube stickers not applied)
// elseif ($sm->pack_slip_motor || $sm->pack_slip_pump || $sm->pack_slip_pumpset) {
// $stickCount += $sm->pack_slip_motor ? 1 : 0;
// $stickCount += $sm->pack_slip_pump ? 1 : 0;
// $stickCount += $sm->pack_slip_pumpset ? 1 : 0;
// }
// }
// // Already scanned
// $scannedCount += $record->motor_scanned_status == 1 ? 1 : 0;
// $scannedCount += $record->pump_scanned_status == 1 ? 1 : 0;
// $scannedCount += $record->capacitor_scanned_status == 1 ? 1 : 0;
// $scannedCount += $record->scanned_status_set == 1 ? 1 : 0;
// return max($stickCount - $scannedCount, 0);
// });
// $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number');
// }
// public function getInvoiceRecordsProperty()
// {
// if (! $this->hasSearched) {
// return collect();
// }
// return InvoiceValidation::with('stickerMasterRelation.item')
// ->where('invoice_number', $this->invoiceNumber)
// ->where('plant_id', $this->plantId)
// ->whereNull('scanned_status')
// ->paginate(7);
// }
public function loadData($invoiceNumber, $plantId, $onCapFocus = false) public function loadData($invoiceNumber, $plantId, $onCapFocus = false)
{ {
$this->plantId = $plantId;
$this->invoiceNumber = $invoiceNumber; $this->invoiceNumber = $invoiceNumber;
$this->plantId = $plantId;
$this->completedInvoice = false; $this->completedInvoice = false;
$this->isSerial = true; $this->isSerial = true;
$this->onCapFocus = $onCapFocus; $this->onCapFocus = $onCapFocus;
@@ -262,77 +319,165 @@ class InvoiceDataTable extends Component
$this->hasSearched = true; $this->hasSearched = true;
$this->materialInvoice = false; $this->materialInvoice = false;
// Eager load stickerMasterRelation and item $this->resetPage();
$invoiceRecords = InvoiceValidation::with('stickerMasterRelation.item')
->where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->whereNull('scanned_status')
->get();
$this->invoiceData = [];
$this->packageCount = 0; $this->packageCount = 0;
foreach ($invoiceRecords as $record) { $this->packageCount = InvoiceValidation::with('stickerMasterRelation')
$sm = $record->stickerMasterRelation; ->where('invoice_number', $this->invoiceNumber)
->where('plant_id', $this->plantId)
->whereNull('scanned_status')
->get()
->sum(function ($record) {
$sm = $record->stickerMasterRelation;
// Compute code $stickCount = 0;
$rowCode = $sm?->item?->code ?? 'N/A'; $scannedCount = 0;
$stickCount = 0; if ($sm) {
$scannedCount = 0;
if ($sm) { // if (strlen($sm->panel_box_code) > 0) $stickCount++;
// Panel box code
if (Str::length($sm->panel_box_code) > 0) { if (!empty($sm->panel_box_code)) {
$stickCount++; $stickCount++;
if (!empty($record->panel_box_serial_number)) {
$scannedCount++;
}
}
// Tube stickers
if ($sm->tube_sticker_motor || $sm->tube_sticker_pump || $sm->tube_sticker_pumpset) {
$stickCount += $sm->tube_sticker_motor ? 1 : 0;
$stickCount += ($sm->tube_sticker_pump || ($sm->tube_sticker_pumpset != 1 && !$sm->tube_sticker_pump && $sm->pack_slip_pump)) ? 1 : 0;
$stickCount += $sm->tube_sticker_pumpset ? 1 : 0;
}
// Pack slips (only if tube stickers not applied)
elseif ($sm->pack_slip_motor || $sm->pack_slip_pump || $sm->pack_slip_pumpset) {
$stickCount += $sm->pack_slip_motor ? 1 : 0;
$stickCount += $sm->pack_slip_pump ? 1 : 0;
$stickCount += $sm->pack_slip_pumpset ? 1 : 0;
}
} }
// Tube stickers logic
if ($sm->tube_sticker_motor == 1 || $sm->tube_sticker_pump == 1 || $sm->tube_sticker_pumpset == 1) {
if ($sm->tube_sticker_motor == 1) $stickCount++;
if ($sm->tube_sticker_pump == 1 || ($sm->tube_sticker_pumpset != 1 && $sm->tube_sticker_pump != 1 && $sm->pack_slip_pump == 1)) $stickCount++;
if ($sm->tube_sticker_pumpset == 1) $stickCount++;
}
// Pack slip logic (only if tube sticker block didn't apply)
elseif ($sm->pack_slip_motor == 1 || $sm->pack_slip_pump == 1 || $sm->pack_slip_pumpset == 1) {
if ($sm->pack_slip_motor == 1) $stickCount++;
if ($sm->pack_slip_pump == 1) $stickCount++;
if ($sm->pack_slip_pumpset == 1) $stickCount++;
}
}
// Count already scanned // Already scanned
$scannedCount += ($record->motor_scanned_status == 1) ? 1 : 0; $scannedCount += $record->motor_scanned_status == 1 ? 1 : 0;
$scannedCount += ($record->pump_scanned_status == 1) ? 1 : 0; $scannedCount += $record->pump_scanned_status == 1 ? 1 : 0;
$scannedCount += ($record->capacitor_scanned_status == 1) ? 1 : 0; $scannedCount += $record->capacitor_scanned_status == 1 ? 1 : 0;
$scannedCount += ($record->scanned_status_set == 1) ? 1 : 0; $scannedCount += $record->scanned_status_set == 1 ? 1 : 0;
// Increment packageCount // if (!empty($record->panel_box_serial_number)) {
$this->packageCount += max($stickCount - $scannedCount, 0); // $scannedCount++;
// }
return max($stickCount - $scannedCount, 0);
});
$this->invoiceData[] = [ $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number');
'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) {
$this->dispatch('focus-capacitor-input');
} else {
$this->dispatch('focus-serial-number');
}
} }
public function getInvoiceRecordsProperty()
{
return InvoiceValidation::with('stickerMasterRelation.item')
->when(! $this->hasSearched, fn ($q) => $q->whereRaw('1 = 0'))
->when($this->hasSearched, fn ($q) =>
$q->where('invoice_number', $this->invoiceNumber)
->where('plant_id', $this->plantId)
->whereNull('scanned_status')
)
->paginate(7);
}
// public function getInvoiceRecordsProperty()
// {
// return InvoiceValidation::with('stickerMasterRelation.item')
// ->where('invoice_number', $this->hasSearched ? $this->invoiceNumber : null)
// ->where('plant_id', $this->hasSearched ? $this->plantId : null)
// ->whereNull('scanned_status')
// ->paginate(7);
// }
// public function loadData($invoiceNumber, $plantId, $onCapFocus = false)
// {
// $this->plantId = $plantId;
// $this->invoiceNumber = $invoiceNumber;
// $this->completedInvoice = false;
// $this->isSerial = true;
// $this->onCapFocus = $onCapFocus;
// $this->emptyInvoice = false;
// $this->hasSearched = true;
// $this->materialInvoice = false;
// // Eager load stickerMasterRelation and item
// $invoiceRecords = InvoiceValidation::with('stickerMasterRelation.item')
// ->where('invoice_number', $invoiceNumber)
// ->where('plant_id', $plantId)
// ->whereNull('scanned_status')
// ->get();
// $this->invoiceData = [];
// $this->packageCount = 0;
// foreach ($invoiceRecords as $record) {
// $sm = $record->stickerMasterRelation;
// // Compute code
// $rowCode = $sm?->item?->code ?? 'N/A';
// $stickCount = 0;
// $scannedCount = 0;
// if ($sm) {
// // Panel box code
// if (Str::length($sm->panel_box_code) > 0) {
// $stickCount++;
// }
// // Tube stickers logic
// if ($sm->tube_sticker_motor == 1 || $sm->tube_sticker_pump == 1 || $sm->tube_sticker_pumpset == 1) {
// if ($sm->tube_sticker_motor == 1) $stickCount++;
// if ($sm->tube_sticker_pump == 1 || ($sm->tube_sticker_pumpset != 1 && $sm->tube_sticker_pump != 1 && $sm->pack_slip_pump == 1)) $stickCount++;
// if ($sm->tube_sticker_pumpset == 1) $stickCount++;
// }
// // Pack slip logic (only if tube sticker block didn't apply)
// elseif ($sm->pack_slip_motor == 1 || $sm->pack_slip_pump == 1 || $sm->pack_slip_pumpset == 1) {
// if ($sm->pack_slip_motor == 1) $stickCount++;
// if ($sm->pack_slip_pump == 1) $stickCount++;
// if ($sm->pack_slip_pumpset == 1) $stickCount++;
// }
// }
// // Count already scanned
// $scannedCount += ($record->motor_scanned_status == 1) ? 1 : 0;
// $scannedCount += ($record->pump_scanned_status == 1) ? 1 : 0;
// $scannedCount += ($record->capacitor_scanned_status == 1) ? 1 : 0;
// $scannedCount += ($record->scanned_status_set == 1) ? 1 : 0;
// // 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) {
// $this->dispatch('focus-capacitor-input');
// } else {
// $this->dispatch('focus-serial-number');
// }
// }
public function loadMaterialData($invoiceNumber, $plantId) public function loadMaterialData($invoiceNumber, $plantId)
{ {
@@ -446,8 +591,20 @@ class InvoiceDataTable extends Component
return; return;
} }
foreach ($this->invoiceData as &$row) { $this->package = InvoiceValidation::with('stickerMasterRelation')
if (($row['code'] ?? '') === $this->currentItemCode && ($row['serial_number'] ?? '') === $this->currentSerialNumber) { ->where('invoice_number', $this->invoiceNumber)
->where('plant_id', $this->plantId)
->whereNull('scanned_status')
->get();
foreach ($this->package as &$row) {
// if (($row['code'] ?? '') === $this->currentItemCode && ($row['serial_number'] ?? '') === $this->currentSerialNumber) {
// if ($row->stickerMasterRelation?->item?->code == $this->currentItemCode && ($row['serial_number'] ?? '') === $this->currentSerialNumber) {
$stickerCode = $row->stickerMasterRelation?->item?->code ?? null;
$serialNumber = $row->serial_number ?? null;
if ($stickerCode === $this->currentItemCode && $serialNumber === $this->currentSerialNumber) {
$row['panel_box_supplier'] = $supplier; $row['panel_box_supplier'] = $supplier;
$row['panel_box_item_code'] = $itemCode; $row['panel_box_item_code'] = $itemCode;
$row['panel_box_serial_number'] = $serialNumber; $row['panel_box_serial_number'] = $serialNumber;
@@ -462,6 +619,8 @@ class InvoiceDataTable extends Component
return $validation->stickerMaster?->item?->code === $this->currentItemCode; return $validation->stickerMaster?->item?->code === $this->currentItemCode;
}); });
// dd($matchingValidation);
if ($matchingValidation) { if ($matchingValidation) {
$hasMotorQr = $matchingValidation->stickerMasterRelation->tube_sticker_motor ?? null; $hasMotorQr = $matchingValidation->stickerMasterRelation->tube_sticker_motor ?? null;
$hasPumpQr = $matchingValidation->stickerMasterRelation->tube_sticker_pump ?? null; $hasPumpQr = $matchingValidation->stickerMasterRelation->tube_sticker_pump ?? null;
@@ -555,15 +714,15 @@ class InvoiceDataTable extends Component
$this->dispatch('focus-serial-number'); $this->dispatch('focus-serial-number');
} }
public function render()
{
return view('livewire.invoice-data-table');
}
// public function render() // public function render()
// { // {
// return view('livewire.invoice-data-table', [ // return view('livewire.invoice-data-table');
// 'records' => $this->invoiceRecords,
// ]);
// } // }
public function render()
{
return view('livewire.invoice-data-table', [
'records' => $this->invoiceRecords,
]);
}
} }

View File

@@ -64,7 +64,7 @@
@endif @endif
{{-- Modal for serial invoice--}} {{-- Modal for serial invoice--}}
@if ($hasSearched) {{-- @if ($hasSearched)
<div class="overflow-x-auto overflow-y-visible" style="height: 385px;"> <div class="overflow-x-auto overflow-y-visible" style="height: 385px;">
<table class="min-w-[1500px] text-sm text-center border border-gray-300"> <table class="min-w-[1500px] text-sm text-center border border-gray-300">
<table class="table-fixed min-w-[1500px] text-sm text-center border border-gray-300"> <table class="table-fixed min-w-[1500px] text-sm text-center border border-gray-300">
@@ -111,14 +111,14 @@
</tbody> </tbody>
</table> </table>
</div> </div>
@endif @endif --}}
@if ($hasSearched)
{{-- @if ($hasSearched)
<div class="overflow-x-auto" style="height: 385px;"> <div class="overflow-x-auto" style="height: 385px;">
<table class="min-w-full text-sm text-center border border-gray-300"> <table class="min-w-full text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold sticky top-0 z-10"> <table class="table-fixed min-w-[1500px] text-sm text-center border border-gray-300">
<thead class="bg-gray-100 font-bold">
<tr> <tr>
<th class="border px-4 py-2">No</th> <th class="border px-4 py-2">No</th>
<th class="border px-4 py-2">Material Code</th> <th class="border px-4 py-2">Material Code</th>
@@ -164,7 +164,8 @@
{{ $records->onEachSide(3)->links() }} {{ $records->onEachSide(3)->links() }}
</div> </div>
</div> </div>
@endif --}}
@endif
{{-- Modal for Capacitor Input --}} {{-- Modal for Capacitor Input --}}
<div> <div>
@@ -198,8 +199,18 @@
</div> </div>
</div> </div>
{{-- Add this script to focus on the input --}} {{-- Add this script to focus on the input --}}
<script> {{-- <script>
document.getElementById('capacitorInput').focus(); document.getElementById('capacitorInput').focus();
</script> --}}
<script>
document.addEventListener('livewire:initialized', () => {
@this.on('focus-capacitor-input', () => {
setTimeout(() => {
const el = document.getElementById('capacitorInput');
if (el) el.focus();
}, 100);
});
});
</script> </script>
@endif @endif
</div> </div>