98 lines
4.1 KiB
PHP
98 lines
4.1 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 Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Carbon\Carbon;
|
|
|
|
class PdfAtendimento
|
|
{
|
|
private const TEMPLATE_BASE_NAME = 'impressoes.template.';
|
|
|
|
private static function getCustomerData()
|
|
{
|
|
$cliente = Cliente::where('link', app('config')->get('database.default'))
|
|
->where('sistema_id', 1)
|
|
->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')
|
|
];
|
|
}
|
|
|
|
public static function generate($title, $template, $data, $orientation = 'portrait')
|
|
{
|
|
$data = array_merge($data, ['title' => $title], ['_data' => self::getCustomerData()]);
|
|
|
|
$snappyPdf = SnappyPdf::loadView(self::TEMPLATE_BASE_NAME . $template, $data)
|
|
->setOption('footer-html', view('impressoes.layout-atendimento.footer', $data)->render())
|
|
->setOption('header-html', view('impressoes.layout-atendimento.header', $data)->render())
|
|
->setOption('margin-bottom', 17)
|
|
->setOption('margin-left', 2)
|
|
->setOption('margin-right', 2)
|
|
->setOption('margin-top', 43)
|
|
->setPaper('a4')
|
|
->setOrientation($orientation);
|
|
|
|
return $snappyPdf->inline();
|
|
}
|
|
}
|