diff --git a/app/Http/Resources/ContainerResource.php b/app/Http/Resources/ContainerResource.php index 49a33232..dd45412c 100644 --- a/app/Http/Resources/ContainerResource.php +++ b/app/Http/Resources/ContainerResource.php @@ -23,17 +23,25 @@ class ContainerResource extends JsonResource 'container_specification' => ContainerTypes::CONTAINER_SPECIFICATION[$this->container_type], 'container_number' => $this->container_number, 'seal_reference' => $this->seal_reference, - 'loading_date' => $this->loading_date ? $this->loading_date->format('d-m-Y') : $this->loading_date, + 'loading_date' => optional($this->loading_date)->format('d-m-Y'), 'transport' => new TransportResource($this->transports()->first()), 'packages_count' => $this->packages()->where('packages.type', '!=', 2)->sum('quantity'), 'total_cbm' => $this->packages()->sum(DB::raw('(width/100) * (height/100) * (length/100) * quantity')), 'remarks' => RemarkResource::collection($this->remarks), 'status' => $this->status, - 'packing_lists' => $this->whenLoaded('packingLists', PackingListResource::collection($this->whenLoaded('packingLists', function(){ - return $this->packingLists()->get()->sortBy(function ($packingList) { - return $packingList->owner->company_module_id; - }); - }))) + 'packing_lists' => $this->shouldIncludePackingListData($request) ? $this->getSortedPackingLists() : null, ]; } + + protected function shouldIncludePackingListData($request) + { + return (isset($request->all()['with_packing_list_data']) && ($request->all()['with_packing_list_data'] == false)) ? false : true; + } + + protected function getSortedPackingLists() + { + return $this->whenLoaded('packingLists', PackingListResource::collection( + $this->packingLists()->get()->sortBy(fn ($packingList) => $packingList->owner->company_module_id) + )); + } } diff --git a/resources/assets/vue/components/containers/forms/ContainerCommentFormComponent.vue b/resources/assets/vue/components/containers/forms/ContainerCommentFormComponent.vue index a77807fa..b38f7ebb 100644 --- a/resources/assets/vue/components/containers/forms/ContainerCommentFormComponent.vue +++ b/resources/assets/vue/components/containers/forms/ContainerCommentFormComponent.vue @@ -1,5 +1,5 @@