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
|
// 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('item.code')
|
ExportColumn::make('item.code')
|
||||||
->label('ITEM CODE'),
|
->label('ITEM CODE'),
|
||||||
ExportColumn::make('obd_number')
|
ExportColumn::make('obd_number')
|
||||||
@@ -58,10 +58,10 @@ class WeightValidationExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
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()) {
|
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;
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ class WeightValidationImporter extends Importer
|
|||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
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('scanned_by')
|
ImportColumn::make('scanned_by')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -92,82 +92,95 @@ class WeightValidationImporter extends Importer
|
|||||||
public function resolveRecord(): ?WeightValidation
|
public function resolveRecord(): ?WeightValidation
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
if (!$plant) {
|
$iCode = $this->data['item'];
|
||||||
$warnMsg[] = "Plant not found";
|
$plantId = null;
|
||||||
}
|
$itemId = null;
|
||||||
$item = null;
|
|
||||||
if ($plant) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
if (Str::length($this->data['item']) < 6 || !ctype_alnum($this->data['item'])) {
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
$warnMsg[] = "Invalid item 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 (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||||
if (!$item) {
|
$warnMsg[] = 'Invalid item code found';
|
||||||
$warnMsg[] = "Item code not 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'];
|
$obdNum = $this->data['obd_number'];
|
||||||
if (Str::length($obdNum) < 8 || !ctype_alnum($obdNum)) {
|
if (Str::length($obdNum) < 8 || ! ctype_alnum($obdNum)) {
|
||||||
$warnMsg[] = "Invalid OBD number found";
|
$warnMsg[] = 'Invalid OBD number found';
|
||||||
}
|
}
|
||||||
$lineNum = $this->data['line_number'];
|
$lineNum = $this->data['line_number'];
|
||||||
if (Str::length($lineNum) < 1 || !is_numeric($lineNum)) {
|
if (Str::length($lineNum) < 1 || ! is_numeric($lineNum)) {
|
||||||
$warnMsg[] = "Invalid line number found";
|
$warnMsg[] = 'Invalid line number found';
|
||||||
}
|
}
|
||||||
$batchNum = $this->data['batch_number'];
|
$batchNum = $this->data['batch_number'];
|
||||||
if (Str::length($batchNum) < 8 || !is_numeric($batchNum)) {
|
if (Str::length($batchNum) < 8 || ! is_numeric($batchNum)) {
|
||||||
$warnMsg[] = "Invalid batch number found";
|
$warnMsg[] = 'Invalid batch number found';
|
||||||
}
|
}
|
||||||
$heatNum = $this->data['heat_number'];
|
$heatNum = $this->data['heat_number'];
|
||||||
if (Str::length($heatNum) < 4) {
|
if (Str::length($heatNum) < 4) {
|
||||||
$warnMsg[] = "Invalid heat number found";
|
$warnMsg[] = 'Invalid heat number found';
|
||||||
}
|
}
|
||||||
$actWeight = $this->data['obd_weight'];
|
$actWeight = $this->data['obd_weight'];
|
||||||
if (Str::length($actWeight) < 1 || !is_numeric($actWeight)) {
|
if (Str::length($actWeight) < 1 || ! is_numeric($actWeight)) {
|
||||||
$warnMsg[] = "Invalid actual weight found";
|
$warnMsg[] = 'Invalid actual weight found';
|
||||||
}
|
}
|
||||||
$vehicleNum = $this->data['vehicle_number'];
|
$vehicleNum = $this->data['vehicle_number'];
|
||||||
if (Str::length($vehicleNum) < 10 || !ctype_alnum($vehicleNum)) {
|
if (Str::length($vehicleNum) < 10 || ! ctype_alnum($vehicleNum)) {
|
||||||
$warnMsg[] = "Invalid vehicle number found";
|
$warnMsg[] = 'Invalid vehicle number found';
|
||||||
}
|
}
|
||||||
$bundleNum = $this->data['bundle_number'];
|
$bundleNum = $this->data['bundle_number'];
|
||||||
if (Str::length($bundleNum) < 1 || !is_numeric($bundleNum)) {
|
if (Str::length($bundleNum) < 1 || ! is_numeric($bundleNum)) {
|
||||||
$warnMsg[] = "Invalid bundle number found";
|
$warnMsg[] = 'Invalid bundle number found';
|
||||||
}
|
}
|
||||||
$pickWeight = $this->data['picked_weight'];
|
$pickWeight = $this->data['picked_weight'];
|
||||||
if (Str::length($pickWeight) < 1 || !is_numeric($pickWeight)) {
|
if (Str::length($pickWeight) < 1 || ! is_numeric($pickWeight)) {
|
||||||
$warnMsg[] = "Invalid picked weight found";
|
$warnMsg[] = 'Invalid picked weight found';
|
||||||
}
|
}
|
||||||
$scanBy = $this->data['scanned_by'];
|
$scanBy = $this->data['scanned_by'];
|
||||||
if (Str::length($scanBy) < 3 || !ctype_alnum($scanBy)) {
|
if (Str::length($scanBy) < 3 || ! ctype_alnum($scanBy)) {
|
||||||
$warnMsg[] = "Invalid scanned by name found";
|
$warnMsg[] = 'Invalid scanned by name found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return WeightValidation::updateOrCreate([
|
return WeightValidation::updateOrCreate([
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plantId,
|
||||||
'obd_number' => $obdNum,
|
'obd_number' => $obdNum,
|
||||||
'line_number' => $lineNum
|
'line_number' => $lineNum,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'item_id' => $item->id,
|
'item_id' => $itemId,
|
||||||
'batch_number' => $batchNum,
|
'batch_number' => $batchNum,
|
||||||
'heat_number' => $heatNum,
|
'heat_number' => $heatNum,
|
||||||
'obd_weight' => $actWeight,
|
'obd_weight' => $actWeight,
|
||||||
'vehicle_number' => $vehicleNum,
|
'vehicle_number' => $vehicleNum,
|
||||||
'bundle_number' => $bundleNum,
|
'bundle_number' => $bundleNum,
|
||||||
'picked_weight' => $pickWeight,
|
'picked_weight' => $pickWeight,
|
||||||
'scanned_by' => $scanBy
|
'scanned_by' => $scanBy,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// return WeightValidation::firstOrNew([
|
// return WeightValidation::firstOrNew([
|
||||||
@@ -180,10 +193,10 @@ class WeightValidationImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
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()) {
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user