company_id); } /** * @return Location * @throws \Exception */ public function getLocation(): Location { return Location::get($this->location_id); } public function getNumber(): int { return $this->id + 999; } public function getDisplayStatus(): string { return SaleStatuses::enumToText($this->status); } /** * @param array $nvp * @return SaleNote[] */ public function getNotes(array $nvp = []): array { $nvp = array_merge($nvp, ["sale_id" => $this->id]); return SaleNote::query($nvp, ["sort" => "id"]); } /** * @param array $nvp * @return SaleItem[] */ public function getItems(array $nvp = []): array { $nvp = array_merge($nvp, ["sale_id" => $this->id]); return SaleItem::query($nvp, ["sort" => "id"]); } public function getUrl(): string { return sprintf("/leads/%d", $this->getNumber()); } public function getUser(): User { return User::get($this->user_id); } public function getDocuments(array $nvp = []): array { $nvp = array_merge($nvp, ["sale_id" => $this->id]); return Document::query($nvp, [ "sort" => "id", "order" => "desc" ]); } /** * @return Document[] */ public function getSalesOrders(): array { return $this->getDocuments(["type" => DocumentTypes::SALES_ORDER]); } /** * @return Ticket[] */ public function getTickets(): array { return Ticket::query([ "sale_id" => $this->id ], [ "sort" => "id", "order" => "desc" ]); } public function getCurrency(): string { return $this->currency; } public function getTitle(): string { return __("Lead %d", $this->getNumber()); } public function getDisplayPredictedSoldDate(string $format = "d/m/Y"): string { if(!$this->date_predicted_sold) { return ""; } return CarbonImmutable::parse($this->date_predicted_sold)->format($format); } /** * @return Document[] */ public function getChildDocuments(): array { return Document::query([ "sale_id" => $this->id, "type" => DocumentTypes::SALES_ORDER ], [ "sort" => "type", ]); } }