diff --git a/app/Filament/Exports/CheckPointTimeExporter.php b/app/Filament/Exports/CheckPointTimeExporter.php index 42193f1..86b9adc 100644 --- a/app/Filament/Exports/CheckPointTimeExporter.php +++ b/app/Filament/Exports/CheckPointTimeExporter.php @@ -24,8 +24,8 @@ class CheckPointTimeExporter extends Exporter // Increment and return the row number return ++$rowNumber; }), - ExportColumn::make('plant.name') - ->label('PLANT'), + ExportColumn::make('plant.code') + ->label('PLANT CODE'), ExportColumn::make('checkPointNames1.name') ->label('CHECK POINT 1'), ExportColumn::make('checkPointNames2.name') @@ -50,10 +50,10 @@ class CheckPointTimeExporter extends Exporter public static function getCompletedNotificationBody(Export $export): string { - $body = 'Your check point time export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.'; + $body = 'Your check point time export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.'; if ($failedRowsCount = $export->getFailedRowsCount()) { - $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.'; + $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.'; } return $body; diff --git a/app/Filament/Imports/CheckPointTimeImporter.php b/app/Filament/Imports/CheckPointTimeImporter.php index b981ce1..946587b 100644 --- a/app/Filament/Imports/CheckPointTimeImporter.php +++ b/app/Filament/Imports/CheckPointTimeImporter.php @@ -21,10 +21,10 @@ class CheckPointTimeImporter extends Importer return [ ImportColumn::make('plant') ->requiredMapping() - ->exampleHeader('Plant Name') - ->example('Ransar Industries-I') - ->label('Plant Name') - ->relationship(resolveUsing: 'name') + ->exampleHeader('Plant Code') + ->example('1000') + ->label('Plant Code') + ->relationship(resolveUsing: 'code') ->rules(['required']), ImportColumn::make('checkPointNames1') ->requiredMapping() @@ -73,50 +73,51 @@ class CheckPointTimeImporter extends Importer public function resolveRecord(): ?CheckPointTime { $warnMsg = []; - $plant = Plant::where('name', $this->data['plant'])->first(); + $plantCod = $this->data['plant']; + $plant = null; $checkPointNames1 = null; $checkPointNames2 = null; - if (!$plant) { - $warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "' - } - else - { - $checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first(); - if (!$checkPointNames1) { - $warnMsg[] = "Check point 1 not found"; - } - else - { - $checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first(); - if (!$checkPointNames2) { - $warnMsg[] = "Check point 2 not found"; - } - else - { - if ($checkPointNames1->id === $checkPointNames2->id) { - $warnMsg[] = "Check point 1 and 2 can't be the same"; + if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { + $warnMsg[] = 'Invalid plant code found'; + } else { + $plant = Plant::where('code', $plantCod)->first(); + if (! $plant) { + $warnMsg[] = 'Plant not found'; // '" . $plantCod . "' + } else { + $checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first(); + if (! $checkPointNames1) { + $warnMsg[] = 'Check point 1 not found'; + } else { + $checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first(); + if (! $checkPointNames2) { + $warnMsg[] = 'Check point 2 not found'; + } else { + if ($checkPointNames1->id === $checkPointNames2->id) { + $warnMsg[] = "Check point 1 and 2 can't be the same"; + } } } } } - if (Str::length($this->data['sequence_number']) < 1 || !is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) { - $warnMsg[] = "Invalid sequence number found"; + if (Str::length($this->data['sequence_number']) < 1 || ! is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) { + $warnMsg[] = 'Invalid sequence number found'; } - if (Str::length($this->data['time_lapse']) < 1 || !is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) { - $warnMsg[] = "Invalid time lapse found"; + if (Str::length($this->data['time_lapse']) < 1 || ! is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) { + $warnMsg[] = 'Invalid time lapse found'; } - if (Str::length($this->data['time_lapse_cushioning']) < 1 || !is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) { - $warnMsg[] = "Invalid time lapse cushioning found"; + if (Str::length($this->data['time_lapse_cushioning']) < 1 || ! is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) { + $warnMsg[] = 'Invalid time lapse cushioning found'; } $createdBy = $this->data['created_by']; if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy) - $warnMsg[] = "Invalid created by name found"; + $warnMsg[] = 'Invalid created by name found'; } - if (!empty($warnMsg)) { + + if (! empty($warnMsg)) { throw new RowImportFailedException(implode(', ', $warnMsg)); } @@ -124,12 +125,12 @@ class CheckPointTimeImporter extends Importer 'plant_id' => $plant->id, 'check_point1_id' => $checkPointNames1->id, 'check_point2_id' => $checkPointNames2->id, - 'sequence_number' => $this->data['sequence_number'] + 'sequence_number' => $this->data['sequence_number'], ], - [ - 'time_lapse' => $this->data['time_lapse'], - 'time_lapse_cushioning' => $this->data['time_lapse_cushioning'], - 'created_by' => $this->data['created_by'] + [ + 'time_lapse' => $this->data['time_lapse'], + 'time_lapse_cushioning' => $this->data['time_lapse_cushioning'], + 'created_by' => $this->data['created_by'], ] ); // // return CheckPointTime::firstOrNew([ @@ -142,10 +143,10 @@ class CheckPointTimeImporter extends Importer public static function getCompletedNotificationBody(Import $import): string { - $body = 'Your check point time import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; + $body = 'Your check point time import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.'; if ($failedRowsCount = $import->getFailedRowsCount()) { - $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.'; + $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.'; } return $body;