141 lines
4.8 KiB
PHP
141 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Utils\Exports;
|
|
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Models\Intranet\Cliente;
|
|
use App\Utils\ComposerJson;
|
|
use App\Utils\MaskUtil;
|
|
use Carbon\Carbon;
|
|
|
|
class Template
|
|
{
|
|
private const TEMPLATE_BASE_NAME = 'impressoes.template.';
|
|
|
|
private string $title;
|
|
private string $subtitle;
|
|
private string $template;
|
|
private array $data;
|
|
private bool $duplicate;
|
|
|
|
public static function make(string $title, string $template, $duplicate = false) : Template
|
|
{
|
|
return new self($title, $template, $duplicate);
|
|
}
|
|
|
|
private function __construct(string $title, string $template, $duplicate = false)
|
|
{
|
|
$this->title = trim($title);
|
|
$this->template = self::TEMPLATE_BASE_NAME . trim(trim(trim($template), '.'));
|
|
$this->duplicate = $duplicate;
|
|
}
|
|
|
|
public function withSubtitle(string $subtitle) : Template
|
|
{
|
|
$this->subtitle = trim($subtitle);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withData(array $data) : Template
|
|
{
|
|
$this->data = $data;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function appendData(array $data) : Template
|
|
{
|
|
$this->data = array_merge($this->data, $data);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHtml()
|
|
{
|
|
$this->setGeneralData();
|
|
|
|
return view($this->template, $this->data)->render();
|
|
}
|
|
|
|
private function setGeneralData() : void
|
|
{
|
|
$data = [
|
|
'dataAtual' => [
|
|
'porExtenso' => Carbon::now()->translatedFormat('d \de F \de Y'),
|
|
],
|
|
'titulo' => $this->title,
|
|
'duplicate' => $this->duplicate,
|
|
];
|
|
|
|
if (!empty($this->subtitle)) {
|
|
|
|
$data['subtitulo'] = $this->subtitle;
|
|
}
|
|
|
|
$this->data['_data'] = array_merge($data, $this->getCustomerData());
|
|
}
|
|
|
|
private function getCustomerData() : array
|
|
{
|
|
$cliente = Cliente::where('link', app('config')->get('database.default'))->firstOrFail();
|
|
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
|
|
|
return [
|
|
'cliente' => [
|
|
'sistema' => [
|
|
'ramo_atividade' => [
|
|
'nome' => $cliente->sistema->ramoAtividade->nome ?? null,
|
|
],
|
|
'nome' => $cliente->sistema->nome ?? null,
|
|
'versao' => ComposerJson::getVersion(),
|
|
],
|
|
'municipio' => [
|
|
'estado' => [
|
|
'uf' => $cliente->municipio->estado->uf ?? null,
|
|
],
|
|
'nome' => $cliente->municipio->nome ?? null,
|
|
],
|
|
'nome' => $cliente->nome ?? null,
|
|
'email' => $cliente->email ?? null,
|
|
'site' => $cliente->site ?? null,
|
|
'logotipo' => $cliente->logotipo ? base64_encode(file_get_contents(storage_path('app/intranet/cliente/logotipo/' . $cliente->logotipo))) : null,
|
|
],
|
|
'infraestrutura' => [
|
|
'unidade' => [
|
|
'nome_fantasia' => $lotacao->infraestrutura->unidade->nome_fantasia ?? null,
|
|
'cnes' => $lotacao->infraestrutura->unidade->cnes ?? null,
|
|
],
|
|
'endereco' => [
|
|
'logradouro' => [
|
|
'municipio' => [
|
|
'estado' => [
|
|
'uf' => $lotacao->infraestrutura->endereco->logradouro->municipio->estado->uf ?? null,
|
|
],
|
|
'nome' => $lotacao->infraestrutura->endereco->logradouro->municipio->nome ?? null,
|
|
],
|
|
'bairro' => [
|
|
'nome' => $lotacao->infraestrutura->endereco->logradouro->bairro->nome ?? null,
|
|
],
|
|
'tipo' => [
|
|
'descricao' => $lotacao->infraestrutura->endereco->logradouro->tipo->descricao ?? null,
|
|
],
|
|
'nome' => $lotacao->infraestrutura->endereco->logradouro->nome ?? null,
|
|
'cep' => MaskUtil::getCepMasked($lotacao->infraestrutura->endereco->logradouro->cep) ?? null,
|
|
],
|
|
'numero' => $lotacao->infraestrutura->endereco->numero ?? null,
|
|
'referencia' => $lotacao->infraestrutura->endereco->referencia ?? null,
|
|
],
|
|
'telefone' => MaskUtil::getPhoneMasked($lotacao->infraestrutura->telefone) ?? null,
|
|
],
|
|
'usuario' => [
|
|
'cidadao' => [
|
|
'nome' => $lotacao->usuario->cidadao->nome ?? null,
|
|
'nome' => $lotacao->usuario->cidadao->nome ?? null,
|
|
]
|
|
],
|
|
'data_impressao' => Carbon::now()->format('d/m/Y H:i:s')
|
|
];
|
|
}
|
|
}
|