Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

This commit is contained in:
dhanabalan
2026-01-13 16:17:03 +05:30
parent 5cba017b72
commit 4de209841a
2 changed files with 44 additions and 43 deletions

View File

@@ -24,8 +24,8 @@ class CheckPointTimeExporter extends Exporter
// Increment and return the row number // Increment and return the row number
return ++$rowNumber; return ++$rowNumber;
}), }),
ExportColumn::make('plant.name') ExportColumn::make('plant.code')
->label('PLANT'), ->label('PLANT CODE'),
ExportColumn::make('checkPointNames1.name') ExportColumn::make('checkPointNames1.name')
->label('CHECK POINT 1'), ->label('CHECK POINT 1'),
ExportColumn::make('checkPointNames2.name') ExportColumn::make('checkPointNames2.name')
@@ -50,10 +50,10 @@ class CheckPointTimeExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string 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()) { 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; return $body;

View File

@@ -21,10 +21,10 @@ class CheckPointTimeImporter extends Importer
return [ return [
ImportColumn::make('plant') ImportColumn::make('plant')
->requiredMapping() ->requiredMapping()
->exampleHeader('Plant Name') ->exampleHeader('Plant Code')
->example('Ransar Industries-I') ->example('1000')
->label('Plant Name') ->label('Plant Code')
->relationship(resolveUsing: 'name') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('checkPointNames1') ImportColumn::make('checkPointNames1')
->requiredMapping() ->requiredMapping()
@@ -73,50 +73,51 @@ class CheckPointTimeImporter extends Importer
public function resolveRecord(): ?CheckPointTime public function resolveRecord(): ?CheckPointTime
{ {
$warnMsg = []; $warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first(); $plantCod = $this->data['plant'];
$plant = null;
$checkPointNames1 = null; $checkPointNames1 = null;
$checkPointNames2 = null; $checkPointNames2 = null;
if (!$plant) { if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "' $warnMsg[] = 'Invalid plant code found';
} } else {
else $plant = Plant::where('code', $plantCod)->first();
{ if (! $plant) {
$checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first(); $warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
if (!$checkPointNames1) { } else {
$warnMsg[] = "Check point 1 not found"; $checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first();
} if (! $checkPointNames1) {
else $warnMsg[] = 'Check point 1 not found';
{ } else {
$checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first(); $checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first();
if (!$checkPointNames2) { if (! $checkPointNames2) {
$warnMsg[] = "Check point 2 not found"; $warnMsg[] = 'Check point 2 not found';
} } else {
else if ($checkPointNames1->id === $checkPointNames2->id) {
{ $warnMsg[] = "Check point 1 and 2 can't be the same";
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) { if (Str::length($this->data['sequence_number']) < 1 || ! is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) {
$warnMsg[] = "Invalid sequence number found"; $warnMsg[] = 'Invalid sequence number found';
} }
if (Str::length($this->data['time_lapse']) < 1 || !is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) { if (Str::length($this->data['time_lapse']) < 1 || ! is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) {
$warnMsg[] = "Invalid time lapse found"; $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) { 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"; $warnMsg[] = 'Invalid time lapse cushioning found';
} }
$createdBy = $this->data['created_by']; $createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy) 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)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
@@ -124,12 +125,12 @@ class CheckPointTimeImporter extends Importer
'plant_id' => $plant->id, 'plant_id' => $plant->id,
'check_point1_id' => $checkPointNames1->id, 'check_point1_id' => $checkPointNames1->id,
'check_point2_id' => $checkPointNames2->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' => $this->data['time_lapse'],
'time_lapse_cushioning' => $this->data['time_lapse_cushioning'], 'time_lapse_cushioning' => $this->data['time_lapse_cushioning'],
'created_by' => $this->data['created_by'] 'created_by' => $this->data['created_by'],
] ]
); );
// // return CheckPointTime::firstOrNew([ // // return CheckPointTime::firstOrNew([
@@ -142,10 +143,10 @@ class CheckPointTimeImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string 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()) { 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; return $body;