commit melhorias compras4
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-22 16:28:03 +02:00
parent efd97e265b
commit 36dcfdf00c
118 changed files with 6042 additions and 92 deletions
@@ -10,6 +10,7 @@ use App\Models\Requisition;
use App\Models\User;
use App\Services\OrganizationAccess;
use App\Services\ProcurementOperationalInsights;
use App\Services\ProcurementPayableInsights;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
@@ -150,7 +151,8 @@ class ProcurementReportController extends Controller
$insights = app(ProcurementOperationalInsights::class)->build($this->records(clone $query, $actor), $instant);
return ['records' => $records, 'counts' => $counts, 'filters' => $filters, 'departments' => $departments, 'generatedAt' => $instant->toIso8601String(), 'insights' => $insights];
return ['records' => $records, 'counts' => $counts, 'filters' => $filters, 'departments' => $departments, 'generatedAt' => $instant->toIso8601String(), 'insights' => $insights,
'payableInsights' => app(ProcurementPayableInsights::class)->build($actor, clone $query)];
});
Inertia::encryptHistory();
@@ -160,6 +162,37 @@ class ProcurementReportController extends Controller
return $response;
}
public function exportPositions(Request $request): Response
{
$data = $this->snapshot(function () use ($request): array {
$instant = CarbonImmutable::now(config('app.timezone'));
$filters = $this->filters($request);
$actor = $this->actor($request);
$positions = app(ProcurementPayableInsights::class)->build($actor, $this->query($actor, $filters, $instant->toDateString()));
abort_unless($positions !== null, 403);
return ['positions' => $positions, 'filters' => $filters, 'generated_at' => $instant->toIso8601String()];
});
return response()->streamDownload(function () use ($data) {
$output = fopen('php://output', 'w');
if ($output === false) {
throw new \RuntimeException('Não foi possível gerar a posição financeira.');
}
fwrite($output, "\xEF\xBB\xBF");
fputcsv($output, ['Posição actual das obrigações', 'Gerado em', $data['generated_at']], ';', '"', '');
fputcsv($output, ['Filtros dos pedidos (data de criação)', json_encode($data['filters'], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)], ';', '"', '');
fputcsv($output, ['Facturas autorizadas', 'Reconhecidas e determinadas', 'Por reconhecer', 'Posição indeterminada'], ';', '"', '');
$coverage = $data['positions']['coverage'];
fputcsv($output, [$coverage['invoices'], $coverage['recognised'], $coverage['unrecognised'], $coverage['indeterminate']], ';', '"', '');
fputcsv($output, ['Moeda', 'Obrigações determinadas', 'Principal (centavos)', 'Histórico conferido (centavos)', 'Liquidações imputadas (centavos)', 'Saldo actual (centavos)'], ';', '"', '');
foreach ($data['positions']['currencies'] as $row) {
fputcsv($output, [$row['currency'], $row['count'], $row['principal_minor'], $row['confirmed_payments_minor'], $row['allocated_payments_minor'], $row['balance_minor']], ';', '"', '');
}
fclose($output);
}, 'posicao-obrigacoes-'.now()->format('Ymd-His').'.csv', ['Content-Type' => 'text/csv; charset=UTF-8', 'Cache-Control' => 'private, no-store, max-age=0']);
}
public function export(Request $request): Response
{
$this->filters($request);