Accept isolated workshop billing draft trial with documented manual evidence

This commit is contained in:
2026-10-28 19:32:10 +02:00
parent 090b7da336
commit 3932b94a16
30 changed files with 633 additions and 1 deletions
+7
View File
@@ -84,6 +84,10 @@ final class ServiceWorkflow
$old = $id ? $this->query($area, $scope)->where('id', $id)->first() : null;
if ($id) {
abort_unless($old, 403, 'Registo fora do âmbito autorizado.');
if (in_array($area, ['service_drafts','billing_drafts'], true) && \Illuminate\Support\Facades\Schema::hasTable('wb_generations')) {
$column = $area === 'service_drafts' ? 'service_draft_id' : 'billing_draft_id';
abort_if(DB::table('wb_generations')->where($column, $id)->exists(),409,'Rascunho ligado a oficina: correcção comercial própria necessária; a proposta revista não pode ser alterada por edição directa.');
}
abort_if($area === 'billing_drafts' && DB::table('b_internal_confirmations')->where('billing_draft_id', $id)->exists(), 409, 'Confirmado internamente — sem validade fiscal. O registo está bloqueado para edição.');
abort_unless((int) $old->version === (int) ($input['version'] ?? 0), 409, 'O registo mudou. Reabra-o antes de guardar.');
}
@@ -137,6 +141,9 @@ final class ServiceWorkflow
$source = null;
if ($area === 'billing_drafts') {
$sourceId = $old ? $old->source_id : $input['source_id'];
if (!$old && \Illuminate\Support\Facades\Schema::hasTable('wb_generations')) {
abort_if(DB::table('wb_generations')->where('service_draft_id', $sourceId)->exists(),409,'Prestação de oficina já convertida: não pode gerar um segundo rascunho por outro percurso.');
}
$source = DB::table('a_service_drafts')->where('tenant_id', $scope['tenant_id'])->where('company_id', $scope['company_id'])->where('unit_id', $scope['unit_id'])->where('id', $sourceId)->first();
abort_unless($source, 403, 'Prestação fora da unidade autorizada.');
$reload = ! $old || ($input['reload_source'] ?? false);