fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,30 +1,354 @@
|
||||
import {useState} from 'react';
|
||||
import {propertyTransferBook,propertyTransferCurrent,propertyTransferReportRows,propertyTransferSource,propertyTransferTreatments,newPropertyTransfer,transferConditions,recordPropertyTransfers,savePropertyTransferBook,switchPropertyTreatment,type PropertyTransferBook,type PropertyTransferRow} from '@/lib/iva-property-transfers';
|
||||
export function SimulationPropertyTransfers({draft,onChange}:{draft:Record<string,unknown>;onChange:(field:string,value:string)=>void}){
|
||||
const[error,setError]=useState('');let book:PropertyTransferBook;
|
||||
try{book=propertyTransferBook(draft);}catch(cause){return<p role="alert">{String(cause)}</p>;}
|
||||
const save=(next:PropertyTransferBook)=>{try{onChange('modelo_a_snapshot',savePropertyTransferBook(draft,next));setError('');}catch(cause){setError(String(cause));}};
|
||||
const change=(id:string,patch:Partial<PropertyTransferRow>)=>save({...book,rows:book.rows.map(r=>r.id===id?{...r,...patch}:r)});
|
||||
return <details className="rounded border p-3"><summary>Locação vinculativa e cessão de estabelecimento</summary>
|
||||
<p>Locação:entrega material e cláusula vinculante para ambas as partes;mera opção de compra não basta. Cessão de estabelecimento:identifique conjunto autónomo e enquadramento do adquirente. Não exigibilidade3(5) não é isenção genérica.</p>
|
||||
<p>Oportunidade: {String(draft.context_opportunity??'projecto')}. Reutilize dados/documentos disponíveis,identificando apenas o âmbito aplicável.</p>
|
||||
<p className="text-sm">{propertyTransferSource}</p>{error&&<p role="alert">{error}</p>}
|
||||
<button type="button" onClick={()=>save({...book,rows:[...book.rows,newPropertyTransfer(crypto.randomUUID(),String(draft.currency??''))]})}>Acrescentar transmissão de propriedade</button>
|
||||
{book.rows.map(row=><details key={row.id} className="rounded border p-3"><summary>{row.description||'Transmissão por identificar'} — {row.period||'mês por indicar'}</summary>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label>Percurso de transmissão<select value={row.treatment} onChange={e=>change(row.id,switchPropertyTreatment(row,e.target.value))}><option value="">Por indicar</option>{propertyTransferTreatments.map(t=><option key={t.id} value={t.id}>{t.label}</option>)}</select></label>
|
||||
<label>Natureza dos dados<select value={row.origin} onChange={e=>change(row.id,{origin:e.target.value as PropertyTransferRow['origin']})}><option value="projected">Projectados / pressupostos</option><option value="effective">Efectivos declarados</option></select></label>
|
||||
{([['description','Transmissão identificada'],['operationRef','Referência da operação / pressuposto'],['operationDate','Data da operação / prevista'],['period','Mês da operação'],['documentRef','Documento / referência da previsão'],['documentDate','Data do documento / prevista'],['goodsRef','Bens e elementos identificados'],['scope','Âmbito:conjunto,operação e período'],['contractRef','Contrato/cessão e referência'],['evidence','Fundamento factual / pressupostos']] as const).map(([field,label])=><label key={field}>{label}<input className="block rounded border p-2" type={['operationDate','documentDate'].includes(field)?'date':field==='period'?'month':'text'} value={row[field]} onChange={e=>change(row.id,{[field]:e.target.value})}/></label>)}
|
||||
{row.treatment==='binding_lease'?<>
|
||||
{([['propertyClauseRef','Cláusula vinculante de transferência para ambas as partes'],['consideration','Contraprestação obtida/a obter,sem próprio IVA'],['considerationRef','Referência e composição da contraprestação'],['currency','Moeda da contraprestação']] as const).map(([field,label])=><label key={field}>{label}<input value={row[field]} onChange={e=>change(row.id,{[field]:e.target.value})}/></label>)}
|
||||
<label>Composição15(1) corresponde ao âmbito e exclui próprioIVA,sem dupla subtracção<select value={row.compositionConfirmed} onChange={e=>change(row.id,{compositionConfirmed:e.target.value as PropertyTransferRow['compositionConfirmed']})}><option value="">Por esclarecer</option><option value="yes">Sim</option><option value="no">Não</option></select></label>
|
||||
<p>Não somar rendas,preço de aquisição e valor residual automaticamente. Base por esclarecer mantém classificação separada.</p>
|
||||
</>:row.treatment&&<>{([['acquirerRef','Adquirente e enquadramento2(1)a'],['autonomousRef','Conjunto susceptível de constituir ramo independente'],['activitiesRef','Operações do adquirente que conferem direito à dedução']] as const).map(([field,label])=><label key={field}>{label}<input value={row[field]} onChange={e=>change(row.id,{[field]:e.target.value})}/></label>)}<p>Factos do enquadramento,não nova dedução concedida. Uma venda isolada de activos não demonstra o conjunto autónomo.</p></>}
|
||||
</div>
|
||||
<fieldset><legend>Condições próprias da transmissão</legend>{transferConditions(row.treatment).map(([key,label])=><label className="block" key={key}>{label}<select value={row.conditions[key]??''} onChange={e=>change(row.id,{conditions:{...row.conditions,[key]:e.target.value as ''|'yes'|'no'}})}><option value="">Por indicar</option><option value="yes">Sim</option><option value="no">Não</option></select></label>)}</fieldset>
|
||||
<p>Trocar percurso conserva dados ocultos e referências;reveja as confirmações aplicáveis.</p>
|
||||
</details>)}
|
||||
{!!book.rows.length&&<button type="button" onClick={()=>{try{save(recordPropertyTransfers(draft,book));}catch(cause){setError(String(cause));}}}>Classificar transmissões e guardar versão</button>}
|
||||
{book.result&&<><p role="status">{propertyTransferCurrent(draft,book)?'Resultados correspondentes às entradas guardadas.':'Entradas alteradas;resultado histórico conservado.Reveja e confira novamente.'} {book.history?.length??0} versões anteriores.Sem IVA,exigibilidade ou nova dedução calculados.</p><dl>{propertyTransferReportRows(draft).map(([,label,value,origin],i)=><div key={i}><dt className="font-semibold">{label}</dt><dd>{value}<small className="block">{origin}</small></dd></div>)}</dl></>}
|
||||
</details>;
|
||||
import { inputText } from '../lib/input-text.ts';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
propertyTransferBook,
|
||||
propertyTransferCurrent,
|
||||
propertyTransferReportRows,
|
||||
propertyTransferSource,
|
||||
propertyTransferTreatments,
|
||||
newPropertyTransfer,
|
||||
transferConditions,
|
||||
recordPropertyTransfers,
|
||||
savePropertyTransferBook,
|
||||
switchPropertyTreatment,
|
||||
type PropertyTransferBook,
|
||||
type PropertyTransferRow,
|
||||
} from '@/lib/iva-property-transfers';
|
||||
export function SimulationPropertyTransfers({
|
||||
draft,
|
||||
onChange,
|
||||
}: {
|
||||
draft: Record<string, unknown>;
|
||||
onChange: (field: string, value: string) => void;
|
||||
}) {
|
||||
const [error, setError] = useState('');
|
||||
let book: PropertyTransferBook;
|
||||
try {
|
||||
book = propertyTransferBook(draft);
|
||||
} catch (cause) {
|
||||
return <p role="alert">{String(cause)}</p>;
|
||||
}
|
||||
const save = (next: PropertyTransferBook) => {
|
||||
try {
|
||||
onChange(
|
||||
'modelo_a_snapshot',
|
||||
savePropertyTransferBook(draft, next),
|
||||
);
|
||||
setError('');
|
||||
} catch (cause) {
|
||||
setError(String(cause));
|
||||
}
|
||||
};
|
||||
const change = (id: string, patch: Partial<PropertyTransferRow>) =>
|
||||
save({
|
||||
...book,
|
||||
rows: book.rows.map((r) => (r.id === id ? { ...r, ...patch } : r)),
|
||||
});
|
||||
return (
|
||||
<details className="rounded border p-3">
|
||||
<summary>Locação vinculativa e cessão de estabelecimento</summary>
|
||||
<p>
|
||||
Locação:entrega material e cláusula vinculante para ambas as
|
||||
partes;mera opção de compra não basta. Cessão de
|
||||
estabelecimento:identifique conjunto autónomo e enquadramento do
|
||||
adquirente. Não exigibilidade3(5) não é isenção genérica.
|
||||
</p>
|
||||
<p>
|
||||
Oportunidade:{' '}
|
||||
{inputText(draft.context_opportunity ?? 'projecto')}. Reutilize
|
||||
dados/documentos disponíveis,identificando apenas o âmbito
|
||||
aplicável.
|
||||
</p>
|
||||
<p className="text-sm">{propertyTransferSource}</p>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
save({
|
||||
...book,
|
||||
rows: [
|
||||
...book.rows,
|
||||
newPropertyTransfer(
|
||||
crypto.randomUUID(),
|
||||
inputText(draft.currency ?? ''),
|
||||
),
|
||||
],
|
||||
})
|
||||
}
|
||||
>
|
||||
Acrescentar transmissão de propriedade
|
||||
</button>
|
||||
{book.rows.map((row) => (
|
||||
<details key={row.id} className="rounded border p-3">
|
||||
<summary>
|
||||
{row.description || 'Transmissão por identificar'} —{' '}
|
||||
{row.period || 'mês por indicar'}
|
||||
</summary>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<label>
|
||||
Percurso de transmissão
|
||||
<select
|
||||
value={row.treatment}
|
||||
onChange={(e) =>
|
||||
change(
|
||||
row.id,
|
||||
switchPropertyTreatment(
|
||||
row,
|
||||
e.target.value,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
{propertyTransferTreatments.map((t) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Natureza dos dados
|
||||
<select
|
||||
value={row.origin}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
origin: e.target
|
||||
.value as PropertyTransferRow['origin'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="projected">
|
||||
Projectados / pressupostos
|
||||
</option>
|
||||
<option value="effective">
|
||||
Efectivos declarados
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{(
|
||||
[
|
||||
['description', 'Transmissão identificada'],
|
||||
[
|
||||
'operationRef',
|
||||
'Referência da operação / pressuposto',
|
||||
],
|
||||
[
|
||||
'operationDate',
|
||||
'Data da operação / prevista',
|
||||
],
|
||||
['period', 'Mês da operação'],
|
||||
[
|
||||
'documentRef',
|
||||
'Documento / referência da previsão',
|
||||
],
|
||||
[
|
||||
'documentDate',
|
||||
'Data do documento / prevista',
|
||||
],
|
||||
['goodsRef', 'Bens e elementos identificados'],
|
||||
['scope', 'Âmbito:conjunto,operação e período'],
|
||||
['contractRef', 'Contrato/cessão e referência'],
|
||||
[
|
||||
'evidence',
|
||||
'Fundamento factual / pressupostos',
|
||||
],
|
||||
] as const
|
||||
).map(([field, label]) => (
|
||||
<label key={field}>
|
||||
{label}
|
||||
<input
|
||||
className="block rounded border p-2"
|
||||
type={
|
||||
[
|
||||
'operationDate',
|
||||
'documentDate',
|
||||
].includes(field)
|
||||
? 'date'
|
||||
: field === 'period'
|
||||
? 'month'
|
||||
: 'text'
|
||||
}
|
||||
value={row[field]}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
[field]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
{row.treatment === 'binding_lease' ? (
|
||||
<>
|
||||
{(
|
||||
[
|
||||
[
|
||||
'propertyClauseRef',
|
||||
'Cláusula vinculante de transferência para ambas as partes',
|
||||
],
|
||||
[
|
||||
'consideration',
|
||||
'Contraprestação obtida/a obter,sem próprio IVA',
|
||||
],
|
||||
[
|
||||
'considerationRef',
|
||||
'Referência e composição da contraprestação',
|
||||
],
|
||||
[
|
||||
'currency',
|
||||
'Moeda da contraprestação',
|
||||
],
|
||||
] as const
|
||||
).map(([field, label]) => (
|
||||
<label key={field}>
|
||||
{label}
|
||||
<input
|
||||
value={row[field]}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
[field]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<label>
|
||||
Composição15(1) corresponde ao âmbito e
|
||||
exclui próprioIVA,sem dupla subtracção
|
||||
<select
|
||||
value={row.compositionConfirmed}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
compositionConfirmed: e.target
|
||||
.value as PropertyTransferRow['compositionConfirmed'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por esclarecer</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não</option>
|
||||
</select>
|
||||
</label>
|
||||
<p>
|
||||
Não somar rendas,preço de aquisição e valor
|
||||
residual automaticamente. Base por
|
||||
esclarecer mantém classificação separada.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
row.treatment && (
|
||||
<>
|
||||
{(
|
||||
[
|
||||
[
|
||||
'acquirerRef',
|
||||
'Adquirente e enquadramento2(1)a',
|
||||
],
|
||||
[
|
||||
'autonomousRef',
|
||||
'Conjunto susceptível de constituir ramo independente',
|
||||
],
|
||||
[
|
||||
'activitiesRef',
|
||||
'Operações do adquirente que conferem direito à dedução',
|
||||
],
|
||||
] as const
|
||||
).map(([field, label]) => (
|
||||
<label key={field}>
|
||||
{label}
|
||||
<input
|
||||
value={row[field]}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
[field]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<p>
|
||||
Factos do enquadramento,não nova dedução
|
||||
concedida. Uma venda isolada de activos
|
||||
não demonstra o conjunto autónomo.
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Condições próprias da transmissão</legend>
|
||||
{transferConditions(row.treatment).map(
|
||||
([key, label]) => (
|
||||
<label className="block" key={key}>
|
||||
{label}
|
||||
<select
|
||||
value={row.conditions[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
change(row.id, {
|
||||
conditions: {
|
||||
...row.conditions,
|
||||
[key]: e.target.value as
|
||||
| ''
|
||||
| 'yes'
|
||||
| 'no',
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não</option>
|
||||
</select>
|
||||
</label>
|
||||
),
|
||||
)}
|
||||
</fieldset>
|
||||
<p>
|
||||
Trocar percurso conserva dados ocultos e
|
||||
referências;reveja as confirmações aplicáveis.
|
||||
</p>
|
||||
</details>
|
||||
))}
|
||||
{!!book.rows.length && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
try {
|
||||
save(recordPropertyTransfers(draft, book));
|
||||
} catch (cause) {
|
||||
setError(String(cause));
|
||||
}
|
||||
}}
|
||||
>
|
||||
Classificar transmissões e guardar versão
|
||||
</button>
|
||||
)}
|
||||
{book.result && (
|
||||
<>
|
||||
<p role="status">
|
||||
{propertyTransferCurrent(draft, book)
|
||||
? 'Resultados correspondentes às entradas guardadas.'
|
||||
: 'Entradas alteradas;resultado histórico conservado.Reveja e confira novamente.'}{' '}
|
||||
{book.history?.length ?? 0} versões anteriores.Sem
|
||||
IVA,exigibilidade ou nova dedução calculados.
|
||||
</p>
|
||||
<dl>
|
||||
{propertyTransferReportRows(draft).map(
|
||||
([, label, value, origin], i) => (
|
||||
<div key={i}>
|
||||
<dt className="font-semibold">{label}</dt>
|
||||
<dd>
|
||||
{value}
|
||||
<small className="block">
|
||||
{origin}
|
||||
</small>
|
||||
</dd>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</dl>
|
||||
</>
|
||||
)}
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user