Refactor validation logic in CreateInvoiceValidation to include additional checks for package types (use pack_slip if tube_sticker does not exist) and streamline code structure

This commit is contained in:
dhanabalan
2025-09-26 18:59:33 +05:30
parent d2c7f85917
commit 998fbf814c
2 changed files with 32 additions and 27 deletions

View File

@@ -481,7 +481,6 @@ class InvoiceValidationResource extends Resource
$duplicateSerialCodes = array_unique($duplicateSerials); $duplicateSerialCodes = array_unique($duplicateSerials);
if (!empty($uniqueInvalidCodes)) { if (!empty($uniqueInvalidCodes)) {
Notification::make() Notification::make()
->title('Invalid Item Codes') ->title('Invalid Item Codes')
@@ -539,17 +538,17 @@ class InvoiceValidationResource extends Resource
return; return;
} }
$uniqueCodes = array_unique($materialCodes); $uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item') $matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) { ->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes); $query->whereIn('code', $uniqueCodes);
}) })
->get(); ->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray(); $matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes); $missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes)) if (!empty($missingCodes))
{ {
@@ -615,7 +614,6 @@ class InvoiceValidationResource extends Resource
->visible(function() { ->visible(function() {
return Filament::auth()->user()->can('view import serial invoice'); return Filament::auth()->user()->can('view import serial invoice');
}), }),
Tables\Actions\Action::make('Import Invoice Material') Tables\Actions\Action::make('Import Invoice Material')
->label('Import Material Invoice') ->label('Import Material Invoice')
->form([ ->form([

View File

@@ -1059,7 +1059,7 @@ class CreateInvoiceValidation extends CreateRecord
} }
$missPackCodes = $matchedItems $missPackCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->panel_box_code)) //filter invalid ->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->pack_slip_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->pack_slip_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->pack_slip_pumpset) && empty($sticker->panel_box_code)) //filter invalid
->pluck('item.code') ->pluck('item.code')
->toArray(); ->toArray();
@@ -2064,7 +2064,7 @@ class CreateInvoiceValidation extends CreateRecord
} }
$missPackCodes = $matchedItems $missPackCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->panel_box_code)) ->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->pack_slip_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->pack_slip_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->pack_slip_pumpset) && empty($sticker->panel_box_code))
->pluck('item.code') ->pluck('item.code')
->toArray(); ->toArray();
@@ -3077,6 +3077,13 @@ class CreateInvoiceValidation extends CreateRecord
$hasPumpSetQr = $record->stickerMasterRelation->tube_sticker_pumpset ?? null; $hasPumpSetQr = $record->stickerMasterRelation->tube_sticker_pumpset ?? null;
$hasCapacitorQr = $record->stickerMasterRelation->panel_box_code ?? null; $hasCapacitorQr = $record->stickerMasterRelation->panel_box_code ?? null;
if (!$hasMotorQr && !$hasPumpQr && !$hasPumpSetQr && !$hasCapacitorQr)
{
$hasMotorQr = $record->stickerMasterRelation->pack_slip_motor ?? null;
$hasPumpQr = $record->stickerMasterRelation->pack_slip_pump ?? null;
$hasPumpSetQr = $record->stickerMasterRelation->pack_slip_pumpset ?? null;
}
$hadMotorQr = $record->motor_scanned_status ?? null; $hadMotorQr = $record->motor_scanned_status ?? null;
$hadPumpQr = $record->pump_scanned_status ?? null; $hadPumpQr = $record->pump_scanned_status ?? null;
$hadPumpSetQr = $record->scanned_status_set ?? null; $hadPumpSetQr = $record->scanned_status_set ?? null;
@@ -3085,23 +3092,23 @@ class CreateInvoiceValidation extends CreateRecord
if (!$hasMotorQr && !$hasPumpQr && !$hasPumpSetQr && !$hasCapacitorQr) if (!$hasMotorQr && !$hasPumpQr && !$hasPumpSetQr && !$hasCapacitorQr)
{ {
Notification::make() Notification::make()
->title('Invalid: Item Code') ->title('Invalid: Item Code')
->body("Scanned 'Item Code' doesn't have valid package type to proceed!") ->body("Scanned 'Item Code' doesn't have valid package type to proceed!")
->danger() ->danger()
->seconds(2) ->seconds(2)
->send(); ->send();
$this->dispatch('playWarnSound'); $this->dispatch('playWarnSound');
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
'invoice_number' => $invoiceNumber, 'invoice_number' => $invoiceNumber,
'serial_number' => null, 'serial_number' => null,
'total_quantity' => $totQuan, 'total_quantity' => $totQuan,
'update_invoice' => false, 'update_invoice' => false,
'scanned_quantity'=> $scanSQuan, 'scanned_quantity'=> $scanSQuan,
]); ]);
return; return;
} }
if ($isMarkM) { if ($isMarkM) {