<?php
declare(strict_types=1);
namespace App\Entity\Customer;
use App\Entity\Addressing\Address;
use App\Entity\Addressing\AddressType;
use App\Entity\ClinicalManager\ClinicalManager;
use App\Entity\Distributor\Distributor;
use App\Entity\Doctor\Doctor;
use App\Entity\Order\OrderRecurring;
use App\Entity\Patient\Patient;
use App\Entity\Product\ProductCustomerStatistic;
use App\Entity\Product\ReductionProduct;
use App\Entity\Refund\Refund;
use App\Entity\Taxonomy\ReductionTaxon;
use App\Entity\User\AdminUser;
use App\Entity\User\ShopUser;
use App\Entity\Wallet\Wallet;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
use Sylius\Component\Core\Model\ImageAwareInterface;
use Sylius\Component\Core\Model\ImageInterface;
use TheCodingMachine\SogecommercePlugin\Model\CustomerTrait as SogecommerceCustomerTrait;
use function sprintf;
/** @method ShopUser|null getUser() */
#[ORM\Table(name: 'sylius_customer')]
#[ORM\Entity]
#[ExclusionPolicy('all')]
class Customer extends BaseCustomer implements ImageAwareInterface
{
use SogecommerceCustomerTrait {
SogecommerceCustomerTrait::__construct as private __sogecommerceCustomerTraitConstruct;
}
#[ORM\Column(name: 'social_reason', type: 'string', length: 255, nullable: true)]
private string|null $socialReason = null;
#[ORM\Column(name: 'inter_community_tva_number', type: 'string', length: 255, nullable: true)]
private string|null $interCommunityTvaNumber = null;
#[ORM\Column(name: 'secondary_emails', type: Types::JSON, nullable: true)]
private array $secondaryEmails = [];
#[ORM\Column(name: 'city', type: 'string', length: 255, nullable: true)]
private string|null $city = null;
#[ORM\Column(name: 'country', type: 'string', length: 255, nullable: true)]
private string|null $country = null;
#[ORM\Column(name: 'company', type: 'string', length: 255, nullable: true)]
private string|null $company = null;
#[ORM\OneToOne(inversedBy: 'customer', targetEntity: AdminUser::class, cascade: ['all'])]
private AdminUser|null $adminUser = null;
#[ORM\OneToOne(inversedBy: 'customer', targetEntity: Doctor::class, cascade: ['all'])]
private Doctor|null $doctor = null;
#[ORM\OneToOne(inversedBy: 'customer', targetEntity: Patient::class, cascade: ['all'])]
private Patient|null $patient = null;
#[ORM\OneToOne(inversedBy: 'customer', targetEntity: Distributor::class, cascade: ['all'])]
private Distributor|null $distributor = null;
#[ORM\OneToOne(inversedBy: 'customer', targetEntity: ClinicalManager::class, cascade: ['all'])]
private ClinicalManager|null $clinicalManager = null;
#[ORM\OneToOne(mappedBy: 'owner', targetEntity: CustomerPhoto::class, cascade: ['all'], orphanRemoval: true)]
private ImageInterface|null $photo = null;
#[ORM\ManyToOne(targetEntity: AdminUser::class, inversedBy: 'attachedCustomers')]
#[ORM\JoinColumn(name: 'attached_pdm_id', nullable: true, onDelete: 'SET NULL')]
private AdminUser|null $attachedPDM = null;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: ReductionProduct::class, cascade: ['all'], orphanRemoval: true)]
private Collection $reductionProducts;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: ReductionTaxon::class, cascade: ['all'], orphanRemoval: true)]
private Collection $reductionTaxons;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Refund::class, cascade: ['all'], orphanRemoval: true)]
private Collection $refunds;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: OrderRecurring::class, cascade: ['all'], orphanRemoval: true)]
private Collection $orderRecurrings;
#[ORM\Column(name: 'id_sage', type: 'string', length: 255, nullable: true)]
private string|null $idSage = null;
#[ORM\Column(name: 'number_orders', type: 'integer', nullable: false, options: ['default' => 0])]
private int $numberOrders = 0;
#[ORM\Column(name: 'turnover', type: 'integer', nullable: false, options: ['default' => 0])]
private int $turnover = 0;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: CustomerYearlyStatistic::class, cascade: ['all'], orphanRemoval: true)]
private Collection $customerYearlyStatistics;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: ProductCustomerStatistic::class, cascade: ['all'], orphanRemoval: true)]
private Collection $productCustomerStatistics;
#[ORM\OneToOne(mappedBy: 'customer', targetEntity: CustomerSocialAccount::class, orphanRemoval: true)]
private CustomerSocialAccount|null $socialAccount;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: DeviceToken::class, cascade: ['all'], orphanRemoval: true)]
private Collection $deviceTokens;
#[ORM\OneToOne(mappedBy: 'customer', targetEntity: Wallet::class, cascade: ['all'], orphanRemoval: true)]
private Wallet|null $wallet = null;
public function __construct()
{
parent::__construct();
$this->refunds = new ArrayCollection();
$this->reductionProducts = new ArrayCollection();
$this->reductionTaxons = new ArrayCollection();
$this->__sogecommerceCustomerTraitConstruct();
$this->orderRecurrings = new ArrayCollection();
$this->customerYearlyStatistics = new ArrayCollection();
$this->productCustomerStatistics = new ArrayCollection();
$this->deviceTokens = new ArrayCollection();
}
#[VirtualProperty]
#[SerializedName('id')]
#[Groups(['Default', 'Detailed', 'Autocomplete'])]
public function getId(): int|null
{
return parent::getId();
}
#[VirtualProperty]
#[SerializedName('name')]
#[Groups(['Default', 'Detailed', 'Autocomplete'])]
public function getFullName(): string
{
return parent::getFullName();
}
#[VirtualProperty]
#[SerializedName('email_full_name')]
#[Groups(['Default', 'Detailed', 'Autocomplete'])]
public function getFullNameAndEmail(): string
{
return sprintf('%s (%s)', parent::getFullName(), parent::getEmail());
}
public function getSocialReason(): string|null
{
return $this->socialReason;
}
public function setSocialReason(string|null $socialReason): void
{
$this->socialReason = $socialReason;
}
public function getInterCommunityTvaNumber(): string|null
{
return $this->interCommunityTvaNumber;
}
public function setInterCommunityTvaNumber(string|null $interCommunityTvaNumber): void
{
$this->interCommunityTvaNumber = $interCommunityTvaNumber;
}
/** @return string[] */
public function getSecondaryEmails(): array
{
return $this->secondaryEmails;
}
/** @param string[] $secondaryEmails */
public function setSecondaryEmails(array $secondaryEmails): void
{
$this->secondaryEmails = $secondaryEmails;
}
public function getCity(): string|null
{
return $this->city;
}
public function setCity(string|null $city): void
{
$this->city = $city;
}
public function getCountry(): string|null
{
return $this->country;
}
public function setCountry(string|null $country): void
{
$this->country = $country;
}
public function getAdminUser(): AdminUser|null
{
return $this->adminUser;
}
public function setAdminUser(AdminUser|null $adminUser): void
{
$this->adminUser = $adminUser;
}
public function getDoctor(): Doctor|null
{
return $this->doctor;
}
public function setDoctor(Doctor|null $doctor): void
{
$this->doctor = $doctor;
}
public function getDistributor(): Distributor|null
{
return $this->distributor;
}
public function setDistributor(Distributor|null $distributor): void
{
$this->distributor = $distributor;
}
public function getImage(): ImageInterface|null
{
return $this->photo;
}
public function setImage(ImageInterface|null $image): void
{
$image?->setOwner($this);
$this->photo = $image;
}
public function getClinicalManager(): ClinicalManager|null
{
return $this->clinicalManager;
}
public function setClinicalManager(ClinicalManager|null $clinicalManager): void
{
$this->clinicalManager = $clinicalManager;
}
/** @return Collection<array-key, ReductionProduct> */
public function getReductionProducts(): Collection
{
return $this->reductionProducts;
}
/** @param Collection<array-key, ReductionProduct> $reductionProducts */
public function setReductionProducts(Collection $reductionProducts): void
{
$this->reductionProducts = $reductionProducts;
}
public function addReductionProduct(ReductionProduct $reductionProduct): self
{
if (! $this->reductionProducts->contains($reductionProduct)) {
$this->reductionProducts[] = $reductionProduct;
}
return $this;
}
public function removeReductionProduct(ReductionProduct $reductionProduct): self
{
$this->reductionProducts->removeElement($reductionProduct);
return $this;
}
public function clearReductionProducts(): void
{
$this->reductionProducts->clear();
}
/** @return Collection<array-key, ReductionTaxon> */
public function getReductionTaxons(): Collection
{
return $this->reductionTaxons;
}
/** @param Collection<array-key, ReductionTaxon> $reductionTaxons */
public function setReductionTaxons(Collection $reductionTaxons): void
{
$this->reductionTaxons = $reductionTaxons;
}
public function addReductionTaxon(ReductionTaxon $reductionTaxon): self
{
if (! $this->reductionTaxons->contains($reductionTaxon)) {
$this->reductionTaxons[] = $reductionTaxon;
}
return $this;
}
public function removeReductionTaxon(ReductionTaxon $reductionTaxon): self
{
$this->reductionTaxons->removeElement($reductionTaxon);
return $this;
}
public function clearReductionTaxons(): void
{
$this->reductionTaxons->clear();
}
/** @return Collection<array-key, Refund> */
public function getRefunds(): Collection
{
return $this->refunds;
}
/** @return Collection<array-key, Refund> */
public function getUnarchivedRefunds(): Collection
{
return $this->getRefunds()->filter(static fn (Refund $refund) => ! $refund->isArchived());
}
/** @param Collection<array-key, Refund> $refunds */
public function setRefunds(Collection $refunds): void
{
$this->refunds = $refunds;
}
public function addRefund(Refund $refund): void
{
if ($this->refunds->contains($refund)) {
return;
}
$this->refunds[] = $refund;
$refund->setCustomer($this);
}
public function removeRefund(Refund $refund): void
{
$this->refunds->removeElement($refund);
}
public function getAttachedPDM(): AdminUser|null
{
return $this->attachedPDM;
}
public function setAttachedPDM(AdminUser|null $attachedPDM): void
{
$this->attachedPDM = $attachedPDM;
}
public function getCompany(): string|null
{
return $this->company;
}
public function setCompany(string|null $company): void
{
$this->company = $company;
}
/** @param Collection<array-key, OrderRecurring> $orderRecurrings */
public function setOrderRecurrings(Collection $orderRecurrings): void
{
$this->orderRecurrings = $orderRecurrings;
}
/** @return Collection<array-key, OrderRecurring> */
public function getOrderRecurrings(): Collection
{
return $this->orderRecurrings;
}
public function addOrderRecurring(OrderRecurring $orderRecurring): void
{
if ($this->orderRecurrings->contains($orderRecurring)) {
return;
}
$this->orderRecurrings[] = $orderRecurring;
$orderRecurring->setCustomer($this);
}
public function removeOrderRecurring(OrderRecurring $orderRecurring): void
{
$this->orderRecurrings->removeElement($orderRecurring);
}
public function hasActiveOrderRecurring(): bool
{
foreach ($this->getOrderRecurrings() as $orderRecurring) {
if ($orderRecurring->isActive()) {
return true;
}
}
return false;
}
public function getActiveOrderRecurring(): OrderRecurring|null
{
foreach ($this->getOrderRecurrings() as $orderRecurring) {
if ($orderRecurring->isActive()) {
return $orderRecurring;
}
}
return null;
}
public function getIdSage(): string|null
{
return $this->idSage;
}
public function setIdSage(string|null $idSage): void
{
$this->idSage = $idSage;
}
public function getShippingAddress(): Address|null
{
/** @var Address $address */
foreach ($this->getAddresses() as $address) {
if ($address->getType() === AddressType::SHIPPING) {
return $address;
}
}
return null;
}
public function getBillingAddress(): Address|null
{
/** @var Address $address */
foreach ($this->getAddresses() as $address) {
if ($address->getType() === AddressType::BILLING) {
return $address;
}
}
return null;
}
public function getNumberOrders(): int
{
return $this->numberOrders;
}
public function setNumberOrders(int $numberOrders): void
{
$this->numberOrders = $numberOrders;
}
public function getTurnover(): int
{
return $this->turnover;
}
public function setTurnover(int $turnover): void
{
$this->turnover = $turnover;
}
/** @return Collection<array-key, CustomerYearlyStatistic> */
public function getCustomerYearlyStatistics(): Collection
{
return $this->customerYearlyStatistics;
}
/** @param Collection<array-key, CustomerYearlyStatistic> $customerYearlyStatistics */
public function setCustomerYearlyStatistics(Collection $customerYearlyStatistics): void
{
$this->customerYearlyStatistics = $customerYearlyStatistics;
}
public function addCustomerYearlyStatistic(CustomerYearlyStatistic $customerYearlyStatistic): self
{
if (! $this->customerYearlyStatistics->contains($customerYearlyStatistic)) {
$this->customerYearlyStatistics[] = $customerYearlyStatistic;
$customerYearlyStatistic->setCustomer($this);
}
return $this;
}
public function removeCustomerYearlyStatistic(CustomerYearlyStatistic $customerYearlyStatistic): self
{
$this->customerYearlyStatistics->removeElement($customerYearlyStatistic);
return $this;
}
/** @return Collection<array-key, ProductCustomerStatistic> */
public function getProductCustomerStatistics(): Collection
{
return $this->productCustomerStatistics;
}
/** @param Collection<array-key, ProductCustomerStatistic> $productCustomerStatistics */
public function setProductCustomerStatistics(Collection $productCustomerStatistics): void
{
$this->productCustomerStatistics = $productCustomerStatistics;
}
public function addProductCustomerStatistic(ProductCustomerStatistic $productCustomerStatistic): self
{
if (! $this->productCustomerStatistics->contains($productCustomerStatistic)) {
$this->productCustomerStatistics[] = $productCustomerStatistic;
$productCustomerStatistic->setCustomer($this);
}
return $this;
}
public function removeProductCustomerStatistic(ProductCustomerStatistic $productCustomerStatistic): self
{
$this->productCustomerStatistics->removeElement($productCustomerStatistic);
return $this;
}
public function getAttachedClinicalManager(): ClinicalManager|null
{
if ($this->doctor !== null) {
return $this->doctor->getAttachedClinicalManager();
}
return $this->clinicalManager?->getAttachedClinicalManager();
}
public function getPatient(): Patient|null
{
return $this->patient;
}
public function setPatient(Patient|null $patient): void
{
$this->patient = $patient;
}
public function getSocialAccount(): CustomerSocialAccount|null
{
return $this->socialAccount;
}
public function setSocialAccount(CustomerSocialAccount|null $socialAccount): void
{
$this->socialAccount = $socialAccount;
}
/** @return Collection<array-key, DeviceToken> */
public function getDeviceTokens(): Collection
{
return $this->deviceTokens;
}
/** @param Collection<array-key, DeviceToken> $deviceTokens */
public function setDeviceTokens(Collection $deviceTokens): void
{
$this->deviceTokens = $deviceTokens;
}
public function addDeviceToken(DeviceToken $deviceToken): void
{
if ($this->deviceTokens->contains($deviceToken)) {
return;
}
$this->deviceTokens[] = $deviceToken;
$deviceToken->setCustomer($this);
}
public function removeDeviceToken(DeviceToken $deviceToken): void
{
$this->deviceTokens->removeElement($deviceToken);
}
public function getWallet(): Wallet|null
{
return $this->wallet;
}
public function setWallet(Wallet|null $wallet): void
{
$this->wallet = $wallet;
}
}