M3 Integration fixes
This commit is contained in:
Executable
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\M3\Console;
|
||||
|
||||
use Config;
|
||||
use DB;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Modules\M3\Http\Controllers\API\CloseShipment;
|
||||
|
||||
class CallCloseAPI extends Command
|
||||
{
|
||||
protected $signature = 'command:CallCloseAPI {user?} {manifest?} {co?} {whs?} ';
|
||||
|
||||
protected $description = 'Call Close API';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
self::configureTimeouts();
|
||||
try {
|
||||
$manifest = (string) ($this->argument('manifest') ?? '');
|
||||
if ($manifest !== '') {
|
||||
return $this->closeSpecificManifest($manifest, (string) ($this->argument('co') ?? ''), (string) ($this->argument('whs') ?? ''));
|
||||
}
|
||||
$this->closePendingManifests();
|
||||
|
||||
return self::SUCCESS;
|
||||
} catch (\Throwable $th) {
|
||||
Log::channel('dailyCron')->error($th);
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
private static function configureTimeouts(): void
|
||||
{
|
||||
$timeout = Config::get('arrays.PHPTimeOut');
|
||||
ini_set('max_execution_time', $timeout);
|
||||
ini_set('max_input_time', $timeout);
|
||||
ini_set('default_socket_timeout', $timeout);
|
||||
}
|
||||
|
||||
private function closePendingManifests(): void
|
||||
{
|
||||
$rows = 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();
|
||||
foreach ($rows as $row) {
|
||||
$this->closeManifest((string) $row->APMANIFEST, (string) ($row->APCO ?? ''), (string) ($row->APWHS ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
private function closeSpecificManifest(string $manifest, string $co, string $whs): int
|
||||
{
|
||||
$exists = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->where('APSPARE2', '')->where('APCO', $co)->where('APWHS', $whs)->where('APMANIFEST', $manifest)->exists();
|
||||
if (! $exists) {
|
||||
Log::channel('dailyCron')->warning('Manifest not available for close', compact('manifest', 'co', 'whs'));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
$this->closeManifest($manifest, $co, $whs);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function closeManifest(string $manifest, string $co, string $whs): void
|
||||
{
|
||||
DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
|
||||
->where('APMANIFEST', $manifest)->where('APCO', $co)->where('APWHS', $whs)->update(['APSPARE2' => 'P']);
|
||||
$request = Request::create('', 'POST', ['WHS' => $whs, 'COMPANY' => $co, 'TRANSTYPE' => 'M', 'MANIFEST' => $manifest]);
|
||||
$response = CloseShipment::CloseShipmentCoChargeAPI($request);
|
||||
$json = json_encode($response->getData());
|
||||
Log::channel('dailyCron')->info('Close Shipment API Response for Manifest:' . $manifest . '-' . $json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user