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

This commit is contained in:
dhanabalan
2026-01-13 16:34:49 +05:30
parent 5a74f9a4ca
commit 0cb5373312
2 changed files with 60 additions and 51 deletions

View File

@@ -29,13 +29,13 @@ class ProductionPlanExporter extends Exporter
ExportColumn::make('production_quantity') ExportColumn::make('production_quantity')
->label('PRODUCTION QUANTITY'), ->label('PRODUCTION QUANTITY'),
ExportColumn::make('line.name') ExportColumn::make('line.name')
->label('LINE'), ->label('LINE NAME'),
ExportColumn::make('shift.block.name') ExportColumn::make('shift.block.name')
->label('BLOCK'), ->label('BLOCK NAME'),
ExportColumn::make('shift.name') ExportColumn::make('shift.name')
->label('SHIFT'), ->label('SHIFT NAME'),
ExportColumn::make('plant.name') ExportColumn::make('plant.code')
->label('PLANT'), ->label('PLANT CODE'),
ExportColumn::make('operator_id') ExportColumn::make('operator_id')
->label('OPERATOR ID'), ->label('OPERATOR ID'),
ExportColumn::make('created_at') ExportColumn::make('created_at')

View File

@@ -65,10 +65,10 @@ class ProductionPlanImporter extends Importer
->rules(['required']), ->rules(['required']),
ImportColumn::make('plant') ImportColumn::make('plant')
->requiredMapping() ->requiredMapping()
->exampleHeader('Plant Name') ->exampleHeader('Plant Code')
->example(['Ransar Industries-I', 'Ransar Industries-I']) ->example(['1000', '1000'])
->label('Plant Name') ->label('Plant Code')
->relationship(resolveUsing:'name') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('updated_at') ImportColumn::make('updated_at')
->requiredMapping() ->requiredMapping()
@@ -88,36 +88,45 @@ class ProductionPlanImporter extends Importer
public function resolveRecord(): ?ProductionPlan public function resolveRecord(): ?ProductionPlan
{ {
$warnMsg = []; $warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first(); $plantCod = $this->data['plant'];
$plant = null;
$line = null; $line = null;
$block = null; $block = null;
if (!$plant) {
$warnMsg[] = "Plant not found"; 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();
} }
else {
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first(); $line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
// block_reference // block_reference
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first(); $block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
} }
if (! $line) { if (! $line) {
$warnMsg[] = "Line not found"; $warnMsg[] = 'Line not found';
} }
$shift = null; $shift = null;
if (! $block) { if (! $block) {
$warnMsg[] = "Block not found"; $warnMsg[] = 'Block not found';
} } elseif ($plant) {
else {
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first(); $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(); // $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (! $shift) { if (! $shift) {
$warnMsg[] = "Shift not found"; $warnMsg[] = 'Shift not found';
} }
if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) { if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
$warnMsg[] = "Invalid plan quantity found"; $warnMsg[] = 'Invalid plan quantity found';
} }
if (Str::length($this->data['production_quantity']) < 0 || ! is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) { if (Str::length($this->data['production_quantity']) < 0 || ! is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
$warnMsg[] = "Invalid production quantity found"; $warnMsg[] = 'Invalid production quantity found';
} }
$fromDate = $this->data['created_at']; $fromDate = $this->data['created_at'];
@@ -152,8 +161,7 @@ class ProductionPlanImporter extends Importer
if (! isset($fdateTime)) { if (! isset($fdateTime)) {
// throw new \Exception('Invalid date time format'); // throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
} } else {
else {
$fDateOnly = $fdateTime->toDateString(); $fDateOnly = $fdateTime->toDateString();
} }
if (! isset($tdateTime)) { if (! isset($tdateTime)) {
@@ -175,13 +183,12 @@ class ProductionPlanImporter extends Importer
$user = User::where('name', $this->data['operator_id'])->first(); $user = User::where('name', $this->data['operator_id'])->first();
if (! $user) { if (! $user) {
$warnMsg[] = "Operator ID not found"; $warnMsg[] = 'Operator ID not found';
} }
if (! empty($warnMsg)) { if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} } else { // if (empty($warnMsg))
else { //if (empty($warnMsg))
$productionPlan = ProductionPlan::where('plant_id', $plant->id) $productionPlan = ProductionPlan::where('plant_id', $plant->id)
->where('shift_id', $shift->id) ->where('shift_id', $shift->id)
->where('line_id', $line->id) ->where('line_id', $line->id)
@@ -205,6 +212,7 @@ class ProductionPlanImporter extends Importer
'operator_id' => $this->data['operator_id'], 'operator_id' => $this->data['operator_id'],
]); ]);
$productionPlan->save(); $productionPlan->save();
return null; return null;
} }
} }
@@ -219,6 +227,7 @@ class ProductionPlanImporter extends Importer
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'], 'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
'operator_id' => $this->data['operator_id'], 'operator_id' => $this->data['operator_id'],
]); ]);
return null; return null;
// return ProductionPlan::firstOrNew([ // return ProductionPlan::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']` // // Update existing records, matching them by `$this->data['column_name']`