85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Impressao\Almoxarifado;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Almoxarifado\Saida;
|
|
use App\Services\Almoxarifado\SaidaService;
|
|
use App\Utils\Exports\Pdf1;
|
|
use App\Utils\MaskUtil;
|
|
use Carbon\Carbon;
|
|
|
|
class SaidaController extends Controller
|
|
{
|
|
private const TITLE = 'SAÍDA';
|
|
private const TEMPLATE = 'almoxarifado.saida';
|
|
|
|
public static function getTemplate($id)
|
|
{
|
|
$saida = Saida::findOrFail($id);
|
|
$data = SaidaService::edit($id);
|
|
|
|
$data['model']['itens'] = $data['model']['itens']->filter(fn ($i) => !$i['estornado'])->map(function ($item) {
|
|
|
|
$semLote = collect();
|
|
$comLote = collect();
|
|
|
|
collect($item['entrada_itens'])->each(function ($entrada) use ($semLote, $comLote) {
|
|
|
|
if (is_null($entrada['lote'])) {
|
|
|
|
$semLote->push($entrada);
|
|
}
|
|
else {
|
|
|
|
$comLote->push($entrada);
|
|
}
|
|
});
|
|
|
|
$item['possui_entrada_com_lote'] = $comLote->isNotEmpty();
|
|
|
|
$semLote = $semLote
|
|
->sortBy('entrada_item_id')
|
|
->values();
|
|
|
|
$comLote = $comLote
|
|
->sortBy([
|
|
['validade_lote', 'asc'],
|
|
['entrada_item_id', 'asc']
|
|
])
|
|
->values();
|
|
|
|
$item['entrada_itens'] = $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 $item;
|
|
});
|
|
|
|
return [
|
|
'data' => (new Carbon($saida->requisicao->data))->format('d/m/Y'),
|
|
'numero' => $saida->requisicao->numero,
|
|
'requisitante' => [
|
|
'unidade' => $saida->requisicao->centroCusto->infraestrutura->unidade->nome_fantasia,
|
|
'local_atendimento' => $saida->requisicao->centroCusto->infraestrutura->nome,
|
|
'setor' => $saida->requisicao->centroCusto->setor->nome,
|
|
'usuario' => $saida->requisicao->usuario->cidadao->nome,
|
|
'endereco' => $saida->requisicao->centroCusto->infraestrutura->endereco->completo,
|
|
'telefone' => MaskUtil::getPhoneMasked($saida->requisicao->centroCusto->infraestrutura->telefone)
|
|
],
|
|
'itens' => $data['model']['itens'],
|
|
];
|
|
}
|
|
|
|
public function __invoke($id)
|
|
{
|
|
return Pdf1::generate(self::TITLE, self::TEMPLATE, self::getTemplate($id));
|
|
}
|
|
}
|