96 lines
3.2 KiB
PHP
96 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Impressao\Almoxarifado;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Almoxarifado\SaidaItem;
|
|
use App\Utils\Exports\Pdf1;
|
|
use App\Utils\MaskUtil;
|
|
use Illuminate\Support\Str;
|
|
|
|
class BaixaController extends Controller
|
|
{
|
|
private const TITLE = 'BAIXA';
|
|
private const TEMPLATE = 'almoxarifado.baixa';
|
|
|
|
public static function getTemplate($id)
|
|
{
|
|
$saidaItem = SaidaItem::findOrFail($id);
|
|
|
|
$entradaItens = $saidaItem->entradaItens->map(fn ($entradaItem) => [
|
|
'entrada_item_id' => $entradaItem->id,
|
|
'quantidade_saida' => $entradaItem->pivotSaidaItemEntradaItem->quantidade_saida,
|
|
'lote' => $entradaItem->lote,
|
|
'validade_lote' => $entradaItem->validade_lote,
|
|
]);
|
|
|
|
$semLote = collect();
|
|
$comLote = collect();
|
|
|
|
collect($entradaItens)->each(function ($entrada) use ($semLote, $comLote) {
|
|
|
|
if (is_null($entrada['lote'])) {
|
|
|
|
$semLote->push($entrada);
|
|
}
|
|
else {
|
|
|
|
$comLote->push($entrada);
|
|
}
|
|
});
|
|
|
|
$possuiEntradaComLote = $comLote->isNotEmpty();
|
|
|
|
$semLote = $semLote
|
|
->sortBy('entrada_item_id')
|
|
->values();
|
|
|
|
$comLote = $comLote
|
|
->sortBy([
|
|
['validade_lote', 'asc'],
|
|
['entrada_item_id', 'asc']
|
|
])
|
|
->values();
|
|
|
|
$entradaItens = $comLote->concat($semLote)->map(function ($entrada) {
|
|
|
|
if (!is_null($entrada['validade_lote'])) {
|
|
|
|
$entrada['validade_lote'] = $entrada['validade_lote']->format('d/m/Y');
|
|
}
|
|
|
|
return $entrada;
|
|
});
|
|
|
|
return [
|
|
'data' => $saidaItem->saida->created_at->format('d/m/Y'),
|
|
'unidade' => $saidaItem->createdCentroCusto->infraestrutura->unidade->nome_fantasia,
|
|
'localAtendimento' => $saidaItem->createdCentroCusto->infraestrutura->nome,
|
|
'setor' => $saidaItem->createdCentroCusto->setor->nome,
|
|
'usuario' => $saidaItem->createdLotacao->usuario->cidadao->nome,
|
|
'endereco' => $saidaItem->createdCentroCusto->infraestrutura->endereco->completo,
|
|
'telefone' => MaskUtil::getPhoneMasked($saidaItem->createdCentroCusto->infraestrutura->telefone),
|
|
'motivo' => $saidaItem->saida->baixa->motivo->descricao,
|
|
'justificativa' => $saidaItem->saida->baixa->justificativa,
|
|
'usuarioSolicitante' => $saidaItem->saida->baixa->usuarioSolicitante->cidadao->nome ?? null,
|
|
'itens' => collect([
|
|
[
|
|
'material' => [
|
|
'id' => $saidaItem->material->id,
|
|
'descricao' => $saidaItem->material->descricao_completa,
|
|
],
|
|
'quantidade' => $saidaItem->quantidade,
|
|
'possui_entrada_com_lote' => $possuiEntradaComLote,
|
|
'entrada_itens' => $entradaItens,
|
|
'estornado' => $saidaItem->estornado,
|
|
]
|
|
])->filter(fn ($i) => !$i['estornado'])->all()
|
|
];
|
|
}
|
|
|
|
public function __invoke($id)
|
|
{
|
|
return Pdf1::generate(self::TITLE, self::TEMPLATE, self::getTemplate($id));
|
|
}
|
|
}
|