src/Entity/Customer.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
  5. /**
  6. * Customers
  7. *
  8. * @ORM\Table(name="customers", indexes={@ORM\Index(name="purchased_without_account", columns={"purchased_without_account"})})
  9. * @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
  10. * @ORM\HasLifecycleCallbacks()
  11. */
  12. class Customer
  13. {
  14. const INVOICE_TYPE_PAPER = 0;
  15. const INVOICE_TYPE_NUMERIC = 1;
  16. public const STATUS_WAITING = 'en attente';
  17. public const STATUS_VALIDATED = 'valide';
  18. public const STATUS_BLOCKED = 'invalide';
  19. /**
  20. * @var int
  21. *
  22. * @ORM\Column(name="customers_id", type="integer", nullable=false)
  23. * @ORM\Id
  24. * @ORM\GeneratedValue(strategy="IDENTITY")
  25. */
  26. private $id;
  27. /**
  28. * @var bool
  29. *
  30. * @ORM\Column(name="purchased_without_account", type="boolean", nullable=false)
  31. */
  32. private $purchasedWithoutAccount = '0';
  33. /**
  34. * @var string
  35. *
  36. * @ORM\Column(name="customers_gender", type="string", length=1, nullable=false, options={"fixed"=true})
  37. */
  38. private $gender = '';
  39. /**
  40. * @var string
  41. *
  42. * @ORM\Column(name="customers_firstname", type="string", length=32, nullable=false)
  43. */
  44. private $firstname = '';
  45. /**
  46. * @var string
  47. *
  48. * @ORM\Column(name="customers_lastname", type="string", length=32, nullable=false)
  49. */
  50. private $lastname = '';
  51. /**
  52. * @var ?\DateTime
  53. *
  54. * @ORM\Column(name="customers_dob", type="datetime", nullable=true)
  55. */
  56. private $dateOfBirth;
  57. /**
  58. * @var string
  59. *
  60. * @ORM\Column(name="customers_email_address", type="string", length=96, nullable=false)
  61. */
  62. private $email = '';
  63. /**
  64. * @var ?\App\Entity\Address
  65. *
  66. * @ORM\ManyToOne(targetEntity="App\Entity\Address")
  67. * @ORM\JoinColumn(name="customers_default_address_id", referencedColumnName="address_book_id", nullable=true)
  68. */
  69. private $defaultAddress;
  70. /**
  71. * @var \App\Entity\Language
  72. *
  73. * @ORM\ManyToOne(targetEntity="App\Entity\Language")
  74. * @ORM\JoinColumn(name="languages_id", referencedColumnName="languages_id")
  75. */
  76. private $language;
  77. /**
  78. * @var string
  79. *
  80. * @ORM\Column(name="customers_telephone", type="string", length=32, nullable=false)
  81. */
  82. private $telephone = '';
  83. /**
  84. * @var string|null
  85. *
  86. * @ORM\Column(name="customers_fax", type="string", length=32, nullable=true)
  87. */
  88. private $fax;
  89. /**
  90. * @var string|null
  91. *
  92. * @ORM\Column(name="customers_tva", type="string", length=32, nullable=true)
  93. */
  94. private $tva;
  95. /**
  96. * @var string|null
  97. *
  98. * @ORM\Column(name="customers_siret", type="string", length=32, nullable=true)
  99. */
  100. private $siret;
  101. /**
  102. * @var string|null
  103. *
  104. * @ORM\Column(name="customers_elevage", type="string", length=20, nullable=true)
  105. */
  106. private $elevage;
  107. /**
  108. * @var string|null
  109. *
  110. * @ORM\Column(name="customers_affixe", type="string", length=100, nullable=true)
  111. */
  112. private $affixe;
  113. /**
  114. * @var string
  115. *
  116. * @ORM\Column(name="customers_password", type="string", length=40, nullable=false)
  117. */
  118. private $password = '';
  119. /**
  120. * @var string|null
  121. *
  122. * @ORM\Column(name="customers_newsletter", type="string", length=1, nullable=true, options={"fixed"=true})
  123. */
  124. private $newsletter;
  125. /**
  126. * @var string|null
  127. *
  128. * @ORM\Column(name="customers_selected_template", type="string", length=20, nullable=true)
  129. */
  130. private $selectedTemplate;
  131. /**
  132. * @var \App\Entity\CustomerGroup
  133. *
  134. * @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup")
  135. * @ORM\JoinColumn(name="customers_group_id", referencedColumnName="customers_group_id", nullable=true)
  136. */
  137. private $group;
  138. /**
  139. * @var string
  140. *
  141. * @ORM\Column(name="customers_group_ra", type="string", length=0, nullable=false)
  142. */
  143. private $groupRa = '0';
  144. /**
  145. * @var string
  146. *
  147. * @ORM\Column(name="customers_payment_allowed", type="string", length=255, nullable=false)
  148. */
  149. private $paymentAllowed = '';
  150. /**
  151. * @var string
  152. *
  153. * @ORM\Column(name="customers_shipment_allowed", type="string", length=255, nullable=false)
  154. */
  155. private $shipmentAllowed = '';
  156. /**
  157. * @var string
  158. *
  159. * @ORM\Column(name="customers_validation_code", type="string", length=48, nullable=false)
  160. */
  161. private $validationCode = '';
  162. /**
  163. * @var string
  164. *
  165. * @ORM\Column(name="customers_validation", type="string", length=1, nullable=false, options={"fixed"=true})
  166. */
  167. private $validation = '0';
  168. /**
  169. * @var string
  170. *
  171. * @ORM\Column(name="customers_email_registered", type="string", length=32, nullable=false)
  172. */
  173. private $emailRegistered = '';
  174. /**
  175. * @var string|null
  176. *
  177. * @ORM\Column(name="customers_sage", type="text", length=65535, nullable=true, options={"comment"="Code client de SAGE"})
  178. */
  179. private $sage;
  180. /**
  181. * @var string|null
  182. *
  183. * @ORM\Column(name="customers_sap_id", type="string", length=50, nullable=true, options={"comment"="Code client de SAP"})
  184. */
  185. private $sapId;
  186. /**
  187. * @var string|null
  188. *
  189. * @ORM\Column(name="customers_company", type="string", length=64, nullable=true)
  190. */
  191. private $company;
  192. /**
  193. * @var string|null
  194. *
  195. * @ORM\Column(name="customers_referent", type="string", length=32, nullable=true)
  196. */
  197. private $referent;
  198. /**
  199. * @var string|null
  200. *
  201. * @ORM\Column(name="customers_metier", type="string", length=32, nullable=true)
  202. */
  203. private $metier;
  204. /**
  205. * @var string|null
  206. *
  207. * @ORM\Column(name="customers_metier_sap", type="string", length=32, nullable=true)
  208. */
  209. private $metierSAP;
  210. /**
  211. * @var string|null
  212. *
  213. * @ORM\Column(name="customers_autreprecisez", type="string", length=32, nullable=true)
  214. */
  215. private $autreprecisez;
  216. /**
  217. * @var int
  218. *
  219. * @ORM\Column(name="customers_pai_differe", type="integer", nullable=true)
  220. */
  221. private $paiDiffere;
  222. /**
  223. * @var int
  224. *
  225. * @ORM\Column(name="customers_exclu_TVA", type="integer", nullable=true)
  226. */
  227. private $excluTva;
  228. /**
  229. * @var int
  230. *
  231. * @ORM\Column(name="customers_invoice_type", type="integer", nullable=true)
  232. */
  233. private $invoiceType = null;
  234. /**
  235. * @var ?\DateTime
  236. *
  237. * @ORM\Column(name="customers_last_login", type="datetime", nullable=true)
  238. */
  239. private $lastLogin;
  240. /**
  241. * @var ?\DateTime
  242. *
  243. * @ORM\Column(name="customers_creation", type="datetime", nullable=true)
  244. */
  245. private $creation;
  246. /**
  247. * @var ?int
  248. *
  249. * @ORM\Column(name="customers_nblogin", type="integer", nullable=true)
  250. */
  251. private $nbLogin = 0;
  252. /**
  253. * @var ?\DateTime
  254. *
  255. * @ORM\Column(name="customers_account_update", type="datetime", nullable=true)
  256. */
  257. private $accountUpdate;
  258. /**
  259. * @var string
  260. *
  261. * @ORM\Column(name="customers_status", type="string", length="20", nullable=true)
  262. */
  263. private $status;
  264. /**
  265. * @ORM\Column(name="customers_expert", type="integer", nullable=true)
  266. */
  267. private $expert = 0;
  268. /**
  269. * @ORM\Column(name="customers_expert_id", type="string", length="20", nullable=true)
  270. */
  271. private $expertId;
  272. /**
  273. * @var array
  274. *
  275. * @ORM\OneToMany(targetEntity="App\Entity\CustomerPriceGroup", mappedBy="customer", cascade={"persist", "remove"}, orphanRemoval=true)
  276. */
  277. private $priceGroups;
  278. /**
  279. * @ORM\Column(name="customers_consent_ad_products", type="integer", nullable=true)
  280. */
  281. private $consentAdProducts;
  282. /**
  283. * @ORM\Column(name="customers_consent_ad_others", type="integer", nullable=true)
  284. */
  285. private $consentAdOthers;
  286. /**
  287. * @ORM\Column(name="customers_consent_group", type="integer", nullable=true)
  288. */
  289. private $consentGroup;
  290. public function __construct()
  291. {
  292. $this->priceGroups = new \Doctrine\Common\Collections\ArrayCollection();
  293. }
  294. public function getId() {
  295. return $this->id;
  296. }
  297. public function getPurchasedWithoutAccount() {
  298. return $this->purchasedWithoutAccount;
  299. }
  300. public function getGender() {
  301. return $this->gender;
  302. }
  303. public function getFirstname() {
  304. return $this->firstname;
  305. }
  306. public function getLastname() {
  307. return $this->lastname;
  308. }
  309. public function getDateOfBirth(): ?\DateTime {
  310. return $this->dateOfBirth;
  311. }
  312. public function getEmailAddress() {
  313. return $this->email;
  314. }
  315. public function getEmail() {
  316. return $this->getEmailAddress();
  317. }
  318. public function getDefaultAddressId() {
  319. return $this->getDefaultAddress()->getId();
  320. }
  321. public function getDefaultAddress() {
  322. return $this->defaultAddress;
  323. }
  324. public function getTelephone() {
  325. return $this->telephone;
  326. }
  327. public function getFax() {
  328. return $this->fax;
  329. }
  330. public function getTva(): ?string {
  331. return strtoupper($this->tva);
  332. }
  333. public function getSiret(): ?string {
  334. return $this->siret;
  335. }
  336. public function getElevage(): ?string {
  337. return $this->elevage;
  338. }
  339. public function getVatNumber() {
  340. return $this->getTva();
  341. }
  342. public function getAffixe(): ?string {
  343. return $this->affixe;
  344. }
  345. public function getPassword() {
  346. return $this->password;
  347. }
  348. public function getNewsletter() {
  349. return $this->newsletter;
  350. }
  351. public function getSelectedTemplate() {
  352. return $this->selectedTemplate;
  353. }
  354. public function getGroup() {
  355. return $this->group;
  356. }
  357. public function getGroupRa() {
  358. return $this->groupRa;
  359. }
  360. public function getPaymentAllowed() {
  361. return $this->paymentAllowed;
  362. }
  363. public function getShipmentAllowed() {
  364. return $this->shipmentAllowed;
  365. }
  366. public function getValidationCode() {
  367. return $this->validationCode;
  368. }
  369. public function getValidation() {
  370. return $this->validation;
  371. }
  372. public function getEmailRegistered() {
  373. return $this->emailRegistered;
  374. }
  375. public function getSage() {
  376. return $this->sage;
  377. }
  378. public function getSynopticId() {
  379. $value = $this->sage;
  380. $value = str_replace('SYNOPTIC','',$value);
  381. $value = trim(str_replace(':','',$value));
  382. $value = intval($value);
  383. if(!empty($value)){
  384. return $value;
  385. }
  386. return 'new';
  387. }
  388. public function getCompany() {
  389. return $this->company;
  390. }
  391. public function getReferent() {
  392. return $this->referent;
  393. }
  394. public function getMetier() {
  395. return $this->metier;
  396. }
  397. public function getAutreprecisez() {
  398. return $this->autreprecisez;
  399. }
  400. public function getPaiDiffere() {
  401. return $this->paiDiffere;
  402. }
  403. public function getExcluTva() {
  404. return $this->excluTva;
  405. }
  406. public function getInvoiceType() {
  407. return $this->invoiceType;
  408. }
  409. public function getFullname() {
  410. $firstname = $this->getFirstname();
  411. $lastname = $this->getLastname();
  412. if(empty($lastname)||empty($firstname))
  413. return $this->getCompany ();
  414. return $firstname.' '.$lastname;
  415. }
  416. public function getLanguage(): \App\Entity\Language {
  417. return $this->language;
  418. }
  419. public function getLastLogin(): ?\DateTime {
  420. return $this->lastLogin;
  421. }
  422. public function getCreation(): ?\DateTime {
  423. return $this->creation;
  424. }
  425. public function getNbLogin(): ?int {
  426. return is_null($this->nbLogin)?0:$this->nbLogin;
  427. }
  428. public function getAccountUpdate(): ?\DateTime {
  429. return $this->accountUpdate;
  430. }
  431. public function getSapId(): ?string {
  432. return empty($this->sapId) ? 'new' : $this->sapId;
  433. $value = $this->sage;
  434. if(!empty($value)){
  435. return $value;
  436. }
  437. return 'new';
  438. }
  439. public function getSapIdByPriceGroup(PriceGroup $priceGroup): ?string {
  440. $sapId = $this->sapId;
  441. foreach($this->priceGroups as $pGroup) {
  442. if($pGroup->getGroup() == $priceGroup)
  443. $sapId = $pGroup->getSapId();
  444. }
  445. return empty($sapId) ? 'new' : $sapId;
  446. }
  447. public function getMetierSAP(): ?string {
  448. return $this->metierSAP;
  449. }
  450. public function getStatus(): ?string {
  451. return $this->status;
  452. }
  453. public function getConsentAdProducts() {
  454. return $this->consentAdProducts;
  455. }
  456. public function getConsentAdOthers() {
  457. return $this->consentAdOthers;
  458. }
  459. public function getConsentGroup() {
  460. return $this->consentGroup;
  461. }
  462. public function setStatus($status): void {
  463. $this->status = $status;
  464. }
  465. public function getPriceGroups() {
  466. return $this->priceGroups;
  467. }
  468. public function getExpert() {
  469. return $this->expert;
  470. }
  471. public function getExpertId() {
  472. return $this->expertId;
  473. }
  474. public function setId($id) {
  475. $this->id = $id;
  476. }
  477. public function setPurchasedWithoutAccount($purchasedWithoutAccount) {
  478. $this->purchasedWithoutAccount = $purchasedWithoutAccount;
  479. }
  480. public function setGender($gender) {
  481. $this->gender = $gender;
  482. }
  483. public function setFirstname($firstname) {
  484. $this->firstname = $firstname;
  485. }
  486. public function setLastname($lastname) {
  487. $this->lastname = $lastname;
  488. }
  489. public function setDateOfBirth(?\DateTime $dateOfBirth) {
  490. $this->dateOfBirth = $dateOfBirth;
  491. }
  492. public function setEmailAddress($email) {
  493. $this->email = $email;
  494. }
  495. public function setDefaultAddressId($defaultAddressId) {
  496. $this->defaultAddressId = $defaultAddressId;
  497. }
  498. public function setDefaultAddress($defaultAddress) {
  499. $this->defaultAddress = $defaultAddress;
  500. }
  501. public function setTelephone($telephone) {
  502. $this->telephone = $telephone;
  503. }
  504. public function setFax($fax) {
  505. $this->fax = $fax;
  506. }
  507. public function setTva(?string $tva): void {
  508. $this->tva = strtoupper($tva);
  509. }
  510. public function setSiret(?string $siret): void {
  511. $this->siret = $siret;
  512. }
  513. public function setElevage(?string $elevage): void {
  514. $this->elevage = $elevage;
  515. }
  516. public function setAffixe(?string $affixe): void {
  517. $this->affixe = $affixe;
  518. }
  519. public function setPassword($password) {
  520. $this->password = $password;
  521. }
  522. public function setNewsletter($newsletter) {
  523. $this->newsletter = $newsletter;
  524. }
  525. public function setSelectedTemplate($selectedTemplate) {
  526. $this->selectedTemplate = $selectedTemplate;
  527. }
  528. public function setGroup(\App\Entity\CustomerGroup $group) {
  529. $this->group = $group;
  530. }
  531. public function setGroupRa($groupRa) {
  532. $this->groupRa = $groupRa;
  533. }
  534. public function setPaymentAllowed($paymentAllowed) {
  535. $this->paymentAllowed = $paymentAllowed;
  536. }
  537. public function setShipmentAllowed($shipmentAllowed) {
  538. $this->shipmentAllowed = $shipmentAllowed;
  539. }
  540. public function setValidationCode($validationCode) {
  541. $this->validationCode = $validationCode;
  542. }
  543. public function setValidation($validation) {
  544. $this->validation = $validation;
  545. }
  546. public function setEmailRegistered($emailRegistered) {
  547. $this->emailRegistered = $emailRegistered;
  548. }
  549. public function setSage($sage) {
  550. $this->sage = $sage;
  551. }
  552. public function setCompany($company) {
  553. $this->company = $company;
  554. }
  555. public function setReferent($referent) {
  556. $this->referent = $referent;
  557. }
  558. public function setMetier($metier) {
  559. $this->metier = $metier;
  560. }
  561. public function setAutreprecisez($autreprecisez) {
  562. $this->autreprecisez = $autreprecisez;
  563. }
  564. public function setPaiDiffere($paiDiffere) {
  565. $this->paiDiffere = $paiDiffere;
  566. }
  567. public function setExcluTva($excluTva) {
  568. $this->excluTva = $excluTva;
  569. }
  570. public function setInvoiceType($invoiceType) {
  571. $this->invoiceType = $invoiceType;
  572. }
  573. public function setLanguage(\App\Entity\Language $language): void {
  574. $this->language = $language;
  575. }
  576. public function setLastLogin(?\DateTime $lastLogin): void {
  577. $this->lastLogin = $lastLogin;
  578. }
  579. public function setCreation(?\DateTime $creation): void {
  580. $this->creation = $creation;
  581. }
  582. public function setNbLogin(?int $nbLogin): void {
  583. $this->nbLogin = $nbLogin;
  584. }
  585. public function setAccountUpdate(?\DateTime $accountUpdate): void {
  586. $this->accountUpdate = $accountUpdate;
  587. }
  588. public function setSapId(?string $sapId): void {
  589. $this->sapId = $sapId;
  590. }
  591. public function setMetierSAP(?string $metierSAP): void {
  592. $this->metierSAP = $metierSAP;
  593. }
  594. public function setPriceGroups($priceGroups): void {
  595. $this->priceGroups = $priceGroups;
  596. }
  597. public function setExpert($expert): void {
  598. $this->expert = $expert;
  599. }
  600. public function setExpertId($expertId): void {
  601. $this->expertId = $expertId;
  602. }
  603. public function setConsentAdProducts($consentAdProducts): void {
  604. $this->consentAdProducts = $consentAdProducts;
  605. }
  606. public function setConsentAdOthers($consentAdOthers): void {
  607. $this->consentAdOthers = $consentAdOthers;
  608. }
  609. public function setConsentGroup($consentGroup): void {
  610. $this->consentGroup = $consentGroup;
  611. }
  612. public function hasSoleil() {
  613. $address = $this->getDefaultAddress();
  614. if($address){
  615. return $address->getCountry()->getSoleil() == 1;
  616. }
  617. return false;
  618. }
  619. public function hasBienvenue() {
  620. $address = $this->getDefaultAddress();
  621. if($address){
  622. return $address->getCountry()->getBienvenue() == 1;
  623. }
  624. return false;
  625. }
  626. public function hasPlatiniumDiscount() {
  627. $group = $this->getGroup();
  628. return $group && $group->getId() == 2;
  629. }
  630. public function hasEliteDiscount() {
  631. $group = $this->getGroup();
  632. return $group && $group->getId() == 3;
  633. }
  634. public function hasNoTva() {
  635. return $this->getExcluTva() == 1;
  636. }
  637. public function isValidated() {
  638. return is_null($this->status) || ($this->getStatus() == self::STATUS_VALIDATED);
  639. }
  640. public function hasPriceGroup(PriceGroup $priceGroup): self
  641. {
  642. return $this->priceGroups->contains($priceGroup);
  643. }
  644. public function addPriceGroup(CustomerPriceGroup $priceGroup): self
  645. {
  646. if (!$this->priceGroups->contains($priceGroup)) {
  647. $this->priceGroups->add($priceGroup);
  648. $priceGroup->setCustomer($this);
  649. }
  650. return $this;
  651. }
  652. public function removePriceGroup(CustomerPriceGroup $priceGroup): self
  653. {
  654. if ($this->priceGroups->removeElement($priceGroup)) {
  655. if ($priceGroup->getCustomer() === $this) {
  656. $priceGroup->setCustomer(null);
  657. }
  658. }
  659. return $this;
  660. }
  661. public function toArray() : array{
  662. $output = [
  663. 'id' => $this->getId(),
  664. 'purchasedWithoutAccount' => $this->getPurchasedWithoutAccount(),
  665. 'gender' => $this->getGender(),
  666. 'firstname' => $this->getFirstname(),
  667. 'lastname' => $this->getLastname(),
  668. 'dateOfBirth' => $this->getDateOfBirth(),
  669. 'email' => $this->getEmailAddress(),
  670. //'defaultAddressId' => $this->getDefaultAddress()?$this->getDefaultAddress()->getId():0,
  671. 'telephone' => $this->getTelephone(),
  672. 'fax' => $this->getFax(),
  673. 'newsletter' => $this->getNewsletter(),
  674. 'selectedTemplate' => $this->getSelectedTemplate(),
  675. 'group' => empty($this->group)?null:$this->getGroup()->toArray(),
  676. 'groupRa' => $this->getGroupRa(),
  677. 'paymentAllowed' => $this->getPaymentAllowed(),
  678. 'shipmentAllowed' => $this->getShipmentAllowed(),
  679. 'validationCode' => $this->getValidationCode(),
  680. 'validation' => $this->getValidation(),
  681. 'status' => $this->getStatus(),
  682. 'emailRegistered' => $this->getEmailRegistered(),
  683. 'sage' => $this->getSage(),
  684. 'company' => $this->getCompany(),
  685. 'referent' => $this->getReferent(),
  686. 'metier' => $this->getMetier(),
  687. 'autreprecisez' => $this->getId(),
  688. 'paiDiffere' => $this->getPaiDiffere(),
  689. 'excluTva' => $this->getExcluTva(),
  690. 'expert' => $this->getExpert(),
  691. 'expertId' => $this->getExpertId(),
  692. 'priceGroups' => []
  693. ];
  694. foreach($this->getPriceGroups() as $priceGroup) {
  695. $output['priceGroups'][] = $priceGroup->getGroup()->toArray();
  696. }
  697. return $output;
  698. }
  699. /**
  700. * @ORM\PrePersist
  701. */
  702. public function prePersist(\Doctrine\ORM\Event\LifecycleEventArgs $arg)
  703. {
  704. if(is_null($this->telephone)){
  705. $this->setTelephone('');
  706. }
  707. }
  708. /**
  709. * @ORM\PostLoad
  710. */
  711. public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $arg)
  712. {
  713. if ($this->getGroup() && $this->getGroup()->getId() == 0) {
  714. $this->group = null;
  715. }
  716. // if($this->defaultAddressId) {
  717. // $address = $arg->getObjectManager()->getRepository('App:Address')->find($this->defaultAddressId);
  718. // if($address)
  719. // $this->setDefaultAddress($address);
  720. // }
  721. }
  722. }