diff --git a/Modules/M3/Console/ClosedOrderSaveXls.php b/Modules/M3/Console/ClosedOrderSaveXls.php index 3c95b125..ada7559e 100644 --- a/Modules/M3/Console/ClosedOrderSaveXls.php +++ b/Modules/M3/Console/ClosedOrderSaveXls.php @@ -13,6 +13,8 @@ use Str; class ClosedOrderSaveXls extends Command { + private const XLSX_EXTENSION = '.xlsx'; + /** * The name and signature of the console command. * @@ -75,9 +77,9 @@ class ClosedOrderSaveXls extends Command $toreportDateWD = $toPreviousMonth; if ($WHS == '321') { - $prevMonthFile = 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '.xlsx'; + $prevMonthFile = 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . self::XLSX_EXTENSION; } else { - $prevMonthFile = $WHS . '/Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '-' . $WHS . '.xlsx'; + $prevMonthFile = $WHS . '/Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '-' . $WHS . self::XLSX_EXTENSION; } $this->info('Generate Last Month Report...'); @@ -165,7 +167,7 @@ class ClosedOrderSaveXls extends Command if ($WHS == '321') { $currentMonthFile = 'first_of_month_to_current_date.xlsx'; } else { - $currentMonthFile = $WHS . '/first_of_month_to_current_date_' . $WHS . '.xlsx'; + $currentMonthFile = $WHS . '/first_of_month_to_current_date_' . $WHS . self::XLSX_EXTENSION; } $this->info('Generate Current Month Report...'); diff --git a/Modules/M3/Http/Controllers/API/CloseShipment.php b/Modules/M3/Http/Controllers/API/CloseShipment.php index 4879a6cd..0932ed22 100644 --- a/Modules/M3/Http/Controllers/API/CloseShipment.php +++ b/Modules/M3/Http/Controllers/API/CloseShipment.php @@ -17,6 +17,10 @@ use Str; // use Request; class CloseShipment extends Controller { + private const ZERO_PAD = '000000'; + private const JSON_CONTENT_TYPE = 'application/json'; + private const NULL_M3_RESPONSE = 'M3 API responded with null value'; + // CloseShipmentCoChargeAPI : with URL PARAMS COCharge public static function CloseShipmentCoChargeAPI(Request $request) { @@ -49,7 +53,7 @@ class CloseShipment extends Controller $LineAck = []; // PDF File PATH $pdfFilePath = Config::get('arrays.PdfPath'); - $DELIVERYNO = $MANIFEST != '' ? $MANIFEST : '000000'; + $DELIVERYNO = $MANIFEST != '' ? $MANIFEST : self::ZERO_PAD; // Log::channel('dailyCron')->info("Close Manifest:".$MANIFEST.'-WHS: '.$WHS."-CO:".$COMPANY); @@ -89,7 +93,7 @@ class CloseShipment extends Controller $IonToken = isset($tokenData->token) ? $tokenData->token : ''; } else { $SHDATA = isset($tokenData->message) ? $tokenData->message : ''; - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; // Write to Logs : Error $data = [ @@ -439,7 +443,7 @@ class CloseShipment extends Controller // If billable=Y and a4ratetcp(FREIGHT)>0 and a4ratem3=blank, then call the freight API CoCharge if ($BILLABLE == 'Y' && $FREIGHT > 0 && $A4RATEM3 == '') { - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; if ($SHIPTYPE == 'LTL') { $shippingToBill = $FREIGHT * (100.00 - Config::get('arrays.misc.discountCarrierRateForCustomerPriceLTL')) / 100; @@ -496,6 +500,9 @@ class CloseShipment extends Controller $ContentLabel = route('m3.M3GetPDFFromCache.index', ['MACPKR' => $AYMACPKR, 'DOCTYPE' => $DOCTYPE]); } break; + + default: + break; } } @@ -602,7 +609,7 @@ class CloseShipment extends Controller // No Errors Proceed in Calling M3 CLose API if ($ErrorMsgs == '') { // Write to Logs Out : Send JSON Request To M3 - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; // dump($DELIVERYNO); // MAK : Log JSON Manifest # and MACKPKR # // Log::channel('dailyCron')->info('1 >>> JSON Sent for Manifest: '.$MANIFEST.' ,Macpicker: '.$AYMACPKR); @@ -624,12 +631,12 @@ class CloseShipment extends Controller Helper::logToICM699M($data); $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', - 'Connection' => 'close', - ]) + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, + 'Connection' => 'close', + ]) ->withToken($token) - ->withBody($JSONCS, 'application/json') + ->withBody($JSONCS, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->retry(3, 100) ->post($endPointURL); @@ -683,8 +690,8 @@ class CloseShipment extends Controller } } else { $M3APIRESULT = 'Error'; - $responseMsg = 'M3 API responded with null value'; - $M3APIRESULTMsg = 'M3 API responded with null value'; + $responseMsg = self::NULL_M3_RESPONSE; + $M3APIRESULTMsg = self::NULL_M3_RESPONSE; $responseResult = ''; $M3Errors = $responseStatusCode; } @@ -692,7 +699,7 @@ class CloseShipment extends Controller // If you get a successful response if ($M3APIRESULT != 'Error') { // Write to Logs Out : Success - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -718,7 +725,7 @@ class CloseShipment extends Controller ->update(['A4PICKSTS' => 'a']); // Write to Logs Out : Error - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -743,7 +750,7 @@ class CloseShipment extends Controller // Write to Logs : Error // Clear Duplicate messages $ErrorMsgsC = Helper::removeDuplicateSubstrings($ErrorMsgs); - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -831,7 +838,7 @@ class CloseShipment extends Controller ]); // Write to Logs Out : JSON Request To M3 - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -848,12 +855,12 @@ class CloseShipment extends Controller Helper::logToICM699M($data); $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', - 'Connection' => 'close', - ]) + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, + 'Connection' => 'close', + ]) ->withToken($token) - ->withBody($JSONCS, 'application/json') + ->withBody($JSONCS, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->retry(2, 100) ->post($endPointURL); @@ -884,14 +891,14 @@ class CloseShipment extends Controller } else { $M3APIRESULT = 'Error'; - $responseMsg = 'M3 API responded with null value'; - $M3APIRESULTMsg = 'M3 API responded with null value'; + $responseMsg = self::NULL_M3_RESPONSE; + $M3APIRESULTMsg = self::NULL_M3_RESPONSE; } // If you get a successful response if ($M3APIRESULT != 'Error') { // Write to Logs Out : Success - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -918,7 +925,7 @@ class CloseShipment extends Controller ->update(['A4PICKSTS' => 'a']); // Write to Logs Out : Error - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -968,7 +975,7 @@ class CloseShipment extends Controller } // ## End Zero Pick else { - $DELIVERYNO = isset($MANIFEST) ? $MANIFEST : '000000'; + $DELIVERYNO = isset($MANIFEST) ? $MANIFEST : self::ZERO_PAD; // # Set SHDATA Message $SHDATAMSG = 'No records found in ICM695M1,or URL parameters incomplete'; // count($ICM695M1TMP)==0 ? 'MacPkr already closed' : @@ -1000,7 +1007,7 @@ class CloseShipment extends Controller } } else { // Write to Logs Out : Error - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), @@ -1051,7 +1058,7 @@ class CloseShipment extends Controller ]); } else { // Write to Logs Out : Error - $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : '000000'; + $DELIVERYNO = isset($AYMACPKR) ? $AYMACPKR : self::ZERO_PAD; $data = [ 'SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), diff --git a/Modules/M3/Http/Controllers/API/M3Controller.php b/Modules/M3/Http/Controllers/API/M3Controller.php index c134694a..05c45f3f 100644 --- a/Modules/M3/Http/Controllers/API/M3Controller.php +++ b/Modules/M3/Http/Controllers/API/M3Controller.php @@ -13,6 +13,9 @@ use Str; class M3Controller extends Controller { + private const FIELD_PREFIX = 'Field: '; + private const M3_LIST_SUFFIX = ' M3-Lis-JSN'; + // Split Data and Write to ICM666M2 public function insertToICM666M2($dataSplit, $commentData) { @@ -377,18 +380,18 @@ class M3Controller extends Controller if (! $lengthTest[413] || ! $lengthTest[411] || ! $lengthTest[417]) { if (! $lengthTest[413]) { - $message[] = ['code' => '413', 'status' => 'error', 'message' => 'Field: ' . $key . ' is larger then expected']; + $message[] = ['code' => '413', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is larger then expected']; } if (! $lengthTest[411]) { - $message[] = ['code' => '411', 'status' => 'error', 'message' => 'Field: ' . $key . ' is empty']; + $message[] = ['code' => '411', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is empty']; } if (! $lengthTest[417]) { - $message[] = ['code' => '417', 'status' => 'error', 'message' => 'Field: ' . $key . 'type is different then Expected type: ' . $value[2]]; + $message[] = ['code' => '417', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . 'type is different then Expected type: ' . $value[2]]; } // Write to Logs Out : Error & JSON $data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-spl', - 'SHDATA' => json_encode($message) . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; + 'SHDATA' => json_encode($message) . self::M3_LIST_SUFFIX . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; Helper::logToICM699M($data); return response()->json($message); @@ -485,7 +488,7 @@ class M3Controller extends Controller if ($PGMERRORS != '') { // Write to Logs Out : Error & JSON $data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-spl', - 'SHDATA' => $PGMERRORS . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; + 'SHDATA' => $PGMERRORS . self::M3_LIST_SUFFIX . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; Helper::logToICM699M($data); } } @@ -517,7 +520,7 @@ class M3Controller extends Controller } catch (\Throwable $th) { // Write to Logs Out : Error & JSON $data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-in', - 'SHDATA' => 'General Catchable Error - ' . substr($th, 0, 300) . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; + 'SHDATA' => 'General Catchable Error - ' . substr($th, 0, 300) . self::M3_LIST_SUFFIX . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse]; Helper::logToICM699M($data); // Log::error($th); diff --git a/Modules/M3/Http/Controllers/API/M3InventoryReport.php b/Modules/M3/Http/Controllers/API/M3InventoryReport.php index 5b1648ee..af086990 100644 --- a/Modules/M3/Http/Controllers/API/M3InventoryReport.php +++ b/Modules/M3/Http/Controllers/API/M3InventoryReport.php @@ -15,6 +15,10 @@ use Str; class M3InventoryReport extends Controller { + private const ZERO_PAD = '000000'; + private const JSON_CONTENT_TYPE = 'application/json'; + private const NO_M3_RESPONSE = 'Error: No Response from M3'; + // M3InventoryReport for Single Part public function M3InventoryReport(Request $request) { @@ -28,7 +32,7 @@ class M3InventoryReport extends Controller // Set SHSOURCE $SHSOURCE = 'M3InventoryReport'; $M3Errors = ''; - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; try { // Get Json Contents @@ -49,7 +53,7 @@ class M3InventoryReport extends Controller } else { $SHDATA = isset($tokenData->message) ? $tokenData->message : ''; // Write to Logs : Error - $data = ['SHMACPKR' => '000000', 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', + $data = ['SHMACPKR' => self::ZERO_PAD, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => $SHDATA, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => '', 'SHWHS' => $WHS]; Helper::logToICM699M($data); @@ -66,8 +70,8 @@ class M3InventoryReport extends Controller ]; $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, ]) ->withToken($token) ->timeout(Config::get('arrays.curlTimeOut')) @@ -82,7 +86,7 @@ class M3InventoryReport extends Controller $responseJSON = $response->getBody()->getContents(); $JsonSanytized = Helper::sanityzeString($responseJSON); } else { - $M3Errors = 'Error: No Response from M3'; + $M3Errors = self::NO_M3_RESPONSE; } if ($M3Errors != '') { @@ -162,7 +166,7 @@ class M3InventoryReport extends Controller $REQKPKUS = isset($urlParams['REQKPKUS']) ? $urlParams['REQKPKUS'] : 'WebUser'; $CO = isset($urlParams['CO']) ? $urlParams['CO'] : ''; $WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : ''; - $MACPKR = isset($urlParams['MACPKR']) ? $urlParams['MACPKR'] : '000000'; // Delivery Number + $MACPKR = isset($urlParams['MACPKR']) ? $urlParams['MACPKR'] : self::ZERO_PAD; // Delivery Number $PKLN = isset($urlParams['PKLN']) ? $urlParams['PKLN'] : ''; if ($urlParams != '') { @@ -228,11 +232,11 @@ class M3InventoryReport extends Controller $token = $IonToken; $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, ]) ->withToken($token) - ->withBody($JSON, 'application/json') + ->withBody($JSON, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->post($endPointURL); @@ -248,7 +252,7 @@ class M3InventoryReport extends Controller $responseArray = json_decode($JsonSanytized, true); $responseTMP = $responseArray['result']; } else { - $M3Errors = 'Error: No Response from M3'; + $M3Errors = self::NO_M3_RESPONSE; } // Validate response From M3 @@ -262,7 +266,7 @@ class M3InventoryReport extends Controller return response()->json([ 'code' => '405', 'status' => 'error', - 'message' => 'Error: No Response from M3', + 'message' => self::NO_M3_RESPONSE, ]); } else { // Write to Logs : JSON @@ -366,7 +370,7 @@ class M3InventoryReport extends Controller ]); } else { // Write to Logs Out : Error - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => 'No Records Found in ICM688M2', 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS]; Helper::logToICM699M($data); @@ -381,7 +385,7 @@ class M3InventoryReport extends Controller } else { // Write to Logs Out : Error - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => 'No URL Parameters Sent', 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS]; Helper::logToICM699M($data); @@ -395,7 +399,7 @@ class M3InventoryReport extends Controller } } catch (\Throwable $th) { // Write to Logs Out : Error - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $getCurlErrors = str_contains($th->getMessage(), 'cURL error'); if ($getCurlErrors) { // dd($getCurlErrors); diff --git a/Modules/M3/Http/Controllers/API/PdfStorage.php b/Modules/M3/Http/Controllers/API/PdfStorage.php index 1ffb6b3e..39c1fef5 100644 --- a/Modules/M3/Http/Controllers/API/PdfStorage.php +++ b/Modules/M3/Http/Controllers/API/PdfStorage.php @@ -14,6 +14,8 @@ use Str; class PdfStorage extends Controller { + private const ZERO_PAD = '000000'; + // PdfStorageAPI : PDF file read and save to Cache public function PdfStorageAPI(Request $request) { @@ -41,8 +43,8 @@ class PdfStorage extends Controller if ($urlParams != '') { // Key Combination : COMPANY WHS A4MACPKR DOCTYPE DOCNUM // Document type (PackingList, CarrierLabel, ContentLabel) - $DELIVERYNO = isset($A4MACPKR) ? $A4MACPKR : '000000'; - $DELIVERYNO = $DELIVERYNO != '' && $DELIVERYNO != null ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($A4MACPKR) ? $A4MACPKR : self::ZERO_PAD; + $DELIVERYNO = $DELIVERYNO != '' && $DELIVERYNO != null ? $DELIVERYNO : self::ZERO_PAD; // Write to Logs : Params In $IncomingParams = ['COMPANY' => $COMPANY, 'WHS' => $WHS, 'DOCTYPE' => $DOCTYPE, 'FILENAME' => $FILENAME, 'A4MACPKR' => $A4MACPKR, 'DOCNUM' => $DOCNUM]; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => $DOCNUM, 'SHTYPE' => 'M3-Req-out', @@ -127,7 +129,7 @@ class PdfStorage extends Controller } } else { // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => 'No URL Parameters Sent.', 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS]; Helper::logToICM699M($data); @@ -143,7 +145,7 @@ class PdfStorage extends Controller // Log::error($th); // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => 'An Error Occured - ' . substr($th, 0, 300), 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS]; Helper::logToICM699M($data); diff --git a/Modules/M3/Http/Controllers/API/ReplenAPI.php b/Modules/M3/Http/Controllers/API/ReplenAPI.php index 7ad1335e..f119fb9b 100644 --- a/Modules/M3/Http/Controllers/API/ReplenAPI.php +++ b/Modules/M3/Http/Controllers/API/ReplenAPI.php @@ -14,6 +14,9 @@ use Str; class ReplenAPI extends Controller { + private const ZERO_PAD = '000000'; + private const JSON_CONTENT_TYPE = 'application/json'; + // M3Replenishement with URL Params public function M3InventoryReportReplen(Request $request) { @@ -25,7 +28,7 @@ class ReplenAPI extends Controller // Log::info( $request->all() ); // Get The Calling User $SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser'; - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $SHSOURCE = 'M3InventoryReportReplen'; $M3Errors = ''; @@ -83,11 +86,11 @@ class ReplenAPI extends Controller $token = $IonToken; $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', - ]) + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, + ]) ->withToken($token) - ->withBody($JSON, 'application/json') + ->withBody($JSON, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->retry(3, 100) ->post($endPointURL); @@ -226,7 +229,7 @@ class ReplenAPI extends Controller ]); } else { // Write to Logs Out : Error - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', 'SHDATA' => 'No URL Parameters Sent', 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS]; Helper::logToICM699M($data); @@ -240,7 +243,7 @@ class ReplenAPI extends Controller } } catch (\Throwable $th) { // Write to Logs Out : Error - $MACPKR = isset($MACPKR) ? $MACPKR : '000000'; + $MACPKR = isset($MACPKR) ? $MACPKR : self::ZERO_PAD; $getCurlErrors = str_contains($th->getMessage(), 'cURL error'); if ($getCurlErrors) { diff --git a/Modules/M3/Http/Controllers/API/TransferAPI.php b/Modules/M3/Http/Controllers/API/TransferAPI.php index dd0bba5a..8b965315 100644 --- a/Modules/M3/Http/Controllers/API/TransferAPI.php +++ b/Modules/M3/Http/Controllers/API/TransferAPI.php @@ -15,6 +15,11 @@ use Str; class TransferAPI extends Controller { + private const ZERO_PAD = '000000'; + private const JSON_CONTENT_TYPE = 'application/json'; + private const ORDER_CATEGORY_LABEL = ' Order Category: '; + private const NO_URL_PARAMETERS = 'No URL Parameters Sent'; + // TransferAPIURL : with URL PARAMS public function TransferAPIURL(Request $request) { @@ -44,7 +49,7 @@ class TransferAPI extends Controller $LOTNUMBER = isset($urlParams['LOTNUMBER']) ? $urlParams['LOTNUMBER'] : ''; $CONUMBER = isset($urlParams['CONUMBER']) ? $urlParams['CONUMBER'] : ''; $COLINENO = isset($urlParams['COLINENO']) ? $urlParams['COLINENO'] : ''; - $DELIVERYNO = isset($urlParams['DELIVERYNO']) ? $urlParams['DELIVERYNO'] : '000000'; + $DELIVERYNO = isset($urlParams['DELIVERYNO']) ? $urlParams['DELIVERYNO'] : self::ZERO_PAD; $PICKLISTSUFFIX = isset($urlParams['PICKLISTSUFFIX']) ? $urlParams['PICKLISTSUFFIX'] : ''; $ENDFLAG = isset($urlParams['ENDFLAG']) ? $urlParams['ENDFLAG'] : ''; $TYPE = isset($urlParams['TYPE']) ? $urlParams['TYPE'] : ''; @@ -65,7 +70,7 @@ class TransferAPI extends Controller // 5 = Distribution Order // 9 = Move order - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $TRANSTYPE = isset($urlParams['TRANSTYPE']) ? $urlParams['TRANSTYPE'] : ''; // R for Retry $SHDT = isset($urlParams['SHDT']) ? $urlParams['SHDT'] : ''; @@ -129,7 +134,7 @@ class TransferAPI extends Controller $LOTNUMBER = isset($JSONTR->LOTNUMBER) ? $JSONTR->LOTNUMBER : ''; $CONUMBER = isset($JSONTR->CONUMBER) ? $JSONTR->CONUMBER : ''; $COLINENO = isset($JSONTR->COLINENO) ? $JSONTR->COLINENO : ''; - $DELIVERYNO = isset($JSONTR->DELIVERYNO) ? $JSONTR->DELIVERYNO : '000000'; + $DELIVERYNO = isset($JSONTR->DELIVERYNO) ? $JSONTR->DELIVERYNO : self::ZERO_PAD; $PICKLISTSUFFIX = isset($JSONTR->PICKLISTSUFFIX) ? $JSONTR->PICKLISTSUFFIX : ''; $ENDFLAG = isset($JSONTR->ENDFLAG) ? $JSONTR->ENDFLAG : ''; $TYPE = isset($JSONTR->TYPE) ? $JSONTR->TYPE : ''; @@ -255,11 +260,11 @@ class TransferAPI extends Controller $token = $IonToken; $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, ]) ->withToken($token) - ->withBody($JSON, 'application/json') + ->withBody($JSON, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->post($endPointURL); $responseStatusCode = $response->getStatusCode(); @@ -294,7 +299,7 @@ class TransferAPI extends Controller 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', - 'SHDATA' => $responseStatusCode . 'TYPE :' . $TYPE . ' Order Category: ' . $ORDERCATEGORY . '-' . $M3JSONResponse . $M3SessionId . $M3ResponseTime . $M3transferTime, + 'SHDATA' => $responseStatusCode . 'TYPE :' . $TYPE . self::ORDER_CATEGORY_LABEL . $ORDERCATEGORY . '-' . $M3JSONResponse . $M3SessionId . $M3ResponseTime . $M3transferTime, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $DIVI, @@ -334,7 +339,7 @@ class TransferAPI extends Controller 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', - 'SHDATA' => $responseStatusCode . '-' . $M3Errors . '-TYPE:' . $TYPE . ' Order Category: ' . $ORDERCATEGORY . '-' . $M3JSONResponse . + 'SHDATA' => $responseStatusCode . '-' . $M3Errors . '-TYPE:' . $TYPE . self::ORDER_CATEGORY_LABEL . $ORDERCATEGORY . '-' . $M3JSONResponse . 'M3-JSN-out' . $JSONIN . $M3SessionId . $M3ResponseTime . $M3transferTime, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, @@ -346,7 +351,7 @@ class TransferAPI extends Controller return response()->json([ 'code' => '206', 'status' => 'Error', - 'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . ' Order Category: ' . $ORDERCATEGORY . '-' . $M3JSONResponse, + 'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . self::ORDER_CATEGORY_LABEL . $ORDERCATEGORY . '-' . $M3JSONResponse, ]); } } @@ -361,14 +366,14 @@ class TransferAPI extends Controller } } else { // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', - 'SHDATA' => 'No URL Parameters Sent', + 'SHDATA' => self::NO_URL_PARAMETERS, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $DIVI, @@ -380,7 +385,7 @@ class TransferAPI extends Controller return response()->json([ 'code' => '405', 'status' => 'Error', - 'message' => 'No URL Parameters Sent', + 'message' => self::NO_URL_PARAMETERS, ]); } } catch (\Throwable $th) { @@ -409,7 +414,7 @@ class TransferAPI extends Controller ]); } else { // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), @@ -545,11 +550,11 @@ class TransferAPI extends Controller $token = $IonToken; $response = Http::withHeaders([ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', + 'accept' => self::JSON_CONTENT_TYPE, + 'Content-Type' => self::JSON_CONTENT_TYPE, ]) ->withToken($token) - ->withBody($JSON, 'application/json') + ->withBody($JSON, self::JSON_CONTENT_TYPE) ->timeout(Config::get('arrays.curlTimeOut')) ->post($endPointURL); $responseStatusCode = $response->getStatusCode(); @@ -628,14 +633,14 @@ class TransferAPI extends Controller } } else { // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out', - 'SHDATA' => 'No URL Parameters Sent', + 'SHDATA' => self::NO_URL_PARAMETERS, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $DIVI, @@ -647,7 +652,7 @@ class TransferAPI extends Controller return response()->json([ 'code' => '405', 'status' => 'Error', - 'message' => 'No URL Parameters Sent', + 'message' => self::NO_URL_PARAMETERS, ]); } } catch (\Throwable $th) { @@ -676,7 +681,7 @@ class TransferAPI extends Controller ]); } else { // Write to Logs Out : Error - $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000'; + $DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : self::ZERO_PAD; $data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), diff --git a/Modules/M3/Http/Controllers/BoxPackToPalletController.php b/Modules/M3/Http/Controllers/BoxPackToPalletController.php index bcf8b120..60016240 100644 --- a/Modules/M3/Http/Controllers/BoxPackToPalletController.php +++ b/Modules/M3/Http/Controllers/BoxPackToPalletController.php @@ -8,6 +8,12 @@ use Str; class BoxPackToPalletController extends Controller { + private const PALLET_TABLE_ALIAS = 'ICM659M as p'; + private const CONVEYOR_SELECT = 'cnv.R652SORTK as CONVEYOR_NAME'; + private const CARTON_TABLE_ALIAS = 'ICM695M1 as c'; + private const CONVEYOR_VALUE_ALIAS = 'ICM688M1 as cv'; + private const CONVEYOR_TABLE_ALIAS = 'ICM652M as cnv'; + public static function index(Request $request) { return view('m3::liberty-theme.pages.BoxPackToPallet'); @@ -21,7 +27,7 @@ class BoxPackToPalletController extends Controller $userWhsCoPlant = self::getUserWhsCoPlant(); // dump($userWhsCoPlant); - $boxes = DB::connection(config('m3.connection', 'pgsql'))->table('ICM659M as p') + $boxes = DB::connection(config('m3.connection', 'pgsql'))->table(self::PALLET_TABLE_ALIAS) ->select( 'p.R659PALT', 'p.R659BOX', @@ -33,11 +39,11 @@ class BoxPackToPalletController extends Controller 'c.AYSPR15A01', 'cv.A4APR8N001', 'cv.A4SHSHCT', - 'cnv.R652SORTK as CONVEYOR_NAME', + self::CONVEYOR_SELECT, ) - ->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX') - ->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR') - ->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ') + ->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX') + ->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR') + ->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ') ->where('p.R659PALT', $R659PALT) ->where('p.R659CO', trim($userWhsCoPlant['USERCO'])) ->where('p.R659WHS', trim($userWhsCoPlant['USERWHS'])) @@ -90,17 +96,17 @@ class BoxPackToPalletController extends Controller // Step 2: Check if Box exists in ICM695M1 (with carrier + conveyor joined) $ICM695M1Sel = DB::connection(config('m3.connection', 'pgsql')) - ->table('ICM695M1 as c') + ->table(self::CARTON_TABLE_ALIAS) ->select( 'c.AYINTBOX', 'c.AYSPR15A01', 'c.AYTYPE', 'c.AYMACPKR', 'cv.A4APR8N001', - 'cnv.R652SORTK as CONVEYOR_NAME', + self::CONVEYOR_SELECT, ) - ->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR') - ->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ') + ->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR') + ->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ') ->where('c.AYINTBOX', $R659BOX) ->where('c.AYCO', trim($userWhsCoPlant['USERCO'])) ->where('c.AYWHS', trim($userWhsCoPlant['USERWHS'])) @@ -123,14 +129,14 @@ class BoxPackToPalletController extends Controller // Step 3: Check that all boxes on the pallet share the same Carrier and Conveyor if ($boxExistInICM695M && ! $boxisPalletICM695M && ! $exists) { $firstPalletBox = DB::connection(config('m3.connection', 'pgsql')) - ->table('ICM659M as p') + ->table(self::PALLET_TABLE_ALIAS) ->select( 'c.AYSPR15A01', - 'cnv.R652SORTK as CONVEYOR_NAME', + self::CONVEYOR_SELECT, ) - ->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX') - ->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR') - ->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ') + ->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX') + ->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR') + ->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ') ->where('p.R659PALT', $R659PALT) ->where('p.R659CO', trim($userWhsCoPlant['USERCO'])) ->where('p.R659WHS', trim($userWhsCoPlant['USERWHS'])) @@ -178,7 +184,7 @@ class BoxPackToPalletController extends Controller ]); // Step 5: Return the full refreshed box list - $boxes = DB::connection(config('m3.connection', 'pgsql'))->table('ICM659M as p') + $boxes = DB::connection(config('m3.connection', 'pgsql'))->table(self::PALLET_TABLE_ALIAS) ->select( 'p.R659PALT', 'p.R659BOX', @@ -190,11 +196,11 @@ class BoxPackToPalletController extends Controller 'c.AYSPR15A01', 'cv.A4APR8N001', 'cv.A4SHSHCT', - 'cnv.R652SORTK as CONVEYOR_NAME', + self::CONVEYOR_SELECT, ) - ->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX') - ->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR') - ->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ') + ->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX') + ->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR') + ->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ') ->where('p.R659PALT', $R659PALT) ->where('p.R659CO', trim($userWhsCoPlant['USERCO'])) ->where('p.R659WHS', trim($userWhsCoPlant['USERWHS'])) @@ -249,7 +255,7 @@ class BoxPackToPalletController extends Controller ->delete(); // Return refreshed list - $boxes = DB::connection(config('m3.connection', 'pgsql'))->table('ICM659M as p') + $boxes = DB::connection(config('m3.connection', 'pgsql'))->table(self::PALLET_TABLE_ALIAS) ->select( 'p.R659PALT', 'p.R659BOX', @@ -261,11 +267,11 @@ class BoxPackToPalletController extends Controller 'c.AYSPR15A01', 'cv.A4APR8N001', 'cv.A4SHSHCT', - 'cnv.R652SORTK as CONVEYOR_NAME', + self::CONVEYOR_SELECT, ) - ->leftJoin('ICM695M1 as c', 'p.R659BOX', '=', 'c.AYINTBOX') - ->leftJoin('ICM688M1 as cv', 'c.AYMACPKR', '=', 'cv.A4MACPKR') - ->leftJoin('ICM652M as cnv', 'cv.A4APR8N001', '=', 'cnv.R652SEQ') + ->leftJoin(self::CARTON_TABLE_ALIAS, 'p.R659BOX', '=', 'c.AYINTBOX') + ->leftJoin(self::CONVEYOR_VALUE_ALIAS, 'c.AYMACPKR', '=', 'cv.A4MACPKR') + ->leftJoin(self::CONVEYOR_TABLE_ALIAS, 'cv.A4APR8N001', '=', 'cnv.R652SEQ') ->where('p.R659PALT', $R659PALT) ->where('p.R659CO', trim($userWhsCoPlant['USERCO'])) ->where('p.R659WHS', trim($userWhsCoPlant['USERWHS'])) diff --git a/Modules/M3/Http/Controllers/OrderLinesOfClosedOrder.php b/Modules/M3/Http/Controllers/OrderLinesOfClosedOrder.php index 61c812fb..30b1a0eb 100644 --- a/Modules/M3/Http/Controllers/OrderLinesOfClosedOrder.php +++ b/Modules/M3/Http/Controllers/OrderLinesOfClosedOrder.php @@ -13,6 +13,8 @@ use Str; class OrderLinesOfClosedOrder extends Controller { + private const XLSX_EXTENSION = '.xlsx'; + public static function index(Request $request) { $IC670M = $ICM688M2 = []; @@ -202,7 +204,7 @@ class OrderLinesOfClosedOrder extends Controller // Download Excel // Add true at the end to include fields names in the Header - return app(SpreadsheetExport::class)->download($ICM688M2Col, 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '.xlsx'); + return app(SpreadsheetExport::class)->download($ICM688M2Col, 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . self::XLSX_EXTENSION); // return $ICM688M2Col->downloadExcel('Closedorderlinesreport_'.$reportDateWD.'-'.$toreportDateWD.'.csv',\Maatwebsite\Excel\Excel::CSV,false); } catch (\Throwable $th) { Log::error($th); @@ -302,9 +304,9 @@ class OrderLinesOfClosedOrder extends Controller } if ($WHS == '321') { - $prevMonthFile = 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '.xlsx'; + $prevMonthFile = 'Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . self::XLSX_EXTENSION; } else { - $prevMonthFile = $WHS . '/Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '-' . $WHS . '.xlsx'; + $prevMonthFile = $WHS . '/Closedorderlinesreport_' . $reportDateWD . '-' . $toreportDateWD . '-' . $WHS . self::XLSX_EXTENSION; } // MAK Store the File to Storage diff --git a/Modules/M3/Http/Controllers/execSummaryLineController.php b/Modules/M3/Http/Controllers/execSummaryLineController.php index 49fb879b..a5af7a84 100644 --- a/Modules/M3/Http/Controllers/execSummaryLineController.php +++ b/Modules/M3/Http/Controllers/execSummaryLineController.php @@ -9,6 +9,10 @@ use Str; class execSummaryLineController extends Controller { + private const FIRST_DAY_THIS_MONTH = 'first day of this month'; + private const LAST_DAY_THIS_MONTH = 'last day of this month'; + private const ONE_YEAR_AGO = '-1 year'; + public static function index(Request $request) { try { @@ -82,12 +86,12 @@ class execSummaryLineController extends Controller $firstDay = isset($request->REPORTDATE) ? \DateTime::createFromFormat('Y-m', $request->REPORTDATE) : null; $lastDay = (clone $firstDay); - $reportDate = $firstDay->modify('-11 months')->modify('first day of this month')->format('Ymd'); // - $toreportDate = $lastDay ? $lastDay->modify('last day of this month')->format('Ymd') : ''; + $reportDate = $firstDay->modify('-11 months')->modify(self::FIRST_DAY_THIS_MONTH)->format('Ymd'); // + $toreportDate = $lastDay ? $lastDay->modify(self::LAST_DAY_THIS_MONTH)->format('Ymd') : ''; // Last Year Dates // Same period, but for Last Year (LY) - $reportDateLY = (clone $firstDay)->modify('-1 year')->modify('first day of this month')->format('Ymd'); - $toreportDateLY = (clone $lastDay)->modify('-1 year')->modify('last day of this month')->format('Ymd'); + $reportDateLY = (clone $firstDay)->modify(self::ONE_YEAR_AGO)->modify(self::FIRST_DAY_THIS_MONTH)->format('Ymd'); + $toreportDateLY = (clone $lastDay)->modify(self::ONE_YEAR_AGO)->modify(self::LAST_DAY_THIS_MONTH)->format('Ymd'); // Build SQL $selectContent = "with tempfile as ( @@ -121,12 +125,12 @@ class execSummaryLineController extends Controller case 'custom': // Set Dates based on reportPeriod type $firstDay = isset($request->REPORTDATE) ? \DateTime::createFromFormat('Y-m', $request->REPORTDATE) : ''; - $reportDate = $firstDay->modify('first day of this month')->format('Ymd'); - $toreportDate = $firstDay->modify('last day of this month')->format('Ymd'); + $reportDate = $firstDay->modify(self::FIRST_DAY_THIS_MONTH)->format('Ymd'); + $toreportDate = $firstDay->modify(self::LAST_DAY_THIS_MONTH)->format('Ymd'); // Last Year Dates - $reportDateLY = (clone $firstDay)->modify('-1 year')->modify('first day of this month')->format('Ymd'); - $toreportDateLY = (clone $firstDay)->modify('-1 year')->modify('last day of this month')->format('Ymd'); + $reportDateLY = (clone $firstDay)->modify(self::ONE_YEAR_AGO)->modify(self::FIRST_DAY_THIS_MONTH)->format('Ymd'); + $toreportDateLY = (clone $firstDay)->modify(self::ONE_YEAR_AGO)->modify(self::LAST_DAY_THIS_MONTH)->format('Ymd'); // Build SQL $selectContent = "with tempfile as ( diff --git a/Modules/M3/Http/Controllers/userControlController.php b/Modules/M3/Http/Controllers/userControlController.php index 3d1b345a..f45edd44 100644 --- a/Modules/M3/Http/Controllers/userControlController.php +++ b/Modules/M3/Http/Controllers/userControlController.php @@ -11,6 +11,12 @@ use Modules\M3\Services\PostgresProgramBridge; class userControlController extends Controller { + private const AUTH_FAILURE_MESSAGE = 'Could not connect due to wrong user or password.'; + private const DATABASE_NOT_FOUND_MESSAGE = 'Database not found. Try WRKRDBDIRE to check.'; + private const CONNECTION_ERROR_PREFIX = 'Could not connect. Error: '; + private const PROGRAM_ERROR_PREFIX = 'Error calling program. Code: '; + private const MESSAGE_SEPARATOR = ' Msg: '; + public static function index(Request $request) { $connection = config('m3.connection', 'pgsql'); @@ -85,17 +91,17 @@ class userControlController 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 = self::AUTH_FAILURE_MESSAGE; return 'error profile3'; break; case 42705: - $PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.'; + $PGMERRORS = self::DATABASE_NOT_FOUND_MESSAGE; return 'error profile4'; break; default: - $PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg; + $PGMERRORS = self::CONNECTION_ERROR_PREFIX . $code . ' ' . $msg; return 'error profile5'; break; @@ -112,7 +118,7 @@ class userControlController extends Controller // # $result = $conn->PgmCall(Config::get('eproconf.misc.PGM1'), Config::get('eproconf.misc.libname4'), $params, array(), array()); $result = $conn->PgmCall('ICMUSRPRF', 'EWOBJ', $params, [], []); if (! $result) { - $PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg(); + $PGMERRORS = self::PROGRAM_ERROR_PREFIX . $conn->getErrorCode() . self::MESSAGE_SEPARATOR . $conn->getErrorMsg(); // echo ""; return 'error profile2'; @@ -200,13 +206,13 @@ class userControlController 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 = self::AUTH_FAILURE_MESSAGE; break; case 42705: - $PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.'; + $PGMERRORS = self::DATABASE_NOT_FOUND_MESSAGE; break; default: - $PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg; + $PGMERRORS = self::CONNECTION_ERROR_PREFIX . $code . ' ' . $msg; break; } } @@ -240,7 +246,7 @@ class userControlController extends Controller $result = $conn->PgmCall('ICMCHGPRF', 'EWOBJ', $params, [], []); if (! $result) { - $PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg(); + $PGMERRORS = self::PROGRAM_ERROR_PREFIX . $conn->getErrorCode() . self::MESSAGE_SEPARATOR . $conn->getErrorMsg(); // dump($PGMERRORS); echo ""; @@ -302,13 +308,13 @@ class userControlController 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 = self::AUTH_FAILURE_MESSAGE; break; case 42705: - $PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.'; + $PGMERRORS = self::DATABASE_NOT_FOUND_MESSAGE; break; default: - $PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg; + $PGMERRORS = self::CONNECTION_ERROR_PREFIX . $code . ' ' . $msg; break; } } @@ -325,7 +331,7 @@ class userControlController extends Controller // echo ""; if (! $result) { - $PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg(); + $PGMERRORS = self::PROGRAM_ERROR_PREFIX . $conn->getErrorCode() . self::MESSAGE_SEPARATOR . $conn->getErrorMsg(); dump($PGMERRORS); echo ""; diff --git a/Modules/M3/Http/Middleware/BasicAuth.php b/Modules/M3/Http/Middleware/BasicAuth.php index 05a02d92..7dc997d3 100644 --- a/Modules/M3/Http/Middleware/BasicAuth.php +++ b/Modules/M3/Http/Middleware/BasicAuth.php @@ -4,69 +4,54 @@ namespace Modules\M3\Http\Middleware; use Closure; use Illuminate\Http\Request; +use Symfony\Component\HttpFoundation\Response; class BasicAuth { - /** - * Handle an incoming request. - * - * @param Request $request - * @param Closure $next - * - * @return mixed - */ - public function handle(Request $request, Closure $next) + public function handle(Request $request, Closure $next): mixed { + $login = trim((string) m3_user()); + $password = (string) m3_legacy_password(); - // select md5 or crypt for $mode. md5 is for md5 encoded passwords, crypt is for passwords encoded using apache's httpasswd - $mode = 'crypt'; - if (! m3_user() !== '') { - $this->authenticate(); - } else { - if ($this->check_pass(m3_user(), m3_legacy_password(), $mode, '%%SYSTEM%%')) { - return $next($request); - } else { - $this->authenticate(); - } + if ($login !== '' && $this->checkPassword($login, $password, '%%SYSTEM%%')) { + return $next($request); } + return $this->unauthorized(); } - public static function check_pass($login, $password, $mode, $password_file) + private function checkPassword(string $login, string $password, string $passwordFile): bool { - if (! $fh = fopen($password_file, 'r')) { - exit('
Could Not Open Password File'); + if (! is_readable($passwordFile)) { + return false; } - $match = 0; - while (! feof($fh)) { - $line = fgets($fh, 4096); - $from_file = explode(':', $line); - if ($from_file[0] == $login) { - if ($mode == 'crypt') { - $salt = substr($from_file[1], 0, 2); - $user_pass = crypt($password, $salt); - } elseif ($mode == 'md5') { - $user_pass = md5($password); - } - if (rtrim($from_file[1]) == $user_pass) { - $match = 1; - break; + + $handle = fopen($passwordFile, 'rb'); + if ($handle === false) { + return false; + } + + try { + while (($line = fgets($handle)) !== false) { + $parts = explode(':', trim($line), 2); + if (count($parts) !== 2 || ! hash_equals($parts[0], $login)) { + continue; } + + $storedHash = trim($parts[1]); + + return $storedHash !== '' && password_verify($password, $storedHash); } + } finally { + fclose($handle); } - if ($match) { - return 1; - } else { - return 0; - } - fclose($fh); + + return false; } - public static function authenticate() + private function unauthorized(): Response { - header('WWW-Authenticate: Basic realm="RESTRICTED ACCESS"'); - header('HTTP/1.0 401 Unauthorized'); - echo '