M3 Integration fixes pass 20
This commit is contained in:
@@ -26,8 +26,10 @@ class M3Controller extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function index() { dd('Index'); }
|
||||
public function create() {}
|
||||
public function index()
|
||||
{
|
||||
dd('Index');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
@@ -165,9 +167,15 @@ class M3Controller extends Controller
|
||||
|
||||
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];
|
||||
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
|
||||
@@ -180,18 +188,24 @@ class M3Controller extends Controller
|
||||
|
||||
private function callUpdateProgram(array $c, array $json): void
|
||||
{
|
||||
if ($c['warehouse'] === '' || $c['picker'] === '' || $c['company'] === '') return;
|
||||
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();
|
||||
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');
|
||||
if ($error !== '') {
|
||||
$this->log($c, $error . self::M3_LIST_SUFFIX . json_encode($json), 'X', 'M3-Lis-spl');
|
||||
}
|
||||
}
|
||||
|
||||
private function programConnectionError(\Throwable $e): string
|
||||
@@ -297,10 +311,6 @@ class M3Controller extends Controller
|
||||
'GS1Label' => ['A1SPR1A01', 1, 'string'],
|
||||
'CurrencyExchangeRate' => ['A1EXGRATE', 18, 'DEC'],
|
||||
|
||||
]; }
|
||||
|
||||
public function show($id) {}
|
||||
public function edit($id) {}
|
||||
public function update(Request $request, $id) {}
|
||||
public function destroy($id) {}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Str;
|
||||
|
||||
class TransferAPI extends Controller
|
||||
{
|
||||
use TransferApiSupport;
|
||||
private const ZERO_PAD = '000000';
|
||||
private const JSON_CONTENT_TYPE = 'application/json';
|
||||
private const ORDER_CATEGORY_LABEL = ' Order Category: ';
|
||||
@@ -47,13 +48,6 @@ class TransferAPI extends Controller
|
||||
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'));
|
||||
}
|
||||
|
||||
private function transferContext(Request $request): array
|
||||
{
|
||||
$params = $request->all();
|
||||
@@ -137,31 +131,6 @@ class TransferAPI extends Controller
|
||||
->update(['SHERROR' => 'Z', 'SHACKUSER' => $context['user'], 'SHACKDATE' => date('Y-m-d'), 'SHACKTIME' => date('H:i:s')]);
|
||||
}
|
||||
|
||||
private function retryPayload(string $data): array
|
||||
{
|
||||
$json = '';
|
||||
$marker = 'M3-JSN-out';
|
||||
$urlMarker = 'url:http://127.0.0.1:10005/api/TransferAPIURL?';
|
||||
$position = strpos($data, $marker);
|
||||
$urlPosition = strpos($data, $urlMarker);
|
||||
|
||||
if ($position !== false) {
|
||||
$json = substr($data, $position + strlen($marker));
|
||||
} elseif ($urlPosition !== false) {
|
||||
parse_str(substr($data, $urlPosition + strlen($urlMarker)), $payload);
|
||||
return is_array($payload) ? $payload : [];
|
||||
}
|
||||
|
||||
$start = strpos($json, '{');
|
||||
$end = strrpos($json, '}');
|
||||
if ($start === false || $end === false || $end < $start) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$decoded = json_decode(substr($json, $start, $end - $start + 1), true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
private function executeTransfer(array &$context)
|
||||
{
|
||||
$line = $this->transferLine($context);
|
||||
@@ -281,17 +250,6 @@ class TransferAPI extends Controller
|
||||
return ['status' => $status, 'json' => $jsonResponse, 'errors' => $errors, 'metrics' => $this->responseMetrics($response)];
|
||||
}
|
||||
|
||||
private function responseMetrics($response): string
|
||||
{
|
||||
$session = $response->hasHeader('x-transaction-id') ? '-sessionID:' . $response->header('x-transaction-id') : '-sessionID';
|
||||
$raw = $response->hasHeader('x-response-time') ? ltrim($response->header('x-response-time'), '-') : '0';
|
||||
$dateTime = new DateTime;
|
||||
$dateTime->setTimestamp(floatval($raw) / 1000);
|
||||
$responseTime = $raw !== '' ? '-M3ResponseTime:' . $dateTime->format('d/m/Y H:i:s.v') : '-M3ResponseTime';
|
||||
$transfer = $response->transferStats->getTransferTime();
|
||||
return $session . $responseTime . ($transfer !== null ? '-M3transferTime:' . $transfer : '-M3transferTime');
|
||||
}
|
||||
|
||||
private function transferResult(array $c, array $result)
|
||||
{
|
||||
$prefix = $result['status'] . 'TYPE :' . $c['type'] . self::ORDER_CATEGORY_LABEL . $c['order_category'] . '-';
|
||||
@@ -344,8 +302,4 @@ class TransferAPI extends Controller
|
||||
return response()->json(['code' => '405', 'status' => 'error', 'message' => 'Uncaught Error']);
|
||||
}
|
||||
|
||||
private function errorResponse(string $code, string $message)
|
||||
{
|
||||
return response()->json(['code' => $code, 'status' => 'Error', 'message' => $message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\M3\Http\Controllers\API;
|
||||
|
||||
use Config;
|
||||
|
||||
trait TransferApiSupport
|
||||
{
|
||||
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'));
|
||||
}
|
||||
|
||||
private function retryPayload(string $data): array
|
||||
{
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
private function responseMetrics($response): string
|
||||
{
|
||||
return json_encode([
|
||||
'status' => $response->status(),
|
||||
'successful' => $response->successful(),
|
||||
'failed' => $response->failed(),
|
||||
'clientError' => $response->clientError(),
|
||||
'serverError' => $response->serverError(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function errorResponse(string $code, string $message)
|
||||
{
|
||||
return response()->json([
|
||||
'code' => $code,
|
||||
'status' => 'error',
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user