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:
@@ -481,7 +481,6 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
$duplicateSerialCodes = array_unique($duplicateSerials);
|
||||
|
||||
|
||||
if (!empty($uniqueInvalidCodes)) {
|
||||
Notification::make()
|
||||
->title('Invalid Item Codes')
|
||||
@@ -539,17 +538,17 @@ class InvoiceValidationResource extends Resource
|
||||
return;
|
||||
}
|
||||
|
||||
$uniqueCodes = array_unique($materialCodes);
|
||||
$uniqueCodes = array_unique($materialCodes);
|
||||
|
||||
$matchedItems = StickerMaster::with('item')
|
||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||
$query->whereIn('code', $uniqueCodes);
|
||||
})
|
||||
->get();
|
||||
$matchedItems = StickerMaster::with('item')
|
||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||
$query->whereIn('code', $uniqueCodes);
|
||||
})
|
||||
->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))
|
||||
{
|
||||
@@ -615,7 +614,6 @@ class InvoiceValidationResource extends Resource
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import serial invoice');
|
||||
}),
|
||||
|
||||
Tables\Actions\Action::make('Import Invoice Material')
|
||||
->label('Import Material Invoice')
|
||||
->form([
|
||||
|
||||
@@ -1059,7 +1059,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
}
|
||||
|
||||
$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')
|
||||
->toArray();
|
||||
|
||||
@@ -2064,7 +2064,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
}
|
||||
|
||||
$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')
|
||||
->toArray();
|
||||
|
||||
@@ -3077,6 +3077,13 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
$hasPumpSetQr = $record->stickerMasterRelation->tube_sticker_pumpset ?? 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;
|
||||
$hadPumpQr = $record->pump_scanned_status ?? null;
|
||||
$hadPumpSetQr = $record->scanned_status_set ?? null;
|
||||
@@ -3085,23 +3092,23 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
if (!$hasMotorQr && !$hasPumpQr && !$hasPumpSetQr && !$hasCapacitorQr)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Invalid: Item Code')
|
||||
->body("Scanned 'Item Code' doesn't have valid package type to proceed!")
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->send();
|
||||
->title('Invalid: Item Code')
|
||||
->body("Scanned 'Item Code' doesn't have valid package type to proceed!")
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->send();
|
||||
|
||||
$this->dispatch('playWarnSound');
|
||||
$this->dispatch('playWarnSound');
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'serial_number' => null,
|
||||
'total_quantity' => $totQuan,
|
||||
'update_invoice' => false,
|
||||
'scanned_quantity'=> $scanSQuan,
|
||||
]);
|
||||
return;
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'serial_number' => null,
|
||||
'total_quantity' => $totQuan,
|
||||
'update_invoice' => false,
|
||||
'scanned_quantity'=> $scanSQuan,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isMarkM) {
|
||||
|
||||
Reference in New Issue
Block a user