Refactor QualityValidationImporter to improve record uniqueness on update logic

This commit is contained in:
dhanabalan
2025-09-13 11:16:22 +05:30
parent 36006e6e08
commit bac7c610f8

View File

@@ -193,9 +193,9 @@ class QualityValidationImporter extends Importer
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first(); $line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
$uniqueCode = trim($this->data['sticker_master_id_code']);// stickerMaster.item $uniqueCode = trim($this->data['sticker_master_id_code']);// stickerMaster.item
$stickMaster = StickerMaster::select('id')->with('item') $stickMaster = StickerMaster::select('id')->with('item')
->whereHas('item', function ($query) use ($uniqueCode, $plant) { ->whereHas('item', function ($query) use ($uniqueCode, $plant) {
$query->where('code', $uniqueCode)->where('plant_id', $plant->id); $query->where('code', $uniqueCode)->where('plant_id', $plant->id);
})->value('id'); })->value('id');
} }
if (!$line) { if (!$line) {
@@ -281,11 +281,13 @@ class QualityValidationImporter extends Importer
QualityValidation::updateOrCreate([ QualityValidation::updateOrCreate([
'plant_id' => $plant->id, 'plant_id' => $plant->id,
'line_id' => $line->id,
'sticker_master_id' => $stickMaster,//->id 'sticker_master_id' => $stickMaster,//->id
'serial_number' => $this->data['serial_number']
],
[
'line_id' => $line->id,
'uom' => $this->data['uom'], 'uom' => $this->data['uom'],
'production_order' => $this->data['production_order'], 'production_order' => $this->data['production_order'],
'serial_number' => $this->data['serial_number'],
'serial_number_motor' => $this->data['serial_number_motor'], 'serial_number_motor' => $this->data['serial_number_motor'],
'serial_number_pump' => $this->data['serial_number_pump'], 'serial_number_pump' => $this->data['serial_number_pump'],
'serial_number_pumpset' => $this->data['serial_number_pumpset'], 'serial_number_pumpset' => $this->data['serial_number_pumpset'],