Decisão do proprietário de 04/12/2026: o investidor não escolhe a taxa de IVA; ela decorre da actividade (CAE) do plano. Saúde privada (CAE 86), ensino privado reconhecido e formação profissional usam a taxa reduzida do artigo 17-A da Lei 22/2022; as restantes actividades usam a taxa geral. O IVA mensal das vendas mostra a taxa, a base legal e as condições da lei para o investidor confirmar. A taxa reduzida é uma versão governada própria (IVA-REDUZIDA-17A-BASE-LIQUIDA), com ficha em database/qa, registo QA por fiscal:qa-register-iva --reduced, pré-visualização QA e ligação por INVESTMOZ_IVA_REDUCED_RULE_ID/VERSION. Enquanto não estiver publicada, o IVA das actividades a 5% fica por determinar e nunca usa a taxa geral em substituição. Os resultados anteriores à taxa geral continuam actuais. Decisões e pendências da sessão registadas no manual existente. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
57 lines
3.2 KiB
PHP
57 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\InvestmentLegalSource;
|
|
use App\Models\User;
|
|
use App\Services\SimulationTaxParameterResolver;
|
|
use App\Services\SimulationTaxRuleExpression;
|
|
use App\Services\SimulationTaxRuleGovernance;
|
|
use App\Support\CheckedFile;
|
|
use App\Support\IsolatedQaDatabase;
|
|
use Illuminate\Console\Command;
|
|
|
|
/** Explicit registration: never run during migration, deployment or document import. */
|
|
class RegisterFiscalQaDraft extends Command
|
|
{
|
|
protected $signature = 'fiscal:qa-register-iva {actor : Existing QA editor ID} {source : Existing accepted legal source UUID}
|
|
{--reduced : Taxa reduzida do artigo 17-A (5%) em vez da taxa geral}';
|
|
|
|
protected $description = 'Cadastrar apenas o rascunho IVA (taxa geral ou, com --reduced, taxa do artigo 17-A) numa base QA isolada, sem publicação';
|
|
|
|
public function handle(SimulationTaxRuleGovernance $governance): int
|
|
{
|
|
abort_unless(IsolatedQaDatabase::allowsSchemaChanges(), 403, 'O cadastro deste lote só é permitido na base QA isolada.');
|
|
$actor = User::findOrFail($this->argument('actor'));
|
|
$source = InvestmentLegalSource::findOrFail($this->argument('source'));
|
|
$reduced = (bool) $this->option('reduced');
|
|
$article = $reduced ? 'Artigo 17-A' : 'Artigo 17(1)';
|
|
abort_unless($source->validation_status === 'validated' && $source->diploma === 'Lei 22/2022'
|
|
&& $source->article === $article, 422, $reduced
|
|
? 'Seleccione a referência aceite da taxa reduzida, Lei 22/2022, artigo 17-A.'
|
|
: 'Seleccione a referência aceite da taxa geral, Lei 22/2022, artigo 17(1).');
|
|
$payload = json_decode(CheckedFile::read(database_path($reduced ? 'qa/iva-reduced-17a-net-v1.json' : 'qa/iva-general-net-v1.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
$actualHash = CheckedFile::sha256(base_path('docs/investmoz/simulations/source-archive/Lei-22-2022-IVA-republicada-BR-250-2-suplemento.pdf'));
|
|
abort_unless(hash_equals($payload['source_sha256'], $actualHash), 422, 'O exemplar não corresponde ao hash da ficha.');
|
|
$payload['legal_source_id'] = (string) $source->id;
|
|
app(SimulationTaxRuleExpression::class)->validate($payload['rule_definition']);
|
|
app(SimulationTaxParameterResolver::class)->validateParameters($payload['parameters']);
|
|
$existing = $governance->listing($actor, ['rule_code' => $payload['rule_code']])->getCollection()
|
|
->firstWhere('rule_version', 1);
|
|
if ($existing) {
|
|
foreach ($payload as $field => $value) {
|
|
$stored = $existing->attributesToArray()[$field] ?? null;
|
|
abort_unless($stored == $value, 409, 'O cadastro existente difere desta ficha; não será sobrescrito.');
|
|
}
|
|
abort_unless($existing->status === 'draft', 409, 'A versão existente já não é um rascunho.');
|
|
$this->line(json_encode(['id' => $existing->id, 'status' => 'draft', 'reused' => true], JSON_THROW_ON_ERROR));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
$rule = $governance->create($actor, $payload);
|
|
$this->line(json_encode(['id' => $rule->id, 'status' => $rule->status, 'reused' => false], JSON_THROW_ON_ERROR));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|