Files
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

98 lines
3.3 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 Pdf1Externo
{
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();
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' => null,
'cnes' => null,
],
'endereco' => [
'logradouro' => [
'municipio' => [
'estado' => [
'uf' => null,
],
'nome' => null,
],
'bairro' => [
'nome' => null,
],
'tipo' => [
'descricao' => null,
],
'nome' => null,
'cep' => null,
],
'numero' => null,
'referencia' => null,
],
'telefone' => null,
],
'usuario' => [
'cidadao' => [
'nome' => null,
'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.layout1.footer', $data)->render())
->setOption('header-html', view('impressoes.layout1.header', $data)->render())
->setOption('margin-bottom', 18)
->setOption('margin-left', 2)
->setOption('margin-right', 2)
->setOption('margin-top', 27)
->setPaper('a4')
->setOrientation($orientation);
return $snappyPdf->inline();
}
}