companyModules()->first(); $companyTypeArray = CompanyType::COMPANY_TYPE_ID; return [ 'id' => $this->id, 'hash_id' => Crypt::encryptString($this->id), 'name' => $this->name, 'debtor' => $this->debtor, 'reference' => $this->reference, 'type' => (int) $this->type, 'type_name' => ($companyTypeArray[(int) $this->type]), 'business_type' => (int) $this->business_type, 'status' => (int) $this->status, 'segments' => SegmentResource::collection($companyModule->connections()->first()->segments), 'is_credit_term' => $companyModule->connections()->first()->is_credit_term, 'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())), 'employee' => new UserResource($companyModule->employees()->first()), 'company_module' => new CompanyModuleResource($companyModule), 'last_order' => $companyModule->type === 7 ? new DeliveryOrderResource($companyModule->orders()->orderBy('id', 'DESC')->first()) : new OrderResource($companyModule->orders()->orderBy('id', 'DESC')->first()), 'order_count' => $companyModule->orders()->count(), 'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->first()), 'created_at' => $this->created_at->format('d-m-Y') ]; } }