145 lines
5.6 KiB
PHP
145 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\M3\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Modules\M3\Http\Controllers\Controller;
|
|
use DB;
|
|
use Config;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Log;
|
|
use Str;
|
|
|
|
use Modules\M3\Http\Controllers\API\CloseShipment;
|
|
|
|
class CallCloseAPI extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'command:CallCloseAPI {user?} {manifest?} {co?} {whs?} ';
|
|
|
|
protected $description = 'Call Close API';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
//$this->info('Start CallCloseAPI...');
|
|
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
|
|
$userId = $this->argument('user');
|
|
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
|
|
|
|
# Get the Manifest Number
|
|
$manifest = $this->argument('manifest');
|
|
$MANIFESTNum = isset($manifest) ? $manifest : '';
|
|
$co = $this->argument('co');
|
|
$APCO = isset($co) ? $co : '';
|
|
$whs = $this->argument('whs');
|
|
$APWHS = isset($whs) ? $whs : '';
|
|
|
|
// if ($SHUSER!='') {
|
|
// Log::channel('dailyCron')->info("Cron...Start CallCloseAPI...For Manifest#: ".$MANIFESTNum); // ".$SHUSER."
|
|
|
|
if( $MANIFESTNum==''){
|
|
# Get Macpickers from ICM705M1
|
|
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
|
->select('APMANIFEST','APCO','APWHS')
|
|
->where('APSPARE2','')
|
|
->where('APMANIFEST','!=','0')
|
|
->whereRaw('EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - APLDCLOZ)) / 60 > 15')
|
|
->orderBy('APMANIFEST','desc')
|
|
->get();
|
|
// dump($ICM705M1);
|
|
|
|
if (count($ICM705M1)>0) {
|
|
# Loop the Results from $ICM705M1
|
|
foreach ($ICM705M1 as $key => $ICM705M1R) {
|
|
$MANIFESTNum = $ICM705M1R->APMANIFEST;
|
|
|
|
$USERCO = isset($ICM705M1R->APCO) ? $ICM705M1R->APCO : '';
|
|
$USERWH = isset($ICM705M1R->APWHS) ? $ICM705M1R->APWHS : '';
|
|
|
|
# Update ICM705M1 and set APSPARE2 to P
|
|
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
|
->where('APMANIFEST',$MANIFESTNum)
|
|
->where('APCO',$USERCO)
|
|
->where('APWHS',$USERWH)
|
|
->update(["APSPARE2"=>"P"]);
|
|
|
|
$myRequest = new Request();
|
|
$myRequest->setMethod('POST');
|
|
$myRequest->request->add([
|
|
'WHS' => $USERWH,
|
|
'COMPANY' => $USERCO,
|
|
'TRANSTYPE' => 'M',
|
|
'MANIFEST' => $MANIFESTNum
|
|
]);
|
|
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
|
|
$responseData = $callCloseShipment->getData();
|
|
$jsonData = json_encode($responseData);
|
|
Log::channel('dailyCron')->info("Close Shipment API Response for Manifest:".(string)(int)$MANIFESTNum.'-'.$jsonData);
|
|
}
|
|
}
|
|
}
|
|
# Call Closing for a specific Manifest
|
|
else{
|
|
# Get Macpickers from ICM705M1
|
|
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
|
->select('APMANIFEST','APCO','APWHS')
|
|
->where('APSPARE2','')
|
|
->where('APCO',$APCO)
|
|
->where('APWHS',$APWHS)
|
|
->where('APMANIFEST','=',$MANIFESTNum)
|
|
->first();
|
|
|
|
# Update ICM705M1 and set APSPARE2 to P
|
|
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
|
->where('APMANIFEST',$MANIFESTNum)
|
|
->where('APCO',$APCO)
|
|
->where('APWHS',$APWHS)
|
|
->update(["APSPARE2"=>"P"]);
|
|
|
|
$myRequest = new Request();
|
|
$myRequest->setMethod('POST');
|
|
|
|
$myRequest->request->add([
|
|
'WHS' => $APWHS ,
|
|
'COMPANY' => $APCO,
|
|
'TRANSTYPE' => 'M',
|
|
'MANIFEST' => $MANIFESTNum
|
|
]);
|
|
|
|
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
|
|
$responseData = $callCloseShipment->getData();
|
|
$jsonData = json_encode($responseData);
|
|
Log::channel('dailyCron')->info("Close Shipment API Response for Manifest:".$MANIFESTNum.'-'.$jsonData);
|
|
return 1;
|
|
}
|
|
// }
|
|
// else{
|
|
// Log::channel('dailyCron')->error('A user must be defined...');
|
|
|
|
// $this->error('A user must be defined...');
|
|
// }
|
|
|
|
}
|
|
catch (\Throwable $th) {
|
|
// Log::error($th);
|
|
Log::channel('dailyCron')->error($th);
|
|
}
|
|
}
|
|
}
|