<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\CompanySubscriptionRepository") */class CompanySubscription{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="subscriptions") * @ORM\JoinColumn(nullable=false) */ private $company; /** * @ORM\Column(type="float") */ private $priceCharged=0; /** * @ORM\Column(type="boolean") */ private $usedPromo=false; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $promoCode; /** * @ORM\Column(type="boolean", nullable=true) */ private $frequency; /** * @ORM\Column(type="boolean") */ private $active=false; /** * @ORM\Column(type="datetime") */ private $date; /** * @ORM\Column(type="float") */ private $priceChargedWithoutTaxes=0; /** * @ORM\Column(type="boolean") */ private $isPaid=false; /** * @ORM\ManyToOne(targetEntity="App\Entity\CompanyPromoCode", inversedBy="subscriptions") */ private $promoCodeUsed; /** * @ORM\Column(type="datetime", nullable=true) */ private $datePaid; /** * @ORM\OneToMany(targetEntity="App\Entity\InvoiceService", mappedBy="companySubscription") */ private $invoice; public function __construct(){ $this->date = new \DateTime(); $this->invoice = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getCompany(): ?Company { return $this->company; } public function setCompany(?Company $company): self { $this->company = $company; return $this; } public function getPriceCharged(): ?float { return $this->priceCharged; } public function setPriceCharged(float $priceCharged): self { $this->priceCharged = $priceCharged; return $this; } public function getUsedPromo(): ?bool { return $this->usedPromo; } public function setUsedPromo(bool $usedPromo): self { $this->usedPromo = $usedPromo; return $this; } public function getPromoCode(): ?string { return $this->promoCode; } public function setPromoCode($promoCode): self { $this->promoCode = $promoCode; return $this; } public function getEstimatedPricing(){ switch($this->getStripePlan()){ case 'maturin-monthly': return '12'; break; case 'maturin-yearly': return '125'; break; case 'monthly-20': return '20'; case 'yearly-200': return '200'; case 'maturin-15': return '15'; case 'maturin-150': return '150'; } } public function getStripePlan(){ $date = new \DateTime('2022-08-10'); $now = new \DateTime(); if($date < $now ){ switch($this->getFrequency()){ case '1': return 'maturin-150'; default: return 'maturin-15'; } }else{ switch($this->getFrequency()){ case '1': return 'maturin-yearly'; default: return 'maturin-monthly'; } } } public function getFrequency(): ?bool { return $this->frequency; } public function getStringFrequency(): ?string { if($this->frequency == '1') return 'Annual'; else return 'Monthly'; } public function isYearly(){ if($this->frequency == '1') return true; else return false; } public function setFrequency(bool $frequency): self { if(is_string($frequency)){ if($frequency == 'annual') $this->frequency = true; else $this->frequency = false; }else $this->frequency = $frequency; return $this; } public function getActive(): ?bool { return $this->active; } public function setActive(bool $active): self { $this->active = $active; return $this; } public function getDate(): ?\DateTimeInterface { return $this->date; } public function setDate(\DateTimeInterface $date): self { $this->date = $date; return $this; } public function __toString(){ $return = ''; if($this->getActive()) $return = 'Actif: '; else $return = 'Non actif: '; return $return.$this->getStringFrequency().' - '.$this->getPriceCharged().'$'; } public function getPriceChargedWithoutTaxes(): ?float { return $this->priceChargedWithoutTaxes; } public function setPriceChargedWithoutTaxes(float $priceChargedWithoutTaxes): self { $this->priceChargedWithoutTaxes = $priceChargedWithoutTaxes; return $this; } public function getIsPaid(): ?bool { return $this->isPaid; } public function setIsPaid(bool $isPaid): self { $this->isPaid = $isPaid; return $this; } public function getPromoCodeUsed(): ?CompanyPromoCode { return $this->promoCodeUsed; } public function setPromoCodeUsed(?CompanyPromoCode $promoCodeUsed): self { $this->promoCodeUsed = $promoCodeUsed; return $this; } public function getDatePaid(): ?\DateTimeInterface { return $this->datePaid; } public function setDatePaid(?\DateTimeInterface $datePaid): self { $this->datePaid = $datePaid; return $this; } /** * @return Collection|InvoiceService[] */ public function getInvoice(): Collection { return $this->invoice; } public function addInvoice(InvoiceService $invoice): self { if (!$this->invoice->contains($invoice)) { $this->invoice[] = $invoice; $invoice->setCompanySubscription($this); } return $this; } public function removeInvoice(InvoiceService $invoice): self { if ($this->invoice->contains($invoice)) { $this->invoice->removeElement($invoice); // set the owning side to null (unless already changed) if ($invoice->getCompanySubscription() === $this) { $invoice->setCompanySubscription(null); } } return $this; }}