$e]); return response()->json(['error' => 'Program bridge connection failed.'], 503); } $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) { dump($result); } // 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. $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 $ICM688M2SL) { $a5MACPKR = isset($ICM688M2SL->A5MACPKR) ? $ICM688M2SL->A5MACPKR : ''; $a5SENTPKR = isset($ICM688M2SL->A5SENTPKR) ? $ICM688M2SL->A5SENTPKR : ''; dump('ICM688M2 Record: ' . $a5MACPKR . '-' . $a5SENTPKR); 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(); $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 $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 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 // 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'); $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(); $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); } } }