src/Entity/Customer.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Product\Product;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation\ExclusionPolicy;
  9. use JMS\Serializer\Annotation\Expose;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * Class Customer
  13.  *
  14.  * @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
  15.  * @ORM\Table(name="malys_customer")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  * @ExclusionPolicy("all")
  18.  */
  19. class Customer
  20. {
  21.     /**
  22.      * @var integer
  23.      *
  24.      * @ORM\Column(name="id", type="integer")
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      * @Expose
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @var string
  32.      * @ORM\Column(name="brand_name", type="string", length=255, nullable=false)
  33.      * @Assert\NotBlank(message="Veuillez indiquer le nom de l'établissement")
  34.      * @Expose
  35.      */
  36.     protected $brandName;
  37.     /**
  38.      * @var string
  39.      * @ORM\Column(name="company_name", type="string", length=255, nullable=false)
  40.      * @Assert\NotBlank(message="Veuillez indiquer la raison sociale de la société")
  41.      * @Expose
  42.      */
  43.     protected $companyName;
  44.     /**
  45.      * @var string
  46.      *
  47.      * @ORM\Column(name="business_number", type="string", length=255, nullable=true)
  48.      * @Expose
  49.      */
  50.     protected $businessNumber;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @ORM\Column(name="address", type="string", nullable=false)
  55.      * @Assert\NotBlank(message="Veuillez indiquer l'adresse de l'établissement")
  56.      * @Expose
  57.      */
  58.     protected $address;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(name="zip_code", type="string", nullable=false)
  63.      * @Assert\NotBlank(message="Veuillez indiquer le code postal")
  64.      * @Expose
  65.      */
  66.     protected $zipCode;
  67.     /**
  68.      * @var string
  69.      *
  70.      * @ORM\Column(name="city", type="string", nullable=false)
  71.      * @Assert\NotBlank(message="Veuillez indiquer la ville")
  72.      * @Expose
  73.      */
  74.     protected $city;
  75.     /**
  76.      * @var string
  77.      *
  78.      * @ORM\Column(name="country", type="string", nullable=true)
  79.      * @Expose
  80.      */
  81.     protected $country;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="phone", type="string", nullable=true)
  86.      * @Expose
  87.      */
  88.     protected $phone;
  89.     /**
  90.      * @var string
  91.      *
  92.      * @ORM\Column(name="mobile", type="string", nullable=true)
  93.      * @Expose
  94.      */
  95.     protected $mobile;
  96.     /**
  97.      * @var string
  98.      *
  99.      * @ORM\Column(name="comment", type="text", nullable=true)
  100.      */
  101.     protected $comment;
  102.     /**
  103.      * @var boolean
  104.      *
  105.      * @ORM\Column(name="enabled", type="boolean", options={"default" : true})
  106.      * @Expose
  107.      */
  108.     protected $enabled true;
  109.     /**
  110.      * @var ArrayCollection
  111.      *
  112.      * @ORM\ManyToMany(targetEntity="App\Entity\User", cascade={"persist"}, mappedBy="shops")
  113.      */
  114.     protected $teamMembers;
  115.     /**
  116.      * @var BusinessType
  117.      *
  118.      * @ORM\ManyToOne(targetEntity="BusinessType")
  119.      * @ORM\JoinColumn(name="business_type_id", referencedColumnName="id")
  120.      */
  121.     protected $businessType;
  122.     /**
  123.      * @var ArrayCollection
  124.      *
  125.      * @ORM\OneToMany(targetEntity="SupplierCustomer", mappedBy="customer", cascade={"remove"})
  126.      */
  127.     protected $supplierCustomers;
  128.     /**
  129.      * @var DateTime
  130.      *
  131.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  132.      * @Expose
  133.      */
  134.     protected $createdAt;
  135.     /**
  136.      * @var DateTime
  137.      *
  138.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  139.      * @Expose
  140.      */
  141.     protected $updatedAt;
  142.     /**
  143.      * One Customer has Many PriceOptimized
  144.      * @ORM\OneToMany(targetEntity="App\Entity\PriceOptimized", mappedBy="customer")
  145.      */
  146.     protected $optimizedPrices;
  147.     /**
  148.      * @ORM\ManyToMany(targetEntity="App\Entity\Product\Product", mappedBy="customers")
  149.      */
  150.     protected $favoritesProducts;
  151.     /**
  152.      * One Customer has Many OldPrice
  153.      * @ORM\OneToMany(targetEntity="App\Entity\OldPrice", mappedBy="customer")
  154.      */
  155.     protected $oldPrices;
  156.     /**
  157.      * @var array
  158.      */
  159.     protected $suppliers;
  160.     /**
  161.      * @var DateTime
  162.      *
  163.      * @ORM\Column(name="slotStart", type="datetime", nullable=true)
  164.      * @Expose
  165.      * @Assert\Expression("value <= this.slotFinish", message="La date de début de livraison ne peut être supérieure à la date de fin de livraison")
  166.      */
  167.     public $slotStart;
  168.     /**
  169.      * @var DateTime
  170.      *
  171.      * @ORM\Column(name="slotFinish", type="datetime", nullable=true)
  172.      * @Expose
  173.      * @Assert\Expression("value >= this.slotStart", message="La date de fin de livraison ne peut être inférieure à la date de début de livraison")
  174.      */
  175.     public $slotFinish;
  176.     /**
  177.      * @var string
  178.      *
  179.      * @ORM\Column(name="delivery_comment", type="text", nullable=true)
  180.      * @Expose
  181.      */
  182.     protected $deliveryComment;
  183.     /**
  184.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  185.      * @ORM\JoinColumn(name="saleperson_id", referencedColumnName="id", nullable=true)
  186.      * @Expose
  187.      */
  188.     protected $salePerson;
  189.     /**
  190.      * @ORM\ManyToMany(targetEntity="App\Entity\Supplier", inversedBy="suggestedForCustomers")
  191.      * @ORM\JoinTable(name="malys_customer_suggested_suppliers")
  192.      */
  193.     protected $suggestedSuppliers;
  194.     /**
  195.      * @ORM\Column(name="latitude", type="decimal", precision=18, scale=12, nullable=true)
  196.      */
  197.     public $latitude;
  198.     /**
  199.      * @ORM\Column(name="longitude", type="decimal", precision=18, scale=12, nullable=true)
  200.      */
  201.     public $longitude;
  202.     /**
  203.      * @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup", inversedBy="customers")
  204.      * @ORM\JoinColumn(name="customer_group_id", referencedColumnName="id", onDelete="CASCADE")
  205.      * @Assert\NotBlank
  206.      */
  207.     public $customerGroup;
  208.     /**
  209.      * @var string
  210.      *
  211.      * @ORM\Column(name="source_system", type="string", nullable=true)
  212.      * @Expose
  213.      */
  214.     protected $sourceSystem;
  215.     /**
  216.      * Customer constructor.
  217.      */
  218.     public function __construct()
  219.     {
  220.         $this->supplierCustomers  = new ArrayCollection();
  221.         $this->optimizedPrices    = new ArrayCollection();
  222.         $this->favoritesProducts  = new ArrayCollection();
  223.         $this->oldPrices          = new ArrayCollection();
  224.         $this->suggestedSuppliers = new ArrayCollection();
  225.         $this->teamMembers        = new ArrayCollection();
  226.         $this->suppliers          null;
  227.     }
  228.     public function __toString()
  229.     {
  230.         return $this->brandName ' (' $this->address ')';
  231.     }
  232.     /**
  233.      * @return int
  234.      */
  235.     public function getId()
  236.     {
  237.         return $this->id;
  238.     }
  239.     /**
  240.      * @param int $id
  241.      */
  242.     public function setId($id)
  243.     {
  244.         $this->id $id;
  245.     }
  246.     /**
  247.      * @return string
  248.      */
  249.     public function getBrandName()
  250.     {
  251.         return $this->brandName;
  252.     }
  253.     /**
  254.      * @param string $brandName
  255.      */
  256.     public function setBrandName($brandName)
  257.     {
  258.         $this->brandName $brandName;
  259.     }
  260.     /**
  261.      * @return string
  262.      */
  263.     public function getCompanyName()
  264.     {
  265.         return $this->companyName;
  266.     }
  267.     /**
  268.      * @param string $companyName
  269.      */
  270.     public function setCompanyName($companyName)
  271.     {
  272.         $this->companyName $companyName;
  273.     }
  274.     /**
  275.      * @return string
  276.      */
  277.     public function getBusinessNumber()
  278.     {
  279.         return $this->businessNumber;
  280.     }
  281.     /**
  282.      * @param string $businessNumber
  283.      */
  284.     public function setBusinessNumber($businessNumber)
  285.     {
  286.         $this->businessNumber $businessNumber;
  287.     }
  288.     /**
  289.      * @return string
  290.      */
  291.     public function getAddress()
  292.     {
  293.         return $this->address;
  294.     }
  295.     /**
  296.      * @param string $address
  297.      */
  298.     public function setAddress($address)
  299.     {
  300.         $this->address $address;
  301.     }
  302.     /**
  303.      * @return string
  304.      */
  305.     public function getZipCode()
  306.     {
  307.         return $this->zipCode;
  308.     }
  309.     /**
  310.      * @param string $zipCode
  311.      */
  312.     public function setZipCode($zipCode)
  313.     {
  314.         $this->zipCode $zipCode;
  315.     }
  316.     /**
  317.      * @return string
  318.      */
  319.     public function getCity()
  320.     {
  321.         return $this->city;
  322.     }
  323.     /**
  324.      * @param string $city
  325.      */
  326.     public function setCity($city)
  327.     {
  328.         $this->city $city;
  329.     }
  330.     /**
  331.      * @return string
  332.      */
  333.     public function getCountry()
  334.     {
  335.         return $this->country;
  336.     }
  337.     /**
  338.      * @param string $country
  339.      */
  340.     public function setCountry($country)
  341.     {
  342.         $this->country $country;
  343.     }
  344.     /**
  345.      * @return string
  346.      */
  347.     public function getPhone()
  348.     {
  349.         return $this->phone;
  350.     }
  351.     /**
  352.      * @param string $phone
  353.      */
  354.     public function setPhone($phone)
  355.     {
  356.         $this->phone $phone;
  357.     }
  358.     /**
  359.      * @return string
  360.      */
  361.     public function getMobile()
  362.     {
  363.         return $this->mobile;
  364.     }
  365.     /**
  366.      * @param string $mobile
  367.      */
  368.     public function setMobile($mobile)
  369.     {
  370.         $this->mobile $mobile;
  371.     }
  372.     /**
  373.      * @return string
  374.      */
  375.     public function getComment()
  376.     {
  377.         return $this->comment;
  378.     }
  379.     /**
  380.      * @param string $comment
  381.      */
  382.     public function setComment($comment)
  383.     {
  384.         $this->comment $comment;
  385.     }
  386.     /**
  387.      * @return bool
  388.      */
  389.     public function isEnabled()
  390.     {
  391.         return $this->enabled;
  392.     }
  393.     /**
  394.      * @param bool $enabled
  395.      */
  396.     public function setEnabled($enabled)
  397.     {
  398.         $this->enabled $enabled;
  399.     }
  400.     /**
  401.      * @return ArrayCollection
  402.      */
  403.     public function getUsers()
  404.     {
  405.         return $this->users;
  406.     }
  407.     /**
  408.      * @param ArrayCollection $users
  409.      */
  410.     public function setUsers($users)
  411.     {
  412.         $this->users $users;
  413.     }
  414.     /**
  415.      * @param User $user
  416.      */
  417.     public function addUser($user)
  418.     {
  419.         $this->users->add($user);
  420.     }
  421.     /**
  422.      * @param User $user
  423.      */
  424.     public function removeUser($user)
  425.     {
  426.         if ($this->users->contains($user)) {
  427.             $this->users->removeElement($user);
  428.         }
  429.     }
  430.     /**
  431.      * @return BusinessType
  432.      */
  433.     public function getBusinessType()
  434.     {
  435.         return $this->businessType;
  436.     }
  437.     /**
  438.      * @param BusinessType $businessType
  439.      */
  440.     public function setBusinessType($businessType)
  441.     {
  442.         $this->businessType $businessType;
  443.     }
  444.     /**
  445.      * @return ArrayCollection
  446.      */
  447.     public function getSupplierCustomers()
  448.     {
  449.         return $this->supplierCustomers;
  450.     }
  451.     /**
  452.      * @param ArrayCollection $supplierCustomers
  453.      */
  454.     public function setSupplierCustomers($supplierCustomers)
  455.     {
  456.         $this->supplierCustomers $supplierCustomers;
  457.     }
  458.     public function hasSupplier(Supplier $supplier)
  459.     {
  460.         $suppliers $this->getSuppliers();
  461.         return isset($suppliers$supplier->getId() ]);
  462.     }
  463.     /**
  464.      * @return DateTime
  465.      */
  466.     public function getCreatedAt()
  467.     {
  468.         return $this->createdAt;
  469.     }
  470.     /**
  471.      * Set createdAt
  472.      *
  473.      * @return Customer
  474.      * @ORM\PrePersist
  475.      */
  476.     public function setCreatedAt()
  477.     {
  478.         $this->createdAt = new DateTime();
  479.         $this->updatedAt = new DateTime();
  480.         return $this;
  481.     }
  482.     /**
  483.      * @return DateTime
  484.      */
  485.     public function getUpdatedAt()
  486.     {
  487.         return $this->updatedAt;
  488.     }
  489.     /**
  490.      * Set updatedAt
  491.      *
  492.      * @return Customer
  493.      * @ORM\PreUpdate
  494.      */
  495.     public function setUpdatedAt()
  496.     {
  497.         $this->updatedAt = new DateTime();
  498.         return $this;
  499.     }
  500.     /**
  501.      * @return mixed
  502.      */
  503.     public function getOptimizedPrices()
  504.     {
  505.         return $this->optimizedPrices;
  506.     }
  507.     /**
  508.      * @param mixed $optimizedPrices
  509.      */
  510.     public function setOptimizedPrices($optimizedPrices)
  511.     {
  512.         $this->optimizedPrices $optimizedPrices;
  513.     }
  514.     /**
  515.      * @return ArrayCollection|Collection
  516.      */
  517.     public function getFavoritesProducts()
  518.     {
  519.         return $this->favoritesProducts;
  520.         // Je comment out car le controle de la vente de produit n'est pas censé se faire ici
  521.         //        return $this->favoritesProducts->filter(function($product) {
  522.         //            if($product instanceof Product && $product->isEnabled()
  523.         //                && $product->getSupplier() instanceof Supplier
  524.         //                && $product->getSupplier()->isEnabled()
  525.         //                && $this->getSupplierCustomerBySupplier($product->getSupplier()) instanceof SupplierCustomer
  526.         //            ) {
  527.         //                return true;
  528.         //            }
  529.         //            return false;
  530.         //        });
  531.     }
  532.     public function setFavoritesProducts($favoritesProducts)
  533.     {
  534.         $this->favoritesProducts $favoritesProducts;
  535.     }
  536.     /**
  537.      * @param Product $product
  538.      */
  539.     public function addFavoriteProduct(Product $product)
  540.     {
  541.         if (! $this->favoritesProducts->contains($product)) {
  542.             $this->favoritesProducts->add($product);
  543.         }
  544.     }
  545.     /**
  546.      * @param Product $product
  547.      */
  548.     public function removeFavoriteProduct(Product $product)
  549.     {
  550.         if ($this->favoritesProducts->contains($product)) {
  551.             $this->favoritesProducts->removeElement($product);
  552.         }
  553.     }
  554.     /**
  555.      * Add or Remove Favorite and return true if product is favorite, false is product is not a favorite
  556.      *
  557.      * @param Product $product
  558.      *
  559.      * @return bool
  560.      */
  561.     public function addOrremoveFavoriteProduct(Product $product)
  562.     {
  563.         if ($this->favoritesProducts->contains($product)) {
  564.             $this->favoritesProducts->removeElement($product);
  565.             return false;
  566.         } else {
  567.             $this->favoritesProducts->add($product);
  568.             return true;
  569.         }
  570.     }
  571.     /**
  572.      * @return mixed
  573.      */
  574.     public function getOldPrices()
  575.     {
  576.         return $this->oldPrices;
  577.     }
  578.     /**
  579.      * @param mixed $oldPrices
  580.      */
  581.     public function setOldPrices($oldPrices)
  582.     {
  583.         $this->oldPrices $oldPrices;
  584.     }
  585.     /**
  586.      * @return array
  587.      */
  588.     public function getSuppliers()
  589.     {
  590.         if ($this->suppliers === null) {
  591.             $this->suppliers = [];
  592.             /** @var SupplierCustomer $supplierCustomer */
  593.             foreach ($this->getSupplierCustomers() as $supplierCustomer) {
  594.                 $this->suppliers$supplierCustomer->getSupplier()->getId() ] = $supplierCustomer->getSupplier();
  595.             }
  596.         }
  597.         return $this->suppliers;
  598.     }
  599.     /**
  600.      * @return DateTime
  601.      */
  602.     public function getSlotStart()
  603.     {
  604.         return $this->slotStart;
  605.     }
  606.     /**
  607.      * Set slotStart
  608.      *
  609.      * @param Datetime $slotStart
  610.      */
  611.     public function setSlotStart($slotStart)
  612.     {
  613.         $this->slotStart $slotStart;
  614.     }
  615.     /**
  616.      * @return DateTime
  617.      */
  618.     public function getSlotFinish()
  619.     {
  620.         return $this->slotFinish;
  621.     }
  622.     /**
  623.      * Set slotFinish
  624.      *
  625.      * @param Datetime $slotFinish
  626.      */
  627.     public function setSlotFinish($slotFinish)
  628.     {
  629.         $this->slotFinish $slotFinish;
  630.     }
  631.     /**
  632.      * @param Supplier $supplier
  633.      *
  634.      * @return SupplierCustomer|false
  635.      */
  636.     public function getSupplierCustomerBySupplier(Supplier $supplier)
  637.     {
  638.         return $this->supplierCustomers->filter(function (SupplierCustomer $supplierCustomer) use ($supplier) {
  639.             return $supplierCustomer->getSupplier()->getId() == $supplier->getId();
  640.         })->first();
  641.     }
  642.     /**
  643.      * @param $supplierId
  644.      *
  645.      * @return mixed
  646.      */
  647.     public function getSupplierCustomerBySupplierId($supplierId)
  648.     {
  649.         return $this->supplierCustomers->filter(function (SupplierCustomer $supplierCustomer) use ($supplierId) {
  650.             return $supplierCustomer->getSupplier()->getId() == $supplierId;
  651.         })->first();
  652.     }
  653.     /**
  654.      * @return string
  655.      */
  656.     public function getDeliveryComment()
  657.     {
  658.         return $this->deliveryComment;
  659.     }
  660.     /**
  661.      * @param string $deliveryComment
  662.      */
  663.     public function setDeliveryComment($deliveryComment)
  664.     {
  665.         $this->deliveryComment $deliveryComment;
  666.     }
  667.     /**
  668.      * @return mixed
  669.      */
  670.     public function getSalePerson()
  671.     {
  672.         return $this->salePerson;
  673.     }
  674.     /**
  675.      * @param mixed $salePerson
  676.      */
  677.     public function setSalePerson($salePerson)
  678.     {
  679.         $this->salePerson $salePerson;
  680.     }
  681.     /**
  682.      * @return mixed
  683.      */
  684.     public function getSuggestedSuppliers()
  685.     {
  686.         return $this->suggestedSuppliers;
  687.     }
  688.     /**
  689.      * @param mixed $suggestedSuppliers
  690.      */
  691.     public function setSuggestedSuppliers($suggestedSuppliers)
  692.     {
  693.         $this->suggestedSuppliers $suggestedSuppliers;
  694.     }
  695.     public function addSuggestedSupplier($supplier)
  696.     {
  697.         $this->suggestedSuppliers->add($supplier);
  698.     }
  699.     public function removeSuggestedSupplier($supplier)
  700.     {
  701.         $this->suggestedSuppliers->removeElement($supplier);
  702.     }
  703.     /**
  704.      * @return mixed
  705.      */
  706.     public function getLatitude()
  707.     {
  708.         return $this->latitude;
  709.     }
  710.     /**
  711.      * @param mixed $latitude
  712.      */
  713.     public function setLatitude($latitude)
  714.     {
  715.         $this->latitude $latitude;
  716.     }
  717.     /**
  718.      * @return mixed
  719.      */
  720.     public function getLongitude()
  721.     {
  722.         return $this->longitude;
  723.     }
  724.     /**
  725.      * @param mixed $longitude
  726.      */
  727.     public function setLongitude($longitude)
  728.     {
  729.         $this->longitude $longitude;
  730.     }
  731.     /**
  732.      * @return CustomerGroup
  733.      */
  734.     public function getCustomerGroup()
  735.     {
  736.         return $this->customerGroup;
  737.     }
  738.     /**
  739.      * @param CustomerGroup $customerGroup
  740.      */
  741.     public function setCustomerGroup(CustomerGroup $customerGroup)
  742.     {
  743.         $this->customerGroup $customerGroup;
  744.     }
  745.     /**
  746.      * @return ArrayCollection
  747.      */
  748.     public function getTeamMembers()
  749.     {
  750.         return $this->teamMembers;
  751.     }
  752.     /**
  753.      * @param ArrayCollection $teamMembers
  754.      */
  755.     //    public function setTeamMembers( ArrayCollection $teamMembers ): void {
  756.     //        $this->teamMembers = $teamMembers;
  757.     //    }
  758.     public function addTeamMember(User $user)
  759.     {
  760.         if ($this->teamMembers->contains($user)) {
  761.             return;
  762.         }
  763.         $this->teamMembers->add($user);
  764.         $user->addShop($this);
  765.     }
  766.     public function removeTeamMember(User $user)
  767.     {
  768.         if (! $this->teamMembers->contains($user)) {
  769.             return;
  770.         }
  771.         $this->teamMembers->removeElement($user);
  772.         $user->removeShop($this);
  773.     }
  774.     /**
  775.      * @return string
  776.      */
  777.     public function getSourceSystem(): ?string
  778.     {
  779.         return $this->sourceSystem;
  780.     }
  781.     /**
  782.      * @param string $sourceSystem
  783.      */
  784.     public function setSourceSystem(?string $sourceSystem): void
  785.     {
  786.         $this->sourceSystem $sourceSystem;
  787.     }
  788. }