src/Entity/CompanySubscription.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\CompanySubscriptionRepository")
  8.  */
  9. class CompanySubscription
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="subscriptions")
  19.      * @ORM\JoinColumn(nullable=false)
  20.      */
  21.     private $company;
  22.     /**
  23.      * @ORM\Column(type="float")
  24.      */
  25.     private $priceCharged=0;
  26.     /**
  27.      * @ORM\Column(type="boolean")
  28.      */
  29.     private $usedPromo=false;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $promoCode;
  34.     /**
  35.      * @ORM\Column(type="boolean", nullable=true)
  36.      */
  37.     private $frequency;
  38.     /**
  39.      * @ORM\Column(type="boolean")
  40.      */
  41.     private $active=false;
  42.     /**
  43.      * @ORM\Column(type="datetime")
  44.      */
  45.     private $date;
  46.     /**
  47.      * @ORM\Column(type="float")
  48.      */
  49.     private $priceChargedWithoutTaxes=0;
  50.     /**
  51.      * @ORM\Column(type="boolean")
  52.      */
  53.     private $isPaid=false;
  54.     /**
  55.      * @ORM\ManyToOne(targetEntity="App\Entity\CompanyPromoCode", inversedBy="subscriptions")
  56.      */
  57.     private $promoCodeUsed;
  58.     /**
  59.      * @ORM\Column(type="datetime", nullable=true)
  60.      */
  61.     private $datePaid;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity="App\Entity\InvoiceService", mappedBy="companySubscription")
  64.      */
  65.     private $invoice;
  66.     public function __construct(){
  67.         $this->date = new \DateTime();
  68.         $this->invoice = new ArrayCollection();
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getCompany(): ?Company
  75.     {
  76.         return $this->company;
  77.     }
  78.     public function setCompany(?Company $company): self
  79.     {
  80.         $this->company $company;
  81.         return $this;
  82.     }
  83.     public function getPriceCharged(): ?float
  84.     {
  85.         return $this->priceCharged;
  86.     }
  87.     public function setPriceCharged(float $priceCharged): self
  88.     {
  89.         $this->priceCharged $priceCharged;
  90.         return $this;
  91.     }
  92.     public function getUsedPromo(): ?bool
  93.     {
  94.         return $this->usedPromo;
  95.     }
  96.     public function setUsedPromo(bool $usedPromo): self
  97.     {
  98.         $this->usedPromo $usedPromo;
  99.         return $this;
  100.     }
  101.     public function getPromoCode(): ?string
  102.     {
  103.         return $this->promoCode;
  104.     }
  105.     public function setPromoCode($promoCode): self
  106.     {
  107.         $this->promoCode $promoCode;
  108.         return $this;
  109.     }
  110.     public function getEstimatedPricing(){
  111.         switch($this->getStripePlan()){
  112.             case 'maturin-monthly':
  113.                 return '12';
  114.                 break;
  115.             case 'maturin-yearly':
  116.                 return '125';
  117.                 break;
  118.             case 'monthly-20':
  119.                 return '20';
  120.             case 'yearly-200':
  121.                 return '200';
  122.             case 'maturin-15':
  123.                 return '15';
  124.             case 'maturin-150':
  125.                 return '150';
  126.         }
  127.     }
  128.     public function getStripePlan(){
  129.         $date = new \DateTime('2022-08-10');
  130.         $now = new \DateTime();
  131.         
  132.         if($date $now ){
  133.             switch($this->getFrequency()){
  134.                 case '1':
  135.                     return 'maturin-150';
  136.                 default:
  137.                     return 'maturin-15';
  138.             }
  139.         }else{
  140.             switch($this->getFrequency()){
  141.                 case '1':
  142.                     return 'maturin-yearly';
  143.                 default:
  144.                     return 'maturin-monthly';
  145.             }
  146.         }
  147.     }
  148.     public function getFrequency(): ?bool
  149.     {
  150.         return $this->frequency;
  151.     }
  152.     public function getStringFrequency(): ?string
  153.     {
  154.         if($this->frequency == '1')
  155.             return 'Annual';
  156.         else
  157.             return 'Monthly';
  158.     }
  159.     public function isYearly(){
  160.         if($this->frequency == '1')
  161.             return true;
  162.         else
  163.             return false;
  164.     }
  165.     public function setFrequency(bool $frequency): self
  166.     {
  167.         if(is_string($frequency)){
  168.             if($frequency == 'annual')
  169.                 $this->frequency true;
  170.             else
  171.                 $this->frequency false;
  172.         }else
  173.             $this->frequency $frequency;
  174.         return $this;
  175.     }
  176.     public function getActive(): ?bool
  177.     {
  178.         return $this->active;
  179.     }
  180.     public function setActive(bool $active): self
  181.     {
  182.         $this->active $active;
  183.         return $this;
  184.     }
  185.     public function getDate(): ?\DateTimeInterface
  186.     {
  187.         return $this->date;
  188.     }
  189.     public function setDate(\DateTimeInterface $date): self
  190.     {
  191.         $this->date $date;
  192.         return $this;
  193.     }
  194.     public function __toString(){
  195.         $return '';
  196.         if($this->getActive())
  197.             $return 'Actif: ';
  198.         else
  199.             $return 'Non actif: ';
  200.         return $return.$this->getStringFrequency().' - '.$this->getPriceCharged().'$';
  201.     }
  202.     public function getPriceChargedWithoutTaxes(): ?float
  203.     {
  204.         return $this->priceChargedWithoutTaxes;
  205.     }
  206.     public function setPriceChargedWithoutTaxes(float $priceChargedWithoutTaxes): self
  207.     {
  208.         $this->priceChargedWithoutTaxes $priceChargedWithoutTaxes;
  209.         return $this;
  210.     }
  211.     public function getIsPaid(): ?bool
  212.     {
  213.         return $this->isPaid;
  214.     }
  215.     public function setIsPaid(bool $isPaid): self
  216.     {
  217.         $this->isPaid $isPaid;
  218.         return $this;
  219.     }
  220.     public function getPromoCodeUsed(): ?CompanyPromoCode
  221.     {
  222.         return $this->promoCodeUsed;
  223.     }
  224.     public function setPromoCodeUsed(?CompanyPromoCode $promoCodeUsed): self
  225.     {
  226.         $this->promoCodeUsed $promoCodeUsed;
  227.         return $this;
  228.     }
  229.     public function getDatePaid(): ?\DateTimeInterface
  230.     {
  231.         return $this->datePaid;
  232.     }
  233.     public function setDatePaid(?\DateTimeInterface $datePaid): self
  234.     {
  235.         $this->datePaid $datePaid;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return Collection|InvoiceService[]
  240.      */
  241.     public function getInvoice(): Collection
  242.     {
  243.         return $this->invoice;
  244.     }
  245.     public function addInvoice(InvoiceService $invoice): self
  246.     {
  247.         if (!$this->invoice->contains($invoice)) {
  248.             $this->invoice[] = $invoice;
  249.             $invoice->setCompanySubscription($this);
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeInvoice(InvoiceService $invoice): self
  254.     {
  255.         if ($this->invoice->contains($invoice)) {
  256.             $this->invoice->removeElement($invoice);
  257.             // set the owning side to null (unless already changed)
  258.             if ($invoice->getCompanySubscription() === $this) {
  259.                 $invoice->setCompanySubscription(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264. }