commit13
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { Plus, Save, Trash2 } from 'lucide-react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
@@ -97,7 +98,10 @@ export default function RequisitionForm({
|
||||
defaultTaxRate?: string;
|
||||
catalogue?: CatalogueOptions;
|
||||
}) {
|
||||
const ready = usePage().props.internalRequisitionReady === true;
|
||||
const form = useForm({
|
||||
operation_key: ready ? crypto.randomUUID() : null,
|
||||
process_version: requisition?.process_version ?? null,
|
||||
cost_center_id: requisition ? String(requisition.cost_center_id) : '',
|
||||
priority: requisition?.priority ?? 'normal',
|
||||
needed_by: requisition?.needed_by ?? '',
|
||||
@@ -125,6 +129,14 @@ export default function RequisitionForm({
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
});
|
||||
const formElement = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: formElement.current, dirty: form.isDirty },
|
||||
}),
|
||||
);
|
||||
}, [form.isDirty]);
|
||||
const changeLine = (index: number, field: keyof Line, value: string) =>
|
||||
form.setData(
|
||||
'items',
|
||||
@@ -157,12 +169,25 @@ export default function RequisitionForm({
|
||||
description="Descreva a necessidade e os artigos. Guarde o rascunho e confira os valores antes de submeter."
|
||||
/>
|
||||
<form
|
||||
ref={formElement}
|
||||
data-context-save
|
||||
className="space-y-6"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
const element = e.currentTarget;
|
||||
const result = (success: boolean) =>
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-save-result', {
|
||||
detail: { form: element, success },
|
||||
}),
|
||||
);
|
||||
const options = {
|
||||
onSuccess: () => result(true),
|
||||
onError: () => result(false),
|
||||
};
|
||||
if (requisition)
|
||||
form.put(`/requisicoes/${requisition.id}`);
|
||||
else form.post('/requisicoes');
|
||||
form.put(`/requisicoes/${requisition.id}`, options);
|
||||
else form.post('/requisicoes', options);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { Check, Circle, Pencil, Send } from 'lucide-react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
@@ -36,9 +36,29 @@ export default function Show({
|
||||
audit,
|
||||
technical,
|
||||
comparisonPolicy,
|
||||
replenishmentSource,
|
||||
approvalRouting,
|
||||
canRefreshRouting = false,
|
||||
}: {
|
||||
requisition: Requisition;
|
||||
canRefreshRouting?: boolean;
|
||||
approvalRouting?: {
|
||||
status: string;
|
||||
step_id: number | null;
|
||||
role: string | null;
|
||||
people: { id: number; name: string }[];
|
||||
checked_at: string;
|
||||
};
|
||||
comparisonPolicy: ComparisonPolicy;
|
||||
replenishmentSource?: {
|
||||
approval_version: number;
|
||||
prepared_on: string;
|
||||
quantity_milli: number;
|
||||
unit: string;
|
||||
delivery_on: string;
|
||||
purpose: string;
|
||||
origin: string;
|
||||
} | null;
|
||||
canEdit: boolean;
|
||||
canDecide: boolean;
|
||||
conflictBlocked: boolean;
|
||||
@@ -55,13 +75,25 @@ export default function Show({
|
||||
}[];
|
||||
};
|
||||
}) {
|
||||
const submission = useForm({});
|
||||
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,
|
||||
step_id: approvalRouting?.step_id,
|
||||
reason: '',
|
||||
});
|
||||
const review = useForm({
|
||||
basis_hash: technical?.basis_hash ?? '',
|
||||
decision: 'approved',
|
||||
reason: '',
|
||||
});
|
||||
const decision = useForm<{ decision: string; comment: string }>({
|
||||
const decision = useForm({
|
||||
operation_key: ready ? crypto.randomUUID() : null,
|
||||
process_version: r.process_version ?? null,
|
||||
decision: 'approved',
|
||||
comment: '',
|
||||
});
|
||||
@@ -69,6 +101,11 @@ export default function Show({
|
||||
<>
|
||||
<Head title={r.number} />
|
||||
<div className="mx-auto flex w-full max-w-6xl flex-col gap-7 p-5 lg:p-8">
|
||||
{r.process_version && (
|
||||
<p className="text-sm">
|
||||
Compras internas · Versão {r.process_version}
|
||||
</p>
|
||||
)}
|
||||
<PageTitle
|
||||
eyebrow="Requisição de compra"
|
||||
title={r.number}
|
||||
@@ -85,6 +122,35 @@ export default function Show({
|
||||
}
|
||||
/>
|
||||
<FormErrors errors={submission.errors} />
|
||||
{replenishmentSource && (
|
||||
<Panel title="Origem na reposição">
|
||||
<p className="text-sm">
|
||||
Criada a partir de uma sugestão de reposição, versão
|
||||
aprovada {replenishmentSource.approval_version},
|
||||
preparada em {replenishmentSource.prepared_on}.
|
||||
Proposta de{' '}
|
||||
{(
|
||||
replenishmentSource.quantity_milli / 1000
|
||||
).toLocaleString('pt-MZ', {
|
||||
maximumFractionDigits: 3,
|
||||
})}{' '}
|
||||
{replenishmentSource.unit}, para{' '}
|
||||
{replenishmentSource.delivery_on}.
|
||||
</p>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{replenishmentSource.purpose === 'resale'
|
||||
? 'Revenda'
|
||||
: 'Uso interno'}{' '}
|
||||
·{' '}
|
||||
{replenishmentSource.origin === 'import'
|
||||
? 'Importação directa'
|
||||
: 'Compra local'}
|
||||
. A preparação e as decisões originais permanecem
|
||||
preservadas; esta requisição segue o circuito
|
||||
habitual.
|
||||
</p>
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Regra de comparação deste processo">
|
||||
<ComparisonPolicySummary policy={comparisonPolicy} />
|
||||
</Panel>
|
||||
@@ -408,6 +474,111 @@ export default function Show({
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-6">
|
||||
{approvalRouting &&
|
||||
approvalRouting.status !== 'inactive' && (
|
||||
<Panel
|
||||
title="Quem pode tratar a etapa actual"
|
||||
description="Consulta das permissões e impedimentos actuais, respeitando o percurso já aprovado."
|
||||
>
|
||||
<p className="text-sm">
|
||||
Etapa:{' '}
|
||||
{roleLabels[
|
||||
approvalRouting.role ?? ''
|
||||
] ?? approvalRouting.role}
|
||||
.
|
||||
</p>
|
||||
{canRefreshRouting && (
|
||||
<details className="my-3 rounded-md border p-3">
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Actualizar encaminhamento
|
||||
</summary>
|
||||
<form
|
||||
className="mt-3 space-y-3"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
routing.post(
|
||||
`/requisicoes/${r.id}/encaminhamento`,
|
||||
{
|
||||
preserveState:
|
||||
'errors',
|
||||
preserveScroll: true,
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<p className="text-sm">
|
||||
Avisa novas pessoas
|
||||
actualmente elegíveis para
|
||||
esta etapa. Não muda perfis,
|
||||
aprovações ou avisos já
|
||||
lidos.
|
||||
</p>
|
||||
<FormErrors
|
||||
errors={routing.errors}
|
||||
/>
|
||||
<label className="block text-sm">
|
||||
Motivo
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
value={
|
||||
routing.data.reason
|
||||
}
|
||||
onChange={(event) =>
|
||||
routing.setData(
|
||||
'reason',
|
||||
event.target
|
||||
.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
disabled={
|
||||
routing.processing
|
||||
}
|
||||
>
|
||||
Actualizar avisos da etapa
|
||||
</Button>
|
||||
</form>
|
||||
</details>
|
||||
)}
|
||||
{approvalRouting.people.length === 0 ? (
|
||||
<p
|
||||
className="mt-3 text-sm"
|
||||
role="status"
|
||||
>
|
||||
Sem pessoa actualmente elegível para
|
||||
decidir esta etapa. A administração
|
||||
deve conferir perfis, departamento,
|
||||
validade dos acessos e impedimentos.
|
||||
O pedido continua pendente.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<ul className="mt-3 space-y-1 text-sm">
|
||||
{approvalRouting.people.map(
|
||||
(person) => (
|
||||
<li key={person.id}>
|
||||
{person.name}
|
||||
</li>
|
||||
),
|
||||
)}
|
||||
</ul>
|
||||
<p className="mt-3 text-xs text-muted-foreground">
|
||||
Estas pessoas podem consultar a
|
||||
tarefa em As minhas aprovações.
|
||||
A lista é uma fila de elegíveis,
|
||||
sem atribuição exclusiva ou
|
||||
aviso enviado; o servidor volta
|
||||
a validar a autorização ao
|
||||
decidir.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Percurso de aprovação">
|
||||
{r.steps.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
|
||||
Reference in New Issue
Block a user