@@ -0,0 +1,871 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import {
|
||||
PageTitle,
|
||||
Panel,
|
||||
FormErrors,
|
||||
TableViewport,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
||||
|
||||
type Row = Record<string, string | number | boolean | null>;
|
||||
type Basis<T = Row> = { hash: string; rows: T[] };
|
||||
type Account = {
|
||||
id: number;
|
||||
code: string;
|
||||
label: string;
|
||||
currency: string;
|
||||
is_movement: boolean;
|
||||
};
|
||||
type Person = { id: number; name: string; email: string };
|
||||
type Page<T> = {
|
||||
data: T[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Access = Basis & {
|
||||
user: Person;
|
||||
eligible: boolean;
|
||||
person: string;
|
||||
actions: string[];
|
||||
other_actions: string[];
|
||||
identity_inconsistent: boolean;
|
||||
};
|
||||
type Props = {
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
q: string;
|
||||
users: Page<Person>;
|
||||
selectedAccess: Access | null;
|
||||
accounts: Basis<Account>;
|
||||
periods: Basis;
|
||||
rules: Basis;
|
||||
actions: Record<string, string>;
|
||||
effects: Record<string, string>;
|
||||
history: Page<{
|
||||
id: number;
|
||||
actor_id: number;
|
||||
kind: string;
|
||||
reason: string;
|
||||
before: Basis;
|
||||
after: Basis;
|
||||
created_at: string;
|
||||
}>;
|
||||
};
|
||||
type Kind = 'access' | 'account' | 'period' | 'rule';
|
||||
type Data = {
|
||||
operation_key: string;
|
||||
basis_hash: string;
|
||||
reason: string;
|
||||
user_id?: number;
|
||||
person?: string;
|
||||
actions?: string[];
|
||||
code?: string;
|
||||
label?: string;
|
||||
currency?: string;
|
||||
is_movement?: boolean;
|
||||
period_key?: string;
|
||||
starts_on?: string;
|
||||
ends_on?: string;
|
||||
rule_key?: string;
|
||||
effect_type?: string;
|
||||
valid_from?: string;
|
||||
valid_to?: string;
|
||||
debit_account_id?: string;
|
||||
credit_account_id?: string;
|
||||
};
|
||||
const base = '/administracao/financeiro';
|
||||
|
||||
function useConfigurationForm(
|
||||
kind: Kind,
|
||||
hash: string,
|
||||
identity: string,
|
||||
fields: Partial<Data>,
|
||||
clearAfterSave = true,
|
||||
) {
|
||||
const initial: Data = {
|
||||
...fields,
|
||||
operation_key: '',
|
||||
basis_hash: hash,
|
||||
reason: '',
|
||||
};
|
||||
const form = useForm<Data>(identity, initial);
|
||||
const ref = usePreparationDirty(form.isDirty);
|
||||
const current = form.data.basis_hash === hash;
|
||||
const review = () => {
|
||||
form.setData({ ...form.data, operation_key: '', basis_hash: hash });
|
||||
form.clearErrors();
|
||||
};
|
||||
const submit = (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (!current || form.processing) return;
|
||||
const operation = form.data.operation_key || crypto.randomUUID();
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({ ...data, operation_key: operation }));
|
||||
form.post(`${base}/${kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: (page) => {
|
||||
const source =
|
||||
page.props[
|
||||
kind === 'access'
|
||||
? 'selectedAccess'
|
||||
: kind === 'account'
|
||||
? 'accounts'
|
||||
: kind === 'period'
|
||||
? 'periods'
|
||||
: 'rules'
|
||||
];
|
||||
if (
|
||||
!source ||
|
||||
typeof source !== 'object' ||
|
||||
!('hash' in source) ||
|
||||
typeof source.hash !== 'string'
|
||||
)
|
||||
return;
|
||||
const next = {
|
||||
...(clearAfterSave ? initial : form.data),
|
||||
operation_key: '',
|
||||
basis_hash: source.hash,
|
||||
reason: '',
|
||||
};
|
||||
form.setData(next);
|
||||
form.setDefaults(next);
|
||||
form.clearErrors();
|
||||
},
|
||||
});
|
||||
};
|
||||
return { form, ref, current, review, submit };
|
||||
}
|
||||
|
||||
function Reason({
|
||||
value,
|
||||
change,
|
||||
id,
|
||||
}: {
|
||||
value: string;
|
||||
change: (value: string) => void;
|
||||
id: string;
|
||||
}) {
|
||||
return (
|
||||
<label className="grid gap-2" htmlFor={id}>
|
||||
Motivo da alteração
|
||||
<textarea
|
||||
className={controlClass}
|
||||
id={id}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={2000}
|
||||
value={value}
|
||||
onChange={(event) => change(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
function Review({ current, review }: { current: boolean; review: () => void }) {
|
||||
return current ? null : (
|
||||
<div
|
||||
className="rounded-lg border border-amber-300 bg-amber-50 p-4 text-amber-950"
|
||||
role="status"
|
||||
>
|
||||
<p>
|
||||
A configuração foi actualizada. Compare os dados actuais com a
|
||||
sua preparação antes de continuar.
|
||||
</p>
|
||||
<Button type="button" variant="outline" onClick={review}>
|
||||
Rever preparação com a configuração actual
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function Pagination({ page, label }: { page: Page<unknown>; label: string }) {
|
||||
return (
|
||||
<nav aria-label={label} className="flex flex-wrap gap-5">
|
||||
{page.prev_page_url && (
|
||||
<Link className="underline" href={page.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{page.next_page_url && (
|
||||
<Link className="underline" href={page.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
function Field({ label, children }: { label: string; children: ReactNode }) {
|
||||
return (
|
||||
<label className="grid min-w-0 gap-2">
|
||||
{label}
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
function AccessForm({
|
||||
access,
|
||||
labels,
|
||||
identity,
|
||||
}: {
|
||||
access: Access;
|
||||
labels: Record<string, string>;
|
||||
identity: string;
|
||||
}) {
|
||||
const state = useConfigurationForm(
|
||||
'access',
|
||||
access.hash,
|
||||
identity,
|
||||
{
|
||||
user_id: access.user.id,
|
||||
person: access.person,
|
||||
actions: access.actions,
|
||||
},
|
||||
false,
|
||||
);
|
||||
const { form } = state;
|
||||
const selected = form.data.actions ?? [];
|
||||
return (
|
||||
<form ref={state.ref} onSubmit={state.submit} className="grid gap-5">
|
||||
<h3 className="font-semibold">
|
||||
{access.user.name} · {access.user.email}
|
||||
</h3>
|
||||
<p>
|
||||
Use a mesma referência de pessoa quando duas contas de acesso
|
||||
pertencem à mesma pessoa. A revisão independente considera essa
|
||||
identidade.
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
Identidade actualmente registada:{' '}
|
||||
{access.person || 'Por definir'}. Permissões actuais:{' '}
|
||||
{access.actions
|
||||
.map((action) => labels[action] ?? action)
|
||||
.join('; ') || 'Nenhuma deste contrato'}
|
||||
.
|
||||
</p>
|
||||
{!access.eligible && (
|
||||
<p role="status">
|
||||
Este utilizador precisa de uma função de Finanças ou
|
||||
Administração em Compras internas para receber acessos. Pode
|
||||
preparar a revogação dos acessos existentes.
|
||||
</p>
|
||||
)}
|
||||
{access.identity_inconsistent && (
|
||||
<p role="status">
|
||||
Os acessos actuais contêm identidades diferentes. Confira a
|
||||
identidade antes de guardar.
|
||||
</p>
|
||||
)}
|
||||
{access.other_actions.length > 0 && (
|
||||
<p>
|
||||
Acessos de outros contratos preservados:{' '}
|
||||
{access.other_actions.join(', ')}.
|
||||
</p>
|
||||
)}
|
||||
<FormErrors errors={form.errors} />
|
||||
<Review current={state.current} review={state.review} />
|
||||
<Field label="Referência nominativa da pessoa">
|
||||
<input
|
||||
className={controlClass}
|
||||
maxLength={160}
|
||||
required={selected.length > 0}
|
||||
value={form.data.person ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('person', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<fieldset className="grid gap-3 sm:grid-cols-2">
|
||||
<legend className="mb-3 font-semibold">
|
||||
Competências expressamente atribuídas
|
||||
</legend>
|
||||
{Object.entries(labels).map(([action, label]) => (
|
||||
<label className="flex items-start gap-3" key={action}>
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={!access.eligible}
|
||||
checked={selected.includes(action)}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'actions',
|
||||
event.target.checked
|
||||
? [...selected, action]
|
||||
: selected.filter(
|
||||
(value) => value !== action,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span>{label}</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<p className="text-sm">
|
||||
Seleccione também a consulta de obrigações para conceder outros
|
||||
acessos, a consulta de pagamentos para preparar ou rever
|
||||
afectações e a consulta contabilística para actuar no diário.
|
||||
</p>
|
||||
<Reason
|
||||
id="finance-access-reason"
|
||||
value={form.data.reason}
|
||||
change={(value) => form.setData('reason', value)}
|
||||
/>
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:flex-wrap">
|
||||
<Button
|
||||
disabled={
|
||||
!state.current ||
|
||||
form.processing ||
|
||||
(!access.eligible && selected.length > 0)
|
||||
}
|
||||
>
|
||||
Guardar acessos explícitos
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => form.setData('actions', [])}
|
||||
>
|
||||
Preparar revogação deste contrato
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
Mudar a identidade ou retirar competências pode impedir a
|
||||
aplicação de propostas anteriores. O histórico e as decisões
|
||||
anteriores são preservados.
|
||||
</p>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function AccountForm({
|
||||
basis,
|
||||
identity,
|
||||
}: {
|
||||
basis: Basis<Account>;
|
||||
identity: string;
|
||||
}) {
|
||||
const state = useConfigurationForm('account', basis.hash, identity, {
|
||||
code: '',
|
||||
label: '',
|
||||
is_movement: false,
|
||||
currency: 'MZN',
|
||||
});
|
||||
const { form } = state;
|
||||
return (
|
||||
<form ref={state.ref} onSubmit={state.submit} className="grid gap-4">
|
||||
<FormErrors errors={form.errors} />
|
||||
<Review current={state.current} review={state.review} />
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field label="Código da conta">
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={80}
|
||||
value={form.data.code ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('code', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Designação">
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={200}
|
||||
value={form.data.label ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('label', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<label className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.is_movement ?? false}
|
||||
onChange={(event) =>
|
||||
form.setData('is_movement', event.target.checked)
|
||||
}
|
||||
/>
|
||||
Conta de movimento, disponível para regras de lançamento
|
||||
</label>
|
||||
<p className="text-sm">
|
||||
Este livro contabilístico utiliza MZN. Os códigos e as contas
|
||||
registadas são preservados.
|
||||
</p>
|
||||
<Reason
|
||||
id="finance-account-reason"
|
||||
value={form.data.reason}
|
||||
change={(value) => form.setData('reason', value)}
|
||||
/>
|
||||
<Button
|
||||
className="justify-self-start"
|
||||
disabled={!state.current || form.processing}
|
||||
>
|
||||
Registar conta
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function PeriodForm({ basis, identity }: { basis: Basis; identity: string }) {
|
||||
const state = useConfigurationForm('period', basis.hash, identity, {
|
||||
period_key: '',
|
||||
starts_on: '',
|
||||
ends_on: '',
|
||||
});
|
||||
const { form } = state;
|
||||
return (
|
||||
<form ref={state.ref} onSubmit={state.submit} className="grid gap-4">
|
||||
<FormErrors errors={form.errors} />
|
||||
<Review current={state.current} review={state.review} />
|
||||
<Field label="Referência do período">
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={80}
|
||||
value={form.data.period_key ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('period_key', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field label="Início">
|
||||
<input
|
||||
className={controlClass}
|
||||
type="date"
|
||||
required
|
||||
value={form.data.starts_on ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('starts_on', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Fim">
|
||||
<input
|
||||
className={controlClass}
|
||||
type="date"
|
||||
required
|
||||
value={form.data.ends_on ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('ends_on', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
Escolha um intervalo distinto dos períodos registados. O fecho
|
||||
exige conferência independente e não é alterado por este
|
||||
cadastro.
|
||||
</p>
|
||||
<Reason
|
||||
id="finance-period-reason"
|
||||
value={form.data.reason}
|
||||
change={(value) => form.setData('reason', value)}
|
||||
/>
|
||||
<Button
|
||||
className="justify-self-start"
|
||||
disabled={!state.current || form.processing}
|
||||
>
|
||||
Criar período aberto
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function RuleForm({
|
||||
basis,
|
||||
accounts,
|
||||
effects,
|
||||
identity,
|
||||
}: {
|
||||
basis: Basis;
|
||||
accounts: Account[];
|
||||
effects: Record<string, string>;
|
||||
identity: string;
|
||||
}) {
|
||||
const state = useConfigurationForm('rule', basis.hash, identity, {
|
||||
rule_key: '',
|
||||
effect_type: '',
|
||||
valid_from: '',
|
||||
valid_to: '',
|
||||
debit_account_id: '',
|
||||
credit_account_id: '',
|
||||
});
|
||||
const { form } = state;
|
||||
const movement = accounts.filter(
|
||||
(account) => account.is_movement && account.currency === 'MZN',
|
||||
);
|
||||
return (
|
||||
<form ref={state.ref} onSubmit={state.submit} className="grid gap-4">
|
||||
<FormErrors errors={form.errors} />
|
||||
<Review current={state.current} review={state.review} />
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field label="Referência da regra">
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={80}
|
||||
value={form.data.rule_key ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('rule_key', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Efeito financeiro">
|
||||
<select
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.effect_type ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('effect_type', event.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione o efeito</option>
|
||||
{Object.entries(effects).map(([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{(['debit_account_id', 'credit_account_id'] as const).map(
|
||||
(name) => (
|
||||
<Field
|
||||
key={name}
|
||||
label={
|
||||
name === 'debit_account_id'
|
||||
? 'Conta a debitar'
|
||||
: 'Conta a creditar'
|
||||
}
|
||||
>
|
||||
<select
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data[name] ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData(name, event.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Seleccione a conta de movimento
|
||||
</option>
|
||||
{movement.map((account) => (
|
||||
<option key={account.id} value={account.id}>
|
||||
{account.code} · {account.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{movement.length < 2 && (
|
||||
<p role="status">
|
||||
Registe duas contas de movimento distintas antes de definir
|
||||
a regra.
|
||||
</p>
|
||||
)}
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Field label="Vigência desde">
|
||||
<input
|
||||
className={controlClass}
|
||||
type="date"
|
||||
required
|
||||
value={form.data.valid_from ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('valid_from', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Vigência até">
|
||||
<input
|
||||
className={controlClass}
|
||||
type="date"
|
||||
required
|
||||
value={form.data.valid_to ?? ''}
|
||||
onChange={(event) =>
|
||||
form.setData('valid_to', event.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
A mesma referência cria uma nova versão. As próximas capturas
|
||||
usam essa versão; propostas afectadas exigem nova conferência.
|
||||
Os lançamentos aplicados conservam a regra e as contas
|
||||
utilizadas.
|
||||
</p>
|
||||
<Reason
|
||||
id="finance-rule-reason"
|
||||
value={form.data.reason}
|
||||
change={(value) => form.setData('reason', value)}
|
||||
/>
|
||||
<Button
|
||||
className="justify-self-start"
|
||||
disabled={
|
||||
!state.current || form.processing || movement.length < 2
|
||||
}
|
||||
>
|
||||
Registar versão da regra
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function HistoryRows({
|
||||
kind,
|
||||
rows,
|
||||
labels,
|
||||
effects,
|
||||
}: {
|
||||
kind: string;
|
||||
rows: Row[];
|
||||
labels: Record<string, string>;
|
||||
effects: Record<string, string>;
|
||||
}) {
|
||||
return rows.length === 0 ? (
|
||||
<p>Sem registos neste estado.</p>
|
||||
) : (
|
||||
<ul className="grid gap-2">
|
||||
{rows.map((row, index) => (
|
||||
<li key={index} className="break-words">
|
||||
{kind === 'configuration.access'
|
||||
? `${labels[String(row.action)] ?? row.action} · pessoa ${row.person} · utilizador #${row.user_id}`
|
||||
: kind === 'configuration.account'
|
||||
? `${row.code} · ${row.label}`
|
||||
: kind === 'configuration.period'
|
||||
? `${row.period_key} · versão ${row.version} · ${row.status} · ${row.starts_on} a ${row.ends_on}`
|
||||
: `${row.rule_key} · versão ${row.version} · ${effects[String(row.effect_type)] ?? row.effect_type} · débito #${row.debit_account_id} / crédito #${row.credit_account_id}`}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export default function FinanceConfiguration(props: Props) {
|
||||
const scope = useProcurementPreparationIdentity(
|
||||
`common-finance:${props.tenantId}:${props.actorId}`,
|
||||
);
|
||||
const [term, setTerm] = useState(props.q);
|
||||
return (
|
||||
<div className="mx-auto grid w-full max-w-6xl gap-6 p-5 lg:p-8">
|
||||
<Head title="Configuração financeira" />
|
||||
<PageTitle
|
||||
eyebrow="SGC · Administração"
|
||||
title="Configuração financeira"
|
||||
description="Defina explicitamente quem intervém e quais as contas, períodos e regras utilizados no livro da empresa. O cadastro não regista dívidas, pagamentos ou lançamentos."
|
||||
/>
|
||||
<Link className="underline" href="/administracao/parametrizacao">
|
||||
Voltar à parametrização da empresa
|
||||
</Link>
|
||||
<nav aria-label="Áreas da configuração financeira">
|
||||
<ul className="flex flex-wrap gap-4">
|
||||
{[
|
||||
['finance-access', 'Pessoas e acessos'],
|
||||
['finance-accounts', 'Plano de contas'],
|
||||
['finance-periods', 'Períodos'],
|
||||
['finance-rules', 'Regras'],
|
||||
['finance-history', 'Histórico'],
|
||||
].map(([id, label]) => (
|
||||
<li key={id}>
|
||||
<a className="underline" href={`#${id}`}>
|
||||
{label}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
<Panel
|
||||
id="finance-access"
|
||||
title="Pessoas e competências financeiras"
|
||||
description="A atribuição é nominativa. As competências de consulta, preparação, revisão e aplicação são escolhidas separadamente."
|
||||
>
|
||||
<div className="grid gap-6">
|
||||
<form
|
||||
className="flex flex-col gap-3 sm:flex-row"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
router.get(
|
||||
base,
|
||||
{ q: term },
|
||||
{ preserveScroll: true },
|
||||
);
|
||||
}}
|
||||
>
|
||||
<label className="grid flex-1 gap-2">
|
||||
Pesquisar utilizadores
|
||||
<input
|
||||
className={controlClass}
|
||||
value={term}
|
||||
maxLength={100}
|
||||
onChange={(event) =>
|
||||
setTerm(event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button className="self-start sm:self-end">
|
||||
Pesquisar
|
||||
</Button>
|
||||
</form>
|
||||
<ul className="grid gap-3 sm:grid-cols-2">
|
||||
{props.users.data.map((person) => (
|
||||
<li key={person.id}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`${base}?${new URLSearchParams({ user: String(person.id), q: props.q })}`}
|
||||
>
|
||||
{person.name} · {person.email}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Pagination
|
||||
page={props.users}
|
||||
label="Páginas dos utilizadores"
|
||||
/>
|
||||
{props.selectedAccess ? (
|
||||
<AccessForm
|
||||
key={`${scope}:access:${props.selectedAccess.user.id}`}
|
||||
access={props.selectedAccess}
|
||||
labels={props.actions}
|
||||
identity={`${scope}:access:${props.selectedAccess.user.id}`}
|
||||
/>
|
||||
) : (
|
||||
<p>
|
||||
Seleccione expressamente o utilizador a configurar.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel id="finance-accounts" title="Plano de contas próprio">
|
||||
<div className="grid gap-6">
|
||||
<AccountForm
|
||||
key={`${scope}:account`}
|
||||
identity={`${scope}:account`}
|
||||
basis={props.accounts}
|
||||
/>
|
||||
{props.accounts.rows.length > 0 && (
|
||||
<TableViewport label="Contas registadas">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2">Código</th>
|
||||
<th className="p-2">Designação</th>
|
||||
<th className="p-2">Tipo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{props.accounts.rows.map((account) => (
|
||||
<tr key={account.id}>
|
||||
<td className="p-2 break-all">
|
||||
{account.code}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
{account.label}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
{account.is_movement
|
||||
? 'Movimento'
|
||||
: 'Agrupamento'}{' '}
|
||||
· {account.currency}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableViewport>
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel id="finance-periods" title="Períodos do livro">
|
||||
<div className="grid gap-6">
|
||||
<PeriodForm
|
||||
key={`${scope}:period`}
|
||||
identity={`${scope}:period`}
|
||||
basis={props.periods}
|
||||
/>
|
||||
<HistoryRows
|
||||
kind="configuration.period"
|
||||
rows={props.periods.rows}
|
||||
labels={props.actions}
|
||||
effects={props.effects}
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel id="finance-rules" title="Regras de lançamento">
|
||||
<div className="grid gap-6">
|
||||
<RuleForm
|
||||
key={`${scope}:rule`}
|
||||
identity={`${scope}:rule`}
|
||||
basis={props.rules}
|
||||
accounts={props.accounts.rows}
|
||||
effects={props.effects}
|
||||
/>
|
||||
<HistoryRows
|
||||
kind="configuration.rule"
|
||||
rows={props.rules.rows}
|
||||
labels={props.actions}
|
||||
effects={props.effects}
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel id="finance-history" title="Histórico da configuração">
|
||||
<div className="grid gap-5">
|
||||
{props.history.data.length === 0 ? (
|
||||
<p>Sem alterações registadas neste percurso.</p>
|
||||
) : (
|
||||
props.history.data.map((event) => (
|
||||
<article
|
||||
key={event.id}
|
||||
className="grid gap-3 border-b pb-5"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
Operador #{event.actor_id} ·{' '}
|
||||
<time dateTime={event.created_at}>
|
||||
{event.created_at}
|
||||
</time>
|
||||
</h3>
|
||||
<p>{event.reason}</p>
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Conferir alteração preservada
|
||||
</summary>
|
||||
<div className="mt-3 grid gap-4 sm:grid-cols-2">
|
||||
<section>
|
||||
<h4 className="mb-2 font-semibold">
|
||||
Antes
|
||||
</h4>
|
||||
<HistoryRows
|
||||
kind={event.kind}
|
||||
rows={event.before.rows}
|
||||
labels={props.actions}
|
||||
effects={props.effects}
|
||||
/>
|
||||
</section>
|
||||
<section>
|
||||
<h4 className="mb-2 font-semibold">
|
||||
Depois
|
||||
</h4>
|
||||
<HistoryRows
|
||||
kind={event.kind}
|
||||
rows={event.after.rows}
|
||||
labels={props.actions}
|
||||
effects={props.effects}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
</details>
|
||||
</article>
|
||||
))
|
||||
)}
|
||||
<Pagination
|
||||
page={props.history}
|
||||
label="Páginas do histórico financeiro"
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -200,6 +200,7 @@ function ParameterFields({
|
||||
approvalLevels,
|
||||
approvalLevelsReady = false,
|
||||
expiryReady = false,
|
||||
financeConfigurationReady = false,
|
||||
urgentReviewsReady = false,
|
||||
requisitionCategoryOptions = {},
|
||||
companyDetails,
|
||||
@@ -234,6 +235,7 @@ function ParameterFields({
|
||||
approvalLevels?: RequisitionApprovalPlan | null;
|
||||
approvalLevelsReady?: boolean;
|
||||
expiryReady?: boolean;
|
||||
financeConfigurationReady?: boolean;
|
||||
urgentReviewsReady?: boolean;
|
||||
requisitionCategoryOptions?: Record<string, string>;
|
||||
companyDetails: CompanyDetails | null;
|
||||
@@ -502,6 +504,17 @@ function ParameterFields({
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
{financeConfigurationReady && (
|
||||
<li>
|
||||
<Link
|
||||
className="font-medium underline underline-offset-4"
|
||||
href="/administracao/financeiro"
|
||||
>
|
||||
Configuração financeira: acessos, contas e
|
||||
períodos
|
||||
</Link>
|
||||
</li>
|
||||
)}
|
||||
{urgentReviewsReady && (
|
||||
<li>
|
||||
<Link
|
||||
|
||||
Reference in New Issue
Block a user