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
|
// 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('line.name')
|
ExportColumn::make('line.name')
|
||||||
->label('LINE'),
|
->label('LINE NAME'),
|
||||||
ExportColumn::make('name')
|
ExportColumn::make('name')
|
||||||
->label('MACHINE'),
|
->label('MACHINE NAME'),
|
||||||
ExportColumn::make('work_center')
|
ExportColumn::make('work_center')
|
||||||
->label('WORK CENTER'),
|
->label('WORK CENTER'),
|
||||||
ExportColumn::make('workGroupMaster.name')
|
ExportColumn::make('workGroupMaster.name')
|
||||||
@@ -44,10 +44,10 @@ class MachineExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
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()) {
|
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;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ class MachineImporter extends Importer
|
|||||||
return [
|
return [
|
||||||
ImportColumn::make('name')
|
ImportColumn::make('name')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Machine')
|
->exampleHeader('Machine Name')
|
||||||
->example(['1600251'])
|
->example(['1600251'])
|
||||||
->label('Machine')
|
->label('Machine Name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('work_center')
|
ImportColumn::make('work_center')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -41,16 +41,16 @@ class MachineImporter extends Importer
|
|||||||
ImportColumn::make('line')
|
ImportColumn::make('line')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->relationship(resolveUsing: 'name')
|
->relationship(resolveUsing: 'name')
|
||||||
->exampleHeader('Line')
|
->exampleHeader('Line Name')
|
||||||
->example(['4 inch pump line'])
|
->example(['4 inch pump line'])
|
||||||
->label('Line')
|
->label('Line Name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('plant')
|
ImportColumn::make('plant')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->relationship(resolveUsing: 'name')
|
->relationship(resolveUsing: 'code')
|
||||||
->exampleHeader('Plant')
|
->exampleHeader('Plant Code')
|
||||||
->example(['Ransar Industries-I'])
|
->example(['1000'])
|
||||||
->label('Plant')
|
->label('Plant Code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -58,74 +58,74 @@ class MachineImporter extends Importer
|
|||||||
public function resolveRecord(): ?Machine
|
public function resolveRecord(): ?Machine
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
$line = null;
|
$line = null;
|
||||||
$machine = $this->data['name'];
|
$machine = $this->data['name'];
|
||||||
$workCenter = $this->data['work_center'];
|
$workCenter = $this->data['work_center'];
|
||||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->first();
|
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->first();
|
||||||
if (!$plant) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = "Plant not found!";
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
}
|
} else {
|
||||||
else {
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
|
if (! $plant) {
|
||||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
$warnMsg[] = 'Plant not found!';
|
||||||
if ($line) {
|
} else {
|
||||||
$grpWrkCnr = $line->no_of_operation;
|
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
|
||||||
if (!$grpWrkCnr || $grpWrkCnr < 1)//Str::length($grpWrkCnr) < 1)
|
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||||
{
|
if ($line) {
|
||||||
$warnMsg[] = "Group work center line not found!";
|
$grpWrkCnr = $line->no_of_operation;
|
||||||
}
|
if (! $grpWrkCnr || $grpWrkCnr < 1) {// Str::length($grpWrkCnr) < 1)
|
||||||
else if (!$groupWorkCenter) {
|
$warnMsg[] = 'Group work center line not found!';
|
||||||
$warnMsg[] = "Group work center not found!";
|
} elseif (! $groupWorkCenter) {
|
||||||
}
|
$warnMsg[] = 'Group work center not found!';
|
||||||
else {
|
} else {
|
||||||
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
|
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
|
||||||
if ($dupMachine) {
|
if ($dupMachine) {
|
||||||
$warnMsg[] = "Duplicate machine name found!";
|
$warnMsg[] = 'Duplicate machine name found!';
|
||||||
}
|
} else {
|
||||||
else {
|
$isValidGroupWork = false;
|
||||||
$isValidGroupWork = false;
|
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
||||||
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
$column = "work_group{$i}_id";
|
||||||
$column = "work_group{$i}_id";
|
if (! empty($line->$column)) {
|
||||||
if (!empty($line->$column)) {
|
if ($groupWorkCenter->id == $line->$column) {
|
||||||
if ($line->$column == $groupWorkCenter->id) {
|
$isValidGroupWork = true;
|
||||||
$isValidGroupWork = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!$isValidGroupWork) {
|
if (! $isValidGroupWork) {
|
||||||
$warnMsg[] = "Group work center does not match with line!";
|
$warnMsg[] = 'Group work center does not match with line!';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$warnMsg[] = 'Line not found!';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$warnMsg[] = "Line not found!";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($machine) <= 0) {
|
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));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
Machine::updateOrCreate(
|
Machine::updateOrCreate(
|
||||||
[
|
[
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'work_center' => $workCenter
|
'work_center' => $workCenter,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'line_id' => $line->id,
|
'line_id' => $line->id,
|
||||||
'name' => $machine,
|
'name' => $machine,
|
||||||
'work_group_master_id' => $groupWorkCenter->id
|
'work_group_master_id' => $groupWorkCenter->id,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// // return Machine::firstOrNew([
|
// // return Machine::firstOrNew([
|
||||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
// // // 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
|
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()) {
|
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