@@ -0,0 +1,507 @@
|
||||
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';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
|
||||
type Account = {
|
||||
id: number;
|
||||
code: string;
|
||||
label: string;
|
||||
currency: string;
|
||||
source_hash: string;
|
||||
};
|
||||
type Allocation = {
|
||||
account: Account;
|
||||
subtotal_minor: string;
|
||||
total_minor: string;
|
||||
};
|
||||
type Version = {
|
||||
id: number;
|
||||
version: number;
|
||||
reason: string;
|
||||
data: { requisition_item_id: number; allocations: Allocation[] };
|
||||
};
|
||||
type Page<T> = {
|
||||
data: T[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
requisition: { id: number; number: string; status: string };
|
||||
items: {
|
||||
id: number;
|
||||
description: string;
|
||||
subtotal_minor: string;
|
||||
total_minor: string;
|
||||
basis_hash: string;
|
||||
}[];
|
||||
current: Version[];
|
||||
history: Page<Version>;
|
||||
accounts: Page<Account> | null;
|
||||
canWrite: boolean;
|
||||
search: string;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
};
|
||||
type InputAllocation = {
|
||||
account_id: number;
|
||||
source_hash: string;
|
||||
label: string;
|
||||
subtotal: string;
|
||||
total: string;
|
||||
};
|
||||
|
||||
export default function RequisitionAccounts(props: Props) {
|
||||
const url = `/requisicoes/${props.requisition.id}/contas`;
|
||||
const form = useForm(
|
||||
`req-accounts:${props.tenantId}:${props.actorId}:${props.requisition.id}`,
|
||||
{
|
||||
item_id: '',
|
||||
basis_hash: '',
|
||||
version: 0,
|
||||
reason: '',
|
||||
operation_key: '',
|
||||
allocations: [] as InputAllocation[],
|
||||
},
|
||||
);
|
||||
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]);
|
||||
const selected = props.items.find(
|
||||
(line) => String(line.id) === form.data.item_id,
|
||||
);
|
||||
const current = props.current.find(
|
||||
(row) => String(row.data.requisition_item_id) === form.data.item_id,
|
||||
);
|
||||
const choose = (id: string) => {
|
||||
if (
|
||||
form.isDirty &&
|
||||
!window.confirm('Descartar a preparação desta linha e abrir outra?')
|
||||
)
|
||||
return;
|
||||
const line = props.items.find((row) => String(row.id) === id);
|
||||
const old = props.current.find(
|
||||
(row) => String(row.data.requisition_item_id) === id,
|
||||
);
|
||||
form.setData({
|
||||
item_id: id,
|
||||
basis_hash: line?.basis_hash ?? '',
|
||||
version: old?.version ?? 0,
|
||||
reason: '',
|
||||
operation_key: '',
|
||||
allocations: [],
|
||||
});
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Head title="Contas da requisição" />
|
||||
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Requisição de compra"
|
||||
title="Contas contabilísticas por linha"
|
||||
description={props.requisition.number}
|
||||
/>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${props.requisition.id}`}
|
||||
>
|
||||
Voltar à requisição
|
||||
</Link>
|
||||
<Panel
|
||||
title="Imputação da necessidade"
|
||||
description="Contas de movimento do núcleo comum na base própria de Compras. As parcelas são explícitas; o registo não cria lançamentos contabilísticos, pagamentos ou alterações da distribuição orçamental."
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{props.canWrite ? (
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const data = {
|
||||
...form.data,
|
||||
operation_key:
|
||||
form.data.operation_key ||
|
||||
crypto.randomUUID(),
|
||||
};
|
||||
form.setData(data);
|
||||
form.transform(() => data);
|
||||
form.post(url, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const next = {
|
||||
...data,
|
||||
version: data.version + 1,
|
||||
operation_key: '',
|
||||
};
|
||||
form.setData(next);
|
||||
form.setDefaults(next);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label className="block">
|
||||
Linha
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.item_id}
|
||||
onChange={(event) =>
|
||||
choose(event.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione a linha</option>
|
||||
{props.items.map((line) => (
|
||||
<option key={line.id} value={line.id}>
|
||||
{line.description}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{selected && (
|
||||
<p>
|
||||
Base sem IVA:{' '}
|
||||
{exactMinorAmount(
|
||||
selected.subtotal_minor,
|
||||
'MZN',
|
||||
)}{' '}
|
||||
· Total:{' '}
|
||||
{exactMinorAmount(
|
||||
selected.total_minor,
|
||||
'MZN',
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{current && (
|
||||
<div>
|
||||
<p>Versão actual: {current.version}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'allocations',
|
||||
current.data.allocations.map(
|
||||
(row) => ({
|
||||
account_id:
|
||||
row.account.id,
|
||||
source_hash:
|
||||
row.account
|
||||
.source_hash,
|
||||
label: `${row.account.code} · ${row.account.label}`,
|
||||
subtotal:
|
||||
(
|
||||
BigInt(
|
||||
row.subtotal_minor,
|
||||
) / 100n
|
||||
).toString() +
|
||||
'.' +
|
||||
(
|
||||
BigInt(
|
||||
row.subtotal_minor,
|
||||
) % 100n
|
||||
)
|
||||
.toString()
|
||||
.padStart(
|
||||
2,
|
||||
'0',
|
||||
),
|
||||
total:
|
||||
(
|
||||
BigInt(
|
||||
row.total_minor,
|
||||
) / 100n
|
||||
).toString() +
|
||||
'.' +
|
||||
(
|
||||
BigInt(
|
||||
row.total_minor,
|
||||
) % 100n
|
||||
)
|
||||
.toString()
|
||||
.padStart(
|
||||
2,
|
||||
'0',
|
||||
),
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Reutilizar parcelas actuais para revisão
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{form.data.allocations.map((row, index) => (
|
||||
<fieldset
|
||||
key={row.account_id}
|
||||
className="grid gap-3 rounded-xl border p-4 sm:grid-cols-2"
|
||||
>
|
||||
<legend className="px-2 break-words">
|
||||
{row.label}
|
||||
</legend>
|
||||
{(['subtotal', 'total'] as const).map(
|
||||
(field) => (
|
||||
<label key={field}>
|
||||
{field === 'subtotal'
|
||||
? 'Base sem IVA (MZN)'
|
||||
: 'Total com IVA (MZN)'}
|
||||
<input
|
||||
className={controlClass}
|
||||
inputMode="decimal"
|
||||
value={row[field]}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'allocations',
|
||||
form.data.allocations.map(
|
||||
(value, at) =>
|
||||
at === index
|
||||
? {
|
||||
...value,
|
||||
[field]:
|
||||
event
|
||||
.target
|
||||
.value,
|
||||
}
|
||||
: value,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
),
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
if (
|
||||
window.confirm(
|
||||
'Remover esta parcela da preparação?',
|
||||
)
|
||||
)
|
||||
form.setData(
|
||||
'allocations',
|
||||
form.data.allocations.filter(
|
||||
(_, at) => at !== index,
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
Remover parcela
|
||||
</Button>
|
||||
</fieldset>
|
||||
))}
|
||||
<label className="block">
|
||||
Motivo da imputação ou correcção
|
||||
<textarea
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'reason',
|
||||
event.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
disabled={
|
||||
form.processing ||
|
||||
!selected ||
|
||||
form.data.allocations.length === 0
|
||||
}
|
||||
>
|
||||
Guardar versão
|
||||
</Button>
|
||||
</form>
|
||||
) : (
|
||||
<p>
|
||||
Consulta das imputações preservadas; a edição
|
||||
pertence ao requisitante enquanto o pedido está em
|
||||
rascunho.
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
{props.accounts && (
|
||||
<Panel title="Escolher contas do plano de Compras">
|
||||
<form
|
||||
method="get"
|
||||
action={url}
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const search = new FormData(
|
||||
event.currentTarget,
|
||||
).get('account_search');
|
||||
router.get(
|
||||
url,
|
||||
{
|
||||
account_search:
|
||||
typeof search === 'string'
|
||||
? search
|
||||
: '',
|
||||
},
|
||||
{
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
},
|
||||
);
|
||||
}}
|
||||
className="mb-4 flex flex-wrap gap-3"
|
||||
>
|
||||
<label>
|
||||
Código ou designação
|
||||
<input
|
||||
className={controlClass}
|
||||
name="account_search"
|
||||
defaultValue={props.search}
|
||||
maxLength={100}
|
||||
/>
|
||||
</label>
|
||||
<Button variant="outline">Pesquisar contas</Button>
|
||||
</form>
|
||||
<ul className="space-y-3">
|
||||
{props.accounts.data.map((account) => (
|
||||
<li
|
||||
key={account.id}
|
||||
className="flex flex-wrap items-center justify-between gap-3 border-b pb-3"
|
||||
>
|
||||
<span>
|
||||
{account.code} · {account.label} ·{' '}
|
||||
{account.currency}
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={
|
||||
!selected ||
|
||||
form.data.allocations.length >=
|
||||
20 ||
|
||||
form.data.allocations.some(
|
||||
(row) =>
|
||||
row.account_id ===
|
||||
account.id,
|
||||
)
|
||||
}
|
||||
onClick={() =>
|
||||
form.setData('allocations', [
|
||||
...form.data.allocations,
|
||||
{
|
||||
account_id: account.id,
|
||||
source_hash:
|
||||
account.source_hash,
|
||||
label: `${account.code} · ${account.label}`,
|
||||
subtotal: '',
|
||||
total: '',
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Adicionar conta à linha
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{props.accounts.data.length === 0 && (
|
||||
<p>Sem contas de movimento nesta pesquisa.</p>
|
||||
)}
|
||||
<nav className="mt-4 flex gap-4">
|
||||
{props.accounts.prev_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
preserveScroll
|
||||
className="underline"
|
||||
href={props.accounts.prev_page_url}
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.accounts.next_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
preserveScroll
|
||||
className="underline"
|
||||
href={props.accounts.next_page_url}
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Versões preservadas">
|
||||
<ul className="space-y-4">
|
||||
{props.history.data.map((row) => (
|
||||
<li key={row.id}>
|
||||
<p>
|
||||
Linha #{row.data.requisition_item_id} ·
|
||||
Versão {row.version} · {row.reason}
|
||||
</p>
|
||||
<ul>
|
||||
{row.data.allocations.map((part) => (
|
||||
<li key={part.account.id}>
|
||||
{part.account.code} ·{' '}
|
||||
{part.account.label} · Base sem IVA:{' '}
|
||||
{exactMinorAmount(
|
||||
part.subtotal_minor,
|
||||
'MZN',
|
||||
)}{' '}
|
||||
· Total:{' '}
|
||||
{exactMinorAmount(
|
||||
part.total_minor,
|
||||
'MZN',
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<nav className="mt-4 flex gap-4">
|
||||
{props.history.prev_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
preserveScroll
|
||||
className="underline"
|
||||
href={props.history.prev_page_url}
|
||||
>
|
||||
Histórico anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.history.next_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
preserveScroll
|
||||
className="underline"
|
||||
href={props.history.next_page_url}
|
||||
>
|
||||
Histórico seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import { Head, Link, router, useForm } from "@inertiajs/react";
|
||||
import { useEffect, useRef } from "react";
|
||||
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";
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { date, money, priorityLabels, roleLabels } from '@/types/procurement';
|
||||
|
||||
type Deadline = {
|
||||
timing?: string;
|
||||
state: string;
|
||||
step_id: number | null;
|
||||
expires_at: string | null;
|
||||
@@ -36,12 +38,48 @@ type Props = {
|
||||
id: number;
|
||||
data: { cycle: number; next_cycle: number };
|
||||
reason: string;
|
||||
request: { number: string };
|
||||
created_at?: string | null;
|
||||
approval_amount_minor?: number | null;
|
||||
approval_uses_separate_basis?: boolean;
|
||||
request: {
|
||||
number: string;
|
||||
priority?: string;
|
||||
justification?: string;
|
||||
needed_by?: string | null;
|
||||
submitted_at?: string | null;
|
||||
subtotal_minor?: number | null;
|
||||
tax_minor?: number | null;
|
||||
total_minor?: number | null;
|
||||
};
|
||||
rules?: {
|
||||
first_limit_minor?: number | null;
|
||||
second_limit_minor?: number | null;
|
||||
approval_includes_tax?: boolean;
|
||||
rules_provisional?: boolean;
|
||||
routing_plan_revision?: number;
|
||||
};
|
||||
items?:
|
||||
| {
|
||||
id: number;
|
||||
description: string;
|
||||
quantity: string;
|
||||
unit: string;
|
||||
unit_price_minor?: number | null;
|
||||
tax_rate?: string | null;
|
||||
subtotal_minor?: number | null;
|
||||
tax_minor?: number | null;
|
||||
total_minor?: number | null;
|
||||
}[]
|
||||
| null;
|
||||
steps: {
|
||||
id: number;
|
||||
position: number;
|
||||
role: string;
|
||||
decision: string;
|
||||
approver_id?: number | null;
|
||||
decided_at?: string | null;
|
||||
comment?: string | null;
|
||||
routing?: { name?: string } | null;
|
||||
}[];
|
||||
}[];
|
||||
prev_page_url: string | null;
|
||||
@@ -49,40 +87,50 @@ type Props = {
|
||||
};
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
inactive: "Sem etapa pendente",
|
||||
unconfigured: "Sem prazo configurado",
|
||||
unverified: "Datas por conferir",
|
||||
running: "Em prazo",
|
||||
expired: "Prazo terminado",
|
||||
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";
|
||||
value ? new Date(value).toLocaleString('pt-MZ') : 'Por indicar';
|
||||
const pastTime = (value?: string | null) =>
|
||||
value ? time(value) : 'Não preservada';
|
||||
const historicalDecisions: Record<string, string> = {
|
||||
approved: 'Aprovação preservada',
|
||||
pending: 'Etapa pendente no momento da devolução',
|
||||
rejected: 'Rejeição preservada',
|
||||
expired: 'Etapa expirada',
|
||||
};
|
||||
const preservedMoney = (value?: number | null) =>
|
||||
value == null ? 'Não preservado' : money(value);
|
||||
export default function Expiry(props: Props) {
|
||||
const r = props.requisition;
|
||||
const check = useForm({
|
||||
operation_key: "",
|
||||
operation_key: '',
|
||||
process_version: r.process_version,
|
||||
});
|
||||
const form = useForm(`expiry:${props.tenantId}:${props.actorId}:${r.id}`, {
|
||||
operation_key: "",
|
||||
operation_key: '',
|
||||
process_version: r.process_version,
|
||||
basis_hash: props.deadline.basis_hash || "",
|
||||
comment: "",
|
||||
basis_hash: props.deadline.basis_hash || '',
|
||||
comment: '',
|
||||
});
|
||||
const current =
|
||||
form.data.process_version === r.process_version &&
|
||||
form.data.basis_hash === (props.deadline.basis_hash || "");
|
||||
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", {
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: form.isDirty },
|
||||
}),
|
||||
);
|
||||
return () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("sgc:context-dirty", {
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: false },
|
||||
}),
|
||||
);
|
||||
@@ -100,8 +148,15 @@ export default function Expiry(props: Props) {
|
||||
Voltar à requisição
|
||||
</Link>
|
||||
<Panel
|
||||
title={`${labels[props.deadline.state] || "Por conferir"} · ciclo ${r.approval_cycle}`}
|
||||
title={`${labels[props.deadline.state] || 'Por conferir'} · ciclo ${r.approval_cycle}`}
|
||||
>
|
||||
{props.deadline.timing && (
|
||||
<p className="mb-4 text-sm">
|
||||
{props.deadline.timing === 'urgent_override'
|
||||
? 'Prazos reduzidos para urgência, preservados na submissão.'
|
||||
: 'Prazos gerais da etapa, preservados na submissão.'}
|
||||
</p>
|
||||
)}
|
||||
<dl className="grid gap-3 text-sm">
|
||||
<div>
|
||||
<dt>Início da etapa</dt>
|
||||
@@ -143,7 +198,7 @@ export default function Expiry(props: Props) {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
check.data.operation_key || crypto.randomUUID();
|
||||
check.setData("operation_key", operation);
|
||||
check.setData('operation_key', operation);
|
||||
check.transform(() => ({
|
||||
operation_key: operation,
|
||||
process_version: r.process_version,
|
||||
@@ -180,7 +235,7 @@ export default function Expiry(props: Props) {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
form.data.operation_key || crypto.randomUUID();
|
||||
form.setData("operation_key", operation);
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
operation_key: operation,
|
||||
@@ -209,8 +264,8 @@ export default function Expiry(props: Props) {
|
||||
...data,
|
||||
process_version: r.process_version,
|
||||
basis_hash:
|
||||
props.deadline.basis_hash || "",
|
||||
operation_key: "",
|
||||
props.deadline.basis_hash || '',
|
||||
operation_key: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
@@ -225,7 +280,7 @@ export default function Expiry(props: Props) {
|
||||
maxLength={2000}
|
||||
value={form.data.comment}
|
||||
onChange={(event) =>
|
||||
form.setData("comment", event.target.value)
|
||||
form.setData('comment', event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
@@ -259,17 +314,171 @@ export default function Expiry(props: Props) {
|
||||
className="space-y-2 border-b py-4 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
Ciclo {row.data.cycle} · devolvido para o ciclo{" "}
|
||||
Ciclo {row.data.cycle} · devolvido para o ciclo{' '}
|
||||
{row.data.next_cycle}
|
||||
</h3>
|
||||
<p>{row.reason}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Documento preservado na devolução. As decisões e os
|
||||
valores deste ciclo não são as aprovações da nova
|
||||
submissão.
|
||||
</p>
|
||||
<dl className="grid gap-2 text-sm sm:grid-cols-2">
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Submissão original
|
||||
</dt>
|
||||
<dd>{pastTime(row.request.submitted_at)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Devolvido em
|
||||
</dt>
|
||||
<dd>{pastTime(row.created_at)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Prioridade original
|
||||
</dt>
|
||||
<dd>
|
||||
{row.request.priority
|
||||
? (priorityLabels[
|
||||
row.request.priority
|
||||
] ?? row.request.priority)
|
||||
: 'Não preservada'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Data de necessidade original
|
||||
</dt>
|
||||
<dd>
|
||||
{row.request.needed_by
|
||||
? date(row.request.needed_by)
|
||||
: 'Não preservada'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Sem IVA
|
||||
</dt>
|
||||
<dd>
|
||||
{preservedMoney(row.request.subtotal_minor)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">IVA</dt>
|
||||
<dd>{preservedMoney(row.request.tax_minor)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Total original (MZN)
|
||||
</dt>
|
||||
<dd>
|
||||
{preservedMoney(row.request.total_minor)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
{row.request.justification && (
|
||||
<p className="whitespace-pre-wrap">
|
||||
{row.request.justification}
|
||||
</p>
|
||||
)}
|
||||
<details className="rounded border p-3">
|
||||
<summary>Artigos e regras preservados</summary>
|
||||
<ul className="mt-3 space-y-3">
|
||||
{row.items?.map((item) => (
|
||||
<li key={item.id} className="break-words">
|
||||
<p>
|
||||
{item.description} · {item.quantity}{' '}
|
||||
{item.unit}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
Preço unitário:{' '}
|
||||
{preservedMoney(
|
||||
item.unit_price_minor,
|
||||
)}{' '}
|
||||
· Taxa de IVA declarada:{' '}
|
||||
{item.tax_rate == null
|
||||
? 'Não preservada'
|
||||
: `${item.tax_rate}%`}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
Sem IVA:{' '}
|
||||
{preservedMoney(
|
||||
item.subtotal_minor,
|
||||
)}{' '}
|
||||
· IVA:{' '}
|
||||
{preservedMoney(item.tax_minor)} ·
|
||||
Total:{' '}
|
||||
{preservedMoney(item.total_minor)}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{!row.items?.length && (
|
||||
<p>Artigos não preservados neste registo.</p>
|
||||
)}
|
||||
<p className="mt-3 text-sm">
|
||||
Base de aprovação:{' '}
|
||||
{row.rules?.approval_includes_tax === true
|
||||
? 'com IVA'
|
||||
: row.rules?.approval_includes_tax === false
|
||||
? 'sem IVA'
|
||||
: 'Não preservada'}
|
||||
.
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
Valor usado no encaminhamento:{' '}
|
||||
{preservedMoney(row.approval_amount_minor)}.
|
||||
</p>
|
||||
{row.approval_uses_separate_basis && (
|
||||
<p className="text-sm">
|
||||
Base adicional preservada na submissão
|
||||
original.
|
||||
</p>
|
||||
)}
|
||||
{row.rules?.routing_plan_revision != null && (
|
||||
<p className="text-sm">
|
||||
Plano de encaminhamento · versão{' '}
|
||||
{row.rules.routing_plan_revision}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-sm">
|
||||
Limites preservados:{' '}
|
||||
{preservedMoney(row.rules?.first_limit_minor)} /{' '}
|
||||
{preservedMoney(row.rules?.second_limit_minor)}.
|
||||
</p>
|
||||
{row.rules?.rules_provisional === true && (
|
||||
<p className="text-sm">
|
||||
Regras provisórias na submissão original.
|
||||
</p>
|
||||
)}
|
||||
</details>
|
||||
<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 key={step.id} className="my-3">
|
||||
Etapa {step.position}:{' '}
|
||||
{step.routing?.name ??
|
||||
roleLabels[step.role] ??
|
||||
step.role}{' '}
|
||||
·{' '}
|
||||
{historicalDecisions[step.decision] ??
|
||||
'Estado não preservado'}
|
||||
{step.approver_id != null && (
|
||||
<span>
|
||||
{' '}
|
||||
· Utilizador #{step.approver_id}
|
||||
</span>
|
||||
)}
|
||||
{step.decided_at && (
|
||||
<span> · {time(step.decided_at)}</span>
|
||||
)}
|
||||
{step.comment && (
|
||||
<p className="mt-1 whitespace-pre-wrap">
|
||||
{step.comment}
|
||||
</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -12,7 +12,8 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { money } from '@/types/procurement';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
import { requisitionEstimate } from '@/lib/requisition-estimate';
|
||||
import type { CostCenter, Requisition } from '@/types/procurement';
|
||||
import { CatalogueSearch } from '@/components/requisition-catalogue';
|
||||
import { RequisitionCategoryFields } from '@/components/requisition-category-fields';
|
||||
@@ -186,15 +187,49 @@ export default function RequisitionForm({
|
||||
i === index ? { ...item, [field]: value } : item,
|
||||
),
|
||||
);
|
||||
const estimate = form.data.items.reduce(
|
||||
(sum, i) =>
|
||||
sum +
|
||||
Math.round(
|
||||
Math.round(Number(i.quantity) * Number(i.unit_price) * 100) *
|
||||
(1 + Number(i.tax_rate) / 100),
|
||||
),
|
||||
0,
|
||||
);
|
||||
const estimate = requisitionEstimate(form.data.items);
|
||||
const validationErrors: Record<string, string> = form.errors;
|
||||
const errorAttributes = (field: string) => ({
|
||||
'aria-invalid': !!validationErrors[field],
|
||||
'aria-describedby': validationErrors[field]
|
||||
? `error-${field}`
|
||||
: undefined,
|
||||
});
|
||||
const fieldError = (field: string) =>
|
||||
validationErrors[field] ? (
|
||||
<p id={`error-${field}`} className="text-sm text-destructive">
|
||||
{validationErrors[field]}
|
||||
</p>
|
||||
) : null;
|
||||
const errorTargets: Record<string, string> = {
|
||||
cost_center_id: 'cost-center',
|
||||
priority: 'priority',
|
||||
needed_by: 'needed-by',
|
||||
justification: 'justification',
|
||||
items: 'requisition-items',
|
||||
};
|
||||
for (const error of Object.keys(form.errors)) {
|
||||
const match = /^items\.(\d+)(?:\.(.+))?$/.exec(error);
|
||||
if (!match) continue;
|
||||
const index = Number(match[1]);
|
||||
const line = form.data.items[index];
|
||||
if (!line) continue;
|
||||
const field = match[2];
|
||||
errorTargets[error] = lineFields.some(({ key }) => key === field)
|
||||
? `${field}-${line.key}`
|
||||
: field === 'purchase_type' && !line.catalogue_entry_id
|
||||
? `type-${line.key}`
|
||||
: `requisition-line-${line.key}`;
|
||||
if (Object.keys(requisitionCategories).length > 0) {
|
||||
if (field === 'procurement_category')
|
||||
errorTargets[error] = `rq-category-${index}`;
|
||||
if (
|
||||
field === 'category_reason' &&
|
||||
(line.procurement_category || line.category_reason)
|
||||
)
|
||||
errorTargets[error] = `rq-category-${index}-reason`;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Head
|
||||
@@ -212,6 +247,7 @@ export default function RequisitionForm({
|
||||
/>
|
||||
<form
|
||||
ref={formElement}
|
||||
data-preparation-dirty={preparationDirty ? 'true' : 'false'}
|
||||
data-context-save
|
||||
noValidate={incompleteDraftsAvailable}
|
||||
className="space-y-6"
|
||||
@@ -233,7 +269,7 @@ export default function RequisitionForm({
|
||||
else form.post('/requisicoes', options);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<FormErrors errors={form.errors} targets={errorTargets} />
|
||||
{incompleteDraftsAvailable && (
|
||||
<p className="rounded-lg border p-4 text-sm">
|
||||
Pode guardar esta preparação mesmo com campos em
|
||||
@@ -266,6 +302,7 @@ export default function RequisitionForm({
|
||||
</Label>
|
||||
<select
|
||||
id="cost-center"
|
||||
{...errorAttributes('cost_center_id')}
|
||||
required
|
||||
className={controlClass}
|
||||
value={form.data.cost_center_id}
|
||||
@@ -283,11 +320,13 @@ export default function RequisitionForm({
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{fieldError('cost_center_id')}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="priority">Prioridade</Label>
|
||||
<select
|
||||
id="priority"
|
||||
{...errorAttributes('priority')}
|
||||
className={controlClass}
|
||||
value={form.data.priority}
|
||||
onChange={(e) =>
|
||||
@@ -298,6 +337,7 @@ export default function RequisitionForm({
|
||||
<option value="high">Alta</option>
|
||||
<option value="urgent">Urgente</option>
|
||||
</select>
|
||||
{fieldError('priority')}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="needed-by">
|
||||
@@ -305,6 +345,7 @@ export default function RequisitionForm({
|
||||
</Label>
|
||||
<Input
|
||||
id="needed-by"
|
||||
{...errorAttributes('needed_by')}
|
||||
type="date"
|
||||
required
|
||||
value={form.data.needed_by}
|
||||
@@ -315,6 +356,7 @@ export default function RequisitionForm({
|
||||
)
|
||||
}
|
||||
/>
|
||||
{fieldError('needed_by')}
|
||||
</div>
|
||||
<div className="space-y-2 sm:col-span-3">
|
||||
<Label htmlFor="justification">
|
||||
@@ -322,6 +364,7 @@ export default function RequisitionForm({
|
||||
</Label>
|
||||
<textarea
|
||||
id="justification"
|
||||
{...errorAttributes('justification')}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={5000}
|
||||
@@ -335,6 +378,7 @@ export default function RequisitionForm({
|
||||
)
|
||||
}
|
||||
/>
|
||||
{fieldError('justification')}
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
@@ -342,12 +386,18 @@ export default function RequisitionForm({
|
||||
title="Artigos e serviços"
|
||||
description="Preços em MZN. Confira a taxa de IVA aplicável a cada artigo antes de submeter."
|
||||
>
|
||||
<div className="space-y-5">
|
||||
<div
|
||||
className="space-y-5"
|
||||
id="requisition-items"
|
||||
tabIndex={-1}
|
||||
>
|
||||
{catalogue?.ready && (
|
||||
<CatalogueSearch data={catalogue} />
|
||||
)}
|
||||
{form.data.items.map((line, index) => (
|
||||
<fieldset
|
||||
id={`requisition-line-${line.key}`}
|
||||
tabIndex={-1}
|
||||
className="rounded-lg border bg-muted/20 p-4"
|
||||
key={line.key}
|
||||
>
|
||||
@@ -504,6 +554,9 @@ export default function RequisitionForm({
|
||||
</Label>
|
||||
<Input
|
||||
id={`${key}-${line.key}`}
|
||||
{...errorAttributes(
|
||||
`items.${index}.${key}`,
|
||||
)}
|
||||
{...attributes}
|
||||
readOnly={
|
||||
!!line.catalogue_entry_id &&
|
||||
@@ -523,6 +576,9 @@ export default function RequisitionForm({
|
||||
)
|
||||
}
|
||||
/>
|
||||
{fieldError(
|
||||
`items.${index}.${key}`,
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
@@ -719,6 +775,23 @@ export default function RequisitionForm({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{Object.keys(validationErrors)
|
||||
.filter(
|
||||
(field) =>
|
||||
field.startsWith(
|
||||
`items.${index}.`,
|
||||
) &&
|
||||
!lineFields.some(
|
||||
({ key }) =>
|
||||
field ===
|
||||
`items.${index}.${key}`,
|
||||
),
|
||||
)
|
||||
.map((field) => (
|
||||
<div key={field} className="mt-2">
|
||||
{fieldError(field)}
|
||||
</div>
|
||||
))}
|
||||
<ActionBar align="end" className="mt-3">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -761,18 +834,9 @@ export default function RequisitionForm({
|
||||
<p className="text-sm">
|
||||
Total estimado com IVA{' '}
|
||||
<strong className="ml-3 text-lg">
|
||||
{money(
|
||||
form.data.items.length > 0 &&
|
||||
form.data.items.every(
|
||||
(line) =>
|
||||
line.quantity !== '' &&
|
||||
line.unit_price !== '' &&
|
||||
line.tax_rate !== '',
|
||||
) &&
|
||||
Number.isFinite(estimate)
|
||||
? estimate
|
||||
: null,
|
||||
)}
|
||||
{estimate === null
|
||||
? 'Por completar'
|
||||
: exactMinorAmount(estimate, 'MZN')}
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { Check, Circle, Pencil, Send } from 'lucide-react';
|
||||
import { Check, Circle, Pencil } from 'lucide-react';
|
||||
import {
|
||||
RequisitionSubmissionAction,
|
||||
type SubmissionPreview,
|
||||
} from '@/components/requisition-submission-confirmation';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import {
|
||||
@@ -37,6 +41,7 @@ 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.accounts_assigned': 'Imputação contabilística preservada',
|
||||
'requisition.expired_returned': 'Pedido devolvido por expiração',
|
||||
'budget.cycle_opened': 'Novo ciclo orçamental preparado',
|
||||
'budget.cycle_closed':
|
||||
@@ -63,10 +68,21 @@ export default function Show({
|
||||
importEstimatesReady = false,
|
||||
capitalRegisterReady = false,
|
||||
expiryReady = false,
|
||||
accountsReady = false,
|
||||
duplicateHints = null,
|
||||
submissionPreview = null,
|
||||
canReadAuditMetadata = false,
|
||||
}: {
|
||||
canReadAuditMetadata?: boolean;
|
||||
submissionPreview?: SubmissionPreview | null;
|
||||
duplicateHints?: {
|
||||
matches: { id: number; number: string; status: string }[];
|
||||
complete: boolean;
|
||||
} | null;
|
||||
importEstimatesReady?: boolean;
|
||||
capitalRegisterReady?: boolean;
|
||||
expiryReady?: boolean;
|
||||
accountsReady?: boolean;
|
||||
importTariffsReady?: boolean;
|
||||
canPrepareDistributions?: boolean;
|
||||
requisition: Requisition;
|
||||
@@ -129,10 +145,6 @@ export default function Show({
|
||||
};
|
||||
}) {
|
||||
const ready = usePage().props.internalRequisitionReady === true;
|
||||
const submission = useForm({
|
||||
operation_key: ready ? crypto.randomUUID() : null,
|
||||
process_version: r.process_version ?? null,
|
||||
});
|
||||
const routing = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
process_version: r.process_version ?? 1,
|
||||
@@ -174,7 +186,6 @@ export default function Show({
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<FormErrors errors={submission.errors} />
|
||||
{capitalRegisterReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link
|
||||
@@ -184,6 +195,13 @@ export default function Show({
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{accountsReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/contas`}>
|
||||
Atribuir contas contabilísticas
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{expiryReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/prazos`}>
|
||||
@@ -216,6 +234,38 @@ export default function Show({
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{duplicateHints &&
|
||||
(duplicateHints.matches.length > 0 ||
|
||||
!duplicateHints.complete) && (
|
||||
<Panel title="Conferir possíveis pedidos repetidos">
|
||||
<p>
|
||||
Pedidos seus com o mesmo centro de custo, data
|
||||
necessária e linhas iguais. Confira a
|
||||
necessidade antes de submeter; este aviso não
|
||||
bloqueia a submissão.
|
||||
</p>
|
||||
<ul className="mt-3 space-y-2">
|
||||
{duplicateHints.matches.map((match) => (
|
||||
<li key={match.id}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${match.id}`}
|
||||
>
|
||||
{match.number}
|
||||
</Link>{' '}
|
||||
· <Status value={match.status} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{!duplicateHints.complete && (
|
||||
<p className="mt-3">
|
||||
Comparação limitada aos 100 candidatos mais
|
||||
recentes. Consulte também as suas
|
||||
requisições anteriores.
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
{automaticSource && (
|
||||
<Panel title="Origem na reposição automática">
|
||||
<p>
|
||||
@@ -406,17 +456,14 @@ export default function Show({
|
||||
Editar
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
disabled={submission.processing}
|
||||
onClick={() =>
|
||||
submission.post(
|
||||
`/requisicoes/${r.id}/submeter`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
<RequisitionSubmissionAction
|
||||
key={`${r.id}:${r.process_version ?? 0}`}
|
||||
id={r.id}
|
||||
number={r.number}
|
||||
version={r.process_version ?? null}
|
||||
ready={ready}
|
||||
preview={submissionPreview}
|
||||
/>
|
||||
</ActionBar>
|
||||
</div>
|
||||
))}
|
||||
@@ -828,6 +875,16 @@ export default function Show({
|
||||
</Panel>
|
||||
<Panel title="Histórico">
|
||||
<div id="requisition-history" />
|
||||
{canReadAuditMetadata && (
|
||||
<p className="mb-3 text-sm">
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/auditoria/eventos?request_reference=${encodeURIComponent(r.number)}`}
|
||||
>
|
||||
Consultar eventos deste pedido
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
<a
|
||||
className="mb-4 inline-block text-sm underline"
|
||||
href={`/requisicoes/${r.id}/historico.csv`}
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
PageTitle,
|
||||
Panel,
|
||||
FormErrors,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
import { date, roleLabels } from '@/types/procurement';
|
||||
import { urgentOutcomes } from '@/pages/requisitions/urgent-reviews';
|
||||
|
||||
type Review = {
|
||||
id: number;
|
||||
version: number;
|
||||
data: { notes: string };
|
||||
snapshot: { fingerprint: string };
|
||||
};
|
||||
type Props = {
|
||||
source: {
|
||||
cycle: number;
|
||||
outcome: string;
|
||||
fingerprint: string;
|
||||
closed_at: string;
|
||||
request: {
|
||||
id: number;
|
||||
number: string;
|
||||
justification: string;
|
||||
total_minor: string | null;
|
||||
};
|
||||
items: {
|
||||
id: number;
|
||||
description: string;
|
||||
quantity: string;
|
||||
unit: string;
|
||||
total_minor: string | null;
|
||||
}[];
|
||||
steps: {
|
||||
id: number;
|
||||
role: string;
|
||||
decision: string;
|
||||
comment: string | null;
|
||||
routing?: { name: string } | null;
|
||||
}[];
|
||||
};
|
||||
current: Review | null;
|
||||
currentVerified: boolean;
|
||||
canReview: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
history: {
|
||||
data: Review[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
};
|
||||
export default function UrgentReview(props: Props) {
|
||||
const source = props.source;
|
||||
const url = `/requisicoes/${source.request.id}/ciclos/${source.cycle}/revisao-urgencia`;
|
||||
const form = useForm(
|
||||
`urgent-review:${props.tenantId}:${props.actorId}:${source.request.id}:${source.cycle}`,
|
||||
{
|
||||
operation_key: '',
|
||||
version: props.current?.version ?? 0,
|
||||
source_hash: source.fingerprint,
|
||||
notes: '',
|
||||
},
|
||||
);
|
||||
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]);
|
||||
const fresh =
|
||||
form.data.version === (props.current?.version ?? 0) &&
|
||||
form.data.source_hash === source.fingerprint;
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-5 lg:p-8">
|
||||
<Head title="Revisão posterior de urgência" />
|
||||
<PageTitle
|
||||
eyebrow={`${source.request.number} · Ciclo ${source.cycle}`}
|
||||
title="Revisão posterior de urgência"
|
||||
description="A revisão regista a conferência posterior da direcção de Compras. As aprovações, a decisão final e os movimentos conservam o seu percurso próprio."
|
||||
/>
|
||||
<nav className="flex flex-wrap gap-4">
|
||||
<Link
|
||||
className="underline"
|
||||
href="/requisicoes/urgencias/revisoes"
|
||||
>
|
||||
Voltar às urgências
|
||||
</Link>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${source.request.id}`}
|
||||
>
|
||||
Consultar o pedido actual
|
||||
</Link>
|
||||
</nav>
|
||||
<Panel
|
||||
title={`Ciclo concluído · ${urgentOutcomes[source.outcome]}`}
|
||||
>
|
||||
<p className="whitespace-pre-wrap">
|
||||
{source.request.justification}
|
||||
</p>
|
||||
<p className="mt-3">
|
||||
Conclusão registada em: {date(source.closed_at)}
|
||||
</p>
|
||||
<p className="mt-3">
|
||||
Valor da necessidade original:{' '}
|
||||
{source.request.total_minor === null
|
||||
? 'Indeterminado'
|
||||
: exactMinorAmount(source.request.total_minor, 'MZN')}
|
||||
</p>
|
||||
{source.outcome === 'expired' && (
|
||||
<p className="mt-3">
|
||||
Estes dados pertencem ao ciclo expirado. O rascunho
|
||||
actual e uma nova submissão podem ter valores
|
||||
diferentes.
|
||||
</p>
|
||||
)}
|
||||
<ul className="mt-4 space-y-2">
|
||||
{source.items.map((line) => (
|
||||
<li key={line.id}>
|
||||
{line.description} · {line.quantity} {line.unit} ·{' '}
|
||||
{line.total_minor === null
|
||||
? 'Indeterminado'
|
||||
: exactMinorAmount(line.total_minor, 'MZN')}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<h3 className="mt-4 font-semibold">Decisões conservadas</h3>
|
||||
<ul className="mt-2 space-y-2">
|
||||
{source.steps.map((step) => (
|
||||
<li key={step.id}>
|
||||
{step.routing?.name ||
|
||||
roleLabels[step.role] ||
|
||||
'Etapa configurada'}{' '}
|
||||
·{' '}
|
||||
{step.decision === 'approved'
|
||||
? 'Aprovada'
|
||||
: step.decision === 'rejected'
|
||||
? 'Rejeitada'
|
||||
: 'Sem decisão antes da conclusão do ciclo'}
|
||||
{step.comment && (
|
||||
<p className="whitespace-pre-wrap">
|
||||
{step.comment}
|
||||
</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
<Panel
|
||||
title={
|
||||
props.current
|
||||
? `Revisão actual · versão ${props.current.version}`
|
||||
: 'Registar a revisão posterior'
|
||||
}
|
||||
>
|
||||
{!props.currentVerified && (
|
||||
<p role="alert">
|
||||
A revisão anterior não confirma a origem actualmente
|
||||
apresentada. O ciclo não é apresentado como revisto.
|
||||
</p>
|
||||
)}
|
||||
{props.current && (
|
||||
<p className="mb-4 whitespace-pre-wrap">
|
||||
{props.current.data.notes}
|
||||
</p>
|
||||
)}
|
||||
{props.canReview ? (
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const data = {
|
||||
...form.data,
|
||||
operation_key:
|
||||
form.data.operation_key ||
|
||||
crypto.randomUUID(),
|
||||
};
|
||||
form.setData(data);
|
||||
form.transform(() => data);
|
||||
form.post(url, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const next = {
|
||||
...data,
|
||||
operation_key: '',
|
||||
version: data.version + 1,
|
||||
notes: '',
|
||||
};
|
||||
form.setData(next);
|
||||
form.setDefaults(next);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{!fresh && (
|
||||
<p role="alert">
|
||||
A origem ou a revisão mudou. Confira os dados
|
||||
actuais antes de registar outra versão.
|
||||
</p>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
if (
|
||||
form.isDirty &&
|
||||
!window.confirm(
|
||||
'Descartar esta preparação e usar a origem actual?',
|
||||
)
|
||||
)
|
||||
return;
|
||||
form.setData({
|
||||
operation_key: '',
|
||||
version: props.current?.version ?? 0,
|
||||
source_hash: source.fingerprint,
|
||||
notes: '',
|
||||
});
|
||||
}}
|
||||
>
|
||||
Preparar versão actual
|
||||
</Button>
|
||||
<label className="block">
|
||||
Conclusões da revisão e observações
|
||||
<textarea
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.notes}
|
||||
onChange={(event) =>
|
||||
form.setData('notes', event.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing || !fresh}>
|
||||
Registar revisão posterior
|
||||
</Button>
|
||||
</form>
|
||||
) : (
|
||||
<p>
|
||||
A consulta não confere competência para registar a
|
||||
revisão. São exigidos perfil designado, função e
|
||||
atribuição actualmente válidos.
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
<Panel title="Histórico das revisões">
|
||||
<ul className="space-y-4">
|
||||
{props.history.data.map((row) => (
|
||||
<li key={row.id}>
|
||||
<h3 className="font-semibold">
|
||||
Versão {row.version}
|
||||
</h3>
|
||||
<p className="whitespace-pre-wrap">
|
||||
{row.data.notes}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<nav className="mt-4 flex gap-4">
|
||||
{props.history.prev_page_url && (
|
||||
<Link
|
||||
preserveScroll
|
||||
preserveState
|
||||
className="underline"
|
||||
href={props.history.prev_page_url}
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.history.next_page_url && (
|
||||
<Link
|
||||
preserveScroll
|
||||
preserveState
|
||||
className="underline"
|
||||
href={props.history.next_page_url}
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { PageTitle, Panel } from '@/components/procurement';
|
||||
import { date } from '@/types/procurement';
|
||||
|
||||
export const urgentOutcomes: Record<string, string> = {
|
||||
approved: 'Aprovada',
|
||||
rejected: 'Rejeitada',
|
||||
expired: 'Expirada e devolvida ao requisitante',
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
pending: 'Por rever',
|
||||
reviewed: 'Revisão registada',
|
||||
indeterminate: 'Origem por conferir',
|
||||
all: 'Todos os ciclos concluídos',
|
||||
};
|
||||
export default function UrgentReviews(props: {
|
||||
coverage: Record<string, number>;
|
||||
state: string;
|
||||
canReview: boolean;
|
||||
canConfigure: boolean;
|
||||
records: {
|
||||
data: {
|
||||
key: string;
|
||||
number: string;
|
||||
cycle: number;
|
||||
outcome: string;
|
||||
status: string;
|
||||
closed_at: string | null;
|
||||
href: string;
|
||||
}[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
};
|
||||
}) {
|
||||
const url = '/requisicoes/urgencias/revisoes';
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-5 lg:p-8">
|
||||
<Head title="Revisão posterior das urgências" />
|
||||
<PageTitle
|
||||
eyebrow="Compras"
|
||||
title="Revisão posterior das urgências"
|
||||
description="Ciclos com decisão final, incluindo rejeição e expiração. A revisão conserva o ciclo concluído e as suas decisões."
|
||||
/>
|
||||
<Link className="underline" href="/requisicoes/tarefas">
|
||||
Voltar às tarefas
|
||||
</Link>
|
||||
{props.canConfigure && (
|
||||
<Link
|
||||
className="underline"
|
||||
href="/administracao/revisao-urgencias"
|
||||
>
|
||||
Designar perfis da direcção de Compras
|
||||
</Link>
|
||||
)}
|
||||
<Panel title="Conferir ciclos concluídos">
|
||||
<dl className="grid gap-4 sm:grid-cols-3">
|
||||
{Object.entries(props.coverage).map(([key, count]) => (
|
||||
<div key={key}>
|
||||
<dt>{states[key]}</dt>
|
||||
<dd className="font-semibold">{count}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<nav
|
||||
aria-label="Filtrar revisões de urgências"
|
||||
className="my-4 flex flex-wrap gap-4"
|
||||
>
|
||||
{Object.entries(states).map(([key, label]) => (
|
||||
<Link
|
||||
key={key}
|
||||
className="underline"
|
||||
href={`${url}?state=${key}`}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
{!props.canReview && (
|
||||
<p className="mb-4 text-sm">
|
||||
O registo da revisão exige um perfil expressamente
|
||||
designado e a função de Compras actualmente válida.
|
||||
</p>
|
||||
)}
|
||||
{props.records.data.length === 0 && (
|
||||
<p>Sem ciclos nesta selecção.</p>
|
||||
)}
|
||||
<ul className="space-y-4">
|
||||
{props.records.data.map((row) => (
|
||||
<li key={row.key} className="border-b pb-4">
|
||||
<Link
|
||||
className="font-semibold underline"
|
||||
href={row.href}
|
||||
>
|
||||
{row.number} · Ciclo {row.cycle}
|
||||
</Link>
|
||||
<p>
|
||||
{urgentOutcomes[row.outcome]} ·{' '}
|
||||
{states[row.status]} · Conclusão:{' '}
|
||||
{row.closed_at
|
||||
? date(row.closed_at)
|
||||
: 'Por conferir'}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="mt-4">
|
||||
{props.records.total} ciclo(s) · Página{' '}
|
||||
{props.records.current_page} de {props.records.last_page}
|
||||
</p>
|
||||
<nav
|
||||
className="mt-3 flex gap-4"
|
||||
aria-label="Páginas de revisão de urgências"
|
||||
>
|
||||
{props.records.current_page > 1 && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`${url}?state=${props.state}&page=${props.records.current_page - 1}`}
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.records.current_page < props.records.last_page && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`${url}?state=${props.state}&page=${props.records.current_page + 1}`}
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user