commit melhorias sgf
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Modules\Accounting;
|
||||
|
||||
use App\Shared\Installation\CompositionRuntime;
|
||||
use App\Shared\Context\CompanyContext;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tempo\Finance\GeneralLedger\LedgerSchema;
|
||||
|
||||
/** Read routing only. Domain facts stay in the host; ledger metadata stays in its original book. */
|
||||
final class SourceBook
|
||||
{
|
||||
private static function connection()
|
||||
{
|
||||
if(!(app()->environment('budget-testing')&&config('sgf_single_installation.enabled')===true&&config('sgf_single_installation.ledger_enabled')===true))return DB::connection();
|
||||
CompositionRuntime::assert();$host=CompositionRuntime::physical();$ctx=app(CompanyContext::class);$scope=$ctx->identifiers();$native=DB::connection('receipt_native');LedgerSchema::assertSynthetic($native);
|
||||
$binding=$native->table('gl_sgf_composition')->where('tenant_id',$scope['tenant_id'])->first();
|
||||
abort_unless($binding&&$binding->host_database===$host['database']&&(int)$binding->company_id===$scope['company_id']&&(int)$binding->unit_id===$ctx->unitId(),403);
|
||||
return $native;
|
||||
}
|
||||
public static function table(string $table){if(!preg_match('/^gl_[a-z_]+$/D',$table))throw new \LogicException('Ledger metadata only');return self::connection()->table($table);}
|
||||
public static function has(string $table):bool{if(!preg_match('/^gl_[a-z_]+$/D',$table))throw new \LogicException('Ledger metadata only');return self::connection()->getSchemaBuilder()->hasTable($table);}
|
||||
}
|
||||
Reference in New Issue
Block a user