commit compras2 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 10:48:22 +02:00
parent 448948a487
commit 7da8d6c87a
64 changed files with 2538 additions and 288 deletions
+26 -5
View File
@@ -5,6 +5,7 @@ namespace App\Services;
use App\Enums\PurchasingRole;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Tempo\Finance\GeneralLedger\LedgerSchema;
use Tempo\Finance\GeneralLedger\PayableJournal;
use Tempo\Finance\GeneralLedger\ReportsWorkspace;
@@ -13,14 +14,25 @@ use Tempo\Finance\Payables\Payables;
/** Standalone adapter; same local package, native finance authority, no SGF remote service. */
final class GeneralLedger
{
public function cycleEnabled(): bool
{
return app(StandaloneRuntime::class)->enabled()
? app(StandaloneRuntime::class)->feature('general-ledger-cycle', DB::connection())
: config('general-ledger.cycle_enabled') === true;
}
/** @return array{actor:User,scope:array<string,int>,person:string} */
private function context(User $user): array
{
abort_unless(app()->environment('payable-testing') && config('general-ledger.synthetic_enabled') === true, 403);
$standalone = app(StandaloneRuntime::class)->enabled();
abort_unless($standalone ? app(StandaloneRuntime::class)->feature('general-ledger', DB::connection())
: app()->environment('payable-testing') && config('general-ledger.synthetic_enabled') === true, 403);
$package = config('general-ledger.path');
abort_unless(is_string($package) && is_file($package.'/bootstrap.php'), 503, 'Pacote contabilístico não composto.');
require_once $package.'/bootstrap.php';
LedgerSchema::assertSynthetic(DB::connection());
if (! $standalone) {
LedgerSchema::assertSynthetic(DB::connection());
}
$context = app(SupplierPayables::class)->readContext($user);
abort_unless(DB::table('pa_access')->where($context['scope'])->where(['user_id' => $user->id, 'action' => 'general_ledger.view', 'person' => $context['person']])->exists(), 403);
@@ -29,7 +41,14 @@ final class GeneralLedger
public function can(User $user, string $action): bool
{
$c = $this->context($user);
try {
$c = $this->context($user);
} catch (HttpExceptionInterface $error) {
if ($error->getStatusCode() === 403) {
return false;
}
throw $error;
}
return DB::table('pa_access')->where($c['scope'])->where(['user_id' => $user->id, 'action' => 'general_ledger.'.$action, 'person' => $c['person']])->exists();
}
@@ -49,7 +68,9 @@ final class GeneralLedger
abort_unless($this->can($user, $action), 403);
};
return new PayableJournal(DB::connection(), $scope, $user->id, $person, fn ($a) => $authorize($a), fn () => $authorize('view', false), fn ($id) => $this->source($user, $scope, $id), $fault);
$hostOptions = app(StandaloneRuntime::class)->enabled() ? ['hostPolicy' => 'COMMON-PAYABLE-JOURNAL-v1'] : [];
return new PayableJournal(DB::connection(), $scope, $user->id, $person, fn ($a) => $authorize($a), fn () => $authorize('view', false), fn ($id) => $this->source($user, $scope, $id), $fault, ...$hostOptions);
}
/** @param array<string,int> $scope
@@ -97,7 +118,7 @@ final class GeneralLedger
/** @return array<string,mixed> */
public function workspace(User $user, int $page = 1): array
{
abort_unless(config('general-ledger.cycle_enabled') === true, 403);
abort_unless($this->cycleEnabled(), 403);
$own = DB::transactionLevel() === 0;
return DB::transaction(function () use ($user, $page, $own) {