addresses()->defaultAddress()->first(); /** @var CompanyModule $defaultAddress */ $defaultAddress = $defaultAddress ? $defaultAddress : $this->addresses()->first(); $connection = $this->inviters()->withPivot('invitee_reference')->first(); $marking = $connection ? $connection->pivot->invitee_reference:''; $segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::WAREHOUSE_RATE)->get(); $segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value; return [ 'id' => $this->id, 'type' => $this->type, 'name' => $this->name, 'reference' => $this->reference, 'address' => new AddressResource($defaultAddress), 'billingAddress' => new AddressResource($this->addresses()->where('type', AddressType::BILLING)->where('status', ApprovalStatus::APPROVED)->first()), 'company' => new CompanyResource($this->whenLoaded('company')), 'remarks' => RemarkResource::collection($this->remarks), 'marking' => $marking, 'warehouseCharges' => array_key_exists($this->id, $segmentConstant) ? $segmentConstant[$this->id] : null, 'connections' => $this->connections, 'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())), 'debtor' => $this->company->debtor, 'e_invoice' => $this->company->e_invoice, 'tin' => $this->company->tin, 'msic_code' => $this->company->msic_code, 'address_einvoice' => $this->company->e_invoice ? new AddressEInvoiceResource($this->when($this->has('addresses'), $this->addresses->where('type', AddressType::E_INVOICE)->sortByDesc('created_at')->first())) : null, ]; } }