src/Billing/Entity/Payment.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Billing\Entity;
  3. use App\Repository\PaymentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassPaymentRepository::class)]
  9. class Payment
  10. {
  11.     const METHOD_CHECK 'CHECK';
  12.     const METHOD_TRANSFER 'TRANSFER';
  13.     const METHOD_CASH 'CASH';
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(typeTypes::DECIMALprecision10scale2)]
  19.     private ?string $amount null;
  20.     #[ORM\Column(length50)]
  21.     private ?string $method null;
  22.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  23.     private ?\DateTimeInterface $date null;
  24.     /**
  25.      * Reference of the payment (e.g. Check Number, Transaction ID)
  26.      */
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $reference null;
  29.     #[ORM\ManyToOne(inversedBy'payments')]
  30.     #[ORM\JoinColumn(nullabletrue)]
  31.     private ?Invoice $invoice null;
  32.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  33.     private ?array $customerSnapshot = [];
  34.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  35.     private ?bool $isAdvance false;
  36.     #[ORM\ManyToMany(targetEntityInstallment::class, inversedBy'payments')]
  37.     private Collection $installments;
  38.     public function __construct()
  39.     {
  40.         $this->installments = new ArrayCollection();
  41.         $this->date = new \DateTime();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getAmount(): ?string
  48.     {
  49.         return $this->amount;
  50.     }
  51.     public function setAmount(string $amount): static
  52.     {
  53.         $this->amount $amount;
  54.         return $this;
  55.     }
  56.     public function getMethod(): ?string
  57.     {
  58.         return $this->method;
  59.     }
  60.     public function setMethod(string $method): static
  61.     {
  62.         $this->method $method;
  63.         return $this;
  64.     }
  65.     public function getDate(): ?\DateTimeInterface
  66.     {
  67.         return $this->date;
  68.     }
  69.     public function setDate(\DateTimeInterface $date): static
  70.     {
  71.         $this->date $date;
  72.         return $this;
  73.     }
  74.     public function getReference(): ?string
  75.     {
  76.         return $this->reference;
  77.     }
  78.     public function setReference(?string $reference): static
  79.     {
  80.         $this->reference $reference;
  81.         return $this;
  82.     }
  83.     public function getInvoice(): ?Invoice
  84.     {
  85.         return $this->invoice;
  86.     }
  87.     public function setInvoice(?Invoice $invoice): static
  88.     {
  89.         $this->invoice $invoice;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return Collection<int, Installment>
  94.      */
  95.     public function getInstallments(): Collection
  96.     {
  97.         return $this->installments;
  98.     }
  99.     public function addInstallment(Installment $installment): static
  100.     {
  101.         if (!$this->installments->contains($installment)) {
  102.             $this->installments->add($installment);
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeInstallment(Installment $installment): static
  107.     {
  108.         $this->installments->removeElement($installment);
  109.         return $this;
  110.     }
  111.     public function getCustomerSnapshot(): array
  112.     {
  113.         return $this->customerSnapshot ?? [];
  114.     }
  115.     public function setCustomerSnapshot(?array $customerSnapshot): static
  116.     {
  117.         $this->customerSnapshot $customerSnapshot;
  118.         return $this;
  119.     }
  120.     public function setCustomer(\App\Billing\Model\BillablePartyInterface $customer): static
  121.     {
  122.         $type null;
  123.         if ($customer instanceof \App\Entity\User) {
  124.             $type 'User';
  125.         } elseif ($customer instanceof \App\Entity\Organization) {
  126.             $type 'Organization';
  127.         }
  128.         $this->customerSnapshot = [
  129.             'id' => method_exists($customer'getId') ? $customer->getId() : null,
  130.             'type' => $type,
  131.             'name' => $customer->getBillingName(),
  132.             'address' => $customer->getBillingAddress(),
  133.             'email' => $customer->getBillingEmail(),
  134.             'tax_id' => $customer->getTaxId(),
  135.         ];
  136.         return $this;
  137.     }
  138.     public function getCustomerName(): ?string
  139.     {
  140.         return $this->customerSnapshot['name'] ?? null;
  141.     }
  142.     public function isAdvance(): bool
  143.     {
  144.         return $this->isAdvance;
  145.     }
  146.     public function setIsAdvance(bool $isAdvance): static
  147.     {
  148.         $this->isAdvance $isAdvance;
  149.         return $this;
  150.     }
  151. }