src/Entity/Invoice.php line 33
<?php/** @author Guerby Duval <info@tranzaksyon.com>* @link https://tranzaksyon.com* @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.*/namespace App\Entity;use App\Enums\InvoiceTypeEnum;use App\Enums\InvoiceTypes;use App\Interfaces\OwnerCompanyInterface;use App\Interfaces\SriInvoiceInterface;use App\Interfaces\SriInvoiceMathInterface;use App\Repository\InvoiceRepository;use App\Utils\Sri\SriData;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints\Count;use Symfony\Component\Validator\Constraints\IsFalse;use Symfony\Component\Validator\Constraints\NotBlank;use Symfony\Component\Validator\Constraints\Valid;use Symfony\Component\Validator\Constraints\When;#[ORM\Entity(repositoryClass: InvoiceRepository::class)]#[ORM\Table]#[ORM\UniqueConstraint(fields: ['externalId', 'sriInfo'])]#[UniqueEntity(['sriInfo', 'externalId'])]class Invoice extends InvoiceSuperClass implements SriInvoiceInterface, SriInvoiceMathInterface, OwnerCompanyInterface{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['invoice_out', 'associated_document_invoice_out'])]private ?int $id = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]#[NotBlank]#[Groups(['invoice_out', 'invoice_in'])]private ?\DateTimeInterface $emitDate = null;#[ORM\ManyToOne(inversedBy: 'invoices')]#[ORM\JoinColumn(nullable: false)]private ?SriInfo $sriInfo = null;#[ORM\Column(type: Types::DECIMAL, precision: 23, scale: 8)]#[Groups(['invoice_out'])]private ?string $total = null;#[ORM\Column(type: Types::DECIMAL, precision: 23, scale: 8)]#[Groups(['invoice_out'])]private float $totalWithoutTax = 0;#[ORM\Column(type: Types::DECIMAL, precision: 20, scale: 6)]#[Groups(['invoice_out'])]private float $totalDiscount = 0;#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]private float $propina = 0;#[ORM\Column(type: Types::DECIMAL, precision: 23, scale: 3, nullable: true)]#[Groups(['invoice_out', 'invoice_in'])]#[When("this.getFormOfPayment()", [new NotBlank()])]private ?string $paidAmount = null;#[ORM\Column(length: 50, nullable: true)]#[Groups(['invoice_out', 'invoice_in'])]private ?string $formOfPayment = null;#[ORM\ManyToOne(inversedBy: 'invoices')]#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]private ?User $user = null;#[ORM\OneToMany(mappedBy: 'Invoice', targetEntity: InvoiceDetail::class, cascade: ['persist'], orphanRemoval: true)]#[Valid(traverse: true)]#[Count(min: 1)]#[Groups(['invoice_out', 'invoice_in', 'invoice_detail_in'])]private Collection $invoiceDetails;#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: InvoiceTaxes::class, cascade: ['persist'], orphanRemoval: true)]private Collection $invoiceTaxes;#[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'invoices')]#[ORM\JoinColumn(nullable: true)]#[Valid(traverse: true)]#[Groups(['invoice_out', 'invoice_in'])]private ?Client $client = null;#[ORM\OneToOne(mappedBy: 'invoice', cascade: ['persist', 'remove'])]#[Groups(['invoice_out'])]#[Valid(groups: ['invoice-received'])]private ?SriDocument $sriDocument = null;#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: AditionalField::class, cascade: ['persist', 'remove'], orphanRemoval: true)]#[Groups(['invoice_out', 'invoice_in'])]private Collection $aditionalFields;#[ORM\ManyToOne(inversedBy: 'invoices')]#[Groups(['invoice_out', 'invoice_in'])]private ?Sucursal $sucursal = null;#[ORM\Column(length: 255, nullable: true)]private ?string $externalId = null;#[Groups(['invoice_in'])]private bool $send = false;#[ORM\Column(nullable: true)]#[Groups(['invoice_out', 'invoice_in'])]/*** use for Proforma*/private ?bool $isNote = null;#[ORM\Column(nullable: true)]private ?bool $isXmlGenerated = null;#[ORM\Column(nullable: true)]#[Groups(['invoice_out'])]private ?bool $isReceived = null;#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: SriPayment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]#[Valid(traverse: true)]#[Groups(['invoice_out', 'invoice_in'])]private Collection $sriPayments;#[ORM\Column(type: Types::DECIMAL, precision: 23, scale: 8, nullable: true)]private ?string $totalIva = null;#[ORM\Column(nullable: true)]#[Groups(['invoice_out', 'invoice_in'])]// Nota de ventaprivate ?bool $isSellNote = null;#[ORM\Column(length: 50, nullable: true)]private ?InvoiceTypeEnum $invoiceTypeEnum = null;#[ORM\Column(type: Types::DECIMAL, precision: 23, scale: 8, nullable: true)]private ?string $totalGravada = null;#[ORM\Column(nullable: true)]#[NotBlank]#[Groups(['invoice_out', 'invoice_in'])]private ?int $condicion = null;#[ORM\OneToOne(inversedBy: 'invoice', cascade: ['persist', 'remove'], orphanRemoval: true)]#[Valid(traverse: true)]#[Groups(['invoice_out', 'invoice_in'])]private ?PaymentCredit $paymentCredit = null;#[ORM\Column(nullable: true)]#[NotBlank]#[Groups(['invoice_out', 'invoice_in'])]private ?int $transactionType = null;#[ORM\OneToMany(mappedBy: 'invoice', targetEntity: AssociatedDocument::class)]private Collection $associatedDocuments;public function __construct(){parent::__construct();$this->invoiceDetails = new ArrayCollection();$this->invoiceTaxes = new ArrayCollection();$this->aditionalFields = new ArrayCollection();$this->sriPayments = new ArrayCollection();$this->associatedDocuments = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getEmitDate(): \DateTimeInterface{return $this->emitDate;}public function setEmitDate(?\DateTimeInterface $emitDate): self{$this->emitDate = $emitDate;return $this;}public function getSriInfo(): SriInfo{return $this->sriInfo;}public function setSriInfo(?SriInfo $sriInfo): self{$this->sriInfo = $sriInfo;return $this;}public function getTotal(): ?string{return $this->total;}public function setTotal(string $total): self{$this->total = $total;return $this;}public function getTotalWithoutTax(): float{return $this->totalWithoutTax;}public function setTotalWithoutTax(float $totalWithoutTax): self{$this->totalWithoutTax = $totalWithoutTax;return $this;}public function getTotalDiscount(): float{return $this->totalDiscount;}public function setTotalDiscount(float $totalDiscount): self{$this->totalDiscount = $totalDiscount;return $this;}public function getPropina(): float{return $this->propina;}public function setPropina(float $propina): self{$this->propina = $propina;return $this;}public function getPaidAmount(): ?string{return $this->paidAmount;}public function setPaidAmount(string $paidAmount): self{$this->paidAmount = $paidAmount;return $this;}public function getFormOfPayment(): ?string{return $this->formOfPayment;}public function setFormOfPayment(string $formOfPayment): self{$this->formOfPayment = $formOfPayment;return $this;}public function getUser(): ?User{return $this->user;}public function setUser(?User $user): self{$this->user = $user;return $this;}/*** @return Collection<int, InvoiceDetail>*/public function getInvoiceDetails(): Collection{return $this->invoiceDetails;}public function addInvoiceDetail(InvoiceDetail $invoiceDetail): self{if (!$this->invoiceDetails->contains($invoiceDetail)) {$this->invoiceDetails->add($invoiceDetail);$invoiceDetail->setInvoice($this);}return $this;}public function removeInvoiceDetail(InvoiceDetail $invoiceDetail): self{if ($this->invoiceDetails->removeElement($invoiceDetail)) {// set the owning side to null (unless already changed)if ($invoiceDetail->getInvoice() === $this) {$invoiceDetail->setInvoice(null);}}return $this;}/*** @return Collection<int, InvoiceTaxes>*/public function getInvoiceTaxes(): Collection{return $this->invoiceTaxes;}public function addInvoiceTax(InvoiceTaxes $invoiceTax): self{if (!$this->invoiceTaxes->contains($invoiceTax)) {$this->invoiceTaxes->add($invoiceTax);$invoiceTax->setInvoice($this);}return $this;}public function removeInvoiceTax(InvoiceTaxes $invoiceTax): self{if ($this->invoiceTaxes->removeElement($invoiceTax)) {// set the owning side to null (unless already changed)if ($invoiceTax->getInvoice() === $this) {$invoiceTax->setInvoice(null);}}return $this;}public function getClient(): ?Client{return $this->client;}public function setClient(?Client $client): self{$this->client = $client;return $this;}public function getSriDocument(): ?SriDocument{return $this->sriDocument;}public function setSriDocument(?SriDocument $sriDocument): self{// unset the owning side of the relation if necessaryif ($sriDocument === null && $this->sriDocument !== null) {$this->sriDocument->setInvoice(null);}// set the owning side of the relation if necessaryif ($sriDocument !== null && $sriDocument->getInvoice() !== $this) {$sriDocument->setInvoice($this);}$this->sriDocument = $sriDocument;return $this;}function getInvoiceType(): InvoiceTypes{return InvoiceTypes::factura;}/*** @return Collection<int, AditionalField>*/public function getAditionalFields(): Collection{return $this->aditionalFields;}public function addAditionalField(AditionalField $aditionalField): self{if (!$this->aditionalFields->contains($aditionalField)) {$this->aditionalFields->add($aditionalField);$aditionalField->setInvoice($this);}return $this;}public function removeAditionalField(AditionalField $aditionalField): self{if ($this->aditionalFields->removeElement($aditionalField)) {// set the owning side to null (unless already changed)if ($aditionalField->getInvoice() === $this) {$aditionalField->setInvoice(null);}}return $this;}public function getSucursal(): ?Sucursal{return $this->sucursal;}public function setSucursal(?Sucursal $sucursal): self{$this->sucursal = $sucursal;return $this;}public function getExternalId(): ?string{return $this->externalId;}public function setExternalId(?string $externalId): self{$this->externalId = $externalId;return $this;}public function setSend(bool $send): void{$this->send = $send;}public function isSend(): bool{return $this->send;}public function isIsNote(): ?bool{return $this->getInvoiceTypeEnum() === InvoiceTypeEnum::note ?? $this->isNote;}public function setIsNote(?bool $isNote): self{$this->isNote = $isNote;return $this;}public function isIsXmlGenerated(): ?bool{return $this->isXmlGenerated;}public function setIsXmlGenerated(?bool $isXmlGenerated): self{$this->isXmlGenerated = $isXmlGenerated;return $this;}#[Groups(['invoice_out'])]public function getCanSendToWhatsapp(): bool{return $this->sriInfo->getWhatsappConfiguration() and $this->sriInfo->getWhatsappConfiguration()->getApiKey() and $this->client?->getPhone();}public function isIsReceived(): ?bool{return $this->isReceived;}public function setIsReceived(?bool $isReceived): static{$this->isReceived = $isReceived;return $this;}/*** @return Collection<int, SriPayment>*/public function getSriPayments(): Collection{return $this->sriPayments;}public function addSriPayment(SriPayment $sriPayment): static{if (!$this->sriPayments->contains($sriPayment)) {$this->sriPayments->add($sriPayment);$sriPayment->setInvoice($this);}return $this;}public function removeSriPayment(SriPayment $sriPayment): static{if ($this->sriPayments->removeElement($sriPayment)) {// set the owning side to null (unless already changed)if ($sriPayment->getInvoice() === $this) {$sriPayment->setInvoice(null);}}return $this;}public function getTotalIva(): ?string{return $this->totalIva;}public function setTotalIva(?string $totalIva): static{$this->totalIva = $totalIva;return $this;}public function getTotalGravada(): ?string{return $this->totalGravada;}public function setTotalGravada(?string $totalGravada): static{$this->totalGravada = $totalGravada;return $this;}public function isIsSellNote(): ?bool{return $this->isSellNote;}public function setIsSellNote(?bool $isSellNote): static{$this->isSellNote = $isSellNote;return $this;}public function setInvoiceTypeEnum(?InvoiceTypeEnum $invoiceType): static{$this->invoiceTypeEnum = $invoiceType;return $this;}public function getInvoiceTypeEnum(): ?InvoiceTypeEnum{return $this->invoiceTypeEnum;}public function getCondicion(): ?int{return $this->condicion;}public function setCondicion(?int $condicion): static{$this->condicion = $condicion;return $this;}public function getPaymentCredit(): ?PaymentCredit{return $this->paymentCredit;}public function setPaymentCredit(?PaymentCredit $paymentCredit): static{$this->paymentCredit = $paymentCredit;$this->paymentCredit->setInvoice($this);return $this;}#[IsFalse(message: 'Falta llenar un pago.')]public function isPaymentInvalid(){return $this->getSriPayments()->isEmpty() && $this->getPaymentCredit() === null;}public function getCondicionDescripcion(){if (empty($this->condicion)) {return '';}return array_flip(SriData::condicionPagos())[$this->condicion];}public function getTransactionType(): ?int{return $this->transactionType;}public function setTransactionType(?int $transactionType): static{$this->transactionType = $transactionType;return $this;}/*** @return Collection<int, AssociatedDocument>*/public function getAssociatedDocuments(): Collection{return $this->associatedDocuments;}public function addAssociatedDocument(AssociatedDocument $associatedDocument): static{if (!$this->associatedDocuments->contains($associatedDocument)) {$this->associatedDocuments->add($associatedDocument);$associatedDocument->setInvoice($this);}return $this;}public function removeAssociatedDocument(AssociatedDocument $associatedDocument): static{if ($this->associatedDocuments->removeElement($associatedDocument)) {// set the owning side to null (unless already changed)if ($associatedDocument->getInvoice() === $this) {$associatedDocument->setInvoice(null);}}return $this;}}