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