diff --git a/app/Filament/Imports/ProductionQuantityImporter.php b/app/Filament/Imports/ProductionQuantityImporter.php index 0ea91002..f15f4f20 100644 --- a/app/Filament/Imports/ProductionQuantityImporter.php +++ b/app/Filament/Imports/ProductionQuantityImporter.php @@ -57,19 +57,19 @@ class ProductionQuantityImporter extends Importer ->label('Line Name') ->relationship(resolveUsing: 'name') ->rules(['required']), - ImportColumn::make('block_reference') - ->requiredMapping() // Or optionalMapping() if not always present - ->exampleHeader('Block Name') - ->example(['Block A', 'Block A']) - ->label('Block Name') - ->rules(['required']), // Or remove if not required - ImportColumn::make('shift') - ->requiredMapping() - ->exampleHeader('Shift Name') - ->example(['Day', 'Night']) - ->label('Shift Name') - ->relationship(resolveUsing: 'name') - ->rules(['required']), + // ImportColumn::make('block_reference') + // ->requiredMapping() // Or optionalMapping() if not always present + // ->exampleHeader('Block Name') + // ->example(['Block A', 'Block A']) + // ->label('Block Name') + // ->rules(['required']), // Or remove if not required + // ImportColumn::make('shift') + // ->requiredMapping() + // ->exampleHeader('Shift Name') + // ->example(['Day', 'Night']) + // ->label('Shift Name') + // ->relationship(resolveUsing: 'name') + // ->rules(['required']), ImportColumn::make('plant') ->requiredMapping() ->exampleHeader('Plant Code') @@ -98,8 +98,8 @@ class ProductionQuantityImporter extends Importer $plantCod = $this->data['plant']; $plant = null; $line = null; - $block = null; - $shift = null; + // $block = null; + // $shift = null; if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { $warnMsg[] = 'Invalid plant code found'; } else { @@ -110,23 +110,11 @@ class ProductionQuantityImporter extends Importer $warnMsg[] = 'Plant not found'; } else { $line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first(); - // block_reference - $block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first(); } if (! $line) { $warnMsg[] = 'Line not found'; } - if (! $block) { - $warnMsg[] = 'Block not found'; - } elseif ($plant) { - $shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first(); - } - - // $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first(); - if (! $shift) { - $warnMsg[] = 'Shift not found'; - } $item = null; if ($plant) { @@ -199,6 +187,31 @@ class ProductionQuantityImporter extends Importer $warnMsg[] = 'Operator ID not found'; } + $shift = null; + + if (isset($fdateTime) && $plant) { + + $createdTime = $fdateTime->format('H:i:s'); + + if ($createdTime >= '08:00:00' && $createdTime < '19:30:00') { + + $shiftName = 'Day'; + + } else { + + $shiftName = 'Night'; + + } + + $shift = Shift::where('plant_id', $plant->id) + ->where('name', $shiftName) + ->first(); + + if (! $shift) { + $warnMsg[] = "{$shiftName} shift not found"; + } + } + if (! empty($warnMsg)) { throw new RowImportFailedException(implode(', ', $warnMsg)); } else { // if (empty($warnMsg)) @@ -212,6 +225,8 @@ class ProductionQuantityImporter extends Importer } } + + ProductionQuantity::updateOrCreate([ 'serial_number' => $this->data['serial_number'], 'plant_id' => $plant->id,