Added Line column and updated sticker_master_id column name with its func.

This commit is contained in:
dhanabalan
2025-05-28 16:57:06 +05:30
parent 6b39fc7236
commit f6d7394ebd

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Imports; namespace App\Filament\Imports;
use App\Models\Item; use App\Models\Item;
use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
use App\Models\QualityValidation; use App\Models\QualityValidation;
use App\Models\StickerMaster; use App\Models\StickerMaster;
@@ -36,21 +37,28 @@ class QualityValidationImporter extends Importer
->label('Plant Name') ->label('Plant Name')
->relationship(resolveUsing:'name') ->relationship(resolveUsing:'name')
->rules(['required']), ->rules(['required']),
ImportColumn::make('sticker_master_id') // stickerMaster.item ImportColumn::make('line')
->requiredMapping()
->exampleHeader('Line Name')
->example('4 inch pump line')
->label('Line Name')
->relationship(resolveUsing:'name')
->rules(['required']),
ImportColumn::make('sticker_master_id_code') // stickerMaster.item
->requiredMapping() ->requiredMapping()
->exampleHeader('Item Code') ->exampleHeader('Item Code')
->example('123456') ->example('123456')
->label('Item Code') ->label('Item Code'),
->relationship( // ->relationship(
name: 'stickerMaster', // name: 'stickerMaster',
resolveUsing: function ($state) { // resolveUsing: function ($state) {
$state = trim($state); // $state = trim($state);
$item = Item::where('code', $state)->first(); // $item = Item::where('code', $state)->first();
return $item // return $item
? StickerMaster::where('item_id', $item->id)->value('id') // ? StickerMaster::where('item_id', $item->id)->value('id')
: null; // : null;
} // }
), // ),
ImportColumn::make('production_order') ImportColumn::make('production_order')
->requiredMapping() ->requiredMapping()
->exampleHeader('Production Order') ->exampleHeader('Production Order')
@@ -176,16 +184,24 @@ class QualityValidationImporter extends Importer
{ {
$warnMsg = []; $warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first(); $plant = Plant::where('name', $this->data['plant'])->first();
$line = null;
$stickMaster = null;
if (!$plant) { if (!$plant) {
$warnMsg[] = "Plant not found"; $warnMsg[] = "Plant not found";
} }
else {
$uniqueCode = trim($this->data['sticker_master_id']);// stickerMaster.item $line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
$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) {
$warnMsg[] = "Line not found";
}
if (!$stickMaster) { if (!$stickMaster) {
$warnMsg[] = "Sticker item code not found"; $warnMsg[] = "Sticker item code not found";
} }
@@ -197,6 +213,7 @@ class QualityValidationImporter extends Importer
if (!ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) { if (!ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
$warnMsg[] = "Invalid serial number found"; $warnMsg[] = "Invalid serial number found";
} }
// dd($stickMaster);
// if (Str::length($this->data['uom']) < 1) { // if (Str::length($this->data['uom']) < 1) {
// $warnMsg[] = "Invalid unit of measure found"; // $warnMsg[] = "Invalid unit of measure found";
@@ -261,8 +278,10 @@ class QualityValidationImporter extends Importer
if (!empty($warnMsg)) { if (!empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
return 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
'uom' => $this->data['uom'], 'uom' => $this->data['uom'],
'production_order' => $this->data['production_order'], 'production_order' => $this->data['production_order'],
@@ -289,6 +308,8 @@ class QualityValidationImporter extends Importer
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'], 'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
'operator_id' => $this->data['operator_id'], 'operator_id' => $this->data['operator_id'],
]); ]);
return null;
// return QualityValidation::firstOrNew([ // return QualityValidation::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']` // // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'], // 'email' => $this->data['email'],