commit12
This commit is contained in:
@@ -37,7 +37,7 @@ final class DocumentPreparation
|
||||
{
|
||||
if ($kind === 'payment') { return $id ? $this->query($kind, $scope)->where('id', $id)->first() : null; }
|
||||
$table = $kind === 'issuer' ? 'companies' : ($kind === 'client' ? 'a_clients' : 'a_'.$kind);
|
||||
$query = DB::table($table)->where('tenant_id', $scope['tenant_id'])->where($kind === 'issuer' ? 'id' : 'company_id', $scope['company_id'])->where('id', $id);
|
||||
$query = \App\Shared\Context\ModuleRecords::query($table)->where('tenant_id', $scope['tenant_id'])->where($kind === 'issuer' ? 'id' : 'company_id', $scope['company_id'])->where('id', $id);
|
||||
if ($scope['unit_id']) { $query->where('unit_id', $scope['unit_id']); }
|
||||
$target = $query->first(); abort_unless($target, 403, 'Registo fora do âmbito autorizado.'); return $target;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ final class DocumentPreparation
|
||||
$scope = $this->scope($kind, $actor, 'view');
|
||||
if ($kind === 'payment') { return $this->query($kind, $scope)->orderBy('id')->get()->map(fn ($row) => $this->decode($row))->all(); }
|
||||
if ($kind === 'issuer') { return [['id' => $scope['company_id'], 'name' => DB::table('companies')->where('id', $scope['company_id'])->value('name')]]; }
|
||||
if ($kind === 'client') { $this->permissions->require($actor, $scope['tenant_id'], $scope['company_id'], 'clients.view'); return DB::table('a_clients')->where('tenant_id', $scope['tenant_id'])->where('company_id', $scope['company_id'])->orderBy('name')->get(['id','name'])->all(); }
|
||||
if ($kind === 'client') { $this->permissions->require($actor, $scope['tenant_id'], $scope['company_id'], 'clients.view'); return \App\Shared\Context\ModuleRecords::query('a_clients')->where('tenant_id', $scope['tenant_id'])->where('company_id', $scope['company_id'])->orderBy('name')->get(['id','name'])->all(); }
|
||||
return $this->workflow->list($kind, $actor);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ final class DocumentPreparation
|
||||
public function snapshot(int $draft, int $actor): ?array
|
||||
{
|
||||
$scope = $this->context->identifiers(); $scope['unit_id'] = $this->context->unitId();
|
||||
$billing = DB::table('a_billing_drafts')->where($scope)->where('id', $draft)->firstOrFail();
|
||||
$billing = \App\Shared\Context\ModuleRecords::query('a_billing_drafts')->where($scope)->where('id', $draft)->firstOrFail();
|
||||
$rows = DB::table('doc_records')->where('tenant_id', $scope['tenant_id'])->where('company_id', $scope['company_id'])->where(function ($q) use ($billing, $draft) {
|
||||
$q->where('kind', 'issuer')->orWhere(fn ($q) => $q->where('kind', 'client')->where('record_id', $billing->client_id))->orWhere(fn ($q) => $q->where('kind', 'billing_drafts')->where('record_id', $draft));
|
||||
})->get();
|
||||
@@ -148,7 +148,7 @@ final class DocumentPreparation
|
||||
$row = $this->query('service_drafts', $scope)->where('record_id', $source)->first();
|
||||
if (! $row) { return; }
|
||||
$data = json_decode($row->data, true, 32, JSON_THROW_ON_ERROR);
|
||||
if ((int) $data['draft_version'] !== (int) DB::table('a_service_drafts')->where('id', $source)->value('version')) { return; }
|
||||
if ((int) $data['draft_version'] !== (int) \App\Shared\Context\ModuleRecords::query('a_service_drafts')->where('id', $source)->value('version')) { return; }
|
||||
$data['draft_version'] = 1; $data['source_preparation'] = ['id' => $row->id, 'version' => $row->version];
|
||||
$encoded = json_encode($data, JSON_THROW_ON_ERROR);
|
||||
$id = DB::table('doc_records')->insertGetId($scope + ['kind' => 'billing_drafts', 'record_id' => $billing, 'version' => 1, 'data' => $encoded, 'created_at' => now(), 'updated_at' => now()]);
|
||||
|
||||
Reference in New Issue
Block a user