<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Bundles\Portfolios\Entity\Portfolio;
use Bundles\Settings\Entity\Settings;
use Bundles\Messenger\Entity\ArticleTag;
/**
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
*/
class Customer {
public $companyTypes = [
1 => 'Entity',
2 => 'Broker',
3 => 'Bank',
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="customer_admins")
*
*/
private $admins;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $surname;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $personCode;
/**
* @ORM\Column(type="string", length=255)
*/
private $companyName;
/**
* @ORM\Column(type="string", length=255)
*/
private $companyCode;
/**
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @ORM\Column(type="string", length=10, nullable=false)
*/
private $functionalCurrency;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $companyPhone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $logo;
/**
* @ORM\Column(type="boolean")
*/
private $useResidualCash = false;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $contractSignDate = '';
private $logoFile;
/**
* @ORM\Column(type="string")
*/
private $licence = '';
/**
* @ORM\Column(type="string", nullable=true)
*/
private $trialExpiresAt = '';
/**
* @return mixed
*/
public function getLogoFile() {
return $this->logoFile;
}
/**
* @param $logoFile
* @throws \Exception
*/
public function setLogoFile($logoFile): void {
$this->logoFile = $logoFile;
if ($logoFile) {
$this->setUpdated(new DateTime());
}
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\Document", mappedBy="customer", cascade = {"persist"})
*/
private $documents;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="customer")
*/
private $users;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $companyType;
/**
* @ORM\OneToMany(targetEntity=Settings::class, mappedBy="customer")
*/
private $settings;
/**
* @ORM\OneToMany(targetEntity=AnalyticsRequests::class, mappedBy="customer")
*/
private $analyticsRequests;
/**
* @ORM\OneToMany(targetEntity=Portfolio::class, mappedBy="customer")
*/
private $portfolios;
/**
* @ORM\OneToMany(targetEntity=Counterparty::class, mappedBy="Customer")
*/
private $counterparties;
/**
* @ORM\ManyToMany(targetEntity=CurrencyPair::class)
* @ORM\JoinTable(name="customer_currency_pair")
*
*/
private $currencyPairs;
/**
* @ORM\ManyToMany(targetEntity=ArticleTag::class)
* @ORM\JoinTable(name="customer_tags")
*/
private $tags;
/**
* @ORM\Column(type="boolean")
*/
private $useRemoteApi = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $remoteSystem = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $remoteUserCode = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $remoteUserId = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $remoteUserKey = '';
public function __construct() {
$this->setCreated(new DateTime());
$this->setUpdated(new DateTime());
$this->documents = new ArrayCollection();
$this->users = new ArrayCollection();
$this->settings = new ArrayCollection();
$this->analyticsRequests = new ArrayCollection();
$this->portfolios = new ArrayCollection();
$this->counterparties = new ArrayCollection();
$this->currencyPairs = new ArrayCollection();
$this->admins = new ArrayCollection();
$this->tags = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
public function getName(): ?string {
return $this->companyName;
}
public function setName(string $name): self {
$this->name = $name;
return $this;
}
public function getSurname(): ?string {
return $this->surname;
}
public function setSurname(string $surname): self {
$this->surname = $surname;
return $this;
}
public function getPersonCode(): ?string {
return $this->personCode;
}
public function setPersonCode($personCode): self {
$this->personCode = (string)$personCode;
return $this;
}
public function getCompanyName(): ?string {
return $this->companyName;
}
public function setCompanyName(string $companyName): self {
$this->companyName = $companyName;
return $this;
}
public function getCompanyCode(): ?string {
return $this->companyCode;
}
public function setCompanyCode(string $companyCode): self {
$this->companyCode = $companyCode;
return $this;
}
public function getCreated(): ?\DateTimeInterface {
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self {
$this->created = $created;
return $this;
}
public function getFunctionalCurrency(): ?string {
return $this->functionalCurrency;
}
public function setFunctionalCurrency(?string $functionalCurrency): self {
$this->functionalCurrency = $functionalCurrency;
return $this;
}
public function getCompanyPhone(): ?string {
return $this->companyPhone;
}
public function setCompanyPhone(string $companyPhone): self {
$this->companyPhone = $companyPhone;
return $this;
}
public function getUpdated(): ?\DateTimeInterface {
return $this->updated;
}
public function setUpdated(\DateTimeInterface $updated): self {
$this->updated = $updated;
return $this;
}
public function getLogo(): ?string {
return $this->logo;
}
public function setLogo(?string $logo): self {
$this->logo = $logo;
return $this;
}
public function __toString() {
return $this->companyName;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection {
return $this->documents;
}
public function unsetDocuments(): self {
$this->documents = null;
return $this;
}
public function addDocument(Document $document): self {
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setCustomer($this);
}
return $this;
}
public function removeDocument(Document $document): self {
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
// set the owning side to null (unless already changed)
if ($document->getCustomer() === $this) {
$document->setCustomer(null);
}
}
return $this;
}
public function getEmail(): ?string {
return $this->email;
}
public function setEmail(?string $email): self {
$this->email = $email;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection {
return $this->users;
}
public function addUser(User $user): self {
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setCustomer($this);
}
return $this;
}
public function removeUser(User $user): self {
if ($this->users->contains($user)) {
$this->users->removeElement($user);
// set the owning side to null (unless already changed)
if ($user->getCustomer() === $this) {
$user->setCustomer(null);
}
}
return $this;
}
public function getCompanyType(): ?int {
return $this->companyType;
}
public function setCompanyType($companyType): self {
$this->companyType = (int)$companyType;
return $this;
}
public function getCompanyTypeName() {
if (!isset($this->companyType)) {
$this->companyType = 0;
}
return $this->companyTypes[$this->companyType];
}
/**
* @return Collection|Settings[]
*/
public function getSettings(): Collection {
return $this->settings;
}
public function addSetting(Settings $setting): self {
if (!$this->settings->contains($setting)) {
$this->settings[] = $setting;
$setting->setCustomer($this);
}
return $this;
}
public function removeSetting(Settings $setting): self {
if ($this->settings->contains($setting)) {
$this->settings->removeElement($setting);
// set the owning side to null (unless already changed)
if ($setting->getCustomer() === $this) {
$setting->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|AnalyticsRequests[]
*/
public function getAnalyticsRequests(): Collection {
return $this->analyticsRequests;
}
public function addAnalyticsRequest(AnalyticsRequests $analyticsRequest): self {
if (!$this->analyticsRequests->contains($analyticsRequest)) {
$this->analyticsRequests[] = $analyticsRequest;
$analyticsRequest->setCustomer($this);
}
return $this;
}
public function removeAnalyticsRequest(AnalyticsRequests $analyticsRequest): self {
if ($this->analyticsRequests->removeElement($analyticsRequest)) {
// set the owning side to null (unless already changed)
if ($analyticsRequest->getCustomer() === $this) {
$analyticsRequest->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|Portfolio[]
*/
public function getPortfolios(): Collection {
return $this->portfolios;
}
public function addAnalyticsPortfolio(Portfolio $analyticsPortfolio): self {
if (!$this->portfolios->contains($analyticsPortfolio)) {
$this->portfolios[] = $analyticsPortfolio;
$analyticsPortfolio->setCustomer($this);
}
return $this;
}
public function removeAnalyticsPortfolio(Portfolio $analyticsPortfolio): self {
if ($this->portfolios->removeElement($analyticsPortfolio)) {
// set the owning side to null (unless already changed)
if ($analyticsPortfolio->getCustomer() === $this) {
$analyticsPortfolio->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, Counterparty>
*/
public function getCounterparties(): Collection {
return $this->counterparties;
}
public function addCounterparty(Counterparty $counterparty): self {
if (!$this->counterparties->contains($counterparty)) {
$this->counterparties[] = $counterparty;
$counterparty->setCustomer($this);
}
return $this;
}
public function removeCounterparty(Counterparty $counterparty): self {
if ($this->counterparties->removeElement($counterparty)) {
// set the owning side to null (unless already changed)
if ($counterparty->getCustomer() === $this) {
$counterparty->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, CurrencyPair>
*/
public function getCurrencyPairs(): Collection {
return $this->currencyPairs;
}
public function addCurrencyPair(CurrencyPair $currencyPair): self {
if (!$this->currencyPairs->contains($currencyPair)) {
$this->currencyPairs[] = $currencyPair;
}
return $this;
}
public function removeCurrencyPair(CurrencyPair $currencyPair): self {
$this->currencyPairs->removeElement($currencyPair);
return $this;
}
public function getTags(): Collection {
return $this->tags;
}
public function setTags(?ArticleTag $tags): self {
if (!$this->tags->contains($tags)) {
$this->tags[] = $tags;
}
return $this;
}
/**
* @return bool
*/
public function isUseResidualCash(): bool {
return $this->useResidualCash;
}
/**
* @param bool $useResidualCash
*/
public function setUseResidualCash(bool $useResidualCash): void {
$this->useResidualCash = $useResidualCash;
}
/**
* @return string
*/
public function getContractSignDate() {
return $this->contractSignDate;
}
/**
* @param string $contractSignDate
*/
public function setContractSignDate($contractSignDate): void {
$this->contractSignDate = $contractSignDate;
}
public function getLicence() {
return $this->licence;
}
public function setLicence($licence): void {
$this->licence = $licence;
}
public function getTrialExpiresAt(): ?string {
return $this->trialExpiresAt;
}
public function setTrialExpiresAt($trialExpiresAt): void {
$this->trialExpiresAt = $trialExpiresAt;
}
/**
* @return Collection<int, User>
*/
public function getAdmins(): Collection {
return $this->admins;
}
public function addAdmins(User $admin): self {
if (!$this->admins->contains($admin)) {
$this->admins[] = $admin;
}
return $this;
}
public function removeAdmins(User $admin): self {
$this->admins->removeElement($admin);
return $this;
}
public function isUseRemoteApi(): ?bool {
return $this->useRemoteApi;
}
public function setUseRemoteApi(bool $useRemoteApi): void {
$this->useRemoteApi = $useRemoteApi;
}
public function getRemoteSystem() {
return $this->remoteSystem;
}
public function setRemoteSystem($remoteSystem): void {
$this->remoteSystem = $remoteSystem;
}
public function getRemoteUserCode(): ?string {
return $this->remoteUserCode;
}
public function setRemoteUserCode($remoteUserCode): void {
$this->remoteUserCode = $remoteUserCode;
}
public function getRemoteUserId(): ?string {
return $this->remoteUserId;
}
public function setRemoteUserId($remoteUserId): void {
$this->remoteUserId = $remoteUserId;
}
public function getRemoteUserKey(): ?string {
return $this->remoteUserKey;
}
public function setRemoteUserKey($remoteUserKey): self
{
$this->remoteUserKey = $remoteUserKey;
return $this;
}
public function getEncryptedKey(string $encryptionKey): ?string
{
return $this->encrypt($this->getRemoteUserKey(), $encryptionKey);
}
public function getDecryptedKey(string $encryptionKey): ?string
{
return $this->decrypt($this->getRemoteUserKey(), $encryptionKey);
}
private function encrypt(string $data, string $key): string
{
return base64_encode(openssl_encrypt($data, 'aes-256-cbc', $key, 0, substr(hash('sha256', $key), 0, 16)));
}
private function decrypt(string $data, string $key): ?string
{
return openssl_decrypt(base64_decode($data), 'aes-256-cbc', $key, 0, substr(hash('sha256', $key), 0, 16));
}
}