src/Entity/Customer/Customer.php line 40

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Customer;
  4. use App\Entity\Addressing\Address;
  5. use App\Entity\Addressing\AddressType;
  6. use App\Entity\ClinicalManager\ClinicalManager;
  7. use App\Entity\Distributor\Distributor;
  8. use App\Entity\Doctor\Doctor;
  9. use App\Entity\Order\OrderRecurring;
  10. use App\Entity\Patient\Patient;
  11. use App\Entity\Product\ProductCustomerStatistic;
  12. use App\Entity\Product\ReductionProduct;
  13. use App\Entity\Refund\Refund;
  14. use App\Entity\Taxonomy\ReductionTaxon;
  15. use App\Entity\User\AdminUser;
  16. use App\Entity\User\ShopUser;
  17. use App\Entity\Wallet\Wallet;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\DBAL\Types\Types;
  21. use Doctrine\ORM\Mapping as ORM;
  22. use JMS\Serializer\Annotation\ExclusionPolicy;
  23. use JMS\Serializer\Annotation\Groups;
  24. use JMS\Serializer\Annotation\SerializedName;
  25. use JMS\Serializer\Annotation\VirtualProperty;
  26. use Sylius\Component\Core\Model\Customer as BaseCustomer;
  27. use Sylius\Component\Core\Model\ImageAwareInterface;
  28. use Sylius\Component\Core\Model\ImageInterface;
  29. use TheCodingMachine\SogecommercePlugin\Model\CustomerTrait as SogecommerceCustomerTrait;
  30. use function sprintf;
  31. /** @method ShopUser|null getUser() */
  32. #[ORM\Table(name'sylius_customer')]
  33. #[ORM\Entity]
  34. #[ExclusionPolicy('all')]
  35. class Customer extends BaseCustomer implements ImageAwareInterface
  36. {
  37.     use SogecommerceCustomerTrait {
  38.         SogecommerceCustomerTrait::__construct as private __sogecommerceCustomerTraitConstruct;
  39.     }
  40.     #[ORM\Column(name'social_reason'type'string'length255nullabletrue)]
  41.     private string|null $socialReason null;
  42.     #[ORM\Column(name'inter_community_tva_number'type'string'length255nullabletrue)]
  43.     private string|null $interCommunityTvaNumber null;
  44.     #[ORM\Column(name'secondary_emails'typeTypes::JSONnullabletrue)]
  45.     private array $secondaryEmails = [];
  46.     #[ORM\Column(name'city'type'string'length255nullabletrue)]
  47.     private string|null $city null;
  48.     #[ORM\Column(name'country'type'string'length255nullabletrue)]
  49.     private string|null $country null;
  50.     #[ORM\Column(name'company'type'string'length255nullabletrue)]
  51.     private string|null $company null;
  52.     #[ORM\OneToOne(inversedBy'customer'targetEntityAdminUser::class, cascade: ['all'])]
  53.     private AdminUser|null $adminUser null;
  54.     #[ORM\OneToOne(inversedBy'customer'targetEntityDoctor::class, cascade: ['all'])]
  55.     private Doctor|null $doctor null;
  56.     #[ORM\OneToOne(inversedBy'customer'targetEntityPatient::class, cascade: ['all'])]
  57.     private Patient|null $patient null;
  58.     #[ORM\OneToOne(inversedBy'customer'targetEntityDistributor::class, cascade: ['all'])]
  59.     private Distributor|null $distributor null;
  60.     #[ORM\OneToOne(inversedBy'customer'targetEntityClinicalManager::class, cascade: ['all'])]
  61.     private ClinicalManager|null $clinicalManager null;
  62.     #[ORM\OneToOne(mappedBy'owner'targetEntityCustomerPhoto::class, cascade: ['all'], orphanRemovaltrue)]
  63.     private ImageInterface|null $photo null;
  64.     #[ORM\ManyToOne(targetEntityAdminUser::class, inversedBy'attachedCustomers')]
  65.     #[ORM\JoinColumn(name'attached_pdm_id'nullabletrueonDelete'SET NULL')]
  66.     private AdminUser|null $attachedPDM null;
  67.     #[ORM\OneToMany(mappedBy'customer'targetEntityReductionProduct::class, cascade: ['all'], orphanRemovaltrue)]
  68.     private Collection $reductionProducts;
  69.     #[ORM\OneToMany(mappedBy'customer'targetEntityReductionTaxon::class, cascade: ['all'], orphanRemovaltrue)]
  70.     private Collection $reductionTaxons;
  71.     #[ORM\OneToMany(mappedBy'customer'targetEntityRefund::class, cascade: ['all'], orphanRemovaltrue)]
  72.     private Collection $refunds;
  73.     #[ORM\OneToMany(mappedBy'customer'targetEntityOrderRecurring::class, cascade: ['all'], orphanRemovaltrue)]
  74.     private Collection $orderRecurrings;
  75.     #[ORM\Column(name'id_sage'type'string'length255nullabletrue)]
  76.     private string|null $idSage null;
  77.     #[ORM\Column(name'number_orders'type'integer'nullablefalseoptions: ['default' => 0])]
  78.     private int $numberOrders 0;
  79.     #[ORM\Column(name'turnover'type'integer'nullablefalseoptions: ['default' => 0])]
  80.     private int $turnover 0;
  81.     #[ORM\OneToMany(mappedBy'customer'targetEntityCustomerYearlyStatistic::class, cascade: ['all'], orphanRemovaltrue)]
  82.     private Collection $customerYearlyStatistics;
  83.     #[ORM\OneToMany(mappedBy'customer'targetEntityProductCustomerStatistic::class, cascade: ['all'], orphanRemovaltrue)]
  84.     private Collection $productCustomerStatistics;
  85.     #[ORM\OneToOne(mappedBy'customer'targetEntityCustomerSocialAccount::class, orphanRemovaltrue)]
  86.     private CustomerSocialAccount|null $socialAccount;
  87.     #[ORM\OneToMany(mappedBy'customer'targetEntityDeviceToken::class, cascade: ['all'], orphanRemovaltrue)]
  88.     private Collection $deviceTokens;
  89.     #[ORM\OneToOne(mappedBy'customer'targetEntityWallet::class, cascade: ['all'], orphanRemovaltrue)]
  90.     private Wallet|null $wallet null;
  91.     public function __construct()
  92.     {
  93.         parent::__construct();
  94.         $this->refunds = new ArrayCollection();
  95.         $this->reductionProducts = new ArrayCollection();
  96.         $this->reductionTaxons = new ArrayCollection();
  97.         $this->__sogecommerceCustomerTraitConstruct();
  98.         $this->orderRecurrings = new ArrayCollection();
  99.         $this->customerYearlyStatistics = new ArrayCollection();
  100.         $this->productCustomerStatistics = new ArrayCollection();
  101.         $this->deviceTokens = new ArrayCollection();
  102.     }
  103.     #[VirtualProperty]
  104.     #[SerializedName('id')]
  105.     #[Groups(['Default''Detailed''Autocomplete'])]
  106.     public function getId(): int|null
  107.     {
  108.         return parent::getId();
  109.     }
  110.     #[VirtualProperty]
  111.     #[SerializedName('name')]
  112.     #[Groups(['Default''Detailed''Autocomplete'])]
  113.     public function getFullName(): string
  114.     {
  115.         return parent::getFullName();
  116.     }
  117.     #[VirtualProperty]
  118.     #[SerializedName('email_full_name')]
  119.     #[Groups(['Default''Detailed''Autocomplete'])]
  120.     public function getFullNameAndEmail(): string
  121.     {
  122.         return sprintf('%s (%s)'parent::getFullName(), parent::getEmail());
  123.     }
  124.     public function getSocialReason(): string|null
  125.     {
  126.         return $this->socialReason;
  127.     }
  128.     public function setSocialReason(string|null $socialReason): void
  129.     {
  130.         $this->socialReason $socialReason;
  131.     }
  132.     public function getInterCommunityTvaNumber(): string|null
  133.     {
  134.         return $this->interCommunityTvaNumber;
  135.     }
  136.     public function setInterCommunityTvaNumber(string|null $interCommunityTvaNumber): void
  137.     {
  138.         $this->interCommunityTvaNumber $interCommunityTvaNumber;
  139.     }
  140.     /** @return string[] */
  141.     public function getSecondaryEmails(): array
  142.     {
  143.         return $this->secondaryEmails;
  144.     }
  145.     /** @param string[] $secondaryEmails */
  146.     public function setSecondaryEmails(array $secondaryEmails): void
  147.     {
  148.         $this->secondaryEmails $secondaryEmails;
  149.     }
  150.     public function getCity(): string|null
  151.     {
  152.         return $this->city;
  153.     }
  154.     public function setCity(string|null $city): void
  155.     {
  156.         $this->city $city;
  157.     }
  158.     public function getCountry(): string|null
  159.     {
  160.         return $this->country;
  161.     }
  162.     public function setCountry(string|null $country): void
  163.     {
  164.         $this->country $country;
  165.     }
  166.     public function getAdminUser(): AdminUser|null
  167.     {
  168.         return $this->adminUser;
  169.     }
  170.     public function setAdminUser(AdminUser|null $adminUser): void
  171.     {
  172.         $this->adminUser $adminUser;
  173.     }
  174.     public function getDoctor(): Doctor|null
  175.     {
  176.         return $this->doctor;
  177.     }
  178.     public function setDoctor(Doctor|null $doctor): void
  179.     {
  180.         $this->doctor $doctor;
  181.     }
  182.     public function getDistributor(): Distributor|null
  183.     {
  184.         return $this->distributor;
  185.     }
  186.     public function setDistributor(Distributor|null $distributor): void
  187.     {
  188.         $this->distributor $distributor;
  189.     }
  190.     public function getImage(): ImageInterface|null
  191.     {
  192.         return $this->photo;
  193.     }
  194.     public function setImage(ImageInterface|null $image): void
  195.     {
  196.         $image?->setOwner($this);
  197.         $this->photo $image;
  198.     }
  199.     public function getClinicalManager(): ClinicalManager|null
  200.     {
  201.         return $this->clinicalManager;
  202.     }
  203.     public function setClinicalManager(ClinicalManager|null $clinicalManager): void
  204.     {
  205.         $this->clinicalManager $clinicalManager;
  206.     }
  207.     /** @return Collection<array-key, ReductionProduct> */
  208.     public function getReductionProducts(): Collection
  209.     {
  210.         return $this->reductionProducts;
  211.     }
  212.     /** @param Collection<array-key, ReductionProduct> $reductionProducts */
  213.     public function setReductionProducts(Collection $reductionProducts): void
  214.     {
  215.         $this->reductionProducts $reductionProducts;
  216.     }
  217.     public function addReductionProduct(ReductionProduct $reductionProduct): self
  218.     {
  219.         if (! $this->reductionProducts->contains($reductionProduct)) {
  220.             $this->reductionProducts[] = $reductionProduct;
  221.         }
  222.         return $this;
  223.     }
  224.     public function removeReductionProduct(ReductionProduct $reductionProduct): self
  225.     {
  226.         $this->reductionProducts->removeElement($reductionProduct);
  227.         return $this;
  228.     }
  229.     public function clearReductionProducts(): void
  230.     {
  231.         $this->reductionProducts->clear();
  232.     }
  233.     /** @return Collection<array-key, ReductionTaxon> */
  234.     public function getReductionTaxons(): Collection
  235.     {
  236.         return $this->reductionTaxons;
  237.     }
  238.     /** @param Collection<array-key, ReductionTaxon> $reductionTaxons */
  239.     public function setReductionTaxons(Collection $reductionTaxons): void
  240.     {
  241.         $this->reductionTaxons $reductionTaxons;
  242.     }
  243.     public function addReductionTaxon(ReductionTaxon $reductionTaxon): self
  244.     {
  245.         if (! $this->reductionTaxons->contains($reductionTaxon)) {
  246.             $this->reductionTaxons[] = $reductionTaxon;
  247.         }
  248.         return $this;
  249.     }
  250.     public function removeReductionTaxon(ReductionTaxon $reductionTaxon): self
  251.     {
  252.         $this->reductionTaxons->removeElement($reductionTaxon);
  253.         return $this;
  254.     }
  255.     public function clearReductionTaxons(): void
  256.     {
  257.         $this->reductionTaxons->clear();
  258.     }
  259.     /** @return Collection<array-key, Refund> */
  260.     public function getRefunds(): Collection
  261.     {
  262.         return $this->refunds;
  263.     }
  264.     /** @return Collection<array-key, Refund> */
  265.     public function getUnarchivedRefunds(): Collection
  266.     {
  267.         return $this->getRefunds()->filter(static fn (Refund $refund) => ! $refund->isArchived());
  268.     }
  269.     /** @param Collection<array-key, Refund> $refunds */
  270.     public function setRefunds(Collection $refunds): void
  271.     {
  272.         $this->refunds $refunds;
  273.     }
  274.     public function addRefund(Refund $refund): void
  275.     {
  276.         if ($this->refunds->contains($refund)) {
  277.             return;
  278.         }
  279.         $this->refunds[] = $refund;
  280.         $refund->setCustomer($this);
  281.     }
  282.     public function removeRefund(Refund $refund): void
  283.     {
  284.         $this->refunds->removeElement($refund);
  285.     }
  286.     public function getAttachedPDM(): AdminUser|null
  287.     {
  288.         return $this->attachedPDM;
  289.     }
  290.     public function setAttachedPDM(AdminUser|null $attachedPDM): void
  291.     {
  292.         $this->attachedPDM $attachedPDM;
  293.     }
  294.     public function getCompany(): string|null
  295.     {
  296.         return $this->company;
  297.     }
  298.     public function setCompany(string|null $company): void
  299.     {
  300.         $this->company $company;
  301.     }
  302.     /** @param Collection<array-key, OrderRecurring> $orderRecurrings */
  303.     public function setOrderRecurrings(Collection $orderRecurrings): void
  304.     {
  305.         $this->orderRecurrings $orderRecurrings;
  306.     }
  307.     /** @return Collection<array-key, OrderRecurring> */
  308.     public function getOrderRecurrings(): Collection
  309.     {
  310.         return $this->orderRecurrings;
  311.     }
  312.     public function addOrderRecurring(OrderRecurring $orderRecurring): void
  313.     {
  314.         if ($this->orderRecurrings->contains($orderRecurring)) {
  315.             return;
  316.         }
  317.         $this->orderRecurrings[] = $orderRecurring;
  318.         $orderRecurring->setCustomer($this);
  319.     }
  320.     public function removeOrderRecurring(OrderRecurring $orderRecurring): void
  321.     {
  322.         $this->orderRecurrings->removeElement($orderRecurring);
  323.     }
  324.     public function hasActiveOrderRecurring(): bool
  325.     {
  326.         foreach ($this->getOrderRecurrings() as $orderRecurring) {
  327.             if ($orderRecurring->isActive()) {
  328.                 return true;
  329.             }
  330.         }
  331.         return false;
  332.     }
  333.     public function getActiveOrderRecurring(): OrderRecurring|null
  334.     {
  335.         foreach ($this->getOrderRecurrings() as $orderRecurring) {
  336.             if ($orderRecurring->isActive()) {
  337.                 return $orderRecurring;
  338.             }
  339.         }
  340.         return null;
  341.     }
  342.     public function getIdSage(): string|null
  343.     {
  344.         return $this->idSage;
  345.     }
  346.     public function setIdSage(string|null $idSage): void
  347.     {
  348.         $this->idSage $idSage;
  349.     }
  350.     public function getShippingAddress(): Address|null
  351.     {
  352.         /** @var Address $address */
  353.         foreach ($this->getAddresses() as $address) {
  354.             if ($address->getType() === AddressType::SHIPPING) {
  355.                 return $address;
  356.             }
  357.         }
  358.         return null;
  359.     }
  360.     public function getBillingAddress(): Address|null
  361.     {
  362.         /** @var Address $address */
  363.         foreach ($this->getAddresses() as $address) {
  364.             if ($address->getType() === AddressType::BILLING) {
  365.                 return $address;
  366.             }
  367.         }
  368.         return null;
  369.     }
  370.     public function getNumberOrders(): int
  371.     {
  372.         return $this->numberOrders;
  373.     }
  374.     public function setNumberOrders(int $numberOrders): void
  375.     {
  376.         $this->numberOrders $numberOrders;
  377.     }
  378.     public function getTurnover(): int
  379.     {
  380.         return $this->turnover;
  381.     }
  382.     public function setTurnover(int $turnover): void
  383.     {
  384.         $this->turnover $turnover;
  385.     }
  386.     /** @return Collection<array-key, CustomerYearlyStatistic> */
  387.     public function getCustomerYearlyStatistics(): Collection
  388.     {
  389.         return $this->customerYearlyStatistics;
  390.     }
  391.     /** @param Collection<array-key, CustomerYearlyStatistic> $customerYearlyStatistics */
  392.     public function setCustomerYearlyStatistics(Collection $customerYearlyStatistics): void
  393.     {
  394.         $this->customerYearlyStatistics $customerYearlyStatistics;
  395.     }
  396.     public function addCustomerYearlyStatistic(CustomerYearlyStatistic $customerYearlyStatistic): self
  397.     {
  398.         if (! $this->customerYearlyStatistics->contains($customerYearlyStatistic)) {
  399.             $this->customerYearlyStatistics[] = $customerYearlyStatistic;
  400.             $customerYearlyStatistic->setCustomer($this);
  401.         }
  402.         return $this;
  403.     }
  404.     public function removeCustomerYearlyStatistic(CustomerYearlyStatistic $customerYearlyStatistic): self
  405.     {
  406.         $this->customerYearlyStatistics->removeElement($customerYearlyStatistic);
  407.         return $this;
  408.     }
  409.     /** @return Collection<array-key, ProductCustomerStatistic> */
  410.     public function getProductCustomerStatistics(): Collection
  411.     {
  412.         return $this->productCustomerStatistics;
  413.     }
  414.     /** @param Collection<array-key, ProductCustomerStatistic> $productCustomerStatistics */
  415.     public function setProductCustomerStatistics(Collection $productCustomerStatistics): void
  416.     {
  417.         $this->productCustomerStatistics $productCustomerStatistics;
  418.     }
  419.     public function addProductCustomerStatistic(ProductCustomerStatistic $productCustomerStatistic): self
  420.     {
  421.         if (! $this->productCustomerStatistics->contains($productCustomerStatistic)) {
  422.             $this->productCustomerStatistics[] = $productCustomerStatistic;
  423.             $productCustomerStatistic->setCustomer($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeProductCustomerStatistic(ProductCustomerStatistic $productCustomerStatistic): self
  428.     {
  429.         $this->productCustomerStatistics->removeElement($productCustomerStatistic);
  430.         return $this;
  431.     }
  432.     public function getAttachedClinicalManager(): ClinicalManager|null
  433.     {
  434.         if ($this->doctor !== null) {
  435.             return $this->doctor->getAttachedClinicalManager();
  436.         }
  437.         return $this->clinicalManager?->getAttachedClinicalManager();
  438.     }
  439.     public function getPatient(): Patient|null
  440.     {
  441.         return $this->patient;
  442.     }
  443.     public function setPatient(Patient|null $patient): void
  444.     {
  445.         $this->patient $patient;
  446.     }
  447.     public function getSocialAccount(): CustomerSocialAccount|null
  448.     {
  449.         return $this->socialAccount;
  450.     }
  451.     public function setSocialAccount(CustomerSocialAccount|null $socialAccount): void
  452.     {
  453.         $this->socialAccount $socialAccount;
  454.     }
  455.     /** @return Collection<array-key, DeviceToken> */
  456.     public function getDeviceTokens(): Collection
  457.     {
  458.         return $this->deviceTokens;
  459.     }
  460.     /** @param Collection<array-key, DeviceToken> $deviceTokens */
  461.     public function setDeviceTokens(Collection $deviceTokens): void
  462.     {
  463.         $this->deviceTokens $deviceTokens;
  464.     }
  465.     public function addDeviceToken(DeviceToken $deviceToken): void
  466.     {
  467.         if ($this->deviceTokens->contains($deviceToken)) {
  468.             return;
  469.         }
  470.         $this->deviceTokens[] = $deviceToken;
  471.         $deviceToken->setCustomer($this);
  472.     }
  473.     public function removeDeviceToken(DeviceToken $deviceToken): void
  474.     {
  475.         $this->deviceTokens->removeElement($deviceToken);
  476.     }
  477.     public function getWallet(): Wallet|null
  478.     {
  479.         return $this->wallet;
  480.     }
  481.     public function setWallet(Wallet|null $wallet): void
  482.     {
  483.         $this->wallet $wallet;
  484.     }
  485. }