Updated invoice import functionality to allow unique record #422
@@ -322,65 +322,76 @@ class InvoiceValidationImporter extends Importer
|
||||
$curPanelBoxSerialNumber = null;
|
||||
}
|
||||
|
||||
$record = InvoiceValidation::where('serial_number', $serialNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->whereHas('stickerMasterRelation.item', function ($query) use ($plantId, $iCode) {
|
||||
$query->where('plant_id', $plantId)->where('code', $iCode);
|
||||
})
|
||||
->first();
|
||||
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->first();
|
||||
|
||||
$invalidPackage = false;
|
||||
if ($record && $record->sticker_master_id != $stickId) {
|
||||
$stickId = null;
|
||||
$warnMsg[] = 'Item code mismatch with existing record!';
|
||||
} elseif ($record) {
|
||||
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)
|
||||
->whereHas('stickerMasterRelation.item', function ($query) use ($plantId, $iCode) {
|
||||
$query->where('plant_id', $plantId)->where('code', $iCode);
|
||||
})
|
||||
->first();
|
||||
|
||||
if ($record) {
|
||||
$invalidPackage = false;
|
||||
|
||||
$hadMotorQr = $record->motor_scanned_status ?? null;
|
||||
$hadPumpQr = $record->pump_scanned_status ?? null;
|
||||
$hadPumpSetQr = $record->scanned_status_set ?? null;
|
||||
$hadCapacitorQr = $record->capacitor_scanned_status ?? null;
|
||||
if ($record) {
|
||||
|
||||
if ($hadMotorQr) {
|
||||
$curMotorQr = $hadMotorQr;
|
||||
}
|
||||
if ($hadPumpQr) {
|
||||
$curPumpQr = $hadPumpQr;
|
||||
}
|
||||
if ($hadPumpSetQr) {
|
||||
$curPumpSetQr = $hadPumpSetQr;
|
||||
}
|
||||
if ($hadCapacitorQr) {
|
||||
$curCapacitorQr = $hadCapacitorQr;
|
||||
$curPanelBoxCode = $record->panel_box_code ?? null;
|
||||
$curPanelBoxSupplier = $record->panel_box_supplier ?? null;
|
||||
$curPanelBoxSerialNumber = $record->panel_box_serial_number ?? null;
|
||||
}
|
||||
$hadMotorQr = $record->motor_scanned_status ?? null;
|
||||
$hadPumpQr = $record->pump_scanned_status ?? null;
|
||||
$hadPumpSetQr = $record->scanned_status_set ?? null;
|
||||
$hadCapacitorQr = $record->capacitor_scanned_status ?? null;
|
||||
|
||||
if ($record->scanned_status == 'Scanned') {
|
||||
return null;
|
||||
} elseif ($record->invoice_number != $invoiceNumber) {
|
||||
throw new RowImportFailedException('Invoice number mismatch with existing record!');
|
||||
}
|
||||
|
||||
// if ($hadPumpQr == $hasPumpQr && $hadPumpSetQr == $hasPumpSetQr)
|
||||
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
|
||||
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpSetQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curCapacitorQr ? $scanCnt + 1 : $scanCnt;
|
||||
|
||||
$record->motor_scanned_status = $curMotorQr;
|
||||
$record->pump_scanned_status = $curPumpQr;
|
||||
$record->scanned_status_set = $curPumpSetQr;
|
||||
$record->capacitor_scanned_status = $curCapacitorQr;
|
||||
$record->panel_box_code = $curPanelBoxCode;
|
||||
$record->panel_box_supplier = $curPanelBoxSupplier;
|
||||
$record->panel_box_serial_number = $curPanelBoxSerialNumber;
|
||||
if ($packCnt == $scanCnt) {
|
||||
$record->scanned_status = 'Scanned';
|
||||
if ($hadMotorQr && $hasMotorQr) {
|
||||
$curMotorQr = $hadMotorQr;
|
||||
}
|
||||
if ($hadPumpQr && $hasPumpQr) {
|
||||
$curPumpQr = $hadPumpQr;
|
||||
}
|
||||
if ($hadPumpSetQr && $hasPumpSetQr) {
|
||||
$curPumpSetQr = $hadPumpSetQr;
|
||||
}
|
||||
if ($hadCapacitorQr && $hasCapacitorQr) {
|
||||
$curCapacitorQr = $hadCapacitorQr;
|
||||
$curPanelBoxCode = $record->panel_box_code ?? null;
|
||||
$curPanelBoxSupplier = $record->panel_box_supplier ?? null;
|
||||
$curPanelBoxSerialNumber = $record->panel_box_serial_number ?? null;
|
||||
}
|
||||
$record->updated_by = $updatedBy;
|
||||
$record->save();
|
||||
|
||||
return null;
|
||||
$warnMsg[] = 'Record Item ID : '.$record->sticker_master_id.' Master Item ID : '.$stickId;
|
||||
if ($record->invoice_number != $invoiceNumber) {
|
||||
$stickId = null;
|
||||
$warnMsg[] = 'Invoice number mismatch with existing record!';
|
||||
// throw new RowImportFailedException('Invoice number mismatch with existing record!');
|
||||
} elseif ($record->scanned_status == 'Scanned') {
|
||||
$stickId = null;
|
||||
|
||||
return null;
|
||||
} else {
|
||||
// if ($hadPumpQr == $hasPumpQr && $hadPumpSetQr == $hasPumpSetQr)
|
||||
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
|
||||
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpSetQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curCapacitorQr ? $scanCnt + 1 : $scanCnt;
|
||||
|
||||
$record->motor_scanned_status = $curMotorQr;
|
||||
$record->pump_scanned_status = $curPumpQr;
|
||||
$record->scanned_status_set = $curPumpSetQr;
|
||||
$record->capacitor_scanned_status = $curCapacitorQr;
|
||||
$record->panel_box_code = $curPanelBoxCode;
|
||||
$record->panel_box_supplier = $curPanelBoxSupplier;
|
||||
$record->panel_box_serial_number = $curPanelBoxSerialNumber;
|
||||
if ($packCnt == $scanCnt) {
|
||||
$record->scanned_status = 'Scanned';
|
||||
}
|
||||
$record->updated_by = $updatedBy;
|
||||
$record->save();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -426,45 +437,47 @@ class InvoiceValidationImporter extends Importer
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
|
||||
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpSetQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curCapacitorQr ? $scanCnt + 1 : $scanCnt;
|
||||
if ($stickId) {
|
||||
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
|
||||
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curPumpSetQr ? $scanCnt + 1 : $scanCnt;
|
||||
$scanCnt = $curCapacitorQr ? $scanCnt + 1 : $scanCnt;
|
||||
|
||||
if ($packCnt == $scanCnt) {
|
||||
$curScanStatus = 'Scanned';
|
||||
} else {
|
||||
$curScanStatus = null;
|
||||
if ($packCnt == $scanCnt) {
|
||||
$curScanStatus = 'Scanned';
|
||||
} else {
|
||||
$curScanStatus = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// $curScanStatus
|
||||
// $curScanStatus
|
||||
|
||||
InvoiceValidation::updateOrCreate([
|
||||
'plant_id' => $plantId,
|
||||
'sticker_master_id' => $stickId,
|
||||
'serial_number' => $serialNumber,
|
||||
],
|
||||
[
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'motor_scanned_status' => $curMotorQr,
|
||||
'pump_scanned_status' => $curPumpQr,
|
||||
'scanned_status_set' => $curPumpSetQr,
|
||||
'capacitor_scanned_status' => $curCapacitorQr,
|
||||
'panel_box_code' => $curPanelBoxCode,
|
||||
'panel_box_supplier' => $curPanelBoxSupplier,
|
||||
'panel_box_serial_number' => $curPanelBoxSerialNumber,
|
||||
'scanned_status' => $curScanStatus,
|
||||
'load_rate' => $loadRate,
|
||||
'upload_status' => $uploadStatus,
|
||||
'batch_number' => null,
|
||||
'quantity' => null,
|
||||
'operator_id' => $operatorId,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
InvoiceValidation::updateOrCreate([
|
||||
'plant_id' => $plantId,
|
||||
'sticker_master_id' => $stickId,
|
||||
'serial_number' => $serialNumber,
|
||||
],
|
||||
[
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'motor_scanned_status' => $curMotorQr,
|
||||
'pump_scanned_status' => $curPumpQr,
|
||||
'scanned_status_set' => $curPumpSetQr,
|
||||
'capacitor_scanned_status' => $curCapacitorQr,
|
||||
'panel_box_code' => $curPanelBoxCode,
|
||||
'panel_box_supplier' => $curPanelBoxSupplier,
|
||||
'panel_box_serial_number' => $curPanelBoxSerialNumber,
|
||||
'scanned_status' => $curScanStatus,
|
||||
'load_rate' => $loadRate,
|
||||
'upload_status' => $uploadStatus,
|
||||
'batch_number' => null,
|
||||
'quantity' => null,
|
||||
'operator_id' => $operatorId,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
|
||||
return null;
|
||||
// return new InvoiceValidation;
|
||||
|
||||
Reference in New Issue
Block a user