m3 Security Fixes

This commit is contained in:
Mark Gregory
2026-09-16 17:16:25 +01:00
parent d68687f062
commit 8f37245e13
64 changed files with 4247 additions and 4426 deletions
File diff suppressed because it is too large Load Diff
+288 -286
View File
@@ -2,18 +2,18 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use DB;
use Illuminate\Http\Request;
use Log;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Modules\M3\Services\PostgresProgramBridge;
use Str;
class M3Controller extends Controller
{
# Split Data and Write to ICM666M2
// Split Data and Write to ICM666M2
public function insertToICM666M2($dataSplit, $commentData)
{
// dump($commentData);
@@ -22,7 +22,7 @@ class M3Controller extends Controller
$commentDataSS = explode("\n", $dataSplit);
$AXLINENO = 1;
foreach ($commentDataSS as $substring) {
# Process each substring
// Process each substring
$fullData = $commentData;
$fullData['AXCOMMENT'] = $substring;
$fullData['AXLINENO'] = $AXLINENO;
@@ -31,17 +31,21 @@ class M3Controller extends Controller
$AXLINENO++;
# AXCO ICM666M2 CHARACTER 3
# AXWHS ICM666M2 CHARACTER 3
# AXPLANT ICM666M2 CHARACTER 3
# AXDOCUMENT ICM666M2 CHARACTER 15
# AXCOMMENT ICM666M2 CHARACTER 60
# AXLINENO DECIMAL(3,0)
// AXCO ICM666M2 CHARACTER 3
// AXWHS ICM666M2 CHARACTER 3
// AXPLANT ICM666M2 CHARACTER 3
// AXDOCUMENT ICM666M2 CHARACTER 15
// AXCOMMENT ICM666M2 CHARACTER 60
// AXLINENO DECIMAL(3,0)
}
}
public function index(){ dd("Index"); }
public function create(){}
public function index()
{
dd('Index');
}
public function create() {}
public function store(Request $request)
{
@@ -53,240 +57,240 @@ class M3Controller extends Controller
$SHSOURCE = 'M3ReceiverAPI';
$ICM666MFields = [
'Company' =>[ 'A1CO' ,3 , 'string' ],
'Warehouse' =>[ 'A1WHS', 3, 'string'],
'Plant' =>[ 'A1PLANT', 3, 'string'],
'PickerNumber' =>[ 'A1DELNO',11,'integer'],
'OrderNumber' =>[ 'A1ONO' ,10, 'string'],
'ReleaseNumber' =>[ 'A1RLNO' , 3,'string'], # Pick list suffix in ICM666M
'ShipmentNumber' =>[ 'A1SHNO' ,7,'string'],
'OrderLine' =>[ 'A1PKLN',6,'integer'],
'PartNumber' =>[ 'A1PART', 15,'string'],
'Description' =>[ 'A1PARTDES', 120,'string'],
'Quantity' =>[ 'A1RSVQTY', 22,'DEC'],
'BaseUnitPrice' =>[ 'A1SLUNPR', 22,'DEC'],
'Currency' =>[ 'A1SHCURR',3,'string'],
'Zone' =>[ 'A1LVZONE', 2,'string'],
'PromDate' =>[ 'A1PROMDTE',8,'integer'],
'RouteCode' =>[ 'A1SHSRT' ,6,'string'],
'BillToId' =>[ 'A1BILLTO' ,10,'string'],
'ShipToId' =>[ 'A1SHIPTO',10,'string'],
'CompanyName' =>[ 'A1SHSHNM',36,'string'],
'Address1' =>[ 'A1SHSHA1', 36,'string'],
'Address2' =>[ 'A1SHSHA2', 36,'string'],
'Address3' =>[ 'A1SHSHA3', 36,'string'],
'Address4' =>[ 'A1SHSHA4', 36,'string'],
'City' =>[ 'A1SHSHCI', 20,'string'],
'State' =>[ 'A1SHSHST', 2,'string'],
'PostalCode' =>[ 'A1SHSHZP', 10,'string'],
'Country' =>[ 'A1SHSHCT',3,'string'],
'CountryName' =>[ 'A1SHP2CNTY', 40,'string'],
'PartWeight' =>[ 'A1PRTWGT', 15,'integer'],
'SellUOM' =>[ 'A1SLUOM', 3,'string'],
'PartConv' =>[ 'A1PARTCONV', 25,'DEC'],
'CarrierCode' =>[ 'A1CARRIER', 6,'string'],
'ShipVia' =>[ 'A1SHPVIA', 3,'string'],
'PrimaryLocation' =>[ 'A1PRIMLOC', 10,'string'],
'Allocation' =>[ 'A1SPR10A01', 10,'string'],
'AllocatedTo' =>[ 'A1SPR15A01', 10,'string'],
'LocationSeq' =>[ 'A1LOCSEQ', 10,'string'],
'UOM' =>[ 'A1UOM' , 3,'string'],
'HazMat' =>[ 'A1MATWRN', 4,'string'],
'PartUPC' =>[ 'A1UPC', 30,'string'],
'PartEAN' =>[ 'A1EAN', 30,'string'],
'LotFlag' =>[ 'A1IZLCF', 1,'string'],
'ManOrd' =>[ 'A1MONUM', 30,'string'],
'LotNumber' =>[ 'A1LOTNUM', 30,'string'],
'ProductArea' =>[ 'A1LVUSD1', 15,'string'],
'FreightClass' =>[ 'A1WBFRCT' , 10,'string'],
'ShipmentPONumber' =>[ 'A1SOPONO', 20,'string'],
'ShipmentPOLine' =>[ 'A1SOPOLN' , 7,'integer'],
'ShipTerms' =>[ 'A1OFSTRM', 3,'string'],
'Company' => ['A1CO', 3, 'string'],
'Warehouse' => ['A1WHS', 3, 'string'],
'Plant' => ['A1PLANT', 3, 'string'],
'PickerNumber' => ['A1DELNO', 11, 'integer'],
'OrderNumber' => ['A1ONO', 10, 'string'],
'ReleaseNumber' => ['A1RLNO', 3, 'string'], // Pick list suffix in ICM666M
'ShipmentNumber' => ['A1SHNO', 7, 'string'],
'OrderLine' => ['A1PKLN', 6, 'integer'],
'PartNumber' => ['A1PART', 15, 'string'],
'Description' => ['A1PARTDES', 120, 'string'],
'Quantity' => ['A1RSVQTY', 22, 'DEC'],
'BaseUnitPrice' => ['A1SLUNPR', 22, 'DEC'],
'Currency' => ['A1SHCURR', 3, 'string'],
'Zone' => ['A1LVZONE', 2, 'string'],
'PromDate' => ['A1PROMDTE', 8, 'integer'],
'RouteCode' => ['A1SHSRT', 6, 'string'],
'BillToId' => ['A1BILLTO', 10, 'string'],
'ShipToId' => ['A1SHIPTO', 10, 'string'],
'CompanyName' => ['A1SHSHNM', 36, 'string'],
'Address1' => ['A1SHSHA1', 36, 'string'],
'Address2' => ['A1SHSHA2', 36, 'string'],
'Address3' => ['A1SHSHA3', 36, 'string'],
'Address4' => ['A1SHSHA4', 36, 'string'],
'City' => ['A1SHSHCI', 20, 'string'],
'State' => ['A1SHSHST', 2, 'string'],
'PostalCode' => ['A1SHSHZP', 10, 'string'],
'Country' => ['A1SHSHCT', 3, 'string'],
'CountryName' => ['A1SHP2CNTY', 40, 'string'],
'PartWeight' => ['A1PRTWGT', 15, 'integer'],
'SellUOM' => ['A1SLUOM', 3, 'string'],
'PartConv' => ['A1PARTCONV', 25, 'DEC'],
'CarrierCode' => ['A1CARRIER', 6, 'string'],
'ShipVia' => ['A1SHPVIA', 3, 'string'],
'PrimaryLocation' => ['A1PRIMLOC', 10, 'string'],
'Allocation' => ['A1SPR10A01', 10, 'string'],
'AllocatedTo' => ['A1SPR15A01', 10, 'string'],
'LocationSeq' => ['A1LOCSEQ', 10, 'string'],
'UOM' => ['A1UOM', 3, 'string'],
'HazMat' => ['A1MATWRN', 4, 'string'],
'PartUPC' => ['A1UPC', 30, 'string'],
'PartEAN' => ['A1EAN', 30, 'string'],
'LotFlag' => ['A1IZLCF', 1, 'string'],
'ManOrd' => ['A1MONUM', 30, 'string'],
'LotNumber' => ['A1LOTNUM', 30, 'string'],
'ProductArea' => ['A1LVUSD1', 15, 'string'],
'FreightClass' => ['A1WBFRCT', 10, 'string'],
'ShipmentPONumber' => ['A1SOPONO', 20, 'string'],
'ShipmentPOLine' => ['A1SOPOLN', 7, 'integer'],
'ShipTerms' => ['A1OFSTRM', 3, 'string'],
// 'ExchangeRate' =>[ 'A1EXGRATE', 18,'DEC'],
'OrderClass' =>[ 'A1SHORCL', 3,'string'],
'LocationType' =>[ 'A1LVUSD2', 2,'string'],
'PallSize' =>[ 'A1LVUSD3', 10,'string'],
'MasterCarton' =>[ 'A1USRLD1', 30,'string'],
'MasterQty' =>[ 'A1WBSHQY', 25,'DEC'],
'InnerQty' =>[ 'A1WBPKQY', 25,'DEC'],
'PalletQty' =>[ 'A1USRN01', 24,'DEC'],
'CartonQty' =>[ 'A1USRN31', 25,'DEC'],
'PersonName' =>[ 'A1PERNAME', 30,'string'],
'AccountNo' =>[ 'A1ACCNUM', 20,'string'],
'Email' =>[ 'A1EMAIL', 100,'string'],
'OrderCategory' =>[ 'A1REFORD', 1,'string'],
'A1DATEADD' =>[ 'A1DATEADD', 12,'string'],
'A1TIMEADD' =>[ 'A1TIMEADD', 12,'string'],
'KitPartNumber' =>[ 'A1KITPART', 15,'string'],
'OrderLineSuffix' =>[ 'A1PKSFX', 6,'DEC'],
'CustomerPartNumber'=>[ 'A1CUSTPART', 20,'string'],
'GS1Label' => ['A1SPR1A01', 1, 'string'],
'CurrencyExchangeRate' =>[ 'A1EXGRATE', 18,'DEC'],
'OrderClass' => ['A1SHORCL', 3, 'string'],
'LocationType' => ['A1LVUSD2', 2, 'string'],
'PallSize' => ['A1LVUSD3', 10, 'string'],
'MasterCarton' => ['A1USRLD1', 30, 'string'],
'MasterQty' => ['A1WBSHQY', 25, 'DEC'],
'InnerQty' => ['A1WBPKQY', 25, 'DEC'],
'PalletQty' => ['A1USRN01', 24, 'DEC'],
'CartonQty' => ['A1USRN31', 25, 'DEC'],
'PersonName' => ['A1PERNAME', 30, 'string'],
'AccountNo' => ['A1ACCNUM', 20, 'string'],
'Email' => ['A1EMAIL', 100, 'string'],
'OrderCategory' => ['A1REFORD', 1, 'string'],
'A1DATEADD' => ['A1DATEADD', 12, 'string'],
'A1TIMEADD' => ['A1TIMEADD', 12, 'string'],
'KitPartNumber' => ['A1KITPART', 15, 'string'],
'OrderLineSuffix' => ['A1PKSFX', 6, 'DEC'],
'CustomerPartNumber' => ['A1CUSTPART', 20, 'string'],
'GS1Label' => ['A1SPR1A01', 1, 'string'],
'CurrencyExchangeRate' => ['A1EXGRATE', 18, 'DEC'],
];
try {
$jsonFile = count($request->json()->all()) > 0 ? $request->json()->all() : '';
# Root
$Company = isset($jsonFile["Company"]) ? $jsonFile["Company"] : '';
$Plant = isset($jsonFile["Plant"]) ? $jsonFile["Plant"] : '';
$Warehouse = isset($jsonFile["Warehouse"]) ? $jsonFile["Warehouse"] : '';
$OrderNumber = isset($jsonFile["OrderNumber"]) ? $jsonFile["OrderNumber"] : '';
$PickerNumber = isset($jsonFile["PickerNumber"]) ? $jsonFile["PickerNumber"] : '';
$PromDate = isset($jsonFile["PromDate"]) ? $jsonFile["PromDate"] : '';
$RouteCode = isset($jsonFile["RouteCode"]) ? $jsonFile["RouteCode"] : '';
$OrderCategory = isset($jsonFile["OrderCategory"]) ? $jsonFile["OrderCategory"] : '';
$ReleaseNumber = isset($jsonFile["ReleaseNumber"]) ? $jsonFile["ReleaseNumber"] : '';
$ShipmentNumber = isset($jsonFile["ShipmentNumber"]) ? $jsonFile["ShipmentNumber"] : '';
$Currency = isset($jsonFile["Currency"]) ? $jsonFile["Currency"] : '';
$CarrierCode = isset($jsonFile["CarrierCode"]) ? $jsonFile["CarrierCode"] : '';
$ShipmentPONumber = isset($jsonFile["ShipmentPONumber"]) ? $jsonFile["ShipmentPONumber"] : ''; // CustPo
$ShipTerms = isset($jsonFile["ShipTerms"]) ? $jsonFile["ShipTerms"] : '';
// Root
$Company = isset($jsonFile['Company']) ? $jsonFile['Company'] : '';
$Plant = isset($jsonFile['Plant']) ? $jsonFile['Plant'] : '';
$Warehouse = isset($jsonFile['Warehouse']) ? $jsonFile['Warehouse'] : '';
$OrderNumber = isset($jsonFile['OrderNumber']) ? $jsonFile['OrderNumber'] : '';
$PickerNumber = isset($jsonFile['PickerNumber']) ? $jsonFile['PickerNumber'] : '';
$PromDate = isset($jsonFile['PromDate']) ? $jsonFile['PromDate'] : '';
$RouteCode = isset($jsonFile['RouteCode']) ? $jsonFile['RouteCode'] : '';
$OrderCategory = isset($jsonFile['OrderCategory']) ? $jsonFile['OrderCategory'] : '';
$ReleaseNumber = isset($jsonFile['ReleaseNumber']) ? $jsonFile['ReleaseNumber'] : '';
$ShipmentNumber = isset($jsonFile['ShipmentNumber']) ? $jsonFile['ShipmentNumber'] : '';
$Currency = isset($jsonFile['Currency']) ? $jsonFile['Currency'] : '';
$CarrierCode = isset($jsonFile['CarrierCode']) ? $jsonFile['CarrierCode'] : '';
$ShipmentPONumber = isset($jsonFile['ShipmentPONumber']) ? $jsonFile['ShipmentPONumber'] : ''; // CustPo
$ShipTerms = isset($jsonFile['ShipTerms']) ? $jsonFile['ShipTerms'] : '';
// $ExchangeRate = isset($jsonFile["ExchangeRate"]) ? $jsonFile["ExchangeRate"] : '';
$OrderClass = isset($jsonFile["OrderClass"]) ? $jsonFile["OrderClass"] : '';
$GS1Label = isset($jsonFile["GS1-128Label"]) ? $jsonFile["GS1-128Label"] : '0';
$CurrencyExchangeRate = isset($jsonFile["CurrencyExchangeRate"]) ? $jsonFile["CurrencyExchangeRate"] : '';
$OrderClass = isset($jsonFile['OrderClass']) ? $jsonFile['OrderClass'] : '';
$GS1Label = isset($jsonFile['GS1-128Label']) ? $jsonFile['GS1-128Label'] : '0';
$CurrencyExchangeRate = isset($jsonFile['CurrencyExchangeRate']) ? $jsonFile['CurrencyExchangeRate'] : '';
# Set Carrier BWAY if it's empty for Tilburg only
if (($CarrierCode=='' || $CarrierCode==null) && $Warehouse=='111' && $Company=='410' && $Plant=='410' ) {
// Set Carrier BWAY if it's empty for Tilburg only
if (($CarrierCode == '' || $CarrierCode == null) && $Warehouse == '111' && $Company == '410' && $Plant == '410') {
$CarrierCode = 'BWAY';
}
$SHMACPKR = $PickerNumber!='' ? $PickerNumber : '000000';
$SHMACPKR = $PickerNumber != '' ? $PickerNumber : '000000';
if($jsonFile!=''){
# Order Category
/*
1 = Material to manufacturing order
3 = Customer Order
4 = Requisition Order
5 = Distribution Order
9 = Move order / Replenishment
*/
if ($jsonFile != '') {
// Order Category
/*
1 = Material to manufacturing order
3 = Customer Order
4 = Requisition Order
5 = Distribution Order
9 = Move order / Replenishment
*/
# Recipient
$recipient = $jsonFile["Recipient"];
$CompanyName = isset($recipient["CompanyName"]) ? $recipient["CompanyName"] : '';
$Address1 = isset($recipient["Address1"]) ? $recipient["Address1"]: '';
$Address2 = isset($recipient["Address2"]) ? $recipient["Address2"] : '';
$City = isset($recipient["City"]) ? $recipient["City"] : '';
$State = isset($recipient["State"]) ? $recipient["State"] : '';
$PostalCode = isset($recipient["PostalCode"]) ? $recipient["PostalCode"]: '';
$Country = isset($recipient["Country"]) ? $recipient["Country"]: '';
$PostalCode = isset($recipient["PostalCode"]) ? $recipient["PostalCode"]: '';
$BillToId = isset($recipient["BillToId"]) ? $recipient["BillToId"]: '';
$ShipToId = isset($recipient["ShipToId"]) ? $recipient["ShipToId"]: '';
$Address3 = isset($recipient["Address3"]) ? $recipient["Address3"] : '';
$Address4 = isset($recipient["Address4"]) ? $recipient["Address4"] : '';
$CountryName = isset($recipient["CountryName"]) ? $recipient["CountryName"] : '';
$PersonName = isset($recipient["PersonName"]) ? $recipient["PersonName"] : '';
$AccountNo = isset($recipient["AccountNo"]) ? $recipient["AccountNo"] : '';
$Email = isset($recipient["Email"]) ? $recipient["Email"] : '';
$A1DATEADD = date("Ymd");
$A1TIMEADD = date("His");
// Recipient
$recipient = $jsonFile['Recipient'];
$CompanyName = isset($recipient['CompanyName']) ? $recipient['CompanyName'] : '';
$Address1 = isset($recipient['Address1']) ? $recipient['Address1'] : '';
$Address2 = isset($recipient['Address2']) ? $recipient['Address2'] : '';
$City = isset($recipient['City']) ? $recipient['City'] : '';
$State = isset($recipient['State']) ? $recipient['State'] : '';
$PostalCode = isset($recipient['PostalCode']) ? $recipient['PostalCode'] : '';
$Country = isset($recipient['Country']) ? $recipient['Country'] : '';
$PostalCode = isset($recipient['PostalCode']) ? $recipient['PostalCode'] : '';
$BillToId = isset($recipient['BillToId']) ? $recipient['BillToId'] : '';
$ShipToId = isset($recipient['ShipToId']) ? $recipient['ShipToId'] : '';
$Address3 = isset($recipient['Address3']) ? $recipient['Address3'] : '';
$Address4 = isset($recipient['Address4']) ? $recipient['Address4'] : '';
$CountryName = isset($recipient['CountryName']) ? $recipient['CountryName'] : '';
$PersonName = isset($recipient['PersonName']) ? $recipient['PersonName'] : '';
$AccountNo = isset($recipient['AccountNo']) ? $recipient['AccountNo'] : '';
$Email = isset($recipient['Email']) ? $recipient['Email'] : '';
$A1DATEADD = date('Ymd');
$A1TIMEADD = date('His');
# MycarrierDetails
$ShipVia = isset($jsonFile["ShipVia"]) ? $jsonFile["ShipVia"]: '';
// MycarrierDetails
$ShipVia = isset($jsonFile['ShipVia']) ? $jsonFile['ShipVia'] : '';
# Comments
$Picker = $Packer = $Carrier = $Other ='';
$AXCO = $Company;
$AXPLANT = $Plant;
$AXWHS = $Warehouse;
$AXDELNO = $PickerNumber;
$AXONO = $OrderNumber;
$AXRLNO = $ReleaseNumber;
$AXSHNO = $ShipmentNumber;
// Comments
$Picker = $Packer = $Carrier = $Other = '';
$AXCO = $Company;
$AXPLANT = $Plant;
$AXWHS = $Warehouse;
$AXDELNO = $PickerNumber;
$AXONO = $OrderNumber;
$AXRLNO = $ReleaseNumber;
$AXSHNO = $ShipmentNumber;
$comments = isset($jsonFile["Comments"]) ? $jsonFile["Comments"] : '';
$comments = isset($jsonFile['Comments']) ? $jsonFile['Comments'] : '';
if ($comments!='') {
foreach($comments as $key => $comment) {
$commentData = [];
$AXDOCUMENT = Helper::sanityzeString($key);
if ($comments != '') {
foreach ($comments as $key => $comment) {
$commentData = [];
$AXDOCUMENT = Helper::sanityzeString($key);
$commentData=["AXCO"=>$AXCO,"AXPLANT"=>$AXPLANT,"AXWHS"=>$AXWHS,"AXDELNO"=>$AXDELNO,"AXONO"=>$AXONO,
"AXRLNO"=>$AXRLNO,"AXSHNO"=>$AXSHNO,"AXDOCUMENT"=>$AXDOCUMENT];
$commentData = ['AXCO' => $AXCO, 'AXPLANT' => $AXPLANT, 'AXWHS' => $AXWHS, 'AXDELNO' => $AXDELNO, 'AXONO' => $AXONO,
'AXRLNO' => $AXRLNO, 'AXSHNO' => $AXSHNO, 'AXDOCUMENT' => $AXDOCUMENT];
// dump($commentData);
switch ($AXDOCUMENT) {
case 'Picker':
$Picker = isset($comment) ? Helper::sanityzeString($comment) : 'null';
$Picker = isset($comment) ? Helper::sanityzeString($comment) : 'null';
// dump($Picker);
if ($Picker!='null') {
$this->insertToICM666M2($Picker,$commentData);
if ($Picker != 'null') {
$this->insertToICM666M2($Picker, $commentData);
}
break;
break;
case 'Packer':
$Packer = isset($comment) ? Helper::sanityzeString($comment) : 'null';
$Packer = isset($comment) ? Helper::sanityzeString($comment) : 'null';
// dump($Packer);
if ($Packer!='null') {
$this->insertToICM666M2($Packer,$commentData);
if ($Packer != 'null') {
$this->insertToICM666M2($Packer, $commentData);
}
break;
break;
case 'Carrier':
$Carrier = isset($comment) ? Helper::sanityzeString($comment) : 'null';
$Carrier = isset($comment) ? Helper::sanityzeString($comment) : 'null';
// dump($Carrier);
if ($Carrier!='null') {
$this->insertToICM666M2($Carrier,$commentData);
if ($Carrier != 'null') {
$this->insertToICM666M2($Carrier, $commentData);
}
break;
break;
case 'Other':
$Other = isset($comment) ? Helper::sanityzeString($comment) : 'null';
$Other = isset($comment) ? Helper::sanityzeString($comment) : 'null';
// dump($Other);
if ($Other!='null') {
$this->insertToICM666M2($Other,$commentData);
if ($Other != 'null') {
$this->insertToICM666M2($Other, $commentData);
}
break;
break;
}
}
}
# Get Products : commodities And Write ICM666M
$tmpProd = "";
$products = $jsonFile["Contents"]["Commodities"];
foreach($products as $key => $product) {
$Quantity = isset($product['Quantity']) ? $product['Quantity'] : '';
$Description = isset($product['Description']) ? Str::limit($product['Description'],25,'') : '';
$PartNumber = isset($product['PartNumber']) ? $product['PartNumber']: '';
$OrderLine = isset($product['OrderLine']) ? $product['OrderLine']: '';
$PartWeight = isset($product['PartWeight']) ? $product['PartWeight']: '';
$PickerLine = isset($product['PickerLine']) ? $product['PickerLine']: '';
$PrimaryLocation = isset($product['PrimaryLocation']) ? $product['PrimaryLocation']: '';
$Allocation = isset($product['Allocation']) ? $product['Allocation']: '';
$AllocatedTo = isset($product['AllocatedTo']) ? $product['AllocatedTo']: '';
$LocationSeq = isset($product['LocationSeq']) ? $product['LocationSeq']: '';
$Zone = isset($product['Zone']) ? $product['Zone']: '';
$BaseUnitPrice = isset($product['BaseUnitPrice']) ? $product['BaseUnitPrice'] : '';
$FrgnUnitPrice = isset($product['FrgnUnitPrice']) ? $product['FrgnUnitPrice'] : '';
$SellUOM = isset($product['SellUOM']) ? $product['SellUOM'] : '';
$PartConv = isset($product['PartConv']) ? $product['PartConv'] : '';
$UOM = isset($product['UOM']) ? $product['UOM']: '';
$HazMat = isset($product['HazMat']) ? $product['HazMat']: '';
$PartUPC = isset($product['PartUPC']) ? $product['PartUPC']: '';
$PartEAN = isset($product['PartEAN']) ? $product['PartEAN']: '';
$LotFlag = isset($product['LotFlag']) ? $product['LotFlag']: '';
$ManOrd = isset($product['ManOrd']) ? $product['ManOrd']: '';
$LotNumber = isset($product['LotNumber']) ? $product['LotNumber']: '';
$ProductArea = isset($product['ProductArea']) ? $product['ProductArea']: '';
$FreightClass = isset($product['FreightClass']) ? $product['FreightClass']: '';
$ShipmentPOLine = isset($product['ShipmentPOLine']) ? $product['ShipmentPOLine']: '';
$LocationType = isset($product['LocationType']) ? $product['LocationType']: '';
$PallSize = isset($product['PallSize']) ? $product['PallSize']: '';
$MasterCarton = isset($product['MasterCarton']) ? $product['MasterCarton']: '';
$MasterQty = isset($product['MasterQty']) ? $product['MasterQty']: '';
$InnerQty = isset($product['InnerQty']) ? $product['InnerQty']: '';
$PalletQty = isset($product['PalletQty']) ? $product['PalletQty']: '';
$CartonQty = isset($product['CartonQty']) ? $product['CartonQty']: '';
$KitPartNumber = isset($product['KitPartNumber']) ? $product['KitPartNumber']: '';
$OrderLineSuffix = isset($product['OrderLineSuffix']) ? $product['OrderLineSuffix']: '';
$CustomerPartNumber = isset($product['CustomerPartNumber']) ? substr($product['CustomerPartNumber'], 0, 20): ''; # Limit to 20 Chars
// Get Products : commodities And Write ICM666M
$tmpProd = '';
$products = $jsonFile['Contents']['Commodities'];
foreach ($products as $key => $product) {
$Quantity = isset($product['Quantity']) ? $product['Quantity'] : '';
$Description = isset($product['Description']) ? Str::limit($product['Description'], 25, '') : '';
$PartNumber = isset($product['PartNumber']) ? $product['PartNumber'] : '';
$OrderLine = isset($product['OrderLine']) ? $product['OrderLine'] : '';
$PartWeight = isset($product['PartWeight']) ? $product['PartWeight'] : '';
$PickerLine = isset($product['PickerLine']) ? $product['PickerLine'] : '';
$PrimaryLocation = isset($product['PrimaryLocation']) ? $product['PrimaryLocation'] : '';
$Allocation = isset($product['Allocation']) ? $product['Allocation'] : '';
$AllocatedTo = isset($product['AllocatedTo']) ? $product['AllocatedTo'] : '';
$LocationSeq = isset($product['LocationSeq']) ? $product['LocationSeq'] : '';
$Zone = isset($product['Zone']) ? $product['Zone'] : '';
$BaseUnitPrice = isset($product['BaseUnitPrice']) ? $product['BaseUnitPrice'] : '';
$FrgnUnitPrice = isset($product['FrgnUnitPrice']) ? $product['FrgnUnitPrice'] : '';
$SellUOM = isset($product['SellUOM']) ? $product['SellUOM'] : '';
$PartConv = isset($product['PartConv']) ? $product['PartConv'] : '';
$UOM = isset($product['UOM']) ? $product['UOM'] : '';
$HazMat = isset($product['HazMat']) ? $product['HazMat'] : '';
$PartUPC = isset($product['PartUPC']) ? $product['PartUPC'] : '';
$PartEAN = isset($product['PartEAN']) ? $product['PartEAN'] : '';
$LotFlag = isset($product['LotFlag']) ? $product['LotFlag'] : '';
$ManOrd = isset($product['ManOrd']) ? $product['ManOrd'] : '';
$LotNumber = isset($product['LotNumber']) ? $product['LotNumber'] : '';
$ProductArea = isset($product['ProductArea']) ? $product['ProductArea'] : '';
$FreightClass = isset($product['FreightClass']) ? $product['FreightClass'] : '';
$ShipmentPOLine = isset($product['ShipmentPOLine']) ? $product['ShipmentPOLine'] : '';
$LocationType = isset($product['LocationType']) ? $product['LocationType'] : '';
$PallSize = isset($product['PallSize']) ? $product['PallSize'] : '';
$MasterCarton = isset($product['MasterCarton']) ? $product['MasterCarton'] : '';
$MasterQty = isset($product['MasterQty']) ? $product['MasterQty'] : '';
$InnerQty = isset($product['InnerQty']) ? $product['InnerQty'] : '';
$PalletQty = isset($product['PalletQty']) ? $product['PalletQty'] : '';
$CartonQty = isset($product['CartonQty']) ? $product['CartonQty'] : '';
$KitPartNumber = isset($product['KitPartNumber']) ? $product['KitPartNumber'] : '';
$OrderLineSuffix = isset($product['OrderLineSuffix']) ? $product['OrderLineSuffix'] : '';
$CustomerPartNumber = isset($product['CustomerPartNumber']) ? substr($product['CustomerPartNumber'], 0, 20) : ''; // Limit to 20 Chars
# Initialise Table Fields to be filled
// Initialise Table Fields to be filled
$InsertArray = [];
$fieldValues = [
'Company' => $Company,
@@ -360,51 +364,51 @@ class M3Controller extends Controller
'CurrencyExchangeRate' => $CurrencyExchangeRate,
];
# Check JSON fields if empty or > DB Fields
// Check JSON fields if empty or > DB Fields
foreach ($ICM666MFields as $key => $value) {
# Sanitize String
// Sanitize String
$fieldValue = Helper::sanityzeString($fieldValues[$key] ?? '');
# Check Var Types & Length
// Check Var Types & Length
$LengthTest = Helper::checkLength($fieldValue, $value[1], $value[2]);
if (!$LengthTest[413] || !$LengthTest[411] || !$LengthTest[417]) {
if (! $LengthTest[413] || ! $LengthTest[411] || ! $LengthTest[417]) {
// Log::error($key .' :: '. $value[0].' :: '. $value[1] .' JSONF: '.$$keyVar .' Type: '.$value[2] );
if(!$LengthTest[413]){
$message[] = [ 'code'=>'413', 'status'=>'error', 'message'=>'Field: '.$key.' is larger then expected'];
if (! $LengthTest[413]) {
$message[] = ['code' => '413', 'status' => 'error', 'message' => 'Field: ' . $key . ' is larger then expected'];
}
if(!$LengthTest[411]){
$message[] = [ 'code'=>'411', 'status'=>'error', 'message'=>'Field: '.$key.' is empty'];
if (! $LengthTest[411]) {
$message[] = ['code' => '411', 'status' => 'error', 'message' => 'Field: ' . $key . ' is empty'];
}
if(!$LengthTest[417]){
$message[] = [ 'code'=>'417', 'status'=>'error', 'message'=>'Field: '.$key.'type is different then Expected type: '.$value[2]];
if (! $LengthTest[417]) {
$message[] = ['code' => '417', 'status' => 'error', 'message' => 'Field: ' . $key . 'type is different then Expected type: ' . $value[2]];
}
# Write to Logs Out : Error & JSON
$data = ['SHMACPKR'=>$SHMACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Lis-spl' ,
'SHDATA'=> json_encode($message).' M3-Lis-JSN'.json_encode($jsonFile) ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$Company,'SHWHS'=>$Warehouse ];
// Write to Logs Out : Error & JSON
$data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-spl',
'SHDATA' => json_encode($message) . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse];
Helper::logToICM699M($data);
return response()->json($message);
} else if ($fieldValue != '') {
} elseif ($fieldValue != '') {
$InsertArray[$value[0]] = $fieldValue;
}
}
// Log::info($InsertArray);
# Check ICM709M
// Check ICM709M
$ICM709MSEL = DB::connection(config('m3.connection', 'pgsql'))->table('icm709m')
->select()
->where('AT9CO',$AXCO)
->where('AT9PLT',$AXPLANT)
->where('AT9WHS',$AXWHS)
->where('AT9PART',$PartNumber)
->where('AT9CO', $AXCO)
->where('AT9PLT', $AXPLANT)
->where('AT9WHS', $AXWHS)
->where('AT9PART', $PartNumber)
->first();
$palletQty = isset($ICM709MSEL->AT9QTY) ? $ICM709MSEL->AT9QTY : 0;
// dd($palletQty);
# Get Pallet Qty
// Get Pallet Qty
$InsertArray['A1USRN01'] = $palletQty;
# Hazard Material
// Hazard Material
$HazMat = isset($ICM709MSEL->AT9WRN) ? $ICM709MSEL->AT9WRN : '';
$InsertArray['A1MATWRN'] = $HazMat;
@@ -412,28 +416,28 @@ class M3Controller extends Controller
// $InsertArray['A1USRN01']=$palletQty;
// }
# SQL Insert to ICM666M
// SQL Insert to ICM666M
$insertSQL = DB::connection(config('m3.connection', 'pgsql'))->table('icm666m')->insert($InsertArray);
}
# Call PGM ICM700CSBM
if ($Warehouse!='' && $PickerNumber!='' && $Company!='') {
// Call PGM ICM700CSBM
if ($Warehouse != '' && $PickerNumber != '' && $Company != '') {
$PGMERRORS = '';
$AWREQN = '';
$AWREQN = '';
# connect to toolkit using DB2 credentials (can also leave blank for default authority)
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
$conn = app(\Modules\M3\Services\PostgresProgramBridge::class);
$conn = app(PostgresProgramBridge::class);
} catch (\Exception $e) {
# Determine reason for failure.
# Probably database authentication error or invalid or unreachable database.
// 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
// "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:
@@ -444,91 +448,89 @@ class M3Controller extends Controller
break;
}
}
$conn->setOptions(array('persistent' => false, 'stateless' => true, 'debug' => true,'debugLogFile' => env('TOOLKIT_DEBUG_LOG')));
$conn->setOptions(['persistent' => false, 'stateless' => true, 'debug' => true, 'debugLogFile' => env('TOOLKIT_DEBUG_LOG')]);
# Add LIB
# $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)');
// Add LIB
// $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)');
# define several input/output params
$params = [];
# $params[] = $conn->AddParameterChar('out',7,'eqNumber');
// 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,'Company','',$Company);
// AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension)
// Add Warehouse Param
$params[] = $conn->AddParameterChar('in', 3, 'Company', '', $Company);
$params[] = $conn->AddParameterChar('in',3,'Warehouse','',$Warehouse);
$params[] = $conn->AddParameterChar('in', 3, 'Warehouse', '', $Warehouse);
# AddParameterPackDec($io, $length, $scale, $comment, $varName, $value,$dimension)
# Add Delivery Note Param
$PickerNumberNoZero = ltrim(strval($PickerNumber), '0');
$params[] = $conn->AddParameterChar('in', 11, 'PickerNumber','',$PickerNumberNoZero);
// AddParameterPackDec($io, $length, $scale, $comment, $varName, $value,$dimension)
// Add Delivery Note Param
$PickerNumberNoZero = ltrim(strval($PickerNumber), '0');
$params[] = $conn->AddParameterChar('in', 11, 'PickerNumber', '', $PickerNumberNoZero);
// $params[] = $conn->AddParameterZoned('in', 11, 0, 'ParamIn');
# Start Time Tracking
// Start Time Tracking
$start = microtime(true);
# ICM700C EWOBJTST ICM700C ICM700CSBM
$result = $conn->PgmCall('ICM700CSBM', env('OBJLIB'), $params, array(), array());
// ICM700C EWOBJTST ICM700C ICM700CSBM
$result = $conn->PgmCall('ICM700CSBM', env('OBJLIB'), $params, [], []);
if (!$result) {
if (! $result) {
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' - Msg: ' . $conn->getErrorMsg();
}
if ($PGMERRORS != '') {
# Write to Logs Out : Error & JSON
$data = ['SHMACPKR'=>$SHMACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Lis-spl' ,
'SHDATA'=>$PGMERRORS .' M3-Lis-JSN'.json_encode($jsonFile) ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$Company,'SHWHS'=>$Warehouse ];
// Write to Logs Out : Error & JSON
$data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-spl',
'SHDATA' => $PGMERRORS . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse];
Helper::logToICM699M($data);
}
}
# Write to Logs Out : Success
$data = ['SHMACPKR'=>$SHMACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Lis-in' ,
'SHDATA'=>json_encode($jsonFile) ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE ,'SHCO'=>$Company,'SHWHS'=>$Warehouse];
// Write to Logs Out : Success
$data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-in',
'SHDATA' => json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse];
Helper::logToICM699M($data);
return response()->json([
'code'=>'200',
'status'=>'success',
'message'=>'File Received, DB Updated'
'code' => '200',
'status' => 'success',
'message' => 'File Received, DB Updated',
]);
}
else{
# Write to Logs Out : Error & JSON
} else {
// Write to Logs Out : Error & JSON
$SHACKNOTE = 'Sentinel automatically closed the error related to this empty data set sent by M3';
$data = ['SHMACPKR'=>$SHMACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'Z','SHINTBOX'=> '','SHTYPE'=> 'M3-Lis-in' ,
'SHDATA'=>'No Json File Found...' ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$Company,'SHWHS'=>$Warehouse,"SHACKNOTE"=> $SHACKNOTE ];
$data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'Z', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-in',
'SHDATA' => 'No Json File Found...', 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse, 'SHACKNOTE' => $SHACKNOTE];
Helper::logToICM699M($data);
return response()->json([
'code'=>'415',
'status'=>'error',
'message'=>'No Json File Found'
'code' => '415',
'status' => 'error',
'message' => 'No Json File Found',
]);
}
}
catch (\Throwable $th) {
# Write to Logs Out : Error & JSON
$data = ['SHMACPKR'=>$SHMACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Lis-in' ,
'SHDATA'=>'General Catchable Error - '.substr($th,0,300).' M3-Lis-JSN'.json_encode($jsonFile) ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$Company,'SHWHS'=>$Warehouse ];
Helper::logToICM699M($data);
} catch (\Throwable $th) {
// Write to Logs Out : Error & JSON
$data = ['SHMACPKR' => $SHMACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Lis-in',
'SHDATA' => 'General Catchable Error - ' . substr($th, 0, 300) . ' M3-Lis-JSN' . json_encode($jsonFile), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $Company, 'SHWHS' => $Warehouse];
Helper::logToICM699M($data);
// Log::error($th);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'An Error Occured...'
'code' => '405',
'status' => 'error',
'message' => 'An Error Occured...',
]);
}
}
public function show($id){}
public function show($id) {}
public function edit($id){}
public function edit($id) {}
public function update(Request $request, $id){}
public function update(Request $request, $id) {}
public function destroy($id){}
public function destroy($id) {}
}
@@ -2,282 +2,272 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Config;
use DB;
use Http;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use File;
use Modules\M3\Helpers\Helper;
use Json;
use Log;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Str;
class M3InventoryReport extends Controller
{
# M3InventoryReport for Single Part
public function M3InventoryReport(Request $request){
// M3InventoryReport for Single Part
public function M3InventoryReport(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
// dd($request->json()->all());
# Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WEBUSER';
# Set SHSOURCE
// Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WEBUSER';
// Set SHSOURCE
$SHSOURCE = 'M3InventoryReport';
$M3Errors = '';
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
try {
# Get Json Contents
$jsonFile = count($request->json()->all())>0 ? $request->json()->all() : '';
if($jsonFile!=''){
$WHS = isset($jsonFile["WHS"]) ? $jsonFile["WHS"] : '';
$PART = isset($jsonFile["PART"]) ? $jsonFile["PART"] : '';
$LOT = isset($jsonFile["LOT"]) ? $jsonFile["LOT"] : '';
}
else {
# code...
// Get Json Contents
$jsonFile = count($request->json()->all()) > 0 ? $request->json()->all() : '';
if ($jsonFile != '') {
$WHS = isset($jsonFile['WHS']) ? $jsonFile['WHS'] : '';
$PART = isset($jsonFile['PART']) ? $jsonFile['PART'] : '';
$LOT = isset($jsonFile['LOT']) ? $jsonFile['LOT'] : '';
} else {
// code...
}
# Get Token
// Get Token
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if($tokenData->code=='200'){
$tokenData = $tokenResponse->getData();
if ($tokenData->code == '200') {
$IonToken = isset($tokenData->token) ? $tokenData->token : '';
}
else{
} else {
$SHDATA = isset($tokenData->message) ? $tokenData->message : '';
# Write to Logs : Error
$data = ['SHMACPKR'=>'000000','SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=> $SHDATA ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>'','SHWHS'=>$WHS];
// Write to Logs : Error
$data = ['SHMACPKR' => '000000', 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $SHDATA, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => '', 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return $tokenResponse;
}
# Call ionapi with Params
$endPointURL = env('ENDPOINTURL').'APIFLOWS/Sentinel/M3InventoryReport?ionapiRespStyle=sync';
$token = $IonToken;
// Call ionapi with Params
$endPointURL = env('ENDPOINTURL') . 'APIFLOWS/Sentinel/M3InventoryReport?ionapiRespStyle=sync';
$token = $IonToken;
$JSON = [
"WHS" => $WHS,
"PART"=> $PART,
"LOT" => $LOT
'WHS' => $WHS,
'PART' => $PART,
'LOT' => $LOT,
];
$response = Http::withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
])
->withToken($token)
->timeout(Config::get('arrays.curlTimeOut'))
->post($endPointURL, $JSON);
->withToken($token)
->timeout(Config::get('arrays.curlTimeOut'))
->post($endPointURL, $JSON);
$responseStatusCode = $response->getStatusCode();
$M3SessionId = $response->hasHeader('x-transaction-id') ? "-sessionID:". $response->header('x-transaction-id') : '-sessionID';
$M3SessionId = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
if ($responseStatusCode =='200') {
# Check M3 Response for Errors
$M3Errors = '';
$responseJSON = $response->getBody()->getContents();
if ($responseStatusCode == '200') {
// Check M3 Response for Errors
$M3Errors = '';
$responseJSON = $response->getBody()->getContents();
$JsonSanytized = Helper::sanityzeString($responseJSON);
}
else{
} else {
$M3Errors = 'Error: No Response from M3';
}
if ($M3Errors!='') {
# Write to Logs : Error
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.$M3Errors.$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>'','SHWHS'=>$WHS ];
if ($M3Errors != '') {
// Write to Logs : Error
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . $M3Errors . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => '', 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Send Response
// Send Response
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>$M3Errors
'code' => '405',
'status' => 'error',
'message' => $M3Errors,
]);
}
else{
# Write to Logs Out : Success
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.$JsonSanytized.'-'.json_encode($JSON).$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,
'SHCO'=>'','SHWHS'=>$WHS];
} else {
// Write to Logs Out : Success
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . $JsonSanytized . '-' . json_encode($JSON) . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE,
'SHCO' => '', 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return response()->json([
'code'=>$responseStatusCode,
'status'=>'Success',
'message'=>json_decode($JsonSanytized)
'code' => $responseStatusCode,
'status' => 'Success',
'message' => json_decode($JsonSanytized),
]);
}
}
catch (\Throwable $th) {
} catch (\Throwable $th) {
// Log::error($th);
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if($getCurlErrors){
# Write to Logs Out : Failed
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'Curl Error: Communication with M3 Timed Out'.' M3-JSN-out'.$JSON ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>'','SHWHS'=>$WHS];
if ($getCurlErrors) {
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'Curl Error: Communication with M3 Timed Out' . ' M3-JSN-out' . $JSON, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => '', 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Curl Error: Communication with M3 Timed Out.'
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with M3 Timed Out.',
]);
}
else {
# Write to Logs Out : Error
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'An Error Occured - '.substr($th,0,300) ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE];
} else {
// Write to Logs Out : Error
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'An Error Occured - ' . substr($th, 0, 300), 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE];
Helper::logToICM699M($data);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Catched Error: '.$th
'code' => '405',
'status' => 'error',
'message' => 'Catched Error: ' . $th,
]);
}
}
}
# End M3InventoryReport
// End M3InventoryReport
# M3InventoryReportList with URL Params
public function M3InventoryReportListURL(Request $request){
// M3InventoryReportList with URL Params
public function M3InventoryReportListURL(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
# Set API Name
// Set API Name
$SHSOURCE = 'M3InventoryReportListURL';
# Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
// Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$M3Errors = '';
try {
# Get Json Contents
$urlParams = count($request->all())>0 ? $request->all() : '';
// Get Json Contents
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$REQPKWS = isset($urlParams["REQPKWS"]) ? $urlParams["REQPKWS"] : '';
$REQKPKUS = isset($urlParams["REQKPKUS"]) ? $urlParams["REQKPKUS"] : 'WebUser';
$CO = isset($urlParams["CO"]) ? $urlParams["CO"] : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$MACPKR = isset($urlParams["MACPKR"]) ? $urlParams["MACPKR"] : '000000'; # Delivery Number
$PKLN = isset($urlParams["PKLN"]) ? $urlParams["PKLN"] : '';
$REQPKWS = isset($urlParams['REQPKWS']) ? $urlParams['REQPKWS'] : '';
$REQKPKUS = isset($urlParams['REQKPKUS']) ? $urlParams['REQKPKUS'] : 'WebUser';
$CO = isset($urlParams['CO']) ? $urlParams['CO'] : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
$MACPKR = isset($urlParams['MACPKR']) ? $urlParams['MACPKR'] : '000000'; // Delivery Number
$PKLN = isset($urlParams['PKLN']) ? $urlParams['PKLN'] : '';
if($urlParams!=''){
$IncomingParams = ['CO'=> $CO,'WHS'=> $WHS,'MACPKR'=> $MACPKR,'PKLN'=> $PKLN,'REQPKWS'=> $REQPKWS,'REQKPKUS'=> $REQKPKUS];
if ($urlParams != '') {
$IncomingParams = ['CO' => $CO, 'WHS' => $WHS, 'MACPKR' => $MACPKR, 'PKLN' => $PKLN, 'REQPKWS' => $REQPKWS, 'REQKPKUS' => $REQKPKUS];
$IncomingParams = json_encode($IncomingParams);
# Write to Logs : Params In
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Req-out' ,
'SHDATA'=>$IncomingParams ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Write to Logs : Params In
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Req-out',
'SHDATA' => $IncomingParams, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Get Parts And Lots from ICM688M2
// Get Parts And Lots from ICM688M2
$ICM688M2SLTMP = DB::connection(config('m3.connection', 'pgsql'))->table('icm688m2')
->select('A5WHS', 'A5PART','A5LOTNUM','A5SENTPKR')
->select('A5WHS', 'A5PART', 'A5LOTNUM', 'A5SENTPKR')
->distinct()
->where('A5CO',$CO)
->where('A5WHS',$WHS)
->where('A5MACPKR',$MACPKR);
->where('A5CO', $CO)
->where('A5WHS', $WHS)
->where('A5MACPKR', $MACPKR);
# Get Pack Lines
if($PKLN!=''){
$ICM688M2SLTMP->where('A5PKLN',$PKLN);
// Get Pack Lines
if ($PKLN != '') {
$ICM688M2SLTMP->where('A5PKLN', $PKLN);
}
$ICM688M2SL = $ICM688M2SLTMP->get();
// dd($ICM688M2SL);
if( count($ICM688M2SL)>0 ){
# Update ICM688M1 : Add Timestamp
if (count($ICM688M2SL) > 0) {
// Update ICM688M1 : Add Timestamp
$ICM688M1TS = now();
DB::connection(config('m3.connection', 'pgsql'))->table('icm688m1')
->where('A4MACPKR',$MACPKR)
->update(['A4INRFSHTS'=>$ICM688M1TS]);
->where('A4MACPKR', $MACPKR)
->update(['A4INRFSHTS' => $ICM688M1TS]);
$PICKERARR = [];
foreach ($ICM688M2SL as $key => $ICM688M2) {
$PART = trim($ICM688M2->A5PART);
$LOT = trim($ICM688M2->A5LOTNUM);
$PARTS[] = ["PART"=> $PART , "LOT"=>$LOT];
$PICKERARR[$PART] = $ICM688M2->A5SENTPKR;
$PART = trim($ICM688M2->A5PART);
$LOT = trim($ICM688M2->A5LOTNUM);
$PARTS[] = ['PART' => $PART, 'LOT' => $LOT];
$PICKERARR[$PART] = $ICM688M2->A5SENTPKR;
}
// Log::info($PARTS);
// dump($PARTS);
$JSON = json_encode( ["WHS" => $WHS,"PARTS"=> $PARTS ] );
$JSON = json_encode(['WHS' => $WHS, 'PARTS' => $PARTS]);
// Log::info($JSON);
# Get Token
// Get Token
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if($tokenData->code=='200'){
$tokenData = $tokenResponse->getData();
if ($tokenData->code == '200') {
$IonToken = isset($tokenData->token) ? $tokenData->token : '';
}
else{
} else {
$SHDATA = isset($tokenData->message) ? $tokenData->message : '';
# Write to Logs : Error
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=> $SHDATA ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $SHDATA, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return $tokenResponse;
}
# Call ionapi with Params
$endPointURL = env('ENDPOINTURL').'APIFLOWS/Sentinel/M3InventoryReportList?ionapiRespStyle=sync';
$token = $IonToken;
// Call ionapi with Params
$endPointURL = env('ENDPOINTURL') . 'APIFLOWS/Sentinel/M3InventoryReportList?ionapiRespStyle=sync';
$token = $IonToken;
$response = Http::withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json'
])
'Content-Type' => 'application/json',
])
->withToken($token)
->withBody($JSON, 'application/json')
->timeout(Config::get('arrays.curlTimeOut'))
->post($endPointURL);
$M3SessionId = $response->hasHeader('x-transaction-id') ? "-sessionID:". $response->header('x-transaction-id') : '-sessionID';
$M3SessionId = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
$responseStatusCode = $response->getStatusCode();
if ($responseStatusCode =='200') {
# Check M3 Response for Errors
if ($responseStatusCode == '200') {
// Check M3 Response for Errors
$M3Errors = '';
$responseJSON = $response->getBody()->getContents();
$JsonSanytized = Helper::sanityzeString($responseJSON);
# Array
$responseArray = json_decode($JsonSanytized,true);
// Array
$responseArray = json_decode($JsonSanytized, true);
$responseTMP = $responseArray['result'];
}
else{
} else {
$M3Errors = 'Error: No Response from M3';
}
# Validate response From M3
if ($M3Errors!='') {
# Write to Logs : Error
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.'-'.$M3Errors.$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Validate response From M3
if ($M3Errors != '') {
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . '-' . $M3Errors . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Send Response
// Send Response
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Error: No Response from M3'
'code' => '405',
'status' => 'error',
'message' => 'Error: No Response from M3',
]);
}
else{
# Write to Logs : JSON
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.'-'.$JsonSanytized.$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
} else {
// Write to Logs : JSON
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . '-' . $JsonSanytized . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
}
@@ -287,167 +277,163 @@ class M3InventoryReport extends Controller
$dataToWrite = [];
foreach ($value as $key2 => $content) {
if($key2!='Locations'){
if ($key2 != 'Locations') {
$dataToWrite[$key2] = $content;
}
else{
} else {
foreach ($content as $key3 => $content2) {
//dump($content2);
$dataToWrite2[] = array_merge($dataToWrite,$content2);
// dump($content2);
$dataToWrite2[] = array_merge($dataToWrite, $content2);
}
}
}
}
// LOG::info($dataToWrite2);
# Delete Old Records from IC630M
// Delete Old Records from IC630M
foreach ($dataToWrite2 as $key => $value) {
$ICM630MDeleteSQL = DB::connection(config('m3.connection', 'pgsql'))->table('ic630m')
->where('LLCO',$CO)
->where('LLWHNO',$WHS)
->where('LLPPN',trim($value['PartNumber']))
->where('LLCO', $CO)
->where('LLWHNO', $WHS)
->where('LLPPN', trim($value['PartNumber']))
->delete();
}
foreach ($dataToWrite2 as $key => $value) {
# Check if Location exist in DE640M ("LVCO", "WSELOC", "VLOCID")
// Check if Location exist in DE640M ("LVCO", "WSELOC", "VLOCID")
$DE640MSQLSEL = DB::connection(config('m3.connection', 'pgsql'))->table('de640m')
->where('LVCO',$CO)
->where('WSELOC',$value['Warehouse'])
->where('VLOCID',$value['Location'])
->where('LVCO', $CO)
->where('WSELOC', $value['Warehouse'])
->where('VLOCID', $value['Location'])
->first();
// dd($DE640MSQLSEL);
$LocationExist = isset($DE640MSQLSEL->VLOCID) ? trim($DE640MSQLSEL->VLOCID) : '';
$WHExist = isset($DE640MSQLSEL->WSELOC) ? trim($DE640MSQLSEL->WSELOC) : '';
$COExist = isset($DE640MSQLSEL->LVCO) ? trim($DE640MSQLSEL->LVCO) : '';
$WHExist = isset($DE640MSQLSEL->WSELOC) ? trim($DE640MSQLSEL->WSELOC) : '';
$COExist = isset($DE640MSQLSEL->LVCO) ? trim($DE640MSQLSEL->LVCO) : '';
// dd($LocationExist .': '.$WHExist.': '.$COExist);
# if No records Founds insert New Record
if ( $LocationExist=='' && $WHExist=='' && $COExist=='' ) {
$SQLInsertPrep640M['LVCO'] = $CO; # Company
$SQLInsertPrep640M['WSELOC'] = $value['Warehouse'];
// if No records Founds insert New Record
if ($LocationExist == '' && $WHExist == '' && $COExist == '') {
$SQLInsertPrep640M['LVCO'] = $CO; // Company
$SQLInsertPrep640M['WSELOC'] = $value['Warehouse'];
// $SQLInsertPrep640M['LVDELNO'] = $MACPKR; # M3 Delivery note number DELETED
// $SQLInsertPrep640M['LVUSD3'] = $value['']; # Pallet Size : Not Found in M3 JSON
$SQLInsertPrep640M['VLOCID'] = $value['Location']; # Stock location
$SQLInsertPrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLInsertPrep640M['LVUSD2'] = $value['LocationType'];
$SQLInsertPrep640M['LVZONE'] = $value['Zone']; # Warehouse zone
$SQLInsertPrep640M['LVMAINTTS'] = now(); # Last maintained time stamp
$SQLInsertPrep640M['VLOCID'] = $value['Location']; // Stock location
$SQLInsertPrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLInsertPrep640M['LVUSD2'] = $value['LocationType'];
$SQLInsertPrep640M['LVZONE'] = $value['Zone']; // Warehouse zone
$SQLInsertPrep640M['LVMAINTTS'] = now(); // Last maintained time stamp
DB::connection(config('m3.connection', 'pgsql'))->table('de640m')->insert($SQLInsertPrep640M);
}
# Update
// Update
else {
$SQLUpdatePrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLUpdatePrep640M['LVUSD2'] = $value['LocationType'];
$SQLUpdatePrep640M['LVZONE'] = $value['Zone'];
$SQLUpdatePrep640M['LVMAINTTS'] = now();
$SQLUpdatePrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLUpdatePrep640M['LVUSD2'] = $value['LocationType'];
$SQLUpdatePrep640M['LVZONE'] = $value['Zone'];
$SQLUpdatePrep640M['LVMAINTTS'] = now();
DB::connection(config('m3.connection', 'pgsql'))->table('de640m')
->where('LVCO',$CO)
->where('WSELOC',$value['Warehouse'])
->where('VLOCID',$value['Location'])
->where('LVCO', $CO)
->where('WSELOC', $value['Warehouse'])
->where('VLOCID', $value['Location'])
->update($SQLUpdatePrep640M);
}
# Insert New Records to IC630M
$SQLInsertPrep630M = [];
$SQLInsertPrep630M['LLCO'] = $CO; # Company
$SQLInsertPrep630M['LLWHNO'] = $value['Warehouse']; # Warehouse
// Insert New Records to IC630M
$SQLInsertPrep630M = [];
$SQLInsertPrep630M['LLCO'] = $CO; // Company
$SQLInsertPrep630M['LLWHNO'] = $value['Warehouse']; // Warehouse
// $SQLInsertPrep630M['LLDELNO'] = $MACPKR; # M3 Delivery note number DELETED
$SQLInsertPrep630M['LLPPN'] = $value['PartNumber']; # Part Number
$SQLInsertPrep630M['LLBALANCE'] = $value['Quantity']; # Quantity
$SQLInsertPrep630M['LLSTLC'] = $value['Location']; # Stock location
$SQLInsertPrep630M['LLLTNO'] = $value['LotNumber']; # Lot Number
$SQLInsertPrep630M['LLMAINTTS'] = now(); # Request time timestamp
$SQLInsertPrep630M['LLIZLCF'] = trim($value['LotNumber'])!='' ? '1' : ''; # Lot control flag
$SQLInsertPrep630M['LLCMDESC'] = $value['Description']; # Description
$SQLInsertPrep630M['LLSPR10A01'] = isset($value['Allocation']) ? $value['Allocation'] : ''; # Allocation
$SQLInsertPrep630M['LLSPR15A01'] = isset($value['AllocatedTo']) ? $value['AllocatedTo'] : ''; # AllocatedTo
$SQLInsertPrep630M['LLPPN'] = $value['PartNumber']; // Part Number
$SQLInsertPrep630M['LLBALANCE'] = $value['Quantity']; // Quantity
$SQLInsertPrep630M['LLSTLC'] = $value['Location']; // Stock location
$SQLInsertPrep630M['LLLTNO'] = $value['LotNumber']; // Lot Number
$SQLInsertPrep630M['LLMAINTTS'] = now(); // Request time timestamp
$SQLInsertPrep630M['LLIZLCF'] = trim($value['LotNumber']) != '' ? '1' : ''; // Lot control flag
$SQLInsertPrep630M['LLCMDESC'] = $value['Description']; // Description
$SQLInsertPrep630M['LLSPR10A01'] = isset($value['Allocation']) ? $value['Allocation'] : ''; // Allocation
$SQLInsertPrep630M['LLSPR15A01'] = isset($value['AllocatedTo']) ? $value['AllocatedTo'] : ''; // AllocatedTo
DB::connection(config('m3.connection', 'pgsql'))->table('ic630m')->insert($SQLInsertPrep630M);
}
// dump($SQLInsertPrep);
#Send Response
// Send Response
return response()->json([
'code' => '200',
'status' => 'Success'
'code' => '200',
'status' => 'Success',
]);
}
else{
# Write to Logs Out : Error
} else {
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'No Records Found in ICM688M2' ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'No Records Found in ICM688M2', 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'code' => '405',
'status' => 'Error',
'message'=> 'No Records Found in ICM688M2'
'message' => 'No Records Found in ICM688M2',
]);
}
}
else {
# Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'No URL Parameters Sent','SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
Helper::logToICM699M($data);
} else {
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'No URL Parameters Sent', 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'code' => '405',
'status' => 'Error',
'message'=> 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
}
catch (\Throwable $th) {
# Write to Logs Out : Error
} catch (\Throwable $th) {
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if($getCurlErrors){
if ($getCurlErrors) {
// dd($getCurlErrors);
# Write to Logs Out : Failed
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$th->getMessage().' M3-JSN-out'.$IncomingParams ,
'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS];
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $th->getMessage() . ' M3-JSN-out' . $IncomingParams,
'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Curl Error: Communication with M3 Timed Out.'
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with M3 Timed Out.',
]);
}
else {
# Set SHERROR To Z if Duplicate Key Detected $th
# Read The substring from SHDATA after M3-JSN-out
$SHERROR = 'X';
$word = 'Duplicate key value specified';
$position = strpos($th, $word);
} else {
// Set SHERROR To Z if Duplicate Key Detected $th
// Read The substring from SHDATA after M3-JSN-out
$SHERROR = 'X';
$word = 'Duplicate key value specified';
$position = strpos($th, $word);
if ($position !== false) {
$SHERROR = 'Z';
}
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> $SHERROR,'SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'An Error Occured-'.substr($th,0,300) ,'SHUSER'=> $REQKPKUS,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS];
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => $SHERROR, 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'An Error Occured-' . substr($th, 0, 300), 'SHUSER' => $REQKPKUS, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
Log::error($th);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Catched Error: '.$th
'code' => '405',
'status' => 'error',
'message' => 'Catched Error: ' . $th,
]);
}
}
}
# End M3InventoryReportListURL
// End M3InventoryReportListURL
}
+71 -78
View File
@@ -2,73 +2,69 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use Config;
use File;
use Illuminate\Http\Request;
use Log;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Smalot\PdfParser\Parser;
use Str;
class PdfStorage extends Controller
{
# PdfStorageAPI : PDF file read and save to Cache
public function PdfStorageAPI(Request $request){
// PdfStorageAPI : PDF file read and save to Cache
public function PdfStorageAPI(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
// dd($request->all());
# Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
// Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$SHSOURCE = 'PdfStorageAPI';
# PDF File PATH
$pdfFilePath = Config::get('arrays.PdfPath');
// PDF File PATH
$pdfFilePath = Config::get('arrays.PdfPath');
try {
# Get URL PARAMS
$urlParams = count($request->all())>0 ? $request->all() : '';
// Get URL PARAMS
$urlParams = count($request->all()) > 0 ? $request->all() : '';
// dd($urlParams);
$COMPANY = isset($urlParams["COMPANY"]) ? trim($urlParams["COMPANY"]) : ''; # Company
$WHS = isset($urlParams["WHS"]) ? trim($urlParams["WHS"]) : ''; # WareHouse
$DOCTYPE = isset($urlParams["DOCTYPE"]) ? trim($urlParams["DOCTYPE"]) : ''; # document type (PackingList, CarrierLabel, ContentLabel)
$FILENAME = isset($urlParams["FILENAME"]) ? trim($urlParams["FILENAME"]) : ''; # PDF File name
$DOCNUM = isset($urlParams["DOCNUM"]) ? trim($urlParams["DOCNUM"]) : ''; # document number (ie the internal box number, the pick list number)
$A4MACPKR = isset($urlParams["A4MACPKR"]) ? trim($urlParams["A4MACPKR"]) : ''; # Delivery note number
$COMPANY = isset($urlParams['COMPANY']) ? trim($urlParams['COMPANY']) : ''; // Company
$WHS = isset($urlParams['WHS']) ? trim($urlParams['WHS']) : ''; // WareHouse
$DOCTYPE = isset($urlParams['DOCTYPE']) ? trim($urlParams['DOCTYPE']) : ''; // document type (PackingList, CarrierLabel, ContentLabel)
$FILENAME = isset($urlParams['FILENAME']) ? trim($urlParams['FILENAME']) : ''; // PDF File name
$DOCNUM = isset($urlParams['DOCNUM']) ? trim($urlParams['DOCNUM']) : ''; // document number (ie the internal box number, the pick list number)
$A4MACPKR = isset($urlParams['A4MACPKR']) ? trim($urlParams['A4MACPKR']) : ''; // Delivery note number
if($urlParams!=''){
# Key Combination : COMPANY WHS A4MACPKR DOCTYPE DOCNUM
# Document type (PackingList, CarrierLabel, ContentLabel)
if ($urlParams != '') {
// Key Combination : COMPANY WHS A4MACPKR DOCTYPE DOCNUM
// Document type (PackingList, CarrierLabel, ContentLabel)
$DELIVERYNO = isset($A4MACPKR) ? $A4MACPKR : '000000';
$DELIVERYNO = $DELIVERYNO!="" && $DELIVERYNO!=null ? $DELIVERYNO : '000000';
# Write to Logs : Params In
$IncomingParams = ['COMPANY'=> $COMPANY,'WHS'=> $WHS,'DOCTYPE'=> $DOCTYPE,'FILENAME'=> $FILENAME,'A4MACPKR'=> $A4MACPKR,'DOCNUM' => $DOCNUM];
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> $DOCNUM,'SHTYPE'=> 'M3-Req-out' ,
'SHDATA'=>json_encode($IncomingParams) ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$COMPANY,'SHWHS'=>$WHS ];
$DELIVERYNO = $DELIVERYNO != '' && $DELIVERYNO != null ? $DELIVERYNO : '000000';
// Write to Logs : Params In
$IncomingParams = ['COMPANY' => $COMPANY, 'WHS' => $WHS, 'DOCTYPE' => $DOCTYPE, 'FILENAME' => $FILENAME, 'A4MACPKR' => $A4MACPKR, 'DOCNUM' => $DOCNUM];
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => $DOCNUM, 'SHTYPE' => 'M3-Req-out',
'SHDATA' => json_encode($IncomingParams), 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Make Key and Test Validity
if ($A4MACPKR!='' && $DOCTYPE!='' && $DOCNUM!='' && $COMPANY!='' && $WHS!=''){
$cacheKey = $A4MACPKR.$DOCTYPE.$DOCNUM.$COMPANY.$WHS;
}
else{
$cacheKey ='';
// Make Key and Test Validity
if ($A4MACPKR != '' && $DOCTYPE != '' && $DOCNUM != '' && $COMPANY != '' && $WHS != '') {
$cacheKey = $A4MACPKR . $DOCTYPE . $DOCNUM . $COMPANY . $WHS;
} else {
$cacheKey = '';
}
# Read PDF File and Encode to Base64
$pdfFileName = $pdfFilePath.$FILENAME.'.pdf';
// Read PDF File and Encode to Base64
$pdfFileName = $pdfFilePath . $FILENAME . '.pdf';
// dd($pdfFileName);
// dd(File::exists($pdfFileName));
if (File::exists($pdfFileName) && $cacheKey!='') {
if (File::exists($pdfFileName) && $cacheKey != '') {
// dd(File::exists($pdfFileName));
// Parse PDF file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$parser = new Parser;
// $pdf = $parser->parseFile('/www/sentm3test/htdocs/labels/E1232824-10826596.pdf');
// dump($pdf);
@@ -83,84 +79,81 @@ class PdfStorage extends Controller
// Output base64 string
// dump($base64PDF);
# Save Cache
// Save Cache
Cache::forever($cacheKey, $base64PDF);
// Cache::put($cacheKey, $base64PDF, now()->addMinutes(60));
# Retrieve Cache
// Retrieve Cache
// $cachedPdfFile = Cache::get($cacheKey);
// dump("Retrieve Base64 Encoded PDF saved in Cache:");
// dump($cachedPdfFile);
// $pdfData = substr($cachedPdfFile,0,50);
# remove File from Cache
// remove File from Cache
// Cache::put(pdfFileName, 'value', -5);
// Cache::forget($pdfFileName);
# Base64 Decode and Display
// Base64 Decode and Display
// $pdf = $parser->parseContent(base64_decode($base64PDF));
// $text = $pdf->getText();
// dump($text);
# Write to Logs Out : Success
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> $DOCNUM,'SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'PDF File converted to Base64 and Saved to Cache.Key: '.$cacheKey,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$COMPANY,'SHWHS'=>$WHS];
// Write to Logs Out : Success
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => $DOCNUM, 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'PDF File converted to Base64 and Saved to Cache.Key: ' . $cacheKey, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS];
// dd($data);
Helper::logToICM699M($data);
return response()->json([
'code' => '200',
'status' => 'Success',
'cacheKey'=> $cacheKey
'code' => '200',
'status' => 'Success',
'cacheKey' => $cacheKey,
// 'PDFData' => $pdfData
]);
}
else {
} else {
$SHDATA = File::exists($pdfFileName) ? '' : 'PDF File Not Found-';
$SHDATA = $cacheKey!='' ? $SHDATA.'' : $SHDATA.'Cache Key is missing Params';
$SHDATA = $cacheKey != '' ? $SHDATA . '' : $SHDATA . 'Cache Key is missing Params';
# Write to Logs Out : Error
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> $DOCNUM,'SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'An Error Occured -'.$SHDATA,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$COMPANY,'SHWHS'=>$WHS];
// Write to Logs Out : Error
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => $DOCNUM, 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'An Error Occured -' . $SHDATA, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'code' => '405',
'status' => 'Error',
'message'=> $SHDATA
'message' => $SHDATA,
]);
}
}
else {
# Write to Logs Out : Error
} else {
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'No URL Parameters Sent.','SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$COMPANY,'SHWHS'=>$WHS];
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'No URL Parameters Sent.', 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'code' => '405',
'status' => 'Error',
'message'=> 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
}
catch (\Throwable $th) {
} catch (\Throwable $th) {
// Log::error($th);
# Write to Logs Out : Error
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR'=>$DELIVERYNO,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'An Error Occured - '.substr($th,0,300) ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$COMPANY,'SHWHS'=>$WHS];
$data = ['SHMACPKR' => $DELIVERYNO, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'An Error Occured - ' . substr($th, 0, 300), 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $COMPANY, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Catched Error: '.$th
'code' => '405',
'status' => 'error',
'message' => 'Catched Error: ' . $th,
]);
}
}
# End PdfStorageAPI
// End PdfStorageAPI
}
+143 -154
View File
@@ -2,94 +2,89 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Config;
use DB;
use Http;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use File;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Str;
class ReplenAPI extends Controller
class ReplenAPI extends Controller
{
# M3Replenishement with URL Params
public function M3InventoryReportReplen(Request $request){
// M3Replenishement with URL Params
public function M3InventoryReportReplen(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
// dd($request->all());
// Log::info( $request->all() );
# Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$SHSOURCE = 'M3InventoryReportReplen';
// Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$SHSOURCE = 'M3InventoryReportReplen';
$M3Errors = '';
try {
# Get Json Contents
$urlParams = count($request->all())>0 ? $request->all() : '';
// Get Json Contents
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$CO = isset($urlParams["CO"]) ? $urlParams["CO"] : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$PARTNO = isset($urlParams["PARTNO"]) ? $urlParams["PARTNO"] : '';
$PKLN = isset($urlParams["PKLN"]) ? $urlParams["PKLN"] : '';
$REQPKWS = isset($urlParams["REQPKWS"]) ? $urlParams["REQPKWS"] : '';
$REQKPKUS = isset($urlParams["REQKPKUS"]) ? $urlParams["REQKPKUS"] : 'WebUser';
$CO = isset($urlParams['CO']) ? $urlParams['CO'] : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
$PARTNO = isset($urlParams['PARTNO']) ? $urlParams['PARTNO'] : '';
$PKLN = isset($urlParams['PKLN']) ? $urlParams['PKLN'] : '';
$REQPKWS = isset($urlParams['REQPKWS']) ? $urlParams['REQPKWS'] : '';
$REQKPKUS = isset($urlParams['REQKPKUS']) ? $urlParams['REQKPKUS'] : 'WebUser';
if($urlParams!=''){
$IncomingParams = ['CO'=> $CO,'WHS'=> $WHS,'PARTNO'=> $PARTNO,'PKLN'=> $PKLN,'REQPKWS'=> $REQPKWS,'REQKPKUS'=> $REQKPKUS];
if ($urlParams != '') {
$IncomingParams = ['CO' => $CO, 'WHS' => $WHS, 'PARTNO' => $PARTNO, 'PKLN' => $PKLN, 'REQPKWS' => $REQPKWS, 'REQKPKUS' => $REQKPKUS];
$IncomingParams = json_encode($IncomingParams);
# Write to Logs : Params In
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Req-out' ,
'SHDATA'=>$IncomingParams ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Write to Logs : Params In
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Req-out',
'SHDATA' => $IncomingParams, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
$PART = explode( ',',$PARTNO);
foreach( $PART as $key => $value){
$PARTS[] = ["PART"=> $value,"LOT"=>""];
$PART = explode(',', $PARTNO);
foreach ($PART as $key => $value) {
$PARTS[] = ['PART' => $value, 'LOT' => ''];
}
// dump($PARTS);
$JSON = json_encode( ["WHS" => $WHS,"PARTS"=> $PARTS ] );
$JSON = json_encode(['WHS' => $WHS, 'PARTS' => $PARTS]);
# Write to Logs : Params Sent To M3
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Req-out' ,
'SHDATA'=>'Sent To M3-'.$JSON ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Write to Logs : Params Sent To M3
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Req-out',
'SHDATA' => 'Sent To M3-' . $JSON, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Get Token
// Get Token
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
$tokenData = $tokenResponse->getData();
// dd($IonToken->code);
if($tokenData->code=='200'){
if ($tokenData->code == '200') {
$IonToken = isset($tokenData->token) ? $tokenData->token : '';
}
else{
} else {
$SHDATA = isset($tokenData->message) ? $tokenData->message : '';
# Write to Logs : Error
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=> $SHDATA,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $SHDATA, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return $tokenResponse;
}
# Call ionapi with Params
$endPointURL = env('ENDPOINTURL').'APIFLOWS/Sentinel/M3InventoryReportList?ionapiRespStyle=sync';
$token = $IonToken;
// Call ionapi with Params
$endPointURL = env('ENDPOINTURL') . 'APIFLOWS/Sentinel/M3InventoryReportList?ionapiRespStyle=sync';
$token = $IonToken;
$response = Http::
withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json'
$response = Http::withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json',
])
->withToken($token)
->withBody($JSON, 'application/json')
@@ -99,41 +94,39 @@ class ReplenAPI extends Controller
$responseStatusCode = $response->getStatusCode();
$M3SessionId = $response->hasHeader('x-transaction-id') ? "-sessionID:". $response->header('x-transaction-id') : '-sessionID';
$M3SessionId = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
if ($responseStatusCode =='200') {
# Check M3 Response for Errors
if ($responseStatusCode == '200') {
// Check M3 Response for Errors
$M3Errors = '';
$responseJSON = $response->getBody()->getContents();
$JsonSanytized = Helper::sanityzeString($responseJSON);
# Array
$responseArray = json_decode($JsonSanytized,true);
// Array
$responseArray = json_decode($JsonSanytized, true);
// LOG::info( $responseArray);
$responseTMP = $responseArray['result'];
// LOG::info($responseTMP);
}
else{
} else {
$M3Errors = 'Error: No Response from M3';
}
# Validate response From M3
if ($M3Errors!='') {
# Write to Logs : Error
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.'-'.$M3Errors.$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
// Validate response From M3
if ($M3Errors != '') {
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . '-' . $M3Errors . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Send Response
// Send Response
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Error: No Response from M3'
'code' => '405',
'status' => 'error',
'message' => 'Error: No Response from M3',
]);
}
else{
# Write to Logs : JSON
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> '','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>$responseStatusCode.'-'.$JsonSanytized.$M3SessionId ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
} else {
// Write to Logs : JSON
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => '', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => $responseStatusCode . '-' . $JsonSanytized . $M3SessionId, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
}
@@ -143,152 +136,148 @@ class ReplenAPI extends Controller
$dataToWrite = [];
foreach ($value as $key2 => $content) {
if($key2!='Locations'){
if ($key2 != 'Locations') {
$dataToWrite[$key2] = $content;
}
else{
} else {
foreach ($content as $key3 => $content2) {
//dump($content2);
$dataToWrite2[] = array_merge($dataToWrite,$content2);
// dump($content2);
$dataToWrite2[] = array_merge($dataToWrite, $content2);
}
}
}
}
// LOG::info($dataToWrite2);
# Delete Old Records from IC630M
// Delete Old Records from IC630M
foreach ($dataToWrite2 as $key => $value) {
$ICM630MDeleteSQL = DB::connection(config('m3.connection', 'pgsql'))->table('ic630m')
->where('LLCO',$CO)
->where('LLWHNO',$WHS)
->where('LLPPN',trim($value['PartNumber']))
->where('LLCO', $CO)
->where('LLWHNO', $WHS)
->where('LLPPN', trim($value['PartNumber']))
->delete();
}
foreach ($dataToWrite2 as $key => $value) {
# Check if Location exist in DE640M $value['Location']
// Check if Location exist in DE640M $value['Location']
$DE640MSQLSEL = DB::connection(config('m3.connection', 'pgsql'))->table('de640m')
->where('LVCO',$CO)
->where('WSELOC',$value['Warehouse'])
->where('VLOCID',$value['Location'])
->where('LVCO', $CO)
->where('WSELOC', $value['Warehouse'])
->where('VLOCID', $value['Location'])
->first();
// dd($DE640MSQLSEL);
$LocationExist = isset($DE640MSQLSEL->VLOCID) ? trim($DE640MSQLSEL->VLOCID) : '';
$WHExist = isset($DE640MSQLSEL->WSELOC) ? trim($DE640MSQLSEL->WSELOC) : '';
$COExist = isset($DE640MSQLSEL->LVCO) ? trim($DE640MSQLSEL->LVCO) : '';
$WHExist = isset($DE640MSQLSEL->WSELOC) ? trim($DE640MSQLSEL->WSELOC) : '';
$COExist = isset($DE640MSQLSEL->LVCO) ? trim($DE640MSQLSEL->LVCO) : '';
// dd($LocationExist .': '.$WHExist.': '.$COExist);
# if No records Founds insert New Record
if ( $LocationExist=='' && $WHExist=='' && $COExist=='' ) {
$SQLInsertPrep640M['LVCO'] = $CO; // Company
$SQLInsertPrep640M['WSELOC'] = $value['Warehouse'];
// if No records Founds insert New Record
if ($LocationExist == '' && $WHExist == '' && $COExist == '') {
$SQLInsertPrep640M['LVCO'] = $CO; // Company
$SQLInsertPrep640M['WSELOC'] = $value['Warehouse'];
// $SQLInsertPrep640M['LVUSD3'] = $value['']; // Pallet Size : Not Found in M3 JSON
$SQLInsertPrep640M['VLOCID'] = $value['Location']; // Stock location
$SQLInsertPrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLInsertPrep640M['LVUSD2'] = $value['LocationType'];
$SQLInsertPrep640M['LVZONE'] = $value['Zone']; // Warehouse zone
$SQLInsertPrep640M['LVMAINTTS'] = now(); // Last maintained time stamp
$SQLInsertPrep640M['VLOCID'] = $value['Location']; // Stock location
$SQLInsertPrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLInsertPrep640M['LVUSD2'] = $value['LocationType'];
$SQLInsertPrep640M['LVZONE'] = $value['Zone']; // Warehouse zone
$SQLInsertPrep640M['LVMAINTTS'] = now(); // Last maintained time stamp
DB::connection(config('m3.connection', 'pgsql'))->table('de640m')->insert($SQLInsertPrep640M);
}
# Update
// Update
else {
$SQLUpdatePrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLUpdatePrep640M['LVUSD2'] = $value['LocationType'];
$SQLUpdatePrep640M['LVZONE'] = $value['Zone'];
$SQLUpdatePrep640M['LVMAINTTS'] = now();
$SQLUpdatePrep640M['LVSEQN'] = $value['LocationSeq'];
$SQLUpdatePrep640M['LVUSD2'] = $value['LocationType'];
$SQLUpdatePrep640M['LVZONE'] = $value['Zone'];
$SQLUpdatePrep640M['LVMAINTTS'] = now();
DB::connection(config('m3.connection', 'pgsql'))->table('de640m')
->where('LVCO',$CO)
->where('WSELOC',$value['Warehouse'])
->where('VLOCID',$value['Location'])
->where('LVCO', $CO)
->where('WSELOC', $value['Warehouse'])
->where('VLOCID', $value['Location'])
->update($SQLUpdatePrep640M);
}
# Insert New Records to IC630M
$SQLInsertPrep630M = [];
$SQLInsertPrep630M['LLCO'] = $CO; # Company
$SQLInsertPrep630M['LLWHNO'] = $value['Warehouse']; # Warehouse
$SQLInsertPrep630M['LLPPN'] = $value['PartNumber']; # Part Number
$SQLInsertPrep630M['LLBALANCE'] = $value['Quantity']; # Quantity
$SQLInsertPrep630M['LLSTLC'] = $value['Location']; # Stock location
$SQLInsertPrep630M['LLLTNO'] = $value['LotNumber']; # Lot Number
$SQLInsertPrep630M['LLMAINTTS'] = now(); # Request time timestamp
$SQLInsertPrep630M['LLIZLCF'] = trim($value['LotNumber'])!='' ? '1' : ''; # Lot control flag
$SQLInsertPrep630M['LLSPR10A01'] = $value['Allocation']; # Allocation
$SQLInsertPrep630M['LLSPR15A01'] = $value['AllocatedTo']; # AllocatedTo
// Insert New Records to IC630M
$SQLInsertPrep630M = [];
$SQLInsertPrep630M['LLCO'] = $CO; // Company
$SQLInsertPrep630M['LLWHNO'] = $value['Warehouse']; // Warehouse
$SQLInsertPrep630M['LLPPN'] = $value['PartNumber']; // Part Number
$SQLInsertPrep630M['LLBALANCE'] = $value['Quantity']; // Quantity
$SQLInsertPrep630M['LLSTLC'] = $value['Location']; // Stock location
$SQLInsertPrep630M['LLLTNO'] = $value['LotNumber']; // Lot Number
$SQLInsertPrep630M['LLMAINTTS'] = now(); // Request time timestamp
$SQLInsertPrep630M['LLIZLCF'] = trim($value['LotNumber']) != '' ? '1' : ''; // Lot control flag
$SQLInsertPrep630M['LLSPR10A01'] = $value['Allocation']; // Allocation
$SQLInsertPrep630M['LLSPR15A01'] = $value['AllocatedTo']; // AllocatedTo
$DescSanytized = Helper::sanityzeString($value['Description']);
$DescSanytized = Helper::sanityzeString($value['Description']);
// $DescSanytized = str_replace(['–','\u20131'], '-',$value['Description']);
$SQLInsertPrep630M['LLCMDESC'] = $DescSanytized; // Description
$SQLInsertPrep630M['LLCMDESC'] = $DescSanytized; // Description
DB::connection(config('m3.connection', 'pgsql'))->table('ic630m')->insert($SQLInsertPrep630M);
}
// dump($SQLInsertPrep);
#Send Response
// Send Response
return response()->json([
'code' => '200',
'status' => 'Success'
'code' => '200',
'status' => 'Success',
]);
}
else {
# Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'No URL Parameters Sent','SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS ];
Helper::logToICM699M($data);
} else {
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'No URL Parameters Sent', 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'code' => '405',
'status' => 'Error',
'message'=> 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
}
catch (\Throwable $th) {
# Write to Logs Out : Error
} catch (\Throwable $th) {
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if($getCurlErrors){
if ($getCurlErrors) {
// dd($getCurlErrors);
# Write to Logs Out : Failed
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> 'X','SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=> 'Curl Error: Communication with M3 Timed Out'.' M3-JSN-out'.$IncomingParams,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS];
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'X', 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'Curl Error: Communication with M3 Timed Out' . ' M3-JSN-out' . $IncomingParams, 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Curl Error: Communication with M3 Timed Out.'
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with M3 Timed Out.',
]);
}
else {
# Set SHERROR To Z if Duplicate Key Detected $th
# Read The substring from SHDATA after M3-JSN-out
$SHERROR = 'X';
$word = 'Duplicate key value specified';
$position = strpos($th, $word);
} else {
// Set SHERROR To Z if Duplicate Key Detected $th
// Read The substring from SHDATA after M3-JSN-out
$SHERROR = 'X';
$word = 'Duplicate key value specified';
$position = strpos($th, $word);
if ($position !== false) {
$SHERROR = 'Z';
}
$data = ['SHMACPKR'=>$MACPKR,'SHDT'=> date('Y-m-d'),'SHTIME'=> date('H:i:s') ,'SHERROR'=> $SHERROR,'SHINTBOX'=> '','SHTYPE'=> 'M3-Res-out' ,
'SHDATA'=>'An Error Occured - '.substr($th,0,300) ,'SHUSER'=> $SHUSER,'SHSOURCE'=> $SHSOURCE,'SHCO'=>$CO,'SHWHS'=>$WHS];
$data = ['SHMACPKR' => $MACPKR, 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => $SHERROR, 'SHINTBOX' => '', 'SHTYPE' => 'M3-Res-out',
'SHDATA' => 'An Error Occured - ' . substr($th, 0, 300), 'SHUSER' => $SHUSER, 'SHSOURCE' => $SHSOURCE, 'SHCO' => $CO, 'SHWHS' => $WHS];
Helper::logToICM699M($data);
// Log::error($th);
return response()->json([
'code'=>'405',
'status'=>'error',
'message'=>'Catched Error: '.$th
'code' => '405',
'status' => 'error',
'message' => 'Catched Error: ' . $th,
]);
}
}
}
# End M3InventoryReportReplen
// End M3InventoryReportReplen
}
+199 -205
View File
@@ -2,23 +2,20 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Config;
use DateTime;
use DB;
use Http;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use File;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Str;
class TransferAPI extends Controller
{
# TransferAPIURL : with URL PARAMS
// TransferAPIURL : with URL PARAMS
public function TransferAPIURL(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
@@ -26,68 +23,67 @@ class TransferAPI extends Controller
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
// dd($request->all());
# Get the Calling User
// Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
# Set SHSOURCE
// Set SHSOURCE
$SHSOURCE = 'TransferAPIURL';
$M3Errors = '';
# Get URL PARAMS
// Get URL PARAMS
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$DIVI = isset($urlParams["COMPANY"]) ? $urlParams["COMPANY"] : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$DIVI = isset($urlParams['COMPANY']) ? $urlParams['COMPANY'] : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
try {
if ($urlParams != '') {
$PART = isset($urlParams["PART"]) ? $urlParams["PART"] : '';
$LOCATIONFROM = isset($urlParams["LOCATIONFROM"]) ? $urlParams["LOCATIONFROM"] : '';
$LOCATIONTO = isset($urlParams["LOCATIONTO"]) ? $urlParams["LOCATIONTO"] : '';
$QUANTITY = isset($urlParams["QUANTITY"]) ? $urlParams["QUANTITY"] : '';
$ORDERCATEGORY = isset($urlParams["ORDERCATEGORY"]) ? $urlParams["ORDERCATEGORY"] : '';
$LOTNUMBER = isset($urlParams["LOTNUMBER"]) ? $urlParams["LOTNUMBER"] : "";
$CONUMBER = isset($urlParams["CONUMBER"]) ? $urlParams["CONUMBER"] : '';
$COLINENO = isset($urlParams["COLINENO"]) ? $urlParams["COLINENO"] : '';
$DELIVERYNO = isset($urlParams["DELIVERYNO"]) ? $urlParams["DELIVERYNO"] : '000000';
$PICKLISTSUFFIX = isset($urlParams["PICKLISTSUFFIX"]) ? $urlParams["PICKLISTSUFFIX"] : '';
$ENDFLAG = isset($urlParams["ENDFLAG"]) ? $urlParams["ENDFLAG"] : '';
$TYPE = isset($urlParams["TYPE"]) ? $urlParams["TYPE"] : '';
$COLINESUFFIX = isset($urlParams["COLINESUFFIX"]) ? $urlParams["COLINESUFFIX"] : '';
$PART = isset($urlParams['PART']) ? $urlParams['PART'] : '';
$LOCATIONFROM = isset($urlParams['LOCATIONFROM']) ? $urlParams['LOCATIONFROM'] : '';
$LOCATIONTO = isset($urlParams['LOCATIONTO']) ? $urlParams['LOCATIONTO'] : '';
$QUANTITY = isset($urlParams['QUANTITY']) ? $urlParams['QUANTITY'] : '';
$ORDERCATEGORY = isset($urlParams['ORDERCATEGORY']) ? $urlParams['ORDERCATEGORY'] : '';
$LOTNUMBER = isset($urlParams['LOTNUMBER']) ? $urlParams['LOTNUMBER'] : '';
$CONUMBER = isset($urlParams['CONUMBER']) ? $urlParams['CONUMBER'] : '';
$COLINENO = isset($urlParams['COLINENO']) ? $urlParams['COLINENO'] : '';
$DELIVERYNO = isset($urlParams['DELIVERYNO']) ? $urlParams['DELIVERYNO'] : '000000';
$PICKLISTSUFFIX = isset($urlParams['PICKLISTSUFFIX']) ? $urlParams['PICKLISTSUFFIX'] : '';
$ENDFLAG = isset($urlParams['ENDFLAG']) ? $urlParams['ENDFLAG'] : '';
$TYPE = isset($urlParams['TYPE']) ? $urlParams['TYPE'] : '';
$COLINESUFFIX = isset($urlParams['COLINESUFFIX']) ? $urlParams['COLINESUFFIX'] : '';
# TYPE :
# DeliveryNote
# S15
# CloseShipment
# COCharge
# Replenishment
# Move
# ORDERCATEGORY : Order Category
# 1 = Material to manufacturing order
# 3 = Customer Order
# 4 = Requisition Order
# 5 = Distribution Order
# 9 = Move order
// TYPE :
// DeliveryNote
// S15
// CloseShipment
// COCharge
// Replenishment
// Move
// ORDERCATEGORY : Order Category
// 1 = Material to manufacturing order
// 3 = Customer Order
// 4 = Requisition Order
// 5 = Distribution Order
// 9 = Move order
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$TRANSTYPE = isset($urlParams["TRANSTYPE"]) ? $urlParams["TRANSTYPE"] : ''; # R for Retry
$SHDT = isset($urlParams["SHDT"]) ? $urlParams["SHDT"] : '';
$SHTIME = isset($urlParams["SHTIME"]) ? $urlParams["SHTIME"] : '';
$SHTYPE = isset($urlParams["SHTYPE"]) ? $urlParams["SHTYPE"] : '';
$TRANSTYPE = isset($urlParams['TRANSTYPE']) ? $urlParams['TRANSTYPE'] : ''; // R for Retry
$SHDT = isset($urlParams['SHDT']) ? $urlParams['SHDT'] : '';
$SHTIME = isset($urlParams['SHTIME']) ? $urlParams['SHTIME'] : '';
$SHTYPE = isset($urlParams['SHTYPE']) ? $urlParams['SHTYPE'] : '';
# Retry Transfer
// Retry Transfer
if ($TRANSTYPE == 'R') {
# $t = strtotime($SHTIME);
# $SHTIMEHM = date('H:i',$t);
# dd($SHTIMEHM);
# Get the record that contain the payload
// $t = strtotime($SHTIME);
// $SHTIMEHM = date('H:i',$t);
// dd($SHTIMEHM);
// Get the record that contain the payload
$ICM699MS = DB::connection(config('m3.connection', 'pgsql'))->table('icm699m')
->select('SHDATA')
->where('SHMACPKR', $DELIVERYNO)
->where('SHDT', $SHDT)
->where('SHTIME', $SHTIME)
# ->whereRaw("VARCHAR_FORMAT (TIMESTAMP (CURRENT DATE) + MIDNIGHT_SECONDS (SHTIME) SECONDS, 'HH24:MI') = ?", [$SHTIMEHM])
// ->whereRaw("VARCHAR_FORMAT (TIMESTAMP (CURRENT DATE) + MIDNIGHT_SECONDS (SHTIME) SECONDS, 'HH24:MI') = ?", [$SHTIMEHM])
->where('SHCO', $DIVI)
->where('SHWHS', $WHS)
->where('SHSOURCE', $SHSOURCE)
@@ -96,28 +92,28 @@ class TransferAPI extends Controller
->first();
// dump($ICM699MS->SHDATA);
# Read The substring from SHDATA after M3-JSN-out
// Read The substring from SHDATA after M3-JSN-out
$word = 'M3-JSN-out';
$SHDATA = isset($ICM699MS->SHDATA) ? $ICM699MS->SHDATA : '';
$SHDATAJSON = "";
$SHDATAJSON = '';
$position = strpos($SHDATA, $word);
# Also Read CommTCP_read
// Also Read CommTCP_read
$word2 = 'url:http://127.0.0.1:10005/api/TransferAPIURL?';
$SHDATA2 = isset($ICM699MS->SHDATA) ? $ICM699MS->SHDATA : '';
$position2 = strpos($SHDATA2, $word2);
if ($position !== false) {
$SHDATAJSON = substr($SHDATA, $position + strlen($word));
} else if ($position2 !== false) {
} elseif ($position2 !== false) {
$SHDATAJSONS = substr($SHDATA2, $position2 + strlen($word2));
$SHDATAJSONA = [];
parse_str($SHDATAJSONS, $SHDATAJSONA);
$SHDATAJSON = json_encode($SHDATAJSONA);
}
# Find the position of the opening and closing curly braces
// Find the position of the opening and closing curly braces
$startPos = strpos($SHDATAJSON, '{');
$endPos = strrpos($SHDATAJSON, '}');
# Extract the substring within the curly braces
// Extract the substring within the curly braces
$SHDATAJSON = substr($SHDATAJSON, $startPos, $endPos - $startPos + 1);
// dd($SHDATAJSON);
@@ -130,7 +126,7 @@ class TransferAPI extends Controller
$LOCATIONTO = isset($JSONTR->LOCATIONTO) ? $JSONTR->LOCATIONTO : '';
$QUANTITY = isset($JSONTR->QUANTITY) ? $JSONTR->QUANTITY : '';
$ORDERCATEGORY = isset($JSONTR->ORDERCATEGORY) ? $JSONTR->ORDERCATEGORY : '';
$LOTNUMBER = isset($JSONTR->LOTNUMBER) ? $JSONTR->LOTNUMBER : "";
$LOTNUMBER = isset($JSONTR->LOTNUMBER) ? $JSONTR->LOTNUMBER : '';
$CONUMBER = isset($JSONTR->CONUMBER) ? $JSONTR->CONUMBER : '';
$COLINENO = isset($JSONTR->COLINENO) ? $JSONTR->COLINENO : '';
$DELIVERYNO = isset($JSONTR->DELIVERYNO) ? $JSONTR->DELIVERYNO : '000000';
@@ -141,7 +137,7 @@ class TransferAPI extends Controller
}
// dd($JSONTR);
# Set SHERROR to Z in ICM699M
// Set SHERROR to Z in ICM699M
$ICM699MU = DB::connection(config('m3.connection', 'pgsql'))->table('icm699m')
->where('SHMACPKR', $DELIVERYNO)
->where('SHDT', $SHDT)
@@ -151,13 +147,13 @@ class TransferAPI extends Controller
->where('SHSOURCE', $SHSOURCE)
->where('SHERROR', 'X')
->where('SHTYPE', $SHTYPE)
->update(["SHERROR" => "Z", "SHACKUSER" => $SHUSER, "SHACKDATE" => date('Y-m-d'), "SHACKTIME" => date('H:i:s')]);
->update(['SHERROR' => 'Z', 'SHACKUSER' => $SHUSER, 'SHACKDATE' => date('Y-m-d'), 'SHACKTIME' => date('H:i:s')]);
}
# Part Exists : proceed
// Part Exists : proceed
if ($PART != '') {
# Read from ICM688M2
# Get Parts And Lots from ICM688M2
// Read from ICM688M2
// Get Parts And Lots from ICM688M2
$ICM688M2SLTMP = DB::connection(config('m3.connection', 'pgsql'))->table('icm688m2')
->select('A5BRADLN', 'A5PKSFX', 'A5PLANT', 'A5SENTPKR')
->distinct()
@@ -165,7 +161,7 @@ class TransferAPI extends Controller
->where('A5WHS', $WHS)
->where('A5MACPKR', $DELIVERYNO);
# Get Pack Lines
// Get Pack Lines
if ($COLINENO != '') {
$ICM688M2SLTMP->where('A5PKLN', $COLINENO);
}
@@ -173,48 +169,48 @@ class TransferAPI extends Controller
// dd($ICM688M2SL->A5BRADLN);
$A5BRADLINE = isset($ICM688M2SL->A5BRADLN) ? $ICM688M2SL->A5BRADLN : '';
$COLINESUFFIX = isset($ICM688M2SL->A5PKSFX) ? $ICM688M2SL->A5PKSFX : ''; # Case 551 : $COLINESUFFIX
$COLINESUFFIX = isset($ICM688M2SL->A5PKSFX) ? $ICM688M2SL->A5PKSFX : ''; // Case 551 : $COLINESUFFIX
$A5PLANT = isset($ICM688M2SL->A5PLANT) ? $ICM688M2SL->A5PLANT : '';
$A5SENTPKR = isset($ICM688M2SL->A5SENTPKR) ? $ICM688M2SL->A5SENTPKR : '';
$JSONIN = json_encode([
"DIVI" => $DIVI,
"WHS" => $WHS,
"PART" => $PART,
"LOCATIONFROM" => $LOCATIONFROM,
"LOCATIONTO" => $LOCATIONTO,
"QUANTITY" => $QUANTITY,
"ORDERCATEGORY" => $ORDERCATEGORY,
"LOTNUMBER" => $LOTNUMBER,
"CONUMBER" => $CONUMBER,
"COLINENO" => $COLINENO,
"DELIVERYNO" => $DELIVERYNO,
"PICKLISTSUFFIX" => $PICKLISTSUFFIX,
"ENDFLAG" => $ENDFLAG,
"TYPE" => $TYPE,
"COLINESUFFIX" => $COLINESUFFIX,
'DIVI' => $DIVI,
'WHS' => $WHS,
'PART' => $PART,
'LOCATIONFROM' => $LOCATIONFROM,
'LOCATIONTO' => $LOCATIONTO,
'QUANTITY' => $QUANTITY,
'ORDERCATEGORY' => $ORDERCATEGORY,
'LOTNUMBER' => $LOTNUMBER,
'CONUMBER' => $CONUMBER,
'COLINENO' => $COLINENO,
'DELIVERYNO' => $DELIVERYNO,
'PICKLISTSUFFIX' => $PICKLISTSUFFIX,
'ENDFLAG' => $ENDFLAG,
'TYPE' => $TYPE,
'COLINESUFFIX' => $COLINESUFFIX,
], JSON_UNESCAPED_SLASHES);
$JSON = json_encode([
"DIVI" => $DIVI,
"WHS" => $WHS,
"PART" => $PART,
"LOCATIONFROM" => $LOCATIONFROM,
"LOCATIONTO" => $LOCATIONTO,
"QUANTITY" => $QUANTITY,
"ORDERCATEGORY" => $ORDERCATEGORY,
"LOTNUMBER" => $LOTNUMBER,
"CONUMBER" => $CONUMBER,
"COLINENO" => $A5BRADLINE,
"DELIVERYNO" => $DELIVERYNO,
"PICKLISTSUFFIX" => $PICKLISTSUFFIX,
"ENDFLAG" => $ENDFLAG,
"TYPE" => $TYPE,
"COLINESUFFIX" => $COLINESUFFIX,
'DIVI' => $DIVI,
'WHS' => $WHS,
'PART' => $PART,
'LOCATIONFROM' => $LOCATIONFROM,
'LOCATIONTO' => $LOCATIONTO,
'QUANTITY' => $QUANTITY,
'ORDERCATEGORY' => $ORDERCATEGORY,
'LOTNUMBER' => $LOTNUMBER,
'CONUMBER' => $CONUMBER,
'COLINENO' => $A5BRADLINE,
'DELIVERYNO' => $DELIVERYNO,
'PICKLISTSUFFIX' => $PICKLISTSUFFIX,
'ENDFLAG' => $ENDFLAG,
'TYPE' => $TYPE,
'COLINESUFFIX' => $COLINESUFFIX,
], JSON_UNESCAPED_SLASHES);
// dd($JSON);
# Write JSON Params to Logs Out
// Write JSON Params to Logs Out
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -225,18 +221,18 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Get Token
// Get Token
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if ($tokenData->code == '200') {
$IonToken = isset($tokenData->token) ? $tokenData->token : '';
} else {
$SHDATA = isset($tokenData->message) ? $tokenData->message : '';
# Write to Logs : Error
// Write to Logs : Error
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -247,43 +243,43 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return $tokenResponse;
}
# Call ionapi with Params
// Call ionapi with Params
$endPointURL = env('ENDPOINTURL') . 'APIFLOWS/Sentinel/TransferAPI?ionapiRespStyle=sync';
$token = $IonToken;
$response = Http::withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
])
->withToken($token)
->withBody($JSON, 'application/json')
->timeout(Config::get('arrays.curlTimeOut'))
->post($endPointURL);
$responseStatusCode = $response->getStatusCode();
$M3SessionId = $response->hasHeader('x-transaction-id') ? "-sessionID:" . $response->header('x-transaction-id') : '-sessionID';
$M3ResponseTimeTmp = $response->hasHeader('x-response-time') ? ltrim($response->header('x-response-time'), "-") : '0';
$M3ResponseTimeTmp2 = floatval($M3ResponseTimeTmp) / 1000; //$M3ResponseTimeTmp / 1000;
$dateTime = new DateTime();
$M3SessionId = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
$M3ResponseTimeTmp = $response->hasHeader('x-response-time') ? ltrim($response->header('x-response-time'), '-') : '0';
$M3ResponseTimeTmp2 = floatval($M3ResponseTimeTmp) / 1000; // $M3ResponseTimeTmp / 1000;
$dateTime = new DateTime;
$dateTime->setTimestamp($M3ResponseTimeTmp2);
// dump( $dateTime->format('d/m/Y H:i:s.v') );
$M3ResponseTime = $M3ResponseTimeTmp != '' ? '-M3ResponseTime:' . $dateTime->format('d/m/Y H:i:s.v') : '-M3ResponseTime';
// dump($M3ResponseTime);
$transferStats = $response->transferStats;
$M3transferTime = $transferStats->getTransferTime() != null ? "-M3transferTime:" . $transferStats->getTransferTime() : "-M3transferTime";
$M3transferTime = $transferStats->getTransferTime() != null ? '-M3transferTime:' . $transferStats->getTransferTime() : '-M3transferTime';
// dd($M3transferTime);
if ($responseStatusCode == '200') {
$responseContents = json_decode($response->getBody()->getContents());
$responseResult = $responseContents->result;
$M3JSONResponse = json_encode($responseContents);
# Check M3 Response for Errors
// Check M3 Response for Errors
$M3Errors = Helper::checkM3Errors($responseResult);
} else {
$M3JSONResponse = '';
@@ -291,7 +287,7 @@ class TransferAPI extends Controller
}
if ($M3Errors == '') {
# Write to Logs Out : Success
// Write to Logs Out : Success
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -302,36 +298,36 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Log to ICM799M
// Log to ICM799M
$ICM799MINS = DB::connection(config('m3.connection', 'pgsql'))->table('icm799m')
->insert(["IMDIV" => $DIVI,
"IMPLANT" => $A5PLANT,
"IMWHS" => $WHS,
"IMSENTPKR" => $A5SENTPKR,
"IMDELNO" => $DELIVERYNO,
"IMORDER" => $CONUMBER,
"IMLINE" => $COLINENO,
"IMBRADLN" => $A5BRADLINE,
"IMSUFFIX" => $PICKLISTSUFFIX,
"IMPART" => $PART,
"IMLOT" => $LOTNUMBER,
"IMQTY" => $QUANTITY,
"IMFRLOC" => $LOCATIONFROM,
"IMTOLOC" => $LOCATIONTO,
"IMDATE" => date('Ymd'),
"IMTIME" => date('His')
->insert(['IMDIV' => $DIVI,
'IMPLANT' => $A5PLANT,
'IMWHS' => $WHS,
'IMSENTPKR' => $A5SENTPKR,
'IMDELNO' => $DELIVERYNO,
'IMORDER' => $CONUMBER,
'IMLINE' => $COLINENO,
'IMBRADLN' => $A5BRADLINE,
'IMSUFFIX' => $PICKLISTSUFFIX,
'IMPART' => $PART,
'IMLOT' => $LOTNUMBER,
'IMQTY' => $QUANTITY,
'IMFRLOC' => $LOCATIONFROM,
'IMTOLOC' => $LOCATIONTO,
'IMDATE' => date('Ymd'),
'IMTIME' => date('His'),
]);
return response()->json([
'code' => $responseStatusCode,
'status' => 'Success'
'status' => 'Success',
]);
} else {
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -343,28 +339,28 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '206',
'status' => 'Error',
'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . ' Order Category: ' . $ORDERCATEGORY . '-' . $M3JSONResponse
'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . ' Order Category: ' . $ORDERCATEGORY . '-' . $M3JSONResponse,
]);
}
}
# Part Does not Exist : Failure
// Part Does not Exist : Failure
else {
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'Json Payload Not Valid, possible cause: Retry butto was clicked by another user.'
'message' => 'Json Payload Not Valid, possible cause: Retry butto was clicked by another user.',
]);
}
} else {
# Write to Logs Out : Error
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
@@ -376,22 +372,22 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
} catch (\Throwable $th) {
// Log::error($th);
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if ($getCurlErrors) {
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -402,17 +398,17 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with M3 Timed Out.'
'message' => 'Curl Error: Communication with M3 Timed Out.',
]);
} else {
# Write to Logs Out : Error
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
@@ -424,7 +420,7 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
Log::error($th);
@@ -432,15 +428,15 @@ class TransferAPI extends Controller
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Uncaught Error'
'message' => 'Uncaught Error',
]);
}
}
}
# End TransferAPIURL
// End TransferAPIURL
# UpdateShipmentNumber : with URL PARAMS
// UpdateShipmentNumber : with URL PARAMS
public function UpdateShipmentNumber(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
@@ -448,29 +444,29 @@ class TransferAPI extends Controller
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
// dd($request->all());
# Get the Calling User
// Get the Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
# Set SHSOURCE
// Set SHSOURCE
$SHSOURCE = 'UpdateShipmentNumber';
$M3Errors = '';
# Get URL PARAMS
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$DIVI = isset($urlParams["COMPANY"]) ? $urlParams["COMPANY"] : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$PLANT = isset($urlParams["PLANT"]) ? $urlParams["PLANT"] : '';
// Get URL PARAMS
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$DIVI = isset($urlParams['COMPANY']) ? $urlParams['COMPANY'] : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
$PLANT = isset($urlParams['PLANT']) ? $urlParams['PLANT'] : '';
// dump($urlParams);
try {
if ($urlParams != '') {
$A4SPR15A01 = isset($urlParams["A4SPR15A01"]) ? $urlParams["A4SPR15A01"] : '';
$DELIVERYNO = isset($urlParams["DELIVERYNO"]) ? $urlParams["DELIVERYNO"] : '';
$TYPE = 'UpdateShipmentNumber';
$A4SPR15A01 = isset($urlParams['A4SPR15A01']) ? $urlParams['A4SPR15A01'] : '';
$DELIVERYNO = isset($urlParams['DELIVERYNO']) ? $urlParams['DELIVERYNO'] : '';
$TYPE = 'UpdateShipmentNumber';
$allMacpkrs = [];
// dd($A4SPR15A01);
if ($A4SPR15A01 != '') {
# Read from ICM688M1
// Read from ICM688M1
$ICM688M1SLTMP = DB::connection(config('m3.connection', 'pgsql'))->table('icm688m1')
->select('A4MACPKR')
->where('A4CO', $DIVI)
@@ -478,34 +474,33 @@ class TransferAPI extends Controller
->where('A4PLANT', $PLANT)
->where('A4SPR15A01', $A4SPR15A01);
# Get Macpikers also if sent as Parameter
// Get Macpikers also if sent as Parameter
if ($DELIVERYNO != '') {
$ICM688M1SLTMP->where('A4MACPKR', $DELIVERYNO);
}
$ICM688M1SL = $ICM688M1SLTMP->get();
# Loop ICM688M1 to get all A4MACPKR
// Loop ICM688M1 to get all A4MACPKR
foreach ($ICM688M1SL as $key => $ICM688M1) {
$allMacpkrs[] = $ICM688M1->A4MACPKR;
}
}
# A4SPR15A01 Exists : proceed
if ($A4SPR15A01 != '' && count($allMacpkrs)>0) {
// A4SPR15A01 Exists : proceed
if ($A4SPR15A01 != '' && count($allMacpkrs) > 0) {
$JSON = json_encode([
"DIVI" => $DIVI,
"WHS" => $WHS,
"ShipmentNumber" => [
"Number" => $A4SPR15A01,
"DeliveryNumbers" => $allMacpkrs
'DIVI' => $DIVI,
'WHS' => $WHS,
'ShipmentNumber' => [
'Number' => $A4SPR15A01,
'DeliveryNumbers' => $allMacpkrs,
],
"TYPE" => $TYPE,
"ENDFLAG" => "",
'TYPE' => $TYPE,
'ENDFLAG' => '',
], JSON_UNESCAPED_SLASHES);
// dd($JSON);
# Write JSON Params to Logs Out
// Write JSON Params to Logs Out
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -516,18 +511,18 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Get Token
// Get Token
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if ($tokenData->code == '200') {
$IonToken = isset($tokenData->token) ? $tokenData->token : '';
} else {
$SHDATA = isset($tokenData->message) ? $tokenData->message : '';
# Write to Logs : Error
// Write to Logs : Error
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -538,40 +533,40 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return $tokenResponse;
}
# Call ionapi with Params
// Call ionapi with Params
$endPointURL = env('ENDPOINTURL') . 'APIFLOWS/Sentinel/TransferAPI?ionapiRespStyle=sync';
$token = $IonToken;
$response = Http::withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
])
->withToken($token)
->withBody($JSON, 'application/json')
->timeout(Config::get('arrays.curlTimeOut'))
->post($endPointURL);
$responseStatusCode = $response->getStatusCode();
$M3SessionId = $response->hasHeader('x-transaction-id') ? "-sessionID:" . $response->header('x-transaction-id') : '-sessionID';
$M3ResponseTimeTmp = $response->hasHeader('x-response-time') ? ltrim($response->header('x-response-time'), "-") : '0';
$M3ResponseTimeTmp2 = floatval($M3ResponseTimeTmp) / 1000; //$M3ResponseTimeTmp / 1000;
$dateTime = new DateTime();
$M3SessionId = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
$M3ResponseTimeTmp = $response->hasHeader('x-response-time') ? ltrim($response->header('x-response-time'), '-') : '0';
$M3ResponseTimeTmp2 = floatval($M3ResponseTimeTmp) / 1000; // $M3ResponseTimeTmp / 1000;
$dateTime = new DateTime;
$dateTime->setTimestamp($M3ResponseTimeTmp2);
$M3ResponseTime = $M3ResponseTimeTmp != '' ? '-M3ResponseTime:' . $dateTime->format('d/m/Y H:i:s.v') : '-M3ResponseTime';
$transferStats = $response->transferStats;
$M3transferTime = $transferStats->getTransferTime() != null ? "-M3transferTime:" . $transferStats->getTransferTime() : "-M3transferTime";
$M3transferTime = $transferStats->getTransferTime() != null ? '-M3transferTime:' . $transferStats->getTransferTime() : '-M3transferTime';
if ($responseStatusCode == '200') {
$responseContents = json_decode($response->getBody()->getContents());
$responseResult = $responseContents->result;
$M3JSONResponse = json_encode($responseContents);
# Check M3 Response for Errors
// Check M3 Response for Errors
$M3Errors = Helper::checkM3Errors($responseResult);
} else {
$M3JSONResponse = '';
@@ -579,7 +574,7 @@ class TransferAPI extends Controller
}
if ($M3Errors == '') {
# Write to Logs Out : Success
// Write to Logs Out : Success
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -590,16 +585,16 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => $responseStatusCode,
'status' => 'Success'
'status' => 'Success',
]);
} else {
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -611,29 +606,28 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '206',
'status' => 'Error',
'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . '-' . $M3JSONResponse
'message' => $responseStatusCode . '-' . $M3Errors . '- TYPE :' . $TYPE . '-' . $M3JSONResponse,
]);
}
}
# A4SPR15A01 Does not Exist : Failure
// A4SPR15A01 Does not Exist : Failure
else {
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'Json Payload Not Valid, missing Parameter or no Macpicker # found.'
'message' => 'Json Payload Not Valid, missing Parameter or no Macpicker # found.',
]);
}
}
else {
# Write to Logs Out : Error
} else {
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
@@ -645,22 +639,22 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
} catch (\Throwable $th) {
// Log::error($th);
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if ($getCurlErrors) {
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -671,17 +665,17 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with M3 Timed Out.'
'message' => 'Curl Error: Communication with M3 Timed Out.',
]);
} else {
# Write to Logs Out : Error
// Write to Logs Out : Error
$DELIVERYNO = isset($DELIVERYNO) ? $DELIVERYNO : '000000';
$data = ['SHMACPKR' => $DELIVERYNO,
'SHDT' => date('Y-m-d'),
@@ -693,7 +687,7 @@ class TransferAPI extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $DIVI,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
Log::error($th);
@@ -701,12 +695,12 @@ class TransferAPI extends Controller
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Uncaught Error'
'message' => 'Uncaught Error',
]);
}
}
}
# End UpdateShipmentNumber
// End UpdateShipmentNumber
}
+74 -79
View File
@@ -2,23 +2,18 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Config;
use DB;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use File;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Str;
class TwoShipAPIs extends Controller
{
# TwoShipUpdateHold with URL Params
// TwoShipUpdateHold with URL Params
public function TwoShipUpdateHold(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
@@ -28,23 +23,23 @@ class TwoShipAPIs extends Controller
// dd($request->all());
// Log::info( $request->all() );
# Get The Calling User
// Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$SHSOURCE = 'TwoShipUpdateHold';
$TwoShipErrors = '';
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$CO = isset($urlParams["COMPANY"]) ? $urlParams["COMPANY"] : '';
$MACPKR = isset($urlParams["MACPKR"]) ? $urlParams["MACPKR"] : '';
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
$CO = isset($urlParams['COMPANY']) ? $urlParams['COMPANY'] : '';
$MACPKR = isset($urlParams['MACPKR']) ? $urlParams['MACPKR'] : '';
try {
if ($urlParams != '') {
$IncomingParams = ['CO' => $CO, 'WHS' => $WHS, 'MACPKR' => $MACPKR];
$IncomingParams = json_encode($IncomingParams);
# Write to Logs : Params In
// Write to Logs : Params In
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -55,37 +50,36 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# First Step : Get MACPKRs list if available
# select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr=233709) and a4shpaggcd<>0 and a4concmplt<>'y' and a4co=410 and a4whs=111
// First Step : Get MACPKRs list if available
// select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr=233709) and a4shpaggcd<>0 and a4concmplt<>'y' and a4co=410 and a4whs=111
$A4MACPKRSel = DB::connection(config('m3.connection', 'pgsql'))->select(
"select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr={$MACPKR})
and a4shpaggcd<>0 and a4concmplt<>'y' and a4co='{$CO}' and a4whs='{$WHS}' "
and a4shpaggcd<>0 and a4concmplt<>'y' and a4co='{$CO}' and a4whs='{$WHS}' ",
);
// dd($A4MACPKRSel);
if (count($A4MACPKRSel)>0){
if (count($A4MACPKRSel) > 0) {
foreach ($A4MACPKRSel as $key => $A4MACPKRR) {
$A4MACPKRArr[] = $A4MACPKRR->A4MACPKR;
$A4MACPKRArr[] = $A4MACPKRR->A4MACPKR;
}
}
else{
} else {
$A4MACPKRArr[] = $MACPKR;
}
// dump($A4MACPKRArr);
# Call 2ship API with Params
// Call 2ship API with Params
$WS_key = Config::get('arrays.2Ship.TwoShip_Key');
$end_point = Config::get('arrays.2Ship.end_point');
$API = Config::get('arrays.2Ship.hold_update');
$ShipOnHoldOrder_url = $end_point . $API;
# Build Json Data
// Build Json Data
$data = [
'WS_Key' => $WS_key,
'OrderNumbers' => [implode(',', $A4MACPKRArr)],
@@ -103,82 +97,82 @@ class TwoShipAPIs extends Controller
// dump($json_string);
#######
# Initialise the cURL var
// ######
// Initialise the cURL var
$ch = curl_init();
# Get the response from cURL
// Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $ShipOnHoldOrder_url);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
#When CURLOPT_SSL_VERIFYPEER is enabled (value=1), and the verification fails to prove that the certificate is authentic, the connection fails.
#When the option is zero, the peer certificate verification succeeds regardless.
// When CURLOPT_SSL_VERIFYPEER is enabled (value=1), and the verification fails to prove that the certificate is authentic, the connection fails.
// When the option is zero, the peer certificate verification succeeds regardless.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
#When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that the server is the server to which you meant to connect,
#or the connection fails. Simply put, it means it has to have the same name in the certificate as is in the URL you operate against.
// When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that the server is the server to which you meant to connect,
// or the connection fails. Simply put, it means it has to have the same name in the certificate as is in the URL you operate against.
# Set data content type
// Set data content type
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
[
'Content-Type: application/json',
'Content-Length: ' . strlen($json_string)
)
'Content-Length: ' . strlen($json_string),
],
);
# Post data
// Post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
# Set timeout
// Set timeout
curl_setopt($ch, CURLOPT_TIMEOUT, Config::get('arrays.PHPTimeOut'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::get('arrays.PHPTimeOut'));
# if set true, cURL will follow redirects
// if set true, cURL will follow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
# Execute the request
// Execute the request
$response = curl_exec($ch);
# Verifying error
// Verifying error
$info = curl_getinfo($ch);
# Get status
// Get status
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
# Output the error code
# $CurlError= curl_error($ch);
$CurlError = str_replace("'", " ", curl_error($ch));
// Output the error code
// $CurlError= curl_error($ch);
$CurlError = str_replace("'", ' ', curl_error($ch));
# Close the session
// Close the session
unset($ch);
// dump($response);
// dump($status);
// dump($CurlError);
if ($status == '200' && $CurlError=='') {
if ($status == '200' && $CurlError == '') {
$responseJSON = json_decode($response);
// dump($responseJSON);
if($responseJSON->Success==false){
$TwoShipErrors = '2Ship Error: '.$responseJSON->GlobalError;
if ($responseJSON->Success == false) {
$TwoShipErrors = '2Ship Error: ' . $responseJSON->GlobalError;
}
} else {
$TwoShipErrors = 'Error: No Response from 2Ship';
$TwoShipErrors .= ' -Curl Error: '.$CurlError;
$TwoShipErrors .= ' -Curl Error: ' . $CurlError;
}
# Validate response From 2Ship
# Error
// Validate response From 2Ship
// Error
if ($TwoShipErrors != '') {
// dump($TwoShipErrors);
# Write to Logs : Error
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -189,20 +183,20 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Send Response
// Send Response
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Status: '.$status . '-' . $TwoShipErrors
'message' => 'Status: ' . $status . '-' . $TwoShipErrors,
]);
}
# Success
else{
# Write to Logs : JSON
// Success
else {
// Write to Logs : JSON
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -213,27 +207,28 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Update ICM688M1 set a4concmplt to 'y'
// Update ICM688M1 set a4concmplt to 'y'
DB::connection(config('m3.connection', 'pgsql'))->table('icm688m1')
->whereIn('A4MACPKR',$A4MACPKRArr)
->where('A4CO',$CO)
->where('A4WHS',$WHS)
->update(['A4CONCMPLT'=>'Y']);
->whereIn('A4MACPKR', $A4MACPKRArr)
->where('A4CO', $CO)
->where('A4WHS', $WHS)
->update(['A4CONCMPLT' => 'Y']);
}
# Send Response
// Send Response
return response()->json([
'code' => '200',
'status' => 'Success'
'status' => 'Success',
]);
}
# Error : No URL params
// Error : No URL params
else {
# Write to Logs Out : Error
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
@@ -245,23 +240,23 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
} catch (\Throwable $th) {
# Write to Logs Out : Error
// Write to Logs Out : Error
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if ($getCurlErrors) {
// dd($getCurlErrors);
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -272,17 +267,17 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with 2Ship Timed Out.'
'message' => 'Curl Error: Communication with 2Ship Timed Out.',
]);
}
}
}
# End TwoShipUpdateHold
// End TwoShipUpdateHold
}