src/Entity/Company.php line 20

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. use Symfony\Component\Serializer\Annotation\Groups;
  7. use SpecShaper\EncryptBundle\Annotations\Encrypted;
  8. use Doctrine\Common\Collections\Criteria;
  9. use App\Entity\CompanyLocation;
  10. use App\Entity\CompanyVariable;
  11. /**
  12.  * @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Company
  16. {
  17.     /*
  18.      * @Groups({"searchable"})
  19.      */
  20.     private $urlName;
  21.     /**
  22.      * @ORM\Id()
  23.      * @ORM\GeneratedValue()
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=170, unique=true)
  29.      * @Groups({"searchable"})
  30.      */
  31.     private $name;
  32.     /**
  33.      * @ORM\OneToOne(targetEntity="App\Entity\Image")
  34.      */
  35.     private $image;
  36.     /**
  37.      * @ORM\OnetoOne(targetEntity="App\Entity\Image")
  38.      */
  39.     private $banner;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $website;
  44.     /**
  45.      * @ORM\Column(type="text", nullable=true)
  46.      * @Groups({"searchable"})
  47.      */
  48.     private $description;
  49.     /**
  50.      * @ORM\Column(type="text", nullable=true)
  51.      * @Groups({"searchable"})
  52.      */
  53.     private $speciality;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private $averageDeliveryTime=0;
  58.     /**
  59.      * @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="adminOfCompanies")
  60.      */
  61.     private $usersAdmin;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="company", cascade={"remove"})
  64.      */
  65.     private $products;
  66.     /**
  67.      * @ORM\OneToOne(targetEntity="App\Entity\CompanyLocation", cascade={"persist", "remove"})
  68.      * @Groups({"searchable"})
  69.      */
  70.     private $mainLocation;
  71.     /**
  72.      * @ORM\OneToMany(targetEntity="App\Entity\CompanyLocation", mappedBy="company", cascade={"persist", "remove"})
  73.      */
  74.     private $otherLocations;
  75.     /**
  76.      * @ORM\Column(type="string", length=20, nullable=true)
  77.      */
  78.     private $taxeTPS;
  79.     /**
  80.      * @ORM\Column(type="string", length=20, nullable=true)
  81.      */
  82.     private $taxeTVX;
  83.     /**
  84.      * @ORM\Column(type="string", length=15, nullable=true)
  85.      */
  86.     private $companyNumber;
  87.     /**
  88.      * @ORM\Column(type="integer", nullable=true)
  89.      */
  90.     private $numberOfSales=0;
  91.     /**
  92.      * @ORM\Column(type="float", nullable=true)
  93.      */
  94.     private $totalSalesInDollars=0;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity="App\Entity\CompanyPayment", mappedBy="company", orphanRemoval=true, cascade={"persist"})
  97.      */
  98.     private $payments;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity="App\Entity\CompanySubscription", mappedBy="company", orphanRemoval=true)
  101.      */
  102.     private $subscriptions;
  103.     /**
  104.      * @ORM\OneToOne(targetEntity="App\Entity\CompanyDeposit", mappedBy="company", cascade={"persist", "remove"})
  105.      */
  106.     private $depositInfo;
  107.     /**
  108.      * @ORM\Column(type="datetime")
  109.      */
  110.     private $dateCreated;
  111.     /**
  112.      * @ORM\OneToOne(targetEntity="App\Entity\CompanyDefaultShipping", mappedBy="company", cascade={"persist", "remove"})
  113.      */
  114.     private $defaultShipping;
  115.     /**
  116.      * @ORM\Column(type="boolean")
  117.      */
  118.     private $customSaleConditions=false;
  119.     /**
  120.      * @ORM\Column(type="text", nullable=true)
  121.      */
  122.     private $conditionsShipping;
  123.     /**
  124.      * @ORM\Column(type="text", nullable=true)
  125.      */
  126.     private $conditionsReturn;
  127.     /**
  128.      * @ORM\Column(type="text", nullable=true)
  129.      */
  130.     private $conditionsCancel;
  131.     /**
  132.      * @ORM\Column(type="datetime", nullable=true)
  133.      */
  134.     private $termsAcceptanceDate;
  135.     /**
  136.      * @ORM\Column(type="string", length=100, nullable=true)
  137.      */
  138.     private $termsAcceptanceIp;
  139.     /**
  140.      * @ORM\Column(type="integer", nullable=true)
  141.      */
  142.     private $solexId;
  143.     /**
  144.      * @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="companyPaying", cascade={"remove"})
  145.      */
  146.     private $transactionsPaid;
  147.     /**
  148.      * @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="companyReceiving", cascade={"remove"})
  149.      */
  150.     private $transactionsReceived;
  151.     /**
  152.      * @ORM\OneToMany(targetEntity="App\Entity\ProductReplenishment", mappedBy="company", orphanRemoval=true)
  153.      */
  154.     private $productReplenishments;
  155.     /**
  156.      * @ORM\Column(type="boolean")
  157.      */
  158.     private $storeMadeByMaturin=false;
  159.     /**
  160.      * @ORM\Column(type="array", nullable=true)
  161.      */
  162.     private $termsAcceptanceFingerPrint = [];
  163.     /**
  164.      * @ORM\Column(type="datetime", nullable=true)
  165.      */
  166.     private $inventoryLastUpdate;
  167.     /**
  168.      * @ORM\Column(type="boolean", nullable=true)
  169.      */
  170.     private $showPublicly=false;
  171.     /**
  172.      * @ORM\OneToMany(targetEntity="App\Entity\CustomOrder", mappedBy="company")
  173.      */
  174.     private $customOrders;
  175.     /**
  176.      * @ORM\OneToMany(targetEntity="App\Entity\MaturinOrder", mappedBy="company")
  177.      */
  178.     private $maturinOrders;
  179.     /**
  180.      * @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="company")
  181.      */
  182.     private $invoices;
  183.     /**
  184.      * @ORM\Column(type="string", length=255, nullable=true)
  185.      */
  186.     private $customUrl;
  187.     /**
  188.      * @ORM\OneToMany(targetEntity="App\Entity\Badge", mappedBy="company")
  189.      */
  190.     private $badges;
  191.     /**
  192.      * @ORM\OneToMany(targetEntity="App\Entity\InvoiceService", mappedBy="company")
  193.      */
  194.     private $invoiceServices;
  195.     /**
  196.      * @ORM\ManyToMany(targetEntity="App\Entity\CompanyAssociation", mappedBy="companies")
  197.      */
  198.     private $associations;
  199.     /**
  200.      * @ORM\Column(type="boolean")
  201.      */
  202.     private $isAllowedToScheduleColdProduct=false;
  203.     /**
  204.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="companiesRecruited")
  205.      */
  206.     private $recruiter;
  207.     /**
  208.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="myGroupOfCompanies")
  209.      */
  210.     private $inGroupOfUser;
  211.     /**
  212.      * @ORM\ManyToMany(targetEntity="App\Entity\Variable", inversedBy="companies")
  213.      */
  214.     private $variables;
  215.     /**
  216.      * @ORM\Column(type="boolean")
  217.      */
  218.     private $reminderStripeVerificationSent false;
  219.     /**
  220.      * @ORM\Column(type="boolean")
  221.      */
  222.     private $exportColabor false;
  223.     public function __construct()
  224.     {
  225.         $this->usersAdmin= new ArrayCollection();
  226.         $this->products = new ArrayCollection();
  227.         $this->otherLocations = new ArrayCollection();
  228.         $this->payments = new ArrayCollection();
  229.         $this->subscriptions = new ArrayCollection();
  230.         $this->dateCreated = new \DateTime();
  231.         $this->transactionsPaid = new ArrayCollection();
  232.         $this->transactionsReceived = new ArrayCollection();
  233.         $this->productReplenishments = new ArrayCollection();
  234.         $this->customOrders = new ArrayCollection();
  235.         $this->maturinOrders = new ArrayCollection();
  236.         $this->invoices = new ArrayCollection();
  237.         $this->badges = new ArrayCollection();
  238.         $this->invoiceServices = new ArrayCollection();
  239.         $this->associations = new ArrayCollection();
  240.         $this->variables = new ArrayCollection();
  241.     }
  242.     /**
  243.      * @ORM\PrePersist
  244.      */
  245.     public function doActionsOnPrePersist(){
  246.         /*
  247.             Executed at creation right before sending to DB
  248.         */
  249.         if($this->getAssociations()->count() > 0)
  250.             $this->doActionsToBeAPublicMarket();
  251.     }
  252.     /**
  253.      * @ORM\PreUpdate
  254.      */
  255.     public function doActionsOnPreUpdate(){
  256.         /*
  257.             Executed at creation right before sending to DB
  258.         */
  259.         if($this->getAssociations()->count() > 0)
  260.             $this->doActionsToBeAPublicMarket();
  261.         else
  262.             $this->doActionsToBeRemovedFromAPublicMarket();
  263.     }
  264.     /*
  265.         Do what's needed to be a public market
  266.     */
  267.     public function doActionsToBeAPublicMarket(){
  268.     }
  269.     /*
  270.         Do what's needed to be a out of a public market
  271.     */
  272.     public function doActionsToBeRemovedFromAPublicMarket(){
  273.     }
  274.     public function setSpeciality($speciality)
  275.     {
  276.         $this->speciality $speciality;
  277.     }
  278.     public function getSpeciality()
  279.     {
  280.         return $this->speciality;
  281.     }
  282.     public function setBanner($banner)
  283.     {
  284.         if(!empty($banner) || $banner == 'reset'){
  285.             if($banner == 'reset'){
  286.                 $banner null;
  287.         }
  288.             $this->banner $banner;
  289.         }
  290.     }
  291.     public function getBanner()
  292.     {
  293.         return $this->banner;
  294.     }
  295.     public function getId()
  296.     {
  297.         return $this->id;
  298.     }
  299.     public function getName(): ?string
  300.     {
  301.         return $this->name;
  302.     }
  303.     public function setName(string $name): self
  304.     {
  305.         $this->name $name;
  306.         return $this;
  307.     }
  308.     /*
  309.      * For export of the mailing list mostly in Omelo
  310.      * Having issue with export of ManyToMany Entities
  311.      */
  312.     public function getFirstNameAdmin(): ?string
  313.     {
  314.         //In theory only those with no SUPER_ADMIN roles are true
  315.         foreach($this->getUsersAdmin() as $u){
  316.             if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
  317.                 return ucfirst(strtolower($u->getFirstName()));
  318.         }
  319.         return null;
  320.     }
  321.     /*
  322.      * For export of the mailing list mostly in Omelo
  323.      * Having issue with export of ManyToMany Entities
  324.      */
  325.     public function getLastNameAdmin(): ?string
  326.     {
  327.         //In theory only those with no SUPER_ADMIN roles are true
  328.         foreach($this->getUsersAdmin() as $u){
  329.             if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
  330.                 return ucfirst(strtolower($u->getLastName()));
  331.         }
  332.         return null;
  333.     }
  334.     /*
  335.      * For export of the mailing list mostly in Omelo
  336.      * Causing issue on export of ManyToMany Entities
  337.      */
  338.     public function getAdminEmail(): ?string
  339.     {
  340.         //In theory only those with no SUPER_ADMIN roles are true
  341.         foreach($this->getUsersAdmin() as $u){
  342.             if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
  343.                 return $u->getEmail();
  344.         }
  345.         return $this->getEmail();
  346.     }
  347.     public function getFullUrl(): string
  348.     {
  349.         return 'https://www.maturin.ca/'.$this->getCustomUrl();
  350.     }
  351.     /**
  352.      * @Groups({"searchable"})
  353.      */
  354.     public function getUrlName(): ?string
  355.     {
  356.         $unwanted_array = array(    'Š'=>'S''š'=>'s''Ž'=>'Z''ž'=>'z''À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  357.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O''Õ'=>'O''Ö'=>'O''Ø'=>'O''Ù'=>'U',
  358.             'Ú'=>'U''Û'=>'U''Ü'=>'U''Ý'=>'Y''Þ'=>'B''ß'=>'Ss''à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  359.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n''ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o',
  360.             'ö'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''û'=>'u''ý'=>'y''þ'=>'b''ÿ'=>'y'"'" => '' '.'=> '''!' => '''?' => ''"'" => "");
  361.         $str strtrtrim($this->name), $unwanted_array );
  362.         return urlencode(str_replace(' ''-'strtolower($str)));
  363.     }
  364.     public function getImage()
  365.     {
  366.         return $this->image;
  367.     }
  368.     public function setImage($image): self
  369.     {
  370.         if(!empty($image) || $image == 'reset'){
  371.             if($image== 'reset'){
  372.                 $imagenull;
  373.         }
  374.           $this->image $image;
  375.         }
  376.         return $this;
  377.     }
  378.     public function getWebsite(): ?string
  379.     {
  380.         return $this->website;
  381.     }
  382.     public function setWebsite($website): self
  383.     {
  384.         $this->website $website;
  385.         return $this;
  386.     }
  387.     public function getDescription(): ?string
  388.     {
  389.         return $this->description;
  390.     }
  391.     public function setDescription(string $description): self
  392.     {
  393.         $this->description $description;
  394.         return $this;
  395.     }
  396.     public function getAverageDeliveryTime(): ?string
  397.     {
  398.         return $this->averageDeliveryTime;
  399.     }
  400.     public function setAverageDeliveryTime(string $averageDeliveryTime): self
  401.     {
  402.         $this->averageDeliveryTime $averageDeliveryTime;
  403.         return $this;
  404.     }
  405.     /**
  406.      * @return Collection|User[]
  407.      */
  408.     public function getUsersAdmin(): Collection
  409.     {
  410.         return $this->usersAdmin;
  411.     }
  412.     public function addUsersAdmin(User $usersAdmin): self
  413.     {
  414.         if (!$this->usersAdmin->contains($usersAdmin)) {
  415.             $this->usersAdmin[] = $usersAdmin;
  416.         }
  417.         return $this;
  418.     }
  419.     public function getAdminUsers(): Collection
  420.     {
  421.         return $this->usersAdmin;
  422.     }
  423.     public function addAdminUser(User $usersAdmin): self
  424.     {
  425.         if (!$this->usersAdmin->contains($usersAdmin)) {
  426.             $this->usersAdmin[] = $usersAdmin;
  427.         }
  428.         return $this;
  429.     }
  430.     public function removeAdminUser(User $usersAdmin): self
  431.     {
  432.         if ($this->usersAdmin->contains($usersAdmin)) {
  433.             $this->usersAdmin->removeElement($usersAdmin);
  434.         }
  435.         return $this;
  436.     }
  437.     public function removeAdminUsers(User $usersAdmin): self
  438.     {
  439.         if ($this->usersAdmin->contains($usersAdmin)) {
  440.             $this->usersAdmin->removeElement($usersAdmin);
  441.         }
  442.         return $this;
  443.     }
  444.     /**
  445.      * @return Collection|Product[]
  446.      */
  447.     public function getProducts(): Collection
  448.     {
  449.         /* Remove the draft */
  450.         $cleanProduct = new ArrayCollection();
  451.         foreach($this->products as $product){
  452.             if(!$product->getDraft())
  453.                 $cleanProduct[]=$product;
  454.         }
  455.         return $cleanProduct;
  456.     }
  457.     public function addProduct(Product $product): self
  458.     {
  459.         if (!$this->products->contains($product)) {
  460.             $this->products[] = $product;
  461.             $product->setCompany($this);
  462.         }
  463.         return $this;
  464.     }
  465.     public function removeProduct(Product $product): self
  466.     {
  467.         if ($this->products->contains($product)) {
  468.             $this->products->removeElement($product);
  469.             // set the owning side to null (unless already changed)
  470.             if ($product->getCompany() === $this) {
  471.                 $product->setCompany(null);
  472.             }
  473.         }
  474.         return $this;
  475.     }
  476.     public function flushProducts(){
  477.         $this->products = new ArrayCollection();
  478.     }
  479.     public function getMainLocation(): ?CompanyLocation
  480.     {
  481.         return $this->mainLocation;
  482.     }
  483.     public function setMainLocation(?CompanyLocation $mainLocation): self
  484.     {
  485.         $this->mainLocation $mainLocation;
  486.         return $this;
  487.     }
  488.     /**
  489.      * @return Collection|CompanyLocation[]
  490.      */
  491.     public function getOtherLocations(): Collection
  492.     {
  493.         return $this->otherLocations;
  494.     }
  495.     public function addOtherLocation(CompanyLocation $otherLocation): self
  496.     {
  497.         if (!$this->otherLocations->contains($otherLocation)) {
  498.             $this->otherLocations[] = $otherLocation;
  499.             $otherLocation->setCompany($this);
  500.         }
  501.         return $this;
  502.     }
  503.     public function removeOtherLocation(CompanyLocation $otherLocation): self
  504.     {
  505.         if ($this->otherLocations->contains($otherLocation)) {
  506.             $this->otherLocations->removeElement($otherLocation);
  507.             // set the owning side to null (unless already changed)
  508.             if ($otherLocation->getCompany() === $this) {
  509.                 $otherLocation->setCompany(null);
  510.             }
  511.         }
  512.         return $this;
  513.     }
  514.     public function getTaxeTPS(): ?string
  515.     {
  516.         return $this->taxeTPS;
  517.     }
  518.     public function setTaxeTPS(?string $taxeTPS): self
  519.     {
  520.         $this->taxeTPS $taxeTPS;
  521.         return $this;
  522.     }
  523.     public function getTaxeTVX(): ?string
  524.     {
  525.         return $this->taxeTVX;
  526.     }
  527.     public function setTaxeTVX(?string $taxeTVX): self
  528.     {
  529.         $this->taxeTVX $taxeTVX;
  530.         return $this;
  531.     }
  532.     public function getCompanyNumber(): ?string
  533.     {
  534.         return $this->companyNumber;
  535.     }
  536.     public function setCompanyNumber(?string $companyNumber): self
  537.     {
  538.         $this->companyNumber $companyNumber;
  539.         return $this;
  540.     }
  541.     public function getSaleId(): ?string
  542.     {
  543.         return $this->id 10000;
  544.     }
  545.     public function setSaleId(?string $saleId): self
  546.     {
  547.         return $this;
  548.     }
  549.     public function getNumberOfSales(): ?int
  550.     {
  551.         return $this->numberOfSales;
  552.     }
  553.     public function setNumberOfSales(?int $numberOfSales): self
  554.     {
  555.         $this->numberOfSales $numberOfSales;
  556.         return $this;
  557.     }
  558.     public function getTotalSalesInDollars(): ?float
  559.     {
  560.         return $this->totalSalesInDollars;
  561.     }
  562.     public function setTotalSalesInDollars(?float $totalSalesInDollars): self
  563.     {
  564.         $this->totalSalesInDollars $totalSalesInDollars;
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return Collection|CompanyPayment[]
  569.      */
  570.     public function getpayments(): Collection
  571.     {
  572.         return $this->payments;
  573.     }
  574.     /*
  575.      * Do more throughout validation
  576.      * @TODO
  577.      */
  578.     public function getCurrentPayment(){
  579.         if(count($this->payments) > 0)
  580.             return $this->getPayments()->last();
  581.         else
  582.             return false;
  583.     }
  584.     public function hasPayment(){
  585.         if(!empty($this->getCurrentPayment()))
  586.             return true;
  587.         else
  588.             return false;
  589.     }
  590.     /*
  591.      * Return is any products of this company is shipped by Maturin
  592.      */
  593.     public function hasProductsShippedByMaturin(): bool
  594.     {
  595.         foreach($this->getProducts() as $p){
  596.             if($p->isShippedByMaturin())
  597.                 return true;
  598.         }
  599.         return false;
  600.     }
  601.     /*
  602.      * Return if there is any inventory with our warehouses
  603.      */
  604.     public function hasInventoryWithMaturin(): bool
  605.     {
  606.         if(!empty($this->productReplenishments) && count($this->productReplenishments) > 0)
  607.             return true;
  608.         else
  609.             return false;
  610.     }
  611.     public function addPayment(CompanyPayment $companyPayment): self
  612.     {
  613.         if (!$this->payments->contains($companyPayment)) {
  614.             $this->payments[] = $companyPayment;
  615.             $companyPayment->setCompany($this);
  616.         }
  617.         return $this;
  618.     }
  619.     public function removePayment(CompanyPayment $companyPayment): self
  620.     {
  621.         if ($this->payments->contains($companyPayment)) {
  622.             $this->payments->removeElement($companyPayment);
  623.             // set the owning side to null (unless already changed)
  624.             if ($companyPayment->getCompany() === $this) {
  625.                 $companyPayment->setCompany(null);
  626.             }
  627.         }
  628.         return $this;
  629.     }
  630.     /*
  631.      * @TODO right now we lock it 1 subscription
  632.      * But in the long run the ManyToOne will be used
  633.      */
  634.     public function getCurrentSubscription(){
  635.         return $this->getSubscriptions()->first();
  636.     }
  637.     /**
  638.      * @return Collection|CompanySubscription[]
  639.      */
  640.     public function getSubscriptions(): Collection
  641.     {
  642.         return $this->subscriptions;
  643.     }
  644.     public function addSubscription(CompanySubscription $subscription): self
  645.     {
  646.         if (!$this->subscriptions->contains($subscription)) {
  647.             $this->subscriptions[] = $subscription;
  648.             $subscription->setCompany($this);
  649.         }
  650.         return $this;
  651.     }
  652.     public function removeSubscription(CompanySubscription $subscription): self
  653.     {
  654.         if ($this->subscriptions->contains($subscription)) {
  655.             $this->subscriptions->removeElement($subscription);
  656.             // set the owning side to null (unless already changed)
  657.             if ($subscription->getCompany() === $this) {
  658.                 $subscription->setCompany(null);
  659.             }
  660.         }
  661.         return $this;
  662.     }
  663.     /*
  664.      * @Todo At some point need to save all bank used
  665.      */
  666.     public function getCurrentDeposit(){
  667.         return $this->depositInfo;
  668.     }
  669.     public function getDeposit(): ?CompanyDeposit
  670.     {
  671.         return $this->depositInfo;
  672.     }
  673.     public function getDepositInfo(): ?CompanyDeposit
  674.     {
  675.         return $this->depositInfo;
  676.     }
  677.     public function setDeposit(CompanyDeposit $depositInfo): self
  678.     {
  679.         $this->depositInfo $depositInfo;
  680.         // set the owning side of the relation if necessary
  681.         if ($this !== $depositInfo->getCompany()) {
  682.             $depositInfo->setCompany($this);
  683.         }
  684.         return $this;
  685.     }
  686.     public function setDepositInfo(CompanyDeposit $depositInfo): self
  687.     {
  688.         $this->depositInfo $depositInfo;
  689.         // set the owning side of the relation if necessary
  690.         if ($this !== $depositInfo->getCompany()) {
  691.             $depositInfo->setCompany($this);
  692.         }
  693.         return $this;
  694.     }
  695.     public function setDateCreated($dateCreated)
  696.     {
  697.         $this->dateCreated $dateCreated;
  698.     }
  699.     public function getDateCreated()
  700.     {
  701.         return $this->dateCreated;
  702.     }
  703.     public function getDefaultShipping(): ?CompanyDefaultShipping
  704.     {
  705.         return $this->defaultShipping;
  706.     }
  707.     public function setDefaultShipping(?CompanyDefaultShipping $defaultShipping): self
  708.     {
  709.         $this->defaultShipping $defaultShipping;
  710.         // set (or unset) the owning side of the relation if necessary
  711.         $newCompany $defaultShipping === null null $this;
  712.         if ($newCompany !== $defaultShipping->getCompany()) {
  713.             $defaultShipping->setCompany($newCompany);
  714.         }
  715.         return $this;
  716.     }
  717.     public function getCustomSaleConditions(): ?bool
  718.     {
  719.         return $this->customSaleConditions;
  720.     }
  721.     public function setCustomSaleConditions(bool $condition): self
  722.     {
  723.         $this->customSaleConditions$condition;
  724.         return $this;
  725.     }
  726.     public function getConditionsShipping(): ?string
  727.     {
  728.         return $this->conditionsShipping;
  729.     }
  730.     public function setConditionsShipping(?string $conditionsShipping): self
  731.     {
  732.         $this->conditionsShipping $conditionsShipping;
  733.         return $this;
  734.     }
  735.     public function getConditionsReturn(): ?string
  736.     {
  737.         return $this->conditionsReturn;
  738.     }
  739.     public function setConditionsReturn(?string $conditionsReturn): self
  740.     {
  741.         $this->conditionsReturn $conditionsReturn;
  742.         return $this;
  743.     }
  744.     public function getConditionsCancel(): ?string
  745.     {
  746.         return $this->conditionsCancel;
  747.     }
  748.     public function setConditionsCancel(?string $conditionsCancel): self
  749.     {
  750.         $this->conditionsCancel $conditionsCancel;
  751.         return $this;
  752.     }
  753.     public function isSearchable(){
  754.         //For now they are all searchable
  755.         //Need the payment option for only displaying the valid one
  756.         //@TODO
  757.         if(!empty($this->getMainLocation()) && $this->getShowPublicly())
  758.             return true;
  759.         else
  760.             return false;
  761.     }
  762.     /**
  763.      * @Groups({"searchable"})
  764.      */
  765.     public function getSuggestions(){
  766.         return array_merge(array(
  767.             $this->getName()
  768.         ),
  769.             explode(' '$this->getName())
  770.         );
  771.     }
  772.     public function getTermsAcceptanceDate(): ?\DateTimeInterface
  773.     {
  774.         return $this->termsAcceptanceDate;
  775.     }
  776.     public function getTermsAcceptanceDateStamp()
  777.     {
  778.         if(!empty($this->termsAcceptanceDate))
  779.             return $this->termsAcceptanceDate->getTimestamp();
  780.         else
  781.             return null;
  782.     }
  783.     public function getTermsAcceptance(){
  784.         if(empty($this->getTermsAcceptanceIp()))
  785.             return false;
  786.         else
  787.             return true;
  788.     }
  789.     public function setTermsAcceptance($accept=false): self
  790.     {
  791.         if(!empty($accept) && $accept){
  792.             $this->termsAcceptanceDate = new \DateTime();
  793.             $this->termsAcceptanceIp $_SERVER['REMOTE_ADDR'];
  794.             $this->termsAcceptanceFingerPrint $_SERVER;
  795.         }
  796.         return $this;
  797.     }
  798.     public function setTermsAcceptanceDate(?\DateTimeInterface $termsAcceptanceDate): self
  799.     {
  800.         $this->termsAcceptanceDate $termsAcceptanceDate;
  801.         return $this;
  802.     }
  803.     public function getTermsAcceptanceIp(): ?string
  804.     {
  805.         return $this->termsAcceptanceIp;
  806.     }
  807.     public function setTermsAcceptanceIp(?string $termsAcceptanceIp): self
  808.     {
  809.         $this->termsAcceptanceIp $termsAcceptanceIp;
  810.         return $this;
  811.     }
  812.     public function getSolexId(): ?int
  813.     {
  814.         return $this->solexId;
  815.     }
  816.     public function setSolexId(?int $solexId): self
  817.     {
  818.         $this->solexId $solexId;
  819.         return $this;
  820.     }
  821.     /**
  822.      * @return Collection|FinancialLog[]
  823.      */
  824.     public function getTransactionsPaid(): Collection
  825.     {
  826.         return $this->transactionsPaid;
  827.     }
  828.     public function addTransactionsPaid(FinancialLog $transactionsPaid): self
  829.     {
  830.         if (!$this->transactionsPaid->contains($transactionsPaid)) {
  831.             $this->transactionsPaid[] = $transactionsPaid;
  832.             $transactionsPaid->setCompanyPaying($this);
  833.         }
  834.         return $this;
  835.     }
  836.     public function removeTransactionsPaid(FinancialLog $transactionsPaid): self
  837.     {
  838.         if ($this->transactionsPaid->contains($transactionsPaid)) {
  839.             $this->transactionsPaid->removeElement($transactionsPaid);
  840.             // set the owning side to null (unless already changed)
  841.             if ($transactionsPaid->getCompanyPaying() === $this) {
  842.                 $transactionsPaid->setCompanyPaying(null);
  843.             }
  844.         }
  845.         return $this;
  846.     }
  847.     /**
  848.      * @return Collection|FinancialLog[]
  849.      */
  850.     public function getTransactionsReceived(): Collection
  851.     {
  852.         return $this->transactionsReceived;
  853.     }
  854.     public function addTransactionsReceived(FinancialLog $transactionsReceived): self
  855.     {
  856.         if (!$this->transactionsReceived->contains($transactionsReceived)) {
  857.             $this->transactionsReceived[] = $transactionsReceived;
  858.             $transactionsReceived->setCompanyReceiving($this);
  859.         }
  860.         return $this;
  861.     }
  862.     public function removeTransactionsReceived(FinancialLog $transactionsReceived): self
  863.     {
  864.         if ($this->transactionsReceived->contains($transactionsReceived)) {
  865.             $this->transactionsReceived->removeElement($transactionsReceived);
  866.             // set the owning side to null (unless already changed)
  867.             if ($transactionsReceived->getCompanyReceiving() === $this) {
  868.                 $transactionsReceived->setCompanyReceiving(null);
  869.             }
  870.         }
  871.         return $this;
  872.     }
  873.     public function __toString(){
  874.         if($this->getId())
  875.             return $this->getId().' - '.$this->name;
  876.         else
  877.             return $this->name;
  878.     }
  879.     /*
  880.      * Check if there is a replishment for this date
  881.      */
  882.     public function hasReplenishmentOn($date){
  883.         foreach($this->getProductReplenishments() as $r){
  884.             if($r->getAppointmentDate() == $date)
  885.                 return $r;
  886.         }
  887.         return false;
  888.     }
  889.     /**
  890.      * @return Collection|ProductReplenishment[]
  891.      */
  892.     public function getProductReplenishments(): Collection
  893.     {
  894.         $criteria Criteria::create();
  895.         $criteria->where(Criteria::expr()->eq('isValid'true));
  896.         $replenishment $this->productReplenishments->matching($criteria);
  897.         return $replenishment;
  898.     }
  899.     public function addProductReplenishment(ProductReplenishment $productReplenishment): self
  900.     {
  901.         if (!$this->productReplenishments->contains($productReplenishment)) {
  902.             $this->productReplenishments[] = $productReplenishment;
  903.             $productReplenishment->setCompany($this);
  904.         }
  905.         return $this;
  906.     }
  907.     public function removeProductReplenishment(ProductReplenishment $productReplenishment): self
  908.     {
  909.         if ($this->productReplenishments->contains($productReplenishment)) {
  910.             $this->productReplenishments->removeElement($productReplenishment);
  911.             // set the owning side to null (unless already changed)
  912.             if ($productReplenishment->getCompany() === $this) {
  913.                 $productReplenishment->setCompany(null);
  914.             }
  915.         }
  916.         return $this;
  917.     }
  918.     public function getStoreMadeByMaturin(): ?bool
  919.     {
  920.         return $this->storeMadeByMaturin;
  921.     }
  922.     public function setStoreMadeByMaturin(bool $storeMadeByMaturin): self
  923.     {
  924.         $this->storeMadeByMaturin $storeMadeByMaturin;
  925.         return $this;
  926.     }
  927.     public function getExportColabor(): ?bool
  928.     {
  929.         return $this->exportColabor;
  930.     }
  931.     public function setExportColabor(bool $exportColabor): self
  932.     {
  933.         $this->exportColabor $exportColabor;
  934.         return $this;
  935.     }
  936.     public function getTermsAcceptanceFingerPrint(): ?array
  937.     {
  938.         return $this->termsAcceptanceFingerPrint;
  939.     }
  940.     public function setTermsAcceptanceFingerPrint(?array $termsAcceptanceFingerPrint): self
  941.     {
  942.         $this->termsAcceptanceFingerPrint $termsAcceptanceFingerPrint;
  943.         return $this;
  944.     }
  945.     public function getInventoryLastUpdate(): ?\DateTimeInterface
  946.     {
  947.         return $this->inventoryLastUpdate;
  948.     }
  949.     public function setInventoryLastUpdate(?\DateTimeInterface $inventoryLastUpdate): self
  950.     {
  951.         $this->inventoryLastUpdate $inventoryLastUpdate;
  952.         return $this;
  953.     }
  954.     public function getEmail(){
  955.         if(empty($this->getMainLocation()))
  956.             return false;
  957.         $email $this->getMainLocation()->getEmail();
  958.         if(empty($email))
  959.             return false;
  960.         else
  961.             return $email;
  962.     }
  963.     public function getShowPublicly(): ?bool
  964.     {
  965.         return $this->showPublicly;
  966.     }
  967.     public function setShowPublicly(?bool $showPublicly): self
  968.     {
  969.         $this->showPublicly $showPublicly;
  970.         return $this;
  971.     }
  972.     /**
  973.      * @return Collection|CustomOrder[]
  974.      */
  975.     public function getCustomOrders(): Collection
  976.     {
  977.         return $this->customOrders;
  978.     }
  979.     public function addCustomOrder(CustomOrder $customOrder): self
  980.     {
  981.         if (!$this->customOrders->contains($customOrder)) {
  982.             $this->customOrders[] = $customOrder;
  983.             $customOrder->setCompany($this);
  984.         }
  985.         return $this;
  986.     }
  987.     public function removeCustomOrder(CustomOrder $customOrder): self
  988.     {
  989.         if ($this->customOrders->contains($customOrder)) {
  990.             $this->customOrders->removeElement($customOrder);
  991.             // set the owning side to null (unless already changed)
  992.             if ($customOrder->getCompany() === $this) {
  993.                 $customOrder->setCompany(null);
  994.             }
  995.         }
  996.         return $this;
  997.     }
  998.     /**
  999.      * @return Collection|MaturinOrder[]
  1000.      */
  1001.     public function getMaturinOrders(): Collection
  1002.     {
  1003.         return $this->maturinOrders;
  1004.     }
  1005.     public function addMaturinOrder(MaturinOrder $maturinOrder): self
  1006.     {
  1007.         if (!$this->maturinOrders->contains($maturinOrder)) {
  1008.             $this->maturinOrders[] = $maturinOrder;
  1009.             $maturinOrder->setCompany($this);
  1010.         }
  1011.         return $this;
  1012.     }
  1013.     public function removeMaturinOrder(MaturinOrder $maturinOrder): self
  1014.     {
  1015.         if ($this->maturinOrders->contains($maturinOrder)) {
  1016.             $this->maturinOrders->removeElement($maturinOrder);
  1017.             // set the owning side to null (unless already changed)
  1018.             if ($maturinOrder->getCompany() === $this) {
  1019.                 $maturinOrder->setCompany(null);
  1020.             }
  1021.         }
  1022.         return $this;
  1023.     }
  1024.     /**
  1025.      * @return Collection|CartProduct[]
  1026.      */
  1027.     public function getPaidInvoices(): Collection
  1028.     {
  1029.         $criteria Criteria::create();
  1030.         $criteria->where(Criteria::expr()->eq('isPaid'true));
  1031.         $paidInvoices $this->invoices->matching($criteria);
  1032.         return $paidInvoices;
  1033.     }
  1034.     /**
  1035.      * @return Collection|CartProduct[]
  1036.      */
  1037.     public function getInvoices(): Collection
  1038.     {
  1039.         return $this->invoices;
  1040.     }
  1041.     public function addInvoice(Invoice $item): self
  1042.     {
  1043.         if (!$this->invoices->contains($item)) {
  1044.             $this->invoices[] = $item;
  1045.             $item->setCompany($this);
  1046.         }
  1047.         return $this;
  1048.     }
  1049.     public function removeInvoice(Invoice $item): self
  1050.     {
  1051.         if ($this->invoices->contains($item)) {
  1052.             $this->invoices->removeElement($item);
  1053.             // set the owning side to null (unless already changed)
  1054.             if ($item->getCompany() === $this) {
  1055.                 $item->setCompany(null);
  1056.             }
  1057.         }
  1058.         return $this;
  1059.     }
  1060.     public function getCustomUrl(): ?string
  1061.     {
  1062.         if(empty($this->customUrl))
  1063.             return 'producteur/'.$this->getUrlName().'/'.$this->getId();
  1064.         else
  1065.             return $this->customUrl;
  1066.     }
  1067.     public function setCustomUrl(?string $customUrl): self
  1068.     {
  1069.         $this->customUrl $customUrl;
  1070.         return $this;
  1071.     }
  1072.     public function getDaysSinceFirstSale()
  1073.     {
  1074.         //We start with the company start
  1075.         $day 0;
  1076.         $now = new \Datetime();
  1077.         //Put in a query at some point
  1078.         foreach($this->getMaturinOrders() as $m){
  1079.             $tmpDay $m->getDateCreated()->diff($now)->format("%a");
  1080.             if($tmpDay $day)
  1081.                 $day $tmpDay;
  1082.         }
  1083.         //Put in a query at some point
  1084.         foreach($this->getCustomOrders() as $m){
  1085.             $tmpDay $m->getDateCreated()->diff($now)->format("%a");
  1086.             if($tmpDay $day)
  1087.                 $day $tmpDay;
  1088.         }
  1089.         return $day;
  1090.     }
  1091.     /**
  1092.      * @return Collection|Badge[]
  1093.      */
  1094.     public function getBadges(): Collection
  1095.     {
  1096.         return $this->badges;
  1097.     }
  1098.     public function addBadge(Badge $badge): self
  1099.     {
  1100.         if (!$this->badges->contains($badge)) {
  1101.             $this->badges[] = $badge;
  1102.             $badge->setCompany($this);
  1103.         }
  1104.         return $this;
  1105.     }
  1106.     public function removeBadge(Badge $badge): self
  1107.     {
  1108.         if ($this->badges->contains($badge)) {
  1109.             $this->badges->removeElement($badge);
  1110.             // set the owning side to null (unless already changed)
  1111.             if ($badge->getCompany() === $this) {
  1112.                 $badge->setCompany(null);
  1113.             }
  1114.         }
  1115.         return $this;
  1116.     }
  1117.     /**
  1118.      * @return Collection|InvoiceService[]
  1119.      */
  1120.     public function getInvoiceServices(): Collection
  1121.     {
  1122.         return $this->invoiceServices;
  1123.     }
  1124.     public function addInvoiceService(InvoiceService $invoiceService): self
  1125.     {
  1126.         if (!$this->invoiceServices->contains($invoiceService)) {
  1127.             $this->invoiceServices[] = $invoiceService;
  1128.             $invoiceService->setCompany($this);
  1129.         }
  1130.         return $this;
  1131.     }
  1132.     public function removeInvoiceService(InvoiceService $invoiceService): self
  1133.     {
  1134.         if ($this->invoiceServices->contains($invoiceService)) {
  1135.             $this->invoiceServices->removeElement($invoiceService);
  1136.             // set the owning side to null (unless already changed)
  1137.             if ($invoiceService->getCompany() === $this) {
  1138.                 $invoiceService->setCompany(null);
  1139.             }
  1140.         }
  1141.         return $this;
  1142.     }
  1143.     /**
  1144.      * @return Collection|CompanyAssociation[]
  1145.      */
  1146.     public function getAssociations(): Collection
  1147.     {
  1148.         return $this->associations;
  1149.     }
  1150.     /**
  1151.      * @Groups({"searchable"})
  1152.      */
  1153.     public function getSearchAssociations(){
  1154.         $ids = [];
  1155.         foreach ($this->getAssociations() as $association){
  1156.             $ids[]=$association->getId();
  1157.         }
  1158.         return array_unique($ids);
  1159.     }
  1160.     public function addAssociation(CompanyAssociation $association): self
  1161.     {
  1162.         if (!$this->associations->contains($association)) {
  1163.             $this->associations[] = $association;
  1164.             $association->addCompany($this);
  1165.         }
  1166.         return $this;
  1167.     }
  1168.     public function removeAssociation(CompanyAssociation $association): self
  1169.     {
  1170.         if ($this->associations->contains($association)) {
  1171.             $this->associations->removeElement($association);
  1172.             $association->removeCompany($this);
  1173.         }
  1174.         return $this;
  1175.     }
  1176.     public function getIsAllowedToScheduleColdProduct(): ?bool
  1177.     {
  1178.         return $this->isAllowedToScheduleColdProduct;
  1179.     }
  1180.     public function setIsAllowedToScheduleColdProduct(bool $isAllowedToScheduleColdProduct): self
  1181.     {
  1182.         $this->isAllowedToScheduleColdProduct $isAllowedToScheduleColdProduct;
  1183.         return $this;
  1184.     }
  1185.     public function getRecruiter(): ?User
  1186.     {
  1187.         return $this->recruiter;
  1188.     }
  1189.     public function setRecruiter(?User $recruiter): self
  1190.     {
  1191.         $this->recruiter$recruiter;
  1192.         return $this;
  1193.     }
  1194.     public function getTotalSales()
  1195.     {
  1196.         $total 0;
  1197.         foreach($this->getInvoices() as $i){
  1198.             if($i->getIsPaid()){
  1199.                 $total += $i->getTotalSales();
  1200.             }
  1201.         }
  1202.         return $total;
  1203.     }
  1204.     /**
  1205.      * @return Collection|EmailSent[]
  1206.      */
  1207.     public function getEmailReceiveds(): Collection
  1208.     {
  1209.         $emails=[];
  1210.         foreach($this->getUsersAdmin() as $u){
  1211.             if(!$u->isGranted('ROLE_SUPER_ADMIN')){
  1212.                 foreach($u->getEmailReceiveds() as $e){
  1213.                     $emails[$e->getId()] = $e;
  1214.                 }
  1215.             }
  1216.         }
  1217.         rsort($emails);
  1218.         return new ArrayCollection($emails);
  1219.     }
  1220.     public function getInGroupOfUser(): ?User
  1221.     {
  1222.         return $this->inGroupOfUser;
  1223.     }
  1224.     public function setInGroupOfUser(?User $inGroupOfUser): self
  1225.     {
  1226.         $this->inGroupOfUser $inGroupOfUser;
  1227.         return $this;
  1228.     }
  1229.     /**
  1230.      * @return Collection|Variable[]
  1231.      */
  1232.     public function getVariables(): Collection
  1233.     {
  1234.         return $this->variables;
  1235.     }
  1236.     public function addVariable(Variable $variable): self
  1237.     {
  1238.         if (!$this->variables->contains($variable)) {
  1239.             $this->variables[] = $variable;
  1240.         }
  1241.         return $this;
  1242.     }
  1243.     public function removeVariable(Variable $variable): self
  1244.     {
  1245.         if ($this->variables->contains($variable)) {
  1246.             $this->variables->removeElement($variable);
  1247.         }
  1248.         return $this;
  1249.     }
  1250.     public function getVariableByCodeName($codeName){
  1251.         foreach($this->getVariables() as $v){
  1252.             if($v->getCodeName() == $codeName)
  1253.                 return $v;
  1254.         }
  1255.         foreach($this->getAssociations() as $c){
  1256.             $test $c->getVariableByCodeName($codeName);
  1257.             if($test)
  1258.                 return $test;
  1259.         }
  1260.         return false;
  1261.     }
  1262.     public function getVariableValueByCodeName($codeName){
  1263.         $test $this->getVariableByCodeName($codeName);
  1264.         if($test && !$test->isExpired())
  1265.             return $test->getValue();
  1266.         return false;
  1267.     }
  1268.       /**
  1269.      * @return bool
  1270.      */
  1271.     public function getReminderStripeVerificationSent(): bool
  1272.     {
  1273.         return $this->reminderStripeVerificationSent;
  1274.     }
  1275.     /**
  1276.      * @param bool $reminderCouponSent
  1277.      * @return Company
  1278.      */
  1279.     public function setReminderStripeVerificationSent(bool $ReminderStripeVerficationSent): self
  1280.     {
  1281.         $this->reminderStripeVerificationSent $ReminderStripeVerficationSent;
  1282.         return $this;
  1283.     }
  1284. }