Added plant code instead of plant name on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -24,8 +24,8 @@ class WeightValidationExporter 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('item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('obd_number')
|
||||
@@ -58,10 +58,10 @@ class WeightValidationExporter extends Exporter
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your weight validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
$body = 'Your weight validation 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;
|
||||
|
||||
@@ -75,10 +75,10 @@ class WeightValidationImporter extends Importer
|
||||
->rules(['required']),
|
||||
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('scanned_by')
|
||||
->requiredMapping()
|
||||
@@ -92,82 +92,95 @@ class WeightValidationImporter extends Importer
|
||||
public function resolveRecord(): ?WeightValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
$item = null;
|
||||
if ($plant) {
|
||||
if (Str::length($this->data['item']) < 6 || !ctype_alnum($this->data['item'])) {
|
||||
$warnMsg[] = "Invalid item code found";
|
||||
$plantCod = $this->data['plant'];
|
||||
$iCode = $this->data['item'];
|
||||
$plantId = null;
|
||||
$itemId = null;
|
||||
|
||||
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';
|
||||
} else {
|
||||
$plantId = $plant->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
|
||||
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||
$warnMsg[] = 'Invalid item code found';
|
||||
} else {
|
||||
$itemCode = Item::where('code', $iCode)->first();
|
||||
if (! $itemCode) {
|
||||
$warnMsg[] = 'Item code not found';
|
||||
} else {
|
||||
if ($plantId) {
|
||||
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||
if (! $itemAgainstPlant) {
|
||||
$warnMsg[] = 'Item code not found for the given plant';
|
||||
} else {
|
||||
$itemId = $itemAgainstPlant->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //if (!$item)
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
|
||||
$obdNum = $this->data['obd_number'];
|
||||
if (Str::length($obdNum) < 8 || !ctype_alnum($obdNum)) {
|
||||
$warnMsg[] = "Invalid OBD number found";
|
||||
if (Str::length($obdNum) < 8 || ! ctype_alnum($obdNum)) {
|
||||
$warnMsg[] = 'Invalid OBD number found';
|
||||
}
|
||||
$lineNum = $this->data['line_number'];
|
||||
if (Str::length($lineNum) < 1 || !is_numeric($lineNum)) {
|
||||
$warnMsg[] = "Invalid line number found";
|
||||
if (Str::length($lineNum) < 1 || ! is_numeric($lineNum)) {
|
||||
$warnMsg[] = 'Invalid line number found';
|
||||
}
|
||||
$batchNum = $this->data['batch_number'];
|
||||
if (Str::length($batchNum) < 8 || !is_numeric($batchNum)) {
|
||||
$warnMsg[] = "Invalid batch number found";
|
||||
if (Str::length($batchNum) < 8 || ! is_numeric($batchNum)) {
|
||||
$warnMsg[] = 'Invalid batch number found';
|
||||
}
|
||||
$heatNum = $this->data['heat_number'];
|
||||
if (Str::length($heatNum) < 4) {
|
||||
$warnMsg[] = "Invalid heat number found";
|
||||
$warnMsg[] = 'Invalid heat number found';
|
||||
}
|
||||
$actWeight = $this->data['obd_weight'];
|
||||
if (Str::length($actWeight) < 1 || !is_numeric($actWeight)) {
|
||||
$warnMsg[] = "Invalid actual weight found";
|
||||
if (Str::length($actWeight) < 1 || ! is_numeric($actWeight)) {
|
||||
$warnMsg[] = 'Invalid actual weight found';
|
||||
}
|
||||
$vehicleNum = $this->data['vehicle_number'];
|
||||
if (Str::length($vehicleNum) < 10 || !ctype_alnum($vehicleNum)) {
|
||||
$warnMsg[] = "Invalid vehicle number found";
|
||||
if (Str::length($vehicleNum) < 10 || ! ctype_alnum($vehicleNum)) {
|
||||
$warnMsg[] = 'Invalid vehicle number found';
|
||||
}
|
||||
$bundleNum = $this->data['bundle_number'];
|
||||
if (Str::length($bundleNum) < 1 || !is_numeric($bundleNum)) {
|
||||
$warnMsg[] = "Invalid bundle number found";
|
||||
if (Str::length($bundleNum) < 1 || ! is_numeric($bundleNum)) {
|
||||
$warnMsg[] = 'Invalid bundle number found';
|
||||
}
|
||||
$pickWeight = $this->data['picked_weight'];
|
||||
if (Str::length($pickWeight) < 1 || !is_numeric($pickWeight)) {
|
||||
$warnMsg[] = "Invalid picked weight found";
|
||||
if (Str::length($pickWeight) < 1 || ! is_numeric($pickWeight)) {
|
||||
$warnMsg[] = 'Invalid picked weight found';
|
||||
}
|
||||
$scanBy = $this->data['scanned_by'];
|
||||
if (Str::length($scanBy) < 3 || !ctype_alnum($scanBy)) {
|
||||
$warnMsg[] = "Invalid scanned by name found";
|
||||
if (Str::length($scanBy) < 3 || ! ctype_alnum($scanBy)) {
|
||||
$warnMsg[] = 'Invalid scanned by name found';
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
return WeightValidation::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'obd_number' => $obdNum,
|
||||
'line_number' => $lineNum
|
||||
],
|
||||
'plant_id' => $plantId,
|
||||
'obd_number' => $obdNum,
|
||||
'line_number' => $lineNum,
|
||||
],
|
||||
[
|
||||
'item_id' => $item->id,
|
||||
'item_id' => $itemId,
|
||||
'batch_number' => $batchNum,
|
||||
'heat_number' => $heatNum,
|
||||
'obd_weight' => $actWeight,
|
||||
'vehicle_number' => $vehicleNum,
|
||||
'bundle_number' => $bundleNum,
|
||||
'picked_weight' => $pickWeight,
|
||||
'scanned_by' => $scanBy
|
||||
'scanned_by' => $scanBy,
|
||||
]
|
||||
);
|
||||
// return WeightValidation::firstOrNew([
|
||||
@@ -180,10 +193,10 @@ class WeightValidationImporter extends Importer
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your weight validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
$body = 'Your weight validation 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;
|
||||
|
||||
Reference in New Issue
Block a user