This commit is contained in:
91
api/app/Utils/Exports/PdfCupom.php
Normal file
91
api/app/Utils/Exports/PdfCupom.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user