M3 Security Fixes for scan command pass 33 major code smell fixes and style fixes

This commit is contained in:
Mark Gregory
2026-09-17 11:34:41 +01:00
parent 0a05f05843
commit 0c445f89af
69 changed files with 1786 additions and 1752 deletions
@@ -24,8 +24,8 @@ class utilitiesContoller extends Controller
dd('SentM3Test');
// Get The Next ID by Calling POM002C
$PGMERRORS = '';
$AWREQN = '';
$pGMERRORS = '';
$aWREQN = '';
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
@@ -40,13 +40,13 @@ class utilitiesContoller extends Controller
case 8001:
// "Authorization failure on distributed database connection attempt"
// Usually means a wrong DB2 user or password
$PGMERRORS = 'Could not connect due to wrong user or password.';
$pGMERRORS = 'Could not connect due to wrong user or password.';
break;
case 42705:
$PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
$pGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
break;
default:
$PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
$pGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
break;
}
}
@@ -66,7 +66,6 @@ class utilitiesContoller extends Controller
// Add Delivery Note Param
$params[] = $conn->AddParameterPackDec('in', 11, 0, 'ParamIn', '', '00000087125');
// Start Time Tracking
$start = microtime(true);
@@ -77,15 +76,15 @@ class utilitiesContoller extends Controller
$result = $conn->PgmCall('ICM700CSBM', 'EWOBJTST', $params, [], []);
if (! $result) {
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
$pGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
}
// Successful Call
else {
dump($result);
}
if ($PGMERRORS != '') {
dump($PGMERRORS);
if ($pGMERRORS != '') {
dump($pGMERRORS);
} else {
}
// Get Execution Time
@@ -142,39 +141,39 @@ class utilitiesContoller extends Controller
dump('Run Fix IMSENTPKR...');
$SHUSER = 'TWOSHIP';
$sHUSER = 'TWOSHIP';
// Get User CO & WH
// Get users from ICM428M
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
$iCM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US', 'R428CO', 'R428WH')
->where('R428US', '=', $SHUSER)
->where('R428US', '=', $sHUSER)
->first();
$DIVI = isset($ICM428M->R428CO) ? $ICM428M->R428CO : '';
$WHS = isset($ICM428M->R428WH) ? $ICM428M->R428WH : '';
$dIVI = isset($iCM428M->R428CO) ? $iCM428M->R428CO : '';
$wHS = isset($iCM428M->R428WH) ? $iCM428M->R428WH : '';
// Get Parts And Lots from ICM688M2
$ICM688M2SLTMP = DB::connection(config('m3.connection', 'pgsql'))->table('icm688m2')
$iCM688M2SLTMP = DB::connection(config('m3.connection', 'pgsql'))->table('icm688m2')
->select('A5MACPKR', 'A5SENTPKR', 'A5PICKSTRD')
->distinct()
->where('A5CO', $DIVI)
->where('A5WHS', $WHS)
->where('A5CO', $dIVI)
->where('A5WHS', $wHS)
->where('A5PICKSTRD', '!=', '0')
->orderBy('A5PICKSTRD', 'ASC')
->get();
foreach ($ICM688M2SLTMP as $key => $ICM688M2SL) {
foreach ($iCM688M2SLTMP as $key => $ICM688M2SL) {
// $counter == 10 ? exit : '';
$A5MACPKR = isset($ICM688M2SL->A5MACPKR) ? $ICM688M2SL->A5MACPKR : '';
$A5SENTPKR = isset($ICM688M2SL->A5SENTPKR) ? $ICM688M2SL->A5SENTPKR : '';
$a5MACPKR = isset($ICM688M2SL->A5MACPKR) ? $ICM688M2SL->A5MACPKR : '';
$a5SENTPKR = isset($ICM688M2SL->A5SENTPKR) ? $ICM688M2SL->A5SENTPKR : '';
dump('ICM688M2 Record: ' . $A5MACPKR . '-' . $A5SENTPKR);
dump('ICM688M2 Record: ' . $a5MACPKR . '-' . $a5SENTPKR);
$ICM799MINS = DB::connection(config('m3.connection', 'pgsql'))->table('icm799m')
->where('IMDELNO', '=', $A5MACPKR)
->update(['IMSENTPKR' => $A5SENTPKR]);
$iCM799MINS = DB::connection(config('m3.connection', 'pgsql'))->table('icm799m')
->where('IMDELNO', '=', $a5MACPKR)
->update(['IMSENTPKR' => $a5SENTPKR]);
}
}
@@ -192,27 +191,27 @@ class utilitiesContoller extends Controller
// Get the Calling User
// $userId = 'TWOSHIP';
// $SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
// $sHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
// Get Manifest Array
$GSArray = $request->query();
$gSArray = $request->query();
$SHUSER = isset($GSArray['User']) ? trim($GSArray['User']) : '';
$sHUSER = isset($gSArray['User']) ? trim($gSArray['User']) : '';
if ($SHUSER != '') {
if ($sHUSER != '') {
// Get User CO & WH from Table ICM428M
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
$iCM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US', 'R428CO', 'R428WH', 'R428PL')
->where('R428US', '=', $SHUSER)
->where('R428US', '=', $sHUSER)
->first();
$R428US = isset($ICM428M->R428US) ? $ICM428M->R428US : ''; // User
$COMPANY = isset($ICM428M->R428CO) ? $ICM428M->R428CO : ''; // Company
$PLANT = isset($ICM428M->R428PL) ? $ICM428M->R428PL : ''; // Plant
$WHS = isset($ICM428M->R428WH) ? $ICM428M->R428WH : ''; // WareHouse
$r428US = isset($iCM428M->R428US) ? $iCM428M->R428US : ''; // User
$cOMPANY = isset($iCM428M->R428CO) ? $iCM428M->R428CO : ''; // Company
$pLANT = isset($iCM428M->R428PL) ? $iCM428M->R428PL : ''; // Plant
$wHS = isset($iCM428M->R428WH) ? $iCM428M->R428WH : ''; // WareHouse
$Macpkr = $GSArray['Macpkr'];
$packageType = trim($GSArray['packageType']); // 1 => Pallet , 0 => Carton
$macpkr = $gSArray['Macpkr'];
$packageType = trim($gSArray['packageType']); // 1 => Pallet , 0 => Carton
$packageTypeDesc = $packageType == 1 ? 'Pallet' : 'Carton';
$manufactID = '0826528'; // MAK : get ID from Nvent and save to Config File
$total_length = 9;
@@ -246,23 +245,23 @@ class utilitiesContoller extends Controller
<body style="font-family: Arial, sans-serif;">';
// Get number of Pallets
$packageCount = count($GSArray['PackagesArray']);
$packageCount = count($gSArray['PackagesArray']);
$packageNum = 1;
// Get GS1 Label MAX ID from ICM695M3 :
$GS1SEQUENCESel = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')->max('ID');
$GS1SEQUENCE = isset($GS1SEQUENCESel) ? $GS1SEQUENCESel : 0;
$gS1SEQUENCESel = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')->max('ID');
$gS1SEQUENCE = isset($gS1SEQUENCESel) ? $gS1SEQUENCESel : 0;
// Loop PackagesArray : Build Table for PDF and Insert to ICM695m3
foreach ($GSArray['PackagesArray'] as $key => $value) {
foreach ($gSArray['PackagesArray'] as $key => $value) {
$table_style = $packageNum < $packageCount ? ' style="page-break-after: always;" ' : '';
$A2INTBOX = trim($value);
$a2INTBOX = trim($value);
$GS1SEQUENCE++;
$GS1SEQUENCEID = str_pad($GS1SEQUENCE, $total_length, '0', STR_PAD_LEFT);
$gS1SEQUENCE++;
$gS1SEQUENCEID = str_pad($gS1SEQUENCE, $total_length, '0', STR_PAD_LEFT);
// Build GS1 18 Digits Code
$gs1_128_bc_1 = '00' . $packageType . $manufactID . $GS1SEQUENCEID;
$gs1_128_bc_1 = '00' . $packageType . $manufactID . $gS1SEQUENCEID;
// Calculate Check Digit
$digits = str_split($gs1_128_bc_1);
@@ -286,17 +285,17 @@ class utilitiesContoller extends Controller
// SSCC 18 Digits Code
$gs1_128_bc = $gs1_128_bc_1 . $checkDigit;
$gs1_128_bc_desc = '(00)' . $packageType . $manufactID . $GS1SEQUENCEID . $checkDigit;
$gs1_128_bc_desc = '(00)' . $packageType . $manufactID . $gS1SEQUENCEID . $checkDigit;
$data = [
'ship_to' => $GSArray['Recipient_CompanyName'] . '<br>' . $GSArray['Recipient_Address1'] . '<br>' .
$GSArray['Recipient_City'] . ',' . $GSArray['Recipient_State']
. '<br>' . $GSArray['Recipient_PostalCode'],
'from' => $GSArray['Sender_CompanyName'] . '<br>' . $GSArray['Sender_Address1'] . '<br>' .
$GSArray['Sender_City'] . ',' . $GSArray['Sender_State']
. '<br>' . $GSArray['Sender_PostalCode'],
'ship_to_lbl' => '420' . $GSArray['Recipient_PostalCode'],
'ship_to_desc' => '(420)' . $GSArray['Recipient_PostalCode'],
'ship_to' => $gSArray['Recipient_CompanyName'] . '<br>' . $gSArray['Recipient_Address1'] . '<br>' .
$gSArray['Recipient_City'] . ',' . $gSArray['Recipient_State']
. '<br>' . $gSArray['Recipient_PostalCode'],
'from' => $gSArray['Sender_CompanyName'] . '<br>' . $gSArray['Sender_Address1'] . '<br>' .
$gSArray['Sender_City'] . ',' . $gSArray['Sender_State']
. '<br>' . $gSArray['Sender_PostalCode'],
'ship_to_lbl' => '420' . $gSArray['Recipient_PostalCode'],
'ship_to_desc' => '(420)' . $gSArray['Recipient_PostalCode'],
'pro' => '190071217845706', // MAK : Check missing info with Brad
'item_number' => '10000B',
'upc' => '098506095310',
@@ -328,15 +327,15 @@ class utilitiesContoller extends Controller
' . $data['ship_to_desc'] . '
</td>
<td class="border_btm margin_t align_lft">
Carrier: ' . $GSArray['CarrierName'] . ' <br>
PRO #: ' . $GSArray['trackingno'] . ' <br>
B/L #: ' . $GSArray['BOLnumber'] . ' <br>
Ref : ' . $A2INTBOX . '
Carrier: ' . $gSArray['CarrierName'] . ' <br>
PRO #: ' . $gSArray['trackingno'] . ' <br>
B/L #: ' . $gSArray['BOLnumber'] . ' <br>
Ref : ' . $a2INTBOX . '
</td>
</tr>
<tr>
<td colspan="4" class="border_btm margin_t align_lft">
PURCHASE ORDER: ' . $GSArray['ShipmentPONumber'] . ' <br>
PURCHASE ORDER: ' . $gSArray['ShipmentPONumber'] . ' <br>
Vendor: ' . $manufactID . '
</td>
</tr>
@@ -356,10 +355,10 @@ class utilitiesContoller extends Controller
$packageNum++;
// Insert new Record to ICM695M3 $gs1_128_bc
$ICM695M3SQLInsert = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')
->insert(['A2CO' => $COMPANY, 'A2WHS' => $WHS, 'A2PLANT' => $PLANT, 'A2MACPKR' => $Macpkr, 'A2GS1LABEL' => $gs1_128_bc, 'A2INTBOX' => $A2INTBOX]);
$iCM695M3SQLInsert = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')
->insert(['A2CO' => $cOMPANY, 'A2WHS' => $wHS, 'A2PLANT' => $pLANT, 'A2MACPKR' => $macpkr, 'A2GS1LABEL' => $gs1_128_bc, 'A2INTBOX' => $a2INTBOX]);
Log::channel('LabelCron')->info('<<< GS1-128...End of Label Creation for Mackpkr: ' . $Macpkr);
Log::channel('LabelCron')->info('<<< GS1-128...End of Label Creation for Mackpkr: ' . $macpkr);
}
$html .= '</body> </html>';
@@ -380,30 +379,29 @@ class utilitiesContoller extends Controller
$labelsPath = Config::get('arrays.PdfPath'); // '/www/sentm3live/htdocs/labels/';
// Put the PDF in labels/CarrierLabel
$GSFolder = 'GSLabel';
$gSFolder = 'GSLabel';
$carrierFileName = $GSFolder . '_' . $Macpkr . '_' . $COMPANY . '_' . $WHS . '_' . $A2INTBOX;
$carrierFileName = $gSFolder . '_' . $macpkr . '_' . $cOMPANY . '_' . $wHS . '_' . $a2INTBOX;
// LTL
// if ($packageType=='1') {
// $carrierFileName = $GSFolder.'_'.$Macpkr.'_'.$COMPANY.'_'.$WHS;
// $carrierFileName = $gSFolder.'_'.$macpkr.'_'.$cOMPANY.'_'.$wHS;
// }
// # small Packs
// else{
// $carrierFileName = $GSFolder.'_'.$Macpkr.'_'.$COMPANY.'_'.$WHS.'_'.$A2INTBOX;
// $carrierFileName = $gSFolder.'_'.$macpkr.'_'.$cOMPANY.'_'.$wHS.'_'.$a2INTBOX;
// }
$GS1FileName = $labelsPath . $GSFolder . '/' . $carrierFileName . '.pdf';
$GS1FileNameNoRoot = $GSFolder . '/' . $carrierFileName;
file_put_contents($GS1FileName, $pdfContent);
$gS1FileName = $labelsPath . $gSFolder . '/' . $carrierFileName . '.pdf';
$gS1FileNameNoRoot = $gSFolder . '/' . $carrierFileName;
file_put_contents($gS1FileName, $pdfContent);
ob_end_clean();
}
// # Insert new Record to ICM695M3 $gs1_128_bc
// $ICM695M3SQLInsert = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')
// ->insert(['A2CO'=> $COMPANY,'A2WHS'=> $WHS,'A2MACPKR'=> $Macpkr,'A2GS1LABEL'=> $gs1_128_bc]);
// $iCM695M3SQLInsert = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')
// ->insert(['A2CO'=> $cOMPANY,'A2WHS'=> $wHS,'A2MACPKR'=> $macpkr,'A2GS1LABEL'=> $gs1_128_bc]);
return json_encode(['result' => 'success', 'GS1File' => $GS1FileNameNoRoot]);
return json_encode(['result' => 'success', 'GS1File' => $gS1FileNameNoRoot]);
} catch (\Throwable $th) {
Log::channel('LabelCron')->error($th);
@@ -519,7 +517,6 @@ class utilitiesContoller extends Controller
</body>
</html>';
// Initialize Dompdf
$dompdf = new Dompdf;
$dompdf->loadHtml($html);
@@ -534,9 +531,9 @@ class utilitiesContoller extends Controller
// // return $pdfContent;
$labelsPath = '/www/sentm3live/htdocs/labels/';
// # Put the PDF in labels/CarrierLabel
$GSFolder = 'GSLabel';
$gSFolder = 'GSLabel';
$carrierFileName = 'GSLabel';
file_put_contents($labelsPath . $GSFolder . '/' . $carrierFileName . '.pdf', $pdfContent);
file_put_contents($labelsPath . $gSFolder . '/' . $carrierFileName . '.pdf', $pdfContent);
// Save the PDF string to a temporary file for debugging
// $tempPdfPath = tempnam(sys_get_temp_dir(), 'pdf') . '.pdf';
@@ -568,28 +565,28 @@ class utilitiesContoller extends Controller
{
// $total_length = 9;
// # MAK replace cache ID with MAX ID+1 from ICM695M3
// $GS1SEQUENCESel = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')->max('ID');
// dump($GS1SEQUENCESel);
// $GS1SEQUENCE = isset($GS1SEQUENCESel) ? $GS1SEQUENCESel : 0;
// $GS1SEQUENCE++;
// $GS1SEQUENCEID = str_pad($GS1SEQUENCE, $total_length, "0", STR_PAD_LEFT);
// dump($GS1SEQUENCEID);
// $gS1SEQUENCESel = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m3')->max('ID');
// dump($gS1SEQUENCESel);
// $gS1SEQUENCE = isset($gS1SEQUENCESel) ? $gS1SEQUENCESel : 0;
// $gS1SEQUENCE++;
// $gS1SEQUENCEID = str_pad($gS1SEQUENCE, $total_length, "0", STR_PAD_LEFT);
// dump($gS1SEQUENCEID);
// MAK Get Contents
// ESN1
// $AYMACPKR='888568'; // LTL example
// $AYMACPKR='894337'; // another LTL example with smaller orders, therefore pallets are more mixed
// $AYMACPKR='1225311'; // parcel example
// $aYMACPKR='888568'; // LTL example
// $aYMACPKR='894337'; // another LTL example with smaller orders, therefore pallets are more mixed
// $aYMACPKR='1225311'; // parcel example
// ESN2
// $AYMACPKR='999999'; // LTL example
$AYMACPKR = '748101'; // LTL example
// $aYMACPKR='999999'; // LTL example
$aYMACPKR = '748101'; // LTL example
$myRequest = new Request;
$myRequest->setMethod('POST');
$myRequest->request->add([
'MACPKR' => $AYMACPKR,
'MACPKR' => $aYMACPKR,
]);
// Call the controller method properly