commit compras 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 13:49:31 +02:00
parent dc73540558
commit e709d900d1
81 changed files with 5352 additions and 107 deletions
@@ -11,6 +11,7 @@ use App\Models\User;
use App\Services\OrganizationAccess;
use App\Services\ProcurementOperationalInsights;
use App\Services\ProcurementPayableInsights;
use App\Services\ProcurementPaymentInsights;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
@@ -152,7 +153,10 @@ 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,
'payableInsights' => app(ProcurementPayableInsights::class)->build($actor, clone $query)];
'payableInsights' => app(ProcurementPayableInsights::class)->build($actor, clone $query),
'paymentInsights' => app(ProcurementPaymentInsights::class)->build($actor,
$this->query($actor, array_diff_key($filters, array_flip(['from', 'to'])), $instant->toDateString()),
$filters['from'] ?? null, $filters['to'] ?? null)];
});
Inertia::encryptHistory();
@@ -193,6 +197,39 @@ class ProcurementReportController extends Controller
}, 'posicao-obrigacoes-'.now()->format('Ymd-His').'.csv', ['Content-Type' => 'text/csv; charset=UTF-8', 'Cache-Control' => 'private, no-store, max-age=0']);
}
public function exportPayments(Request $request): Response
{
$data = $this->snapshot(function () use ($request): array {
$instant = CarbonImmutable::now(config('app.timezone'));
$filters = $this->filters($request);
$actor = $this->actor($request);
$payments = app(ProcurementPaymentInsights::class)->build($actor,
$this->query($actor, array_diff_key($filters, array_flip(['from', 'to'])), $instant->toDateString()),
$filters['from'] ?? null, $filters['to'] ?? null);
abort_unless($payments !== null, 403);
return ['payments' => $payments, '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 exportar a despesa.');
}
fwrite($output, "\xEF\xBB\xBF");
$payments = $data['payments'];
fputcsv($output, ['Pagamentos externos confirmados pela data de confirmação', 'Gerado em', $data['generated_at']], ';', '"', '');
fputcsv($output, ['Confirmação desde', $payments['from'] ?? '', 'Até (inclusive)', $payments['to'] ?? ''], ';', '"', '');
fputcsv($output, ['Facturas no âmbito', 'Históricos indeterminados excluídos', 'Pagamentos confirmados determinados'], ';', '"', '');
fputcsv($output, array_values($payments['coverage']), ';', '"', '');
fputcsv($output, ['Moeda', 'Pagamentos', 'Despesa (centavos)'], ';', '"', '');
foreach ($payments['currencies'] as $row) {
fputcsv($output, [$row['currency'], $row['count'], $row['amount_minor']], ';', '"', '');
}
fclose($output);
}, 'despesa-confirmada-'.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);