id; } public function getCustomer(): ?Customer { return $this->customer; } public function getUser(): ?User { return $this->user; } public function getInvoiceNumber(): ?string { return $this->invoiceNumber; } public function getTotal(): float { return $this->total; } public function getCreatedAt(): ?\DateTime { if (!$this->localized) { if (null !== $this->createdAt && null !== $this->timezone) { $this->createdAt->setTimeZone(new \DateTimeZone($this->timezone)); } $this->localized = true; } return $this->createdAt; } public function getDueDate(): ?\DateTime { if (null === $this->getCreatedAt()) { return null; } $dueDate = clone $this->getCreatedAt(); $dueDate->modify('+ ' . $this->dueDays . 'days'); return $dueDate; } public function isOverdue(): bool { if (null === $this->getDueDate()) { return false; } return $this->getDueDate()->getTimestamp() < (new \DateTime('now', new \DateTimeZone($this->timezone)))->getTimestamp(); } public function setFilename(string $filename): Invoice { $this->invoiceFilename = $filename; return $this; } public function setModel(InvoiceModel $model): Invoice { $this->customer = $model->getCustomer(); $this->user = $model->getUser(); $this->total = $model->getCalculator()->getTotal(); $this->tax = $model->getCalculator()->getTax(); $this->invoiceNumber = $model->getInvoiceNumber(); $this->currency = $model->getCurrency(); $createdAt = $model->getInvoiceDate(); $this->createdAt = $createdAt; $this->timezone = $createdAt->getTimezone()->getName(); $template = $model->getTemplate(); $this->dueDays = $template->getDueDays(); $this->vat = $template->getVat(); return $this; } public function isNew(): bool { return $this->status === self::STATUS_NEW; } public function setIsNew(): Invoice { $this->setPaymentDate(null); $this->status = self::STATUS_NEW; return $this; } public function isPending(): bool { return $this->status === self::STATUS_PENDING; } public function setIsPending(): Invoice { $this->setPaymentDate(null); $this->status = self::STATUS_PENDING; return $this; } public function isPaid(): bool { return $this->status === self::STATUS_PAID; } public function setIsPaid(): Invoice { $this->status = self::STATUS_PAID; return $this; } public function getDueDays(): int { return $this->dueDays; } public function getVat(): float { return $this->vat; } public function getTax(): float { return $this->tax; } public function getCurrency(): ?string { return $this->currency; } public function getInvoiceFilename(): ?string { return $this->invoiceFilename; } /** * @Exporter\Expose(label="invoice.subtotal", type="float", name="subtotal") * @return float|null */ public function getSubtotal(): ?float { return $this->total - $this->tax; } public function getPaymentDate(): ?\DateTime { return $this->paymentDate; } public function setPaymentDate(?\DateTime $paymentDate): Invoice { $this->paymentDate = $paymentDate; return $this; } }