<?php
/**
* @author Quentin CHATELAIN (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\RecurringInvoicesBundle\Entity;
use App\Entity\Traits\EntityManagerServiceEntity;
use App\Services\SoftdeleteFilter;
use Bluue\SalesBundle\DoctrineExtensions\EditPricesWithTaxEntity;
use DateTime;
use DateTimeInterface;
use App\Entity\Context;
use App\Entity\Currency;
use Doctrine\ORM\NonUniqueResultException;
use Symfony\Component\Uid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use Bluue\SalesBundle\Entity\Invoice;
use Gedmo\Mapping\Annotation as Gedmo;
use Bluue\SalesBundle\Entity\Quotation;
use Bluue\SalesBundle\Entity\PaymentTerm;
use Doctrine\Common\Collections\Criteria;
use App\DoctrineExtensions\IsActiveEntity;
use Bluue\CustomersBundle\Entity\Customer;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use App\DoctrineExtensions\Cancelable\Traits\UserCancelableEntity;
use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
use Bluue\RecurringInvoicesBundle\Repository\RecurringInvoiceRepository;
use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
use App\Entity\Establishment;
/**
* @ORM\Entity(repositoryClass=RecurringInvoiceRepository::class)
* @ORM\Table(name="recurring_invoices_bundle__recurring_invoice", indexes={
* @ORM\Index(name="internal_name", columns={"internal_name"}),
* @ORM\Index(name="total_amount_untaxed", columns={"total_amount_untaxed"}),
* @ORM\Index(name="total_amount", columns={"total_amount"}),
* @ORM\Index(name="is_active", columns={"is_active"}),
* @ORM\Index(name="canceled_at", columns={"canceled_at"}),
* @ORM\Index(name="deleted_at", columns={"deleted_at"}),
* @ORM\Index(name="created_at", columns={"created_at"}),
* @ORM\Index(name="updated_at", columns={"updated_at"})
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
*/
class RecurringInvoice
{
use IsActiveEntity;
use UserCancelableEntity;
use UserTimestampableEntity;
use UserSoftDeleteableEntity;
use EditPricesWithTaxEntity;
use EntityManagerServiceEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private ?Uuid $id = null;
/**
* @ORM\ManyToOne(targetEntity=Context::class)
*/
private ?Context $context = null;
/**
* @ORM\ManyToOne(targetEntity=Customer::class)
* @ORM\JoinColumn(nullable=false)
*/
private ?Customer $customer = null;
/**
* @ORM\ManyToOne(targetEntity=Quotation::class)
*/
private ?Quotation $quotation = null;
/**
* @ORM\ManyToOne(targetEntity=Customer::class)
*/
private ?Customer $invoiceAddress = null;
/**
* @ORM\ManyToOne(targetEntity=Customer::class)
*/
private ?Customer $deliveryAddress = null;
/**
* @ORM\ManyToOne(targetEntity=Customer::class)
*/
private ?Customer $invoiceContact = null;
/**
* @ORM\ManyToOne(targetEntity=Customer::class)
*/
private ?Customer $deliveryContact = null;
/**
* @ORM\ManyToOne(targetEntity=Currency::class)
*/
private ?Currency $currency = null;
/**
* @ORM\ManyToOne(targetEntity=PaymentTerm::class)
*/
private ?PaymentTerm $paymentTerm = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=12)
*/
private ?string $currencyChangeRate = null;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private ?string $reference = null;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private ?string $internalName = null;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private ?string $externalName = null;
/**
* @ORM\Column(type="boolean")
*/
private bool $reducedVat = false;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalDiscountUntaxed = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalDiscount = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalAmountNoDiscountUntaxed = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalAmountNoDiscount = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalAmountUntaxed = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalTaxAmount = null;
/**
* @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
*/
private ?string $totalAmount = null;
/**
* @ORM\Column(type="date", nullable="true")
*/
private ?DateTimeInterface $lastInvoiceGeneration = null;
/**
* @ORM\Column(type="date", nullable="true")
*/
private ?DateTimeInterface $nextInvoiceGeneration = null;
/**
* @ORM\Column(type="integer", nullable="true")
*/
private ?int $dailyRecurrence = null;
/**
* @ORM\Column(type="integer", nullable="true")
*/
private ?int $monthlyRecurrence = null;
/**
* @ORM\Column(type="integer", nullable="true")
*/
private ?int $annualRecurrence = null;
/**
* @ORM\Column(type="integer", nullable="true")
*/
private ?int $maxInvoices = 12;
/**
* @ORM\Column(type="boolean")
*/
private bool $autoValidation = false;
/**
* @ORM\Column(type="boolean")
*/
private bool $finished = false;
/**
* @ORM\Column(type="json")
*/
private array $options = [];
/**
* @ORM\OneToMany(
* targetEntity=RecurringInvoiceLine::class,
* mappedBy="recurringInvoice",
* cascade={"persist", "remove"},
* fetch="EXTRA_LAZY"
* )
* @ORM\OrderBy({"position" = "ASC"})
*/
private Collection $lines;
/**
* @ORM\OneToMany(targetEntity=Invoice::class, mappedBy="recurringInvoice", fetch="EXTRA_LAZY")
*/
private Collection $invoices;
/**
* @ORM\ManyToOne(targetEntity=Establishment::class)
*/
private ?Establishment $establishment = null;
/**
* @ORM\ManyToOne(targetEntity=RecurringInvoice::class)
*/
private ?self $recurringInvoiceMerged = null;
public function __construct()
{
$this->lines = new ArrayCollection();
$this->invoices = new ArrayCollection();
}
/**
* @return Uuid|null
*/
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return $this
*/
public function setId(): self
{
$this->id = null;
return $this;
}
/**
* @return Context|null
*/
public function getContext(): ?Context
{
return $this->context;
}
/**
* @param Context|null $context
* @return RecurringInvoice
*/
public function setContext(?Context $context): RecurringInvoice
{
$this->context = $context;
return $this;
}
/**
* @return Customer|null
* @throws NonUniqueResultException
*/
public function getCustomer(): ?Customer
{
if ($this->em && $this->customer) {
SoftdeleteFilter::disable($this->em, [Customer::class]);
$customer = $this->em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.id = :customerId')
->setParameter('customerId', $this->customer->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Customer::class]);
return $customer;
}
return $this->customer;
}
/**
* @param Customer|null $customer
* @return RecurringInvoice
*/
public function setCustomer(?Customer $customer): RecurringInvoice
{
$this->customer = $customer;
$this->setDeliveryAddress(null);
return $this->setInvoiceAddress($customer);
}
/**
* @return Quotation|null
* @throws NonUniqueResultException
*/
public function getquotation(): ?Quotation
{
if ($this->em && $this->quotation) {
SoftdeleteFilter::disable($this->em, [Quotation::class]);
$quotation = $this->em->getRepository(Quotation::class)
->createQueryBuilder('q')
->where('q.id = :quotationId')
->setParameter('quotationId', $this->quotation->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Quotation::class]);
return $quotation;
}
return $this->quotation;
}
/**
* @param Quotation|null $quotation
* @return $this
*/
public function setquotation(?Quotation $quotation): self
{
$this->quotation = $quotation;
return $this;
}
/**
* @return Customer|null
* @throws NonUniqueResultException
*/
public function getInvoiceAddress(): ?Customer
{
if ($this->em && $this->invoiceAddress) {
SoftdeleteFilter::disable($this->em, [Customer::class]);
$invoiceAddress = $this->em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.id = :invoiceAddress')
->setParameter('invoiceAddress', $this->invoiceAddress->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Customer::class]);
return $invoiceAddress;
}
return $this->invoiceAddress;
}
/**
* @param Customer|null $invoiceAddress
* @return RecurringInvoice
*/
public function setInvoiceAddress(?Customer $invoiceAddress): RecurringInvoice
{
$this->invoiceAddress = $invoiceAddress;
return $this;
}
/**
* @return Customer|null
* @throws NonUniqueResultException
*/
public function getDeliveryAddress(): ?Customer
{
if ($this->em && $this->deliveryAddress) {
SoftdeleteFilter::disable($this->em, [Customer::class]);
$deliveryAddress = $this->em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.id = :deliveryAddress')
->setParameter('deliveryAddress', $this->deliveryAddress->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Customer::class]);
return $deliveryAddress;
}
return $this->deliveryAddress;
}
/**
* @param Customer|null $deliveryAddress
* @return RecurringInvoice
*/
public function setDeliveryAddress(?Customer $deliveryAddress): RecurringInvoice
{
$this->deliveryAddress = $deliveryAddress;
return $this;
}
/**
* @return Customer|null
* @throws NonUniqueResultException
*/
public function getInvoiceContact(): ?Customer
{
if ($this->em && $this->invoiceContact) {
SoftdeleteFilter::disable($this->em, [Customer::class]);
$invoiceContact = $this->em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.id = :invoiceContact')
->setParameter('invoiceContact', $this->invoiceContact->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Customer::class]);
return $invoiceContact;
}
return $this->invoiceContact;
}
/**
* @param Customer|null $invoiceContact
* @return RecurringInvoice
*/
public function setInvoiceContact(?Customer $invoiceContact): RecurringInvoice
{
$this->invoiceContact = $invoiceContact;
return $this;
}
/**
* @return Customer|null
* @throws NonUniqueResultException
*/
public function getDeliveryContact(): ?Customer
{
if ($this->em && $this->deliveryContact) {
SoftdeleteFilter::disable($this->em, [Customer::class]);
$deliveryContact = $this->em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.id = :deliveryContact')
->setParameter('deliveryContact', $this->deliveryContact->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [Customer::class]);
return $deliveryContact;
}
return $this->deliveryContact;
}
/**
* @param Customer|null $deliveryContact
* @return RecurringInvoice
*/
public function setDeliveryContact(?Customer $deliveryContact): RecurringInvoice
{
$this->deliveryContact = $deliveryContact;
return $this;
}
/**
* @return Currency|null
*/
public function getCurrency(): ?Currency
{
return $this->currency;
}
/**
* @param Currency $currency
* @return RecurringInvoice
*/
public function setCurrency(Currency $currency): RecurringInvoice
{
$this->currency = $currency;
return $this->setCurrencyChangeRate($currency->getChangeRate());
}
/**
* @return PaymentTerm|null
* @throws NonUniqueResultException
*/
public function getPaymentTerm(): ?PaymentTerm
{
if ($this->em && $this->paymentTerm) {
SoftdeleteFilter::disable($this->em, [PaymentTerm::class]);
$paymentTerm = $this->em->getRepository(PaymentTerm::class)
->createQueryBuilder('pt')
->where('pt.id = :paymentTermId')
->setParameter('paymentTermId', $this->paymentTerm->getId()->toBinary())
->getQuery()
->getOneOrNullResult();
SoftdeleteFilter::enable($this->em, [PaymentTerm::class]);
return $paymentTerm;
}
return $this->paymentTerm;
}
/**
* @param PaymentTerm|null $paymentTerm
* @return RecurringInvoice
*/
public function setPaymentTerm(?PaymentTerm $paymentTerm): RecurringInvoice
{
$this->paymentTerm = $paymentTerm;
return $this;
}
/**
* @return string|null
*/
public function getCurrencyChangeRate(): ?string
{
return $this->currencyChangeRate;
}
/**
* @param string|null $currencyChangeRate
* @return RecurringInvoice
*/
public function setCurrencyChangeRate(?string $currencyChangeRate): RecurringInvoice
{
$this->currencyChangeRate = $currencyChangeRate;
return $this;
}
/**
* @return string|null
*/
public function getReference(): ?string
{
return $this->reference;
}
/**
* @param string|null $reference
* @return RecurringInvoice
*/
public function setReference(?string $reference): RecurringInvoice
{
$this->reference = $reference;
return $this;
}
/**
* @return string|null
*/
public function getInternalName(): ?string
{
return $this->internalName;
}
/**
* @param string|null $internalName
* @return RecurringInvoice
*/
public function setInternalName(?string $internalName): RecurringInvoice
{
$this->internalName = $internalName;
return $this;
}
/**
* @return string|null
*/
public function getExternalName(): ?string
{
return $this->externalName;
}
/**
* @param string|null $externalName
* @return RecurringInvoice
*/
public function setExternalName(?string $externalName): RecurringInvoice
{
$this->externalName = $externalName;
return $this;
}
/**
* @return bool
*/
public function isReducedVat(): bool
{
return $this->reducedVat;
}
/**
* @param bool $reducedVat
* @return RecurringInvoice
*/
public function setReducedVat(bool $reducedVat): RecurringInvoice
{
$this->reducedVat = $reducedVat;
return $this;
}
/**
* @return string|null
*/
public function getTotalDiscountUntaxed(): ?string
{
return $this->totalDiscountUntaxed;
}
/**
* @param string|null $totalDiscountUntaxed
* @return RecurringInvoice
*/
public function setTotalDiscountUntaxed(?string $totalDiscountUntaxed): RecurringInvoice
{
$this->totalDiscountUntaxed = $totalDiscountUntaxed;
return $this;
}
/**
* @return string|null
*/
public function getTotalDiscount(): ?string
{
return $this->totalDiscount;
}
/**
* @param string|null $totalDiscount
* @return RecurringInvoice
*/
public function setTotalDiscount(?string $totalDiscount): RecurringInvoice
{
$this->totalDiscount = $totalDiscount;
return $this;
}
/**
* @return string|null
*/
public function getTotalAmountNoDiscountUntaxed(): ?string
{
return $this->totalAmountNoDiscountUntaxed;
}
/**
* @param string|null $totalAmountNoDiscountUntaxed
* @return RecurringInvoice
*/
public function setTotalAmountNoDiscountUntaxed(?string $totalAmountNoDiscountUntaxed): RecurringInvoice
{
$this->totalAmountNoDiscountUntaxed = $totalAmountNoDiscountUntaxed;
return $this;
}
/**
* @return string|null
*/
public function getTotalAmountNoDiscount(): ?string
{
return $this->totalAmountNoDiscount;
}
/**
* @param string|null $totalAmountNoDiscount
* @return RecurringInvoice
*/
public function setTotalAmountNoDiscount(?string $totalAmountNoDiscount): RecurringInvoice
{
$this->totalAmountNoDiscount = $totalAmountNoDiscount;
return $this;
}
/**
* @return string|null
*/
public function getTotalAmountUntaxed(): ?string
{
return $this->totalAmountUntaxed;
}
/**
* @param string|null $totalAmountUntaxed
* @return RecurringInvoice
*/
public function setTotalAmountUntaxed(?string $totalAmountUntaxed): RecurringInvoice
{
$this->totalAmountUntaxed = $totalAmountUntaxed;
return $this;
}
/**
* @return string|null
*/
public function getTotalTaxAmount(): ?string
{
return $this->totalTaxAmount;
}
/**
* @param string|null $totalTaxAmount
* @return RecurringInvoice
*/
public function setTotalTaxAmount(?string $totalTaxAmount): RecurringInvoice
{
$this->totalTaxAmount = $totalTaxAmount;
return $this;
}
/**
* @return string|null
*/
public function getTotalAmount(): ?string
{
return $this->totalAmount;
}
/**
* @param string|null $totalAmount
* @return RecurringInvoice
*/
public function setTotalAmount(?string $totalAmount): RecurringInvoice
{
$this->totalAmount = $totalAmount;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getLastInvoiceGeneration(): ?DateTimeInterface
{
return $this->lastInvoiceGeneration;
}
/**
* @param DateTimeInterface|null $lastInvoiceGeneration
* @return RecurringInvoice
*/
public function setLastInvoiceGeneration(?DateTimeInterface $lastInvoiceGeneration): RecurringInvoice
{
$this->lastInvoiceGeneration = $lastInvoiceGeneration;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getNextInvoiceGeneration(): ?DateTimeInterface
{
return $this->nextInvoiceGeneration;
}
/**
* @param mixed $nextInvoiceGeneration
* @return RecurringInvoice
*/
public function setNextInvoiceGeneration($nextInvoiceGeneration): RecurringInvoice
{
if ($nextInvoiceGeneration instanceof DateTimeInterface) {
$this->nextInvoiceGeneration = $nextInvoiceGeneration;
$this->finished = false;
} elseif ($nextInvoiceGeneration) {
$this->nextInvoiceGeneration = new DateTime($nextInvoiceGeneration);
$this->finished = false;
} else {
$this->nextInvoiceGeneration = null;
}
return $this;
}
/**
* @return int|null
*/
public function getDailyRecurrence(): ?int
{
return $this->dailyRecurrence;
}
/**
* @param int|null $dailyRecurrence
* @return RecurringInvoice
*/
public function setDailyRecurrence(?int $dailyRecurrence): RecurringInvoice
{
$this->dailyRecurrence = $dailyRecurrence;
return $this;
}
/**
* @return int|null
*/
public function getMonthlyRecurrence(): ?int
{
return $this->monthlyRecurrence;
}
/**
* @param int|null $monthlyRecurrence
* @return RecurringInvoice
*/
public function setMonthlyRecurrence(?int $monthlyRecurrence): RecurringInvoice
{
$this->monthlyRecurrence = $monthlyRecurrence;
return $this;
}
/**
* @return int|null
*/
public function getAnnualRecurrence(): ?int
{
return $this->annualRecurrence;
}
/**
* @param int|null $annualRecurrence
* @return RecurringInvoice
*/
public function setAnnualRecurrence(?int $annualRecurrence): RecurringInvoice
{
$this->annualRecurrence = $annualRecurrence;
return $this;
}
/**
* @return int|null
*/
public function getMaxInvoices(): ?int
{
return $this->maxInvoices;
}
/**
* @param int|null $maxInvoices
* @return RecurringInvoice
*/
public function setMaxInvoices(?int $maxInvoices): RecurringInvoice
{
$this->maxInvoices = (int) $maxInvoices;
return $this;
}
/**
* @return bool
*/
public function isAutoValidation(): bool
{
return $this->autoValidation;
}
/**
* @param bool $autoValidation
* @return RecurringInvoice
*/
public function setAutoValidation(bool $autoValidation): RecurringInvoice
{
$this->autoValidation = $autoValidation;
return $this;
}
/**
* @return bool
*/
public function isFinished(): bool
{
return $this->finished;
}
/**
* @param bool $finished
* @return RecurringInvoice
*/
public function setFinished(bool $finished): RecurringInvoice
{
$this->finished = $finished;
if ($finished) {
$this->setIsActive(false);
$this->setNextInvoiceGeneration(null);
}
return $this;
}
/**
* @return array
*/
public function getOptions(): array
{
return $this->options;
}
/**
* @param array $options
* @return RecurringInvoice
*/
public function setOptions(array $options): self
{
$this->options = $options;
return $this;
}
/**
* @param array $options
* @return RecurringInvoice
*/
public function addOptions(array $options): self
{
return $this->setOptions(array_merge($this->options, $options));
}
/**
* @return Collection|RecurringInvoiceLine[]
*/
public function getLines(): Collection
{
return $this->getFilterLines();
}
/**
* @param RecurringInvoiceLine $line
* @return $this
*/
public function addLine(RecurringInvoiceLine $line): self
{
if (!$this->lines->contains($line)) {
$this->lines[] = $line;
if ($line->getRecurringInvoice() !== $this) {
$line->setRecurringInvoice($this);
}
}
return $this;
}
/**
* @param RecurringInvoiceLine $line
* @return $this
*/
public function removeLine(RecurringInvoiceLine $line): self
{
$this->lines->removeElement($line);
return $this;
}
/**
* @param bool $withGroups
* @param bool $all
* @param bool $withPacks
* @return Collection|RecurringInvoiceLine[]
*/
public function getFilterLines(bool $withGroups = true, bool $all = false, bool $withPacks = true): Collection
{
if ($all) {
$lines = $this->lines;
$goodLines = [];
foreach ($lines as $line) {
if (!$line->getParent() && !$line->getPackParent()) {
$goodLines[] = $line;
foreach ($line->getChildrens() as $child) {
$goodLines[] = $child;
foreach ($child->getPackChildrens() as $grandChild) {
$goodLines[] = $grandChild;
}
}
foreach ($line->getPackChildrens() as $child) {
$goodLines[] = $child;
}
}
}
return new ArrayCollection($goodLines);
}
$criteria = Criteria::create();
if ($withGroups) {
$criteria
->where(Criteria::expr()->eq('parent', null))
->andWhere(Criteria::expr()->eq('packParent', null));
} else {
if ($withPacks) {
$criteria->andWhere(Criteria::expr()->eq('is_pack', true));
} else {
$criteria->andWhere(Criteria::expr()->eq('is_pack', false));
}
$criteria->where(Criteria::expr()->eq('is_group', false));
}
return $this->lines->matching($criteria);
}
/**
* @return Collection|Invoice[]
*/
public function getInvoices(bool $onlyValidated = false): Collection
{
if ($onlyValidated) {
return $this->invoices->filter(function (Invoice $invoice) {
return $invoice->isValidated();
});
} else {
return $this->invoices;
}
}
/**
* @param Invoice $invoice
* @return $this
*/
public function addInvoice(Invoice $invoice): self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices[] = $invoice;
}
return $this;
}
/**
* @return string
*/
public function getChoiceLabel(): string
{
return $this->reference . ($this->internalName ? ' - ' . $this->internalName : null);
}
/**
* @return RecurringInvoice
*/
public function duplicate(): RecurringInvoice
{
if ($this->id) {
$clone = clone $this;
$clone->setId();
$clone->setIsActive(false);
$clone->setFinished(false);
$clone->setCreatedAt(new DateTime());
$clone->setCreatedBy(null);
$clone->setUpdatedAt(new DateTime());
$clone->setUpdatedBy(null);
$clone->setCanceledAt(null);
$clone->setCanceledBy(null);
$clone->setContext(null);
$clone->setReference(null);
$clone->setLastInvoiceGeneration(null);
$clone->setNextInvoiceGeneration(null);
$clone->addOptions([
'invoice_address' => null,
'delivery_address' => null
]);
if (!$this->paymentTerm) {
$clone->setPaymentTerm(null);
}
$clone->invoices = new ArrayCollection();
$clone->lines = new ArrayCollection();
foreach ($this->getFilterLines() as $line) {
$cloneLine = $line->duplicate($clone);
$clone->addLine($cloneLine);
}
return $clone;
}
return $this;
}
/**
* @return Establishment|null
*/
public function getEstablishment(): ?Establishment
{
return $this->establishment;
}
/**
* @param Establishment|null $establishment
* @return $this
*/
public function setEstablishment(?Establishment $establishment): self
{
$this->establishment = $establishment;
return $this;
}
/**
* @return self|null
*/
public function getRecurringInvoiceMerged(): ?self
{
return $this->recurringInvoiceMerged;
}
/**
* @param RecurringInvoice|null $recurringInvoiceMerged
* @return $this
*/
public function setRecurringInvoiceMerged(?self $recurringInvoiceMerged): self
{
$this->recurringInvoiceMerged = $recurringInvoiceMerged;
return $this;
}
}