getCode(); $msg = $e->getMessage(); switch ($code) { 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.'; break; case 42705: $PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.'; break; default: $PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg; break; } } $conn->setOptions(['persistent' => false, 'stateless' => true, 'debug' => true, 'debugLogFile' => '/www/sentustesx/htdocs/storage/logs/toolkit_debug.log']); // Add LIB // $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)'); // define several input/output params $params = []; // AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension) // Add Warehouse Param $params[] = $conn->AddParameterChar('in', 3, 'eqNumber', '', '111'); // AddParameterPackDec($io, $length, $scale, $comment, $varName, $value,$dimension) // Add Delivery Note Param $params[] = $conn->AddParameterPackDec('in', 11, 0, 'ParamIn', '', '00000087125'); // Start Time Tracking $start = microtime(true); dump('Calling: EWOBJTST/ICM700C'); // Config::get('eproconf.misc.PGM1'), Config::get('eproconf.misc.libname4') // ICM700C EWOBJTST ICM700C ICM700CSBM $result = $conn->PgmCall('ICM700CSBM', 'EWOBJTST', $params, [], []); if (! $result) { $PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg(); } // Successful Call else { dump($result); } if ($PGMERRORS != '') { dump($PGMERRORS); } else { } // Get Execution Time $time = microtime(true) - $start; dump($time); } public static function pdfReadWrite(Request $request) { dump('PDF Read Write'); $pdfFileName = 'E1232824-10826596'; // Parse PDF file and build necessary objects. $parser = new Parser; // dump($pdf); // $text = $pdf->getText(); // dump("Text Only"); // dump($text); $pdfFile = File::get('/www/sentm3test/htdocs/labels/' . $pdfFileName . '.pdf'); // Transform content to base64 $base64PDF = base64_encode($pdfFile); // Output base64 string // dump($base64PDF); // Save Cache Cache::put($pdfFileName, $base64PDF, now()->addMinutes(60)); // Retrieve Cache $cachedPdfFile = Cache::get($pdfFileName); dump('Retrieve Base64 Encoded PDF saved in Cache:'); dump($cachedPdfFile); // remove File from Cache // Cache::put(pdfFileName, 'value', -5); // Cache::forget($pdfFileName); // Base64 Decode and Display // $pdf = $parser->parseContent(base64_decode($base64PDF)); // $text = $pdf->getText(); // dump($text); } public static function fixICM799MSentPKR(Request $request) { ini_set('max_execution_time', Config::get('arrays.PHPTimeOutCL')); ini_set('max_input_time', Config::get('arrays.PHPTimeOutCL')); ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOutCL')); ini_set('memory_limit', '1024M'); dump('Run Fix IMSENTPKR...'); $SHUSER = 'TWOSHIP'; // Get User CO & WH // Get users from ICM428M $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') ->select('R428US', 'R428CO', 'R428WH') ->where('R428US', '=', $SHUSER) ->first(); $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') ->select('A5MACPKR', 'A5SENTPKR', 'A5PICKSTRD') ->distinct() ->where('A5CO', $DIVI) ->where('A5WHS', $WHS) ->where('A5PICKSTRD', '!=', '0') ->orderBy('A5PICKSTRD', 'ASC') ->get(); foreach ($ICM688M2SLTMP as $key => $ICM688M2SL) { // $counter == 10 ? exit : ''; $A5MACPKR = isset($ICM688M2SL->A5MACPKR) ? $ICM688M2SL->A5MACPKR : ''; $A5SENTPKR = isset($ICM688M2SL->A5SENTPKR) ? $ICM688M2SL->A5SENTPKR : ''; dump('ICM688M2 Record: ' . $A5MACPKR . '-' . $A5SENTPKR); $ICM799MINS = DB::connection(config('m3.connection', 'pgsql'))->table('icm799m') ->where('IMDELNO', '=', $A5MACPKR) ->update(['IMSENTPKR' => $A5SENTPKR]); } } // Generate GS1-128 public static function generateGS128(Request $request) { ini_set('max_execution_time', Config::get('arrays.PHPTimeOutCL')); ini_set('max_input_time', Config::get('arrays.PHPTimeOutCL')); ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOutCL')); ini_set('memory_limit', '1024M'); try { Log::channel('LabelCron')->info('>>> Run GS1 Label creation Command...'); // Get the Calling User // $userId = 'TWOSHIP'; // $SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : ''); // Get Manifest Array $GSArray = $request->query(); $SHUSER = isset($GSArray['User']) ? trim($GSArray['User']) : ''; if ($SHUSER != '') { // Get User CO & WH from Table ICM428M $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') ->select('R428US', 'R428CO', 'R428WH', 'R428PL') ->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 $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; $html = ' '; // Get number of Pallets $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; // Loop PackagesArray : Build Table for PDF and Insert to ICM695m3 foreach ($GSArray['PackagesArray'] as $key => $value) { $table_style = $packageNum < $packageCount ? ' style="page-break-after: always;" ' : ''; $A2INTBOX = trim($value); $GS1SEQUENCE++; $GS1SEQUENCEID = str_pad($GS1SEQUENCE, $total_length, '0', STR_PAD_LEFT); // Build GS1 18 Digits Code $gs1_128_bc_1 = '00' . $packageType . $manufactID . $GS1SEQUENCEID; // Calculate Check Digit $digits = str_split($gs1_128_bc_1); $sum = 0; $length = count($digits); // Loop through each digit starting from the right for ($i = 0; $i < $length; $i++) { $digit = $digits[$length - $i - 1]; // Assign a weight of 3 or 1 alternately $weight = ($i % 2 == 0) ? 3 : 1; // Add the product of the digit and its weight to the sum $sum += $digit * $weight; } // Calculate the remainder when sum is divided by 10 $remainder = $sum % 10; // If remainder is 0, check digit is 0; otherwise, subtract remainder from 10 $checkDigit = ($remainder == 0) ? 0 : 10 - $remainder; // End Check Digit Calculation // SSCC 18 Digits Code $gs1_128_bc = $gs1_128_bc_1 . $checkDigit; $gs1_128_bc_desc = '(00)' . $packageType . $manufactID . $GS1SEQUENCEID . $checkDigit; $data = [ 'ship_to' => $GSArray['Recipient_CompanyName'] . '
' . $GSArray['Recipient_Address1'] . '
' . $GSArray['Recipient_City'] . ',' . $GSArray['Recipient_State'] . '
' . $GSArray['Recipient_PostalCode'], 'from' => $GSArray['Sender_CompanyName'] . '
' . $GSArray['Sender_Address1'] . '
' . $GSArray['Sender_City'] . ',' . $GSArray['Sender_State'] . '
' . $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', 'quantity' => '1', 'serial_shipping_container' => $gs1_128_bc_desc, ]; // Initialize barcode generator $generator = new BarcodeGeneratorPNG; // Generate barcodes $shipToPostalCodeBarcode = $generator->getBarcode($data['ship_to_lbl'], $generator::TYPE_CODE_128); $serialShippingContainerBarcode = $generator->getBarcode($data['serial_shipping_container'], $generator::TYPE_CODE_128, 2, 50); // HTML content for the label $html .= '
FROM:
' . $data['from'] . '
SHIP TO:
' . $data['ship_to'] . '

' . $data['ship_to_desc'] . '
Carrier: ' . $GSArray['CarrierName'] . '
PRO #: ' . $GSArray['trackingno'] . '
B/L #: ' . $GSArray['BOLnumber'] . '
Ref : ' . $A2INTBOX . '
PURCHASE ORDER: ' . $GSArray['ShipmentPONumber'] . '
Vendor: ' . $manufactID . '
' . $packageTypeDesc . ' # : ' . $packageNum . ' of ' . $packageCount . '

' . $data['serial_shipping_container'] . '
'; $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]); Log::channel('LabelCron')->info('<<< GS1-128...End of Label Creation for Mackpkr: ' . $Macpkr); } $html .= ' '; ob_start(); // Initialize Dompdf $dompdf = new Dompdf; $dompdf->loadHtml($html); $dompdf->setPaper('a6', 'portrait'); // Render the HTML as PDF $dompdf->render(); // Output the generated PDF to Browser // $dompdf->stream(); $pdfContent = $dompdf->output(); $labelsPath = Config::get('arrays.PdfPath'); // '/www/sentm3live/htdocs/labels/'; // Put the PDF in labels/CarrierLabel $GSFolder = 'GSLabel'; $carrierFileName = $GSFolder . '_' . $Macpkr . '_' . $COMPANY . '_' . $WHS . '_' . $A2INTBOX; // LTL // if ($packageType=='1') { // $carrierFileName = $GSFolder.'_'.$Macpkr.'_'.$COMPANY.'_'.$WHS; // } // # small Packs // else{ // $carrierFileName = $GSFolder.'_'.$Macpkr.'_'.$COMPANY.'_'.$WHS.'_'.$A2INTBOX; // } $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]); return json_encode(['result' => 'success', 'GS1File' => $GS1FileNameNoRoot]); } catch (\Throwable $th) { Log::channel('LabelCron')->error($th); return json_encode(['result' => 'error', 'GS1File' => $th]); } } public static function generateGS128Tst(Request $request) { print_r('>>> Generate PDF'); // $image = $builder->output('(10)123456(400)11(3906)333333'); // $builder->setBarcodeType('gs1-128'); // $builder->setFilename('barcode.png'); // $builder->setImageFormat('png'); // $builder->setWidth(500); // $builder->setHeight(150); // $builder->setFontPath('FreeSans.ttf'); // $builder->setFontSize(15); // $builder->setBackgroundColor(255, 255, 255); // $builder->setPaintColor(0, 0, 0); // Barcode\Builder::build()->setWidth(600)->setBackgroundColor(100, 100, 100)->output('(10)123456(400)11'); // return response($image)->header('Content-Type', 'image/png'); $data = [ 'from' => 'Any Vendor
123 Any Street
SomeTown, ST 01234', 'ship_to' => 'True Value Hardware
123 Any Street
SomeTown, ST 01234', 'ship_to_postal_code' => '42016172', 'pro' => '190071217845706', 'item_number' => '10000B', 'upc' => '098506095310', 'quantity' => '1', 'serial_shipping_container' => '(00)107904370000005', ]; // Initialize barcode generator $generator = new BarcodeGeneratorPNG; // Generate barcodes $shipToPostalCodeBarcode = $generator->getBarcode($data['ship_to_postal_code'], $generator::TYPE_CODE_128); $proBarcode = $generator->getBarcode($data['pro'], $generator::TYPE_CODE_128); $serialShippingContainerBarcode = $generator->getBarcode($data['serial_shipping_container'], $generator::TYPE_CODE_128, 2, 50); // HTML content for the label // border="1" style="border-collapse: collapse; width: 100%; height: 300px;" $html = '
FROM:
' . $data['from'] . '
SHIP TO:
' . $data['ship_to'] . '

(' . $data['ship_to_postal_code'] . ')
Carrier Routing(SCAC)
PRO #:
B/L # :
PURCHASE ORDER: PO1234567

PRO: ' . $data['pro'] . '
ITEM #: ' . $data['item_number'] . '
UPC: ' . $data['upc'] . '
QUANTITY: ' . $data['quantity'] . '

' . $data['serial_shipping_container'] . '
'; // Initialize Dompdf $dompdf = new Dompdf; $dompdf->loadHtml($html); $dompdf->setPaper('a6', 'portrait'); // Render the HTML as PDF $dompdf->render(); // Output the generated PDF to Browser // $dompdf->stream(); $pdfContent = $dompdf->output(); // // return $pdfContent; $labelsPath = '/www/sentm3live/htdocs/labels/'; // # Put the PDF in labels/CarrierLabel $GSFolder = 'GSLabel'; $carrierFileName = 'GSLabel'; 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'; // // dump($tempPdfPath); // file_put_contents($tempPdfPath, $pdfContent); // // Check if the PDF was generated correctly // if (!file_exists($tempPdfPath) || filesize($tempPdfPath) === 0) { // } // Create an Imagick instance // $imagick = new \Imagick(); // // Read the PDF from the string // // $imagick->readImageBlob( $pdfContent ); // // Read the PDF from the file // $imagick->readImage($tempPdfPath); // // Set the resolution (optional) // $imagick->setResolution(300, 300); // // Convert the first page of the PDF to an image // $imagick->setIteratorIndex(0); // $imagick->setImageFormat('png'); } public static function miscTests(Request $request) { // $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); // 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 // ESN2 // $AYMACPKR='999999'; // LTL example $AYMACPKR = '748101'; // LTL example $myRequest = new Request; $myRequest->setMethod('POST'); $myRequest->request->add([ 'MACPKR' => $AYMACPKR, ]); // Call the controller method properly $controller = new GetContentsController; $response = $controller->processShipment($myRequest); $responseData = $response->getData(); // $responseJSON = json_encode($responseData); // dump($responseJSON); $error = isset($responseData->error) ? $responseData->error : ''; if ($error == '') { // Get Commodities $commoditiesTmp = isset($responseData->commodities) ? $responseData->commodities : ''; if ($commoditiesTmp != '') { $commodities = json_encode($commoditiesTmp); dump($commodities); } else { dump('Commodities Empty...'); } } else { dump($error); } } }