src/Entity/Customer.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Bundles\Portfolios\Entity\Portfolio;
  8. use Bundles\Settings\Entity\Settings;
  9. use Bundles\Messenger\Entity\ArticleTag;
  10. /**
  11. * @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
  12. */
  13. class Customer {
  14. public $companyTypes = [
  15. 1 => 'Entity',
  16. 2 => 'Broker',
  17. 3 => 'Bank',
  18. ];
  19. /**
  20. * @ORM\Id()
  21. * @ORM\GeneratedValue()
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\ManyToMany(targetEntity=User::class)
  27. * @ORM\JoinTable(name="customer_admins")
  28. *
  29. */
  30. private $admins;
  31. /**
  32. * @ORM\Column(type="string", length=255, nullable=true)
  33. */
  34. private $name;
  35. /**
  36. * @ORM\Column(type="string", length=255, nullable=true)
  37. */
  38. private $surname;
  39. /**
  40. * @ORM\Column(type="string", length=15, nullable=true)
  41. */
  42. private $personCode;
  43. /**
  44. * @ORM\Column(type="string", length=255)
  45. */
  46. private $companyName;
  47. /**
  48. * @ORM\Column(type="string", length=255)
  49. */
  50. private $companyCode;
  51. /**
  52. * @ORM\Column(type="datetime")
  53. */
  54. private $created;
  55. /**
  56. * @ORM\Column(type="datetime")
  57. */
  58. private $updated;
  59. /**
  60. * @ORM\Column(type="string", length=10, nullable=false)
  61. */
  62. private $functionalCurrency;
  63. /**
  64. * @ORM\Column(type="string", length=255, nullable=true)
  65. */
  66. private $companyPhone;
  67. /**
  68. * @ORM\Column(type="string", length=255, nullable=true)
  69. */
  70. private $logo;
  71. /**
  72. * @ORM\Column(type="boolean")
  73. */
  74. private $useResidualCash = false;
  75. /**
  76. * @ORM\Column(type="string", nullable=true)
  77. */
  78. private $contractSignDate = '';
  79. private $logoFile;
  80. /**
  81. * @ORM\Column(type="string")
  82. */
  83. private $licence = '';
  84. /**
  85. * @ORM\Column(type="string", nullable=true)
  86. */
  87. private $trialExpiresAt = '';
  88. /**
  89. * @return mixed
  90. */
  91. public function getLogoFile() {
  92. return $this->logoFile;
  93. }
  94. /**
  95. * @param $logoFile
  96. * @throws \Exception
  97. */
  98. public function setLogoFile($logoFile): void {
  99. $this->logoFile = $logoFile;
  100. if ($logoFile) {
  101. $this->setUpdated(new DateTime());
  102. }
  103. }
  104. /**
  105. * @ORM\OneToMany(targetEntity="App\Entity\Document", mappedBy="customer", cascade = {"persist"})
  106. */
  107. private $documents;
  108. /**
  109. * @ORM\Column(type="string", length=255, nullable=true)
  110. */
  111. private $email;
  112. /**
  113. * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="customer")
  114. */
  115. private $users;
  116. /**
  117. * @ORM\Column(type="integer", nullable=true)
  118. */
  119. private $companyType;
  120. /**
  121. * @ORM\OneToMany(targetEntity=Settings::class, mappedBy="customer")
  122. */
  123. private $settings;
  124. /**
  125. * @ORM\OneToMany(targetEntity=AnalyticsRequests::class, mappedBy="customer")
  126. */
  127. private $analyticsRequests;
  128. /**
  129. * @ORM\OneToMany(targetEntity=Portfolio::class, mappedBy="customer")
  130. */
  131. private $portfolios;
  132. /**
  133. * @ORM\OneToMany(targetEntity=Counterparty::class, mappedBy="Customer")
  134. */
  135. private $counterparties;
  136. /**
  137. * @ORM\ManyToMany(targetEntity=CurrencyPair::class)
  138. * @ORM\JoinTable(name="customer_currency_pair")
  139. *
  140. */
  141. private $currencyPairs;
  142. /**
  143. * @ORM\ManyToMany(targetEntity=ArticleTag::class)
  144. * @ORM\JoinTable(name="customer_tags")
  145. */
  146. private $tags;
  147. /**
  148. * @ORM\Column(type="boolean")
  149. */
  150. private $useRemoteApi = false;
  151. /**
  152. * @ORM\Column(type="string", length=255, nullable=true)
  153. */
  154. private $remoteSystem = '';
  155. /**
  156. * @ORM\Column(type="string", length=255, nullable=true)
  157. */
  158. private $remoteUserCode = '';
  159. /**
  160. * @ORM\Column(type="string", length=255, nullable=true)
  161. */
  162. private $remoteUserId = '';
  163. /**
  164. * @ORM\Column(type="string", length=255, nullable=true)
  165. */
  166. private $remoteUserKey = '';
  167. public function __construct() {
  168. $this->setCreated(new DateTime());
  169. $this->setUpdated(new DateTime());
  170. $this->documents = new ArrayCollection();
  171. $this->users = new ArrayCollection();
  172. $this->settings = new ArrayCollection();
  173. $this->analyticsRequests = new ArrayCollection();
  174. $this->portfolios = new ArrayCollection();
  175. $this->counterparties = new ArrayCollection();
  176. $this->currencyPairs = new ArrayCollection();
  177. $this->admins = new ArrayCollection();
  178. $this->tags = new ArrayCollection();
  179. }
  180. public function getId(): ?int {
  181. return $this->id;
  182. }
  183. public function getName(): ?string {
  184. return $this->companyName;
  185. }
  186. public function setName(string $name): self {
  187. $this->name = $name;
  188. return $this;
  189. }
  190. public function getSurname(): ?string {
  191. return $this->surname;
  192. }
  193. public function setSurname(string $surname): self {
  194. $this->surname = $surname;
  195. return $this;
  196. }
  197. public function getPersonCode(): ?string {
  198. return $this->personCode;
  199. }
  200. public function setPersonCode($personCode): self {
  201. $this->personCode = (string)$personCode;
  202. return $this;
  203. }
  204. public function getCompanyName(): ?string {
  205. return $this->companyName;
  206. }
  207. public function setCompanyName(string $companyName): self {
  208. $this->companyName = $companyName;
  209. return $this;
  210. }
  211. public function getCompanyCode(): ?string {
  212. return $this->companyCode;
  213. }
  214. public function setCompanyCode(string $companyCode): self {
  215. $this->companyCode = $companyCode;
  216. return $this;
  217. }
  218. public function getCreated(): ?\DateTimeInterface {
  219. return $this->created;
  220. }
  221. public function setCreated(\DateTimeInterface $created): self {
  222. $this->created = $created;
  223. return $this;
  224. }
  225. public function getFunctionalCurrency(): ?string {
  226. return $this->functionalCurrency;
  227. }
  228. public function setFunctionalCurrency(?string $functionalCurrency): self {
  229. $this->functionalCurrency = $functionalCurrency;
  230. return $this;
  231. }
  232. public function getCompanyPhone(): ?string {
  233. return $this->companyPhone;
  234. }
  235. public function setCompanyPhone(string $companyPhone): self {
  236. $this->companyPhone = $companyPhone;
  237. return $this;
  238. }
  239. public function getUpdated(): ?\DateTimeInterface {
  240. return $this->updated;
  241. }
  242. public function setUpdated(\DateTimeInterface $updated): self {
  243. $this->updated = $updated;
  244. return $this;
  245. }
  246. public function getLogo(): ?string {
  247. return $this->logo;
  248. }
  249. public function setLogo(?string $logo): self {
  250. $this->logo = $logo;
  251. return $this;
  252. }
  253. public function __toString() {
  254. return $this->companyName;
  255. }
  256. /**
  257. * @return Collection|Document[]
  258. */
  259. public function getDocuments(): Collection {
  260. return $this->documents;
  261. }
  262. public function unsetDocuments(): self {
  263. $this->documents = null;
  264. return $this;
  265. }
  266. public function addDocument(Document $document): self {
  267. if (!$this->documents->contains($document)) {
  268. $this->documents[] = $document;
  269. $document->setCustomer($this);
  270. }
  271. return $this;
  272. }
  273. public function removeDocument(Document $document): self {
  274. if ($this->documents->contains($document)) {
  275. $this->documents->removeElement($document);
  276. // set the owning side to null (unless already changed)
  277. if ($document->getCustomer() === $this) {
  278. $document->setCustomer(null);
  279. }
  280. }
  281. return $this;
  282. }
  283. public function getEmail(): ?string {
  284. return $this->email;
  285. }
  286. public function setEmail(?string $email): self {
  287. $this->email = $email;
  288. return $this;
  289. }
  290. /**
  291. * @return Collection|User[]
  292. */
  293. public function getUsers(): Collection {
  294. return $this->users;
  295. }
  296. public function addUser(User $user): self {
  297. if (!$this->users->contains($user)) {
  298. $this->users[] = $user;
  299. $user->setCustomer($this);
  300. }
  301. return $this;
  302. }
  303. public function removeUser(User $user): self {
  304. if ($this->users->contains($user)) {
  305. $this->users->removeElement($user);
  306. // set the owning side to null (unless already changed)
  307. if ($user->getCustomer() === $this) {
  308. $user->setCustomer(null);
  309. }
  310. }
  311. return $this;
  312. }
  313. public function getCompanyType(): ?int {
  314. return $this->companyType;
  315. }
  316. public function setCompanyType($companyType): self {
  317. $this->companyType = (int)$companyType;
  318. return $this;
  319. }
  320. public function getCompanyTypeName() {
  321. if (!isset($this->companyType)) {
  322. $this->companyType = 0;
  323. }
  324. return $this->companyTypes[$this->companyType];
  325. }
  326. /**
  327. * @return Collection|Settings[]
  328. */
  329. public function getSettings(): Collection {
  330. return $this->settings;
  331. }
  332. public function addSetting(Settings $setting): self {
  333. if (!$this->settings->contains($setting)) {
  334. $this->settings[] = $setting;
  335. $setting->setCustomer($this);
  336. }
  337. return $this;
  338. }
  339. public function removeSetting(Settings $setting): self {
  340. if ($this->settings->contains($setting)) {
  341. $this->settings->removeElement($setting);
  342. // set the owning side to null (unless already changed)
  343. if ($setting->getCustomer() === $this) {
  344. $setting->setCustomer(null);
  345. }
  346. }
  347. return $this;
  348. }
  349. /**
  350. * @return Collection|AnalyticsRequests[]
  351. */
  352. public function getAnalyticsRequests(): Collection {
  353. return $this->analyticsRequests;
  354. }
  355. public function addAnalyticsRequest(AnalyticsRequests $analyticsRequest): self {
  356. if (!$this->analyticsRequests->contains($analyticsRequest)) {
  357. $this->analyticsRequests[] = $analyticsRequest;
  358. $analyticsRequest->setCustomer($this);
  359. }
  360. return $this;
  361. }
  362. public function removeAnalyticsRequest(AnalyticsRequests $analyticsRequest): self {
  363. if ($this->analyticsRequests->removeElement($analyticsRequest)) {
  364. // set the owning side to null (unless already changed)
  365. if ($analyticsRequest->getCustomer() === $this) {
  366. $analyticsRequest->setCustomer(null);
  367. }
  368. }
  369. return $this;
  370. }
  371. /**
  372. * @return Collection|Portfolio[]
  373. */
  374. public function getPortfolios(): Collection {
  375. return $this->portfolios;
  376. }
  377. public function addAnalyticsPortfolio(Portfolio $analyticsPortfolio): self {
  378. if (!$this->portfolios->contains($analyticsPortfolio)) {
  379. $this->portfolios[] = $analyticsPortfolio;
  380. $analyticsPortfolio->setCustomer($this);
  381. }
  382. return $this;
  383. }
  384. public function removeAnalyticsPortfolio(Portfolio $analyticsPortfolio): self {
  385. if ($this->portfolios->removeElement($analyticsPortfolio)) {
  386. // set the owning side to null (unless already changed)
  387. if ($analyticsPortfolio->getCustomer() === $this) {
  388. $analyticsPortfolio->setCustomer(null);
  389. }
  390. }
  391. return $this;
  392. }
  393. /**
  394. * @return Collection<int, Counterparty>
  395. */
  396. public function getCounterparties(): Collection {
  397. return $this->counterparties;
  398. }
  399. public function addCounterparty(Counterparty $counterparty): self {
  400. if (!$this->counterparties->contains($counterparty)) {
  401. $this->counterparties[] = $counterparty;
  402. $counterparty->setCustomer($this);
  403. }
  404. return $this;
  405. }
  406. public function removeCounterparty(Counterparty $counterparty): self {
  407. if ($this->counterparties->removeElement($counterparty)) {
  408. // set the owning side to null (unless already changed)
  409. if ($counterparty->getCustomer() === $this) {
  410. $counterparty->setCustomer(null);
  411. }
  412. }
  413. return $this;
  414. }
  415. /**
  416. * @return Collection<int, CurrencyPair>
  417. */
  418. public function getCurrencyPairs(): Collection {
  419. return $this->currencyPairs;
  420. }
  421. public function addCurrencyPair(CurrencyPair $currencyPair): self {
  422. if (!$this->currencyPairs->contains($currencyPair)) {
  423. $this->currencyPairs[] = $currencyPair;
  424. }
  425. return $this;
  426. }
  427. public function removeCurrencyPair(CurrencyPair $currencyPair): self {
  428. $this->currencyPairs->removeElement($currencyPair);
  429. return $this;
  430. }
  431. public function getTags(): Collection {
  432. return $this->tags;
  433. }
  434. public function setTags(?ArticleTag $tags): self {
  435. if (!$this->tags->contains($tags)) {
  436. $this->tags[] = $tags;
  437. }
  438. return $this;
  439. }
  440. /**
  441. * @return bool
  442. */
  443. public function isUseResidualCash(): bool {
  444. return $this->useResidualCash;
  445. }
  446. /**
  447. * @param bool $useResidualCash
  448. */
  449. public function setUseResidualCash(bool $useResidualCash): void {
  450. $this->useResidualCash = $useResidualCash;
  451. }
  452. /**
  453. * @return string
  454. */
  455. public function getContractSignDate() {
  456. return $this->contractSignDate;
  457. }
  458. /**
  459. * @param string $contractSignDate
  460. */
  461. public function setContractSignDate($contractSignDate): void {
  462. $this->contractSignDate = $contractSignDate;
  463. }
  464. public function getLicence() {
  465. return $this->licence;
  466. }
  467. public function setLicence($licence): void {
  468. $this->licence = $licence;
  469. }
  470. public function getTrialExpiresAt(): ?string {
  471. return $this->trialExpiresAt;
  472. }
  473. public function setTrialExpiresAt($trialExpiresAt): void {
  474. $this->trialExpiresAt = $trialExpiresAt;
  475. }
  476. /**
  477. * @return Collection<int, User>
  478. */
  479. public function getAdmins(): Collection {
  480. return $this->admins;
  481. }
  482. public function addAdmins(User $admin): self {
  483. if (!$this->admins->contains($admin)) {
  484. $this->admins[] = $admin;
  485. }
  486. return $this;
  487. }
  488. public function removeAdmins(User $admin): self {
  489. $this->admins->removeElement($admin);
  490. return $this;
  491. }
  492. public function isUseRemoteApi(): ?bool {
  493. return $this->useRemoteApi;
  494. }
  495. public function setUseRemoteApi(bool $useRemoteApi): void {
  496. $this->useRemoteApi = $useRemoteApi;
  497. }
  498. public function getRemoteSystem() {
  499. return $this->remoteSystem;
  500. }
  501. public function setRemoteSystem($remoteSystem): void {
  502. $this->remoteSystem = $remoteSystem;
  503. }
  504. public function getRemoteUserCode(): ?string {
  505. return $this->remoteUserCode;
  506. }
  507. public function setRemoteUserCode($remoteUserCode): void {
  508. $this->remoteUserCode = $remoteUserCode;
  509. }
  510. public function getRemoteUserId(): ?string {
  511. return $this->remoteUserId;
  512. }
  513. public function setRemoteUserId($remoteUserId): void {
  514. $this->remoteUserId = $remoteUserId;
  515. }
  516. public function getRemoteUserKey(): ?string {
  517. return $this->remoteUserKey;
  518. }
  519. public function setRemoteUserKey($remoteUserKey): self
  520. {
  521. $this->remoteUserKey = $remoteUserKey;
  522. return $this;
  523. }
  524. public function getEncryptedKey(string $encryptionKey): ?string
  525. {
  526. return $this->encrypt($this->getRemoteUserKey(), $encryptionKey);
  527. }
  528. public function getDecryptedKey(string $encryptionKey): ?string
  529. {
  530. return $this->decrypt($this->getRemoteUserKey(), $encryptionKey);
  531. }
  532. private function encrypt(string $data, string $key): string
  533. {
  534. return base64_encode(openssl_encrypt($data, 'aes-256-cbc', $key, 0, substr(hash('sha256', $key), 0, 16)));
  535. }
  536. private function decrypt(string $data, string $key): ?string
  537. {
  538. return openssl_decrypt(base64_decode($data), 'aes-256-cbc', $key, 0, substr(hash('sha256', $key), 0, 16));
  539. }
  540. }