diff --git a/app/Classes/Modules/Orders/ControllersLogic/FetchOrderV2Logic.php b/app/Classes/Modules/Orders/ControllersLogic/FetchOrderV2Logic.php new file mode 100644 index 00000000..08d3cc5d --- /dev/null +++ b/app/Classes/Modules/Orders/ControllersLogic/FetchOrderV2Logic.php @@ -0,0 +1,60 @@ + 'Retrieved Order', + 'message' => 'You have successfully retrieved an order' + ]; + } + + /** @var CanFetchOrder */ + private $canFetchOrder; + + /** @var FetchesOrder */ + private $fetchesOrder; + + /** + * FetchOrderLogic constructor. + * @param CanFetchOrder $canFetchOrder + * @param FetchesOrder $fetchesOrder + */ + public function __construct(CanFetchOrder $canFetchOrder, FetchesOrder $fetchesOrder) + { + $this->canFetchOrder = $canFetchOrder; + $this->fetchesOrder = $fetchesOrder; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canFetchOrder->passes(); + + $query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]); + + return $this->resourceResponse(new OrderV2Resource($query)); + + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Orders/FetchOrderV2Controller.php b/app/Http/Controllers/Orders/FetchOrderV2Controller.php new file mode 100644 index 00000000..45161f7f --- /dev/null +++ b/app/Http/Controllers/Orders/FetchOrderV2Controller.php @@ -0,0 +1,20 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Resources/OrderV2Resource.php b/app/Http/Resources/OrderV2Resource.php new file mode 100644 index 00000000..7ca77149 --- /dev/null +++ b/app/Http/Resources/OrderV2Resource.php @@ -0,0 +1,40 @@ + $this->id, + 'reference' => $this->reference, + 'reference_contract' => (int) $this->type, + 'type' => (int) $this->type, + 'status' => (int) $this->status, + 'company_module' => new CompanyModuleResource($this->companyModule), + 'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee), + 'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()), + 'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()), + 'invoices' => $this->whenLoaded('packingLists', function() { + return TransactionResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->get()); + }), + 'remarks' => RemarkResource::collection($this->remarks), + 'created_at' => $this->created_at->format('d-m-Y') + ]; + + } +} diff --git a/resources/assets/vue/components/orders/sections/OrderProfileV2SectionComponent.vue b/resources/assets/vue/components/orders/sections/OrderProfileV2SectionComponent.vue index 8d20856a..4f16cf86 100644 --- a/resources/assets/vue/components/orders/sections/OrderProfileV2SectionComponent.vue +++ b/resources/assets/vue/components/orders/sections/OrderProfileV2SectionComponent.vue @@ -189,7 +189,7 @@ methods: { fetchCompany(){ this.isLoading = true; - this.submit(route('api.order.show', this.order_number), 'get', this.section, false, false) + this.submit(route('api.order.v2.show', this.order_number), 'get', this.section, false, false) }, successHandler(response){ this.$store.dispatch('completeList', {'name': this.section, 'data': []}); diff --git a/routes/order.php b/routes/order.php index 79a67bd8..507b489f 100644 --- a/routes/order.php +++ b/routes/order.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; Route::group(['prefix' => 'order', 'as' => 'order.', 'namespace' => 'Orders'], function () { Route::get('/show/{id}', 'FetchOrderController@fetch')->name('show'); + Route::get('/v2/show/{id}', 'FetchOrderV2Controller@fetch')->name('v2.show'); Route::get('/list', 'ListOrdersController@list')->name('list'); Route::post('/create', 'CreateOrderController@create')->name('create'); Route::put('/confirm/{id}', 'ConfirmOrderController@confirm')->name('confirm');