<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use SpecShaper\EncryptBundle\Annotations\Encrypted;
use Doctrine\Common\Collections\Criteria;
use App\Entity\CompanyLocation;
use App\Entity\CompanyVariable;
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Company
{
/*
* @Groups({"searchable"})
*/
private $urlName;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=170, unique=true)
* @Groups({"searchable"})
*/
private $name;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Image")
*/
private $image;
/**
* @ORM\OnetoOne(targetEntity="App\Entity\Image")
*/
private $banner;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $website;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"searchable"})
*/
private $description;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"searchable"})
*/
private $speciality;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $averageDeliveryTime=0;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="adminOfCompanies")
*/
private $usersAdmin;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="company", cascade={"remove"})
*/
private $products;
/**
* @ORM\OneToOne(targetEntity="App\Entity\CompanyLocation", cascade={"persist", "remove"})
* @Groups({"searchable"})
*/
private $mainLocation;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CompanyLocation", mappedBy="company", cascade={"persist", "remove"})
*/
private $otherLocations;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $taxeTPS;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $taxeTVX;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $companyNumber;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $numberOfSales=0;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $totalSalesInDollars=0;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CompanyPayment", mappedBy="company", orphanRemoval=true, cascade={"persist"})
*/
private $payments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CompanySubscription", mappedBy="company", orphanRemoval=true)
*/
private $subscriptions;
/**
* @ORM\OneToOne(targetEntity="App\Entity\CompanyDeposit", mappedBy="company", cascade={"persist", "remove"})
*/
private $depositInfo;
/**
* @ORM\Column(type="datetime")
*/
private $dateCreated;
/**
* @ORM\OneToOne(targetEntity="App\Entity\CompanyDefaultShipping", mappedBy="company", cascade={"persist", "remove"})
*/
private $defaultShipping;
/**
* @ORM\Column(type="boolean")
*/
private $customSaleConditions=false;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $conditionsShipping;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $conditionsReturn;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $conditionsCancel;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $termsAcceptanceDate;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $termsAcceptanceIp;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $solexId;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="companyPaying", cascade={"remove"})
*/
private $transactionsPaid;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="companyReceiving", cascade={"remove"})
*/
private $transactionsReceived;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductReplenishment", mappedBy="company", orphanRemoval=true)
*/
private $productReplenishments;
/**
* @ORM\Column(type="boolean")
*/
private $storeMadeByMaturin=false;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $termsAcceptanceFingerPrint = [];
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $inventoryLastUpdate;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $showPublicly=false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomOrder", mappedBy="company")
*/
private $customOrders;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MaturinOrder", mappedBy="company")
*/
private $maturinOrders;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="company")
*/
private $invoices;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $customUrl;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Badge", mappedBy="company")
*/
private $badges;
/**
* @ORM\OneToMany(targetEntity="App\Entity\InvoiceService", mappedBy="company")
*/
private $invoiceServices;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\CompanyAssociation", mappedBy="companies")
*/
private $associations;
/**
* @ORM\Column(type="boolean")
*/
private $isAllowedToScheduleColdProduct=false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="companiesRecruited")
*/
private $recruiter;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="myGroupOfCompanies")
*/
private $inGroupOfUser;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Variable", inversedBy="companies")
*/
private $variables;
/**
* @ORM\Column(type="boolean")
*/
private $reminderStripeVerificationSent = false;
/**
* @ORM\Column(type="boolean")
*/
private $exportColabor = false;
public function __construct()
{
$this->usersAdmin= new ArrayCollection();
$this->products = new ArrayCollection();
$this->otherLocations = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->dateCreated = new \DateTime();
$this->transactionsPaid = new ArrayCollection();
$this->transactionsReceived = new ArrayCollection();
$this->productReplenishments = new ArrayCollection();
$this->customOrders = new ArrayCollection();
$this->maturinOrders = new ArrayCollection();
$this->invoices = new ArrayCollection();
$this->badges = new ArrayCollection();
$this->invoiceServices = new ArrayCollection();
$this->associations = new ArrayCollection();
$this->variables = new ArrayCollection();
}
/**
* @ORM\PrePersist
*/
public function doActionsOnPrePersist(){
/*
Executed at creation right before sending to DB
*/
if($this->getAssociations()->count() > 0)
$this->doActionsToBeAPublicMarket();
}
/**
* @ORM\PreUpdate
*/
public function doActionsOnPreUpdate(){
/*
Executed at creation right before sending to DB
*/
if($this->getAssociations()->count() > 0)
$this->doActionsToBeAPublicMarket();
else
$this->doActionsToBeRemovedFromAPublicMarket();
}
/*
Do what's needed to be a public market
*/
public function doActionsToBeAPublicMarket(){
}
/*
Do what's needed to be a out of a public market
*/
public function doActionsToBeRemovedFromAPublicMarket(){
}
public function setSpeciality($speciality)
{
$this->speciality = $speciality;
}
public function getSpeciality()
{
return $this->speciality;
}
public function setBanner($banner)
{
if(!empty($banner) || $banner == 'reset'){
if($banner == 'reset'){
$banner = null;
}
$this->banner = $banner;
}
}
public function getBanner()
{
return $this->banner;
}
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/*
* For export of the mailing list mostly in Omelo
* Having issue with export of ManyToMany Entities
*/
public function getFirstNameAdmin(): ?string
{
//In theory only those with no SUPER_ADMIN roles are true
foreach($this->getUsersAdmin() as $u){
if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
return ucfirst(strtolower($u->getFirstName()));
}
return null;
}
/*
* For export of the mailing list mostly in Omelo
* Having issue with export of ManyToMany Entities
*/
public function getLastNameAdmin(): ?string
{
//In theory only those with no SUPER_ADMIN roles are true
foreach($this->getUsersAdmin() as $u){
if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
return ucfirst(strtolower($u->getLastName()));
}
return null;
}
/*
* For export of the mailing list mostly in Omelo
* Causing issue on export of ManyToMany Entities
*/
public function getAdminEmail(): ?string
{
//In theory only those with no SUPER_ADMIN roles are true
foreach($this->getUsersAdmin() as $u){
if(!$u->isGranted('ROLE_SUPER_ADMIN') && !$u->isGranted('SUPER_ADMIN'))
return $u->getEmail();
}
return $this->getEmail();
}
public function getFullUrl(): string
{
return 'https://www.maturin.ca/'.$this->getCustomUrl();
}
/**
* @Groups({"searchable"})
*/
public function getUrlName(): ?string
{
$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', "'" => '' , '.'=> '', '!' => '', '?' => '', "'" => "");
$str = strtr( trim($this->name), $unwanted_array );
return urlencode(str_replace(' ', '-', strtolower($str)));
}
public function getImage()
{
return $this->image;
}
public function setImage($image): self
{
if(!empty($image) || $image == 'reset'){
if($image== 'reset'){
$image= null;
}
$this->image = $image;
}
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite($website): self
{
$this->website = $website;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getAverageDeliveryTime(): ?string
{
return $this->averageDeliveryTime;
}
public function setAverageDeliveryTime(string $averageDeliveryTime): self
{
$this->averageDeliveryTime = $averageDeliveryTime;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsersAdmin(): Collection
{
return $this->usersAdmin;
}
public function addUsersAdmin(User $usersAdmin): self
{
if (!$this->usersAdmin->contains($usersAdmin)) {
$this->usersAdmin[] = $usersAdmin;
}
return $this;
}
public function getAdminUsers(): Collection
{
return $this->usersAdmin;
}
public function addAdminUser(User $usersAdmin): self
{
if (!$this->usersAdmin->contains($usersAdmin)) {
$this->usersAdmin[] = $usersAdmin;
}
return $this;
}
public function removeAdminUser(User $usersAdmin): self
{
if ($this->usersAdmin->contains($usersAdmin)) {
$this->usersAdmin->removeElement($usersAdmin);
}
return $this;
}
public function removeAdminUsers(User $usersAdmin): self
{
if ($this->usersAdmin->contains($usersAdmin)) {
$this->usersAdmin->removeElement($usersAdmin);
}
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
/* Remove the draft */
$cleanProduct = new ArrayCollection();
foreach($this->products as $product){
if(!$product->getDraft())
$cleanProduct[]=$product;
}
return $cleanProduct;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCompany($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getCompany() === $this) {
$product->setCompany(null);
}
}
return $this;
}
public function flushProducts(){
$this->products = new ArrayCollection();
}
public function getMainLocation(): ?CompanyLocation
{
return $this->mainLocation;
}
public function setMainLocation(?CompanyLocation $mainLocation): self
{
$this->mainLocation = $mainLocation;
return $this;
}
/**
* @return Collection|CompanyLocation[]
*/
public function getOtherLocations(): Collection
{
return $this->otherLocations;
}
public function addOtherLocation(CompanyLocation $otherLocation): self
{
if (!$this->otherLocations->contains($otherLocation)) {
$this->otherLocations[] = $otherLocation;
$otherLocation->setCompany($this);
}
return $this;
}
public function removeOtherLocation(CompanyLocation $otherLocation): self
{
if ($this->otherLocations->contains($otherLocation)) {
$this->otherLocations->removeElement($otherLocation);
// set the owning side to null (unless already changed)
if ($otherLocation->getCompany() === $this) {
$otherLocation->setCompany(null);
}
}
return $this;
}
public function getTaxeTPS(): ?string
{
return $this->taxeTPS;
}
public function setTaxeTPS(?string $taxeTPS): self
{
$this->taxeTPS = $taxeTPS;
return $this;
}
public function getTaxeTVX(): ?string
{
return $this->taxeTVX;
}
public function setTaxeTVX(?string $taxeTVX): self
{
$this->taxeTVX = $taxeTVX;
return $this;
}
public function getCompanyNumber(): ?string
{
return $this->companyNumber;
}
public function setCompanyNumber(?string $companyNumber): self
{
$this->companyNumber = $companyNumber;
return $this;
}
public function getSaleId(): ?string
{
return $this->id + 10000;
}
public function setSaleId(?string $saleId): self
{
return $this;
}
public function getNumberOfSales(): ?int
{
return $this->numberOfSales;
}
public function setNumberOfSales(?int $numberOfSales): self
{
$this->numberOfSales = $numberOfSales;
return $this;
}
public function getTotalSalesInDollars(): ?float
{
return $this->totalSalesInDollars;
}
public function setTotalSalesInDollars(?float $totalSalesInDollars): self
{
$this->totalSalesInDollars = $totalSalesInDollars;
return $this;
}
/**
* @return Collection|CompanyPayment[]
*/
public function getpayments(): Collection
{
return $this->payments;
}
/*
* Do more throughout validation
* @TODO
*/
public function getCurrentPayment(){
if(count($this->payments) > 0)
return $this->getPayments()->last();
else
return false;
}
public function hasPayment(){
if(!empty($this->getCurrentPayment()))
return true;
else
return false;
}
/*
* Return is any products of this company is shipped by Maturin
*/
public function hasProductsShippedByMaturin(): bool
{
foreach($this->getProducts() as $p){
if($p->isShippedByMaturin())
return true;
}
return false;
}
/*
* Return if there is any inventory with our warehouses
*/
public function hasInventoryWithMaturin(): bool
{
if(!empty($this->productReplenishments) && count($this->productReplenishments) > 0)
return true;
else
return false;
}
public function addPayment(CompanyPayment $companyPayment): self
{
if (!$this->payments->contains($companyPayment)) {
$this->payments[] = $companyPayment;
$companyPayment->setCompany($this);
}
return $this;
}
public function removePayment(CompanyPayment $companyPayment): self
{
if ($this->payments->contains($companyPayment)) {
$this->payments->removeElement($companyPayment);
// set the owning side to null (unless already changed)
if ($companyPayment->getCompany() === $this) {
$companyPayment->setCompany(null);
}
}
return $this;
}
/*
* @TODO right now we lock it 1 subscription
* But in the long run the ManyToOne will be used
*/
public function getCurrentSubscription(){
return $this->getSubscriptions()->first();
}
/**
* @return Collection|CompanySubscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(CompanySubscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setCompany($this);
}
return $this;
}
public function removeSubscription(CompanySubscription $subscription): self
{
if ($this->subscriptions->contains($subscription)) {
$this->subscriptions->removeElement($subscription);
// set the owning side to null (unless already changed)
if ($subscription->getCompany() === $this) {
$subscription->setCompany(null);
}
}
return $this;
}
/*
* @Todo At some point need to save all bank used
*/
public function getCurrentDeposit(){
return $this->depositInfo;
}
public function getDeposit(): ?CompanyDeposit
{
return $this->depositInfo;
}
public function getDepositInfo(): ?CompanyDeposit
{
return $this->depositInfo;
}
public function setDeposit(CompanyDeposit $depositInfo): self
{
$this->depositInfo = $depositInfo;
// set the owning side of the relation if necessary
if ($this !== $depositInfo->getCompany()) {
$depositInfo->setCompany($this);
}
return $this;
}
public function setDepositInfo(CompanyDeposit $depositInfo): self
{
$this->depositInfo = $depositInfo;
// set the owning side of the relation if necessary
if ($this !== $depositInfo->getCompany()) {
$depositInfo->setCompany($this);
}
return $this;
}
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
}
public function getDateCreated()
{
return $this->dateCreated;
}
public function getDefaultShipping(): ?CompanyDefaultShipping
{
return $this->defaultShipping;
}
public function setDefaultShipping(?CompanyDefaultShipping $defaultShipping): self
{
$this->defaultShipping = $defaultShipping;
// set (or unset) the owning side of the relation if necessary
$newCompany = $defaultShipping === null ? null : $this;
if ($newCompany !== $defaultShipping->getCompany()) {
$defaultShipping->setCompany($newCompany);
}
return $this;
}
public function getCustomSaleConditions(): ?bool
{
return $this->customSaleConditions;
}
public function setCustomSaleConditions(bool $condition): self
{
$this->customSaleConditions= $condition;
return $this;
}
public function getConditionsShipping(): ?string
{
return $this->conditionsShipping;
}
public function setConditionsShipping(?string $conditionsShipping): self
{
$this->conditionsShipping = $conditionsShipping;
return $this;
}
public function getConditionsReturn(): ?string
{
return $this->conditionsReturn;
}
public function setConditionsReturn(?string $conditionsReturn): self
{
$this->conditionsReturn = $conditionsReturn;
return $this;
}
public function getConditionsCancel(): ?string
{
return $this->conditionsCancel;
}
public function setConditionsCancel(?string $conditionsCancel): self
{
$this->conditionsCancel = $conditionsCancel;
return $this;
}
public function isSearchable(){
//For now they are all searchable
//Need the payment option for only displaying the valid one
//@TODO
if(!empty($this->getMainLocation()) && $this->getShowPublicly())
return true;
else
return false;
}
/**
* @Groups({"searchable"})
*/
public function getSuggestions(){
return array_merge(array(
$this->getName()
),
explode(' ', $this->getName())
);
}
public function getTermsAcceptanceDate(): ?\DateTimeInterface
{
return $this->termsAcceptanceDate;
}
public function getTermsAcceptanceDateStamp()
{
if(!empty($this->termsAcceptanceDate))
return $this->termsAcceptanceDate->getTimestamp();
else
return null;
}
public function getTermsAcceptance(){
if(empty($this->getTermsAcceptanceIp()))
return false;
else
return true;
}
public function setTermsAcceptance($accept=false): self
{
if(!empty($accept) && $accept){
$this->termsAcceptanceDate = new \DateTime();
$this->termsAcceptanceIp = $_SERVER['REMOTE_ADDR'];
$this->termsAcceptanceFingerPrint = $_SERVER;
}
return $this;
}
public function setTermsAcceptanceDate(?\DateTimeInterface $termsAcceptanceDate): self
{
$this->termsAcceptanceDate = $termsAcceptanceDate;
return $this;
}
public function getTermsAcceptanceIp(): ?string
{
return $this->termsAcceptanceIp;
}
public function setTermsAcceptanceIp(?string $termsAcceptanceIp): self
{
$this->termsAcceptanceIp = $termsAcceptanceIp;
return $this;
}
public function getSolexId(): ?int
{
return $this->solexId;
}
public function setSolexId(?int $solexId): self
{
$this->solexId = $solexId;
return $this;
}
/**
* @return Collection|FinancialLog[]
*/
public function getTransactionsPaid(): Collection
{
return $this->transactionsPaid;
}
public function addTransactionsPaid(FinancialLog $transactionsPaid): self
{
if (!$this->transactionsPaid->contains($transactionsPaid)) {
$this->transactionsPaid[] = $transactionsPaid;
$transactionsPaid->setCompanyPaying($this);
}
return $this;
}
public function removeTransactionsPaid(FinancialLog $transactionsPaid): self
{
if ($this->transactionsPaid->contains($transactionsPaid)) {
$this->transactionsPaid->removeElement($transactionsPaid);
// set the owning side to null (unless already changed)
if ($transactionsPaid->getCompanyPaying() === $this) {
$transactionsPaid->setCompanyPaying(null);
}
}
return $this;
}
/**
* @return Collection|FinancialLog[]
*/
public function getTransactionsReceived(): Collection
{
return $this->transactionsReceived;
}
public function addTransactionsReceived(FinancialLog $transactionsReceived): self
{
if (!$this->transactionsReceived->contains($transactionsReceived)) {
$this->transactionsReceived[] = $transactionsReceived;
$transactionsReceived->setCompanyReceiving($this);
}
return $this;
}
public function removeTransactionsReceived(FinancialLog $transactionsReceived): self
{
if ($this->transactionsReceived->contains($transactionsReceived)) {
$this->transactionsReceived->removeElement($transactionsReceived);
// set the owning side to null (unless already changed)
if ($transactionsReceived->getCompanyReceiving() === $this) {
$transactionsReceived->setCompanyReceiving(null);
}
}
return $this;
}
public function __toString(){
if($this->getId())
return $this->getId().' - '.$this->name;
else
return $this->name;
}
/*
* Check if there is a replishment for this date
*/
public function hasReplenishmentOn($date){
foreach($this->getProductReplenishments() as $r){
if($r->getAppointmentDate() == $date)
return $r;
}
return false;
}
/**
* @return Collection|ProductReplenishment[]
*/
public function getProductReplenishments(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isValid', true));
$replenishment = $this->productReplenishments->matching($criteria);
return $replenishment;
}
public function addProductReplenishment(ProductReplenishment $productReplenishment): self
{
if (!$this->productReplenishments->contains($productReplenishment)) {
$this->productReplenishments[] = $productReplenishment;
$productReplenishment->setCompany($this);
}
return $this;
}
public function removeProductReplenishment(ProductReplenishment $productReplenishment): self
{
if ($this->productReplenishments->contains($productReplenishment)) {
$this->productReplenishments->removeElement($productReplenishment);
// set the owning side to null (unless already changed)
if ($productReplenishment->getCompany() === $this) {
$productReplenishment->setCompany(null);
}
}
return $this;
}
public function getStoreMadeByMaturin(): ?bool
{
return $this->storeMadeByMaturin;
}
public function setStoreMadeByMaturin(bool $storeMadeByMaturin): self
{
$this->storeMadeByMaturin = $storeMadeByMaturin;
return $this;
}
public function getExportColabor(): ?bool
{
return $this->exportColabor;
}
public function setExportColabor(bool $exportColabor): self
{
$this->exportColabor = $exportColabor;
return $this;
}
public function getTermsAcceptanceFingerPrint(): ?array
{
return $this->termsAcceptanceFingerPrint;
}
public function setTermsAcceptanceFingerPrint(?array $termsAcceptanceFingerPrint): self
{
$this->termsAcceptanceFingerPrint = $termsAcceptanceFingerPrint;
return $this;
}
public function getInventoryLastUpdate(): ?\DateTimeInterface
{
return $this->inventoryLastUpdate;
}
public function setInventoryLastUpdate(?\DateTimeInterface $inventoryLastUpdate): self
{
$this->inventoryLastUpdate = $inventoryLastUpdate;
return $this;
}
public function getEmail(){
if(empty($this->getMainLocation()))
return false;
$email = $this->getMainLocation()->getEmail();
if(empty($email))
return false;
else
return $email;
}
public function getShowPublicly(): ?bool
{
return $this->showPublicly;
}
public function setShowPublicly(?bool $showPublicly): self
{
$this->showPublicly = $showPublicly;
return $this;
}
/**
* @return Collection|CustomOrder[]
*/
public function getCustomOrders(): Collection
{
return $this->customOrders;
}
public function addCustomOrder(CustomOrder $customOrder): self
{
if (!$this->customOrders->contains($customOrder)) {
$this->customOrders[] = $customOrder;
$customOrder->setCompany($this);
}
return $this;
}
public function removeCustomOrder(CustomOrder $customOrder): self
{
if ($this->customOrders->contains($customOrder)) {
$this->customOrders->removeElement($customOrder);
// set the owning side to null (unless already changed)
if ($customOrder->getCompany() === $this) {
$customOrder->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|MaturinOrder[]
*/
public function getMaturinOrders(): Collection
{
return $this->maturinOrders;
}
public function addMaturinOrder(MaturinOrder $maturinOrder): self
{
if (!$this->maturinOrders->contains($maturinOrder)) {
$this->maturinOrders[] = $maturinOrder;
$maturinOrder->setCompany($this);
}
return $this;
}
public function removeMaturinOrder(MaturinOrder $maturinOrder): self
{
if ($this->maturinOrders->contains($maturinOrder)) {
$this->maturinOrders->removeElement($maturinOrder);
// set the owning side to null (unless already changed)
if ($maturinOrder->getCompany() === $this) {
$maturinOrder->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|CartProduct[]
*/
public function getPaidInvoices(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isPaid', true));
$paidInvoices = $this->invoices->matching($criteria);
return $paidInvoices;
}
/**
* @return Collection|CartProduct[]
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $item): self
{
if (!$this->invoices->contains($item)) {
$this->invoices[] = $item;
$item->setCompany($this);
}
return $this;
}
public function removeInvoice(Invoice $item): self
{
if ($this->invoices->contains($item)) {
$this->invoices->removeElement($item);
// set the owning side to null (unless already changed)
if ($item->getCompany() === $this) {
$item->setCompany(null);
}
}
return $this;
}
public function getCustomUrl(): ?string
{
if(empty($this->customUrl))
return 'producteur/'.$this->getUrlName().'/'.$this->getId();
else
return $this->customUrl;
}
public function setCustomUrl(?string $customUrl): self
{
$this->customUrl = $customUrl;
return $this;
}
public function getDaysSinceFirstSale()
{
//We start with the company start
$day = 0;
$now = new \Datetime();
//Put in a query at some point
foreach($this->getMaturinOrders() as $m){
$tmpDay = $m->getDateCreated()->diff($now)->format("%a");
if($tmpDay > $day)
$day = $tmpDay;
}
//Put in a query at some point
foreach($this->getCustomOrders() as $m){
$tmpDay = $m->getDateCreated()->diff($now)->format("%a");
if($tmpDay > $day)
$day = $tmpDay;
}
return $day;
}
/**
* @return Collection|Badge[]
*/
public function getBadges(): Collection
{
return $this->badges;
}
public function addBadge(Badge $badge): self
{
if (!$this->badges->contains($badge)) {
$this->badges[] = $badge;
$badge->setCompany($this);
}
return $this;
}
public function removeBadge(Badge $badge): self
{
if ($this->badges->contains($badge)) {
$this->badges->removeElement($badge);
// set the owning side to null (unless already changed)
if ($badge->getCompany() === $this) {
$badge->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|InvoiceService[]
*/
public function getInvoiceServices(): Collection
{
return $this->invoiceServices;
}
public function addInvoiceService(InvoiceService $invoiceService): self
{
if (!$this->invoiceServices->contains($invoiceService)) {
$this->invoiceServices[] = $invoiceService;
$invoiceService->setCompany($this);
}
return $this;
}
public function removeInvoiceService(InvoiceService $invoiceService): self
{
if ($this->invoiceServices->contains($invoiceService)) {
$this->invoiceServices->removeElement($invoiceService);
// set the owning side to null (unless already changed)
if ($invoiceService->getCompany() === $this) {
$invoiceService->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|CompanyAssociation[]
*/
public function getAssociations(): Collection
{
return $this->associations;
}
/**
* @Groups({"searchable"})
*/
public function getSearchAssociations(){
$ids = [];
foreach ($this->getAssociations() as $association){
$ids[]=$association->getId();
}
return array_unique($ids);
}
public function addAssociation(CompanyAssociation $association): self
{
if (!$this->associations->contains($association)) {
$this->associations[] = $association;
$association->addCompany($this);
}
return $this;
}
public function removeAssociation(CompanyAssociation $association): self
{
if ($this->associations->contains($association)) {
$this->associations->removeElement($association);
$association->removeCompany($this);
}
return $this;
}
public function getIsAllowedToScheduleColdProduct(): ?bool
{
return $this->isAllowedToScheduleColdProduct;
}
public function setIsAllowedToScheduleColdProduct(bool $isAllowedToScheduleColdProduct): self
{
$this->isAllowedToScheduleColdProduct = $isAllowedToScheduleColdProduct;
return $this;
}
public function getRecruiter(): ?User
{
return $this->recruiter;
}
public function setRecruiter(?User $recruiter): self
{
$this->recruiter= $recruiter;
return $this;
}
public function getTotalSales()
{
$total = 0;
foreach($this->getInvoices() as $i){
if($i->getIsPaid()){
$total += $i->getTotalSales();
}
}
return $total;
}
/**
* @return Collection|EmailSent[]
*/
public function getEmailReceiveds(): Collection
{
$emails=[];
foreach($this->getUsersAdmin() as $u){
if(!$u->isGranted('ROLE_SUPER_ADMIN')){
foreach($u->getEmailReceiveds() as $e){
$emails[$e->getId()] = $e;
}
}
}
rsort($emails);
return new ArrayCollection($emails);
}
public function getInGroupOfUser(): ?User
{
return $this->inGroupOfUser;
}
public function setInGroupOfUser(?User $inGroupOfUser): self
{
$this->inGroupOfUser = $inGroupOfUser;
return $this;
}
/**
* @return Collection|Variable[]
*/
public function getVariables(): Collection
{
return $this->variables;
}
public function addVariable(Variable $variable): self
{
if (!$this->variables->contains($variable)) {
$this->variables[] = $variable;
}
return $this;
}
public function removeVariable(Variable $variable): self
{
if ($this->variables->contains($variable)) {
$this->variables->removeElement($variable);
}
return $this;
}
public function getVariableByCodeName($codeName){
foreach($this->getVariables() as $v){
if($v->getCodeName() == $codeName)
return $v;
}
foreach($this->getAssociations() as $c){
$test = $c->getVariableByCodeName($codeName);
if($test)
return $test;
}
return false;
}
public function getVariableValueByCodeName($codeName){
$test = $this->getVariableByCodeName($codeName);
if($test && !$test->isExpired())
return $test->getValue();
return false;
}
/**
* @return bool
*/
public function getReminderStripeVerificationSent(): bool
{
return $this->reminderStripeVerificationSent;
}
/**
* @param bool $reminderCouponSent
* @return Company
*/
public function setReminderStripeVerificationSent(bool $ReminderStripeVerficationSent): self
{
$this->reminderStripeVerificationSent = $ReminderStripeVerficationSent;
return $this;
}
}