@@ -0,0 +1,97 @@
|
||||
import { controlClass } from '@/components/procurement';
|
||||
|
||||
export type BudgetDistributionInput = {
|
||||
allocation_key: string;
|
||||
line_id: number;
|
||||
centre_id: number;
|
||||
subtotal: string;
|
||||
total: string;
|
||||
};
|
||||
export type BudgetDistributionOption = BudgetDistributionInput & {
|
||||
line_label: string;
|
||||
centre_label: string;
|
||||
};
|
||||
|
||||
export default function BudgetDistributionFields({
|
||||
options,
|
||||
rows,
|
||||
onChange,
|
||||
reason,
|
||||
onReason,
|
||||
}: {
|
||||
options: BudgetDistributionOption[];
|
||||
rows: BudgetDistributionInput[];
|
||||
onChange: (rows: BudgetDistributionInput[]) => void;
|
||||
reason: string;
|
||||
onReason: (reason: string) => void;
|
||||
}) {
|
||||
return (
|
||||
<fieldset className="space-y-4 rounded border p-4">
|
||||
<legend>Distribuição explícita em MZN</legend>
|
||||
<p className="text-sm">
|
||||
Confira o valor sem IVA e o total de cada parcela com o
|
||||
documento actual. As parcelas conservam os artigos e centros
|
||||
aprovados. Nenhuma diferença será distribuída automaticamente.
|
||||
</p>
|
||||
{rows.map((row, index) => {
|
||||
const option = options.find(
|
||||
(item) => item.allocation_key === row.allocation_key,
|
||||
);
|
||||
return (
|
||||
<fieldset
|
||||
key={row.allocation_key}
|
||||
className="grid gap-3 sm:grid-cols-2"
|
||||
>
|
||||
<legend className="text-sm font-medium">
|
||||
{option?.line_label} · {option?.centre_label}
|
||||
</legend>
|
||||
{(['subtotal', 'total'] as const).map((field) => (
|
||||
<label key={field}>
|
||||
{field === 'subtotal'
|
||||
? 'Sem IVA (MZN)'
|
||||
: 'Total (MZN)'}
|
||||
<input
|
||||
required
|
||||
inputMode="decimal"
|
||||
pattern="[0-9]+([.][0-9]{1,2})?"
|
||||
className={controlClass}
|
||||
value={row[field]}
|
||||
onChange={(event) =>
|
||||
onChange(
|
||||
rows.map((item, i) =>
|
||||
i === index
|
||||
? {
|
||||
...item,
|
||||
[field]:
|
||||
event.target
|
||||
.value,
|
||||
}
|
||||
: item,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
);
|
||||
})}
|
||||
<label>
|
||||
Motivo da imputação
|
||||
<textarea
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
className={controlClass}
|
||||
value={reason}
|
||||
onChange={(event) => onReason(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<p className="text-sm">
|
||||
Use ponto para separar os centavos. Se a referência cambial ou a
|
||||
conferência tiver mudado, os valores terão de ser novamente
|
||||
conferidos.
|
||||
</p>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { Panel } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
export type PayableInsights = {
|
||||
method: 'native_payable_positions_v1';
|
||||
coverage: {
|
||||
invoices: number;
|
||||
recognised: number;
|
||||
unrecognised: number;
|
||||
indeterminate: number;
|
||||
};
|
||||
currencies: {
|
||||
currency: string;
|
||||
count: number;
|
||||
principal_minor: string;
|
||||
confirmed_payments_minor: string;
|
||||
allocated_payments_minor: string;
|
||||
balance_minor: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export function exactMinorAmount(minor: string, currency: string): string {
|
||||
if (!/^-?\d+$/.test(minor)) return 'Indeterminado';
|
||||
const sign = minor.startsWith('-') ? '-' : '';
|
||||
const digits = minor.replace(/^-/, '').padStart(3, '0');
|
||||
const whole = digits.slice(0, -2).replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
||||
return `${sign}${whole},${digits.slice(-2)} ${currency}`;
|
||||
}
|
||||
|
||||
export function ProcurementPayableInsights({
|
||||
data,
|
||||
exportHref,
|
||||
}: {
|
||||
data: PayableInsights;
|
||||
exportHref?: string;
|
||||
}) {
|
||||
return (
|
||||
<Panel title="Posição actual das obrigações aos fornecedores">
|
||||
<div className="space-y-4 text-sm">
|
||||
<p>
|
||||
Posições financeiras reconhecidas para as facturas dos
|
||||
pedidos nos filtros actuais, incluindo todas as páginas. O
|
||||
período dos filtros refere-se à criação do pedido; os saldos
|
||||
são os actuais, na data de geração do relatório.
|
||||
</p>
|
||||
<p>
|
||||
{data.coverage.recognised} de {data.coverage.invoices}{' '}
|
||||
facturas com posição reconhecida e determinada. Por
|
||||
reconhecer: {data.coverage.unrecognised}. Posição
|
||||
indeterminada ou origem divergente:{' '}
|
||||
{data.coverage.indeterminate}.
|
||||
</p>
|
||||
{(data.coverage.unrecognised > 0 ||
|
||||
data.coverage.indeterminate > 0) && (
|
||||
<p role="status">
|
||||
Os totais seguintes abrangem apenas as posições
|
||||
determinadas. A ausência de reconhecimento ou a
|
||||
divergência não é tratada como saldo zero.
|
||||
</p>
|
||||
)}
|
||||
{data.currencies.map((row) => (
|
||||
<div
|
||||
key={row.currency}
|
||||
className="space-y-3 rounded-lg border p-4"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
{row.currency} · {row.count} obrigações
|
||||
</h3>
|
||||
<dl className="grid gap-4 sm:grid-cols-2">
|
||||
<div>
|
||||
<dt>Principal reconhecido</dt>
|
||||
<dd className="font-medium break-words">
|
||||
{exactMinorAmount(
|
||||
row.principal_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Saldo actual</dt>
|
||||
<dd className="font-medium break-words">
|
||||
{exactMinorAmount(
|
||||
row.balance_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Pagamentos históricos conferidos</dt>
|
||||
<dd className="break-words">
|
||||
{exactMinorAmount(
|
||||
row.confirmed_payments_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Liquidações imputadas</dt>
|
||||
<dd className="break-words">
|
||||
{exactMinorAmount(
|
||||
row.allocated_payments_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
))}
|
||||
{data.currencies.length === 0 && (
|
||||
<p>
|
||||
Sem posições determinadas neste âmbito para totalizar.
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
As moedas são apresentadas separadamente, sem conversão
|
||||
adicional. Os valores representam a posição actual das
|
||||
obrigações, sem estimar vencimentos ou atrasos.
|
||||
</p>
|
||||
<a className="underline" href="/obrigacoes-fornecedores">
|
||||
Conferir obrigações e respectivas origens
|
||||
</a>
|
||||
{exportHref && (
|
||||
<div>
|
||||
<Button asChild variant="outline">
|
||||
<a href={exportHref} download>
|
||||
Exportar posição actual (CSV)
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { FormErrors, Panel, controlClass } from '@/components/procurement';
|
||||
|
||||
type SavedLevel = {
|
||||
name: string;
|
||||
profile_ids: number[];
|
||||
scope: 'company' | 'department';
|
||||
min_minor: number | null;
|
||||
categories: string[];
|
||||
cost_center_ids: number[];
|
||||
};
|
||||
export type RequisitionApprovalPlan = {
|
||||
revision: number;
|
||||
enabled: boolean;
|
||||
quorum: 'one_eligible';
|
||||
levels: SavedLevel[];
|
||||
};
|
||||
type Profile = { id: number; name: string; permissions: string[] };
|
||||
const amountInput = (minor: number | null) => {
|
||||
if (minor === null) return '';
|
||||
const digits = String(minor).padStart(3, '0');
|
||||
return `${digits.slice(0, -2)}.${digits.slice(-2)}`;
|
||||
};
|
||||
const newLevel = () => ({
|
||||
name: '',
|
||||
profile_ids: [] as number[],
|
||||
scope: 'department' as 'company' | 'department',
|
||||
min_amount: '',
|
||||
categories_text: '',
|
||||
cost_center_ids: [] as number[],
|
||||
});
|
||||
|
||||
export function RequisitionApprovalSettings({
|
||||
plan,
|
||||
ready,
|
||||
profiles,
|
||||
costCenters,
|
||||
version,
|
||||
}: {
|
||||
plan?: RequisitionApprovalPlan | null;
|
||||
ready: boolean;
|
||||
profiles: Profile[];
|
||||
costCenters: { id: number; code: string; name: string }[];
|
||||
version: number;
|
||||
}) {
|
||||
const form = useForm({
|
||||
version,
|
||||
enabled: plan?.enabled ?? false,
|
||||
reason: '',
|
||||
levels:
|
||||
plan?.levels.map((level) => ({
|
||||
name: level.name,
|
||||
profile_ids: level.profile_ids,
|
||||
scope: level.scope,
|
||||
min_amount: amountInput(level.min_minor),
|
||||
categories_text: level.categories.join('\n'),
|
||||
cost_center_ids: level.cost_center_ids,
|
||||
})) ?? [],
|
||||
});
|
||||
const eligibleProfiles = profiles.filter((profile) =>
|
||||
profile.permissions.includes('requisition_approve'),
|
||||
);
|
||||
const change = (
|
||||
index: number,
|
||||
values: Partial<ReturnType<typeof newLevel>>,
|
||||
) =>
|
||||
form.setData(
|
||||
'levels',
|
||||
form.data.levels.map((level, position) =>
|
||||
position === index ? { ...level, ...values } : level,
|
||||
),
|
||||
);
|
||||
return (
|
||||
<Panel
|
||||
title="Níveis adicionais de aprovação"
|
||||
description="Conserva os controlos de chefia, Compras e Finanças definidos pelas alçadas. Pode acrescentar até cinco níveis condicionais, até oito no total. Uma pessoa elegível decide cada nível; a mesma pessoa não decide duas etapas do processo."
|
||||
>
|
||||
{!ready ? (
|
||||
<p>
|
||||
Os níveis adicionais ainda não estão disponíveis nesta
|
||||
instalação. O circuito actual permanece em vigor.
|
||||
</p>
|
||||
) : (
|
||||
<form
|
||||
className="space-y-5"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.transform((values) => ({
|
||||
version,
|
||||
enabled: values.enabled,
|
||||
reason: values.reason,
|
||||
levels: values.levels.map((level) => ({
|
||||
name: level.name,
|
||||
profile_ids: level.profile_ids,
|
||||
scope: level.scope,
|
||||
min_amount: level.min_amount || null,
|
||||
categories: level.categories_text
|
||||
.split('\n')
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean),
|
||||
cost_center_ids: level.cost_center_ids,
|
||||
})),
|
||||
}));
|
||||
form.post(
|
||||
'/administracao/parametrizacao/approval_levels',
|
||||
{ preserveScroll: true },
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<p className="text-sm">
|
||||
O plano aplica-se apenas a novas submissões. Os níveis
|
||||
já submetidos conservam o plano original; permissões,
|
||||
vigências e conflitos são sempre conferidos no momento
|
||||
da decisão. A configuração não concede funções aos
|
||||
utilizadores.
|
||||
</p>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.enabled}
|
||||
onChange={(event) =>
|
||||
form.setData('enabled', event.target.checked)
|
||||
}
|
||||
/>
|
||||
Aplicar o plano nas novas submissões
|
||||
</label>
|
||||
{eligibleProfiles.length === 0 && (
|
||||
<p>
|
||||
Configure primeiro os perfis com a competência
|
||||
«Aprovar níveis adicionais de requisições». Não são
|
||||
atribuídos automaticamente.
|
||||
</p>
|
||||
)}
|
||||
{form.data.levels.map((level, index) => (
|
||||
<fieldset
|
||||
className="min-w-0 space-y-4 rounded border p-4"
|
||||
key={index}
|
||||
>
|
||||
<legend className="px-2">
|
||||
Nível adicional {index + 1}
|
||||
</legend>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<label
|
||||
className="grid gap-2 text-sm"
|
||||
htmlFor={`approval-name-${index}`}
|
||||
>
|
||||
Designação
|
||||
<input
|
||||
id={`approval-name-${index}`}
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={120}
|
||||
value={level.name}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
name: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
className="grid gap-2 text-sm"
|
||||
htmlFor={`approval-scope-${index}`}
|
||||
>
|
||||
Âmbito
|
||||
<select
|
||||
id={`approval-scope-${index}`}
|
||||
className={controlClass}
|
||||
value={level.scope}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
scope: event.target
|
||||
.value as SavedLevel['scope'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="department">
|
||||
Do departamento da requisição
|
||||
</option>
|
||||
<option value="company">
|
||||
Da empresa
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label
|
||||
className="grid gap-2 text-sm"
|
||||
htmlFor={`approval-amount-${index}`}
|
||||
>
|
||||
Aplicar a partir de (MZN, opcional)
|
||||
<input
|
||||
id={`approval-amount-${index}`}
|
||||
className={controlClass}
|
||||
inputMode="decimal"
|
||||
value={level.min_amount}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
min_amount: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Usa a mesma base com ou sem IVA das
|
||||
alçadas. Vazio aplica-se a qualquer
|
||||
valor.
|
||||
</span>
|
||||
</label>
|
||||
<label
|
||||
className="grid gap-2 text-sm"
|
||||
htmlFor={`approval-categories-${index}`}
|
||||
>
|
||||
Categorias exactas (opcional, uma por linha)
|
||||
<textarea
|
||||
id={`approval-categories-${index}`}
|
||||
className={controlClass}
|
||||
value={level.categories_text}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
categories_text:
|
||||
event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="text-sm font-medium">
|
||||
Perfis elegíveis — basta um aprovador
|
||||
</legend>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{profiles
|
||||
.filter(
|
||||
(profile) =>
|
||||
profile.permissions.includes(
|
||||
'requisition_approve',
|
||||
) ||
|
||||
level.profile_ids.includes(
|
||||
profile.id,
|
||||
),
|
||||
)
|
||||
.map((profile) => (
|
||||
<label
|
||||
className="flex items-center gap-2 text-sm"
|
||||
key={profile.id}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={level.profile_ids.includes(
|
||||
profile.id,
|
||||
)}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
profile_ids: event
|
||||
.target.checked
|
||||
? [
|
||||
...level.profile_ids,
|
||||
profile.id,
|
||||
]
|
||||
: level.profile_ids.filter(
|
||||
(id) =>
|
||||
id !==
|
||||
profile.id,
|
||||
),
|
||||
})
|
||||
}
|
||||
/>
|
||||
{profile.name}
|
||||
{!profile.permissions.includes(
|
||||
'requisition_approve',
|
||||
) &&
|
||||
' · Sem competência de aprovação actualmente; retire da selecção ou reveja o perfil.'}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="text-sm font-medium">
|
||||
Centros de custo (vazio aplica-se a todos)
|
||||
</legend>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{costCenters.map((center) => (
|
||||
<label
|
||||
className="flex items-center gap-2 text-sm"
|
||||
key={center.id}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={level.cost_center_ids.includes(
|
||||
center.id,
|
||||
)}
|
||||
onChange={(event) =>
|
||||
change(index, {
|
||||
cost_center_ids: event
|
||||
.target.checked
|
||||
? [
|
||||
...level.cost_center_ids,
|
||||
center.id,
|
||||
]
|
||||
: level.cost_center_ids.filter(
|
||||
(id) =>
|
||||
id !==
|
||||
center.id,
|
||||
),
|
||||
})
|
||||
}
|
||||
/>
|
||||
{center.code} · {center.name}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={index === 0}
|
||||
onClick={() => {
|
||||
const levels = [...form.data.levels];
|
||||
[levels[index - 1], levels[index]] = [
|
||||
levels[index],
|
||||
levels[index - 1],
|
||||
];
|
||||
form.setData('levels', levels);
|
||||
}}
|
||||
>
|
||||
Subir nível
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'levels',
|
||||
form.data.levels.filter(
|
||||
(_, position) =>
|
||||
position !== index,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar do novo plano
|
||||
</Button>
|
||||
</div>
|
||||
</fieldset>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={form.data.levels.length >= 5}
|
||||
onClick={() =>
|
||||
form.setData('levels', [
|
||||
...form.data.levels,
|
||||
newLevel(),
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar nível
|
||||
</Button>
|
||||
<label
|
||||
className="grid gap-2 text-sm"
|
||||
htmlFor="approval-plan-reason"
|
||||
>
|
||||
Motivo da alteração
|
||||
<textarea
|
||||
id="approval-plan-reason"
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(event) =>
|
||||
form.setData('reason', event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>
|
||||
Guardar plano de aprovação
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user