536 lines
28 KiB
PHP
Executable File
536 lines
28 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\M3\Http\Controllers\API;
|
|
|
|
use Config;
|
|
use DB;
|
|
use Illuminate\Http\Request;
|
|
use Modules\M3\Helpers\Helper;
|
|
use Modules\M3\Http\Controllers\Controller;
|
|
use Modules\M3\Services\PostgresProgramBridge;
|
|
use Str;
|
|
|
|
class M3Controller extends Controller
|
|
{
|
|
private const FIELD_PREFIX = 'Field: ';
|
|
|
|
private const M3_LIST_SUFFIX = ' M3-Lis-JSN';
|
|
|
|
// Split Data and Write to ICM666M2
|
|
public function insertToICM666M2($dataSplit, $commentData)
|
|
{
|
|
|
|
$commentDataSS = explode("\n", $dataSplit);
|
|
$aXLINENO = 1;
|
|
foreach ($commentDataSS as $substring) {
|
|
// Process each substring
|
|
$fullData = $commentData;
|
|
$fullData['AXCOMMENT'] = $substring;
|
|
$fullData['AXLINENO'] = $aXLINENO;
|
|
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()
|
|
{
|
|
// This API controller does not expose a create form.
|
|
}
|
|
|
|
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'] : '';
|
|
$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];
|
|
|
|
switch ($aXDOCUMENT) {
|
|
case 'Picker':
|
|
$picker = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
if ($picker != 'null') {
|
|
$this->insertToICM666M2($picker, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Packer':
|
|
$packer = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
if ($packer != 'null') {
|
|
$this->insertToICM666M2($packer, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Carrier':
|
|
$carrier = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
if ($carrier != 'null') {
|
|
$this->insertToICM666M2($carrier, $commentData);
|
|
}
|
|
break;
|
|
|
|
case 'Other':
|
|
$other = isset($comment) ? Helper::sanityzeString($comment) : 'null';
|
|
if ($other != 'null') {
|
|
$this->insertToICM666M2($other, $commentData);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get Products : commodities And Write ICM666M
|
|
$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'] : '';
|
|
$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'] : '';
|
|
$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'] : '';
|
|
$sonar_pallet_qty = 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,
|
|
'OrderClass' => $orderClass,
|
|
'LocationType' => $locationType,
|
|
'PallSize' => $pallSize,
|
|
'MasterCarton' => $masterCarton,
|
|
'MasterQty' => $masterQty,
|
|
'InnerQty' => $innerQty,
|
|
'PalletQty' => $sonar_pallet_qty,
|
|
'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]) {
|
|
if (! $lengthTest[413]) {
|
|
$message[] = ['code' => '413', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is larger then expected'];
|
|
}
|
|
if (! $lengthTest[411]) {
|
|
$message[] = ['code' => '411', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is empty'];
|
|
}
|
|
if (! $lengthTest[417]) {
|
|
$message[] = ['code' => '417', 'status' => 'error', 'message' => self::FIELD_PREFIX . $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) . self::M3_LIST_SUFFIX . json_encode($jsonFile), 'SHUSER' => $rEQKPKUS, 'SHSOURCE' => $sHSOURCE, 'SHCO' => $company, 'SHWHS' => $warehouse];
|
|
Helper::logToICM699M($data);
|
|
|
|
return response()->json($message);
|
|
} elseif ($fieldValue != '') {
|
|
$insertArray[$value[0]] = $fieldValue;
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
|
|
// }
|
|
|
|
// SQL Insert to ICM666M
|
|
DB::connection(config('m3.connection', 'pgsql'))->table('icm666m')->insert($insertArray);
|
|
}
|
|
|
|
// Call PGM ICM700CSBM
|
|
if ($warehouse != '' && $pickerNumber != '' && $company != '') {
|
|
$pGMERRORS = '';
|
|
|
|
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
|
|
try {
|
|
$conn = app(PostgresProgramBridge::class);
|
|
} catch (\Throwable $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 = [];
|
|
|
|
// 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);
|
|
|
|
// Start Time Tracking
|
|
|
|
// 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 . self::M3_LIST_SUFFIX . 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) . self::M3_LIST_SUFFIX . json_encode($jsonFile), 'SHUSER' => $rEQKPKUS, 'SHSOURCE' => $sHSOURCE, 'SHCO' => $company, 'SHWHS' => $warehouse];
|
|
Helper::logToICM699M($data);
|
|
|
|
return response()->json([
|
|
'code' => '405',
|
|
'status' => 'error',
|
|
'message' => 'An Error Occured...',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
// This resource endpoint is intentionally unsupported.
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
// This resource endpoint is intentionally unsupported.
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
// This resource endpoint is intentionally unsupported.
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
// This resource endpoint is intentionally unsupported.
|
|
}
|
|
}
|