Files
WMS/Modules/M3/Http/Controllers/M3CallCloseAPIController.php
T
2026-09-16 17:16:25 +01:00

106 lines
4.6 KiB
PHP

<?php
namespace Modules\M3\Http\Controllers;
use Artisan;
use Config;
use DB;
use Illuminate\Http\Request;
use Log;
class M3CallCloseAPIController extends Controller
{
public static function index(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'));
try {
// Get the Calling User
// Get URL PARAMS
$urlParams = count($request->all()) > 0 ? $request->all() : '';
// dd($urlParams);
$SHUSER = isset($urlParams['SHUSER']) ? $urlParams['SHUSER'] : '';
$MANIFEST = isset($urlParams['MANIFEST']) ? $urlParams['MANIFEST'] : '';
$APCO = isset($urlParams['APCO']) ? $urlParams['APCO'] : '';
$APWHS = isset($urlParams['APWHS']) ? $urlParams['APWHS'] : '';
if ($MANIFEST != '' && $APCO != '' && $APWHS != '') { // $SHUSER!='' &&
// Log::channel('dailyCron')->info("Cron...Start CallCloseAPI...For user:".$SHUSER." Manifest#: ".$MANIFEST);
// Get Logged User CO & WH
// Get users from ICM428M
// $ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
// ->select('R428US','R428CO', 'R428WH')
// ->where('R428US','=',$SHUSER)
// ->first();
// $R428US = isset($ICM428M->R428US) ? $ICM428M->R428US : '';
// $USERCO = isset($ICM428M->R428CO) ? $ICM428M->R428CO : '';
// $USERWH = isset($ICM428M->R428WH) ? $ICM428M->R428WH : '';
// dump($R428US.':'.$USERCO.':'.$USERWH);
// Get Macpickers from ICM705M1
// SELECT APMANIFEST FROM ICM705M1 WHERE APSPARE2='' AND APCO='110' AND APWHS='321'
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->select('APMANIFEST', 'APCO', 'APWHS')
->where('APSPARE2', '')
->where('APCO', $APCO)
->where('APWHS', $APWHS)
->where('APMANIFEST', '=', $MANIFEST)
->whereRaw('EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - APLDCLOZ)) / 60 > 15')
->orderBy('APMANIFEST')
->get();
// dump($ICM705M1);
if (count($ICM705M1) > 0) {
// Loop the Results from $ICM705M1
foreach ($ICM705M1 as $key => $ICM705M1R) {
// Send CO and WHS to CallCloseAPI
$USERCO = isset($ICM705M1R->APCO) ? $ICM705M1R->APCO : '';
$USERWH = isset($ICM705M1R->APWHS) ? $ICM705M1R->APWHS : '';
$callCloseShipment = Artisan::call('command:CallCloseAPI', ['user' => $SHUSER, 'manifest' => $ICM705M1R->APMANIFEST,
'co' => $USERCO, 'whs' => $USERWH]);
// dump($callCloseShipment);
if ($callCloseShipment == 1) {
return response()->json([
'code' => '200',
'status' => 'Success',
'message' => 'Manifest Closing submitted',
]);
} else {
return response()->json([
'code' => '206',
'status' => 'Failure',
'message' => 'Manifest Closing Failed',
]);
}
}
} else {
Log::channel('dailyCron')->info('Manifest CloseAPI: No records found in ICM705M1...');
return response()->json([
'code' => '206',
'status' => 'Error',
'message' => 'Manifest CloseAPI: No records found in ICM705M1...',
]);
}
} else {
Log::channel('dailyCron')->error('Manifest CloseAPI: A User and Manifest must be defined...');
return response()->json([
'code' => '206',
'status' => 'Error',
'message' => 'Manifest CloseAPI: A User and Manifest must be defined...',
]);
}
} catch (\Throwable $th) {
Log::error($th);
}
}
}