181 lines
8.5 KiB
PHP
Executable File
181 lines
8.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\M3\Http\Controllers;
|
|
|
|
use Config;
|
|
use DB;
|
|
use File;
|
|
use Illuminate\Http\Request;
|
|
use Str;
|
|
|
|
class M3GetPDFFromCacheController extends Controller
|
|
{
|
|
public static function index(Request $request)
|
|
{
|
|
// Parse PDF file and build necessary objects.
|
|
|
|
$aggno = $aggmsg = '';
|
|
$iC670M = $pDFArray = $carrier = $trackingno = $iCM688M1 = [];
|
|
$aYMACPKR = $wHDDA = $cOMPANY = $pLANT = $wHS = '';
|
|
|
|
// PDF File PATH
|
|
$pdfFilePath = Config::get('arrays.PdfPath');
|
|
try {
|
|
// Initialise Vars
|
|
$pDFArray = $trackingno = $carrier = $iCM688M1 = [];
|
|
|
|
$sHUSER = m3User() !== '' ? Str::upper(trim(m3User())) : '';
|
|
|
|
if ($sHUSER != '') {
|
|
// Get User CO & WH
|
|
// Get user from 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
|
|
}
|
|
|
|
// Warehouse Table
|
|
$iC670M = DB::connection(config('m3.connection', 'pgsql'))->table('ic670m')->get();
|
|
// ->where('WDCO',$userCO)->where('WDPL',$userPL)->where('WDWHS',$userWH)
|
|
|
|
// Get URL PARAMS
|
|
$urlParams = count($request->all()) > 0 ? $request->all() : '';
|
|
// dump($urlParams);
|
|
$aYMACPKR = isset($urlParams['MACPKR']) ? trim($urlParams['MACPKR']) : ''; // Delivery note number
|
|
$dOCTYPE = isset($urlParams['DOCTYPE']) ? trim($urlParams['DOCTYPE']) : ''; // Document type (PackingList, CarrierLabel, ContentLabel)
|
|
$wHDDA = $cOMPANY . $pLANT . $wHS;
|
|
|
|
// Check Doctype fisrt
|
|
$docTypes = $dOCTYPE != '' ? [$dOCTYPE] : ['PackingList', 'ContentLabel', 'CarrierLabel', 'GSLabel']; // document type (PackingList, CarrierLabel, ContentLabel)
|
|
|
|
if ($urlParams != '') {
|
|
// dump($urlParams);
|
|
// document number (ie the internal box number, the pick list number)
|
|
// Key Combination : COMPANY WHS A4MACPKR DOCTYPE DOCNUM
|
|
// Document type (PackingList, CarrierLabel, ContentLabel)
|
|
|
|
// Get Aggregation Number if it exists
|
|
$iCM695M1Agg = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m1')
|
|
->select('AYTRUCK')
|
|
->where('AYCO', $cOMPANY)
|
|
->where('AYWHS', $wHS)
|
|
->where('AYMACPKR', $aYMACPKR)
|
|
->first();
|
|
$aggno = isset($iCM695M1Agg->AYTRUCK) ? trim($iCM695M1Agg->AYTRUCK) : '';
|
|
|
|
if ($aggno != '' && $aggno != '0') {
|
|
|
|
$aggmsg = "This delivery note is part of aggregation $aggno ";
|
|
$iCM688M1 = DB::connection(config('m3.connection', 'pgsql'))->select("select A4MACPKR from ICM688M1 where A4SHPAGGCD='$aggno'");
|
|
|
|
// 654 add 'AYSPR15A01', 'AYSPR30A01', 'AYTRUCK' carrier and tracking# and agg#
|
|
$iCM695M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m1')
|
|
->select('AYCO', 'AYWHS', 'AYMACPKR', 'AYINTBOX', 'AYSPR15A01', 'AYSPR30A01', 'AYTRUCK')
|
|
->distinct()
|
|
->where('AYCO', $cOMPANY)
|
|
->where('AYWHS', $wHS)
|
|
// ->where('AYMACPKR',$aYMACPKR)
|
|
->where('AYTRUCK', $aggno)
|
|
->orderBy('AYMACPKR')
|
|
->get();
|
|
} else {
|
|
// 654 add 'AYSPR15A01', 'AYSPR30A01', 'AYTRUCK' carrier and tracking# and agg#
|
|
$iCM695M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm695m1')
|
|
->select('AYCO', 'AYWHS', 'AYMACPKR', 'AYINTBOX', 'AYSPR15A01', 'AYSPR30A01', 'AYTRUCK')
|
|
->distinct()
|
|
->where('AYCO', $cOMPANY)
|
|
->where('AYWHS', $wHS)
|
|
->where('AYMACPKR', $aYMACPKR)
|
|
->orderBy('AYMACPKR')
|
|
->get();
|
|
}
|
|
|
|
if (count($iCM695M1) > 0) {
|
|
$tmpCacheArr = $carrier = $trackingno = [];
|
|
// Loop the Results from $ICM595M1TMP
|
|
foreach ($iCM695M1 as $ICM695M1R) {
|
|
$wHS = trim($ICM695M1R->AYWHS);
|
|
$cOMPANY = trim($ICM695M1R->AYCO);
|
|
$aYMACPKR = trim($ICM695M1R->AYMACPKR);
|
|
$dOCNUM = trim($ICM695M1R->AYINTBOX);
|
|
// 654
|
|
$carrier[] = trim($ICM695M1R->AYSPR15A01);
|
|
$trackingno[] = trim($ICM695M1R->AYSPR30A01);
|
|
$aggno = trim($ICM695M1R->AYTRUCK);
|
|
|
|
// Make Key and Test Validity
|
|
if ($aYMACPKR != '' && $cOMPANY != '' && $wHS != '') {
|
|
$contentLabel = '';
|
|
|
|
// Get Unique Keys
|
|
foreach ($docTypes as $value) {
|
|
// Check Parcel vs LTL
|
|
if ($value == 'ContentLabel') {
|
|
$dOCNUMT = $dOCNUM;
|
|
$contentLabel = ! is_numeric($dOCNUM) ? 'LTL' : '';
|
|
}
|
|
|
|
if ($value == 'CarrierLabel') {
|
|
$dOCNUMT = $dOCNUM;
|
|
|
|
// Keep Solon Logic to read LTL
|
|
$dOCNUMT2 = $contentLabel == 'LTL' ? $aYMACPKR : $dOCNUM;
|
|
if ($dOCNUMT2 != $dOCNUMT) {
|
|
$pDFKey2 = $value . '/' . $value . '_' . $aYMACPKR . '_' . $dOCNUMT2 . '_' . $cOMPANY . '_' . $wHS;
|
|
$tmpCacheArr[] = $pDFKey2;
|
|
}
|
|
}
|
|
|
|
if ($value == 'PackingList') {
|
|
$dOCNUMT = $aYMACPKR;
|
|
}
|
|
|
|
// Get GS1 Labels
|
|
if ($value == 'GSLabel') {
|
|
$pDFKey = $value . '/' . $value . '_' . $aYMACPKR . '_' . $cOMPANY . '_' . $wHS . '_' . $dOCNUM;
|
|
|
|
// $pDFKey = $value.'/'.$value.'_'.$aYMACPKR.'_'.$cOMPANY.'_'.$wHS;
|
|
// }
|
|
// else{
|
|
// $pDFKey = $value.'/'.$value.'_'.$aYMACPKR.'_'.$cOMPANY.'_'.$wHS.'_'.$dOCNUM;
|
|
// }
|
|
} else {
|
|
$pDFKey = $value . '/' . $value . '_' . $aYMACPKR . '_' . $dOCNUMT . '_' . $cOMPANY . '_' . $wHS;
|
|
}
|
|
$tmpCacheArr[] = $pDFKey;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get unique values from array $pDFArray
|
|
$tmpCacheArr = collect($tmpCacheArr)->unique();
|
|
foreach ($tmpCacheArr as $value) {
|
|
|
|
$pdfFileName = $pdfFilePath . $value . '.pdf';
|
|
if (File::exists($pdfFileName)) {
|
|
|
|
$pdfFile = File::get($pdfFileName);
|
|
// Transform content to base64
|
|
// $base64PDF = $pdfFile;
|
|
$base64PDF = base64_encode($pdfFile);
|
|
$pDFArray[] = $base64PDF;
|
|
}
|
|
}
|
|
} else {
|
|
// Nothing Found
|
|
}
|
|
}
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
}
|
|
|
|
return view('m3::liberty-theme.pages.M3GetPDF', ['IC670M' => $iC670M, 'PDFArray' => $pDFArray, 'AYMACPKR' => $aYMACPKR, 'WHDDA' => $wHDDA, 'aggmsg' => $aggmsg, 'carrier' => $carrier, 'trackingno' => $trackingno, 'ICM688M1' => $iCM688M1, 'COMPANY' => $cOMPANY, 'PLANT' => $pLANT, 'WHS' => $wHS]);
|
|
// compact('IC670M','ViewTitle')
|
|
}
|
|
}
|