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:35:57 +05:30
parent 0cb5373312
commit b2044bc851
2 changed files with 62 additions and 54 deletions

View File

@@ -33,13 +33,13 @@ class ProductionQuantityExporter extends Exporter
ExportColumn::make('item.uom') ExportColumn::make('item.uom')
->label('UNIT OF MEASURE'), ->label('UNIT OF MEASURE'),
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('sap_msg_status') ExportColumn::make('sap_msg_status')
->label('SAP MESSAGE STATUS'), ->label('SAP MESSAGE STATUS'),
ExportColumn::make('sap_msg_description') ExportColumn::make('sap_msg_description')

View File

@@ -59,9 +59,9 @@ class ProductionQuantityImporter extends Importer
->rules(['required']), ->rules(['required']),
ImportColumn::make('block_reference') ImportColumn::make('block_reference')
->requiredMapping() // Or optionalMapping() if not always present ->requiredMapping() // Or optionalMapping() if not always present
->exampleHeader('Block') ->exampleHeader('Block Name')
->example(['Block A', 'Block A']) ->example(['Block A', 'Block A'])
->label('Block') ->label('Block Name')
->rules(['required']), // Or remove if not required ->rules(['required']), // Or remove if not required
ImportColumn::make('shift') ImportColumn::make('shift')
->requiredMapping() ->requiredMapping()
@@ -72,10 +72,10 @@ class ProductionQuantityImporter 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()
@@ -95,43 +95,51 @@ class ProductionQuantityImporter extends Importer
public function resolveRecord(): ?ProductionQuantity public function resolveRecord(): ?ProductionQuantity
{ {
$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) { $shift = null;
$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;
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';
} }
$item = null; $item = null;
if ($plant) { if ($plant) {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first(); $item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
} }
if (! $item) { if (! $item) {
$warnMsg[] = "Item not found"; $warnMsg[] = 'Item not found';
} }
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) { if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = "Invalid serial number found"; $warnMsg[] = 'Invalid serial number found';
} }
if (Str::length($this->data['production_order']) > 0 && (Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14 || ! is_numeric($this->data['production_order']))) { if (Str::length($this->data['production_order']) > 0 && (Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14 || ! is_numeric($this->data['production_order']))) {
$warnMsg[] = "Invalid production order found"; $warnMsg[] = 'Invalid production order found';
} }
$fromDate = $this->data['created_at']; $fromDate = $this->data['created_at'];
@@ -188,20 +196,19 @@ class ProductionQuantityImporter 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))
$productionQuan = ProductionQuantity::where('plant_id', $plant->id) $productionQuan = ProductionQuantity::where('plant_id', $plant->id)
->where('serial_number', $this->data['serial_number']) ->where('serial_number', $this->data['serial_number'])
->latest() ->latest()
->first(); ->first();
if ($productionQuan) { if ($productionQuan) {
throw new RowImportFailedException("Serial number already exist!"); throw new RowImportFailedException('Serial number already exist!');
} }
} }
@@ -216,6 +223,7 @@ class ProductionQuantityImporter 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'],
]); ]);
// ProductionQuantity::updateOrCreate([ // ProductionQuantity::updateOrCreate([
// 'serial_number' => $this->data['serial_number'], // 'serial_number' => $this->data['serial_number'],
// 'plant_id' => $plant->id, // 'plant_id' => $plant->id,
@@ -259,7 +267,7 @@ class ProductionQuantityImporter extends Importer
'line_id' => $this->resolveLineId($row['line']), 'line_id' => $this->resolveLineId($row['line']),
'shift_id' => $this->resolveShiftId($row['shift']), 'shift_id' => $this->resolveShiftId($row['shift']),
'plant_id' => $this->resolvePlantId($row['plant']), 'plant_id' => $this->resolvePlantId($row['plant']),
'updated_at' => $row['updated_at'] 'updated_at' => $row['updated_at'],
]); ]);
} finally { } finally {
// Always disable flag even if errors occur // Always disable flag even if errors occur