537 lines
28 KiB
PHP
537 lines
28 KiB
PHP
<?php
|
|
|
|
namespace Modules\M3\Http\Controllers\API;
|
|
|
|
use Config;
|
|
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
|
|
public function insertToICM666M2($dataSplit, $commentData)
|
|
{
|
|
// dump($commentData);
|
|
// dump($dataSplit);
|
|
|
|
$commentDataSS = explode("\n", $dataSplit);
|
|
$AXLINENO = 1;
|
|
foreach ($commentDataSS as $substring) {
|
|
// Process each substring
|
|
$fullData = $commentData;
|
|
$fullData['AXCOMMENT'] = $substring;
|
|
$fullData['AXLINENO'] = $AXLINENO;
|
|
// dump($fullData);
|
|
$insertSQL = DB::connection(config('m3.connection', 'pgsql'))->table('icm666m2')->insert($fullData);
|
|
|
|
$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)
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
dd('Index');
|
|
}
|
|
|
|
public function create() {}
|
|
|
|
public function store(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'));
|
|
|
|
$REQKPKUS = m3_user() !== '' ? Str::upper(m3_user()) : 'WEBUSER';
|
|
$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'],
|
|
// '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'],
|
|
|
|
];
|
|
|
|
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'] : '';
|
|
// $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'] : '';
|
|
|
|
// 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';
|
|
|
|
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');
|
|
|
|
// 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 = isset($jsonFile['Comments']) ? $jsonFile['Comments'] : '';
|
|
|
|
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];
|
|
// dump($commentData);
|
|
|
|
switch ($AXDOCUMENT) {
|
|
case 'Picker':
|
|
$Picker = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
// dump($Picker);
|
|
if ($Picker != 'null') {
|
|
$this->insertToICM666M2($Picker, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Packer':
|
|
$Packer = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
// dump($Packer);
|
|
if ($Packer != 'null') {
|
|
$this->insertToICM666M2($Packer, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Carrier':
|
|
$Carrier = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
// dump($Carrier);
|
|
if ($Carrier != 'null') {
|
|
$this->insertToICM666M2($Carrier, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Other':
|
|
$Other = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
// dump($Other);
|
|
if ($Other != 'null') {
|
|
$this->insertToICM666M2($Other, $commentData);
|
|
}
|
|
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
|
|
|
|
// Initialise Table Fields to be filled
|
|
$InsertArray = [];
|
|
$fieldValues = [
|
|
'Company' => $Company,
|
|
'Warehouse' => $Warehouse,
|
|
'Plant' => $Plant,
|
|
'PickerNumber' => $PickerNumber,
|
|
'OrderNumber' => $OrderNumber,
|
|
'ReleaseNumber' => $ReleaseNumber,
|
|
'ShipmentNumber' => $ShipmentNumber,
|
|
'OrderLine' => $OrderLine,
|
|
'PartNumber' => $PartNumber,
|
|
'Description' => $Description,
|
|
'Quantity' => $Quantity,
|
|
'BaseUnitPrice' => $BaseUnitPrice,
|
|
'Currency' => $Currency,
|
|
'Zone' => $Zone,
|
|
'PromDate' => $PromDate,
|
|
'RouteCode' => $RouteCode,
|
|
'BillToId' => $BillToId,
|
|
'ShipToId' => $ShipToId,
|
|
'CompanyName' => $CompanyName,
|
|
'Address1' => $Address1,
|
|
'Address2' => $Address2,
|
|
'Address3' => $Address3,
|
|
'Address4' => $Address4,
|
|
'City' => $City,
|
|
'State' => $State,
|
|
'PostalCode' => $PostalCode,
|
|
'Country' => $Country,
|
|
'CountryName' => $CountryName,
|
|
'PartWeight' => $PartWeight,
|
|
'SellUOM' => $SellUOM,
|
|
'PartConv' => $PartConv,
|
|
'CarrierCode' => $CarrierCode,
|
|
'ShipVia' => $ShipVia,
|
|
'PrimaryLocation' => $PrimaryLocation,
|
|
'Allocation' => $Allocation,
|
|
'AllocatedTo' => $AllocatedTo,
|
|
'LocationSeq' => $LocationSeq,
|
|
'UOM' => $UOM,
|
|
'HazMat' => $HazMat,
|
|
'PartUPC' => $PartUPC,
|
|
'PartEAN' => $PartEAN,
|
|
'LotFlag' => $LotFlag,
|
|
'ManOrd' => $ManOrd,
|
|
'LotNumber' => $LotNumber,
|
|
'ProductArea' => $ProductArea,
|
|
'FreightClass' => $FreightClass,
|
|
'ShipmentPONumber' => $ShipmentPONumber,
|
|
'ShipmentPOLine' => $ShipmentPOLine,
|
|
'ShipTerms' => $ShipTerms,
|
|
'ExchangeRate' => $ExchangeRate,
|
|
'OrderClass' => $OrderClass,
|
|
'LocationType' => $LocationType,
|
|
'PallSize' => $PallSize,
|
|
'MasterCarton' => $MasterCarton,
|
|
'MasterQty' => $MasterQty,
|
|
'InnerQty' => $InnerQty,
|
|
'PalletQty' => $PalletQty,
|
|
'CartonQty' => $CartonQty,
|
|
'PersonName' => $PersonName,
|
|
'AccountNo' => $AccountNo,
|
|
'Email' => $Email,
|
|
'OrderCategory' => $OrderCategory,
|
|
'A1DATEADD' => $A1DATEADD,
|
|
'A1TIMEADD' => $A1TIMEADD,
|
|
'KitPartNumber' => $KitPartNumber,
|
|
'OrderLineSuffix' => $OrderLineSuffix,
|
|
'CustomerPartNumber' => $CustomerPartNumber,
|
|
'GS1Label' => $GS1Label,
|
|
'CurrencyExchangeRate' => $CurrencyExchangeRate,
|
|
];
|
|
|
|
// Check JSON fields if empty or > DB Fields
|
|
foreach ($ICM666MFields as $key => $value) {
|
|
// Sanitize String
|
|
$fieldValue = Helper::sanityzeString($fieldValues[$key] ?? '');
|
|
// Check Var Types & Length
|
|
$LengthTest = Helper::checkLength($fieldValue, $value[1], $value[2]);
|
|
|
|
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[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]];
|
|
}
|
|
|
|
// 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);
|
|
} elseif ($fieldValue != '') {
|
|
$InsertArray[$value[0]] = $fieldValue;
|
|
}
|
|
}
|
|
// Log::info($InsertArray);
|
|
|
|
// Check ICM709M
|
|
$ICM709MSEL = DB::connection(config('m3.connection', 'pgsql'))->table('icm709m')
|
|
->select()
|
|
->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
|
|
$InsertArray['A1USRN01'] = $palletQty;
|
|
|
|
// Hazard Material
|
|
$HazMat = isset($ICM709MSEL->AT9WRN) ? $ICM709MSEL->AT9WRN : '';
|
|
$InsertArray['A1MATWRN'] = $HazMat;
|
|
|
|
// if ($PalletQty!='') {
|
|
// $InsertArray['A1USRN01']=$palletQty;
|
|
// }
|
|
|
|
// SQL Insert to ICM666M
|
|
$insertSQL = DB::connection(config('m3.connection', 'pgsql'))->table('icm666m')->insert($InsertArray);
|
|
}
|
|
|
|
// Call PGM ICM700CSBM
|
|
if ($Warehouse != '' && $PickerNumber != '' && $Company != '') {
|
|
$PGMERRORS = '';
|
|
$AWREQN = '';
|
|
|
|
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
|
|
try {
|
|
$conn = app(PostgresProgramBridge::class);
|
|
} catch (\Exception $e) {
|
|
// Determine reason for failure.
|
|
// Probably database authentication error or invalid or unreachable database.
|
|
$code = $e->getCode();
|
|
$msg = $e->getMessage();
|
|
|
|
switch ($code) {
|
|
case 8001:
|
|
// "Authorization failure on distributed database connection attempt"
|
|
// Usually means a wrong DB2 user or password
|
|
$PGMERRORS = 'Could not connect due to wrong user or password.';
|
|
break;
|
|
case 42705:
|
|
$PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
|
|
break;
|
|
default:
|
|
$PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
|
|
break;
|
|
}
|
|
}
|
|
$conn->setOptions(['persistent' => false, 'stateless' => true, 'debug' => true, 'debugLogFile' => env('TOOLKIT_DEBUG_LOG')]);
|
|
|
|
// Add LIB
|
|
// $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)');
|
|
|
|
// define several input/output params
|
|
$params = [];
|
|
// $params[] = $conn->AddParameterChar('out',7,'eqNumber');
|
|
|
|
// AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension)
|
|
// Add Warehouse Param
|
|
$params[] = $conn->AddParameterChar('in', 3, 'Company', '', $Company);
|
|
|
|
$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);
|
|
// $params[] = $conn->AddParameterZoned('in', 11, 0, 'ParamIn');
|
|
|
|
// Start Time Tracking
|
|
$start = microtime(true);
|
|
|
|
// ICM700C EWOBJTST ICM700C ICM700CSBM
|
|
$result = $conn->PgmCall('ICM700CSBM', env('OBJLIB'), $params, [], []);
|
|
|
|
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];
|
|
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];
|
|
Helper::logToICM699M($data);
|
|
|
|
return response()->json([
|
|
'code' => '200',
|
|
'status' => 'success',
|
|
'message' => 'File Received, DB Updated',
|
|
]);
|
|
} 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];
|
|
Helper::logToICM699M($data);
|
|
|
|
return response()->json([
|
|
'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);
|
|
|
|
// Log::error($th);
|
|
return response()->json([
|
|
'code' => '405',
|
|
'status' => 'error',
|
|
'message' => 'An Error Occured...',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function show($id) {}
|
|
|
|
public function edit($id) {}
|
|
|
|
public function update(Request $request, $id) {}
|
|
|
|
public function destroy($id) {}
|
|
}
|