Added view rights against plant 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:
@@ -25,11 +25,11 @@ class ShiftExporter extends Exporter
|
|||||||
return ++$rowNumber;
|
return ++$rowNumber;
|
||||||
}),
|
}),
|
||||||
ExportColumn::make('block.name')
|
ExportColumn::make('block.name')
|
||||||
->label('BLOCK'),
|
->label('BLOCK NAME'),
|
||||||
ExportColumn::make('plant.name')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('name')
|
ExportColumn::make('name')
|
||||||
->label('NAME'),
|
->label('SHIFT NAME'),
|
||||||
ExportColumn::make('start_time')
|
ExportColumn::make('start_time')
|
||||||
->label('START TIME'),
|
->label('START TIME'),
|
||||||
ExportColumn::make('duration')
|
ExportColumn::make('duration')
|
||||||
@@ -50,10 +50,10 @@ class ShiftExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
{
|
{
|
||||||
$body = 'Your shift export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
$body = 'Your shift 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;
|
||||||
|
|||||||
@@ -18,79 +18,89 @@ class ShiftImporter extends Importer
|
|||||||
public static function getColumns(): array
|
public static function getColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
ImportColumn::make('name')
|
ImportColumn::make('name')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Shift Name')
|
->exampleHeader('Shift Name')
|
||||||
->example('Day')
|
->example('Day')
|
||||||
->label('Shift Name')
|
->label('Shift Name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('start_time')
|
ImportColumn::make('start_time')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Start Time')
|
->exampleHeader('Start Time')
|
||||||
->example('08:00:00')
|
->example('08:00:00')
|
||||||
->label('Start Time')
|
->label('Start Time')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('duration')
|
ImportColumn::make('duration')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->numeric()
|
->numeric()
|
||||||
->exampleHeader('Shift Duration')
|
->exampleHeader('Shift Duration')
|
||||||
->example('11.30')
|
->example('11.30')
|
||||||
->label('Shift Duration')
|
->label('Shift Duration')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('end_time')
|
ImportColumn::make('end_time')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('End Time')
|
->exampleHeader('End Time')
|
||||||
->example('19:30:00')
|
->example('19:30:00')
|
||||||
->label('End Time')
|
->label('End Time')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('block')
|
ImportColumn::make('block')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Block Name')
|
->exampleHeader('Block Name')
|
||||||
->example('Block A')
|
->example('Block A')
|
||||||
->label('Block Name')
|
->label('Block Name')
|
||||||
->relationship(resolveUsing:'name')
|
->relationship(resolveUsing: 'name')
|
||||||
->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('status')
|
ImportColumn::make('status')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Active Status')
|
->exampleHeader('Active Status')
|
||||||
->example('Active')
|
->example('Active')
|
||||||
->label('Active Status')
|
->label('Active Status')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveRecord(): ?Shift
|
public function resolveRecord(): ?Shift
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
if (!$plant) {
|
$plant = null;
|
||||||
$warnMsg[] = "Plant not found";
|
$block = null;
|
||||||
}
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
if (!$block) {
|
} else {
|
||||||
$warnMsg[] = "Block not found";
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
}
|
|
||||||
if (Str::length($this->data['duration']) < 0 || !is_numeric($this->data['duration'])) {
|
|
||||||
$warnMsg[] = "Invalid duration found";
|
|
||||||
}
|
|
||||||
if (Str::length($this->data['start_time']) < 0) {
|
|
||||||
$warnMsg[] = "Invalid start time found";
|
|
||||||
}
|
|
||||||
if (Str::length($this->data['end_time']) < 0) {
|
|
||||||
$warnMsg[] = "Invalid end time found";
|
|
||||||
}
|
|
||||||
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
|
|
||||||
$warnMsg[] = "Invalid shift status found";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
|
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $block) {
|
||||||
|
$warnMsg[] = 'Block not found';
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['duration']) < 0 || ! is_numeric($this->data['duration'])) {
|
||||||
|
$warnMsg[] = 'Invalid duration found';
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['start_time']) < 0) {
|
||||||
|
$warnMsg[] = 'Invalid start time found';
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['end_time']) < 0) {
|
||||||
|
$warnMsg[] = 'Invalid end time found';
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
|
||||||
|
$warnMsg[] = 'Invalid shift status found';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +115,9 @@ class ShiftImporter extends Importer
|
|||||||
'start_time' => $this->data['start_time'],
|
'start_time' => $this->data['start_time'],
|
||||||
'duration' => $this->data['duration'],
|
'duration' => $this->data['duration'],
|
||||||
'end_time' => $this->data['end_time'],
|
'end_time' => $this->data['end_time'],
|
||||||
'status' => $this->data['status']
|
'status' => $this->data['status'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $shift;
|
return $shift;
|
||||||
} else {
|
} else {
|
||||||
// Safe to create new
|
// Safe to create new
|
||||||
@@ -117,7 +128,7 @@ class ShiftImporter extends Importer
|
|||||||
'start_time' => $this->data['start_time'],
|
'start_time' => $this->data['start_time'],
|
||||||
'duration' => $this->data['duration'],
|
'duration' => $this->data['duration'],
|
||||||
'end_time' => $this->data['end_time'],
|
'end_time' => $this->data['end_time'],
|
||||||
'status' => $this->data['status']
|
'status' => $this->data['status'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// return Shift::firstOrNew([
|
// return Shift::firstOrNew([
|
||||||
@@ -130,10 +141,10 @@ class ShiftImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your shift import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your shift 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