377 lines
17 KiB
TypeScript
377 lines
17 KiB
TypeScript
import { inputText } from '../lib/input-text.ts';
|
|
import { useState } from 'react';
|
|
import {
|
|
newGoodsLocation,
|
|
switchGoodsTreatment,
|
|
goodsLocationBook,
|
|
goodsLocationConditions,
|
|
ownGoodsConditions,
|
|
goodsLocationCurrent,
|
|
goodsLocationReportRows,
|
|
goodsLocationSource,
|
|
goodsLocationTreatments,
|
|
recordGoodsLocations,
|
|
saveGoodsLocationBook,
|
|
type GoodsLocationBook,
|
|
type GoodsLocationRow,
|
|
} from '@/lib/iva-goods-location';
|
|
|
|
export function SimulationGoodsLocation({
|
|
draft,
|
|
onChange,
|
|
}: {
|
|
draft: Record<string, unknown>;
|
|
onChange: (field: string, value: string) => void;
|
|
}) {
|
|
const [error, setError] = useState('');
|
|
let book: GoodsLocationBook;
|
|
try {
|
|
book = goodsLocationBook(draft);
|
|
} catch (cause) {
|
|
return <p role="alert">{String(cause)}</p>;
|
|
}
|
|
const save = (next: GoodsLocationBook) => {
|
|
try {
|
|
onChange('modelo_a_snapshot', saveGoodsLocationBook(draft, next));
|
|
setError('');
|
|
} catch (cause) {
|
|
setError(String(cause));
|
|
}
|
|
};
|
|
const change = (id: string, patch: Partial<GoodsLocationRow>) =>
|
|
save({
|
|
...book,
|
|
rows: book.rows.map((row) =>
|
|
row.id === id ? { ...row, ...patch } : row,
|
|
),
|
|
});
|
|
return (
|
|
<details className="space-y-3 rounded border p-3">
|
|
<summary>
|
|
Localização — transmissões de bens e antes da importação
|
|
</summary>
|
|
<p>
|
|
Oportunidade:{' '}
|
|
{inputText(draft.context_opportunity || 'entrada geral')}.
|
|
Identifique os bens e os factos da transmissão. Com
|
|
transporte,indique onde se encontram ao iniciá-lo;sem
|
|
transporte,onde são postos à disposição. O endereço ou
|
|
nacionalidade do cliente não substituem estes factos.
|
|
</p>
|
|
<p>
|
|
Na transmissão pelo importador ou subsequente antes da
|
|
importação nacional de bens vindos do estrangeiro,confira a
|
|
regra própria6(2). A localização física anterior no estrangeiro
|
|
não a afasta por si. Fora do âmbito territorial não equivale a
|
|
isenção ou IVA zero;esta classificação não calcula imposto.
|
|
</p>
|
|
<p>{goodsLocationSource}</p>
|
|
{error && <p role="alert">{error}</p>}
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() =>
|
|
save({
|
|
...book,
|
|
rows: [
|
|
...book.rows,
|
|
newGoodsLocation(crypto.randomUUID()),
|
|
],
|
|
})
|
|
}
|
|
>
|
|
Acrescentar localização de transmissão
|
|
</button>
|
|
{book.rows.map((row) => (
|
|
<details key={row.id} className="rounded border p-3">
|
|
<summary>
|
|
{row.description || 'Operação por identificar'} —{' '}
|
|
{row.period || 'mês por indicar'}
|
|
</summary>
|
|
<div className="grid gap-3 md:grid-cols-2">
|
|
<label>
|
|
Percurso de localização dos bens
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={row.treatment}
|
|
onChange={(e) =>
|
|
change(
|
|
row.id,
|
|
switchGoodsTreatment(
|
|
row,
|
|
e.target.value,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
<option value="">Por indicar</option>
|
|
{goodsLocationTreatments.map((t) => (
|
|
<option key={t.id} value={t.id}>
|
|
{t.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Natureza dos dados
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={row.origin}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
origin: e.target
|
|
.value as GoodsLocationRow['origin'],
|
|
})
|
|
}
|
|
>
|
|
<option value="projected">
|
|
Projectados / pressupostos
|
|
</option>
|
|
<option value="effective">
|
|
Efectivos declarados
|
|
</option>
|
|
</select>
|
|
</label>
|
|
{(
|
|
[
|
|
[
|
|
'description',
|
|
'Bens e transmissão identificados',
|
|
],
|
|
[
|
|
'operationRef',
|
|
'Referência da operação / pressuposto',
|
|
],
|
|
[
|
|
'operationDate',
|
|
'Data da transmissão / prevista',
|
|
],
|
|
['period', 'Mês da transmissão'],
|
|
[
|
|
'documentRef',
|
|
'Documento da operação / referência da previsão',
|
|
],
|
|
[
|
|
'documentDate',
|
|
'Data do documento / prevista',
|
|
],
|
|
[
|
|
'scope',
|
|
'Âmbito: bens, operação, período e condições',
|
|
],
|
|
[
|
|
'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 &&
|
|
row.treatment !== 'goods_before_import' && (
|
|
<>
|
|
<label>
|
|
{row.treatment ===
|
|
'goods_with_transport'
|
|
? 'Local dos bens no início do transporte/expedição'
|
|
: 'Local dos bens quando postos à disposição sem transporte'}
|
|
<input
|
|
className="block rounded border p-2"
|
|
value={row.goodsPlace}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
goodsPlace: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Situação desse local face ao território
|
|
nacional
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={row.placeCountry}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
placeCountry:
|
|
e.target.value,
|
|
})
|
|
}
|
|
>
|
|
<option value="">
|
|
Por indicar
|
|
</option>
|
|
<option value="MZ">
|
|
Em Moçambique
|
|
</option>
|
|
<option value="foreign">
|
|
Fora de Moçambique
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Referência da localização dos bens /
|
|
pressuposto
|
|
<input
|
|
className="block rounded border p-2"
|
|
value={row.placeRef}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
placeRef: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
</>
|
|
)}
|
|
{[
|
|
'goods_with_transport',
|
|
'goods_before_import',
|
|
].includes(row.treatment) && (
|
|
<label>
|
|
Referência do transporte/expedição / pressuposto
|
|
<input
|
|
className="block rounded border p-2"
|
|
value={row.transportRef}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
transportRef: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
)}
|
|
{row.treatment === 'goods_before_import' && (
|
|
<>
|
|
<label>
|
|
Referência da importação nacional /
|
|
pressuposto
|
|
<input
|
|
className="block rounded border p-2"
|
|
value={row.importRef}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
importRef: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Importador/cadeia e posição desta
|
|
transmissão
|
|
<input
|
|
className="block rounded border p-2"
|
|
value={row.chainRef}
|
|
onChange={(e) =>
|
|
change(row.id, {
|
|
chainRef: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
</>
|
|
)}
|
|
</div>
|
|
<p>
|
|
Mudar percurso conserva os locais e referências,mas
|
|
exige rever os factos próprios. Campos sem aplicação
|
|
ficam ocultos e conservados.
|
|
</p>
|
|
<fieldset>
|
|
<legend>Factos próprios deste percurso</legend>
|
|
{[
|
|
...goodsLocationConditions,
|
|
...ownGoodsConditions(row.treatment),
|
|
].map(([key, label]) => (
|
|
<label className="block" key={key}>
|
|
{label}
|
|
<select
|
|
className="block rounded border p-2"
|
|
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>
|
|
</details>
|
|
))}
|
|
{!!book.rows.length && (
|
|
<button
|
|
type="button"
|
|
className="rounded bg-emerald-800 p-2 text-white"
|
|
onClick={() => {
|
|
try {
|
|
save(recordGoodsLocations(draft, book));
|
|
} catch (cause) {
|
|
setError(String(cause));
|
|
}
|
|
}}
|
|
>
|
|
Classificar localização e guardar versão
|
|
</button>
|
|
)}
|
|
{book.result && (
|
|
<>
|
|
<p role="status">
|
|
{goodsLocationCurrent(draft, book)
|
|
? 'Localizações correspondentes às entradas guardadas.'
|
|
: 'Entradas alteradas;localizações históricas conservadas. Reveja e classifique novamente.'}{' '}
|
|
{book.history?.length ?? 0} versões anteriores.
|
|
Classificação não determina isenção,IVA ou campo11.
|
|
</p>
|
|
<dl>
|
|
{goodsLocationReportRows(draft).map(
|
|
([, label, value, origin], index) => (
|
|
<div key={index}>
|
|
<dt className="font-semibold">{label}</dt>
|
|
<dd>
|
|
{value}
|
|
<small className="block">
|
|
{origin}
|
|
</small>
|
|
</dd>
|
|
</div>
|
|
),
|
|
)}
|
|
</dl>
|
|
</>
|
|
)}
|
|
</details>
|
|
);
|
|
}
|