Updated alignments on import and export
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:29:52 +05:30
parent bbd8ff91a2
commit 5bacc0cba7
2 changed files with 130 additions and 144 deletions

View File

@@ -23,7 +23,7 @@ class MotorTestingMasterExporter extends Exporter
return ++$rowNumber; return ++$rowNumber;
}), }),
ExportColumn::make('plant.code') ExportColumn::make('plant.code')
->label('PLANT'), ->label('PLANT CODE'),
ExportColumn::make('item.category') ExportColumn::make('item.category')
->label('CATEGORY'), ->label('CATEGORY'),
ExportColumn::make('item.code') ExportColumn::make('item.code')

View File

@@ -237,7 +237,7 @@ class MotorTestingMasterImporter extends Importer
$plantCod = trim($this->data['plant']); $plantCod = trim($this->data['plant']);
$iCode = trim($this->data['item']); $iCode = trim($this->data['item']);
$sCode = trim($this->data['subassembly_code']); $sCode = trim($this->data['subassembly_code']);
$isiModel = (trim($this->data['isi_model']) == "1") ? true : false; $isiModel = (trim($this->data['isi_model']) == '1') ? true : false;
$phase = trim($this->data['phase']); $phase = trim($this->data['phase']);
$kw = trim($this->data['kw']); $kw = trim($this->data['kw']);
$hp = trim($this->data['hp']); $hp = trim($this->data['hp']);
@@ -270,40 +270,25 @@ class MotorTestingMasterImporter extends Importer
$updatedBy = trim($this->data['updated_by']); $updatedBy = trim($this->data['updated_by']);
$plant = null; $plant = null;
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
{ $warnMsg[] = 'Invalid plant code found';
$warnMsg[] = "Invalid plant code found"; } elseif (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
} $warnMsg[] = 'Invalid item code found';
else if (Str::length($iCode) < 6 || !ctype_alnum($iCode)) } elseif (Str::length($sCode) < 6 || ! ctype_alnum($sCode)) {
{ $warnMsg[] = 'Invalid sub-assembly code found';
$warnMsg[] = "Invalid item code found"; } else {
}
else if (Str::length($sCode) < 6 || !ctype_alnum($sCode))
{
$warnMsg[] = "Invalid sub-assembly code found";
}
else
{
$plant = Plant::where('code', $plantCod)->first(); $plant = Plant::where('code', $plantCod)->first();
$codeExist = Item::where('code', $iCode)->first(); $codeExist = Item::where('code', $iCode)->first();
if ($plant) if ($plant) {
{
$iCode = Item::where('code', $iCode)->where('plant_id', $plant->id)->first(); $iCode = Item::where('code', $iCode)->where('plant_id', $plant->id)->first();
} }
if (!$plant) if (! $plant) {
{ $warnMsg[] = 'Plant not found';
$warnMsg[] = "Plant not found"; } elseif (! $codeExist) {
} $warnMsg[] = 'Item code not found';
else if (!$codeExist) } elseif (! $iCode) {
{ $warnMsg[] = 'Item code not found for choosed plant';
$warnMsg[] = "Item code not found"; } else {
}
else if (!$iCode)
{
$warnMsg[] = "Item code not found for choosed plant";
}
else
{
// if (Str::length($isiModel) <= 0 || $isiModel == "0" || $isiModel == "1") { // if (Str::length($isiModel) <= 0 || $isiModel == "0" || $isiModel == "1") {
// $warnMsg[] = "Invalid ISI Model found"; // $warnMsg[] = "Invalid ISI Model found";
// } // }
@@ -311,89 +296,89 @@ class MotorTestingMasterImporter extends Importer
// { // {
// $isiModel = ($isiModel == "1"); // $isiModel = ($isiModel == "1");
// } // }
if (Str::length($phase) <= 0 || ($phase != "Single" && $phase != "Three")) {//!is_string($phase) || if (Str::length($phase) <= 0 || ($phase != 'Single' && $phase != 'Three')) {// !is_string($phase) ||
$warnMsg[] = "Invalid phase found"; $warnMsg[] = 'Invalid phase found';
} }
if (Str::length($hp) <= 0 || ! is_numeric($hp)) { if (Str::length($hp) <= 0 || ! is_numeric($hp)) {
$warnMsg[] = "Invalid HP found"; $warnMsg[] = 'Invalid HP found';
} }
if (Str::length($kw) <= 0 || ! is_numeric($kw)) { if (Str::length($kw) <= 0 || ! is_numeric($kw)) {
$warnMsg[] = "Invalid KW found"; $warnMsg[] = 'Invalid KW found';
} }
if (Str::length($volt) <= 0 || ! is_numeric($volt)) { if (Str::length($volt) <= 0 || ! is_numeric($volt)) {
$warnMsg[] = "Invalid volt found"; $warnMsg[] = 'Invalid volt found';
} }
if (Str::length($current) <= 0 || ! is_numeric($current)) { if (Str::length($current) <= 0 || ! is_numeric($current)) {
$warnMsg[] = "Invalid current found"; $warnMsg[] = 'Invalid current found';
} }
if (Str::length($rpm) <= 0 || ! is_numeric($rpm)) { if (Str::length($rpm) <= 0 || ! is_numeric($rpm)) {
$warnMsg[] = "Invalid RPM found"; $warnMsg[] = 'Invalid RPM found';
} }
if (Str::length($torque) <= 0 || ! is_numeric($torque)) { if (Str::length($torque) <= 0 || ! is_numeric($torque)) {
$warnMsg[] = "Invalid torque found"; $warnMsg[] = 'Invalid torque found';
} }
if (Str::length($frequency) <= 0 || ! is_numeric($frequency)) { if (Str::length($frequency) <= 0 || ! is_numeric($frequency)) {
$warnMsg[] = "Invalid frequency found"; $warnMsg[] = 'Invalid frequency found';
} }
if (Str::length($connection) <= 0 || ($connection != "Star-Delta" && $connection != "Star" && $connection != "Delta")) { if (Str::length($connection) <= 0 || ($connection != 'Star-Delta' && $connection != 'Star' && $connection != 'Delta')) {
$warnMsg[] = "Invalid connection found"; $warnMsg[] = 'Invalid connection found';
} }
if (Str::length($insResLimit) <= 0 || ! is_numeric($insResLimit)) { if (Str::length($insResLimit) <= 0 || ! is_numeric($insResLimit)) {
$warnMsg[] = "Invalid insulation resistance limit found"; $warnMsg[] = 'Invalid insulation resistance limit found';
} }
if (Str::length($insResType) <= 0 || ($insResType != "O" && $insResType != "M" && $insResType != "G")) { if (Str::length($insResType) <= 0 || ($insResType != 'O' && $insResType != 'M' && $insResType != 'G')) {
$warnMsg[] = "Invalid insulation resistance type found"; $warnMsg[] = 'Invalid insulation resistance type found';
} }
if (Str::length($routineTestTime) <= 0 || ! isValidTimeFormat($routineTestTime)) { if (Str::length($routineTestTime) <= 0 || ! isValidTimeFormat($routineTestTime)) {
$warnMsg[] = "Invalid routine test time found"; $warnMsg[] = 'Invalid routine test time found';
} }
if (Str::length($resRyLl) <= 0 || ! is_numeric($resRyLl)) { if (Str::length($resRyLl) <= 0 || ! is_numeric($resRyLl)) {
$warnMsg[] = "Invalid resistance RY lower limit found"; $warnMsg[] = 'Invalid resistance RY lower limit found';
} }
if (Str::length($resRyUl) <= 0 || ! is_numeric($resRyUl)) { if (Str::length($resRyUl) <= 0 || ! is_numeric($resRyUl)) {
$warnMsg[] = "Invalid resistance RY upper limit found"; $warnMsg[] = 'Invalid resistance RY upper limit found';
} }
if (Str::length($resYbLl) <= 0 || ! is_numeric($resYbLl)) { if (Str::length($resYbLl) <= 0 || ! is_numeric($resYbLl)) {
$warnMsg[] = "Invalid resistance YB lower limit found"; $warnMsg[] = 'Invalid resistance YB lower limit found';
} }
if (Str::length($resYbUl) <= 0 || ! is_numeric($resYbUl)) { if (Str::length($resYbUl) <= 0 || ! is_numeric($resYbUl)) {
$warnMsg[] = "Invalid resistance YB upper limit found"; $warnMsg[] = 'Invalid resistance YB upper limit found';
} }
if (Str::length($resBrLl) <= 0 || ! is_numeric($resBrLl)) { if (Str::length($resBrLl) <= 0 || ! is_numeric($resBrLl)) {
$warnMsg[] = "Invalid resistance BR lower limit found"; $warnMsg[] = 'Invalid resistance BR lower limit found';
} }
if (Str::length($resBrUl) <= 0 || ! is_numeric($resBrUl)) { if (Str::length($resBrUl) <= 0 || ! is_numeric($resBrUl)) {
$warnMsg[] = "Invalid resistance BR upper limit found"; $warnMsg[] = 'Invalid resistance BR upper limit found';
} }
if (Str::length($lockVoltLimit) <= 0 || ! is_numeric($lockVoltLimit)) { if (Str::length($lockVoltLimit) <= 0 || ! is_numeric($lockVoltLimit)) {
$warnMsg[] = "Invalid locked volt limit found"; $warnMsg[] = 'Invalid locked volt limit found';
} }
if (Str::length($leakCurLimit) <= 0 || ! is_numeric($leakCurLimit)) { if (Str::length($leakCurLimit) <= 0 || ! is_numeric($leakCurLimit)) {
$warnMsg[] = "Invalid leakage current limit found"; $warnMsg[] = 'Invalid leakage current limit found';
} }
if (Str::length($lockCurLl) <= 0 || ! is_numeric($lockCurLl)) { if (Str::length($lockCurLl) <= 0 || ! is_numeric($lockCurLl)) {
$warnMsg[] = "Invalid locked current lower limit found"; $warnMsg[] = 'Invalid locked current lower limit found';
} }
if (Str::length($lockCurUl) <= 0 || ! is_numeric($lockCurUl)) { if (Str::length($lockCurUl) <= 0 || ! is_numeric($lockCurUl)) {
$warnMsg[] = "Invalid locked current upper limit found"; $warnMsg[] = 'Invalid locked current upper limit found';
} }
if (Str::length($noloadCurLl) <= 0 || ! is_numeric($noloadCurLl)) { if (Str::length($noloadCurLl) <= 0 || ! is_numeric($noloadCurLl)) {
$warnMsg[] = "Invalid no load current lower limit found"; $warnMsg[] = 'Invalid no load current lower limit found';
} }
if (Str::length($noloadCurUl) <= 0 || ! is_numeric($noloadCurUl)) { if (Str::length($noloadCurUl) <= 0 || ! is_numeric($noloadCurUl)) {
$warnMsg[] = "Invalid no load current upper limit found"; $warnMsg[] = 'Invalid no load current upper limit found';
} }
if (Str::length($noloadPowLl) <= 0 || ! is_numeric($noloadPowLl)) { if (Str::length($noloadPowLl) <= 0 || ! is_numeric($noloadPowLl)) {
$warnMsg[] = "Invalid no load power lower limit found"; $warnMsg[] = 'Invalid no load power lower limit found';
} }
if (Str::length($noloadPowUl) <= 0 || ! is_numeric($noloadPowUl)) { if (Str::length($noloadPowUl) <= 0 || ! is_numeric($noloadPowUl)) {
$warnMsg[] = "Invalid no load power upper limit found"; $warnMsg[] = 'Invalid no load power upper limit found';
} }
if (Str::length($noloadSpdLl) <= 0 || ! is_numeric($noloadSpdLl)) { if (Str::length($noloadSpdLl) <= 0 || ! is_numeric($noloadSpdLl)) {
$warnMsg[] = "Invalid no load speed lower limit found"; $warnMsg[] = 'Invalid no load speed lower limit found';
} }
if (Str::length($noloadSpdUl) <= 0 || ! is_numeric($noloadSpdUl)) { if (Str::length($noloadSpdUl) <= 0 || ! is_numeric($noloadSpdUl)) {
$warnMsg[] = "Invalid no load speed upper limit found"; $warnMsg[] = 'Invalid no load speed upper limit found';
} }
$oldCode = MotorTestingMaster::where('item_id', $iCode->id)->where('plant_id', $plant->id)->first(); $oldCode = MotorTestingMaster::where('item_id', $iCode->id)->where('plant_id', $plant->id)->first();
@@ -401,22 +386,20 @@ class MotorTestingMasterImporter extends Importer
if ($oldCode) { if ($oldCode) {
$created = $oldCode->created_by ? User::where('name', $oldCode->created_by)->first() : null; $created = $oldCode->created_by ? User::where('name', $oldCode->created_by)->first() : null;
if (! $created) { if (! $created) {
$warnMsg[] = "Created by not found on update"; $warnMsg[] = 'Created by not found on update';
} }
$updated = User::where('name', $updatedBy)->first(); $updated = User::where('name', $updatedBy)->first();
if (! $updated) { if (! $updated) {
$warnMsg[] = "Updated by not found on update"; $warnMsg[] = 'Updated by not found on update';
} }
} } else {
else
{
$created = User::where('name', $createdBy)->first(); $created = User::where('name', $createdBy)->first();
if (! $created) { if (! $created) {
$warnMsg[] = "Created by not found"; $warnMsg[] = 'Created by not found';
} }
$updated = User::where('name', $updatedBy)->first(); $updated = User::where('name', $updatedBy)->first();
if (! $updated) { if (! $updated) {
$warnMsg[] = "Updated by not found"; $warnMsg[] = 'Updated by not found';
} }
} }
} }
@@ -428,7 +411,7 @@ class MotorTestingMasterImporter extends Importer
MotorTestingMaster::updateOrCreate([ MotorTestingMaster::updateOrCreate([
'plant_id' => $plant->id, 'plant_id' => $plant->id,
'item_id' => $iCode->id 'item_id' => $iCode->id,
], ],
[ [
'subassembly_code' => $sCode, 'subassembly_code' => $sCode,
@@ -465,6 +448,7 @@ class MotorTestingMasterImporter extends Importer
'updated_by' => $updated->name, 'updated_by' => $updated->name,
] ]
); );
return null; return null;
// // return MotorTestingMaster::firstOrNew([ // // return MotorTestingMaster::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']` // // // Update existing records, matching them by `$this->data['column_name']`
@@ -486,12 +470,14 @@ class MotorTestingMasterImporter extends Importer
} }
} }
function isValidTimeFormat($time) { function isValidTimeFormat($time)
{
// If time starts with a single digit hour without leading zero, pad it // If time starts with a single digit hour without leading zero, pad it
if (preg_match('/^\d(:\d{2}:\d{2})$/', $time, $matches)) { if (preg_match('/^\d(:\d{2}:\d{2})$/', $time, $matches)) {
$time = '0'.$time; $time = '0'.$time;
} }
$dateTime = DateTime::createFromFormat('H:i:s', $time); $dateTime = DateTime::createFromFormat('H:i:s', $time);
return $dateTime && $dateTime->format('H:i:s') === $time; return $dateTime && $dateTime->format('H:i:s') === $time;
} }