lk.zachem.info/app/Modules/Main/Models/Company/Details.php

102 lines
2.8 KiB
PHP

<?php
namespace Modules\Main\Models\Company;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Modules\Main\Models\Company\Company;
class Details
{
use HasFactory;
public $details;
private $company;
public function __construct(Company $company)
{
$this->company = $company;
}
public function get()
{
if (!$this->company->details)
{
$this->create();
}
return $this->details = $this->company->details;
}
public function create()
{
if (!$this->company->details)
{
if ($this->company->type == CompanyType::SelfEmployer)
{
$this->company->details = $this->emptyForSelfEmp();
$this->company->save();
}
;
if ($this->company->type == CompanyType::SoleProperty)
{
$this->company->details = $this->emptyForSelfEmp();
$this->company->save();
}
;
if ($this->company->type == CompanyType::Agency)
{
$this->company->details = $this->emptyForAgency();
$this->company->save();
}
}
return $this->details = $this->company->details;
}
private function emptyForSelfEmp()
{
$data = [
'user' => [
'firstName' => '',
'secondName' => '',
'email' => $this->company->email,
'phone' => ''
],
'details' => [
'inn' => $this->company->inn,
'snils' => '',
'bank' => [
'name' => '',
'bik' => '',
'cur' => '',
'pers' => ''
],
'address' => $this->company->address,
'legal_address' => $this->company->legal_address
]
];
return $data;
}
private function emptyForAgency()
{
$data = [
'name' => $this->company->name,
'fullName' => '',
'email' => $this->company->email,
'details' => [
'inn' => $this->company->inn,
'kpp' => '',
'ogrn' => '',
'bank' => [
'name' => '',
'bik' => '',
'cur' => '',
'pers' => ''
],
'address' => $this->company->address,
'legal_address' => $this->company->legal_address,
'post_address' => ''
]
];
return $data;
}
}