@@ -33,6 +33,14 @@ type Version = {
|
||||
reason: string;
|
||||
data: { budget_id: number; components: Component[] };
|
||||
snapshot: {
|
||||
legal_sources?: Record<
|
||||
string,
|
||||
{
|
||||
estimate_id: number;
|
||||
estimate_version: number;
|
||||
charge_key: string;
|
||||
}
|
||||
>;
|
||||
plan: {
|
||||
complete: boolean;
|
||||
budget_amount_minor: number | null;
|
||||
@@ -47,6 +55,23 @@ type Page<T> = {
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
legalAmounts?: {
|
||||
id: number;
|
||||
version: number;
|
||||
snapshot: {
|
||||
item: { description: string };
|
||||
legal_rule: { data: { official_reference: string } };
|
||||
result: {
|
||||
lines: {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
amount_minor: number | null;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
}[];
|
||||
requisition: {
|
||||
id: number;
|
||||
number: string;
|
||||
@@ -105,6 +130,12 @@ export default function ImportEstimate(props: Props) {
|
||||
subtotal: estimateMoney(row.subtotal_minor),
|
||||
tax: estimateMoney(row.tax_minor),
|
||||
total: estimateMoney(row.total_minor),
|
||||
legal_estimate_id:
|
||||
latest?.snapshot.legal_sources?.[row.key]?.estimate_id ??
|
||||
(null as number | null),
|
||||
legal_charge_key:
|
||||
latest?.snapshot.legal_sources?.[row.key]?.charge_key ??
|
||||
(null as string | null),
|
||||
})),
|
||||
},
|
||||
);
|
||||
@@ -185,6 +216,25 @@ export default function ImportEstimate(props: Props) {
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
legal_sources: Object.fromEntries(
|
||||
data.components
|
||||
.filter(
|
||||
(row) =>
|
||||
row.legal_estimate_id !==
|
||||
null &&
|
||||
row.legal_charge_key !==
|
||||
null,
|
||||
)
|
||||
.map((row) => [
|
||||
row.key,
|
||||
{
|
||||
estimate_id:
|
||||
row.legal_estimate_id,
|
||||
charge_key:
|
||||
row.legal_charge_key,
|
||||
},
|
||||
]),
|
||||
),
|
||||
operation_key: operation,
|
||||
components: data.components.map((row) => ({
|
||||
key: row.key,
|
||||
@@ -260,6 +310,174 @@ export default function ImportEstimate(props: Props) {
|
||||
<legend>
|
||||
{labels[row.kind] ?? row.kind}
|
||||
</legend>
|
||||
{((props.legalAmounts?.length ?? 0) > 0 ||
|
||||
row.legal_estimate_id !== null) && (
|
||||
<label className="grid gap-1">
|
||||
Reutilizar uma imposição calculada
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
row.legal_estimate_id ===
|
||||
null
|
||||
? ''
|
||||
: `${row.legal_estimate_id}:${row.legal_charge_key}`
|
||||
}
|
||||
onChange={(event) => {
|
||||
const candidates = (
|
||||
props.legalAmounts ?? []
|
||||
).flatMap((estimate) =>
|
||||
estimate.snapshot.result.lines
|
||||
.filter(
|
||||
(line) =>
|
||||
line.kind ===
|
||||
row.kind,
|
||||
)
|
||||
.map((line) => ({
|
||||
estimate,
|
||||
line,
|
||||
value: `${estimate.id}:${line.key}`,
|
||||
})),
|
||||
);
|
||||
const selected =
|
||||
candidates.find(
|
||||
(candidate) =>
|
||||
candidate.value ===
|
||||
event.target
|
||||
.value,
|
||||
);
|
||||
form.setData(
|
||||
'components',
|
||||
form.data.components.map(
|
||||
(component, at) =>
|
||||
at !== index
|
||||
? component
|
||||
: selected
|
||||
? {
|
||||
...component,
|
||||
legal_estimate_id:
|
||||
selected
|
||||
.estimate
|
||||
.id,
|
||||
legal_charge_key:
|
||||
selected
|
||||
.line
|
||||
.key,
|
||||
status:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
null
|
||||
? 'unknown'
|
||||
: selected
|
||||
.line
|
||||
.method ===
|
||||
'not_applicable'
|
||||
? 'not_applicable'
|
||||
: 'known',
|
||||
basis: `Estimativa legal #${selected.estimate.id}, versão ${selected.estimate.version}; ${selected.line.label}. Fonte: ${selected.estimate.snapshot.legal_rule.data.official_reference}.`,
|
||||
total: estimateMoney(
|
||||
selected
|
||||
.line
|
||||
.amount_minor,
|
||||
),
|
||||
subtotal:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
0
|
||||
? '0.00'
|
||||
: '',
|
||||
tax:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
0
|
||||
? '0.00'
|
||||
: '',
|
||||
}
|
||||
: {
|
||||
...component,
|
||||
legal_estimate_id:
|
||||
null,
|
||||
legal_charge_key:
|
||||
null,
|
||||
},
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Pressuposto manual / retirar
|
||||
ligação e conservar os
|
||||
valores
|
||||
</option>
|
||||
{row.legal_estimate_id !==
|
||||
null &&
|
||||
!(
|
||||
props.legalAmounts ?? []
|
||||
).some(
|
||||
(estimate) =>
|
||||
estimate.id ===
|
||||
row.legal_estimate_id,
|
||||
) && (
|
||||
<option
|
||||
value={`${row.legal_estimate_id}:${row.legal_charge_key}`}
|
||||
>
|
||||
Versão preservada da
|
||||
estimativa #
|
||||
{
|
||||
row.legal_estimate_id
|
||||
}
|
||||
</option>
|
||||
)}
|
||||
{(
|
||||
props.legalAmounts ?? []
|
||||
).flatMap((estimate) =>
|
||||
estimate.snapshot.result.lines
|
||||
.filter(
|
||||
(line) =>
|
||||
line.kind ===
|
||||
row.kind,
|
||||
)
|
||||
.map((line) => (
|
||||
<option
|
||||
key={`${estimate.id}:${line.key}`}
|
||||
value={`${estimate.id}:${line.key}`}
|
||||
>
|
||||
{
|
||||
estimate
|
||||
.snapshot
|
||||
.item
|
||||
.description
|
||||
}{' '}
|
||||
· {line.label} ·
|
||||
estimativa #
|
||||
{estimate.id} v
|
||||
{
|
||||
estimate.version
|
||||
}{' '}
|
||||
·{' '}
|
||||
{line.amount_minor ===
|
||||
null
|
||||
? 'Por determinar'
|
||||
: `${estimateMoney(line.amount_minor)} MZN`}
|
||||
</option>
|
||||
)),
|
||||
)}
|
||||
</select>
|
||||
{row.legal_estimate_id !== null && (
|
||||
<span>
|
||||
O total conserva a fonte
|
||||
seleccionada. Indique
|
||||
explicitamente a divisão
|
||||
entre base e imposto segundo
|
||||
o orçamento. Para alterar o
|
||||
montante, retire primeiro a
|
||||
ligação.
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
)}
|
||||
<label className="grid gap-1">
|
||||
Situação
|
||||
<select
|
||||
@@ -366,6 +584,54 @@ export default function ImportEstimate(props: Props) {
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={
|
||||
form.data.components.length >=
|
||||
100
|
||||
}
|
||||
onClick={() =>
|
||||
form.setData('components', [
|
||||
...form.data.components,
|
||||
{
|
||||
key: crypto.randomUUID(),
|
||||
kind: row.kind,
|
||||
status: 'unknown',
|
||||
basis: '',
|
||||
subtotal: '',
|
||||
tax: '',
|
||||
total: '',
|
||||
legal_estimate_id: null,
|
||||
legal_charge_key: null,
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar parcela desta família
|
||||
</Button>
|
||||
{form.data.components.filter(
|
||||
(component) =>
|
||||
component.kind === row.kind,
|
||||
).length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'components',
|
||||
form.data.components.filter(
|
||||
(_, at) =>
|
||||
at !== index,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar parcela da preparação
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</fieldset>
|
||||
))}
|
||||
<label className="grid gap-1">
|
||||
|
||||
Reference in New Issue
Block a user