@@ -2,6 +2,7 @@ import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import {
|
||||
ActionBar,
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
@@ -245,7 +246,7 @@ export default function Distributions({
|
||||
para separar os centavos. Nenhuma diferença será
|
||||
compensada automaticamente.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<ActionBar>
|
||||
<Button disabled={form.processing || rows.length === 0}>
|
||||
Guardar distribuição
|
||||
</Button>
|
||||
@@ -254,7 +255,7 @@ export default function Distributions({
|
||||
Voltar ao pedido
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</ActionBar>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Deadline = {
|
||||
state: string;
|
||||
step_id: number | null;
|
||||
expires_at: string | null;
|
||||
started_at?: string;
|
||||
reminder_at?: string | null;
|
||||
escalation_at?: string | null;
|
||||
basis_hash: string | null;
|
||||
};
|
||||
type Props = {
|
||||
requisition: {
|
||||
id: number;
|
||||
number: string;
|
||||
status: string;
|
||||
process_version: number;
|
||||
approval_cycle: number;
|
||||
};
|
||||
deadline: Deadline;
|
||||
canExpire: boolean;
|
||||
canEdit: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
history: {
|
||||
data: {
|
||||
id: number;
|
||||
data: { cycle: number; next_cycle: number };
|
||||
reason: string;
|
||||
request: { number: string };
|
||||
steps: {
|
||||
id: number;
|
||||
position: number;
|
||||
role: string;
|
||||
decision: string;
|
||||
}[];
|
||||
}[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
inactive: 'Sem etapa pendente',
|
||||
unconfigured: 'Sem prazo configurado',
|
||||
unverified: 'Datas por conferir',
|
||||
running: 'Em prazo',
|
||||
expired: 'Prazo terminado',
|
||||
};
|
||||
const time = (value?: string | null) =>
|
||||
value ? new Date(value).toLocaleString('pt-MZ') : 'Por indicar';
|
||||
export default function Expiry(props: Props) {
|
||||
const r = props.requisition;
|
||||
const form = useForm(`expiry:${props.tenantId}:${props.actorId}:${r.id}`, {
|
||||
operation_key: '',
|
||||
process_version: r.process_version,
|
||||
basis_hash: props.deadline.basis_hash || '',
|
||||
comment: '',
|
||||
});
|
||||
const current =
|
||||
form.data.process_version === r.process_version &&
|
||||
form.data.basis_hash === (props.deadline.basis_hash || '');
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
const node = ref.current;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: form.isDirty },
|
||||
}),
|
||||
);
|
||||
return () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: false },
|
||||
}),
|
||||
);
|
||||
};
|
||||
}, [form.isDirty]);
|
||||
return (
|
||||
<div className="mx-auto grid w-full max-w-6xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<Head title="Prazos da aprovação" />
|
||||
<PageTitle
|
||||
eyebrow={r.number}
|
||||
title="Prazos da aprovação"
|
||||
description="A política preservada na submissão determina os prazos de cada etapa. A devolução mantém o pedido e o histórico para nova submissão pelo requisitante."
|
||||
/>
|
||||
<Link className="underline" href={`/requisicoes/${r.id}`}>
|
||||
Voltar à requisição
|
||||
</Link>
|
||||
<Panel
|
||||
title={`${labels[props.deadline.state] || 'Por conferir'} · ciclo ${r.approval_cycle}`}
|
||||
>
|
||||
<dl className="grid gap-3 text-sm">
|
||||
<div>
|
||||
<dt>Início da etapa</dt>
|
||||
<dd>{time(props.deadline.started_at)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Expiração</dt>
|
||||
<dd>{time(props.deadline.expires_at)}</dd>
|
||||
</div>
|
||||
{props.deadline.reminder_at && (
|
||||
<div>
|
||||
<dt>Lembrete previsto</dt>
|
||||
<dd>{time(props.deadline.reminder_at)}</dd>
|
||||
</div>
|
||||
)}
|
||||
{props.deadline.escalation_at && (
|
||||
<div>
|
||||
<dt>Escalamento previsto</dt>
|
||||
<dd>{time(props.deadline.escalation_at)}</dd>
|
||||
</div>
|
||||
)}
|
||||
</dl>
|
||||
<p className="mt-4 text-sm text-muted-foreground">
|
||||
Os prazos usam minutos corridos desde a activação da etapa.
|
||||
Uma alteração posterior da política não reescreve o ciclo já
|
||||
submetido.
|
||||
</p>
|
||||
<Button
|
||||
className="mt-4"
|
||||
variant="outline"
|
||||
onClick={() => router.reload()}
|
||||
>
|
||||
Actualizar conferência do prazo
|
||||
</Button>
|
||||
</Panel>
|
||||
{props.canExpire && (
|
||||
<Panel
|
||||
title="Devolver o pedido vencido"
|
||||
description="A reserva remanescente deste ciclo é libertada pelo percurso orçamental. As aprovações anteriores ficam no histórico e a nova submissão exige novas etapas."
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
form.data.operation_key || crypto.randomUUID();
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
operation_key: operation,
|
||||
}));
|
||||
form.post(`/requisicoes/${r.id}/expiracao`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{!current && (
|
||||
<div className="space-y-2">
|
||||
<p>
|
||||
A etapa mudou. Reveja a conferência actual
|
||||
antes de devolver.
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
process_version: r.process_version,
|
||||
basis_hash:
|
||||
props.deadline.basis_hash || '',
|
||||
operation_key: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
Preparar devolução da etapa actual
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<label className="grid gap-2">
|
||||
Comentário adicional, quando necessário
|
||||
<textarea
|
||||
className={controlClass}
|
||||
maxLength={2000}
|
||||
value={form.data.comment}
|
||||
onChange={(event) =>
|
||||
form.setData('comment', event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing || !current}>
|
||||
Devolver ao requisitante
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
)}
|
||||
{props.canEdit && (
|
||||
<Panel title="Pedido devolvido para preparação">
|
||||
<p>
|
||||
Reveja os dados do rascunho e submeta novamente quando
|
||||
estiver preparado. O ciclo anterior permanece no
|
||||
histórico.
|
||||
</p>
|
||||
<Button className="mt-3" asChild>
|
||||
<Link href={`/requisicoes/${r.id}/editar`}>
|
||||
Rever rascunho
|
||||
</Link>
|
||||
</Button>
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Ciclos anteriores">
|
||||
{props.history.data.length === 0 && (
|
||||
<p>Ainda não há devoluções por expiração registadas.</p>
|
||||
)}
|
||||
{props.history.data.map((row) => (
|
||||
<article
|
||||
key={row.id}
|
||||
className="space-y-2 border-b py-4 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
Ciclo {row.data.cycle} · devolvido para o ciclo{' '}
|
||||
{row.data.next_cycle}
|
||||
</h3>
|
||||
<p>{row.reason}</p>
|
||||
<ul>
|
||||
{row.steps.map((step) => (
|
||||
<li key={step.id}>
|
||||
Etapa {step.position}:{' '}
|
||||
{step.decision === 'approved'
|
||||
? 'Aprovação preservada'
|
||||
: 'Etapa pendente no momento da devolução'}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</article>
|
||||
))}
|
||||
<nav className="mt-3 flex gap-4" aria-label="Ciclos anteriores">
|
||||
{props.history.prev_page_url && (
|
||||
<Link href={props.history.prev_page_url}>Anterior</Link>
|
||||
)}
|
||||
{props.history.next_page_url && (
|
||||
<Link href={props.history.next_page_url}>Seguinte</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import { Plus, Save, Trash2 } from 'lucide-react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
ActionBar,
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
@@ -718,7 +719,7 @@ export default function RequisitionForm({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex justify-end">
|
||||
<ActionBar align="end" className="mt-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
@@ -738,7 +739,7 @@ export default function RequisitionForm({
|
||||
<Trash2 className="size-4" />
|
||||
Remover linha
|
||||
</Button>
|
||||
</div>
|
||||
</ActionBar>
|
||||
</fieldset>
|
||||
))}
|
||||
</div>
|
||||
@@ -779,7 +780,7 @@ export default function RequisitionForm({
|
||||
O servidor confirma os cálculos ao guardar.
|
||||
</p>
|
||||
</Panel>
|
||||
<div className="flex justify-end gap-3">
|
||||
<ActionBar align="end">
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
href={
|
||||
@@ -801,7 +802,7 @@ export default function RequisitionForm({
|
||||
<Save className="size-4" />
|
||||
Guardar rascunho
|
||||
</Button>
|
||||
</div>
|
||||
</ActionBar>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Check, Circle, Pencil, Send } from 'lucide-react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import {
|
||||
ActionBar,
|
||||
TableViewport,
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
@@ -35,6 +37,10 @@ const actions: Record<string, string> = {
|
||||
'budget.distribution_cancel': 'Compromisso distribuído cancelado',
|
||||
'budget.distribution_amended': 'Compromisso reafectado por Finanças',
|
||||
'requisition.submitted': 'Pedido submetido',
|
||||
'requisition.expired_returned': 'Pedido devolvido por expiração',
|
||||
'budget.cycle_opened': 'Novo ciclo orçamental preparado',
|
||||
'budget.cycle_closed':
|
||||
'Ciclo orçamental encerrado após libertação da reserva',
|
||||
'approval.approved': 'Etapa aprovada',
|
||||
'approval.rejected': 'Pedido rejeitado',
|
||||
};
|
||||
@@ -56,9 +62,11 @@ export default function Show({
|
||||
importTariffsReady = false,
|
||||
importEstimatesReady = false,
|
||||
capitalRegisterReady = false,
|
||||
expiryReady = false,
|
||||
}: {
|
||||
importEstimatesReady?: boolean;
|
||||
capitalRegisterReady?: boolean;
|
||||
expiryReady?: boolean;
|
||||
importTariffsReady?: boolean;
|
||||
canPrepareDistributions?: boolean;
|
||||
requisition: Requisition;
|
||||
@@ -176,6 +184,13 @@ export default function Show({
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{expiryReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/prazos`}>
|
||||
Prazos e ciclos da aprovação
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{importEstimatesReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link
|
||||
@@ -384,7 +399,7 @@ export default function Show({
|
||||
Confira o pedido antes de o enviar para
|
||||
aprovação.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<ActionBar>
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/editar`}>
|
||||
<Pencil className="size-4" />
|
||||
@@ -402,7 +417,7 @@ export default function Show({
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
</div>
|
||||
</ActionBar>
|
||||
</div>
|
||||
))}
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
@@ -460,7 +475,7 @@ export default function Show({
|
||||
title="Artigos e valores"
|
||||
description="Moeda: MZN · Montantes estimados"
|
||||
>
|
||||
<div className="overflow-x-auto">
|
||||
<TableViewport>
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b text-xs text-muted-foreground">
|
||||
<tr>
|
||||
@@ -544,7 +559,7 @@ export default function Show({
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</TableViewport>
|
||||
<dl className="mt-5 ml-auto max-w-xs space-y-3 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<dt>Subtotal sem IVA</dt>
|
||||
|
||||
Reference in New Issue
Block a user