@@ -35,6 +35,8 @@ type Props = {
|
||||
canWrite: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
sourceType?: 'common_allocation';
|
||||
submitUrl?: string;
|
||||
};
|
||||
const decimal = (value: string) => {
|
||||
const digits = value.padStart(3, '0');
|
||||
@@ -44,7 +46,9 @@ const decimal = (value: string) => {
|
||||
export default function ExpenseAllocation(props: Props) {
|
||||
const payment = props.payment;
|
||||
const form = useForm(
|
||||
`expense-allocation:${props.tenantId}:${props.actorId}:${payment.id}`,
|
||||
props.sourceType === 'common_allocation'
|
||||
? `expense-allocation:common-allocation:${props.tenantId}:${props.actorId}:${payment.id}`
|
||||
: `expense-allocation:${props.tenantId}:${props.actorId}:${payment.id}`,
|
||||
{
|
||||
operation_key: '',
|
||||
version: props.current?.version || 0,
|
||||
@@ -80,12 +84,16 @@ export default function ExpenseAllocation(props: Props) {
|
||||
<Head title="Imputação da despesa por categoria" />
|
||||
<PageTitle
|
||||
title="Imputação da despesa por categoria"
|
||||
eyebrow={`Pagamento #${payment.id} · ${payment.invoice_number}`}
|
||||
eyebrow={`${props.sourceType === 'common_allocation' ? 'Afectação' : 'Pagamento'} #${payment.id} · ${payment.invoice_number}`}
|
||||
description="Finanças atribui explicitamente o pagamento confirmado às categorias das linhas da factura. A soma deve coincidir exactamente com o pagamento; o pagamento e o saldo permanecem preservados."
|
||||
/>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/pagamentos?payment_id=${payment.id}`}
|
||||
href={
|
||||
props.sourceType === 'common_allocation'
|
||||
? '/supplier-payments'
|
||||
: `/pagamentos?payment_id=${payment.id}`
|
||||
}
|
||||
>
|
||||
Voltar ao pagamento
|
||||
</Link>
|
||||
@@ -134,24 +142,28 @@ export default function ExpenseAllocation(props: Props) {
|
||||
(row) => row.amount !== '',
|
||||
),
|
||||
}));
|
||||
form.post(`/pagamentos/${payment.id}/categorias`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: (page) => {
|
||||
const saved = page.props
|
||||
.current as RecordVersion;
|
||||
const data = {
|
||||
...form.data,
|
||||
operation_key: '',
|
||||
reason: '',
|
||||
version: saved.version,
|
||||
fingerprint: page.props
|
||||
.fingerprint as string,
|
||||
};
|
||||
form.setData(data);
|
||||
form.setDefaults(data);
|
||||
form.clearErrors();
|
||||
form.post(
|
||||
props.submitUrl ??
|
||||
`/pagamentos/${payment.id}/categorias`,
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: (page) => {
|
||||
const saved = page.props
|
||||
.current as RecordVersion;
|
||||
const data = {
|
||||
...form.data,
|
||||
operation_key: '',
|
||||
reason: '',
|
||||
version: saved.version,
|
||||
fingerprint: page.props
|
||||
.fingerprint as string,
|
||||
};
|
||||
form.setData(data);
|
||||
form.setDefaults(data);
|
||||
form.clearErrors();
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
|
||||
Reference in New Issue
Block a user