mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
update packinglists from vt portal jobs and schedule
This commit is contained in:
@@ -14,6 +14,8 @@ class FetchContainersStatusUpdateFromVTPortalJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
|
||||
@@ -15,6 +15,8 @@ class FetchDeliveryListFromVTPortalJob implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
|
||||
@@ -16,16 +16,16 @@ class FetchLoadedContainersFromVTPortalJob implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @return void
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function handle(?Carbon $start = null, ?Carbon $end = null)
|
||||
public function handle()
|
||||
{
|
||||
(App()->make(FetchLoadedContainersFromVTPortalProcessor::class))->execute($start, $end);
|
||||
(App()->make(FetchLoadedContainersFromVTPortalProcessor::class))->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ class FetchPackingListFromVTPortalJob implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
|
||||
@@ -16,16 +16,16 @@ class FetchWarehouseReceiveListFromVTPortalJob implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @return void
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function handle(?Carbon $start = null, ?Carbon $end = null)
|
||||
public function handle()
|
||||
{
|
||||
(App()->make(FetchWarehouseReceiveListFromVTPortalProcessor::class))->execute($start, $end);
|
||||
(App()->make(FetchWarehouseReceiveListFromVTPortalProcessor::class))->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class ListOrdersLogic extends AbstractControllerLogic
|
||||
{
|
||||
$this->canListOrders->passes();
|
||||
|
||||
$query = $this->listsOrders->execute($this->listsOrders->deserializeFilters($request->input('filters')));
|
||||
$query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true]));
|
||||
|
||||
return $this->collectionResponse(OrderResource::collection($query));
|
||||
|
||||
|
||||
@@ -54,9 +54,10 @@ class FetchesDataFromVTPortal
|
||||
]
|
||||
);
|
||||
|
||||
$request = $client->request($method, $url, [\GuzzleHttp\RequestOptions::JSON => $body]);
|
||||
$request = $client->requestAsync($method, $url, [\GuzzleHttp\RequestOptions::JSON => $body, 'timeout' => 1200]);
|
||||
|
||||
return $request->wait();
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,7 @@ class FetchesDataFromVTPortal
|
||||
|
||||
$latest_cookie = [];
|
||||
$cookieRequest = new \GuzzleHttp\Client(['cookies' => true]);
|
||||
|
||||
$cookieRequest->get('https://portalvt.azurewebsites.net');
|
||||
foreach ($cookieRequest->getConfig('cookies')->toArray() as $key => $row) {
|
||||
$latest_cookie[] = $row['Name'] . '=' . $row['Value'];
|
||||
|
||||
+7
@@ -128,6 +128,13 @@ class FetchLoadedContainersFromVTPortalProcessor
|
||||
|
||||
DB::beginTransaction();
|
||||
$start = $start ? $start : Carbon::now()->subMonth();
|
||||
|
||||
$startLimit = Carbon::parse('11-08-2021');
|
||||
|
||||
if($start->isBefore($startLimit)){
|
||||
$start = $startLimit;
|
||||
}
|
||||
|
||||
$end = $end ? $end : Carbon::now();
|
||||
$filter = '["LoadedTime:$between$%js%\"'.$start->format('Y-m-d').'T00:00:00.000\"$and$%js%\"'.$end->format('Y-m-d').'T00:00:00.000\"\u0000"]';
|
||||
|
||||
|
||||
+82
-74
@@ -30,6 +30,7 @@ use App\Models\Transport;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchWarehouseReceiveListFromVTPortalProcessor
|
||||
{
|
||||
@@ -108,110 +109,117 @@ class FetchWarehouseReceiveListFromVTPortalProcessor
|
||||
* @param Carbon|null $end
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null){
|
||||
|
||||
DB::beginTransaction();
|
||||
$start = $start ? $start : Carbon::now()->subMonth();
|
||||
$end = $end ? $end : Carbon::now();
|
||||
$filter = '["ParcelDate:$between$%js%\"'.$start->format('Y-m-d').'T00:00:00.000\"$and$%js%\"'.$end->format('Y-m-d').'T00:00:00.000\"\u0000"]';
|
||||
try {
|
||||
|
||||
$warehouseListRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"WarehouseList","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
|
||||
$start = $start ? $start : Carbon::now()->subMonth();
|
||||
|
||||
$response = $this->fetchesDataFRomVTPortal->getResponseBody($warehouseListRequest);
|
||||
$startLimit = Carbon::parse('11-08-2021');
|
||||
|
||||
foreach ($response->Rows as $parcel){
|
||||
$marking = explode('/', explode('CIEF/', $parcel[5])[1]);
|
||||
|
||||
if(!array_key_exists(1, $marking)){
|
||||
continue;
|
||||
if($start->isBefore($startLimit)){
|
||||
$start = $startLimit;
|
||||
}
|
||||
|
||||
$orderNumber = $marking[1];
|
||||
$end = $end ? $end : Carbon::now();
|
||||
$filter = '["ParcelDate:$between$%js%\"'.$start->format('Y-m-d').'T00:00:00.000\"$and$%js%\"'.$end->format('Y-m-d').'T00:00:00.000\"\u0000"]';
|
||||
|
||||
if(!$parcel[9]){
|
||||
continue;
|
||||
}
|
||||
$warehouseListRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"WarehouseList","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
|
||||
|
||||
try {
|
||||
$order = $this->fetchesOrder->execute(['reference' => $orderNumber]);
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
$response = $this->fetchesDataFRomVTPortal->getResponseBody($warehouseListRequest);
|
||||
|
||||
$oldOrder = OldOrders::where('marking', '=', $orderNumber)->first();
|
||||
foreach ($response->Rows as $parcel){
|
||||
$marking = explode('/', explode('CIEF/', $parcel[5])[1]);
|
||||
|
||||
if(!$oldOrder){
|
||||
if(!array_key_exists(1, $marking)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$customerMarking = str_replace(' ', '', str_replace('/', '', str_replace('CIEF/', '', $oldOrder->company->marking)));
|
||||
$orderNumber = $marking[1];
|
||||
|
||||
$companyModule = CompanyModule::whereHas('inviters', function($query) use ($customerMarking) {
|
||||
return $query->where('invitee_reference', '=', $customerMarking);
|
||||
})->first();
|
||||
|
||||
if(!$companyModule) {
|
||||
if(!$parcel[9]){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$oldOrder->address) {
|
||||
continue;
|
||||
try {
|
||||
$order = $this->fetchesOrder->execute(['reference' => $orderNumber]);
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
|
||||
$oldOrder = OldOrders::where('marking', '=', $orderNumber)->first();
|
||||
|
||||
if(!$oldOrder){
|
||||
continue;
|
||||
}
|
||||
|
||||
$customerMarking = str_replace(' ', '', str_replace('/', '', str_replace('CIEF/', '', $oldOrder->company->marking)));
|
||||
|
||||
$companyModule = CompanyModule::whereHas('inviters', function($query) use ($customerMarking) {
|
||||
return $query->where('invitee_reference', '=', $customerMarking);
|
||||
})->first();
|
||||
|
||||
if(!$companyModule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$oldOrder->address) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var Address $address */
|
||||
$address = $this->createAddressFromOldAddressProcessor->execute($oldOrder->address, $companyModule);
|
||||
|
||||
if(!$address){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$warehouseId = $parcel[0];
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $warehouseId === 11 ? 3 : 4]);
|
||||
|
||||
$order = $this->createOrderProcessor->execute($companyModule->company, $originWarehouse, $address, $orderNumber);
|
||||
}
|
||||
|
||||
/** @var Address $address */
|
||||
$address = $this->createAddressFromOldAddressProcessor->execute($oldOrder->address, $companyModule);
|
||||
$packingListReference = $parcel[17];
|
||||
$quantity = $parcel[9];
|
||||
$measurement = round(($parcel[10]/$quantity) ** (1/3) * 100, 2);
|
||||
$description = $parcel[7];
|
||||
$tracking = $parcel[6];
|
||||
$receiveDate = $parcel[1];
|
||||
|
||||
if(!$address){
|
||||
continue;
|
||||
$packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST, ApprovalStatus::APPROVED);
|
||||
|
||||
/** @var PackingList $packingList */
|
||||
$packingList = $order->packingLists()->where('reference', '=', $packingListReference)->first();
|
||||
|
||||
if(!$packingList) {
|
||||
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
|
||||
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $tracking, Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED);
|
||||
|
||||
|
||||
$this->createsTransport->execute($transportObject, $packingList);
|
||||
}
|
||||
|
||||
/** @var Transport $transport */
|
||||
$transport = $packingList->transports()->first();
|
||||
|
||||
$warehouseId = $parcel[0];
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $warehouseId === 11 ? 3 : 4]);
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject(Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED));
|
||||
|
||||
$packingList->packages()->delete();
|
||||
|
||||
$packageObject = new PackageObject(PackageType::CARTON, $description, $measurement, $measurement, $measurement, 0, $quantity, ApprovalStatus::APPROVED);
|
||||
$this->createPackageProcessor->execute($packageObject, $packingList);
|
||||
|
||||
$order = $this->createOrderProcessor->execute($companyModule->company, $originWarehouse, $address, $orderNumber);
|
||||
}
|
||||
|
||||
|
||||
$packingListReference = $parcel[17];
|
||||
$quantity = $parcel[9];
|
||||
$measurement = round(($parcel[10]/$quantity) ** (1/3) * 100, 2);
|
||||
$description = $parcel[7];
|
||||
$tracking = $parcel[6];
|
||||
$receiveDate = $parcel[1];
|
||||
|
||||
$packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST, ApprovalStatus::APPROVED);
|
||||
|
||||
/** @var PackingList $packingList */
|
||||
$packingList = $order->packingLists()->where('reference', '=', $packingListReference)->first();
|
||||
|
||||
if(!$packingList) {
|
||||
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
|
||||
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $tracking, Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED);
|
||||
|
||||
|
||||
$this->createsTransport->execute($transportObject, $packingList);
|
||||
}
|
||||
|
||||
/** @var Transport $transport */
|
||||
$transport = $packingList->transports()->first();
|
||||
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject(Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED));
|
||||
|
||||
$packingList->packages()->delete();
|
||||
|
||||
$packageObject = new PackageObject(PackageType::CARTON, $description, $measurement, $measurement, $measurement, 0, $quantity, ApprovalStatus::APPROVED);
|
||||
$this->createPackageProcessor->execute($packageObject, $packingList);
|
||||
|
||||
return [];
|
||||
} catch (\Exception $exception){
|
||||
Log::error($exception->getMessage());
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ class OrdersTableSeeder extends Seeder
|
||||
public function run()
|
||||
{
|
||||
FetchWarehouseReceiveListFromVTPortalJob::dispatch();
|
||||
FetchLoadedContainersFromVTPortalJob::dispatch()->delay(now()->addMinutes(20));
|
||||
FetchPackingListFromVTPortalJob::dispatch()->delay(now()->addMinutes(40));
|
||||
FetchContainersStatusUpdateFromVTPortalJob::dispatch()->delay(now()->addMinutes(60));
|
||||
FetchDeliveryListFromVTPortalJob::dispatch()->delay(now()->addMinutes(80));
|
||||
FetchLoadedContainersFromVTPortalJob::dispatch()->delay(now()->addMinutes(5));
|
||||
FetchPackingListFromVTPortalJob::dispatch()->delay(now()->addMinutes(10));
|
||||
FetchContainersStatusUpdateFromVTPortalJob::dispatch()->delay(now()->addMinutes(15));
|
||||
FetchDeliveryListFromVTPortalJob::dispatch()->delay(now()->addMinutes(20));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,15 +39,15 @@
|
||||
<div class="row text-center">
|
||||
<div class="col b-r b-grey text-info p-t-5 p-b-10">
|
||||
<small class="fs-10 all-caps bold">Received</small>
|
||||
<h6 class="bold no-margin text-info">0</h6>
|
||||
<h6 class="bold no-margin text-info">{{item.parcels.reduce((total, obj) => obj.quantity + total, 0)}}</h6>
|
||||
</div>
|
||||
<div class="col b-r b-grey text-primary p-t-5 p-b-10">
|
||||
<small class="fs-10 all-caps bold">In Transit</small>
|
||||
<h6 class="bold no-margin text-primary">0</h6>
|
||||
<h6 class="bold no-margin text-primary">{{item.in_transit_packages.reduce((total, obj) => obj.quantity + total, 0)}}</h6>
|
||||
</div>
|
||||
<div class="col text-success p-t-5 p-b-10">
|
||||
<small class="fs-10 all-caps bold">Delivered</small>
|
||||
<h6 class="bold no-margin text-success">0</h6>
|
||||
<h6 class="bold no-margin text-success">{{item.delivered_packages.reduce((total, obj) => obj.quantity + total, 0)}}</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user