220 lines
10 KiB
PHP
220 lines
10 KiB
PHP
<?php
|
|
|
|
namespace Modules\M3\Http\Controllers;
|
|
|
|
use Modules\M3\Http\Controllers\Controller;
|
|
use DB;
|
|
use Config;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
// use Datatables;
|
|
use Smalot\PdfParser\Parser;
|
|
use File;
|
|
use Cache;
|
|
use Str;
|
|
|
|
class M3GetPDFFromCacheController extends Controller
|
|
{
|
|
public static function index(Request $request){
|
|
// Parse PDF file and build necessary objects.
|
|
$parser = new \Smalot\PdfParser\Parser();
|
|
|
|
$aggno = $aggmsg = "";
|
|
$IC670M = $PDFArray = $carrier = $trackingno = $ICM688M1 = [];
|
|
$AYMACPKR = $WHDDA = $COMPANY = $PLANT = $WHS = '';
|
|
#$carrier = $trackingno = "";
|
|
|
|
# PDF File PATH
|
|
$pdfFilePath = Config::get('arrays.PdfPath');
|
|
try {
|
|
# Initialise Vars
|
|
$PDFArray = $trackingno = $carrier = $ICM688M1 = [];
|
|
|
|
$SHUSER = m3_user() !== '' ? Str::upper(trim(m3_user())) : '';
|
|
// dd($SHUSER);
|
|
|
|
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();
|
|
|
|
$R428US = isset($ICM428M->R428US) ? $ICM428M->R428US : '';
|
|
$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;
|
|
// dump($WHDDA);
|
|
|
|
# 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();
|
|
// dump($ICM695M1Agg);
|
|
$aggno = isset($ICM695M1Agg->AYTRUCK) ? trim($ICM695M1Agg->AYTRUCK) : '';
|
|
|
|
if($aggno!="" && $aggno!="0") {
|
|
// dump($aggno);
|
|
|
|
$aggmsg="This delivery note is part of aggregation $aggno ";
|
|
$ICM688M1 = DB::connection(config('m3.connection', 'pgsql'))->select("select A4MACPKR from ICM688M1 where A4SHPAGGCD='$aggno'");
|
|
#dump($ICM688M1);
|
|
// foreach($ICM688M1 as $key => $ICM688M1R) {
|
|
// $aggmsg.=' <a href="M3GetPDFFromCache?MACPKR='.$ICM688M1R->A4MACPKR.'&COMPANY='.$COMPANY.'&PLANT='.$PLANT.'&WHS='.$WHS.'">'.$ICM688M1R->A4MACPKR.'</a>';
|
|
// }
|
|
// $aggmsg.=" )";
|
|
|
|
#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();
|
|
}
|
|
#dump($ICM695M1);
|
|
|
|
$allLabels = [];
|
|
|
|
if (count($ICM695M1)>0) {
|
|
$tmpCacheArr = $carrier = $trackingno = [];
|
|
# Loop the Results from $ICM595M1TMP
|
|
foreach ($ICM695M1 as $key => $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!=''){
|
|
//echo "<script>alert('2');</script>";
|
|
$CarrierLabel = '';
|
|
$ContentLabel = '';
|
|
$PackingList = '';
|
|
$cacheKeyPackingList = $cacheKeyCarrierLabel = $cacheKeyContentLabel = '';
|
|
|
|
# Get Unique Keys
|
|
foreach ($docTypes as $key => $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;
|
|
|
|
// if ($ContentLabel=='LTL' ) {
|
|
// $PDFKey = $value.'/'.$value.'_'.$AYMACPKR.'_'.$COMPANY.'_'.$WHS;
|
|
// }
|
|
// else{
|
|
// $PDFKey = $value.'/'.$value.'_'.$AYMACPKR.'_'.$COMPANY.'_'.$WHS.'_'.$DOCNUM;
|
|
// }
|
|
}
|
|
else{
|
|
$PDFKey = $value.'/'.$value.'_'.$AYMACPKR.'_'.$DOCNUMT.'_'.$COMPANY.'_'.$WHS;
|
|
}
|
|
$tmpCacheArr[] = $PDFKey;
|
|
}
|
|
}
|
|
}
|
|
// dump($tmpCacheArr);
|
|
|
|
# Get unique values from array $PDFArray
|
|
$tmpCacheArr = collect($tmpCacheArr)->unique();
|
|
// dump($tmpCacheArr);
|
|
foreach($tmpCacheArr as $key => $value){
|
|
// $isCarrierLabel = Str::contains($value, 'CarrierLabel');
|
|
|
|
$pdfFileName = $pdfFilePath.$value.'.pdf';
|
|
if(File::exists($pdfFileName)){
|
|
// dump($pdfFileName);
|
|
|
|
$pdfFile = File::get($pdfFileName);
|
|
# Transform content to base64
|
|
// $base64PDF = $pdfFile;
|
|
$base64PDF = base64_encode($pdfFile);
|
|
// dd($base64PDF);
|
|
$PDFArray[] = $base64PDF;
|
|
}
|
|
}
|
|
// dump($PDFArray);
|
|
}
|
|
else {
|
|
# Nothing Found
|
|
}
|
|
}
|
|
}
|
|
catch (\Throwable $th) {
|
|
// Log::error($th);
|
|
}
|
|
# dump($PDFArray);
|
|
# dump($AYMACPKR);
|
|
# dump($IC670M);
|
|
# dump($ICM695M1);
|
|
|
|
return view('m3::liberty-theme.pages.M3GetPDF',compact('IC670M','PDFArray','AYMACPKR','WHDDA','aggmsg','carrier','trackingno','ICM688M1','COMPANY','PLANT','WHS'));
|
|
// compact('IC670M','ViewTitle')
|
|
}
|
|
|
|
}
|