src/AdminBundle/Entity/Account.php line 17

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9. * Account
  10. */
  11. #[ORM\Table(name: 'account')]
  12. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\AccountRepository::class)]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Account extends BaseEntity
  15. {
  16. const ACCOUNT_FILE_FOLDER = 'upload/account/';
  17. const ACCOUNT_BADGES_FILE_FOLDER = 'upload/account/badges/';
  18. const EMPLOYER_TYPE_HOSPITAL = 0;
  19. const EMPLOYER_TYPE_SUPERMARKET = 1;
  20. const EMPLOYER_TYPE_FIRE_DEPARTMENT = 2;
  21. const EMPLOYER_TYPES = [
  22. self::EMPLOYER_TYPE_HOSPITAL => 'Hospital',
  23. self::EMPLOYER_TYPE_SUPERMARKET => 'Supermarket',
  24. self::EMPLOYER_TYPE_FIRE_DEPARTMENT => 'Fire department',
  25. ];
  26. const BADGE_PROOF_PICTURE_SETTER = 'setBadgeProofPicture';
  27. /**
  28. * @var int
  29. */
  30. #[ORM\Column(name: 'id', type: 'integer')]
  31. #[ORM\Id]
  32. #[ORM\GeneratedValue(strategy: 'AUTO')]
  33. private $id;
  34. /**
  35. * @var string
  36. */
  37. #[ORM\Column(name: 'title', type: 'string', length: 255)]
  38. private $title;
  39. /**
  40. * @var DateTime
  41. */
  42. #[ORM\Column(name: 'birth_date', type: 'date', nullable: true)]
  43. private $birthDate;
  44. /**
  45. * @var string
  46. */
  47. #[ORM\Column(name: 'name', type: 'string', length: 255)]
  48. private $name;
  49. /**
  50. * @var string
  51. */
  52. #[ORM\Column(name: 'phone', type: 'string', length: 20)]
  53. private $phone;
  54. /**
  55. * @var string
  56. */
  57. #[ORM\Column(name: 'email', type: 'string', length: 255, nullable: true)]
  58. private $email;
  59. /**
  60. * @var string
  61. */
  62. #[ORM\Column(name: 'department', type: 'string', length: 255, nullable: true)]
  63. private $department;
  64. /**
  65. * @var string
  66. */
  67. #[ORM\Column(name: 'job_title', type: 'string', length: 255, nullable: true)]
  68. private $jobTitle;
  69. /**
  70. * @var string
  71. */
  72. #[ORM\Column(name: 'ba_address1', type: 'string', length: 255, nullable: true)]
  73. private $baAddress1;
  74. /**
  75. * @var string
  76. */
  77. #[ORM\Column(name: 'ba_address2', type: 'string', length: 255, nullable: true)]
  78. private $baAddress2;
  79. /**
  80. * @var string
  81. */
  82. #[ORM\Column(name: 'ba_door_number', type: 'string', length: 255, nullable: true)]
  83. private $baDoorNumber;
  84. /**
  85. * @var string
  86. */
  87. #[ORM\Column(name: 'ba_store_apt', type: 'string', length: 255, nullable: true)]
  88. private $baStoreApt;
  89. /**
  90. * @var string
  91. */
  92. #[ORM\Column(name: 'ba_city', type: 'string', length: 255, nullable: true)]
  93. private $baCity;
  94. /**
  95. * @var string
  96. */
  97. #[ORM\Column(name: 'ba_postcode', type: 'string', length: 255, nullable: true)]
  98. private $baPostcode;
  99. /**
  100. * @var string
  101. */
  102. #[ORM\Column(name: 'ba_country', type: 'string', length: 255, nullable: true)]
  103. private $baCountry;
  104. /**
  105. * @var string
  106. */
  107. #[ORM\Column(name: 'picture', type: 'string', length: 255, nullable: true)]
  108. private $picture;
  109. /**
  110. * @var UploadedFile
  111. */
  112. #[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
  113. private $pictureFile;
  114. /**
  115. * @var string
  116. */
  117. #[ORM\Column(name: 'notes', type: 'text', nullable: true)]
  118. private $notes;
  119. /**
  120. * @var float
  121. */
  122. #[ORM\Column(name: 'credit', type: 'float', nullable: true)]
  123. private $credit;
  124. /**
  125. * @var DateTime
  126. */
  127. #[ORM\Column(name: 'creation_date', type: 'datetime')]
  128. private $creationDate;
  129. /**
  130. * @var DateTime
  131. */
  132. #[ORM\Column(name: 'updated', type: 'datetime')]
  133. protected $updated;
  134. /**
  135. * @var GroupAccounts
  136. */
  137. #[ORM\JoinColumn(name: 'group_account_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
  138. #[ORM\ManyToOne(targetEntity: \GroupAccounts::class, inversedBy: 'accounts')]
  139. private $group;
  140. /**
  141. * @var Company
  142. */
  143. #[ORM\JoinColumn(name: 'company_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
  144. #[ORM\ManyToOne(targetEntity: \Company::class, inversedBy: 'accounts')]
  145. private $company;
  146. /**
  147. * @var User
  148. */
  149. #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
  150. #[ORM\OneToOne(targetEntity: \User::class, inversedBy: 'account', cascade: ['all'])]
  151. protected $user;
  152. /**
  153. * @var ClientInvoices
  154. */
  155. #[ORM\OneToMany(targetEntity: \AdminBundle\Entity\ClientInvoices::class, mappedBy: 'client', cascade: ['persist', 'remove'], orphanRemoval: true)]
  156. protected $clientInvoices;
  157. /**
  158. * @var string
  159. */
  160. #[ORM\Column(name: 'employer_name', type: 'string', length: 255, nullable: true)]
  161. protected $employerName;
  162. /**
  163. * @var string
  164. */
  165. #[ORM\Column(name: 'employer_phone', type: 'string', length: 255, nullable: true)]
  166. protected $employerPhone;
  167. /**
  168. * @var string
  169. */
  170. #[ORM\Column(name: 'employer_type', type: 'integer', length: 255, nullable: true)]
  171. protected $employerType;
  172. /**
  173. * @var string
  174. */
  175. #[ORM\Column(name: 'workplace_postcode', type: 'string', length: 255, nullable: true)]
  176. protected $workplacePostcode;
  177. /**
  178. * @var string
  179. */
  180. #[ORM\Column(name: 'badge_proof_picture', type: 'string', length: 255, nullable: true)]
  181. private $badgeProofPicture;
  182. /**
  183. * @var UploadedFile
  184. */
  185. #[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
  186. private $badgeProofPictureFile;
  187. /**
  188. * @var string
  189. */
  190. #[ORM\Column(name: 'worker_voucher_usage', type: 'integer', length: 255, nullable: true)]
  191. protected $workerVoucherUsage;
  192. /**
  193. * @var DateTime
  194. */
  195. #[ORM\Column(name: 'last_used_worker_voucher', type: 'datetime', nullable: true)]
  196. protected $lastUsedWorkerVoucher;
  197. public function __construct()
  198. {
  199. $this->creationDate = new DateTime();
  200. $this->updated = new DateTime();
  201. $this->clientInvoices = new ArrayCollection();
  202. $this->credit = 0;
  203. $this->workerVoucherUsage = 0;
  204. }
  205. /**
  206. * @return GroupAccounts
  207. */
  208. public function getGroup()
  209. {
  210. return $this->group;
  211. }
  212. /**
  213. * @param GroupAccounts $group
  214. * @return Account
  215. */
  216. public function setGroup($group)
  217. {
  218. $this->group = $group;
  219. return $this;
  220. }
  221. /**
  222. * @return Company
  223. */
  224. public function getCompany()
  225. {
  226. return $this->company;
  227. }
  228. /**
  229. * @param Company $company
  230. * @return Account
  231. */
  232. public function setCompany($company)
  233. {
  234. $this->company = $company;
  235. return $this;
  236. }
  237. /**
  238. * @return UploadedFile|null
  239. */
  240. public function getPictureFile()
  241. {
  242. return $this->pictureFile;
  243. }
  244. /**
  245. * @param UploadedFile $pictureFile
  246. * @return $this
  247. */
  248. public function setPictureFile($pictureFile)
  249. {
  250. $this->pictureFile = $pictureFile;
  251. $this->setUpdated(new DateTime());
  252. return $this;
  253. }
  254. /**
  255. * @return DateTime
  256. */
  257. public function getUpdated()
  258. {
  259. return $this->updated;
  260. }
  261. /**
  262. * @param DateTime $updated
  263. */
  264. public function setUpdated($updated)
  265. {
  266. $this->updated = $updated;
  267. return $this;
  268. }
  269. /**
  270. * Get id
  271. *
  272. * @return int
  273. */
  274. public function getId()
  275. {
  276. return $this->id;
  277. }
  278. /**
  279. * Set title
  280. *
  281. * @param string $title
  282. *
  283. * @return Account
  284. */
  285. public function setTitle($title)
  286. {
  287. $this->title = $title;
  288. return $this;
  289. }
  290. /**
  291. * Get title
  292. *
  293. * @return string
  294. */
  295. public function getTitle()
  296. {
  297. return $this->title;
  298. }
  299. /**
  300. * Set birthDate
  301. *
  302. * @param DateTime $birthDate
  303. *
  304. * @return Account
  305. */
  306. public function setBirthDate($birthDate)
  307. {
  308. $this->birthDate = $birthDate;
  309. return $this;
  310. }
  311. /**
  312. * Get birthDate
  313. *
  314. * @return DateTime
  315. */
  316. public function getBirthDate()
  317. {
  318. return $this->birthDate;
  319. }
  320. /**
  321. * Set name
  322. *
  323. * @param string $name
  324. *
  325. * @return Account
  326. */
  327. public function setName($name)
  328. {
  329. $this->name = $name;
  330. return $this;
  331. }
  332. /**
  333. * Get name
  334. *
  335. * @return string
  336. */
  337. public function getName()
  338. {
  339. return $this->name;
  340. }
  341. /**
  342. * Set phone
  343. *
  344. * @param string $phone
  345. *
  346. * @return Account
  347. */
  348. public function setPhone($phone)
  349. {
  350. $this->phone = $phone;
  351. return $this;
  352. }
  353. /**
  354. * Get phone
  355. *
  356. * @return string
  357. */
  358. public function getPhone()
  359. {
  360. return $this->phone;
  361. }
  362. /**
  363. * Set email
  364. *
  365. * @param string $email
  366. *
  367. * @return Account
  368. */
  369. public function setEmail($email)
  370. {
  371. $this->email = $email;
  372. return $this;
  373. }
  374. /**
  375. * Get email
  376. *
  377. * @return string
  378. */
  379. public function getEmail()
  380. {
  381. return $this->email;
  382. }
  383. /**
  384. * Set department
  385. *
  386. * @param string $department
  387. *
  388. * @return Account
  389. */
  390. public function setDepartment($department)
  391. {
  392. $this->department = $department;
  393. return $this;
  394. }
  395. /**
  396. * Get department
  397. *
  398. * @return string
  399. */
  400. public function getDepartment()
  401. {
  402. return $this->department;
  403. }
  404. /**
  405. * Set jobTitle
  406. *
  407. * @param string $jobTitle
  408. *
  409. * @return Account
  410. */
  411. public function setJobTitle($jobTitle)
  412. {
  413. $this->jobTitle = $jobTitle;
  414. return $this;
  415. }
  416. /**
  417. * Get jobTitle
  418. *
  419. * @return string
  420. */
  421. public function getJobTitle()
  422. {
  423. return $this->jobTitle;
  424. }
  425. /**
  426. * Set baAddress1
  427. *
  428. * @param string $baAddress1
  429. *
  430. * @return Account
  431. */
  432. public function setBaAddress1($baAddress1)
  433. {
  434. $this->baAddress1 = $baAddress1;
  435. return $this;
  436. }
  437. /**
  438. * Get baAddress1
  439. *
  440. * @return string
  441. */
  442. public function getBaAddress1()
  443. {
  444. return $this->baAddress1;
  445. }
  446. /**
  447. * Set baAddress2
  448. *
  449. * @param string $baAddress2
  450. *
  451. * @return Account
  452. */
  453. public function setBaAddress2($baAddress2)
  454. {
  455. $this->baAddress2 = $baAddress2;
  456. return $this;
  457. }
  458. /**
  459. * Get baAddress2
  460. *
  461. * @return string
  462. */
  463. public function getBaAddress2()
  464. {
  465. return $this->baAddress2;
  466. }
  467. /**
  468. * Set baDoorNumber
  469. *
  470. * @param string $baDoorNumber
  471. *
  472. * @return Account
  473. */
  474. public function setBaDoorNumber($baDoorNumber)
  475. {
  476. $this->baDoorNumber = $baDoorNumber;
  477. return $this;
  478. }
  479. /**
  480. * Get baDoorNumber
  481. *
  482. * @return string
  483. */
  484. public function getBaDoorNumber()
  485. {
  486. return $this->baDoorNumber;
  487. }
  488. /**
  489. * Set baStoreApt
  490. *
  491. * @param string $baStoreApt
  492. *
  493. * @return Account
  494. */
  495. public function setBaStoreApt($baStoreApt)
  496. {
  497. $this->baStoreApt = $baStoreApt;
  498. return $this;
  499. }
  500. /**
  501. * Get baStoreApt
  502. *
  503. * @return string
  504. */
  505. public function getBaStoreApt()
  506. {
  507. return $this->baStoreApt;
  508. }
  509. /**
  510. * Set baCity
  511. *
  512. * @param string $baCity
  513. *
  514. * @return Account
  515. */
  516. public function setBaCity($baCity)
  517. {
  518. $this->baCity = $baCity;
  519. return $this;
  520. }
  521. /**
  522. * Get baCity
  523. *
  524. * @return string
  525. */
  526. public function getBaCity()
  527. {
  528. return $this->baCity;
  529. }
  530. /**
  531. * Set baPostcode
  532. *
  533. * @param string $baPostcode
  534. *
  535. * @return Account
  536. */
  537. public function setBaPostcode($baPostcode)
  538. {
  539. $this->baPostcode = $baPostcode;
  540. return $this;
  541. }
  542. /**
  543. * Get baPostcode
  544. *
  545. * @return string
  546. */
  547. public function getBaPostcode()
  548. {
  549. return $this->baPostcode;
  550. }
  551. /**
  552. * Set baCountry
  553. *
  554. * @param string $baCountry
  555. *
  556. * @return Account
  557. */
  558. public function setBaCountry($baCountry)
  559. {
  560. $this->baCountry = $baCountry;
  561. return $this;
  562. }
  563. /**
  564. * Get baCountry
  565. *
  566. * @return string
  567. */
  568. public function getBaCountry()
  569. {
  570. return $this->baCountry;
  571. }
  572. /**
  573. * Set picture
  574. *
  575. * @param string $picture
  576. *
  577. * @return Account
  578. */
  579. public function setPicture($picture)
  580. {
  581. $this->picture = $picture;
  582. return $this;
  583. }
  584. /**
  585. * Get picture
  586. *
  587. * @return string
  588. */
  589. public function getPicture()
  590. {
  591. return $this->picture;
  592. }
  593. /**
  594. * Set notes
  595. *
  596. * @param string $notes
  597. *
  598. * @return Account
  599. */
  600. public function setNotes($notes)
  601. {
  602. $this->notes = $notes;
  603. return $this;
  604. }
  605. /**
  606. * Get notes
  607. *
  608. * @return string
  609. */
  610. public function getNotes()
  611. {
  612. return $this->notes;
  613. }
  614. /**
  615. * Set credit
  616. *
  617. * @param float $credit
  618. *
  619. * @return Account
  620. */
  621. public function setCredit($credit)
  622. {
  623. $this->credit = $credit;
  624. return $this;
  625. }
  626. /**
  627. * Get credit
  628. *
  629. * @return float
  630. */
  631. public function getCredit()
  632. {
  633. return empty($this->credit) ? 0 : $this->credit;
  634. }
  635. /**
  636. * Set creationDate
  637. *
  638. * @param DateTime $creationDate
  639. *
  640. * @return Account
  641. */
  642. public function setCreationDate($creationDate)
  643. {
  644. $this->creationDate = $creationDate;
  645. return $this;
  646. }
  647. /**
  648. * Get creationDate
  649. *
  650. * @return DateTime
  651. */
  652. public function getCreationDate()
  653. {
  654. return $this->creationDate;
  655. }
  656. /**
  657. * @return User
  658. */
  659. public function getUser()
  660. {
  661. return $this->user;
  662. }
  663. /**
  664. * @param User $user
  665. * @return Account
  666. */
  667. public function setUser($user)
  668. {
  669. $this->user = $user;
  670. return $this;
  671. }
  672. protected function getUploadFilePath()
  673. {
  674. return self::ACCOUNT_FILE_FOLDER . $this->getId() . '/';
  675. }
  676. public function getPicturePath()
  677. {
  678. if (!$this->picture) {
  679. return;
  680. }
  681. return $this->getUploadFilePath() . $this->picture;
  682. }
  683. public function uploadPicture()
  684. {
  685. if (null === $this->getPictureFile()) {
  686. return;
  687. }
  688. $this->removePictureFile();
  689. $filename = sha1(uniqid(mt_rand(), true));
  690. $this->picture = $filename . '.' . $this->getPictureFile()->guessExtension();
  691. $this->getPictureFile()->move(
  692. $this->getUploadFilePath(),
  693. $this->picture
  694. );
  695. $this->setPictureFile(null);
  696. }
  697. #[ORM\PreUpdate]
  698. #[ORM\PrePersist]
  699. public function lifecycleFileUpload()
  700. {
  701. $this->uploadPicture();
  702. }
  703. #[ORM\PostRemove]
  704. public function removeUpload()
  705. {
  706. $this->removePictureFile();
  707. }
  708. public function removePictureFile()
  709. {
  710. if ($pictureFile = $this->getPicturePath()) {
  711. @unlink($pictureFile);
  712. }
  713. }
  714. public function __toString()
  715. {
  716. return '[' . $this->getId() . ']' . $this->getName() . '(' . $this->getPhone() . ')';
  717. }
  718. public function getClientInvoices()
  719. {
  720. return $this->clientInvoices;
  721. }
  722. public function addClientInvoices(ClientInvoices $clientInvoices)
  723. {
  724. $this->clientInvoices->add($clientInvoices);
  725. }
  726. /**
  727. * @param string $employerName
  728. *
  729. * @return Account
  730. */
  731. public function setEmployerName($employerName)
  732. {
  733. $this->employerName = $employerName;
  734. return $this;
  735. }
  736. /**
  737. * @return string
  738. */
  739. public function getEmployerName()
  740. {
  741. return $this->employerName;
  742. }
  743. /**
  744. * @param string $employerPhone
  745. *
  746. * @return Account
  747. */
  748. public function setEmployerPhone($employerPhone)
  749. {
  750. $this->employerPhone = $employerPhone;
  751. return $this;
  752. }
  753. /**
  754. * @return string
  755. */
  756. public function getEmployerPhone()
  757. {
  758. return $this->employerPhone;
  759. }
  760. /**
  761. * @param int $employerType
  762. *
  763. * @return Account
  764. */
  765. public function setEmployerType($employerType)
  766. {
  767. $this->employerType = $employerType;
  768. return $this;
  769. }
  770. /**
  771. * @return int
  772. */
  773. public function getEmployerType()
  774. {
  775. return $this->employerType;
  776. }
  777. /**
  778. * @param string $workplacePostcode
  779. *
  780. * @return Account
  781. */
  782. public function setWorkplacePostcode($workplacePostcode)
  783. {
  784. $this->workplacePostcode = $workplacePostcode;
  785. return $this;
  786. }
  787. /**
  788. * @return string
  789. */
  790. public function getWorkplacePostcode()
  791. {
  792. return $this->workplacePostcode;
  793. }
  794. /**
  795. * @return UploadedFile|null
  796. */
  797. public function getBadgeProofPictureFile()
  798. {
  799. return $this->badgeProofPictureFile;
  800. }
  801. /**
  802. * @param UploadedFile $badgeProofPictureFile
  803. *
  804. * @return Account
  805. */
  806. public function setBadgeProofPictureFile($badgeProofPictureFile)
  807. {
  808. $this->badgeProofPictureFile = $badgeProofPictureFile;
  809. $this->setUpdated(new DateTime());
  810. return $this;
  811. }
  812. /**
  813. * @param string $badgeProofPicture
  814. *
  815. * @return Account
  816. */
  817. public function setBadgeProofPicture($badgeProofPicture)
  818. {
  819. $this->badgeProofPicture = $badgeProofPicture;
  820. return $this;
  821. }
  822. /**
  823. * @return string
  824. */
  825. public function getBadgeProofPicture()
  826. {
  827. return $this->badgeProofPicture;
  828. }
  829. public function getBadgeUploadFilePath()
  830. {
  831. return self::ACCOUNT_BADGES_FILE_FOLDER . $this->getId() . '/';
  832. }
  833. public function getBadgePicturePath()
  834. {
  835. if (!$this->badgeProofPicture) {
  836. return;
  837. }
  838. return $this->getBadgeUploadFilePath() . $this->badgeProofPicture;
  839. }
  840. public function uploadBadgePicture()
  841. {
  842. if (!$this->getBadgeProofPictureFile()) {
  843. return;
  844. }
  845. $this->removeBadgePictureFile();
  846. $filename = sha1(uniqid(mt_rand(), true));
  847. $this->badgeProofPicture = $filename . '.' . $this->getBadgeProofPictureFile()->guessExtension();
  848. $this->getBadgeProofPictureFile()->move(
  849. $this->getBadgeUploadFilePath(),
  850. $this->badgeProofPicture
  851. );
  852. $this->setBadgeProofPictureFile(null);
  853. }
  854. #[ORM\PreUpdate]
  855. #[ORM\PrePersist]
  856. public function lifecycleBadgeFileUpload()
  857. {
  858. $this->uploadBadgePicture();
  859. }
  860. #[ORM\PostRemove]
  861. public function removeBadgePictureFile()
  862. {
  863. $this->removeBadgePicture();
  864. }
  865. public function removeBadgePicture()
  866. {
  867. if ($pictureFile = $this->getBadgeUploadFilePath()) {
  868. @unlink($pictureFile);
  869. }
  870. }
  871. /**
  872. * @param int $workerVoucherUsage
  873. *
  874. * @return Account
  875. */
  876. public function setWorkerVoucherUsage($workerVoucherUsage)
  877. {
  878. $this->workerVoucherUsage = $workerVoucherUsage;
  879. return $this;
  880. }
  881. /**
  882. * @return int
  883. */
  884. public function getWorkerVoucherUsage()
  885. {
  886. return $this->workerVoucherUsage;
  887. }
  888. /**
  889. * Set lastUsedWorkerVoucher
  890. *
  891. * @param DateTime $lastUsedWorkerVoucher
  892. *
  893. * @return Account
  894. */
  895. public function setLastUsedWorkerVoucher($lastUsedWorkerVoucher)
  896. {
  897. $this->lastUsedWorkerVoucher = $lastUsedWorkerVoucher;
  898. return $this;
  899. }
  900. /**
  901. * Get lastUsedWorkerVoucher
  902. *
  903. * @return DateTime
  904. */
  905. public function getLastUsedWorkerVoucher()
  906. {
  907. return $this->lastUsedWorkerVoucher;
  908. }
  909. public static function getEmployerTypes()
  910. {
  911. $types = [];
  912. foreach (self::EMPLOYER_TYPES as $key => $type) {
  913. $types[] = ['id' => $key, 'name' => $type];
  914. }
  915. return $types;
  916. }
  917. /**
  918. * Get activityHistory
  919. *
  920. * @return Array
  921. */
  922. public static function getActivityHistory()
  923. {
  924. return [];
  925. }
  926. }