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
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -22,12 +22,12 @@ class MachineExporter 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('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('name')
|
||||
->label('MACHINE'),
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('work_center')
|
||||
->label('WORK CENTER'),
|
||||
ExportColumn::make('workGroupMaster.name')
|
||||
@@ -44,10 +44,10 @@ class MachineExporter extends Exporter
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your machine export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
$body = 'Your machine 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;
|
||||
|
||||
@@ -21,9 +21,9 @@ class MachineImporter extends Importer
|
||||
return [
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Machine')
|
||||
->exampleHeader('Machine Name')
|
||||
->example(['1600251'])
|
||||
->label('Machine')
|
||||
->label('Machine Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('work_center')
|
||||
->requiredMapping()
|
||||
@@ -41,16 +41,16 @@ class MachineImporter extends Importer
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Line')
|
||||
->exampleHeader('Line Name')
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line')
|
||||
->label('Line Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000'])
|
||||
->label('Plant Code')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
@@ -58,74 +58,74 @@ class MachineImporter extends Importer
|
||||
public function resolveRecord(): ?Machine
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$machine = $this->data['name'];
|
||||
$workCenter = $this->data['work_center'];
|
||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found!";
|
||||
}
|
||||
else {
|
||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
if ($line) {
|
||||
$grpWrkCnr = $line->no_of_operation;
|
||||
if (!$grpWrkCnr || $grpWrkCnr < 1)//Str::length($grpWrkCnr) < 1)
|
||||
{
|
||||
$warnMsg[] = "Group work center line not found!";
|
||||
}
|
||||
else if (!$groupWorkCenter) {
|
||||
$warnMsg[] = "Group work center not found!";
|
||||
}
|
||||
else {
|
||||
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
|
||||
if ($dupMachine) {
|
||||
$warnMsg[] = "Duplicate machine name found!";
|
||||
}
|
||||
else {
|
||||
$isValidGroupWork = false;
|
||||
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
||||
$column = "work_group{$i}_id";
|
||||
if (!empty($line->$column)) {
|
||||
if ($line->$column == $groupWorkCenter->id) {
|
||||
$isValidGroupWork = true;
|
||||
break;
|
||||
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 {
|
||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
if ($line) {
|
||||
$grpWrkCnr = $line->no_of_operation;
|
||||
if (! $grpWrkCnr || $grpWrkCnr < 1) {// Str::length($grpWrkCnr) < 1)
|
||||
$warnMsg[] = 'Group work center line not found!';
|
||||
} elseif (! $groupWorkCenter) {
|
||||
$warnMsg[] = 'Group work center not found!';
|
||||
} else {
|
||||
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
|
||||
if ($dupMachine) {
|
||||
$warnMsg[] = 'Duplicate machine name found!';
|
||||
} else {
|
||||
$isValidGroupWork = false;
|
||||
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
||||
$column = "work_group{$i}_id";
|
||||
if (! empty($line->$column)) {
|
||||
if ($groupWorkCenter->id == $line->$column) {
|
||||
$isValidGroupWork = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isValidGroupWork) {
|
||||
$warnMsg[] = "Group work center does not match with line!";
|
||||
if (! $isValidGroupWork) {
|
||||
$warnMsg[] = 'Group work center does not match with line!';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$warnMsg[] = 'Line not found!';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = "Line not found!";
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($machine) <= 0) {
|
||||
$warnMsg[] = "Machine name not found!";
|
||||
$warnMsg[] = 'Machine name not found!';
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Machine::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'work_center' => $workCenter
|
||||
'work_center' => $workCenter,
|
||||
],
|
||||
[
|
||||
'line_id' => $line->id,
|
||||
'name' => $machine,
|
||||
'work_group_master_id' => $groupWorkCenter->id
|
||||
'work_group_master_id' => $groupWorkCenter->id,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return Machine::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
@@ -137,10 +137,10 @@ class MachineImporter extends Importer
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your machine import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
$body = 'Your machine 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