M3 Integration fixes pass 20

This commit is contained in:
Mark Gregory
2026-09-22 13:03:06 +01:00
parent 5be9e9dbc8
commit 90e6c80a61
2 changed files with 520 additions and 1096 deletions
+204 -433
View File
@@ -13,53 +13,220 @@ 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)
$line = 1;
foreach (explode("\n", $dataSplit) as $substring) {
$data = $commentData;
$data['AXCOMMENT'] = $substring;
$data['AXLINENO'] = $line++;
DB::connection(config('m3.connection', 'pgsql'))->table('icm666m2')->insert($data);
}
}
public function index()
{
dd('Index');
}
public function create()
{
// This API controller does not expose a create form.
}
public function index() { dd('Index'); }
public function create() {}
public function store(Request $request)
{
$this->configureTimeouts();
$user = m3User() !== '' ? Str::upper(m3User()) : 'WEBUSER';
$json = $request->json()->all();
$context = $this->rootContext($json, $user);
try {
$response = $json === [] ? $this->emptyPayloadResponse($context) : $this->processPayload($json, $context);
} catch (\Throwable $throwable) {
$response = $this->exceptionResponse($context, $json, $throwable);
}
return $response;
}
private function configureTimeouts(): void
{
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 = m3User() !== '' ? Str::upper(m3User()) : 'WEBUSER';
$sHSOURCE = 'M3ReceiverAPI';
private function rootContext(array $json, string $user): array
{
$carrier = $json['CarrierCode'] ?? '';
if (($carrier === '' || $carrier === null) && ($json['Warehouse'] ?? '') === '111' && ($json['Company'] ?? '') === '410' && ($json['Plant'] ?? '') === '410') {
$carrier = 'BWAY';
}
return [
'user' => $user, 'source' => 'M3ReceiverAPI', 'company' => $json['Company'] ?? '', 'plant' => $json['Plant'] ?? '',
'warehouse' => $json['Warehouse'] ?? '', 'order' => $json['OrderNumber'] ?? '', 'picker' => $json['PickerNumber'] ?? '',
'prom_date' => $json['PromDate'] ?? '', 'route' => $json['RouteCode'] ?? '', 'category' => $json['OrderCategory'] ?? '',
'release' => $json['ReleaseNumber'] ?? '', 'shipment' => $json['ShipmentNumber'] ?? '', 'currency' => $json['Currency'] ?? '',
'carrier' => $carrier, 'po' => $json['ShipmentPONumber'] ?? '', 'terms' => $json['ShipTerms'] ?? '',
'order_class' => $json['OrderClass'] ?? '', 'gs1' => $json['GS1-128Label'] ?? '0', 'exchange' => $json['CurrencyExchangeRate'] ?? '',
'macpkr' => ($json['PickerNumber'] ?? '') !== '' ? $json['PickerNumber'] : '000000',
];
}
$iCM666MFields = [
private function processPayload(array $json, array $context)
{
$recipient = $this->recipient($json['Recipient'] ?? []);
$this->storeComments($json['Comments'] ?? [], $context);
$validation = $this->storeProducts($json['Contents']['Commodities'] ?? [], $context, $recipient, $json);
if ($validation !== null) {
return $validation;
}
$this->callUpdateProgram($context, $json);
$this->log($context, json_encode($json), '', 'M3-Lis-in');
return response()->json(['code' => '200', 'status' => 'success', 'message' => 'File Received, DB Updated']);
}
private function recipient(array $recipient): array
{
return [
'CompanyName' => $recipient['CompanyName'] ?? '', 'Address1' => $recipient['Address1'] ?? '', 'Address2' => $recipient['Address2'] ?? '',
'Address3' => $recipient['Address3'] ?? '', 'Address4' => $recipient['Address4'] ?? '', 'City' => $recipient['City'] ?? '',
'State' => $recipient['State'] ?? '', 'PostalCode' => $recipient['PostalCode'] ?? '', 'Country' => $recipient['Country'] ?? '',
'CountryName' => $recipient['CountryName'] ?? '', 'BillToId' => $recipient['BillToId'] ?? '', 'ShipToId' => $recipient['ShipToId'] ?? '',
'PersonName' => $recipient['PersonName'] ?? '', 'AccountNo' => $recipient['AccountNo'] ?? '', 'Email' => $recipient['Email'] ?? '',
];
}
private function storeComments(array $comments, array $c): void
{
foreach ($comments as $document => $comment) {
$document = Helper::sanityzeString($document);
if (! in_array($document, ['Picker', 'Packer', 'Carrier', 'Other'], true)) {
continue;
}
$text = Helper::sanityzeString($comment ?? 'null');
if ($text === 'null') {
continue;
}
$this->insertToICM666M2($text, [
'AXCO' => $c['company'], 'AXPLANT' => $c['plant'], 'AXWHS' => $c['warehouse'], 'AXDELNO' => $c['picker'],
'AXONO' => $c['order'], 'AXRLNO' => $c['release'], 'AXSHNO' => $c['shipment'], 'AXDOCUMENT' => $document,
]);
}
}
private function storeProducts(array $products, array $c, array $recipient, array $json)
{
foreach ($products as $product) {
$values = $this->productValues($product, $c, $recipient, $json);
[$insert, $messages] = $this->validatedInsert($values);
if ($messages !== []) {
$this->log($c, json_encode($messages) . self::M3_LIST_SUFFIX . json_encode($json), 'X', 'M3-Lis-spl');
return response()->json($messages);
}
$this->enrichProduct($insert, $c, (string) ($product['PartNumber'] ?? ''));
DB::connection(config('m3.connection', 'pgsql'))->table('icm666m')->insert($insert);
}
return null;
}
private function productValues(array $p, array $c, array $r, array $json): array
{
return array_merge($r, [
'Company' => $c['company'], 'Warehouse' => $c['warehouse'], 'Plant' => $c['plant'], 'PickerNumber' => $c['picker'],
'OrderNumber' => $c['order'], 'ReleaseNumber' => $c['release'], 'ShipmentNumber' => $c['shipment'],
'OrderLine' => $p['OrderLine'] ?? '', 'PartNumber' => $p['PartNumber'] ?? '',
'Description' => isset($p['Description']) ? Str::limit($p['Description'], 25, '') : '', 'Quantity' => $p['Quantity'] ?? '',
'BaseUnitPrice' => $p['BaseUnitPrice'] ?? '', 'Currency' => $c['currency'], 'Zone' => $p['Zone'] ?? '', 'PromDate' => $c['prom_date'],
'RouteCode' => $c['route'], 'PartWeight' => $p['PartWeight'] ?? '', 'SellUOM' => $p['SellUOM'] ?? '', 'PartConv' => $p['PartConv'] ?? '',
'CarrierCode' => $c['carrier'], 'ShipVia' => $json['ShipVia'] ?? '', 'PrimaryLocation' => $p['PrimaryLocation'] ?? '',
'Allocation' => $p['Allocation'] ?? '', 'AllocatedTo' => $p['AllocatedTo'] ?? '', 'LocationSeq' => $p['LocationSeq'] ?? '',
'UOM' => $p['UOM'] ?? '', 'HazMat' => $p['HazMat'] ?? '', 'PartUPC' => $p['PartUPC'] ?? '', 'PartEAN' => $p['PartEAN'] ?? '',
'LotFlag' => $p['LotFlag'] ?? '', 'ManOrd' => $p['ManOrd'] ?? '', 'LotNumber' => $p['LotNumber'] ?? '', 'ProductArea' => $p['ProductArea'] ?? '',
'FreightClass' => $p['FreightClass'] ?? '', 'ShipmentPONumber' => $c['po'], 'ShipmentPOLine' => $p['ShipmentPOLine'] ?? '',
'ShipTerms' => $c['terms'], 'OrderClass' => $c['order_class'], 'LocationType' => $p['LocationType'] ?? '', 'PallSize' => $p['PallSize'] ?? '',
'MasterCarton' => $p['MasterCarton'] ?? '', 'MasterQty' => $p['MasterQty'] ?? '', 'InnerQty' => $p['InnerQty'] ?? '',
'PalletQty' => $p['PalletQty'] ?? '', 'CartonQty' => $p['CartonQty'] ?? '', 'OrderCategory' => $c['category'],
'A1DATEADD' => date('Ymd'), 'A1TIMEADD' => date('His'), 'KitPartNumber' => $p['KitPartNumber'] ?? '',
'OrderLineSuffix' => $p['OrderLineSuffix'] ?? '', 'CustomerPartNumber' => isset($p['CustomerPartNumber']) ? substr($p['CustomerPartNumber'], 0, 20) : '',
'GS1Label' => $c['gs1'], 'CurrencyExchangeRate' => $c['exchange'],
]);
}
private function validatedInsert(array $values): array
{
$insert = []; $messages = [];
foreach ($this->fieldDefinitions() as $key => $definition) {
$value = Helper::sanityzeString($values[$key] ?? '');
$test = Helper::checkLength($value, $definition[1], $definition[2]);
$this->appendValidationMessages($messages, $key, $definition[2], $test);
if ($value !== '') {
$insert[$definition[0]] = $value;
}
}
return [$insert, $messages];
}
private function appendValidationMessages(array &$messages, string $key, string $type, array $test): void
{
if (! ($test[413] ?? false)) $messages[] = ['code' => '413', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is larger then expected'];
if (! ($test[411] ?? false)) $messages[] = ['code' => '411', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . ' is empty'];
if (! ($test[417] ?? false)) $messages[] = ['code' => '417', 'status' => 'error', 'message' => self::FIELD_PREFIX . $key . 'type is different then Expected type: ' . $type];
}
private function enrichProduct(array &$insert, array $c, string $part): void
{
$row = DB::connection(config('m3.connection', 'pgsql'))->table('icm709m')->select()
->where('AT9CO', $c['company'])->where('AT9PLT', $c['plant'])->where('AT9WHS', $c['warehouse'])->where('AT9PART', $part)->first();
$insert['A1USRN01'] = $row->AT9QTY ?? 0;
$insert['A1MATWRN'] = $row->AT9WRN ?? '';
}
private function callUpdateProgram(array $c, array $json): void
{
if ($c['warehouse'] === '' || $c['picker'] === '' || $c['company'] === '') return;
$error = '';
try {
$conn = app(PostgresProgramBridge::class);
$conn->setOptions(['persistent' => false, 'stateless' => true, 'debug' => true, 'debugLogFile' => env('TOOLKIT_DEBUG_LOG')]);
$params = [$conn->addParameterChar('in', 3, 'Company', '', $c['company']), $conn->addParameterChar('in', 3, 'Warehouse', '', $c['warehouse'])];
$params[] = $conn->addParameterChar('in', 11, 'PickerNumber', '', ltrim(strval($c['picker']), '0'));
if (! $conn->pgmCall('ICM700CSBM', env('OBJLIB'), $params, [], [])) $error = 'Error calling program. Code: ' . $conn->getErrorCode() . ' - Msg: ' . $conn->getErrorMsg();
} catch (\Throwable $e) {
$error = $this->programConnectionError($e);
}
if ($error !== '') $this->log($c, $error . self::M3_LIST_SUFFIX . json_encode($json), 'X', 'M3-Lis-spl');
}
private function programConnectionError(\Throwable $e): string
{
return match ((int) $e->getCode()) {
8001 => 'Could not connect due to wrong user or password.',
42705 => 'Database not found. Try WRKRDBDIRE to check.',
default => 'Could not connect. Error: ' . $e->getCode() . ' ' . $e->getMessage(),
};
}
private function emptyPayloadResponse(array $c)
{
$data = 'No Json File Found...';
Helper::logToICM699M(['SHMACPKR' => $c['macpkr'], 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => 'Z', 'SHINTBOX' => '',
'SHTYPE' => 'M3-Lis-in', 'SHDATA' => $data, 'SHUSER' => $c['user'], 'SHSOURCE' => $c['source'], 'SHCO' => $c['company'], 'SHWHS' => $c['warehouse'],
'SHACKNOTE' => 'Sentinel automatically closed the error related to this empty data set sent by M3']);
return response()->json(['code' => '415', 'status' => 'error', 'message' => 'No Json File Found']);
}
private function exceptionResponse(array $c, array $json, \Throwable $th)
{
$this->log($c, 'General Catchable Error - ' . substr((string) $th, 0, 300) . self::M3_LIST_SUFFIX . json_encode($json), 'X', 'M3-Lis-in');
return response()->json(['code' => '405', 'status' => 'error', 'message' => 'An Error Occured...']);
}
private function log(array $c, string $message, string $error, string $type): void
{
Helper::logToICM699M(['SHMACPKR' => $c['macpkr'], 'SHDT' => date('Y-m-d'), 'SHTIME' => date('H:i:s'), 'SHERROR' => $error, 'SHINTBOX' => '',
'SHTYPE' => $type, 'SHDATA' => $message, 'SHUSER' => $c['user'], 'SHSOURCE' => $c['source'], 'SHCO' => $c['company'], 'SHWHS' => $c['warehouse']]);
}
private function fieldDefinitions(): array
{
return [
'Company' => ['A1CO', 3, 'string'],
'Warehouse' => ['A1WHS', 3, 'string'],
'Plant' => ['A1PLANT', 3, 'string'],
@@ -130,406 +297,10 @@ class M3Controller extends Controller
'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.
}
public function show($id) {}
public function edit($id) {}
public function update(Request $request, $id) {}
public function destroy($id) {}
}
File diff suppressed because it is too large Load Diff