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

@@ -17,13 +17,13 @@ class MotorTestingMasterExporter extends Exporter
return [ return [
ExportColumn::make('no') ExportColumn::make('no')
->label('NO') ->label('NO')
->state(function ($record) use (&$rowNumber) { ->state(function ($record) use (&$rowNumber) {
// Increment and return the row number // Increment and return the row number
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')
@@ -106,10 +106,10 @@ class MotorTestingMasterExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string public static function getCompletedNotificationBody(Export $export): string
{ {
$body = 'Your motor testing master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.'; $body = 'Your motor testing master 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;

View File

@@ -24,7 +24,7 @@ class MotorTestingMasterImporter extends Importer
ImportColumn::make('item') ImportColumn::make('item')
->requiredMapping() ->requiredMapping()
->exampleHeader('Item Code') ->exampleHeader('Item Code')
->example(['123456','123457','123458']) ->example(['123456', '123457', '123458'])
->label('Item Code') ->label('Item Code')
->relationship(resolveUsing: 'code') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
@@ -38,181 +38,181 @@ class MotorTestingMasterImporter extends Importer
->requiredMapping() ->requiredMapping()
->boolean() ->boolean()
->exampleHeader('ISI Model') ->exampleHeader('ISI Model')
->example(['Y','N','Y']) ->example(['Y', 'N', 'Y'])
->label('ISI Model') ->label('ISI Model')
->rules(['boolean']), ->rules(['boolean']),
ImportColumn::make('phase') ImportColumn::make('phase')
->requiredMapping() ->requiredMapping()
->exampleHeader('Phase') ->exampleHeader('Phase')
->example(['Single','Three','Single']) ->example(['Single', 'Three', 'Single'])
->label('Phase') ->label('Phase')
->rules(['required']), ->rules(['required']),
ImportColumn::make('hp') ImportColumn::make('hp')
->requiredMapping() ->requiredMapping()
->exampleHeader('HP') ->exampleHeader('HP')
->example(['5','10','5']) ->example(['5', '10', '5'])
->label('HP') ->label('HP')
->rules(['required']), ->rules(['required']),
ImportColumn::make('kw') ImportColumn::make('kw')
->requiredMapping() ->requiredMapping()
->exampleHeader('KW') ->exampleHeader('KW')
->example(['5','7.5','5']) ->example(['5', '7.5', '5'])
->label('KW') ->label('KW')
->rules(['required']), ->rules(['required']),
ImportColumn::make('volt') ImportColumn::make('volt')
->requiredMapping() ->requiredMapping()
->exampleHeader('Volt') ->exampleHeader('Volt')
->example(['230','380','230']) ->example(['230', '380', '230'])
->label('Volt') ->label('Volt')
->rules(['required']), ->rules(['required']),
ImportColumn::make('current') ImportColumn::make('current')
->requiredMapping() ->requiredMapping()
->exampleHeader('Current') ->exampleHeader('Current')
->example(['7','21.8','7']) ->example(['7', '21.8', '7'])
->label('Current') ->label('Current')
->rules(['required']), ->rules(['required']),
ImportColumn::make('rpm') ImportColumn::make('rpm')
->requiredMapping() ->requiredMapping()
->exampleHeader('RPM') ->exampleHeader('RPM')
->example(['2500','3420','2500']) ->example(['2500', '3420', '2500'])
->label('RPM') ->label('RPM')
->rules(['required']), ->rules(['required']),
ImportColumn::make('torque') ImportColumn::make('torque')
->requiredMapping() ->requiredMapping()
->exampleHeader('Torque') ->exampleHeader('Torque')
->example(['0.5','1.25','0.5']) ->example(['0.5', '1.25', '0.5'])
->label('Torque') ->label('Torque')
->rules(['required']), ->rules(['required']),
ImportColumn::make('frequency') ImportColumn::make('frequency')
->requiredMapping() ->requiredMapping()
->exampleHeader('Frequency') ->exampleHeader('Frequency')
->label('Frequency') ->label('Frequency')
->example(['50','60','50']) ->example(['50', '60', '50'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('connection') ImportColumn::make('connection')
->requiredMapping() ->requiredMapping()
->exampleHeader('Connection') ->exampleHeader('Connection')
->label('Connection') ->label('Connection')
->example(['Star','Star-Delta','Delta']) ->example(['Star', 'Star-Delta', 'Delta'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('ins_res_limit') ImportColumn::make('ins_res_limit')
->requiredMapping() ->requiredMapping()
->exampleHeader('Insulation Resistance Limit') ->exampleHeader('Insulation Resistance Limit')
->label('Insulation Resistance Limit') ->label('Insulation Resistance Limit')
->example(['1000','2','1000']) ->example(['1000', '2', '1000'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('ins_res_type') ImportColumn::make('ins_res_type')
->requiredMapping() ->requiredMapping()
->exampleHeader('Insulation Resistance Type') ->exampleHeader('Insulation Resistance Type')
->label('Insulation Resistance Type') ->label('Insulation Resistance Type')
->example(['O','G','O']) ->example(['O', 'G', 'O'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('routine_test_time') ImportColumn::make('routine_test_time')
->requiredMapping() ->requiredMapping()
->exampleHeader('Routine Test Time') ->exampleHeader('Routine Test Time')
->label('Routine Test Time') ->label('Routine Test Time')
->example(['00:40:00','00:40:00','00:40:00']) ->example(['00:40:00', '00:40:00', '00:40:00'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_ry_ll') ImportColumn::make('res_ry_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance RY LL') ->exampleHeader('Resistance RY LL')
->label('Resistance RY LL') ->label('Resistance RY LL')
->example(['0.05','0.05','0.05']) ->example(['0.05', '0.05', '0.05'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_ry_ul') ImportColumn::make('res_ry_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance RY UL') ->exampleHeader('Resistance RY UL')
->label('Resistance RY UL') ->label('Resistance RY UL')
->example(['99','99','99']) ->example(['99', '99', '99'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_yb_ll') ImportColumn::make('res_yb_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance YB LL') ->exampleHeader('Resistance YB LL')
->label('Resistance YB LL') ->label('Resistance YB LL')
->example(['0.05','0.05','0.05']) ->example(['0.05', '0.05', '0.05'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_yb_ul') ImportColumn::make('res_yb_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance YB UL') ->exampleHeader('Resistance YB UL')
->label('Resistance YB UL') ->label('Resistance YB UL')
->example(['99','99','99']) ->example(['99', '99', '99'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_br_ll') ImportColumn::make('res_br_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance BR LL') ->exampleHeader('Resistance BR LL')
->label('Resistance BR LL') ->label('Resistance BR LL')
->example(['0.05','0.05','0.05']) ->example(['0.05', '0.05', '0.05'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('res_br_ul') ImportColumn::make('res_br_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('Resistance BR UL') ->exampleHeader('Resistance BR UL')
->label('Resistance BR UL') ->label('Resistance BR UL')
->example(['99','99','99']) ->example(['99', '99', '99'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('lock_volt_limit') ImportColumn::make('lock_volt_limit')
->requiredMapping() ->requiredMapping()
->exampleHeader('Lock Volt Limit') ->exampleHeader('Lock Volt Limit')
->label('Lock Volt Limit') ->label('Lock Volt Limit')
->example(['80','100','80']) ->example(['80', '100', '80'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('leak_cur_limit') ImportColumn::make('leak_cur_limit')
->requiredMapping() ->requiredMapping()
->exampleHeader('Leak Current Limit') ->exampleHeader('Leak Current Limit')
->label('Leak Current Limit') ->label('Leak Current Limit')
->example(['50','50','50']) ->example(['50', '50', '50'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('lock_cur_ll') ImportColumn::make('lock_cur_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('Lock Current LL') ->exampleHeader('Lock Current LL')
->label('Lock Current LL') ->label('Lock Current LL')
->example(['10','12.5','10']) ->example(['10', '12.5', '10'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('lock_cur_ul') ImportColumn::make('lock_cur_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('Lock Current UL') ->exampleHeader('Lock Current UL')
->label('Lock Current UL') ->label('Lock Current UL')
->example(['15','14.6','15']) ->example(['15', '14.6', '15'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_cur_ll') ImportColumn::make('noload_cur_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Current LL') ->exampleHeader('No Load Current LL')
->label('No Load Current LL') ->label('No Load Current LL')
->example(['3','5.9','3']) ->example(['3', '5.9', '3'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_cur_ul') ImportColumn::make('noload_cur_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Current UL') ->exampleHeader('No Load Current UL')
->label('No Load Current UL') ->label('No Load Current UL')
->example(['15','6.9','15']) ->example(['15', '6.9', '15'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_pow_ll') ImportColumn::make('noload_pow_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Power LL') ->exampleHeader('No Load Power LL')
->label('No Load Power LL') ->label('No Load Power LL')
->example(['250','850','250']) ->example(['250', '850', '250'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_pow_ul') ImportColumn::make('noload_pow_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Power UL') ->exampleHeader('No Load Power UL')
->label('No Load Power UL') ->label('No Load Power UL')
->example(['500','1200','500']) ->example(['500', '1200', '500'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_spd_ll') ImportColumn::make('noload_spd_ll')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Speed LL') ->exampleHeader('No Load Speed LL')
->label('No Load Speed LL') ->label('No Load Speed LL')
->example(['2000','2500','2000']) ->example(['2000', '2500', '2000'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('noload_spd_ul') ImportColumn::make('noload_spd_ul')
->requiredMapping() ->requiredMapping()
->exampleHeader('No Load Speed UL') ->exampleHeader('No Load Speed UL')
->label('No Load Speed UL') ->label('No Load Speed UL')
->example(['4000','3500','4000']) ->example(['4000', '3500', '4000'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('plant') ImportColumn::make('plant')
->requiredMapping() ->requiredMapping()
->exampleHeader('Plant') ->exampleHeader('Plant')
->example(['1000','1010','1020']) ->example(['1000', '1010', '1020'])
->label('Plant') ->label('Plant')
->relationship(resolveUsing: 'code') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
@@ -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,125 +296,123 @@ 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();
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';
} }
} }
} }
} }
if (!empty($warnMsg)) { if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
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,
'isi_model' => $isiModel, 'isi_model' => $isiModel,
@@ -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']`
@@ -476,22 +460,24 @@ class MotorTestingMasterImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string public static function getCompletedNotificationBody(Import $import): string
{ {
$body = 'Your motor testing master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; $body = 'Your motor testing master 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;
} }
} }
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;
} }