mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
sync vt do with shipping portal
This commit is contained in:
@@ -53,3 +53,5 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
UNITY_APP_URL="https://unity.izyim.com"
|
||||
EXCHANGE_URL=https://dev.exchange.cief-malaysia.com/
|
||||
MIX_EXCHANGE_URL="${EXCHANGE_URL}"
|
||||
|
||||
YD_API_CODE=''
|
||||
|
||||
@@ -29,6 +29,7 @@ class CurlYdOrderListJob implements ShouldQueue
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -89,15 +89,13 @@ class CreateAddressLogic extends AbstractControllerLogic
|
||||
/** @var Address $address */
|
||||
$address = $this->createsAddress->execute($this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]), $object);
|
||||
|
||||
if($request->input('phone')){
|
||||
$contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', '');
|
||||
|
||||
if($contactObject->getPhone()){
|
||||
$this->createContactProcessor->execute($contactObject, $address);
|
||||
}
|
||||
|
||||
if($request->input('remark')){
|
||||
$remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id);
|
||||
|
||||
if($remarkObject->getContent()){
|
||||
$this->createRemarkProcessor->execute($address, $remarkObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,15 +90,13 @@ class UpdateAddressLogic extends AbstractControllerLogic
|
||||
|
||||
$address->contacts()->delete(); $address->remarks()->delete();
|
||||
|
||||
if($request->input('phone')){
|
||||
$contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', '');
|
||||
|
||||
if($contactObject->getPhone()){
|
||||
$this->createContactProcessor->execute($contactObject, $address);
|
||||
}
|
||||
|
||||
if($request->input('remark')){
|
||||
$remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id);
|
||||
|
||||
if($remarkObject->getContent()){
|
||||
$this->createRemarkProcessor->execute($address, $remarkObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,10 @@ class ApproveChangeOrderAddressProcessor
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\InternalServerErrorException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function execute(Request $request)
|
||||
{
|
||||
@@ -53,12 +55,11 @@ class ApproveChangeOrderAddressProcessor
|
||||
|
||||
if($status === ApprovalStatus::APPROVED){
|
||||
$address->owner->addresses()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
$this->updateDoFromVTPortalProcessor->execute($address);
|
||||
}
|
||||
|
||||
$address = $this->updatesOrdersAddress->execute($address, $status);
|
||||
|
||||
$vt_do_update = $this->updateDoFromVTPortalProcessor->execute($address);
|
||||
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,13 @@ class RequestChangeOrderAddressProcessor
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request)
|
||||
{
|
||||
$this->canChangeOrderAddress->passes();
|
||||
@@ -73,6 +80,7 @@ class RequestChangeOrderAddressProcessor
|
||||
$order_address = $this->createsAddress->execute($order, $addressObject);
|
||||
|
||||
$contact = $address->contacts()->first();
|
||||
if($contact){
|
||||
$contactObject = new ContactObject(
|
||||
$contact->reference,
|
||||
$contact->phone,
|
||||
@@ -80,21 +88,22 @@ class RequestChangeOrderAddressProcessor
|
||||
''
|
||||
);
|
||||
|
||||
if($contactObject->getPhone()){
|
||||
$order_remark = $this->createContactProcessor->execute($contactObject, $order_address);
|
||||
$this->createContactProcessor->execute($contactObject, $order_address);
|
||||
|
||||
}
|
||||
|
||||
$remark = $address->remarks()->first();
|
||||
|
||||
if($remark){
|
||||
$remarkObject = new RemarkObject(
|
||||
$remark->content,
|
||||
Auth()->user()->id
|
||||
);
|
||||
|
||||
if($remarkObject->getContent()){
|
||||
$this->createRemarkProcessor->execute($order_address, $remarkObject);
|
||||
}
|
||||
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\Modules\Orders\Processors;
|
||||
|
||||
use App\Classes\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\Modules\Orders\Services\FetchesDataFromVTPortal;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
|
||||
@@ -33,9 +34,7 @@ class UpdateDoFromVTPortalProcessor
|
||||
/**
|
||||
* FetchDeliveryListFromVTPortalProcessor constructor.
|
||||
* @param FetchesDataFromVTPortal $fetchesDataFRomVTPortal
|
||||
* @param CreatesTransport $createsTransport
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param UpdatesContractObligation $updatesContractObligations
|
||||
* @param FetchesAddress $fetchesAddress
|
||||
*/
|
||||
public function __construct(FetchesDataFromVTPortal $fetchesDataFRomVTPortal, FetchesAddress $fetchesAddress)
|
||||
{
|
||||
@@ -44,7 +43,10 @@ class UpdateDoFromVTPortalProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $address
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function execute($address) {
|
||||
|
||||
@@ -56,61 +58,22 @@ class UpdateDoFromVTPortalProcessor
|
||||
$contact = $address->contacts()->first();
|
||||
$remark = $address->remarks()->first();
|
||||
|
||||
$status = 'Release';
|
||||
$remark = $remark ? $remark->content : 'URGENT!!! PLEASE CALL BEFORE ONE DAY DELIVERY.';
|
||||
$phone = $contact ? $contact->phone : null;
|
||||
$reference = $contact ? $contact->reference : null;
|
||||
|
||||
if ($packing_list->status == ApprovalStatus::PENDING_VERIFICATION) {
|
||||
$status = 'Release';
|
||||
}
|
||||
else if($packing_list->status == ApprovalStatus::SUSPENDED) {
|
||||
$status = 'On Hold';
|
||||
|
||||
if (in_array($packing_list->status, [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$status = 'Release';
|
||||
}
|
||||
|
||||
$vt_do = $this->fetchesDataFRomVTPortal->clientRequest(
|
||||
'http://portal.vtnation.com.my/Services/DataControllerService.asmx/GetPage',
|
||||
'POST',
|
||||
json_decode('{
|
||||
"controller": "Do",
|
||||
"view": "grid1",
|
||||
"request": {
|
||||
"PageIndex": -2,
|
||||
"PageSize": 10,
|
||||
"PageOffset": 0,
|
||||
"SortExpression": "",
|
||||
"GroupExpression": "",
|
||||
"Filter": [
|
||||
"FullMarking:$contains$%js%\"' . $order->reference . '\"\u0000"
|
||||
],
|
||||
"ContextKey": "view2",
|
||||
"FilterIsExternal": true,
|
||||
"LookupContextFieldName": null,
|
||||
"LookupContextController": null,
|
||||
"LookupContextView": null,
|
||||
"LookupContext": null,
|
||||
"Inserting": false,
|
||||
"LastCommandName": null,
|
||||
|
||||
"DoesNotRequireData": false,
|
||||
"LastView": "grid1",
|
||||
"Tag": null,
|
||||
"RequiresFirstLetters": false,
|
||||
"ViewType": "Grid",
|
||||
"SupportsCaching": true,
|
||||
"SystemFilter": null,
|
||||
"RequiresRowCount": true,
|
||||
"QuickFindHint": null,
|
||||
"RequiresPivot": false,
|
||||
"PivotDefinitions": null,
|
||||
"RequiresMetaData": true
|
||||
}
|
||||
}'
|
||||
), '');
|
||||
$vt_do = $this->fetchesDataFRomVTPortal->clientRequest('http://portal.vtnation.com.my/Services/DataControllerService.asmx/GetPage', 'POST', json_decode('{"controller":"Do","view":"grid1","request":{"PageIndex":-1,"PageSize":10000,"Filter": ["FullMarking:$contains$%js%\"' . $order->reference . '\"\u0000"]}}'), '');
|
||||
|
||||
$vt_do = $this->fetchesDataFRomVTPortal->getResponseBody($vt_do);
|
||||
|
||||
if ($vt_do) {
|
||||
foreach ($vt_do->Rows as $key => $row) {
|
||||
|
||||
$vt_do_update = $this->fetchesDataFRomVTPortal->clientRequest(
|
||||
'http://portal.vtnation.com.my/Services/DataControllerService.asmx/Execute',
|
||||
'POST',
|
||||
@@ -125,21 +88,21 @@ class UpdateDoFromVTPortalProcessor
|
||||
"Values": [
|
||||
{
|
||||
"Name": "ShippingAddress",
|
||||
"NewValue": "' . $address->street_one . ' ' . $address->street_two . '",
|
||||
"NewValue": "' . $address->street_one . ' ' . $address->street_two . ' '. $address->district->name.' '. $address->post_code.' '.$address->state->name.' '.$address->country->name.'",
|
||||
"Modified": true,
|
||||
"ReadOnly": false,
|
||||
"Error": null
|
||||
},
|
||||
{
|
||||
"Name": "Attn",
|
||||
"NewValue": "' . $contact->reference . '",
|
||||
"NewValue": "'.$reference.'",
|
||||
"Modified": true,
|
||||
"ReadOnly": false,
|
||||
"Error": null
|
||||
},
|
||||
{
|
||||
"Name": "Tel",
|
||||
"NewValue": "' . $contact->phone . '",
|
||||
"NewValue": "'.$phone.'",
|
||||
"Modified": true,
|
||||
"ReadOnly": false,
|
||||
"Error": null
|
||||
@@ -153,40 +116,21 @@ class UpdateDoFromVTPortalProcessor
|
||||
},
|
||||
{
|
||||
"Name": "Doremarks",
|
||||
"NewValue": "' . $remark->content . '",
|
||||
"NewValue": "'. $remark .'",
|
||||
"Modified": true,
|
||||
"ReadOnly": false,
|
||||
"Error": null
|
||||
},
|
||||
{
|
||||
"Name": "ModifiedBy",
|
||||
"OldValue": "CIEF",
|
||||
"NewValue": "CIEF",
|
||||
"Modified": false,
|
||||
"ReadOnly": false,
|
||||
"Error": null
|
||||
},
|
||||
{
|
||||
"Name": "DoID",
|
||||
"OldValue": 1471,
|
||||
"OldValue": '.$row[0].',
|
||||
"NewValue": '.$row[0].',
|
||||
"Modified": false,
|
||||
"ReadOnly": true,
|
||||
"Error": null
|
||||
}
|
||||
],
|
||||
"ContextKey": "do",
|
||||
"Controller": "Do",
|
||||
"View": "editForm1",
|
||||
"LastView": "grid1",
|
||||
"Tag": null,
|
||||
"Filter": [
|
||||
"DoID:=%js%' . $row[0] . '",
|
||||
"ContainerID:=%js%' . $row[1] . '"
|
||||
],
|
||||
"SortExpression": "",
|
||||
"GroupExpression": "",
|
||||
"SelectedValues": []
|
||||
"Controller": "Do"
|
||||
}
|
||||
}'), '');
|
||||
}
|
||||
@@ -194,9 +138,8 @@ class UpdateDoFromVTPortalProcessor
|
||||
}
|
||||
|
||||
} catch (\Exception $exception){
|
||||
Log::error($exception);
|
||||
throw new InternalServerErrorException('failed to approve address due to an error related to VT portal');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ class FetchesDataFromYDPortal
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @param $body
|
||||
* @param bool $requiresAuthentication
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function clientRequest(string $url, string $method, $body){
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
$body['apicode'] = env('YD_API_CODE');
|
||||
|
||||
$request = $client->requestAsync($method, $url, ['query' => $body]);
|
||||
|
||||
return $request->wait();
|
||||
|
||||
@@ -53,7 +53,9 @@ class UpdatePackingListStatusLogic extends AbstractControllerLogic
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\InternalServerErrorException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
@@ -62,7 +64,7 @@ class UpdatePackingListStatusLogic extends AbstractControllerLogic
|
||||
$packing_list = $this->updatesPackingListStatus->execute($packingList, $request->route('status'));
|
||||
$address = $packing_list->owner()->first()->addresses()->first();
|
||||
|
||||
$vt_do_update = $this->updateDoFromVTPortalProcessor->execute($address);
|
||||
$this->updateDoFromVTPortalProcessor->execute($address);
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($packing_list));
|
||||
}
|
||||
|
||||
+32
-8
@@ -4,6 +4,8 @@ namespace App\Classes\Modules\PackingLists\Processors;
|
||||
|
||||
use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal;
|
||||
|
||||
use App\Models\Order;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -21,20 +23,42 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
/**
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
* @return void
|
||||
*/
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null) {
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null)
|
||||
{
|
||||
$start = $start ? $start : Carbon::now()->subMonths(2);
|
||||
|
||||
$startLimit = Carbon::parse('01-12-2021');
|
||||
|
||||
if($start->isBefore($startLimit)){
|
||||
$start = $startLimit;
|
||||
}
|
||||
|
||||
$end = $end ? $end : Carbon::now();
|
||||
|
||||
$orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [
|
||||
'apicode' => '393b1cb4b8b37d09',
|
||||
'begintime' => '1633968000',
|
||||
'endtime' => '1639308222',
|
||||
'begintime' => $start->timestamp,
|
||||
'endtime' => $end->timestamp,
|
||||
]);
|
||||
|
||||
$order = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
|
||||
|
||||
foreach($rows->data as $row){
|
||||
if (strpos($row->customerno, '/') !== false) { $customerno = explode('/', explode('CIEF/', $row->customerno)[1]); }
|
||||
if(strpos($row->customerno, '-') !== false){ $customerno = explode('-', explode('CIEF-', $row->customerno)[1]); }
|
||||
|
||||
$marking = $customerno[0];
|
||||
$orderNumber = $customerno[1];
|
||||
|
||||
$order = Order::where('reference', $orderNumber)->first();
|
||||
|
||||
if(!$order){
|
||||
continue;
|
||||
}
|
||||
|
||||
dump($order);
|
||||
}
|
||||
|
||||
dd($order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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\FetchOrderListsFromYdPortalProcessor;
|
||||
use App\Models\CompanyConnection;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use App\Models\Container;
|
||||
@@ -177,3 +178,7 @@ Route::get('/debug', function (){
|
||||
|
||||
dd($issues);
|
||||
});
|
||||
|
||||
Route::get('/yd', function (){
|
||||
(App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user