<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
/**
* Customers
*
* @ORM\Table(name="customers", indexes={@ORM\Index(name="purchased_without_account", columns={"purchased_without_account"})})
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Customer
{
const INVOICE_TYPE_PAPER = 0;
const INVOICE_TYPE_NUMERIC = 1;
public const STATUS_WAITING = 'en attente';
public const STATUS_VALIDATED = 'valide';
public const STATUS_BLOCKED = 'invalide';
/**
* @var int
*
* @ORM\Column(name="customers_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var bool
*
* @ORM\Column(name="purchased_without_account", type="boolean", nullable=false)
*/
private $purchasedWithoutAccount = '0';
/**
* @var string
*
* @ORM\Column(name="customers_gender", type="string", length=1, nullable=false, options={"fixed"=true})
*/
private $gender = '';
/**
* @var string
*
* @ORM\Column(name="customers_firstname", type="string", length=32, nullable=false)
*/
private $firstname = '';
/**
* @var string
*
* @ORM\Column(name="customers_lastname", type="string", length=32, nullable=false)
*/
private $lastname = '';
/**
* @var ?\DateTime
*
* @ORM\Column(name="customers_dob", type="datetime", nullable=true)
*/
private $dateOfBirth;
/**
* @var string
*
* @ORM\Column(name="customers_email_address", type="string", length=96, nullable=false)
*/
private $email = '';
/**
* @var ?\App\Entity\Address
*
* @ORM\ManyToOne(targetEntity="App\Entity\Address")
* @ORM\JoinColumn(name="customers_default_address_id", referencedColumnName="address_book_id", nullable=true)
*/
private $defaultAddress;
/**
* @var \App\Entity\Language
*
* @ORM\ManyToOne(targetEntity="App\Entity\Language")
* @ORM\JoinColumn(name="languages_id", referencedColumnName="languages_id")
*/
private $language;
/**
* @var string
*
* @ORM\Column(name="customers_telephone", type="string", length=32, nullable=false)
*/
private $telephone = '';
/**
* @var string|null
*
* @ORM\Column(name="customers_fax", type="string", length=32, nullable=true)
*/
private $fax;
/**
* @var string|null
*
* @ORM\Column(name="customers_tva", type="string", length=32, nullable=true)
*/
private $tva;
/**
* @var string|null
*
* @ORM\Column(name="customers_siret", type="string", length=32, nullable=true)
*/
private $siret;
/**
* @var string|null
*
* @ORM\Column(name="customers_elevage", type="string", length=20, nullable=true)
*/
private $elevage;
/**
* @var string|null
*
* @ORM\Column(name="customers_affixe", type="string", length=100, nullable=true)
*/
private $affixe;
/**
* @var string
*
* @ORM\Column(name="customers_password", type="string", length=40, nullable=false)
*/
private $password = '';
/**
* @var string|null
*
* @ORM\Column(name="customers_newsletter", type="string", length=1, nullable=true, options={"fixed"=true})
*/
private $newsletter;
/**
* @var string|null
*
* @ORM\Column(name="customers_selected_template", type="string", length=20, nullable=true)
*/
private $selectedTemplate;
/**
* @var \App\Entity\CustomerGroup
*
* @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup")
* @ORM\JoinColumn(name="customers_group_id", referencedColumnName="customers_group_id", nullable=true)
*/
private $group;
/**
* @var string
*
* @ORM\Column(name="customers_group_ra", type="string", length=0, nullable=false)
*/
private $groupRa = '0';
/**
* @var string
*
* @ORM\Column(name="customers_payment_allowed", type="string", length=255, nullable=false)
*/
private $paymentAllowed = '';
/**
* @var string
*
* @ORM\Column(name="customers_shipment_allowed", type="string", length=255, nullable=false)
*/
private $shipmentAllowed = '';
/**
* @var string
*
* @ORM\Column(name="customers_validation_code", type="string", length=48, nullable=false)
*/
private $validationCode = '';
/**
* @var string
*
* @ORM\Column(name="customers_validation", type="string", length=1, nullable=false, options={"fixed"=true})
*/
private $validation = '0';
/**
* @var string
*
* @ORM\Column(name="customers_email_registered", type="string", length=32, nullable=false)
*/
private $emailRegistered = '';
/**
* @var string|null
*
* @ORM\Column(name="customers_sage", type="text", length=65535, nullable=true, options={"comment"="Code client de SAGE"})
*/
private $sage;
/**
* @var string|null
*
* @ORM\Column(name="customers_sap_id", type="string", length=50, nullable=true, options={"comment"="Code client de SAP"})
*/
private $sapId;
/**
* @var string|null
*
* @ORM\Column(name="customers_company", type="string", length=64, nullable=true)
*/
private $company;
/**
* @var string|null
*
* @ORM\Column(name="customers_referent", type="string", length=32, nullable=true)
*/
private $referent;
/**
* @var string|null
*
* @ORM\Column(name="customers_metier", type="string", length=32, nullable=true)
*/
private $metier;
/**
* @var string|null
*
* @ORM\Column(name="customers_metier_sap", type="string", length=32, nullable=true)
*/
private $metierSAP;
/**
* @var string|null
*
* @ORM\Column(name="customers_autreprecisez", type="string", length=32, nullable=true)
*/
private $autreprecisez;
/**
* @var int
*
* @ORM\Column(name="customers_pai_differe", type="integer", nullable=true)
*/
private $paiDiffere;
/**
* @var int
*
* @ORM\Column(name="customers_exclu_TVA", type="integer", nullable=true)
*/
private $excluTva;
/**
* @var int
*
* @ORM\Column(name="customers_invoice_type", type="integer", nullable=true)
*/
private $invoiceType = null;
/**
* @var ?\DateTime
*
* @ORM\Column(name="customers_last_login", type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @var ?\DateTime
*
* @ORM\Column(name="customers_creation", type="datetime", nullable=true)
*/
private $creation;
/**
* @var ?int
*
* @ORM\Column(name="customers_nblogin", type="integer", nullable=true)
*/
private $nbLogin = 0;
/**
* @var ?\DateTime
*
* @ORM\Column(name="customers_account_update", type="datetime", nullable=true)
*/
private $accountUpdate;
/**
* @var string
*
* @ORM\Column(name="customers_status", type="string", length="20", nullable=true)
*/
private $status;
/**
* @ORM\Column(name="customers_expert", type="integer", nullable=true)
*/
private $expert = 0;
/**
* @ORM\Column(name="customers_expert_id", type="string", length="20", nullable=true)
*/
private $expertId;
/**
* @var array
*
* @ORM\OneToMany(targetEntity="App\Entity\CustomerPriceGroup", mappedBy="customer", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $priceGroups;
/**
* @ORM\Column(name="customers_consent_ad_products", type="integer", nullable=true)
*/
private $consentAdProducts;
/**
* @ORM\Column(name="customers_consent_ad_others", type="integer", nullable=true)
*/
private $consentAdOthers;
/**
* @ORM\Column(name="customers_consent_group", type="integer", nullable=true)
*/
private $consentGroup;
public function __construct()
{
$this->priceGroups = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId() {
return $this->id;
}
public function getPurchasedWithoutAccount() {
return $this->purchasedWithoutAccount;
}
public function getGender() {
return $this->gender;
}
public function getFirstname() {
return $this->firstname;
}
public function getLastname() {
return $this->lastname;
}
public function getDateOfBirth(): ?\DateTime {
return $this->dateOfBirth;
}
public function getEmailAddress() {
return $this->email;
}
public function getEmail() {
return $this->getEmailAddress();
}
public function getDefaultAddressId() {
return $this->getDefaultAddress()->getId();
}
public function getDefaultAddress() {
return $this->defaultAddress;
}
public function getTelephone() {
return $this->telephone;
}
public function getFax() {
return $this->fax;
}
public function getTva(): ?string {
return strtoupper($this->tva);
}
public function getSiret(): ?string {
return $this->siret;
}
public function getElevage(): ?string {
return $this->elevage;
}
public function getVatNumber() {
return $this->getTva();
}
public function getAffixe(): ?string {
return $this->affixe;
}
public function getPassword() {
return $this->password;
}
public function getNewsletter() {
return $this->newsletter;
}
public function getSelectedTemplate() {
return $this->selectedTemplate;
}
public function getGroup() {
return $this->group;
}
public function getGroupRa() {
return $this->groupRa;
}
public function getPaymentAllowed() {
return $this->paymentAllowed;
}
public function getShipmentAllowed() {
return $this->shipmentAllowed;
}
public function getValidationCode() {
return $this->validationCode;
}
public function getValidation() {
return $this->validation;
}
public function getEmailRegistered() {
return $this->emailRegistered;
}
public function getSage() {
return $this->sage;
}
public function getSynopticId() {
$value = $this->sage;
$value = str_replace('SYNOPTIC','',$value);
$value = trim(str_replace(':','',$value));
$value = intval($value);
if(!empty($value)){
return $value;
}
return 'new';
}
public function getCompany() {
return $this->company;
}
public function getReferent() {
return $this->referent;
}
public function getMetier() {
return $this->metier;
}
public function getAutreprecisez() {
return $this->autreprecisez;
}
public function getPaiDiffere() {
return $this->paiDiffere;
}
public function getExcluTva() {
return $this->excluTva;
}
public function getInvoiceType() {
return $this->invoiceType;
}
public function getFullname() {
$firstname = $this->getFirstname();
$lastname = $this->getLastname();
if(empty($lastname)||empty($firstname))
return $this->getCompany ();
return $firstname.' '.$lastname;
}
public function getLanguage(): \App\Entity\Language {
return $this->language;
}
public function getLastLogin(): ?\DateTime {
return $this->lastLogin;
}
public function getCreation(): ?\DateTime {
return $this->creation;
}
public function getNbLogin(): ?int {
return is_null($this->nbLogin)?0:$this->nbLogin;
}
public function getAccountUpdate(): ?\DateTime {
return $this->accountUpdate;
}
public function getSapId(): ?string {
return empty($this->sapId) ? 'new' : $this->sapId;
$value = $this->sage;
if(!empty($value)){
return $value;
}
return 'new';
}
public function getSapIdByPriceGroup(PriceGroup $priceGroup): ?string {
$sapId = $this->sapId;
foreach($this->priceGroups as $pGroup) {
if($pGroup->getGroup() == $priceGroup)
$sapId = $pGroup->getSapId();
}
return empty($sapId) ? 'new' : $sapId;
}
public function getMetierSAP(): ?string {
return $this->metierSAP;
}
public function getStatus(): ?string {
return $this->status;
}
public function getConsentAdProducts() {
return $this->consentAdProducts;
}
public function getConsentAdOthers() {
return $this->consentAdOthers;
}
public function getConsentGroup() {
return $this->consentGroup;
}
public function setStatus($status): void {
$this->status = $status;
}
public function getPriceGroups() {
return $this->priceGroups;
}
public function getExpert() {
return $this->expert;
}
public function getExpertId() {
return $this->expertId;
}
public function setId($id) {
$this->id = $id;
}
public function setPurchasedWithoutAccount($purchasedWithoutAccount) {
$this->purchasedWithoutAccount = $purchasedWithoutAccount;
}
public function setGender($gender) {
$this->gender = $gender;
}
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
public function setLastname($lastname) {
$this->lastname = $lastname;
}
public function setDateOfBirth(?\DateTime $dateOfBirth) {
$this->dateOfBirth = $dateOfBirth;
}
public function setEmailAddress($email) {
$this->email = $email;
}
public function setDefaultAddressId($defaultAddressId) {
$this->defaultAddressId = $defaultAddressId;
}
public function setDefaultAddress($defaultAddress) {
$this->defaultAddress = $defaultAddress;
}
public function setTelephone($telephone) {
$this->telephone = $telephone;
}
public function setFax($fax) {
$this->fax = $fax;
}
public function setTva(?string $tva): void {
$this->tva = strtoupper($tva);
}
public function setSiret(?string $siret): void {
$this->siret = $siret;
}
public function setElevage(?string $elevage): void {
$this->elevage = $elevage;
}
public function setAffixe(?string $affixe): void {
$this->affixe = $affixe;
}
public function setPassword($password) {
$this->password = $password;
}
public function setNewsletter($newsletter) {
$this->newsletter = $newsletter;
}
public function setSelectedTemplate($selectedTemplate) {
$this->selectedTemplate = $selectedTemplate;
}
public function setGroup(\App\Entity\CustomerGroup $group) {
$this->group = $group;
}
public function setGroupRa($groupRa) {
$this->groupRa = $groupRa;
}
public function setPaymentAllowed($paymentAllowed) {
$this->paymentAllowed = $paymentAllowed;
}
public function setShipmentAllowed($shipmentAllowed) {
$this->shipmentAllowed = $shipmentAllowed;
}
public function setValidationCode($validationCode) {
$this->validationCode = $validationCode;
}
public function setValidation($validation) {
$this->validation = $validation;
}
public function setEmailRegistered($emailRegistered) {
$this->emailRegistered = $emailRegistered;
}
public function setSage($sage) {
$this->sage = $sage;
}
public function setCompany($company) {
$this->company = $company;
}
public function setReferent($referent) {
$this->referent = $referent;
}
public function setMetier($metier) {
$this->metier = $metier;
}
public function setAutreprecisez($autreprecisez) {
$this->autreprecisez = $autreprecisez;
}
public function setPaiDiffere($paiDiffere) {
$this->paiDiffere = $paiDiffere;
}
public function setExcluTva($excluTva) {
$this->excluTva = $excluTva;
}
public function setInvoiceType($invoiceType) {
$this->invoiceType = $invoiceType;
}
public function setLanguage(\App\Entity\Language $language): void {
$this->language = $language;
}
public function setLastLogin(?\DateTime $lastLogin): void {
$this->lastLogin = $lastLogin;
}
public function setCreation(?\DateTime $creation): void {
$this->creation = $creation;
}
public function setNbLogin(?int $nbLogin): void {
$this->nbLogin = $nbLogin;
}
public function setAccountUpdate(?\DateTime $accountUpdate): void {
$this->accountUpdate = $accountUpdate;
}
public function setSapId(?string $sapId): void {
$this->sapId = $sapId;
}
public function setMetierSAP(?string $metierSAP): void {
$this->metierSAP = $metierSAP;
}
public function setPriceGroups($priceGroups): void {
$this->priceGroups = $priceGroups;
}
public function setExpert($expert): void {
$this->expert = $expert;
}
public function setExpertId($expertId): void {
$this->expertId = $expertId;
}
public function setConsentAdProducts($consentAdProducts): void {
$this->consentAdProducts = $consentAdProducts;
}
public function setConsentAdOthers($consentAdOthers): void {
$this->consentAdOthers = $consentAdOthers;
}
public function setConsentGroup($consentGroup): void {
$this->consentGroup = $consentGroup;
}
public function hasSoleil() {
$address = $this->getDefaultAddress();
if($address){
return $address->getCountry()->getSoleil() == 1;
}
return false;
}
public function hasBienvenue() {
$address = $this->getDefaultAddress();
if($address){
return $address->getCountry()->getBienvenue() == 1;
}
return false;
}
public function hasPlatiniumDiscount() {
$group = $this->getGroup();
return $group && $group->getId() == 2;
}
public function hasEliteDiscount() {
$group = $this->getGroup();
return $group && $group->getId() == 3;
}
public function hasNoTva() {
return $this->getExcluTva() == 1;
}
public function isValidated() {
return is_null($this->status) || ($this->getStatus() == self::STATUS_VALIDATED);
}
public function hasPriceGroup(PriceGroup $priceGroup): self
{
return $this->priceGroups->contains($priceGroup);
}
public function addPriceGroup(CustomerPriceGroup $priceGroup): self
{
if (!$this->priceGroups->contains($priceGroup)) {
$this->priceGroups->add($priceGroup);
$priceGroup->setCustomer($this);
}
return $this;
}
public function removePriceGroup(CustomerPriceGroup $priceGroup): self
{
if ($this->priceGroups->removeElement($priceGroup)) {
if ($priceGroup->getCustomer() === $this) {
$priceGroup->setCustomer(null);
}
}
return $this;
}
public function toArray() : array{
$output = [
'id' => $this->getId(),
'purchasedWithoutAccount' => $this->getPurchasedWithoutAccount(),
'gender' => $this->getGender(),
'firstname' => $this->getFirstname(),
'lastname' => $this->getLastname(),
'dateOfBirth' => $this->getDateOfBirth(),
'email' => $this->getEmailAddress(),
//'defaultAddressId' => $this->getDefaultAddress()?$this->getDefaultAddress()->getId():0,
'telephone' => $this->getTelephone(),
'fax' => $this->getFax(),
'newsletter' => $this->getNewsletter(),
'selectedTemplate' => $this->getSelectedTemplate(),
'group' => empty($this->group)?null:$this->getGroup()->toArray(),
'groupRa' => $this->getGroupRa(),
'paymentAllowed' => $this->getPaymentAllowed(),
'shipmentAllowed' => $this->getShipmentAllowed(),
'validationCode' => $this->getValidationCode(),
'validation' => $this->getValidation(),
'status' => $this->getStatus(),
'emailRegistered' => $this->getEmailRegistered(),
'sage' => $this->getSage(),
'company' => $this->getCompany(),
'referent' => $this->getReferent(),
'metier' => $this->getMetier(),
'autreprecisez' => $this->getId(),
'paiDiffere' => $this->getPaiDiffere(),
'excluTva' => $this->getExcluTva(),
'expert' => $this->getExpert(),
'expertId' => $this->getExpertId(),
'priceGroups' => []
];
foreach($this->getPriceGroups() as $priceGroup) {
$output['priceGroups'][] = $priceGroup->getGroup()->toArray();
}
return $output;
}
/**
* @ORM\PrePersist
*/
public function prePersist(\Doctrine\ORM\Event\LifecycleEventArgs $arg)
{
if(is_null($this->telephone)){
$this->setTelephone('');
}
}
/**
* @ORM\PostLoad
*/
public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $arg)
{
if ($this->getGroup() && $this->getGroup()->getId() == 0) {
$this->group = null;
}
// if($this->defaultAddressId) {
// $address = $arg->getObjectManager()->getRepository('App:Address')->find($this->defaultAddressId);
// if($address)
// $this->setDefaultAddress($address);
// }
}
}