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:
@@ -37,13 +37,13 @@ class ProductionLineStopExporter extends Exporter
|
||||
ExportColumn::make('stop_min')
|
||||
->label('STOP MINUTE'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('shift.block.name')
|
||||
->label('BLOCK'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('shift.name')
|
||||
->label('SHIFT'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
->label('SHIFT NAME'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('operator_id')
|
||||
->label('OPERATOR ID'),
|
||||
ExportColumn::make('created_at')
|
||||
|
||||
@@ -15,6 +15,7 @@ use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class ProductionLineStopImporter extends Importer
|
||||
{
|
||||
@@ -78,10 +79,10 @@ class ProductionLineStopImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example(['Ransar Industries-I', 'Ransar Industries-I'])
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('operator_id')
|
||||
->requiredMapping()
|
||||
@@ -95,56 +96,57 @@ class ProductionLineStopImporter extends Importer
|
||||
public function resolveRecord(): ?ProductionLineStop
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$block = null;
|
||||
$shift = 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 {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
// block_reference
|
||||
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
}
|
||||
if (! $line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
$shift = null;
|
||||
if (! $block) {
|
||||
$warnMsg[] = "Block not found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Block not found';
|
||||
} elseif ($plant) {
|
||||
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||
}
|
||||
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||
if (! $shift) {
|
||||
$warnMsg[] = "Shift not found";
|
||||
$warnMsg[] = 'Shift not found';
|
||||
}
|
||||
$linestop = LineStop::where('code', $this->data['linestop'])->first();
|
||||
if (! $linestop) {
|
||||
$warnMsg[] = "Line stop code not found";
|
||||
$warnMsg[] = 'Line stop code not found';
|
||||
}
|
||||
$stophour = is_numeric($this->data['stop_hour']) && $this->data['stop_hour'] >= 0;
|
||||
$stopmin = is_numeric($this->data['stop_min']) && $this->data['stop_min'] >= 0 && $this->data['stop_min'] <= 60;
|
||||
if (! $stophour && ! $stopmin) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
}
|
||||
else if (!$stophour) {
|
||||
$warnMsg[] = "Invalid stop hour found";
|
||||
}
|
||||
else if (!$stopmin) {
|
||||
$warnMsg[] = "Invalid stop min found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
} elseif (! $stophour) {
|
||||
$warnMsg[] = 'Invalid stop hour found';
|
||||
} elseif (! $stopmin) {
|
||||
$warnMsg[] = 'Invalid stop min found';
|
||||
} else {
|
||||
$stophour = (int) $this->data['stop_hour'];
|
||||
$stopmin = (int) $this->data['stop_min'];
|
||||
if ($stophour == 0 && $stopmin == 0) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
}
|
||||
}
|
||||
$validHourMin = ($stophour == 0 && $stopmin == 0) ? false : true;
|
||||
if (! $validHourMin) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
}
|
||||
$fromDate = $this->data['from_datetime'];
|
||||
$toDate = $this->data['to_datetime'];
|
||||
@@ -201,7 +203,7 @@ class ProductionLineStopImporter extends Importer
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -219,6 +221,7 @@ class ProductionLineStopImporter extends Importer
|
||||
'stop_min' => (int) $this->data['stop_min'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
// return ProductionLineStop::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
Reference in New Issue
Block a user