src/Entity/Company.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\File;
  4. use App\Entity\User\User;
  5. use App\Entity\Traits\IdTrait;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\CompanyRepository;
  8. use App\Entity\Traits\TimeStampAbleTrait;
  9. use Symfony\Component\HttpFoundation\Request;
  10. /**
  11.  * @ORM\Entity(repositoryClass=CompanyRepository::class)
  12.  * @ORM\HasLifecycleCallbacks
  13.  */
  14. class Company
  15. {
  16.     use IdTrait;
  17.     use TimeStampAbleTrait;
  18.     /**
  19.      * @ORM\Column (type="string", length=255, nullable=true)
  20.      */
  21.     private ?string $phoneNumber;
  22.     /**
  23.      * @ORM\Column (type="string", length=255, nullable=true)
  24.      */
  25.     private ?string $websiteUrl;
  26.     /**
  27.      * @ORM\Column (type="string", length=255, nullable=true)
  28.      */
  29.     private ?string $numberOfEmployers;
  30.     /**
  31.      * @ORM\Column (type="text", nullable=true)
  32.      */
  33.     private ?string $description;
  34.     /**
  35.      * @ORM\Column(type="boolean", nullable=true)
  36.      */
  37.     private ?bool $isExtraInvoiceData = false;
  38.     /**
  39.      * @ORM\ManyToOne (targetEntity=InvoiceData::class)
  40.      */
  41.     private ?InvoiceData $invoiceData;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=InvoiceData::class)
  44.      */
  45.     private ?InvoiceData $extraInvoiceData;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=File::class, inversedBy="company")
  48.      * @ORM\JoinColumn(nullable=true)
  49.      */
  50.     private ?File $logo = null;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="company")
  53.      */
  54.     private ?User $user;
  55.     /**
  56.      * @ORM\Column(type="boolean", nullable=true)
  57.      */
  58.     private $isExternalApplications;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $sourceForTheExternalApplication;
  63.     /**
  64.      * @return string|null
  65.      */
  66.     public function getPhoneNumber(): ?string
  67.     {
  68.         return $this->phoneNumber;
  69.     }
  70.     /**
  71.      * @param string|null $phoneNumber
  72.      */
  73.     public function setPhoneNumber(?string $phoneNumber): self
  74.     {
  75.         $this->phoneNumber = $phoneNumber;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return string|null
  80.      */
  81.     public function getWebsiteUrl(): ?string
  82.     {
  83.         return $this->websiteUrl;
  84.     }
  85.     /**
  86.      * @param string|null $websiteUrl
  87.      */
  88.     public function setWebsiteUrl(?string $websiteUrl): self
  89.     {
  90.         $this->websiteUrl = $websiteUrl;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return string|null
  95.      */
  96.     public function getNumberOfEmployers(): ?string
  97.     {
  98.         return $this->numberOfEmployers;
  99.     }
  100.     /**
  101.      * @param string|null $numberOfEmployers
  102.      */
  103.     public function setNumberOfEmployers(?string $numberOfEmployers): self
  104.     {
  105.         $this->numberOfEmployers = $numberOfEmployers;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return string|null
  110.      */
  111.     public function getDescription(): ?string
  112.     {
  113.         return $this->description;
  114.     }
  115.     /**
  116.      * @param string|null $description
  117.      */
  118.     public function setDescription(?string $description): self
  119.     {
  120.         $this->description = $description;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return bool|null
  125.      */
  126.     public function getIsExtraInvoiceData(): ?bool
  127.     {
  128.         return $this->isExtraInvoiceData;
  129.     }
  130.     /**
  131.      * @param bool|null $isExtraInvoiceData
  132.      */
  133.     public function setIsExtraInvoiceData(?bool $isExtraInvoiceData): self
  134.     {
  135.         $this->isExtraInvoiceData = $isExtraInvoiceData;
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return InvoiceData|null
  140.      */
  141.     public function getInvoiceData(): ?InvoiceData
  142.     {
  143.         return $this->invoiceData;
  144.     }
  145.     /**
  146.      * @param InvoiceData|null $invoiceData
  147.      */
  148.     public function setInvoiceData(?InvoiceData $invoiceData): self
  149.     {
  150.         $this->invoiceData = $invoiceData;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return InvoiceData|null
  155.      */
  156.     public function getExtraInvoiceData(): ?InvoiceData
  157.     {
  158.         return $this->extraInvoiceData;
  159.     }
  160.     /**
  161.      * @param InvoiceData|null $extraInvoiceData
  162.      */
  163.     public function setExtraInvoiceData(?InvoiceData $extraInvoiceData): self
  164.     {
  165.         $this->extraInvoiceData = $extraInvoiceData;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return File|null
  170.      */
  171.     public function getLogo(): ?File
  172.     {
  173.         return $this->logo;
  174.     }
  175.     /**
  176.      * @param File|null $logo
  177.      */
  178.     public function setLogo(?File $logo): self
  179.     {
  180.         $this->logo = $logo;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return User|null
  185.      */
  186.     public function getUser(): ?User
  187.     {
  188.         return $this->user;
  189.     }
  190.     /**
  191.      * @param User|null $user
  192.      */
  193.     public function setUser(?User $user): self
  194.     {
  195.         $this->user = $user;
  196.         return $this;
  197.     }
  198.     public function getIsExternalApplications(): ?bool
  199.     {
  200.         return $this->isExternalApplications;
  201.     }
  202.     public function setIsExternalApplications(?bool $isExternalApplications): self
  203.     {
  204.         $this->isExternalApplications = $isExternalApplications;
  205.         return $this;
  206.     }
  207.     public function getSourceForTheExternalApplication(): ?string
  208.     {
  209.         return $this->sourceForTheExternalApplication;
  210.     }
  211.     public function setSourceForTheExternalApplication(?string $sourceForTheExternalApplication): self
  212.     {
  213.         $this->sourceForTheExternalApplication = $sourceForTheExternalApplication;
  214.         return $this;
  215.     }
  216.     public static function createMyCompany(?Company $company, Request $request): ?array
  217.     {
  218.         $data = $request->request->all();
  219.         if (
  220.             is_null($company) ||
  221.             empty($company->getInvoiceData()->getName()) ||
  222.             empty($company->getInvoiceData()->getVatId())
  223.         ) {
  224.             $name = $data['company']['invoice_data']['name'] ?? '';
  225.             $nip = $data['company']['invoice_data']['nip'] ?? '';
  226.             $address =  $data['company']['address']['address'] ?? '';
  227.             $postCode = $data['company']['address']['post_code'] ?? '';
  228.             $city = $data['company']['address']['city'] ?? '';
  229.             $country = $data['company']['address']['country'] ?? '';
  230.         } else {
  231.             $name = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getName() : $company->getExtraInvoiceData()->getName();
  232.             $nip = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getVatId(): $company->getExtraInvoiceData()->getVatId();
  233.             $address = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getAddress(): $company->getExtraInvoiceData()->getAddress()->getAddress();
  234.             $postCode = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getPostCode(): $company->getExtraInvoiceData()->getAddress()->getPostCode();
  235.             $city = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getCity(): $company->getExtraInvoiceData()->getAddress()->getCity();
  236.             $country = (bool)$company->getIsExtraInvoiceData() === false ? $company->getInvoiceData()->getAddress()->getCountry(): $company->getExtraInvoiceData()->getAddress()->getCountry();
  237.         }
  238.         return [
  239.             'name' => $name,
  240.             'nip' => $nip,
  241.             'address' => $address,
  242.             'postCode' => $postCode,
  243.             'city' => $city,
  244.             'country' => $country,
  245.         ];
  246.     }
  247. }