Compare commits

..

1 Commits

Author SHA1 Message Date
Amirul Amin 1cea477145 order details responsive 2021-08-19 22:22:34 +08:00
115 changed files with 2007 additions and 3325 deletions
@@ -1,20 +0,0 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Illuminate\Database\Eloquent\Builder;
class WithParcels implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->with('parcels');
}
}
@@ -1,13 +0,0 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface ContainerOwner
{
public function containers(): morphMany;
}
@@ -1,13 +0,0 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Packable
{
public function packingLists(): morphMany;
}
@@ -1,13 +0,0 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Steppable
{
public function steps(): morphMany;
}
@@ -1,13 +0,0 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Transportable
{
public function transports(): morphMany;
}
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace App\Classes\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CurlWarehouseListJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
private $page;
public function __construct($page = -2)
{
$this->page = $page;
}
/**
* Execute the job.
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function handle()
{
$cookies = $this->getCookie();
$headers = [
'Content-Type' => 'application/json',
'Cookie' => $cookies,
];
$yesterday = Carbon::now()->subDays(1)->format('Y-m-d');
$client = new \GuzzleHttp\Client(['headers' => $headers]);
$res = $client->post('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', [\GuzzleHttp\RequestOptions::JSON => json_decode('{"controller":"WarehouseList","view":"grid1","request":{"PageIndex":' . $this->page . ',"PageSize":100,"PageOffset":0,"SortExpression":"ParcelDate DESC,FullMarking DESC","GroupExpression":"","Filter":["ParcelDate:=%js%\"' . $yesterday . 'T00:00:00.000\"\u0000"],"ContextKey":"view1","FilterIsExternal":false,"LookupContextFieldName":null,"LookupContextController":null,"LookupContextView":null,"LookupContext":null,"Inserting":false,"LastCommandName":null,"ExternalFilter":[],"DoesNotRequireData":false,"LastView":"grid1","Tag":null,"RequiresFirstLetters":false,"ViewType":"Grid","SupportsCaching":true,"SystemFilter":null,"RequiresRowCount":true,"QuickFindHint":null,"RequiresPivot":false,"PivotDefinitions":null,"RequiresMetaData":true}}')]);
$data = json_decode($res->getBody()->getContents());
if (!empty($data->d->Row)) {
// insert data here
// next page
$this->page = $this->page > 0 ? $this->page + 1 : 1;
CurlWarehouseListJob::dispatch($this->page + 1)
->delay(Carbon::now()->addSeconds(10));
}
}
public function getCookie()
{
// get latest cookies
$client = new \GuzzleHttp\Client(['cookies' => true]);
$r = $client->request('GET', 'https://portalvt.azurewebsites.net');
$call_cookie = $client->getConfig('cookies');
$call_cookie = $call_cookie->toArray();
$latest_cookie = [];
foreach ($call_cookie as $key => $row) {
$latest_cookie[] = $row['Name'] . '=' . $row['Value'];
}
$latest_cookie = implode(';', $latest_cookie);
// get access token
$headers = [
'Content-Type' => 'application/json',
'Cookie' => $latest_cookie,
];
$client = new \GuzzleHttp\Client(['headers' => $headers]);
$res = $client->post('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login', [\GuzzleHttp\RequestOptions::JSON => [
"username" => "CIEF",
"password" => "0122120880",
"createPersistentCookie" => true,
]]);
$token = json_decode($res->getBody()->getContents());
$token = $token->d->AccessToken;
$latest_cookie = $latest_cookie . ';AppVTCC=' . $token;
return $latest_cookie;
}
}
@@ -1,29 +0,0 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchContainersStatusUpdateFromVTPortalProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FetchContainersStatusUpdateFromVTPortalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 900;
/**
* Execute the job.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
(App()->make(FetchContainersStatusUpdateFromVTPortalProcessor::class))->execute();
}
}
@@ -1,31 +0,0 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchDeliveryListFromVTPortalProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FetchDeliveryListFromVTPortalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 900;
/**
* Execute the job.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
(App()->make(FetchDeliveryListFromVTPortalProcessor::class))->execute();
}
}
@@ -1,31 +0,0 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchLoadedContainersFromVTPortalProcessor;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FetchLoadedContainersFromVTPortalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 900;
/**
* Execute the job.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
(App()->make(FetchLoadedContainersFromVTPortalProcessor::class))->execute();
}
}
@@ -1,30 +0,0 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchPackingListFromVTPortalProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FetchPackingListFromVTPortalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 1800;
/**
* Execute the job.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
(App()->make(FetchPackingListFromVTPortalProcessor::class))->execute();
}
}
@@ -1,31 +0,0 @@
<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchWarehouseReceiveListFromVTPortalProcessor;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FetchWarehouseReceiveListFromVTPortalJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 900;
/**
* Execute the job.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
(App()->make(FetchWarehouseReceiveListFromVTPortalProcessor::class))->execute();
}
}
@@ -138,7 +138,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
$this->uploadIdentityDocumentProcessor->execute($request, $company);
// $this->generateEmailVerificationAttemptProcessor->execute($user);
$this->generateEmailVerificationAttemptProcessor->execute($user);
return $this->response($this->authenticationProcessor->execute($request));
}
@@ -1,55 +0,0 @@
<?php
namespace App\Classes\Modules\Addresses\Processors;
use App\Classes\General\Interfaces\Addressable;
use App\Classes\Modules\Addresses\Services\CleansOldAddress;
use App\Classes\Modules\Addresses\Services\CreatesAddress;
use App\Classes\Modules\Addresses\Services\FetchesAddress;
use App\Models\OldAddress;
use Illuminate\Database\Eloquent\Model;
class CreateAddressFromOldAddressProcessor
{
/** @var CleansOldAddress */
private $cleansOldAddress;
/** @var CreatesAddress */
private $createsAddress;
/**
* CreateAddressFromOldAddressProcessor constructor.
* @param CleansOldAddress $cleansOldAddress
* @param CreatesAddress $createsAddress
*/
public function __construct(CleansOldAddress $cleansOldAddress, CreatesAddress $createsAddress)
{
$this->cleansOldAddress = $cleansOldAddress;
$this->createsAddress = $createsAddress;
}
/**
* @param OldAddress $address
* @param Addressable $addressable
* @return Model|null
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(OldAddress $address, Addressable $addressable): ?Model {
if(!$object = $this->cleansOldAddress->execute($address)){
return null;
}
if($address = $addressable->addresses()->where('street_one', $object->getStreetOne())->first()){
return $address;
}
return $this->createsAddress->execute($addressable, $object);
}
}
@@ -1,52 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Omair Saleh
* Date: 20/8/2021
* Time: 1:05 AM
*/
namespace App\Classes\Modules\Addresses\Services;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Models\District;
use App\Models\OldAddress;
class CleansOldAddress
{
public function execute(OldAddress $address){
if($address->street_one === '' && $address->street_two === ''){
return null;
}
if(!$address->post_code){
return null;
}
$district = District::where('postcode', 'like', '%'. $address->post_code .'%')->first();
if(!$district) {
return null;
}
return new AddressObject($this->cleanAddress($address->street_one, $district, $address->post_code), $this->cleanAddress($address->street_two, $district, $address->post_code), $district->country_id, $district->state_id, $district->id, $address->post_code, 'Delivery Address');
}
public function cleanAddress($address, $district, $postcode){
$address = str_replace('Malaysia', '', str_replace('malaysia', '', str_replace('MALAYSIA', '', $address)));
$address = str_replace($district->state->name, '',str_replace($district->name, '', $address));
$address = str_replace(strtolower($district->state->name), '',str_replace(strtolower($district->name), '', $address));
$address = str_replace(strtoupper($district->state->name), '',str_replace(strtoupper($district->name), '', $address));
$address = str_replace($postcode, '', $address);
$address = str_replace(', ,', ',', str_replace(', ,', ',', str_replace(', ,', ',', $address)));
$address = str_replace(',', ', ', $address);
$address = preg_replace('!\s+!', ' ', $address);
$address = preg_replace("/,+/", ",", $address);
return rtrim(rtrim(rtrim(rtrim($address, '.')), ','));
}
}
@@ -53,6 +53,10 @@ class ListCompaniesLogic extends AbstractControllerLogic
{
$this->canListCompanies->passes();
logger("llogic");
logger($request->input('filters'));
$query = $this->listsCompanies->execute($this->listsCompanies->deserializeFilters($request->input('filters')));
return $this->collectionResponse(CompanyResource::collection($query));
@@ -3,11 +3,7 @@
namespace App\Classes\Modules\Orders\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Addresses\Services\FetchesAddress;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Orders\Processors\CreateOrderProcessor;
use App\Classes\Modules\Orders\Services\GeneratesOrderNumber;
use App\Http\Resources\OrderResource;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
@@ -15,6 +11,13 @@ use Illuminate\Http\JsonResponse;
class CreateOrderLogic extends AbstractControllerLogic
{
private $createOrderProcessor;
public function __construct( CreateOrderProcessor $createsOrderProcessor)
{
$this->createOrderProcessor = $createsOrderProcessor;
}
protected function notification():array {
return [
'title' => 'Created Order',
@@ -22,48 +25,9 @@ class CreateOrderLogic extends AbstractControllerLogic
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var fetchesAddress */
private $fetchesAddress;
/** @var CreateOrderProcessor */
private $createOrderProcessor;
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/** @var GeneratesOrderNumber */
private $generatesOrderNumber;
/**
* CreateOrderLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param FetchesAddress $fetchesAddress
* @param CreateOrderProcessor $createOrderProcessor
* @param FetchesCompanyModule $fetchesCompanyModule
* @param GeneratesOrderNumber $generatesOrderNumber
*/
public function __construct(FetchesCompany $fetchesCompany, FetchesAddress $fetchesAddress, CreateOrderProcessor $createOrderProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesOrderNumber $generatesOrderNumber)
{
$this->fetchesCompany = $fetchesCompany;
$this->fetchesAddress = $fetchesAddress;
$this->createOrderProcessor = $createOrderProcessor;
$this->fetchesCompanyModule = $fetchesCompanyModule;
$this->generatesOrderNumber = $generatesOrderNumber;
}
public function logic(Request $request) : JsonResponse {
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
$address = $this->fetchesAddress->execute(['id' => $request->input('address_id')]);
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $request->input('warehouse_id')]);
$order = $this->createOrderProcessor->execute($company, $originWarehouse, $address, $this->generatesOrderNumber->execute());
$order = $this->createOrderProcessor->execute($request);
return $this->resourceResponse(new OrderResource($order));
}
@@ -52,7 +52,7 @@ class FetchOrderLogic extends AbstractControllerLogic
$this->canFetchOrder->passes();
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_parcels' => true]);
$query = $this->fetchesOrder->execute(['reference' => $request->route('id')]);
return $this->resourceResponse(new OrderResource($query));
@@ -44,7 +44,7 @@ class ListOrdersLogic extends AbstractControllerLogic
{
$this->canListOrders->passes();
$query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true]));
$query = $this->listsOrders->execute($this->listsOrders->deserializeFilters($request->input('filters')));
return $this->collectionResponse(OrderResource::collection($query));
@@ -13,69 +13,83 @@ use App\Classes\Modules\Orders\Services\GeneratesOrderNumber;
use App\Classes\Modules\Orders\Standards\Rules\CanCreateOrder;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\OrderType;
use App\Models\Address;
use App\Models\Company;
use App\Models\CompanyModule;
use App\Models\Order;
use Illuminate\Http\Request;
class CreateOrderProcessor
{
/** @var GeneratesOrderNumber */
private $generatesOrderNumber;
/** @var CanCreateOrder */
private $canCreateOrder;
/** @var CreatesOrder */
private $createsOrder;
/** @var fetchesAddress */
private $fetchesAddress;
/** @var CreatesAddress */
private $createAddress;
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreateOrderRolesProcessor */
private $createOrderRolesProcessor;
/**
* CreateOrderProcessor constructor.
* @param GeneratesOrderNumber $generatesOrderNumber
* @param CanCreateOrder $canCreateOrder
* @param CreatesOrder $createsOrder
* @param FetchesAddress $fetchesAddress
* @param CreatesAddress $createAddress
* @param FetchesCompany $fetchesCompany
* @param CreateOrderRolesProcessor $createOrderRolesProcessor
*/
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreatesAddress $createAddress, CreateOrderRolesProcessor $createOrderRolesProcessor)
public function __construct(GeneratesOrderNumber $generatesOrderNumber, CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, FetchesAddress $fetchesAddress, CreatesAddress $createAddress, FetchesCompany $fetchesCompany, CreateOrderRolesProcessor $createOrderRolesProcessor)
{
$this->generatesOrderNumber = $generatesOrderNumber;
$this->canCreateOrder = $canCreateOrder;
$this->createsOrder = $createsOrder;
$this->fetchesAddress = $fetchesAddress;
$this->createAddress = $createAddress;
$this->fetchesCompany = $fetchesCompany;
$this->createOrderRolesProcessor = $createOrderRolesProcessor;
}
/**
* @param Company $company
* @param CompanyModule $originWarehouse
* @param Address $address
* @param int|null $orderNumber
* @param Request $request
* @return Addressable
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(Company $company, CompanyModule $originWarehouse, Address $address, int $orderNumber){
public function execute(Request $request){
$company = $this->fetchesCompany->execute(['id' => $request->get('company_id')]);
/** @var CompanyModule $importer */
$importer = $company->companyModules()->importers()->first();
$importer = $this->fetchesCompany->execute(['id' => $request->get('company_id')])->companyModules()->importers()->first();
$orderObject = new OrderObject($orderNumber, OrderType::SHARED_CONTAINER, $company->status === ApprovalStatus::APPROVED ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION);
$orderObject = new OrderObject($this->generatesOrderNumber->execute(), OrderType::SHARED_CONTAINER, $company->status === ApprovalStatus::APPROVED ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION);
$this->canCreateOrder->passes($orderObject);
/** @var Order $order */
$order = $this->createsOrder->execute($importer, $orderObject);
$address = $this->fetchesAddress->execute(['id' => $request->get('address_id')]);
$addressObject = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode,$address->reference);
$this->createAddress->execute($order, $addressObject);
$this->createOrderRolesProcessor->execute($originWarehouse, $order);
$this->createOrderRolesProcessor->execute($request, $order);
return $order;
}
@@ -10,7 +10,6 @@ use App\Classes\Modules\Orders\Services\CreatesOrder;
use App\Classes\Modules\Orders\Standards\Rules\CanCreateOrder;
use App\Classes\Modules\Orders\Processors\ConfirmOrderProcessor;
use App\Classes\Modules\OrderSteps\Processors\CreateOrderStepsProcessor;
use App\Classes\Modules\Steps\Processors\CreateStepsProcessor;
use App\Classes\Modules\Unity\Services\CreatesContract;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\OrderSteps;
@@ -34,8 +33,8 @@ class CreateOrderProcessorOld
/** @var ConfirmOrderProcessor */
private $confirmOrderProcessor;
/** @var CreateStepsProcessor */
private $createStepsProcessor;
/** @var CreateOrderStepsProcessor */
private $createOrderStepsProcessor;
/** @var CreatesContract */
private $unityCreateContract;
@@ -59,11 +58,11 @@ class CreateOrderProcessorOld
private $fetchesAddress;
/**
* CreateOrderProcessorOld constructor.
* CreateOrderProcessor constructor.
* @param CanCreateOrder $canCreateOrder
* @param CreatesOrder $createsOrder
* @param \App\Classes\Modules\Orders\Processors\ConfirmOrderProcessor $confirmOrderProcessor
* @param CreateStepsProcessor $createStepsProcessor
* @param CreateOrderStepsProcessor $createOrderStepsProcessor
* @param CreatesContract $unityCreateContract
* @param AssignContractEntityProcessor $unityAssignContractEntity
* @param CreateContractEntityProcessor $unityCreateContractEntity
@@ -72,12 +71,12 @@ class CreateOrderProcessorOld
* @param CreatesAddress $createAddress
* @param FetchesAddress $fetchesAddress
*/
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, \App\Classes\Modules\Orders\Processors\ConfirmOrderProcessor $confirmOrderProcessor, CreateStepsProcessor $createStepsProcessor, CreatesContract $unityCreateContract, AssignContractEntityProcessor $unityAssignContractEntity, CreateContractEntityProcessor $unityCreateContractEntity, ActivateContractProcessor $unityActivateContract, \App\Classes\Modules\Orders\Processors\CreateOrderRolesProcessor $createOrderRoleProcessor, CreatesAddress $createAddress, FetchesAddress $fetchesAddress)
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, \App\Classes\Modules\Orders\Processors\ConfirmOrderProcessor $confirmOrderProcessor, CreateOrderStepsProcessor $createOrderStepsProcessor, CreatesContract $unityCreateContract, AssignContractEntityProcessor $unityAssignContractEntity, CreateContractEntityProcessor $unityCreateContractEntity, ActivateContractProcessor $unityActivateContract, \App\Classes\Modules\Orders\Processors\CreateOrderRolesProcessor $createOrderRoleProcessor, CreatesAddress $createAddress, FetchesAddress $fetchesAddress)
{
$this->canCreateOrder = $canCreateOrder;
$this->createsOrder = $createsOrder;
$this->confirmOrderProcessor = $confirmOrderProcessor;
$this->createStepsProcessor = $createStepsProcessor;
$this->createOrderStepsProcessor = $createOrderStepsProcessor;
$this->unityCreateContract = $unityCreateContract;
$this->unityAssignContractEntity = $unityAssignContractEntity;
$this->unityCreateContractEntity = $unityCreateContractEntity;
@@ -121,7 +120,7 @@ class CreateOrderProcessorOld
//Add processing to order step
//Note: For processing apointee_id is CIEF Freight Forward , id is 1, reserved in company table
$this->createStepsProcessor->execute($order, OrderSteps::PROCESSING, 1);
$this->createOrderStepsProcessor->execute($order, OrderSteps::PROCESSING, 1);
//Pre-approved order, no need Admin to process it
//This processor then calls Generate Order Steps
@@ -40,20 +40,17 @@ class CreateOrderRolesProcessor
}
/**
* @param CompanyModule $originWarehouse
* @param Order $order
* @return bool
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(CompanyModule $originWarehouse, Order $order){
public function execute(Request $request, Order $order){
$address = $order->addresses()->first();
$importer = $order->companyModule;
/** @var CompanyModule $originWarehouse */
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $request->get('warehouse_id')]);
/** @var CompanyModule $destinationWarehouse */
$destinationWarehouse = $this->fetchesCompanyModule->execute(['reference' => WarehouseReferences::DESTINATION_WAREHOUSE[$address->state_id ]]);
$destinationWarehouse = $this->fetchesCompanyModule->execute(['reference' => $address->state_id = 13 ? WarehouseReferences::SABAH : ($address->state_id === 14 ? WarehouseReferences::SARAWAK : WarehouseReferences::KLANG)]);
/** @var CompanyModule $freightForwarder */
$freightForwarder = $originWarehouse->company->companyModules()->freightForwarders()->first();
@@ -83,28 +80,5 @@ class CreateOrderRolesProcessor
$this->createsOrderRole->execute($roleObject);
return true;
$companies = $this->fetchesCompany->getRepository()->whereIn('id',[1, $request->get('warehouse_id')])->get();
$cief_company = $companies[0]->id == 1 ? $companies[0] : $companies[1];
$warehouse_company = $companies[0]->id != 1 ? $companies[0] : $companies[1];
$cief_company_module = $cief_company->companyModule()->first();
$contractEntities[] = $this->unityCreateContractEntity->execute( $contract_reference_no, [$cief_company_module->unity_hash_id]);
$contractEntities[0]->{"company_module_id"} = $cief_company_module->id;
$warehouse_company_module = $warehouse_company->companyModule()->first();
$contractEntities[] = $this->unityCreateContractEntity->execute( $contract_reference_no, [$warehouse_company_module->unity_hash_id]);
$contractEntities[1]->{"company_module_id"} = $warehouse_company_module->id;
foreach($contractEntities as $entity){
$order_role_object = new OrderRoleObject($orderId, $entity->company_module_id, $entity->hash_id, $entity->entity_signature_hash_id);
$this->canCreateOrderRole->passes($order_role_object);
$this->createsOrderRole->execute($order_role_object);
}
return $contractEntities;
}
}
@@ -1,94 +0,0 @@
<?php
namespace App\Classes\Modules\Orders\Services;
use Psr\Http\Message\ResponseInterface;
class FetchesDataFromVTPortal
{
/** @var string|null */
private $cookies;
/**
* @param string $cookies
*/
public function setCookies(string $cookies): void
{
$this->cookies = $cookies;
}
/**
* @return string|null
*/
public function getCookies(): ?string
{
return $this->cookies;
}
/**
* @param string $url
* @param string $method
* @param $body
* @param string $cookie
* @param bool $requiresAuthentication
* @return \Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function clientRequest(string $url, string $method, $body, string $cookie, $requiresAuthentication = true){
if($requiresAuthentication) {
if(!$this->getCookies()){
$this->remoteLogin();
}
}
$client = new \GuzzleHttp\Client(
[
'cookies' => true,
'headers' => [
'Content-Type' => 'application/json',
'Cookie' => $this->getCookies() ? $this->getCookies() : $cookie
]
]
);
$request = $client->requestAsync($method, $url, [\GuzzleHttp\RequestOptions::JSON => $body, 'timeout' => 1200]);
return $request->wait();
}
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function remoteLogin(){
$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'];
}
$latest_cookie = implode(';', $latest_cookie);
/** @var $loginRequest */
$loginRequest = $this->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login', 'POST', [
"username" => "CIEF",
"password" => "0122120880",
"createPersistentCookie" => true,
], $latest_cookie, false);
$this->setCookies($latest_cookie.';AppVTCC='.$this->getResponseBody($loginRequest)->AccessToken);
}
public function getResponseBody(ResponseInterface $request){
return json_decode($request->getBody()->getContents())->d;
}
}
@@ -5,7 +5,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\CreatesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanCreateContainer;
use App\Classes\Modules\PackingLists\Standards\Containers\Rules\CanCreateContainer;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Http\Resources\ContainerResource;
@@ -52,7 +52,9 @@ class CreateContainerLogic extends AbstractControllerLogic
public function logic(Request $request) : JsonResponse
{
$object = new ContainerObject($request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
$packingList = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
$object = new ContainerObject( $packingList->id , $request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
$this->canCreateContainer->passes($object);
@@ -6,7 +6,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\DeletesContainer;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanDeleteContainer;
use App\Classes\Modules\PackingLists\Standards\Containers\Rules\CanDeleteContainer;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -5,7 +5,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanFetchContainer;
use App\Classes\Modules\PackingLists\Standards\Containers\Rules\CanFetchContainer;
use App\Http\Resources\ContainerResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
@@ -5,7 +5,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\ListsContainers;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanListContainers;
use App\Classes\Modules\PackingLists\Standards\Containers\Rules\CanListContainers;
use App\Http\Resources\ContainerResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
@@ -6,7 +6,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\UpdatesContainer;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanUpdateContainer;
use App\Classes\Modules\PackingLists\Standards\Containers\Rules\CanUpdateContainer;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Http\Resources\ContainerResource;
use ErrorException;
@@ -2,10 +2,6 @@
namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\Processors\CreatePackingListProcessor;
use App\Classes\Modules\PackingLists\Services\Packages\FetchesPackage;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
@@ -13,14 +9,16 @@ use App\Classes\Modules\PackingLists\Services\CreatesPackingListPackage;
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingListPackage;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListPackageObject;
use App\Classes\Modules\Packages\Services\FetchesPackage;
use App\Http\Resources\PackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreatePackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
@@ -31,28 +29,62 @@ class CreatePackingListLogic extends AbstractControllerLogic
];
}
/** @var CreatePackingListProcessor */
private $createPackingListProcessor;
/** @var CanCreatePackingList */
private $canCreatePackingList;
private $canCreatePackingListPackage;
/** @var FetchesCompany */
private $fetchesPackage;
/** @var CreatesPackingList */
private $createsPackingList;
private $createsPackingListPackage;
/**
* CreatePackingListLogic constructor.
* @param CreatePackingListProcessor $createPackingListProcessor
* @param CanCreatePackingList $canCreatePackingList
* @param FetchesCompany $fetchesCompany
* @param CreatesPackingList $createsPackingList
*/
public function __construct(CreatePackingListProcessor $createPackingListProcessor)
public function __construct(CanCreatePackingList $canCreatePackingList, CanCreatePackingListPackage $canCreatePackingListPackage, FetchesPackage $fetchesPackage, CreatesPackingList $createsPackingList, CreatesPackingListPackage $createsPackingListPackage)
{
$this->createPackingListProcessor = $createPackingListProcessor;
$this->canCreatePackingList = $canCreatePackingList;
$this->canCreatePackingListPackage = $canCreatePackingListPackage;
$this->fetchesPackage = $fetchesPackage;
$this->createsPackingList = $createsPackingList;
$this->createsPackingListPackage = $createsPackingListPackage;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
$object = new PackingListObject($request->input('reference_number'), ApprovalStatus::PENDING_SUBMISSION);
$package = $this->fetchesPackage->execute(['id'=>$request->input('package_id')]);
$reference_no = rand(1000000, 9999999);
$object = new PackingListObject($reference_no, ApprovalStatus::PENDING_SUBMISSION);
$this->canCreatePackingList->passes($object);
$packageList = $this->createsPackingList->execute( $object);
$object = new PackingListPackageObject($packageList->id, $package->id);
$this->canCreatePackingListPackage->passes($object);
$query = $this->createsPackingListPackage->execute($object);
$query = $this->createPackingListProcessor->execute($object);
return $this->resourceResponse(new PackingListResource($query));
@@ -65,6 +65,7 @@ class CreatePackageLogic extends AbstractControllerLogic
$order = $this->fetchesOrder->execute(['id' => $request->input('order_id')]);
$object = new PackageObject(
$order->id,
null,
$request->input('type'),
$request->input('description'),
@@ -73,7 +74,7 @@ class CreatePackageLogic extends AbstractControllerLogic
$request->input('length'),
$request->input('weight'),
$request->input('quantity'),
ApprovalStatus::PENDING_VERIFICATION);
ApprovalStatus::PENDING_SUBMISSION);
$this->canCreatePackage->passes($object);
@@ -7,76 +7,39 @@ use App\Classes\General\Interfaces\DataTransferObject;
class ContainerObject implements DataTransferObject
{
/** @var string */
private $reference;
private $packingListId;
/** @var string */
private $containerNumber;
private $containerReference;
/** @var string */
private $sealNumber;
/** @var int */
private $containerType;
/** @var int */
private $status;
private $sealReference;
/**
* ContainerObject constructor.
* @param string $reference
* @param string $containerNumber
* @param string $sealNumber
* @param int $containerType
* @param int $status
*/
public function __construct(string $reference, string $containerNumber, string $sealNumber, int $containerType, int $status)
public function __construct(int $packingListId, ?string $containerReference, int $containerType, ?String $sealReference)
{
$this->reference = $reference;
$this->containerNumber = $containerNumber;
$this->sealNumber = $sealNumber;
$this->packingListId = $packingListId;
$this->containerReference = $containerReference;
$this->containerType = $containerType;
$this->status = $status;
$this->sealReference = $sealReference;
}
/**
* @return string
*/
public function getReference(): string
public function getPackingListId(): int
{
return $this->reference;
return $this->packingListId;
}
/**
* @return string
*/
public function getContainerNumber(): string
public function getContainerReference(): ?string
{
return $this->containerNumber;
return $this->containerReference;
}
/**
* @return string
*/
public function getSealNumber(): string
{
return $this->sealNumber;
}
/**
* @return int
*/
public function getContainerType(): int
{
return $this->containerType;
}
/**
* @return int
*/
public function getStatus(): int
public function getSealReference(): ?string
{
return $this->status;
return $this->sealReference;
}
}
@@ -7,47 +7,30 @@ use App\Classes\General\Interfaces\DataTransferObject;
class PackageObject implements DataTransferObject
{
/** @var int */
private $orderId;
private $claimantId;
private $type;
/** @var null|string */
private $description;
/** @var float */
private $width;
/** @var float */
private $height;
/** @var float */
private $length;
/** @var float */
private $weight;
/** @var int */
private $quantity;
/** @var int */
private $status;
/** @var string|null */
private $reference;
/**
* PackageObject constructor.
* @param int $type
* @param null|string $description
* @param float $width
* @param float $height
* @param float $length
* @param float $weight
* @param int $quantity
* @param int $status
* @param null|string $reference
*/
public function __construct(int $type, ?string $description, float $width, float $height, float $length, float $weight, int $quantity, int $status, ?string $reference=null)
public function __construct(int $orderId, ?int $claimantId, int $type, ?string $description, float $width, float $height, float $length, float $weight, int $quantity, int $status)
{
$this->orderId = $orderId;
$this->claimantId = $claimantId;
$this->type = $type;
$this->description = $description;
$this->width = $width;
@@ -56,80 +39,55 @@ class PackageObject implements DataTransferObject
$this->weight = $weight;
$this->quantity = $quantity;
$this->status = $status;
$this->reference = $reference;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
public function getClaimantId(): ?int
{
return $this->claimantId;
}
public function getType(): int
{
return $this->type;
}
/**
* @return null|string
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return float
*/
public function getWidth(): float
{
return $this->width;
}
/**
* @return float
*/
public function getHeight(): float
{
return $this->height;
}
/**
* @return float
*/
public function getLength(): float
{
return $this->length;
}
/**
* @return float
*/
public function getWeight(): float
{
return $this->weight;
}
/**
* @return int
*/
public function getQuantity(): int
{
return $this->quantity;
}
/**
* @return int
*/
public function getStatus(): int
{
return $this->status;
}
/**
* @return null|string
*/
public function getReference(): ?string
{
return $this->reference;
}
}
@@ -7,62 +7,31 @@ use App\Classes\General\Interfaces\DataTransferObject;
class PackingListObject implements DataTransferObject
{
/** @var string */
/** @var null|string */
private $reference;
/** @var int */
private $claimantId;
/** @var int */
private $type;
/** @var int */
private $status;
/** @var string|null */
private $contractReference;
/**
* PackingListObject constructor.
* @param string $reference
* @param int $claimantId
* @param int $type
* @param null|string $reference
* @param int $status
* @param null|string $contractReference
*/
public function __construct(string $reference, int $claimantId, int $type, int $status, ?string $contractReference = null)
public function __construct(?string $reference, int $status)
{
$this->reference = $reference;
$this->claimantId = $claimantId;
$this->type = $type;
$this->status = $status;
$this->contractReference = $contractReference;
}
/**
* @return string
* @return null|string
*/
public function getReference(): string
public function getReference(): ?string
{
return $this->reference;
}
/**
* @return int
*/
public function getClaimantId(): int
{
return $this->claimantId;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @return int
*/
@@ -71,13 +40,5 @@ class PackingListObject implements DataTransferObject
return $this->status;
}
/**
* @return null|string
*/
public function getContractReference(): ?string
{
return $this->contractReference;
}
}
@@ -1,45 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Classes\Modules\PackingLists\Services\Containers\CreatesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanCreateContainer;
class CreateContainerProcessor
{
/** @var CanCreateContainer */
private $canCreateContainer;
/** @var CreatesContainer */
private $createsContainer;
/**
* CreateContainerProcessor constructor.
* @param CanCreateContainer $canCreateContainer
* @param CreatesContainer $createsContainer
*/
public function __construct(CanCreateContainer $canCreateContainer, CreatesContainer $createsContainer)
{
$this->canCreateContainer = $canCreateContainer;
$this->createsContainer = $createsContainer;
}
/**
* @param ContainerObject $object
* @param ContainerOwner $owner
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(ContainerObject $object, ContainerOwner $owner){
$this->canCreateContainer->passes($object);
return $this->createsContainer->execute($object, $owner);
}
}
@@ -1,48 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\Services\Packages\CreatesPackage;
use App\Classes\Modules\PackingLists\Standards\Rules\Packages\CanCreatePackage;
use App\Models\PackingList;
class CreatePackageProcessor
{
/** @var CanCreatePackage */
private $canCreatePackage;
/** @var CreatesPackage */
private $createsPackage;
/**
* CreatePackageProcessor constructor.
* @param CanCreatePackage $canCreatePackage
* @param CreatesPackage $createsPackage
*/
public function __construct(CanCreatePackage $canCreatePackage, CreatesPackage $createsPackage)
{
$this->canCreatePackage = $canCreatePackage;
$this->createsPackage = $createsPackage;
}
/**
* @param PackageObject $object
* @param PackingList $packingList
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(PackageObject $object, PackingList $packingList){
$this->canCreatePackage->passes($object);
return $this->createsPackage->execute($object, $packingList);
}
}
@@ -1,47 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\General\Interfaces\Packable;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
class CreatePackingListProcessor
{
/** @var CanCreatePackingList */
private $canCreatePackingList;
/** @var CreatesPackingList */
private $createsPackingList;
/**
* CreatePackingListLogic constructor.
* @param CanCreatePackingList $canCreatePackingList
* @param CreatesPackingList $createsPackingList
*/
public function __construct(CanCreatePackingList $canCreatePackingList, CreatesPackingList $createsPackingList)
{
$this->canCreatePackingList = $canCreatePackingList;
$this->createsPackingList = $createsPackingList;
}
/**
* @param PackingListObject $object
* @param Packable $packable
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(PackingListObject $object, Packable $packable){
$this->canCreatePackingList->passes($object);
return $this->createsPackingList->execute($object, $packable);
}
}
@@ -1,148 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
use App\Classes\Modules\Transports\Services\CreatesTransport;
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\ContainerTypes;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransportType;
use App\Models\Container;
use App\Models\Order;
use App\Models\PackingList;
use App\Models\Transport;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FetchContainersStatusUpdateFromVTPortalProcessor
{
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomVTPortal;
/** @var CreatesTransport */
private $createsTransport;
/** @var CreatesSchedule */
private $createsSchedule;
/** @var UpdatesContractObligation */
private $updatesContractObligations;
/**
* FetchContainersStatusUpdateFromVTPortalProcessor constructor.
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
* @param CreatesTransport $createsTransport
* @param CreatesSchedule $createsSchedule
* @param UpdatesContractObligation $updatesContractObligations
*/
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, UpdatesContractObligation $updatesContractObligations)
{
$this->fetchesDataFRomVTPortal = $fetchesDataFRomVTPortal;
$this->createsTransport = $createsTransport;
$this->createsSchedule = $createsSchedule;
$this->updatesContractObligations = $updatesContractObligations;
}
/**
* @return array
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(){
try {
$containers = Container::where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get();
/** @var Container $container */
foreach($containers as $container){
try {
$filter = '["RefNo:=%js%\"'.$container->reference.'\"\u0000"]';
$containerDetailsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
$containerDetails = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailsRequest);
$containerDetails = $containerDetails->Rows[0];
if(!$eta = $containerDetails[3]){
continue;
}
$eta = Carbon::parse($eta);
$delayDate = $containerDetails[6];
$containerStatus = $containerDetails[9];
$unstuffingDate = $containerDetails[7];
$transport = $container->transports()->first();
if(!$transport){
$transportObject = new TransportObject(TransportType::SEA, null, null, $eta, null, ApprovalStatus::APPROVED);
/** @var Transport $transport */
$transport = $this->createsTransport->execute($transportObject, $container);
$this->createsSchedule->execute($transport, new ScheduleObject($eta->subDays(5), $eta, ApprovalStatus::APPROVED));
}
if($delayDate){
$delayDate = Carbon::parse($delayDate);
$transport = $container->transports()->first();
$schedule = $transport->schedules()->where('eta', '=', $delayDate)->first();
$etd = $delayDate->subDays(5);
if(!$schedule){
$etd = $schedule->etd;
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
}
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $delayDate, ApprovalStatus::APPROVED));
}
if($containerStatus === 'Unstuffing'){
$container->update(['status' => ApprovalStatus::COMPLETED]);
$container->transports()->first()->update(['drop_date' => Carbon::parse($unstuffingDate)->subDay(), 'status' => ApprovalStatus::COMPLETED]);
$container->packingLists()->update(['status' => ApprovalStatus::APPROVED]);
/** @var PackingList $packingList */
foreach($container->packingLists as $packingList){
$signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture;
foreach($packingList->steps()->where('reference', '!=', 'DELIVERY')->get() as $step){
$this->updatesContractObligations->execute($signature, $step->obligation_hash_id);
$step->update(['status' => ApprovalStatus::COMPLETED]);
}
}
}
} catch (GuzzleException $exception) {
continue;
}
}
} catch (\Exception $exception) {
Log::error($exception);
}
return [];
}
}
@@ -1,105 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
use App\Classes\Modules\Transports\Services\CreatesTransport;
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransportType;
use App\Models\PackingList;
use App\Models\Transport;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
class FetchDeliveryListFromVTPortalProcessor
{
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomVTPortal;
/** @var CreatesTransport */
private $createsTransport;
/** @var CreatesSchedule */
private $createsSchedule;
/** @var UpdatesContractObligation */
private $updatesContractObligations;
/**
* FetchDeliveryListFromVTPortalProcessor constructor.
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
* @param CreatesTransport $createsTransport
* @param CreatesSchedule $createsSchedule
* @param UpdatesContractObligation $updatesContractObligations
*/
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, UpdatesContractObligation $updatesContractObligations)
{
$this->fetchesDataFRomVTPortal = $fetchesDataFRomVTPortal;
$this->createsTransport = $createsTransport;
$this->createsSchedule = $createsSchedule;
$this->updatesContractObligations = $updatesContractObligations;
}
/**
* @return array
*/
public function execute(){
try {
$packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::APPROVED)->get();
/** @var PackingList $packingList */
foreach($packingLists as $packingList){
try {
$filter = '["PoNumber:=%js%\"'.$packingList->reference.'\"\u0000"]';
$shippingPackingListsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
$shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest);
foreach($shippingPackingLists->Rows as $shippingPackingList){
if(!$shippingPackingList[9] && !$shippingPackingList[10]) {
continue;
}
$deliveryDate = Carbon::parse($shippingPackingList[9] ? $shippingPackingList[9]:$shippingPackingList[10]);
$transportObject = new TransportObject(TransportType::LAND, null, null, $deliveryDate, $deliveryDate, ApprovalStatus::APPROVED);
/** @var Transport $transport */
$transport = $this->createsTransport->execute($transportObject, $packingList);
$this->createsSchedule->execute($transport, new ScheduleObject($deliveryDate, $deliveryDate, ApprovalStatus::APPROVED));
$deliveryStep = $packingList->steps()->where('reference', '=', 'LAST_MILE_DELIVERY')->first();
$signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture;
$this->updatesContractObligations->execute($signature, $deliveryStep->obligation_hash_id);
$deliveryStep->update(['status' => ApprovalStatus::COMPLETED]);
}
} catch (GuzzleException $exception) {
continue;
}
}
} catch (\Exception $exception){
Log::error($exception);
}
return [];
}
}
@@ -1,230 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\PackingList\Processors\GenerateShippingOrderStepsProcessor;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Classes\Modules\Steps\Services\CreatesStep;
use App\Classes\Modules\Transports\Services\CreatesTransport;
use App\Classes\Modules\Unity\Processors\ActivateContractProcessor;
use App\Classes\Modules\Unity\Processors\AssignContractEntityProcessor;
use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor;
use App\Classes\Modules\Unity\Services\CreatesContract;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\ContainerTypes;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Models\Order;
use App\Models\PackingList;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FetchLoadedContainersFromVTPortalProcessor
{
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomVTPortal;
/** @var FetchesOrder */
private $fetchesOrder;
/** @var CreatePackingListProcessor */
private $createPackingListProcessor;
/** @var CreatePackageProcessor */
private $createPackageProcessor;
/** @var CreatesTransport */
private $createsTransport;
/** @var CreatesSchedule */
private $createsSchedule;
/** @var FetchesContainer */
private $fetchesContainer;
/** @var FetchesPackingList */
private $fetchesPackingList;
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/** @var CreateContainerProcessor */
private $createContainerProcessor;
/** @var CreatesContract */
private $unityCreateContract;
/** @var AssignContractEntityProcessor */
private $unityAssignContractEntity;
/** @var CreateContractEntityProcessor */
private $unityCreateContractEntity;
/** @var CreatesStep */
private $createsStep;
/** @var ActivateContractProcessor */
private $unityActivateContract;
/**
* FetchLoadedContainersFromVTPortalProcessor constructor.
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
* @param FetchesOrder $fetchesOrder
* @param CreatePackingListProcessor $createPackingListProcessor
* @param CreatePackageProcessor $createPackageProcessor
* @param CreatesTransport $createsTransport
* @param CreatesSchedule $createsSchedule
* @param FetchesContainer $fetchesContainer
* @param FetchesPackingList $fetchesPackingList
* @param FetchesCompanyModule $fetchesCompanyModule
* @param CreateContainerProcessor $createContainerProcessor
* @param CreatesContract $unityCreateContract
* @param AssignContractEntityProcessor $unityAssignContractEntity
* @param CreateContractEntityProcessor $unityCreateContractEntity
* @param CreatesStep $createsStep
* @param ActivateContractProcessor $unityActivateContract
*/
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, FetchesOrder $fetchesOrder, CreatePackingListProcessor $createPackingListProcessor, CreatePackageProcessor $createPackageProcessor, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, FetchesContainer $fetchesContainer, FetchesPackingList $fetchesPackingList, FetchesCompanyModule $fetchesCompanyModule, CreateContainerProcessor $createContainerProcessor, CreatesContract $unityCreateContract, AssignContractEntityProcessor $unityAssignContractEntity, CreateContractEntityProcessor $unityCreateContractEntity, CreatesStep $createsStep, ActivateContractProcessor $unityActivateContract)
{
$this->fetchesDataFRomVTPortal = $fetchesDataFRomVTPortal;
$this->fetchesOrder = $fetchesOrder;
$this->createPackingListProcessor = $createPackingListProcessor;
$this->createPackageProcessor = $createPackageProcessor;
$this->createsTransport = $createsTransport;
$this->createsSchedule = $createsSchedule;
$this->fetchesContainer = $fetchesContainer;
$this->fetchesPackingList = $fetchesPackingList;
$this->fetchesCompanyModule = $fetchesCompanyModule;
$this->createContainerProcessor = $createContainerProcessor;
$this->unityCreateContract = $unityCreateContract;
$this->unityAssignContractEntity = $unityAssignContractEntity;
$this->unityCreateContractEntity = $unityCreateContractEntity;
$this->createsStep = $createsStep;
$this->unityActivateContract = $unityActivateContract;
}
/**
* @param Carbon|null $start
* @param Carbon|null $end
* @return array
* @throws GuzzleException
*/
public function execute(?Carbon $start = null, ?Carbon $end = null){
DB::beginTransaction();
try {
$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"]';
$containersRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VCustomercontainer","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
$containers = $this->fetchesDataFRomVTPortal->getResponseBody($containersRequest);
foreach ($containers->Rows as $container){
$filter = '["ContainerID:=%js%'.$container[11].'"]';
$containerDetailRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
$containerDetail = $this->fetchesDataFRomVTPortal->getResponseBody($containerDetailRequest);
$containerObject = new ContainerObject($container[0], str_replace(' ', '', $container[24]), str_replace(' ', '', $container[15]), ContainerTypes::FORTY_FEET_DRY_CONTAINER, ApprovalStatus::PENDING_VERIFICATION);
try {
$container = $this->fetchesContainer->execute(['reference' => $containerObject->getReference()]);
} catch (ResourceNotFoundException $exception){
$warehouseId = $container[12];
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $warehouseId === 11 ? 3 : 4]);
$container = $this->createContainerProcessor->execute($containerObject, $originWarehouse);
}
foreach($containerDetail->Rows as $packingList){
$marking = explode('/', explode('CIEF/', $packingList[13])[1]);
if(!array_key_exists(1, $marking)){
continue;
}
$orderNumber = $marking[1];
if(!$packingList[22]){
continue;
}
try {
/** @var Order $order */
$order = $this->fetchesOrder->execute(['reference' => $orderNumber]);
} catch (ResourceNotFoundException $exception){
continue;
}
$packingListReference = $packingList[16];
try{
$this->fetchesPackingList->execute(['reference' => $packingListReference]);
} catch (ResourceNotFoundException $exception){
$contract = $this->unityCreateContract->execute();
$contractReference = $contract->hash_id;
$contractObligations = $contract->contract_obligation_list;
$this->unityActivateContract->execute($contractReference);
$supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id;
$supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId);
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]);
$importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id);
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]);
$this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations);
$packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION, $contractReference);
/** @var PackingList $packingList */
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
$container->packingLists()->attach($packingList);
foreach($contractObligations as $obligation) {
$stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id);
$this->createsStep->execute($packingList, $stepObject);
}
}
}
}
} catch (\Exception $exception){
Log::error($exception);
}
DB::commit();
return [];
}
}
@@ -1,85 +0,0 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Models\PackingList;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FetchPackingListFromVTPortalProcessor
{
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomVTPortal;
/** @var ListsPackingLists */
private $listsPackingLists;
/** @var CreatePackageProcessor */
private $createPackageProcessor;
/**
* FetchPackingListFromVTPortalProcessor constructor.
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
* @param ListsPackingLists $listsPackingLists
* @param CreatePackageProcessor $createPackageProcessor
*/
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, ListsPackingLists $listsPackingLists, CreatePackageProcessor $createPackageProcessor)
{
$this->fetchesDataFRomVTPortal = $fetchesDataFRomVTPortal;
$this->listsPackingLists = $listsPackingLists;
$this->createPackageProcessor = $createPackageProcessor;
}
/**
* @return array
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(){
$packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get();
foreach($packingLists as $packingList){
try {
DB::beginTransaction();
$filter = '["PoNumber:=%js%\"'.$packingList->reference.'\"\u0000"]';
$shippingPackingListsRequest = $this->fetchesDataFRomVTPortal->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"VPodetailparcel","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC","Filter":'.$filter.'}}'), '');
$shippingPackingLists = $this->fetchesDataFRomVTPortal->getResponseBody($shippingPackingListsRequest);
$packingList->packages()->delete();
foreach($shippingPackingLists->Rows as $shippingPackingList){
if(!$shippingPackingList[22]) {
continue;
}
$packageObject = new PackageObject(PackageType::CARTON, $shippingPackingList[19], $shippingPackingList[31], $shippingPackingList[30], $shippingPackingList[29], 0, $shippingPackingList[22], ApprovalStatus::APPROVED);
$this->createPackageProcessor->execute($packageObject, $packingList);
}
DB::commit();
} catch (GuzzleException $exception) {
continue;
}
}
return [];
}
}
@@ -2,230 +2,275 @@
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Exceptions\ResourceNotFoundException;
use App\Classes\Modules\Addresses\Processors\CreateAddressFromOldAddressProcessor;
use App\Classes\Modules\Addresses\Services\CleansOldAddress;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\Orders\Processors\CreateOrderProcessor;
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\PackingLists\ControllersLogic\Packages\CreatePackageLogic;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
use App\Classes\Modules\Transports\Services\CreatesTransport;
use App\Classes\General\Services\GeneratesInitials;
use App\Classes\Modules\Accounts\Processors\CreateUserProcessor;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Classes\Modules\Addresses\Services\CreatesAddress;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyConnectionObject;
use App\Classes\Modules\Companies\Processors\CreateCompanyModuleProcessor;
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
use App\Classes\Modules\Companies\Services\ApprovesCompanyConnection;
use App\Classes\Modules\Companies\Services\CreatesCompanyConnection;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransportType;
use App\Models\Address;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Models\Company;
use App\Models\CompanyModule;
use App\Models\OldOrders;
use App\Models\PackingList;
use App\Models\Transport;
use App\Models\District;
use App\Models\OldAddress;
use App\Models\OldCompany;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Cache;
use Psr\Http\Message\ResponseInterface;
class FetchWarehouseReceiveListFromVTPortalProcessor
{
/** @var CreateUserProcessor */
private $createUserProcessor;
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomVTPortal;
/** @var CreateCompanyProcessor */
private $createCompanyProcessor;
/** @var CleansOldAddress */
private $cleansOldAddress;
/** @var UpdatesCompanyStatus*/
private $updatesCompanyStatus;
/** @var CreateAddressFromOldAddressProcessor */
private $createAddressFromOldAddressProcessor;
/** @var CreateCompanyModuleProcessor */
private $createCompanyModuleProcessor;
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/** @var CreateContactProcessor */
private $createContactProcessor;
/** @var FetchesOrder */
private $fetchesOrder;
/** @var CreatesCompanyConnection */
private $createsCompanyConnection;
/** @var CreateOrderProcessor */
private $createOrderProcessor;
/** @var ApprovesCompanyConnection */
private $approvesCompanyConnection;
/** @var FetchesPackingList */
private $fetchesPackingList;
/** @var CreatePackingListProcessor */
private $createPackingListProcessor;
/** @var CreatePackageLogic */
private $createPackage;
/** @var CreatePackageProcessor */
private $createPackageProcessor;
/** @var CreatesTransport */
private $createsTransport;
/** @var CreatesSchedule */
private $createsSchedule;
/** @var CreatesAddress */
private $createsAddress;
/**
* FetchWarehouseReceiveListFromVTPortalProcessor constructor.
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
* @param CleansOldAddress $cleansOldAddress
* @param CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor
* @param FetchesCompanyModule $fetchesCompanyModule
* @param FetchesOrder $fetchesOrder
* @param CreateOrderProcessor $createOrderProcessor
* @param FetchesPackingList $fetchesPakcingList
* @param CreatePackingListProcessor $createPackingListProcessor
* @param CreatePackageLogic $createPackage
* @param CreatePackageProcessor $createPackageProcessor
* @param CreatesTransport $createsTransport
* @param CreatesSchedule $createsSchedule
* @param CreateUserProcessor $createUserProcessor
* @param CreateCompanyProcessor $createCompanyProcessor
* @param UpdatesCompanyStatus $updatesCompanyStatus
* @param CreateCompanyModuleProcessor $createCompanyModuleProcessor
* @param CreateContactProcessor $createContactProcessor
* @param CreatesCompanyConnection $createsCompanyConnection
* @param ApprovesCompanyConnection $approvesCompanyConnection
* @param CreatesAddress $createsAddress
*/
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, CleansOldAddress $cleansOldAddress, CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor, FetchesCompanyModule $fetchesCompanyModule, FetchesOrder $fetchesOrder, CreateOrderProcessor $createOrderProcessor, FetchesPackingList $fetchesPakcingList, CreatePackingListProcessor $createPackingListProcessor, CreatePackageLogic $createPackage, CreatePackageProcessor $createPackageProcessor, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule)
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, UpdatesCompanyStatus $updatesCompanyStatus, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, CreatesAddress $createsAddress)
{
$this->fetchesDataFRomVTPortal = $fetchesDataFRomVTPortal;
$this->cleansOldAddress = $cleansOldAddress;
$this->createAddressFromOldAddressProcessor = $createAddressFromOldAddressProcessor;
$this->fetchesCompanyModule = $fetchesCompanyModule;
$this->fetchesOrder = $fetchesOrder;
$this->createOrderProcessor = $createOrderProcessor;
$this->fetchesPackingList = $fetchesPakcingList;
$this->createPackingListProcessor = $createPackingListProcessor;
$this->createPackage = $createPackage;
$this->createPackageProcessor = $createPackageProcessor;
$this->createsTransport = $createsTransport;
$this->createsSchedule = $createsSchedule;
$this->createUserProcessor = $createUserProcessor;
$this->createCompanyProcessor = $createCompanyProcessor;
$this->updatesCompanyStatus = $updatesCompanyStatus;
$this->createCompanyModuleProcessor = $createCompanyModuleProcessor;
$this->createContactProcessor = $createContactProcessor;
$this->createsCompanyConnection = $createsCompanyConnection;
$this->approvesCompanyConnection = $approvesCompanyConnection;
$this->createsAddress = $createsAddress;
}
/**
* @param Carbon|null $start
* @param Carbon|null $end
* @return array
* @return string
* @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){
public function execute(){
DB::beginTransaction();
// $addresses = OldAddress::whereIn('id', [2, 3, 4, 9, 11, 12, 17, 18, 19, 22, 23, 27, 28, 30, 31, 33, 36, 38, 40, 42, 45, 50, 51, 52, 53, 54, 58, 59, 61, 67, 68, 70, 72, 78, 80, 82, 83, 85, 86, 89, 93, 94, 97, 100, 102, 103, 104, 106, 107, 111, 115, 120, 125, 126, 128, 130, 131, 132, 133, 134, 135, 136, 137, 140, 142, 144, 145, 155, 156, 159, 170, 172, 173, 175, 177, 178, 180, 181, 182, 183, 185, 186, 187, 190, 199, 200, 202, 204, 207, 210, 213, 214, 215, 217, 218, 220, 222, 228, 231, 232, 234, 237, 242, 244, 245, 251, 252, 255, 258, 259, 261, 262, 266, 268, 273, 274, 275, 278, 281, 282, 285, 287, 292, 294, 295, 296, 297, 299, 303, 306, 307, 308, 311, 315, 316, 317, 319, 320, 321, 328, 329, 330, 332, 333, 334, 336, 339, 341]);
$companies = OldCompany::has('orders')->get();
try {
foreach($companies as $company){
$start = $start ? $start : Carbon::now()->subMonth();
$startLimit = Carbon::parse('11-08-2021');
if($start->isBefore($startLimit)){
$start = $startLimit;
$marking = explode("CIEF/", $company->marking);
if(count($marking) < 2){
continue;
}
$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"]';
/** @var Company $newCompany */
$newCompany = $this->createCompanyProcessor->execute($company->name, CompanyType::COMPANY_BUSINESS, ApprovalStatus::PENDING_SUBMISSION);
$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.'}}'), '');
$this->updatesCompanyStatus->execute($newCompany, ApprovalStatus::APPROVED);
$response = $this->fetchesDataFRomVTPortal->getResponseBody($warehouseListRequest);
/** @var CompanyModule $companyModule */
$companyModule = $this->createCompanyModuleProcessor->execute($newCompany, BusinessType::IMPORTER);
foreach ($response->Rows as $parcel){
$marking = explode('/', explode('CIEF/', $parcel[5])[1]);
$connectionObject = new CompanyConnectionObject($companyModule, 'CIEF', $marking[1]);
if(!array_key_exists(1, $marking)){
$connection = $this->createsCompanyConnection->execute($connectionObject);
$this->approvesCompanyConnection->execute($connection);
$i = 0;
foreach($company->addresses as $address){
if($address->street_one === '' && $address->street_two === ''){
continue;
}
$orderNumber = $marking[1];
if(!$parcel[9]){
if(!$address->post_code){
continue;
}
try {
$order = $this->fetchesOrder->execute(['reference' => $orderNumber]);
} catch (ResourceNotFoundException $exception) {
$district = District::where('postcode', 'like', '%'. $address->post_code .'%')->first();
$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);
if(!$district) {
continue;
}
$packingListReference = $parcel[17];
$quantity = $parcel[9];
$measurement = round(($parcel[10]/$quantity) ** (1/3) * 100, 2);
$description = $parcel[7];
$tracking = $parcel[6];
$receiveDate = $parcel[1];
$street_one = str_replace($district->name, '',str_replace($district->state->name, '', $address->street_one));
$street_two = str_replace($district->name, '',str_replace($district->state->name, '', $address->street_two));
$packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST, ApprovalStatus::APPROVED);
$object = new AddressObject($street_one, $street_two, $district->country_id, $district->state_id, $district->id, $address->post_code, 'Business Address');
$this->createsAddress->execute($companyModule, $object);
/** @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);
if($address->contact){
$i++;
if($i === 1) {
$contactObject = new ContactObject('', $address->contact, $company->email, '',);
$this->createContactProcessor->execute($contactObject, $newCompany);
}
}
/** @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());
}
dd('done');
DB::commit();
return '';
Cache::forget('VT_COOKIE_CACHE');
$loginRequest = $this->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"WarehouseList","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"SortExpression":"ModifiedOn DESC"}}'), '');
$response = $this->getResponseBody($loginRequest);
$orders = [];
$unknown = 0;
foreach ($response->Rows as $parcel){
$marking = explode('/', explode('CIEF/', $parcel[5])[1]);
$customerMarking = $marking[0];
if($customerMarking === '2752CHG'){
if(!array_key_exists(1, $marking)){
$unknown++;
echo "found and order without order number";
continue;
}
$orderNumber = $marking[1];
$ctn = $parcel[9];
if(!array_key_exists($customerMarking, $orders)){
$orders[$customerMarking] = [
$orderNumber => [
'ctn' => $ctn,
'cbm' => $parcel[10],
]
];
continue;
}
//
if(!array_key_exists($orderNumber, $orders[$customerMarking])){
$orders[$customerMarking][$orderNumber]['ctn'] = 0;
$orders[$customerMarking][$orderNumber]['cbm'] = 0;
}
$orders[$customerMarking][$orderNumber]['ctn'] += $ctn;
$orders[$customerMarking][$orderNumber]['cbm'] += $parcel[10];
}
// $orders[$customerMarking][$orderNumber]['cbm'] += $parcel[10];
// $orders[$customerMarking][$orderNumber]['ctn'] += $ctn;
// if(!$orders->contains($customerMarking)){
// $orders->push(collect([
// $customerMarking => collect()
// ]));
// }
// dd($orders);
//
// if(!$orders[$customerMarking]->contains($orderNumber)){
// $orders[$customerMarking]->push(collect([
// $orderNumber => [
// 'ctn' => $ctn,
// 'cbm' => $parcel[10]
// ]
// ]));
// } else {
// $orders[$customerMarking][$orderNumber]['ctn'] += $ctn;
// $orders[$customerMarking][$orderNumber]['cbm'] += $parcel[10];
// }
}
dd($orders, $unknown);
}
/**
* @throws GuzzleException
*/
private function remoteLogin(){
$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'];
}
$latest_cookie = implode(';', $latest_cookie);
/** @var $loginRequest */
$loginRequest = $this->clientRequest('https://portalvt.azurewebsites.net/Services/DataControllerService.asmx/Login', 'POST', [
"username" => "CIEF",
"password" => "0122120880",
"createPersistentCookie" => true,
], $latest_cookie, false);
Cache::store('file')->put('VT_COOKIE_CACHE', $latest_cookie.';AppVTCC='.$this->getResponseBody($loginRequest)->AccessToken, 3000);
}
/**
* @param string $url
* @param string $method
* @param $body
* @param string $cookie
* @param bool $requiresAuthentication
* @return ResponseInterface
* @throws GuzzleException
*/
private function clientRequest(string $url, string $method, $body, string $cookie, $requiresAuthentication = true){
if($requiresAuthentication) {
if(!Cache::has('VT_COOKIE_CACHE')){
$this->remoteLogin();
}
}
$client = new \GuzzleHttp\Client(
[
'cookies' => true,
'headers' => [
'Content-Type' => 'application/json',
'Cookie' => Cache::has('VT_COOKIE_CACHE') ? Cache::get('VT_COOKIE_CACHE'):$cookie
]
]
);
$request = $client->request($method, $url, [\GuzzleHttp\RequestOptions::JSON => $body]);
return $request;
}
private function getResponseBody(ResponseInterface $request){
return json_decode($request->getBody()->getContents())->d;
}
}
@@ -1,58 +0,0 @@
<?php
namespace App\Classes\Modules\PackingList\Processors;
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Classes\Modules\Orders\Processors\UpdatesOrderCurrentStepProcessor;
use App\Classes\Modules\Steps\Processors\UpdateStepsProcessor;
use App\Classes\Modules\Orders\Services\FetchesOrder;
use App\Classes\Modules\Steps\Services\FetchesSteps;
use App\Classes\Modules\Orders\Services\UpdatesCurrentStep;
use App\Classes\Modules\Orders\Standards\Rules\CanUpdateCurrentStep;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Classes\Modules\Steps\Services\CreatesManySteps;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\OrderSteps;
use App\Classes\ValueObjects\Constants\Steps;
use App\Classes\Modules\Unity\Processors\GetContractObligationsProcessor;
use App\Models\CompanyModule;
use App\Models\Order;
use App\Models\Step;
use App\Classes\Jobs\UnityLogin;
use Config;
use Illuminate\Support\Facades\Http;
use function PHPSTORM_META\map;
class GenerateShippingOrderStepsProcessor
{
/** @var CreatesManySteps */
private $createsManyStep;
/** @var UpdateStepsProcessor */
private $updateStepProcessors;
/**
* GenerateShippingOrderStepsProcessor constructor.
* @param CreatesManySteps $createsManyStep
* @param UpdateStepsProcessor $updateStepProcessors
*/
public function __construct(CreatesManySteps $createsManyStep, UpdateStepsProcessor $updateStepProcessors)
{
$this->createsManyStep = $createsManyStep;
$this->updateStepProcessors = $updateStepProcessors;
}
public function execute(Steppable $owner, CompanyModule $appointee, array $contract_obligation_list = []){
$obligations = $contract_obligation_list;
$this->createsManyStep->execute($owner, array_map(function($obligation) use ($appointee) {
return new StepsObject($appointee->id, $obligation->name,true, $step->sequence??0, 0,0, null,0, $step->hash_id);
}, $obligations));
$this->updateStepProcessors->execute(OrderSteps::PROCESSING);
}
}
@@ -2,29 +2,26 @@
namespace App\Classes\Modules\PackingLists\Services\Containers;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Models\Container;
class CreatesContainer extends AbstractUpdateRelationshipRecord
class CreatesContainer extends AbstractUpdateRecord
{
/**
* @param ContainerObject $object
* @param ContainerOwner $owner
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(ContainerObject $object, ContainerOwner $owner) {
public function execute(ContainerObject $object) {
$model = new Container();
$model->reference = $object->getReference();
$model->container_number = $object->getContainerNumber();
$model->packing_list_id = $object->getPackingListId();
$model->container_reference = $object->getContainerReference();
$model->container_type = $object->getContainerType();
$model->seal_reference = $object->getSealNumber();
$model->status = $object->getStatus();
$model->seal_reference = $object->getSealReference();
return $this->handler($owner->containers(), $model);
return $this->handler($model);
}
}
@@ -3,27 +3,17 @@
namespace App\Classes\Modules\PackingLists\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Packable;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Models\PackingList;
class CreatesPackingList extends AbstractUpdateRelationshipRecord
class CreatesPackingList extends AbstractUpdateRecord
{
/**
* @param PackingListObject $object
* @param Packable $packable
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(PackingListObject $object, Packable $packable) {
public function execute(PackingListObject $object) {
$model = new PackingList();
$model->reference = $object->getReference();
$model->claimant_id = $object->getClaimantId();
$model->type = $object->getType();
$model->status = $object->getStatus();
return $this->handler($packable->packingLists(), $model);
return $this->handler($model);
}
}
@@ -3,15 +3,15 @@
namespace App\Classes\Modules\PackingLists\Services\Packages;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Models\Package;
use App\Models\PackingList;
class CreatesPackage extends AbstractUpdateRelationshipRecord
class CreatesPackage extends AbstractUpdateRecord
{
public function execute(PackageObject $object, PackingList $packingList) {
public function execute(PackageObject $object) {
$model = new Package();
$model->order_id = $object->getOrderId();
$model->claimant_id = $object->getClaimantId();
$model->type = $object->getType();
$model->description = $object->getDescription();
$model->width = $object->getWidth();
@@ -21,7 +21,7 @@ class CreatesPackage extends AbstractUpdateRelationshipRecord
$model->quantity = $object->getQuantity();
$model->status = $object->getStatus();
return $this->handler($packingList->packages(), $model);
return $this->handler($model);
}
}
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\PackingLists\Standards\Rules\Containers;
namespace App\Classes\Modules\PackingLists\Standards\Containers\Rules;
use App\Classes\General\Abstracts\AbstractRule;
@@ -10,16 +10,16 @@ use App\Classes\Modules\PackingLists\Standards\Validators\ContainerValidation;
class CanCreateContainer extends AbstractRule
{
/** @var ContainerValidation */
private $containerValidation;
/** @var PackingListValidation */
private $containerPackingListValidation;
/**
* CanCreateContainer constructor.
* @param ContainerValidation $containerValidation
* CanCreatePackingList constructor.
* @param PackingListValidation $PackingListValidation
*/
public function __construct(ContainerValidation $containerValidation)
public function __construct(ContainerValidation $containerPackingListValidation)
{
$this->containerValidation = $containerValidation;
$this->containerPackingListValidation = $containerPackingListValidation;
}
@@ -34,19 +34,19 @@ class CanCreateContainer extends AbstractRule
}
/**
* @param ContainerObject $object
* @param PackingListObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->containerValidation->validate($object);
return $this->containerPackingListValidation->validate($object);
}
/**
* @param ContainerObject $object
* @param PackingListObject $object
* @return bool
*/
protected function criteria($object): bool
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\PackingLists\Standards\Rules\Containers;
namespace App\Classes\Modules\PackingLists\Standards\Containers\Rules;
use App\Classes\General\Abstracts\AbstractRule;
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\PackingLists\Standards\Rules\Containers;
namespace App\Classes\Modules\PackingLists\Standards\Containers\Rules;
use App\Classes\General\Abstracts\AbstractRule;
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\PackingLists\Standards\Rules\Containers;
namespace App\Classes\Modules\PackingLists\Standards\Containers\Rules;
use App\Classes\General\Abstracts\AbstractRule;
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\PackingLists\Standards\Rules\Containers;
namespace App\Classes\Modules\PackingLists\Standards\Containers\Rules;
use App\Classes\General\Abstracts\AbstractRule;
@@ -15,7 +15,10 @@ class ContainerValidation extends AbstractValidation
*/
protected function data($object): array {
return [
'reference' => $object->getReference()
'packing_list_id' => $object->getPackingListId(),
'container_reference' => $object->getContainerReference(),
'container_type' => $object->getContainerType(),
'seal_reference' => $object->getSealReference(),
];
}
@@ -24,7 +27,8 @@ class ContainerValidation extends AbstractValidation
*/
protected function rules(): array {
return [
'reference' => 'required'
'packing_list_id' => 'required',
'container_reference' => 'required',
];
}
@@ -16,6 +16,7 @@ class PackageValidation extends AbstractValidation
*/
protected function data($object): array {
return [
'order_id' => $object->getOrderId(),
'type' => $object->getType(),
'width' => $object->getWidth(),
'height' => $object->getHeight(),
@@ -30,6 +31,7 @@ class PackageValidation extends AbstractValidation
*/
protected function rules(): array {
return [
'order_id' => 'required',
'type' => 'required',
'width' => 'required',
'height' => 'required',
@@ -8,42 +8,54 @@ use Carbon\Carbon;
class ScheduleObject implements DataTransferObject
{
/** @var Carbon */
/** @var Carbonn date */
private $etd;
/** @var Carbon */
/** @var Carbon date */
private $eta;
/** @var int */
private $transport_id;
/** @var int */
private $status;
/**
* ScheduleObject constructor.
* @param Carbon $etd
* @param Carbon $eta
* @param int $status
* ScheduleObject constructor
* @param int $etd
* @param int $eta
* @param int $transport_id
*/
public function __construct(Carbon $etd, Carbon $eta, int $status)
public function __construct(string $etd, string $eta, int $transport_id, int $status)
{
$this->etd = $etd;
$this->eta = $eta;
$this->transport_id = $transport_id;
$this->status = $status;
}
/**
* @return Carbon
* @return string
*/
public function getEtd(): Carbon
public function getETD(): Carbon
{
return $this->etd;
return Carbon::parse($this->etd);
}
/**
* @return Carbon
* @return string
*/
public function getEta(): Carbon
public function getETA(): Carbon
{
return $this->eta;
return Carbon::parse($this->eta);
}
/**
* @return int
*/
public function getTransportId(): int
{
return $this->transport_id;
}
/**
@@ -53,6 +65,4 @@ class ScheduleObject implements DataTransferObject
{
return $this->status;
}
}
@@ -22,7 +22,6 @@ class CreatesSchedule extends AbstractUpdateRelationshipRecord
$model->etd = $object->getETD();
$model->eta = $object->getETA();
$model->status = $object->getStatus();
return $this->handler($transport->schedules(), $model);
@@ -7,64 +7,81 @@ use Carbon\Carbon;
class StepsObject implements DataTransferObject
{
/** @var int */
private $appointeeId;
private $id;
private $appointee_id;
/** @var string */
private $reference;
/** @var float */
private $primary;
private $sequence;
/** @var string */
private $obligationId;
private $status;
/**
* StepsObject constructor.
* @param int $appointeeId
* @param string $reference
* @param float $sequence
* @param string $obligationId
*/
public function __construct(int $appointeeId, string $reference, float $sequence, string $obligationId)
private $contract_status;
private $completed_date;
private $hash_id;
public function __construct(int $appointee_id, string $reference, bool $primary, float $sequence, int $status, int $contract_status, ?string $completed_date, int $id=0, ?string $hash_id)
{
$this->appointeeId = $appointeeId;
$this->appointee_id = $appointee_id;
$this->reference = $reference;
$this->primary = $primary;
$this->sequence = $sequence;
$this->obligationId = $obligationId;
$this->status = $status;
$this->contract_status = $contract_status;
$this->completed_date = $completed_date;
$this->id = $id;
$this->hash_id = $hash_id;
}
/**
* @return int
*/
public function getAppointeeId(): int
{
return $this->appointeeId;
return $this->appointee_id;
}
/**
* @return string
*/
public function getReference(): string
{
return $this->reference;
}
/**
* @return float
*/
public function getPrimary(): bool
{
return $this->primary;
}
public function getSequence(): float
{
return $this->sequence;
}
/**
* @return string
*/
public function getObligationId(): string
public function getStatus(): int
{
return $this->obligationId;
return $this->status;
}
public function getContractStatus(): int
{
return $this->contract_status;
}
public function getCompletedDate(): Carbon
{
return $this->completed_date ? Carbon::parse($this->completed_date) : Carbon::now();
}
public function getId(): int
{
return $this->id;
}
public function getHashId(): ?string
{
return $this->hash_id;
}
}
@@ -35,20 +35,11 @@ class CreateStepsProcessor
$this->fetchesSteps = $fetchesSteps;
}
/**
* @param Order $order
* @param string $currentStep
* @param $appointee_id
* @return Model
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function execute(Order $order, string $currentStep, $appointee_id){
public function execute(Model $order, string $currentStep, $appointee_id){
$stepObject = new StepsObject( $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null, 0, null);
$order_steps_object = new StepsObject( $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null, 0, null);
$this->canCreateStep->passes($stepObject);
$this->canCreateStep->passes($order_steps_object);
return $this->createsSteps->execute($order, $order_steps_object);
@@ -8,10 +8,10 @@ use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Models\Step;
use App\Models\Order;
class CreatesManySteps extends AbstractUpdateRelationshipRecord
class CreatesManySteps extends AbstractUpdateRecord
{
public function execute(Steppable $owner, array $orderSteps) {
public function execute(Order $order, array $orderSteps) {
$orderStepsModel=[];
foreach($orderSteps as $step){
@@ -1,33 +0,0 @@
<?php
namespace App\Classes\Modules\Steps\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Steppable;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Models\Step;
use App\Models\Order;
class CreatesStep extends AbstractUpdateRelationshipRecord
{
/**
* @param Steppable $owner
* @param StepsObject $orderSteps
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Steppable $owner, StepsObject $orderSteps) {
$model = new Step();
$model->appointee_id = $orderSteps->getAppointeeId();
$model->reference = $orderSteps->getReference();
$model->sequence = $orderSteps->getSequence();
$model->obligation_hash_id = $orderSteps->getObligationId();
return $this->handler($owner->steps(), $model);
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Classes\Modules\Steps\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Models\Step;
use App\Models\Order;
class CreatesSteps extends AbstractUpdateRelationshipRecord
{
/**
* @param Order $order
* @param StepsObject $orderSteps
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Order $order, StepsObject $orderSteps) {
$orderStepsModel = new Step();
$orderStepsModel->appointee_id = $orderSteps->getAppointeeId();
$orderStepsModel->reference = $orderSteps->getReference();
$orderStepsModel->primary = $orderSteps->getPrimary();
$orderStepsModel->sequence = $orderSteps->getSequence();
$orderStepsModel->status = 0;
$orderStepsModel->contract_status = 0;
$orderStepsModel->complete_date = null;
return $this->handler($order->orderSteps(), $orderStepsModel);
}
}
@@ -11,44 +11,44 @@ class TransportObject implements DataTransferObject
/** @var string */
private $type;
/** @var null|string */
/** @var string|null */
private $courier;
/** @var null|string */
private $trackingNumber;
/** @var int */
private $tracking_number;
/** @var Carbon|null */
private $dispatchDate;
/** @var int */
private $dispacth_date;
/** @var Carbon|null */
private $dropDate;
/** @var int */
private $drop_date;
/** @var int */
private $status;
/**
* TransportObject constructor.
* @param string $type
* @param int $type
* @param null|string $courier
* @param null|string $trackingNumber
* @param Carbon|null $dispatchDate
* @param Carbon|null $dropDate
* @param string $tracking_number
* @param int $dispatch_date
* @param int $drop_date
* @param int $status
*/
public function __construct(string $type, ?string $courier, ?string $trackingNumber, ?Carbon $dispatchDate, ?Carbon $dropDate, int $status)
public function __construct(int $type, string $courier, string $tracking_number, ?string $dispatch_date, ?string $drop_date, int $status)
{
$this->type = $type;
$this->courier = $courier;
$this->trackingNumber = $trackingNumber;
$this->dispatchDate = $dispatchDate;
$this->dropDate = $dropDate;
$this->tracking_number = $tracking_number;
$this->dispatch_date = $dispatch_date;
$this->drop_date = $drop_date;
$this->status = $status;
}
/**
* @return string
* @return int
*/
public function getType(): string
public function getType(): int
{
return $this->type;
}
@@ -62,27 +62,27 @@ class TransportObject implements DataTransferObject
}
/**
* @return null|string
* @return int
*/
public function getTrackingNumber(): ?string
public function getTrackingNumber(): string
{
return $this->trackingNumber;
return $this->tracking_number;
}
/**
* @return Carbon|null
* @return int
*/
public function getDispatchDate(): ?Carbon
{
return $this->dispatchDate;
return $this->dispatch_date ? Carbon::parse($this->dispatch_date) : null;
}
/**
* @return Carbon|null
* @return int
*/
public function getDropDate(): ?Carbon
{
return $this->dropDate;
return $this->drop_date ? Carbon::parse($this->drop_date) : null;
}
/**
@@ -4,7 +4,6 @@ namespace App\Classes\Modules\Transports\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Transportable;
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
use App\Models\Transport;
use App\Models\Container;
@@ -13,12 +12,12 @@ class CreatesTransport extends AbstractUpdateRelationshipRecord
{
/**
* @param Container $containerPackingList
* @param TransportObject $object
* @param Transportable $transportable
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(TransportObject $object, Transportable $transportable) {
public function execute(Container $containerPackingList, TransportObject $object) {
$model = new Transport();
$model->type = $object->getType();
@@ -28,7 +27,7 @@ class CreatesTransport extends AbstractUpdateRelationshipRecord
$model->drop_date = $object->getDropDate();
$model->status = $object->getStatus();
return $this->handler($transportable->transports(), $model);
return $this->handler($containerPackingList->transports(), $model);
}
}
@@ -20,12 +20,15 @@ class AssignContractEntityProcessor
$this->fetchesCompany = $fetchesCompany;
}
public function execute(string $contractEntities, array $obligations){
public function execute(Request $request, array $contractEntities, array $obligations){
$responses = [];
//CIEF Contract Entity Hash ID
$contract_entity_hash_id = $contractEntities[0]->hash_id;
foreach($obligations as $obligation){
$responses[] = $this->updatesContractEntity->execute($obligation->hash_id, [$contractEntities]);
$responses[] = $this->updatesContractEntity->execute($obligation->hash_id, [$contract_entity_hash_id]);
}
return $responses;
@@ -20,7 +20,7 @@ class CreateContractEntityProcessor
$this->fetchesCompany = $fetchesCompany;
}
public function execute(string $new_contract_id, string $entity_hash_ids){
public function execute(string $new_contract_id, array $entity_hash_ids){
return $this->createsContractEntity->execute($new_contract_id, $entity_hash_ids);
}
}
@@ -21,10 +21,12 @@ class CreatesContractEntity
$this->contract_hash_id = Config::get('unity.contract_template_hash_id');
}
public function execute(string $new_contract_id, string $entity_hash_ids){
public function execute(string $new_contract_id, array $entity_hash_ids){
$accesToken=$this->getAccessToken->execute();
$response = Http::withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object();
return (isset($response->data)) ? $response->data : null;
}
@@ -1,11 +0,0 @@
<?php
namespace App\Classes\ValueObjects\Constants;
final class PackageType {
public const CARTON = 0;
public const PALLET = 1;
}
@@ -1,18 +0,0 @@
<?php
namespace App\Classes\ValueObjects\Constants;
final class PackingListType {
public const SUPPLIER_PACKING_LIST = 0;
public const WAREHOUSE_RECEIVE_LIST = 1;
public const SHIPPING_PACKING_LIST = 2;
public const TRANSPORT_PACKING_LIST = 3;
public const DELIVERY_PACKING_LIST = 4;
}
@@ -1,15 +0,0 @@
<?php
namespace App\Classes\ValueObjects\Constants;
final class TransportType {
public const AIR = 0;
public const SEA = 1;
public const LAND = 2;
}
@@ -14,24 +14,5 @@ final class WarehouseReferences {
public const SARAWAK = 'SRW-V01';
public const DESTINATION_WAREHOUSE = [
1 => self::KLANG,
2 => self::KLANG,
3 => self::KLANG,
4 => self::KLANG,
5 => self::SABAH,
6 => self::KLANG,
7 => self::KLANG,
8 => self::KLANG,
9 => self::KLANG,
10 => self::KLANG,
11 => self::KLANG,
12 => self::KLANG,
13 => self::SABAH,
14 => self::KLANG,
15 => self::KLANG,
16 => self::KLANG,
];
}
+1 -10
View File
@@ -2,11 +2,6 @@
namespace App\Console;
use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob;
use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob;
use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob;
use App\Classes\Jobs\FetchPackingListFromVTPortalJob;
use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -29,11 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(FetchWarehouseReceiveListFromVTPortalJob::class)->dailyAt('21:00');
$schedule->job(FetchLoadedContainersFromVTPortalJob::class)->dailyAt('21:15');
$schedule->job(FetchPackingListFromVTPortalJob::class)->dailyAt('21:30');
$schedule->job(FetchContainersStatusUpdateFromVTPortalJob::class)->dailyAt('21:45');
$schedule->job(FetchDeliveryListFromVTPortalJob::class)->dailyAt('22:00');
// $schedule->command('inspire')->hourly();
}
/**
+1 -1
View File
@@ -16,7 +16,7 @@ class ContactResource extends JsonResource
{
return [
'id' => $this->id,
// 'country_code' => $this->country->phone_code,
//'country_code' => $this->country->phone_code,
'reference' => $this->reference,
'phone' => $this->phone,
'email' => $this->email,
+2 -2
View File
@@ -16,10 +16,10 @@ class ContainerResource extends JsonResource
{
return [
'id' => $this->id,
'container_reference' => $this->reference,
'container_reference' => $this->container_reference,
'container_type' => $this->container_type,
'container_number' => $this->container_number,
'seal_reference' => $this->seal_reference,
'packing_list' => PackingListResource::collection($this->packingLists),
'transport' => TransportResource::collection($this->transports),
];
}
-53
View File
@@ -2,11 +2,7 @@
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransportType;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderResource extends JsonResource
@@ -28,55 +24,6 @@ class OrderResource extends JsonResource
'company_module' => new CompanyModuleResource($this->companyModule),
'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee),
'address' => new AddressResource($this->addresses()->first()),
$this->mergeWhen($this->relationLoaded('parcels'), [
'origin_warehouse_packages' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::SHIPPING_PACKING_LIST)->whereDoesntHave('containers', function($query) {
return $query->whereHas('transports', function($query){
return $query->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
});
})->get()),
'in_transit_packages' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::SHIPPING_PACKING_LIST)->whereHas('containers', function($query) {
return $query->whereHas('transports', function($query){
return $query->where('status', '=', ApprovalStatus::APPROVED)->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
});
})->get()),
'destination_warehouse_packages' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::SHIPPING_PACKING_LIST)->whereHas('containers', function($query) {
return $query->whereHas('transports', function($query){
return $query->where('type', '=', TransportType::SEA)->where('status', '=', ApprovalStatus::COMPLETED)->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
})->whereDoesntHave('transports', function($query){
return $query->where('type', '=', TransportType::LAND)->where('status', '=', ApprovalStatus::APPROVED)->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
})->get()),
'delivered_packages' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::SHIPPING_PACKING_LIST)->whereHas('containers', function($query) {
return $query->whereHas('transports', function($query){
return $query->where('type', '=', TransportType::SEA)->where('status', '=', ApprovalStatus::COMPLETED)->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
})->whereHas('transports', function($query){
return $query->where('type', '=', TransportType::LAND)->where('status', '=', ApprovalStatus::APPROVED)->whereHas('schedules', function($query){
return $query->where('etd', '<', Carbon::now());
});
});
})->get()),
'parcels' => PackageResource::collection($this->parcels()->whereHas('packingList', function($query){
return $query->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST);
})->get()),
]),
'created_at' => $this->created_at->format('d-m-Y')
];
}
+4 -7
View File
@@ -16,18 +16,15 @@ class PackageResource extends JsonResource
{
return [
'id' => $this->id,
'packing_list_id' => $this->packing_list_id,
'type' => $this->type,
'description' => $this->description,
'width' => floatval($this->width),
'height' => floatval($this->height),
'length' => floatval($this->length),
'width' => $this->width,
'height' => $this->height,
'length' => $this->length,
'weight' => $this->weight,
'quantity' => $this->quantity,
'cbm' => (($this->width / 100) * ($this->width / 100) * ($this->width / 100)) * $this->quantity,
'status' => $this->status,
'order' => new OrderResource($this->packingList->owner),
'container' => new ContainerResource($this->packingList->containers()->first()),
'transport' => new TransportResource($this->packingList->transports()->first())
];
}
}
@@ -19,8 +19,6 @@ class PackingListResource extends JsonResource
'claimant_id' => $this->claimant_id,
'reference' => $this->reference,
'status' => $this->status,
'transport' => new TransportResource($this->transports()->first()),
'packages' => PackageResource::collection($this->packages),
];
}
}
+2 -2
View File
@@ -16,8 +16,8 @@ class ScheduleResource extends JsonResource
{
return [
'id' => $this->id,
'etd' => $this->etd->format('d-m-Y'),
'eta' => $this->eta->format('d-m-Y'),
'etd' => $this->etd,
'eta' => $this->eta,
'status' => $this->status,
];
}
+2 -5
View File
@@ -2,7 +2,6 @@
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Illuminate\Http\Resources\Json\JsonResource;
class TransportResource extends JsonResource
@@ -20,11 +19,9 @@ class TransportResource extends JsonResource
'type' => $this->type,
'courier' => $this->courier,
'tracking_number' => $this->tracking_number,
'dispatch_date' => $this->dispatch_date ? $this->dispatch_date->format('d-m-Y') : $this->dispatch_date,
'drop_date' => $this->drop_date ? $this->drop_date->format('d-m-Y') : $this->drop_date,
'dispatch_date' => $this->dispatch_date,
'drop_date' => $this->drop_date,
'status' => $this->status,
'current_schedule' => new ScheduleResource($this->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()),
'schedule_history' => ScheduleResource::collection($this->schedules()->where('status', '!=', ApprovalStatus::APPROVED)->get())
];
}
}
+4 -4
View File
@@ -11,10 +11,10 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
* Class Address
* @package App\Models
*
* @property int country_id
* @property int company_id
* @property int state_id
* @property int district_id
* @property \App\Models\Country country_id
* @property \App\Models\Company company_id
* @property \App\Models\State state_id
* @property \App\Models\District district_id
* @property string postcode
* @property string street_one
* @property string street_two
+1 -12
View File
@@ -4,7 +4,6 @@ namespace App\Models;
use App\Classes\General\Interfaces\Addressable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
@@ -28,7 +27,7 @@ use PhpParser\Node\Expr\AssignOp\Mod;
* @property integer type
* @property integer status
*/
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable
{
use SoftDeletes;
@@ -121,14 +120,6 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable,
return $this->HasMany(Bank::class, 'company_id');
}
/**
* @return MorphMany
*/
public function containers(): morphMany
{
return $this->morphMany(Container::class, 'owner');
}
/**
* @param Builder $query
* @return Builder
@@ -156,6 +147,4 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable,
return $query->where('type', '=', BusinessType::WAREHOUSE);
}
}
+2 -5
View File
@@ -2,22 +2,19 @@
namespace App\Models;
use App\Classes\General\Interfaces\Transportable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Container extends AbstractModel implements Transportable
class Container extends AbstractModel
{
use SoftDeletes;
protected $table = 'containers';
protected $fillable = ['status'];
public function packingLists(): belongsToMany
{
return $this->belongsToMany(PackingList::class, ContainerPackingList::class, 'container_id', 'packing_list_id');
return $this->belongsToMany(PackingList::class, Container::class, 'container_id', 'packing_list_id');
}
/**
+1 -1
View File
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class ContainerPackingList extends AbstractModel
class Container extends AbstractModel
{
use SoftDeletes;
+5
View File
@@ -2,7 +2,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class OldAddress extends Model
{
+12
View File
@@ -2,9 +2,21 @@
namespace App\Models;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceConfigurationsObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
class OldCompany extends Model
+3 -16
View File
@@ -2,9 +2,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class OldOrders extends Model
{
@@ -12,20 +15,4 @@ class OldOrders extends Model
protected $table = 'orders';
/**
* @return hasOne
*/
public function address(): hasOne
{
return $this->hasOne(OldAddress::class, 'reference_id', 'address_id')->where('type', '=', 1);
}
/**
* @return belongsTo
*/
public function company(): belongsTo
{
return $this->belongsTo(OldCompany::class, 'company_id');
}
}
+1 -21
View File
@@ -3,17 +3,14 @@
namespace App\Models;
use App\Classes\General\Interfaces\Addressable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\Packable;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Scopes\CustomerOrdersScope;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Order extends AbstractModel implements Addressable, Packable
class Order extends AbstractModel implements Addressable
{
use SoftDeletes;
@@ -46,22 +43,6 @@ class Order extends AbstractModel implements Addressable, Packable
return $this->morphMany(Address::class, 'owner');
}
/**
* @return MorphMany
*/
public function packingLists(): morphMany
{
return $this->morphMany(PackingList::class, 'owner');
}
/**
* @return HasManyThrough
*/
public function parcels(): HasManyThrough
{
return $this->HasManyThrough(Package::class, PackingList::class, 'owner_id', 'packing_list_id')->where('owner_type', Order::class);
}
/**
* @return HasMany
*/
@@ -70,7 +51,6 @@ class Order extends AbstractModel implements Addressable, Packable
return $this->HasMany(OrderRole::class, 'order_id');
}
protected static function booted()
{
// if (auth()->user()->type === RoleTypes::USER) {
-2
View File
@@ -10,8 +10,6 @@ class OrderRole extends Model
{
use HasFactory;
protected $fillable = ['entity_hash_id', 'entity_signature'];
/**
* @return BelongsTo
*/
+7 -6
View File
@@ -3,7 +3,6 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -13,12 +12,14 @@ class Package extends AbstractModel
protected $table = 'packages';
/**
* @return BelongsTo
*/
public function packingList(): BelongsTo
public function order(): BelongsTo
{
return $this->belongsTo(PackingList::class, 'packing_list_id');
return $this->BelongsTo(Order::class, 'order_id', 'id');
}
public function owner(): morphTo
{
return $this->morphTo();
}
}
+2 -43
View File
@@ -2,58 +2,17 @@
namespace App\Models;
use App\Classes\General\Interfaces\Steppable;
use App\Classes\General\Interfaces\Transportable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class PackingList extends AbstractModel implements Transportable, Steppable
class PackingList extends AbstractModel
{
use SoftDeletes;
protected $table = 'packing_lists';
protected $fillable = ['status'];
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function owner(): morphTo
{
return $this->morphTo();
}
public function containers(): BelongsToMany
{
return $this->BelongsToMany(Container::class, ContainerPackingList::class);
}
/**
* @return MorphMany
*/
public function steps(): morphMany
public function orderSteps(): morphMany
{
return $this->morphMany(Step::class, 'owner');
}
/**
* @return HasMany
*/
public function packages(): hasMany
{
return $this->hasMany(Package::class, 'packing_list_id');
}
/**
* @return morphMany
*/
public function transports(): morphMany
{
return $this->morphMany(Transport::class, 'owner');
}
}
-2
View File
@@ -12,8 +12,6 @@ class Schedule extends AbstractModel
protected $table = 'schedules';
protected $dates = ['etd', 'eta'];
public function owner(): morphTo
{
return $this->morphTo();
+13 -3
View File
@@ -10,12 +10,22 @@ class Step extends AbstractModel
{
use SoftDeletes;
protected $table = 'steps';
protected $fillable = ['status'];
protected $table = 'order_steps';
protected $dates = ['deleted_at'];
protected $fillable = ['order_id','appointee_id','reference','primary','sequence','status','contract_status','complete_date','unity_hash_id'];
public function companyModule(): belongsTo
{
return $this->belongsTo(CompanyModule::class, 'appointee_id', 'id');
}
public function orderRole(): belongsTo
{
return $this->belongsTo(OrderRole::class, 'appointee_id', 'company_module_id');
}
public function owner(): morphTo
{
return $this->morphTo();
-4
View File
@@ -13,10 +13,6 @@ class Transport extends AbstractModel
protected $table = 'transport_arrangements';
protected $fillable = ['status', 'drop_date'];
protected $dates = ['dispatch_date', 'drop_date'];
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
+5 -5
View File
@@ -65,12 +65,12 @@ return [
'old_izyim_db' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'url' => env('DATABASE_URL_IZYIM'),
'host' => env('DB_HOST_IZYIM', '127.0.0.1'),
'port' => env('DB_PORT_IZYIM', '3306'),
'database' => env('DB_DATABASE_IZYIM', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'username' => env('DB_USERNAME_IZYIM', 'forge'),
'password' => env('DB_PASSWORD_IZYIM', ''),
'unix_socket' => env('DB_SOCKET_IZYIM', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
+1 -1
View File
@@ -38,7 +38,7 @@ return [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 3600,
'retry_after' => 90,
'after_commit' => false,
],
+7 -1
View File
@@ -41,7 +41,9 @@ return [
'on_error_email' => env('UNITY_ON_ERROR_EMAIL','dev@shipping.com,dev@unity.com'),
'contract_template_hash_id' => env('UNITY_CONTRACT_TEMPLATE_HASH_ID', 'Kp3qzMV82m5R2PZg6eX0'),
'contract_template_id' => env('UNITY_CONTRACT_TEMPLATE_ID', 105),
'contract_template_hash_id' => env('UNITY_CONTRACT_TEMPLATE_HASH_ID', 'zDMkNBK3dpej1Zpg7yv9'),
'contract_template_cache' => env('UNITY_CONTRACT_TEMPLATE_CACHE','60'),
@@ -49,4 +51,8 @@ return [
'PACKING' => Constant\OrderSteps::PACKING,
],
'step_processors' => [
Constant\OrderSteps::PACKING => Step\Packing::class,
],
];
@@ -1,6 +1,5 @@
<?php
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -20,9 +19,9 @@ class CreateStepsTable extends Migration
$table->bigInteger('appointee_id')->unsigned()->index();
$table->string('obligation_hash_id',200)->nullable();
$table->string('reference');
$table->integer('primary')->default(false);
$table->integer('primary')->default(0);
$table->decimal('sequence', 4, 2);
$table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION);
$table->integer('status')->default(0);
$table->date('complete_date')->nullable();
$table->softDeletes();
$table->timestamps();
@@ -16,8 +16,7 @@ class CreatePackingListsTable extends Migration
Schema::create('packing_lists', function (Blueprint $table) {
$table->id();
$table->morphs('owner');
$table->bigInteger('claimant_id')->unsigned()->index()->nullable();
$table->string('reference_contract')->nullable();
$table->bigInteger('claimant_id')->unsigned()->index()->nullable(true);
$table->string('reference',200);
$table->integer('type')->default(0);
$table->integer('status')->default(0);
@@ -20,7 +20,7 @@ class CreatePackagesTable extends Migration
$table->integer('type')->default(0);
$table->string('reference')->nullable();
$table->string('description')->nullable();
$table->string('description',45)->nullable();
$table->decimal('width', 8, 2);
$table->decimal('height', 8, 2);
@@ -17,11 +17,10 @@ class CreateContainersTable extends Migration
{
Schema::create('containers', function (Blueprint $table) {
$table->id();
$table->morphs('owner');
$table->string('reference');
$table->string('container_number')->nullable();
$table->string('reference',45);
$table->string('container_number',45);
$table->integer('container_type')->default(ContainerTypes::FORTY_FEET_DRY_CONTAINER);
$table->string('seal_reference')->nullable();
$table->string('seal_reference',45);
$table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION);
$table->softDeletes();
$table->timestamps();
@@ -1,7 +1,5 @@
<?php
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransportType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -18,15 +16,15 @@ class CreateTransportArrangementsTable extends Migration
Schema::create('transport_arrangements', function (Blueprint $table) {
$table->id();
$table->morphs('owner');
$table->integer('type')->default(TransportType::SEA);
$table->integer('type')->default(0);
$table->string('courier')->nullable();
$table->string('tracking_number')->nullable();
$table->string('courier',45);
$table->string('tracking_number',45);
$table->timestamp('dispatch_date')->nullable();
$table->timestamp('drop_date')->nullable();
$table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION);
$table->integer('status')->default(0);
$table->softDeletes();
$table->timestamps();
});
+35 -14
View File
@@ -3,7 +3,6 @@
namespace Database\Seeders;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Classes\Modules\Addresses\Processors\CreateAddressFromOldAddressProcessor;
use App\Classes\Modules\Addresses\Services\CreatesAddress;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyConnectionObject;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
@@ -21,10 +20,12 @@ use App\Classes\ValueObjects\Constants\CompanyType;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Models\CompanyModule;
use App\Models\District;
use App\Models\OldCompany;
use Illuminate\Database\Seeder;
use App\Models\Company;
use Illuminate\Support\Facades\App;
class CompaniesTableSeeder extends Seeder
{
@@ -47,9 +48,6 @@ class CompaniesTableSeeder extends Seeder
/** @var ApprovesCompanyConnection */
private $approvesCompanyConnection;
/** @var CreateAddressFromOldAddressProcessor */
private $createAddressFromOldAddressProcessor;
/** @var CreatesAddress */
private $createsAddress;
@@ -67,12 +65,11 @@ class CompaniesTableSeeder extends Seeder
* @param CreateContactProcessor $createContactProcessor
* @param CreatesCompanyConnection $createsCompanyConnection
* @param ApprovesCompanyConnection $approvesCompanyConnection
* @param CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor
* @param CreatesAddress $createsAddress
* @param CreatesCompany $createsCompany
* @param CreatesContact $createsContact
*/
public function __construct(CreateCompanyProcessor $createCompanyProcessor, UpdatesCompanyStatus $updatesCompanyStatus, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor, CreatesAddress $createsAddress, CreatesCompany $createsCompany, CreatesContact $createsContact)
public function __construct(CreateCompanyProcessor $createCompanyProcessor, UpdatesCompanyStatus $updatesCompanyStatus, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, CreatesAddress $createsAddress, CreatesCompany $createsCompany, CreatesContact $createsContact)
{
$this->createCompanyProcessor = $createCompanyProcessor;
$this->updatesCompanyStatus = $updatesCompanyStatus;
@@ -80,7 +77,6 @@ class CompaniesTableSeeder extends Seeder
$this->createContactProcessor = $createContactProcessor;
$this->createsCompanyConnection = $createsCompanyConnection;
$this->approvesCompanyConnection = $approvesCompanyConnection;
$this->createAddressFromOldAddressProcessor = $createAddressFromOldAddressProcessor;
$this->createsAddress = $createsAddress;
$this->createsCompany = $createsCompany;
$this->createsContact = $createsContact;
@@ -172,20 +168,16 @@ class CompaniesTableSeeder extends Seeder
}
if(true){
if(App::environment(['production'])){
$companies = OldCompany::all();
foreach($companies as $company){
$marking = explode("CIEF/", $company->marking);
if(count($marking) < 2){
continue;
}
$marking = str_replace(' ', '', str_replace('/', '', $marking[1]));
/** @var Company $newCompany */
$newCompany = $this->createCompanyProcessor->execute($company->name, CompanyType::COMPANY_BUSINESS, ApprovalStatus::PENDING_SUBMISSION);
@@ -194,14 +186,33 @@ class CompaniesTableSeeder extends Seeder
/** @var CompanyModule $companyModule */
$companyModule = $this->createCompanyModuleProcessor->execute($newCompany, BusinessType::IMPORTER);
$connectionObject = new CompanyConnectionObject($companyModule, 'CIEF', $marking);
$connectionObject = new CompanyConnectionObject($companyModule, 'CIEF', $marking[1]);
$connection = $this->createsCompanyConnection->execute($connectionObject);
$this->approvesCompanyConnection->execute($connection);
$i = 0;
foreach($company->addresses as $address){
$this->createAddressFromOldAddressProcessor->execute($address, $companyModule);
if($address->street_one === '' && $address->street_two === ''){
continue;
}
if(!$address->post_code){
continue;
}
$district = District::where('postcode', 'like', '%'. $address->post_code .'%')->first();
if(!$district) {
continue;
}
$street_one = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_one));
$street_two = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_two));
$object = new AddressObject(str_replace(', ,', ',', str_replace(', ,', ',', $street_one)), str_replace(', ,', ',', str_replace(', ,', ',', $street_two)), $district->country_id, $district->state_id, $district->id, $address->post_code, 'Business Address');
$this->createsAddress->execute($companyModule, $object);
$contact = preg_replace("/[^0-9.]/", "", $address->contact);
if($contact){
$i++;
@@ -213,10 +224,20 @@ class CompaniesTableSeeder extends Seeder
}
}
}
}
private function cleanAddress($address){
$address = str_replace('Malaysia', '', str_replace('malaysia', '', $address));
$address = str_replace(', ,', ',', str_replace(', ,', ',', str_replace(', ,', ',', $address)));
$address = str_replace(' ', ' ', str_replace(' ', ' ', str_replace(' ', ' ', $address)));
return str_replace(', ,', ',', str_replace(', ,', ',', $address));
}
}
-1
View File
@@ -24,6 +24,5 @@ class DatabaseSeeder extends Seeder
$this->call(CurrenciesTableSeeder::class);
$this->call(CompaniesTableSeeder::class);
$this->call(OrdersTableSeeder::class);
}
}
-33
View File
@@ -1,33 +0,0 @@
<?php
namespace Database\Seeders;
use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob;
use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob;
use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob;
use App\Classes\Jobs\FetchPackingListFromVTPortalJob;
use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob;
use App\Classes\Modules\PackingLists\Processors\FetchContainersStatusUpdateFromVTPortalProcessor;
use Illuminate\Database\Seeder;
class OrdersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
FetchWarehouseReceiveListFromVTPortalJob::withChain([
new FetchLoadedContainersFromVTPortalJob,
new FetchPackingListFromVTPortalJob,
new FetchContainersStatusUpdateFromVTPortalJob,
new FetchDeliveryListFromVTPortalJob
])->dispatch();
}
}

Some files were not shown because too many files have changed in this diff Show More