647 lines
26 KiB
PHP
647 lines
26 KiB
PHP
<?php
|
|
|
|
namespace Modules\M3\Http\Controllers;
|
|
use DB;
|
|
// use Symfony\Component\HttpFoundation\Request;
|
|
use Smalot\PdfParser\Parser;
|
|
use File;
|
|
use Cache;
|
|
use DateTime;
|
|
use Config;
|
|
use Artisan;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Ayeo\Barcode;
|
|
use PDF;
|
|
use Log;
|
|
use Http;
|
|
use Picqer\Barcode\BarcodeGeneratorPNG;
|
|
use Dompdf\Dompdf;
|
|
|
|
use Zebra\Client;
|
|
use Zebra\Zpl\Image;
|
|
use Zebra\Zpl\Builder;
|
|
use Zebra\Zpl\GdDecoder;
|
|
|
|
use Modules\M3\Http\Controllers\GetContentsController;
|
|
|
|
class utilitiesContoller extends Controller
|
|
{
|
|
public static function index(Request $request)
|
|
{
|
|
dd("SentM3Test");
|
|
|
|
// Get The Next ID by Calling POM002C
|
|
$PGMERRORS = '';
|
|
$AWREQN = '';
|
|
|
|
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
|
|
try {
|
|
$conn = app(\Modules\M3\Services\PostgresProgramBridge::class);
|
|
} catch (Exception $e) {
|
|
// Determine reason for failure.
|
|
// Probably database authentication error or invalid or unreachable database.
|
|
$code = $e->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(array('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 = [];
|
|
// $params[] = $conn->AddParameterChar('out',7,'eqNumber');
|
|
|
|
// 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');
|
|
|
|
// $params[] = $conn->AddParameterZoned('in', 11, 0, 'ParamIn');
|
|
|
|
// 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, array(), array());
|
|
|
|
if (!$result) {
|
|
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
|
|
}
|
|
// Successful Call
|
|
else {
|
|
dump($result);
|
|
// $AWREQN = $result['io_param']["var0"];
|
|
}
|
|
|
|
if ($PGMERRORS != "") {
|
|
// return back()->withMessage('Can not Create PR: '.$PGMERRORS);
|
|
dump($PGMERRORS);
|
|
} else {
|
|
// return $AWREQN;
|
|
}
|
|
// 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 \Smalot\PdfParser\Parser();
|
|
|
|
// $pdf = $parser->parseFile('/www/sentm3test/htdocs/labels/E1232824-10826596.pdf');
|
|
// dump($pdf);
|
|
// $text = $pdf->getText();
|
|
// dump("Text Only");
|
|
// dump($text);
|
|
|
|
// $pdfFile = file_get_contents('/www/sentm3test/htdocs/labels/E1232824-10826596.pdf');
|
|
$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();
|
|
|
|
// $counter=0;
|
|
foreach ($ICM688M2SLTMP as $key => $ICM688M2SL) {
|
|
// $counter++;
|
|
// $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();
|
|
// dump($GSArray);
|
|
|
|
$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 = '
|
|
<html>
|
|
<head>
|
|
<style>
|
|
.border_btm {
|
|
border-bottom: 1px solid;
|
|
}
|
|
.border_rght {
|
|
border-right: 1px solid;
|
|
}
|
|
|
|
.margin_t {
|
|
padding-top : 10px;
|
|
}
|
|
|
|
.align_lft {
|
|
text-align: left;
|
|
}
|
|
.align_center {
|
|
text-align: center;
|
|
}
|
|
|
|
@page { margin: 5px; }
|
|
body { margin: 0px; }
|
|
</style>
|
|
</head>
|
|
<body style="font-family: Arial, sans-serif;">';
|
|
|
|
# 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"] . '<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',
|
|
'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 .= '
|
|
<table ' . $table_style . '>
|
|
<tr>
|
|
<td colspan="2" class="border_btm border_rght align_lft">
|
|
FROM:<br>' . $data['from'] . '
|
|
</td>
|
|
<td colspan="2" class="border_btm align_lft">
|
|
SHIP TO:<br>' . $data['ship_to'] . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="3" class="border_btm border_rght margin_t align_center">
|
|
<img src="data:image/png;base64,' . base64_encode($shipToPostalCodeBarcode) . '"> <br>
|
|
' . $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 . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" class="border_btm margin_t align_lft">
|
|
PURCHASE ORDER: ' . $GSArray["ShipmentPONumber"] . ' <br>
|
|
Vendor: ' . $manufactID . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" class="border_btm margin_t align_center">
|
|
' . $packageTypeDesc . ' # : ' . $packageNum . ' of ' . $packageCount . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" style="text-align: center;" class="margin_t">
|
|
<img src="data:image/png;base64,' . base64_encode($serialShippingContainerBarcode) . '"><br>
|
|
' . $data['serial_shipping_container'] . '
|
|
</td>
|
|
</tr>
|
|
</table>';
|
|
|
|
$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 .= '</body> </html>';
|
|
// dump($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();
|
|
// dump($pdfContent);
|
|
|
|
$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]);
|
|
|
|
// Log::channel('LabelCron')->info("<<< GS1-128...End of Label Creation for Mackpkr: ".$Macpkr);
|
|
|
|
return json_encode(["result" => "success", "GS1File" => $GS1FileNameNoRoot]);
|
|
|
|
} catch (\Throwable $th) {
|
|
// Log::error($th);
|
|
Log::channel('LabelCron')->error($th);
|
|
return json_encode(["result" => "error", "GS1File" => $th]);
|
|
|
|
}
|
|
}
|
|
|
|
public static function generateGS128Tst(Request $request)
|
|
{
|
|
print_r(">>> Generate PDF");
|
|
|
|
// $builder = new Barcode\Builder();
|
|
// $image = $builder->output('(10)123456(400)11(3906)333333');
|
|
|
|
// $builder = new Barcode\Builder();
|
|
// $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<br>123 Any Street<br>SomeTown, ST 01234',
|
|
'ship_to' => 'True Value Hardware<br>123 Any Street<br>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 = '
|
|
<html>
|
|
<style>
|
|
.border_btm {
|
|
border-bottom: 1px solid;
|
|
}
|
|
.border_rght {
|
|
border-right: 1px solid;
|
|
}
|
|
|
|
.margin_t {
|
|
padding-top : 10px;
|
|
}
|
|
|
|
.align_lft {
|
|
text-align: left;
|
|
}
|
|
|
|
@page { margin: 5px; }
|
|
body { margin: 0px; }
|
|
</style>
|
|
</head>
|
|
<body style="font-family: Arial, sans-serif;">
|
|
<table class="table">
|
|
<tr>
|
|
<td colspan="2" class="border_btm border_rght align_lft">
|
|
FROM:<br>' . $data['from'] . '
|
|
</td>
|
|
<td colspan="2" class="border_btm align_lft">
|
|
SHIP TO:<br>' . $data['ship_to'] . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" class="border_btm border_rght margin_t align_lft">
|
|
<img src="data:image/png;base64,' . base64_encode($shipToPostalCodeBarcode) . '"><br>
|
|
(' . $data['ship_to_postal_code'] . ')
|
|
</td>
|
|
<td colspan="2" class="border_btm margin_t align_lft">
|
|
Carrier Routing(SCAC) <br>
|
|
PRO #: <br>
|
|
B/L # :
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" style="text-align: center;" class="border_btm margin_t">
|
|
PURCHASE ORDER: PO1234567 <br>
|
|
<img src="data:image/png;base64,' . base64_encode($proBarcode) . '"><br>
|
|
PRO: ' . $data['pro'] . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" style="text-align: left;" class="border_btm margin_t">
|
|
ITEM #: ' . $data['item_number'] . '<br>
|
|
UPC: ' . $data['upc'] . '<br>
|
|
QUANTITY: ' . $data['quantity'] . '
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" style="text-align: center;" class="margin_t">
|
|
<img src="data:image/png;base64,' . base64_encode($serialShippingContainerBarcode) . '"><br>
|
|
' . $data['serial_shipping_container'] . '
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</body>
|
|
</html>';
|
|
|
|
// return ($html);
|
|
|
|
// 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) {
|
|
// throw new Exception('PDF generation failed.');
|
|
// }
|
|
|
|
# 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();
|
|
// dd($responseData);
|
|
// $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);
|
|
}
|
|
|
|
}
|
|
}
|