Added Line column and updated sticker_master_id column name with its func.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
@@ -36,21 +37,28 @@ class QualityValidationImporter extends Importer
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->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()
|
||||
->exampleHeader('Item Code')
|
||||
->example('123456')
|
||||
->label('Item Code')
|
||||
->relationship(
|
||||
name: 'stickerMaster',
|
||||
resolveUsing: function ($state) {
|
||||
$state = trim($state);
|
||||
$item = Item::where('code', $state)->first();
|
||||
return $item
|
||||
? StickerMaster::where('item_id', $item->id)->value('id')
|
||||
: null;
|
||||
}
|
||||
),
|
||||
->label('Item Code'),
|
||||
// ->relationship(
|
||||
// name: 'stickerMaster',
|
||||
// resolveUsing: function ($state) {
|
||||
// $state = trim($state);
|
||||
// $item = Item::where('code', $state)->first();
|
||||
// return $item
|
||||
// ? StickerMaster::where('item_id', $item->id)->value('id')
|
||||
// : null;
|
||||
// }
|
||||
// ),
|
||||
ImportColumn::make('production_order')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Production Order')
|
||||
@@ -176,16 +184,24 @@ class QualityValidationImporter extends Importer
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$line = null;
|
||||
$stickMaster = null;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
|
||||
$uniqueCode = trim($this->data['sticker_master_id']);// stickerMaster.item
|
||||
|
||||
$stickMaster = StickerMaster::select('id')->with('item')
|
||||
else {
|
||||
$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')
|
||||
->whereHas('item', function ($query) use ($uniqueCode, $plant) {
|
||||
$query->where('code', $uniqueCode)->where('plant_id', $plant->id);
|
||||
})->value('id');
|
||||
}
|
||||
|
||||
if (!$line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
}
|
||||
|
||||
if (!$stickMaster) {
|
||||
$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) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
}
|
||||
// dd($stickMaster);
|
||||
|
||||
// if (Str::length($this->data['uom']) < 1) {
|
||||
// $warnMsg[] = "Invalid unit of measure found";
|
||||
@@ -261,8 +278,10 @@ class QualityValidationImporter extends Importer
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
return QualityValidation::updateOrCreate([
|
||||
|
||||
QualityValidation::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'line_id' => $line->id,
|
||||
'sticker_master_id' => $stickMaster,//->id
|
||||
'uom' => $this->data['uom'],
|
||||
'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'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
// return QualityValidation::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
|
||||
Reference in New Issue
Block a user