<?php
namespace App\Entity;
use App\Entity\File;
use App\Entity\User\User;
use App\Entity\Traits\IdTrait;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CompanyRepository;
use App\Entity\Traits\TimeStampAbleTrait;
use Symfony\Component\HttpFoundation\Request;
/**
* @ORM\Entity(repositoryClass=CompanyRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class Company
{
use IdTrait;
use TimeStampAbleTrait;
/**
* @ORM\Column (type="string", length=255, nullable=true)
*/
private ?string $phoneNumber;
/**
* @ORM\Column (type="string", length=255, nullable=true)
*/
private ?string $websiteUrl;
/**
* @ORM\Column (type="string", length=255, nullable=true)
*/
private ?string $numberOfEmployers;
/**
* @ORM\Column (type="text", nullable=true)
*/
private ?string $description;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isExtraInvoiceData = false;
/**
* @ORM\ManyToOne (targetEntity=InvoiceData::class)
*/
private ?InvoiceData $invoiceData;
/**
* @ORM\ManyToOne(targetEntity=InvoiceData::class)
*/
private ?InvoiceData $extraInvoiceData;
/**
* @ORM\ManyToOne(targetEntity=File::class, inversedBy="company")
* @ORM\JoinColumn(nullable=true)
*/
private ?File $logo = null;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="company")
*/
private ?User $user;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isExternalApplications;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sourceForTheExternalApplication;
/**
* @return string|null
*/
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
/**
* @param string|null $phoneNumber
*/
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return string|null
*/
public function getWebsiteUrl(): ?string
{
return $this->websiteUrl;
}
/**
* @param string|null $websiteUrl
*/
public function setWebsiteUrl(?string $websiteUrl): self
{
$this->websiteUrl = $websiteUrl;
return $this;
}
/**
* @return string|null
*/
public function getNumberOfEmployers(): ?string
{
return $this->numberOfEmployers;
}
/**
* @param string|null $numberOfEmployers
*/
public function setNumberOfEmployers(?string $numberOfEmployers): self
{
$this->numberOfEmployers = $numberOfEmployers;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
*/
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return bool|null
*/
public function getIsExtraInvoiceData(): ?bool
{
return $this->isExtraInvoiceData;
}
/**
* @param bool|null $isExtraInvoiceData
*/
public function setIsExtraInvoiceData(?bool $isExtraInvoiceData): self
{
$this->isExtraInvoiceData = $isExtraInvoiceData;
return $this;
}
/**
* @return InvoiceData|null
*/
public function getInvoiceData(): ?InvoiceData
{
return $this->invoiceData;
}
/**
* @param InvoiceData|null $invoiceData
*/
public function setInvoiceData(?InvoiceData $invoiceData): self
{
$this->invoiceData = $invoiceData;
return $this;
}
/**
* @return InvoiceData|null
*/
public function getExtraInvoiceData(): ?InvoiceData
{
return $this->extraInvoiceData;
}
/**
* @param InvoiceData|null $extraInvoiceData
*/
public function setExtraInvoiceData(?InvoiceData $extraInvoiceData): self
{
$this->extraInvoiceData = $extraInvoiceData;
return $this;
}
/**
* @return File|null
*/
public function getLogo(): ?File
{
return $this->logo;
}
/**
* @param File|null $logo
*/
public function setLogo(?File $logo): self
{
$this->logo = $logo;
return $this;
}
/**
* @return User|null
*/
public function getUser(): ?User
{
return $this->user;
}
/**
* @param User|null $user
*/
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getIsExternalApplications(): ?bool
{
return $this->isExternalApplications;
}
public function setIsExternalApplications(?bool $isExternalApplications): self
{
$this->isExternalApplications = $isExternalApplications;
return $this;
}
public function getSourceForTheExternalApplication(): ?string
{
return $this->sourceForTheExternalApplication;
}
public function setSourceForTheExternalApplication(?string $sourceForTheExternalApplication): self
{
$this->sourceForTheExternalApplication = $sourceForTheExternalApplication;
return $this;
}
public static function createMyCompany(?Company $company, Request $request): ?array
{
$data = $request->request->all();
if (
is_null($company) ||
empty($company->getInvoiceData()->getName()) ||
empty($company->getInvoiceData()->getVatId())
) {
$name = $data['company']['invoice_data']['name'] ?? '';
$nip = $data['company']['invoice_data']['nip'] ?? '';
$address = $data['company']['address']['address'] ?? '';
$postCode = $data['company']['address']['post_code'] ?? '';
$city = $data['company']['address']['city'] ?? '';
$country = $data['company']['address']['country'] ?? '';
} else {
$name = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getName() : $company->getExtraInvoiceData()->getName();
$nip = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getVatId(): $company->getExtraInvoiceData()->getVatId();
$address = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getAddress(): $company->getExtraInvoiceData()->getAddress()->getAddress();
$postCode = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getPostCode(): $company->getExtraInvoiceData()->getAddress()->getPostCode();
$city = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getCity(): $company->getExtraInvoiceData()->getAddress()->getCity();
$country = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getCountry(): $company->getExtraInvoiceData()->getAddress()->getCountry();
}
return [
'name' => $name,
'nip' => $nip,
'address' => $address,
'postCode' => $postCode,
'city' => $city,
'country' => $country,
];
}
}