user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]); $packages = []; $receive_packing_list = null; if($this->include_packages){ $packages = !$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages; foreach ($packages as $item) { if(isset($this->include_order_in_packages) && $this->include_order_in_packages){ $item['include_order'] = $this->include_order_in_packages; } if(isset($this->include_transport_in_packages) && $this->include_transport_in_packages){ $item['include_transport'] = $this->include_transport_in_packages; } } } if($this->include_receive_packing_list){ $receive_packing_list = $this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first())); } $data = [ 'id' => $this->id, 'claimant_id' => $this->claimant_id, 'reference' => $this->reference, 'status' => $this->status, 'transport' => new TransportResource($this->transports()->first()), 'type' => $this->type, 'receive_packing_list' => $receive_packing_list, 'container' => new ContainerResource($this->containers->first()), 'packages' => PackageBaseResource::collection($packages), $this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]), // 'suspended_invoices' => TransactionResource::collection($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->get()), ]; if($this->include_shipping_transaction){ $data['shipping_transaction'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()); } if($this->include_suspended_invoice){ $data['suspended_invoice'] = new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()); } return $data; } }