301 lines
11 KiB
TypeScript
301 lines
11 KiB
TypeScript
import { Head, useForm, usePage } from '@inertiajs/react';
|
|
import {
|
|
FormErrors,
|
|
Panel,
|
|
PageTitle,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { money } from '@/types/procurement';
|
|
|
|
type Policy = {
|
|
id: number;
|
|
created_by: number;
|
|
revision: number;
|
|
status: string;
|
|
mode: string;
|
|
scope: string;
|
|
currency: string;
|
|
ceiling_minor: number;
|
|
includes_tax: boolean;
|
|
valid_from: string;
|
|
valid_until: string;
|
|
reason: string;
|
|
};
|
|
type Review = {
|
|
id: number;
|
|
investment_policy_id: number;
|
|
reviewed_by: number;
|
|
decision: string;
|
|
reason: string;
|
|
};
|
|
function Proposal({ previousId }: { previousId: number }) {
|
|
const form = useForm({
|
|
previous_id: previousId,
|
|
mode: '',
|
|
scope: '',
|
|
currency: '',
|
|
ceiling: '',
|
|
includes_tax: '',
|
|
valid_from: '',
|
|
valid_until: '',
|
|
reason: '',
|
|
});
|
|
return (
|
|
<Panel
|
|
title="Propor nova versão"
|
|
description="São necessárias duas aprovações de administradores distintos do proponente. Valores e vigência são decisões da empresa."
|
|
>
|
|
<form
|
|
className="grid gap-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.transform((d) => ({
|
|
...d,
|
|
includes_tax: d.includes_tax === '1',
|
|
}));
|
|
form.post('/regras-investimento');
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label>
|
|
Significado do limite
|
|
<select
|
|
required
|
|
className={controlClass}
|
|
value={form.data.mode}
|
|
onChange={(e) => form.setData('mode', e.target.value)}
|
|
>
|
|
<option value="">Decisão explícita</option>
|
|
<option value="ceiling">
|
|
Tecto absoluto: acima do limite, bloquear
|
|
</option>
|
|
<option disabled>
|
|
Aprovação adicional: circuito ainda por definir
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Âmbito
|
|
<select
|
|
required
|
|
className={controlClass}
|
|
value={form.data.scope}
|
|
onChange={(e) => form.setData('scope', e.target.value)}
|
|
>
|
|
<option value="">Decisão explícita</option>
|
|
<option value="process_total">
|
|
Total do processo que inclua equipamento
|
|
</option>
|
|
<option disabled>
|
|
Agregação por projecto: ainda não suportada
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Moeda
|
|
<select
|
|
required
|
|
className={controlClass}
|
|
value={form.data.currency}
|
|
onChange={(e) =>
|
|
form.setData('currency', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Seleccionar</option>
|
|
<option value="MZN">MZN</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Tecto (MZN)
|
|
<Input
|
|
required
|
|
inputMode="decimal"
|
|
value={form.data.ceiling}
|
|
onChange={(e) =>
|
|
form.setData('ceiling', e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Base de IVA
|
|
<select
|
|
required
|
|
className={controlClass}
|
|
value={form.data.includes_tax}
|
|
onChange={(e) =>
|
|
form.setData('includes_tax', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Decisão explícita</option>
|
|
<option value="1">Com IVA</option>
|
|
<option value="0">Sem IVA</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Início da vigência
|
|
<Input
|
|
required
|
|
type="date"
|
|
value={form.data.valid_from}
|
|
onChange={(e) =>
|
|
form.setData('valid_from', e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Fim da vigência
|
|
<Input
|
|
required
|
|
type="date"
|
|
value={form.data.valid_until}
|
|
onChange={(e) =>
|
|
form.setData('valid_until', e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Fundamento
|
|
<textarea
|
|
required
|
|
className="w-full rounded border p-3"
|
|
value={form.data.reason}
|
|
onChange={(e) => form.setData('reason', e.target.value)}
|
|
/>
|
|
</label>
|
|
<Button disabled={form.processing}>
|
|
Propor para duas aprovações
|
|
</Button>
|
|
</form>
|
|
</Panel>
|
|
);
|
|
}
|
|
function Decision({ id }: { id: number }) {
|
|
const form = useForm({ decision: 'approved', reason: '' });
|
|
return (
|
|
<form
|
|
className="mt-4 grid gap-3"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.post(`/regras-investimento/${id}/decidir`);
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label>
|
|
Decisão
|
|
<select
|
|
className={controlClass}
|
|
value={form.data.decision}
|
|
onChange={(e) => form.setData('decision', e.target.value)}
|
|
>
|
|
<option value="approved">Aprovar esta versão</option>
|
|
<option value="rejected">Rejeitar esta versão</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Fundamento
|
|
<textarea
|
|
required
|
|
className="w-full rounded border p-3"
|
|
value={form.data.reason}
|
|
onChange={(e) => form.setData('reason', e.target.value)}
|
|
/>
|
|
</label>
|
|
<Button disabled={form.processing}>Guardar decisão imutável</Button>
|
|
</form>
|
|
);
|
|
}
|
|
export default function Investment({
|
|
policies,
|
|
reviews,
|
|
currentPolicyId,
|
|
canManage,
|
|
}: {
|
|
policies: Policy[];
|
|
reviews: Review[];
|
|
currentPolicyId: number | null;
|
|
canManage: boolean;
|
|
}) {
|
|
const { auth } = usePage().props;
|
|
return (
|
|
<>
|
|
<Head title="Regras de investimento" />
|
|
<div className="mx-auto grid w-full max-w-6xl gap-6 p-6">
|
|
<PageTitle
|
|
eyebrow="SGC · Regras da empresa"
|
|
title="Investimento em equipamentos"
|
|
description="Tecto explícito e versionado, com duas aprovações administrativas. Não substitui validação técnica, Finanças ou disponibilidade orçamental."
|
|
/>
|
|
<p className="rounded border border-amber-300 p-4 text-sm">
|
|
Sem regra vigente, a adjudicação e emissão ficam bloqueadas.
|
|
Não há limites automáticos, dispensa de cotações ou
|
|
autorização para fraccionar aquisições. Os documentos
|
|
continuam de desenvolvimento.
|
|
</p>
|
|
<p className="text-sm">
|
|
Uma proposta pendente não substitui a regra aprovada. Uma
|
|
nova regra aprovada aplica-se a partir do início da sua
|
|
vigência. Quando uma regra mais recente entra em vigor, não
|
|
se regressa a versões anteriores se ela expirar.
|
|
Adjudicações guardam a versão aplicável; mudanças
|
|
posteriores exigem revisão do processo.
|
|
</p>
|
|
{canManage && (
|
|
<Proposal
|
|
key={policies[0]?.id ?? 0}
|
|
previousId={policies[0]?.id ?? 0}
|
|
/>
|
|
)}
|
|
{policies.map((p) => (
|
|
<Panel
|
|
key={p.id}
|
|
title={`Versão ${p.revision} · ${p.status === 'approved' ? 'Aprovada' : p.status === 'rejected' ? 'Rejeitada' : 'Pendente'}`}
|
|
>
|
|
{currentPolicyId === p.id && (
|
|
<p className="mb-3 font-semibold text-teal-700">
|
|
Regra vigente seleccionada
|
|
</p>
|
|
)}
|
|
<p>
|
|
Tecto {money(p.ceiling_minor)} ·{' '}
|
|
{p.includes_tax ? 'com IVA' : 'sem IVA'} · total do
|
|
processo com equipamento
|
|
</p>
|
|
<p>
|
|
Vigência: {p.valid_from} a {p.valid_until}
|
|
</p>
|
|
<p className="my-3 whitespace-pre-wrap">{p.reason}</p>
|
|
{reviews
|
|
.filter((r) => r.investment_policy_id === p.id)
|
|
.map((r) => (
|
|
<p
|
|
key={r.id}
|
|
className="my-2 rounded border p-3 text-sm"
|
|
>
|
|
{r.decision === 'approved'
|
|
? 'Aprovação'
|
|
: 'Rejeição'}{' '}
|
|
· Administrador #{r.reviewed_by} ·{' '}
|
|
{r.reason}
|
|
</p>
|
|
))}
|
|
{canManage &&
|
|
p.status === 'pending' &&
|
|
p.id === policies[0]?.id &&
|
|
p.created_by !== auth.user.id &&
|
|
!reviews.some(
|
|
(r) =>
|
|
r.investment_policy_id === p.id &&
|
|
r.reviewed_by === auth.user.id,
|
|
) && <Decision id={p.id} />}
|
|
</Panel>
|
|
))}
|
|
{policies.length === 0 && (
|
|
<p>Sem regras propostas nesta empresa.</p>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|