init commit
All checks were successful
build-api-image / build (push) Successful in 51s

This commit is contained in:
Antonio Lopes dos Santos
2026-08-04 16:52:02 -03:00
commit afec302c3e
11594 changed files with 1636728 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Utils\Exports;
use Dompdf\Dompdf;
use Dompdf\Options;
class Pdf
{
private Dompdf $dompdf;
public function __construct(Options $options = null)
{
$this->dompdf = new Dompdf($options ?? $this->getDefaultOptions());
$this->setPaper('A4', 'portrait');
}
private function getDefaultOptions() : Options
{
$options = new Options;
$options->set('isPhpEnabled', true);
return $options;
}
public function setPaper(string $type, string $orientation) : void
{
$this->dompdf->setPaper($type, $orientation);
}
public function stream(string $html, string $fileName = 'documento')
{
$this->dompdf->loadHtml($html);
$this->dompdf->render();
return response()->streamDownload(
function () {
echo $this->dompdf->output();
},
"{$fileName}.pdf",
['Content-Type' => 'Application/pdf']
);
}
public function output(string $html)
{
$this->dompdf->loadHtml($html);
$this->dompdf->render();
return $this->dompdf->output();
}
}

View File

@@ -0,0 +1,99 @@
<?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 Pdf1
{
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.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);
$snappyPdf->setTimeout(300);
return $snappyPdf->inline();
}
}

View File

@@ -0,0 +1,97 @@
<?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();
}
}

View File

@@ -0,0 +1,97 @@
<?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();
}
}

View File

@@ -0,0 +1,91 @@
<?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 PdfCupom
{
private const TEMPLATE_BASE_NAME = 'impressoes.template.';
private static function getCustomerData()
{
$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_social' => $lotacao->usuario->cidadao->nome_social ?? null,
]
],
'data_impressao' => Carbon::now()->format('d/m/Y H:i:s')
];
}
public static function generate($title, $template, $data)
{
$data = array_merge($data, ['title' => $title], ['_data' => self::getCustomerData()]);
return SnappyPdf::loadView(self::TEMPLATE_BASE_NAME . $template, $data)
->setOption('header-html', view('impressoes.layout-cupom.header', $data)->render())
->setOption('margin-bottom', 25)
->setOption('margin-left', 2)
->setOption('margin-right', 2)
->setOption('margin-top', 33)
->setPaper('a4')
->inline();
}
}

View File

@@ -0,0 +1,91 @@
<?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 PdfEtiqueta
{
private const TEMPLATE_BASE_NAME = 'impressoes.template.';
private static function getCustomerData()
{
$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')
];
}
public static function generate($template, $data)
{
$data = array_merge($data, ['_data' => self::getCustomerData()]);
return SnappyPdf::loadView(self::TEMPLATE_BASE_NAME . $template, $data)
->setOption('header-html', view('impressoes.layout-etiqueta.header', $data)->render())
->setOption('margin-bottom', 25)
->setOption('margin-left', 2)
->setOption('margin-right', 2)
->setOption('margin-top', 10)
->setPaper('a4')
->inline();
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Utils\Exports;
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfParser\StreamReader;
class PhpMerge
{
public static function mergePdfDocuments($documentTitle, $pdfContents)
{
$pdf = new Fpdi();
foreach ($pdfContents as $pdfContent) {
$streamReader = StreamReader::createByString($pdfContent['data']);
$pageCount = $pdf->setSourceFile($streamReader);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$pdf->AddPage($pdfContent['orientation'], 'A4');
$pdf->useTemplate($templateId);
}
}
return response($pdf->Output($documentTitle . '.pdf', 'S'))
->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'inline; filename="' . $documentTitle . '.pdf"')
->header('Cache-Control', 'no-cache, no-store, must-revalidate')
->header('Pragma', 'no-cache')
->header('Expires', '0');
}
}

View File

@@ -0,0 +1,140 @@
<?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')
];
}
}