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; // 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'"); // foreach($ICM688M1 as $key => $ICM688M1R) { // $aggmsg.=' '.$ICM688M1R->A4MACPKR.''; // } // $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(); } $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 != '') { $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; // $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 $key => $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) { } // 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') } }