From 0e301e12e17907f5761d0207131252053750b8e3 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Jan 2026 12:45:44 +0530 Subject: [PATCH] changed logic in invoice data table livewire page --- app/Livewire/InvoiceDataTable.php | 274 +++++++++--------- .../livewire/invoice-data-table.blade.php | 8 +- 2 files changed, 141 insertions(+), 141 deletions(-) diff --git a/app/Livewire/InvoiceDataTable.php b/app/Livewire/InvoiceDataTable.php index 3566887..24a2495 100644 --- a/app/Livewire/InvoiceDataTable.php +++ b/app/Livewire/InvoiceDataTable.php @@ -184,77 +184,11 @@ class InvoiceDataTable extends Component // #[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) // { - // $this->plantId = $plantId; // $this->invoiceNumber = $invoiceNumber; + // $this->plantId = $plantId; + // $this->completedInvoice = false; // $this->isSerial = true; // $this->onCapFocus = $onCapFocus; @@ -262,77 +196,143 @@ class InvoiceDataTable extends Component // $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->resetPage(); - // $this->invoiceData = []; - // $this->packageCount = 0; + // $this->packageCount = InvoiceValidation::with('stickerMasterRelation') + // ->where('invoice_number', $this->invoiceNumber) + // ->where('plant_id', $this->plantId) + // ->get() + // ->sum(function ($record) { + // $sm = $record->stickerMasterRelation; - // foreach ($invoiceRecords as $record) { - // $sm = $record->stickerMasterRelation; + // $stickCount = 0; + // $scannedCount = 0; - // // Compute code - // $rowCode = $sm?->item?->code ?? 'N/A'; + // if ($sm) { + // // Panel box + // if (strlen($sm->panel_box_code) > 0) $stickCount++; - // $stickCount = 0; - // $scannedCount = 0; - - // if ($sm) { - // // Panel box code - // if (Str::length($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; + // } // } - // // 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; + // // 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); + // return 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'); - // } + // $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) + { + $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) { @@ -555,15 +555,15 @@ class InvoiceDataTable extends Component $this->dispatch('focus-serial-number'); } - // public function render() - // { - // return view('livewire.invoice-data-table'); - // } - public function render() { - return view('livewire.invoice-data-table', [ - 'records' => $this->invoiceRecords, - ]); + return view('livewire.invoice-data-table'); } + + // public function render() + // { + // return view('livewire.invoice-data-table', [ + // 'records' => $this->invoiceRecords, + // ]); + // } } diff --git a/resources/views/livewire/invoice-data-table.blade.php b/resources/views/livewire/invoice-data-table.blade.php index 09dacf7..ae11814 100644 --- a/resources/views/livewire/invoice-data-table.blade.php +++ b/resources/views/livewire/invoice-data-table.blade.php @@ -64,7 +64,7 @@ @endif {{-- Modal for serial invoice--}} - {{-- @if ($hasSearched) + @if ($hasSearched)
@@ -111,11 +111,11 @@
- @endif --}} + @endif - @if ($hasSearched) + {{-- @if ($hasSearched)
@@ -164,7 +164,7 @@ {{ $records->onEachSide(3)->links() }} - @endif + @endif --}} {{-- Modal for Capacitor Input --}}