@@ -0,0 +1,378 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Plus, Save, Trash2 } from 'lucide-react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { money } from '@/types/procurement';
|
||||
import type { CostCenter, Requisition } from '@/types/procurement';
|
||||
|
||||
type Line = {
|
||||
key: string;
|
||||
description: string;
|
||||
category: string;
|
||||
purchase_type: string;
|
||||
quantity: string;
|
||||
unit: string;
|
||||
unit_price: string;
|
||||
tax_rate: string;
|
||||
};
|
||||
const emptyLine = (): Line => ({
|
||||
key: crypto.randomUUID(),
|
||||
description: '',
|
||||
category: '',
|
||||
purchase_type: 'consumable',
|
||||
quantity: '1',
|
||||
unit: 'un',
|
||||
unit_price: '',
|
||||
tax_rate: '0',
|
||||
});
|
||||
const lineFields = [
|
||||
{ key: 'description', label: 'Descrição', type: 'text', maxLength: 255 },
|
||||
{ key: 'category', label: 'Categoria', type: 'text', maxLength: 100 },
|
||||
{
|
||||
key: 'quantity',
|
||||
label: 'Quantidade',
|
||||
type: 'number',
|
||||
min: '0.001',
|
||||
max: '1000000',
|
||||
step: '0.001',
|
||||
},
|
||||
{ key: 'unit', label: 'Unidade', type: 'text', maxLength: 30 },
|
||||
{
|
||||
key: 'unit_price',
|
||||
label: 'Preço unitário sem IVA (MZN)',
|
||||
type: 'number',
|
||||
min: '0.01',
|
||||
max: '100000000',
|
||||
step: '0.01',
|
||||
},
|
||||
{
|
||||
key: 'tax_rate',
|
||||
label: 'Taxa de IVA (%)',
|
||||
type: 'number',
|
||||
min: '0',
|
||||
max: '100',
|
||||
step: '0.01',
|
||||
},
|
||||
] as const;
|
||||
|
||||
export default function RequisitionForm({
|
||||
costCenters,
|
||||
requisition,
|
||||
}: {
|
||||
costCenters: CostCenter[];
|
||||
requisition: Requisition | null;
|
||||
}) {
|
||||
const form = useForm({
|
||||
cost_center_id: requisition ? String(requisition.cost_center_id) : '',
|
||||
priority: requisition?.priority ?? 'normal',
|
||||
needed_by: requisition?.needed_by ?? '',
|
||||
justification: requisition?.justification ?? '',
|
||||
items: requisition?.items.map((i) => ({
|
||||
key: String(i.id),
|
||||
description: i.description,
|
||||
category: i.category,
|
||||
purchase_type: i.purchase_type,
|
||||
quantity: String(i.quantity),
|
||||
unit: i.unit,
|
||||
unit_price: (i.unit_price_minor / 100).toFixed(2),
|
||||
tax_rate: String(i.tax_rate),
|
||||
})) ?? [emptyLine()],
|
||||
});
|
||||
const changeLine = (index: number, field: keyof Line, value: string) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map((item, i) =>
|
||||
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,
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Head
|
||||
title={requisition ? 'Editar requisição' : 'Nova requisição'}
|
||||
/>
|
||||
<div className="mx-auto flex w-full max-w-6xl flex-col gap-7 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Pedido de compra"
|
||||
title={
|
||||
requisition
|
||||
? `Editar ${requisition.number}`
|
||||
: 'Nova requisição'
|
||||
}
|
||||
description="Descreva a necessidade e os artigos. Guarde o rascunho e confira os valores antes de submeter."
|
||||
/>
|
||||
<form
|
||||
className="space-y-6"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (requisition)
|
||||
form.put(`/requisicoes/${requisition.id}`);
|
||||
else form.post('/requisicoes');
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{costCenters.length === 0 && (
|
||||
<div
|
||||
role="alert"
|
||||
className="rounded-lg border p-4 text-sm"
|
||||
>
|
||||
O seu departamento ainda não tem centros de custo.
|
||||
Peça ao administrador para criar um antes de
|
||||
registar pedidos.
|
||||
</div>
|
||||
)}
|
||||
<Panel
|
||||
title="Informações do pedido"
|
||||
description="O solicitante e o departamento são determinados pela sua conta."
|
||||
>
|
||||
<div className="grid gap-5 sm:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="cost-center">
|
||||
Centro de custo
|
||||
</Label>
|
||||
<select
|
||||
id="cost-center"
|
||||
required
|
||||
className={controlClass}
|
||||
value={form.data.cost_center_id}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'cost_center_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{costCenters.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.code} · {c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="priority">Prioridade</Label>
|
||||
<select
|
||||
id="priority"
|
||||
className={controlClass}
|
||||
value={form.data.priority}
|
||||
onChange={(e) =>
|
||||
form.setData('priority', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="normal">Normal</option>
|
||||
<option value="high">Alta</option>
|
||||
<option value="urgent">Urgente</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="needed-by">
|
||||
Entrega pretendida
|
||||
</Label>
|
||||
<Input
|
||||
id="needed-by"
|
||||
type="date"
|
||||
required
|
||||
value={form.data.needed_by}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'needed_by',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2 sm:col-span-3">
|
||||
<Label htmlFor="justification">
|
||||
Justificação da compra
|
||||
</Label>
|
||||
<textarea
|
||||
id="justification"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={5000}
|
||||
className={`${controlClass} h-24 py-3`}
|
||||
placeholder="Explique a necessidade e a utilização prevista…"
|
||||
value={form.data.justification}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'justification',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel
|
||||
title="Artigos e serviços"
|
||||
description="Preços em MZN. Indique a taxa de IVA aplicável; o valor inicial de 0% deve ser revisto por Finanças."
|
||||
>
|
||||
<div className="space-y-5">
|
||||
{form.data.items.map((line, index) => (
|
||||
<fieldset
|
||||
className="rounded-lg border bg-muted/20 p-4"
|
||||
key={line.key}
|
||||
>
|
||||
<legend className="px-2 text-xs font-semibold text-muted-foreground">
|
||||
LINHA {index + 1}
|
||||
</legend>
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{lineFields.map(
|
||||
({ key, label, ...attributes }) => (
|
||||
<div
|
||||
className="space-y-2"
|
||||
key={key}
|
||||
>
|
||||
<Label
|
||||
htmlFor={`${key}-${line.key}`}
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${key}-${line.key}`}
|
||||
{...attributes}
|
||||
required
|
||||
value={line[key]}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
key,
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`type-${line.key}`}>
|
||||
Tipo de compra
|
||||
</Label>
|
||||
<select
|
||||
id={`type-${line.key}`}
|
||||
className={controlClass}
|
||||
value={line.purchase_type}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
'purchase_type',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="consumable">
|
||||
Insumos / matéria-prima
|
||||
</option>
|
||||
<option value="service">
|
||||
Serviço
|
||||
</option>
|
||||
<option value="other">
|
||||
Outro
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex justify-end">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={
|
||||
form.data.items.length === 1
|
||||
}
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.filter(
|
||||
(_, i) => i !== index,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
Remover linha
|
||||
</Button>
|
||||
</div>
|
||||
</fieldset>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-5 flex flex-wrap items-center justify-between gap-4">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={form.data.items.length >= 50}
|
||||
onClick={() =>
|
||||
form.setData('items', [
|
||||
...form.data.items,
|
||||
emptyLine(),
|
||||
])
|
||||
}
|
||||
>
|
||||
<Plus className="size-4" />
|
||||
Adicionar linha
|
||||
</Button>
|
||||
<p className="text-sm">
|
||||
Total estimado com IVA{' '}
|
||||
<strong className="ml-3 text-lg">
|
||||
{money(
|
||||
Number.isFinite(estimate)
|
||||
? estimate
|
||||
: 0,
|
||||
)}
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-4 text-xs text-muted-foreground">
|
||||
O servidor confirma os cálculos ao guardar.
|
||||
Equipamentos e peças terão formulários próprios numa
|
||||
próxima etapa.
|
||||
</p>
|
||||
</Panel>
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
href={
|
||||
requisition
|
||||
? `/requisicoes/${requisition.id}`
|
||||
: '/requisicoes'
|
||||
}
|
||||
>
|
||||
Cancelar
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
disabled={
|
||||
form.processing || costCenters.length === 0
|
||||
}
|
||||
>
|
||||
<Save className="size-4" />
|
||||
Guardar rascunho
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
RequisitionForm.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Requisições', href: '/requisicoes' },
|
||||
{ title: 'Formulário', href: '#' },
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,117 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Plus, Search } from 'lucide-react';
|
||||
import {
|
||||
PageTitle,
|
||||
Panel,
|
||||
RequisitionTable,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { statusLabels } from '@/types/procurement';
|
||||
import type { Requisition } from '@/types/procurement';
|
||||
|
||||
type Props = {
|
||||
requisitions: {
|
||||
data: Requisition[];
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
total: number;
|
||||
};
|
||||
filters: { search?: string; status?: string };
|
||||
};
|
||||
export default function Index({ requisitions, filters }: Props) {
|
||||
const form = useForm({
|
||||
search: filters.search ?? '',
|
||||
status: filters.status ?? '',
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<Head title="Requisições" />
|
||||
<div className="mx-auto flex w-full max-w-7xl flex-col gap-7 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras"
|
||||
title="Requisições"
|
||||
description="Registe necessidades e acompanhe cada pedido até à aprovação."
|
||||
action={
|
||||
<Button asChild>
|
||||
<Link href="/requisicoes/criar">
|
||||
<Plus className="size-4" />
|
||||
Nova requisição
|
||||
</Link>
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Panel title="Pedidos de compra">
|
||||
<form
|
||||
className="mb-6 flex flex-wrap gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.get('/requisicoes', { preserveState: true });
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
className="max-w-xs"
|
||||
aria-label="Pesquisar pela referência"
|
||||
placeholder="Pesquisar referência…"
|
||||
value={form.data.search}
|
||||
onChange={(e) =>
|
||||
form.setData('search', e.target.value)
|
||||
}
|
||||
/>
|
||||
<select
|
||||
className={`${controlClass} max-w-48`}
|
||||
aria-label="Filtrar por estado"
|
||||
value={form.data.status}
|
||||
onChange={(e) =>
|
||||
form.setData('status', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Todos os estados</option>
|
||||
{Object.entries(statusLabels).map(
|
||||
([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
<Button variant="outline" disabled={form.processing}>
|
||||
<Search className="size-4" />
|
||||
Filtrar
|
||||
</Button>
|
||||
</form>
|
||||
<RequisitionTable rows={requisitions.data} />
|
||||
<div className="mt-5 flex flex-wrap items-center justify-between gap-3 border-t pt-4 text-sm text-muted-foreground">
|
||||
<p>
|
||||
{requisitions.total} pedidos · Página{' '}
|
||||
{requisitions.current_page} de{' '}
|
||||
{requisitions.last_page}
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
{requisitions.prev_page_url && (
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href={requisitions.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{requisitions.next_page_url && (
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href={requisitions.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Index.layout = {
|
||||
breadcrumbs: [{ title: 'Requisições', href: '/requisicoes' }],
|
||||
};
|
||||
@@ -0,0 +1,368 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Check, Circle, Pencil, Send } from 'lucide-react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
Status,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { date, money, priorityLabels, roleLabels } from '@/types/procurement';
|
||||
import type { Requisition } from '@/types/procurement';
|
||||
|
||||
type Audit = {
|
||||
id: number;
|
||||
action: string;
|
||||
user_id: number;
|
||||
created_at: string;
|
||||
};
|
||||
const actions: Record<string, string> = {
|
||||
'requisition.created': 'Rascunho criado',
|
||||
'requisition.updated': 'Rascunho actualizado',
|
||||
'requisition.submitted': 'Pedido submetido',
|
||||
'approval.approved': 'Etapa aprovada',
|
||||
'approval.rejected': 'Pedido rejeitado',
|
||||
};
|
||||
|
||||
export default function Show({
|
||||
requisition: r,
|
||||
canEdit,
|
||||
canDecide,
|
||||
conflictBlocked,
|
||||
audit,
|
||||
}: {
|
||||
requisition: Requisition;
|
||||
canEdit: boolean;
|
||||
canDecide: boolean;
|
||||
conflictBlocked: boolean;
|
||||
audit: Audit[];
|
||||
}) {
|
||||
const submission = useForm({});
|
||||
const decision = useForm<{ decision: string; comment: string }>({
|
||||
decision: 'approved',
|
||||
comment: '',
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<Head title={r.number} />
|
||||
<div className="mx-auto flex w-full max-w-6xl flex-col gap-7 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Requisição de compra"
|
||||
title={r.number}
|
||||
description={`${r.requester?.name} · ${r.department?.name} · ${date(r.created_at)}`}
|
||||
action={<Status value={r.status} />}
|
||||
/>
|
||||
<FormErrors errors={submission.errors} />
|
||||
{conflictBlocked && (
|
||||
<div className="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
||||
Existe um conflito de interesses activo que impede a
|
||||
participação neste processo. As operações são
|
||||
verificadas pelo servidor.{' '}
|
||||
<Link href="/conflitos" className="underline">
|
||||
Consultar as declarações disponíveis para o meu
|
||||
perfil
|
||||
</Link>
|
||||
.
|
||||
</div>
|
||||
)}
|
||||
{canEdit && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border bg-muted/30 p-5">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Confira o pedido antes de o enviar para aprovação.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/editar`}>
|
||||
<Pencil className="size-4" />
|
||||
Editar
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
disabled={submission.processing}
|
||||
onClick={() =>
|
||||
submission.post(
|
||||
`/requisicoes/${r.id}/submeter`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
<Panel title="Detalhes do pedido">
|
||||
<dl className="grid gap-5 text-sm sm:grid-cols-3">
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Centro de custo
|
||||
</dt>
|
||||
<dd className="mt-1 font-medium">
|
||||
{r.cost_center?.code} ·{' '}
|
||||
{r.cost_center?.name}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Prioridade
|
||||
</dt>
|
||||
<dd className="mt-1 font-medium">
|
||||
{priorityLabels[r.priority]}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted-foreground">
|
||||
Entrega pretendida
|
||||
</dt>
|
||||
<dd className="mt-1 font-medium">
|
||||
{date(r.needed_by)}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="sm:col-span-3">
|
||||
<dt className="text-muted-foreground">
|
||||
Justificação
|
||||
</dt>
|
||||
<dd className="mt-2 whitespace-pre-wrap">
|
||||
{r.justification}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</Panel>
|
||||
<Panel
|
||||
title="Artigos e valores"
|
||||
description="Moeda: MZN · Montantes estimados"
|
||||
>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="pb-3">Artigo</th>
|
||||
<th className="pr-3">Qtd.</th>
|
||||
<th className="pr-3">
|
||||
Preço s/ IVA
|
||||
</th>
|
||||
<th className="pr-3">IVA</th>
|
||||
<th className="text-right">
|
||||
Total c/ IVA
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.items.map((i) => (
|
||||
<tr key={i.id} className="border-b">
|
||||
<td className="py-4 pr-4">
|
||||
<p className="font-medium">
|
||||
{i.description}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{i.category}
|
||||
</p>
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{Number(i.quantity)}{' '}
|
||||
{i.unit}
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{money(i.unit_price_minor)}
|
||||
</td>
|
||||
<td className="pr-3">
|
||||
{Number(i.tax_rate)}%
|
||||
</td>
|
||||
<td className="text-right whitespace-nowrap">
|
||||
{money(i.total_minor)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<dl className="mt-5 ml-auto max-w-xs space-y-3 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<dt>Subtotal sem IVA</dt>
|
||||
<dd>{money(r.subtotal_minor)}</dd>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<dt>IVA</dt>
|
||||
<dd>{money(r.tax_minor)}</dd>
|
||||
</div>
|
||||
<div className="flex justify-between border-t pt-3 text-base font-semibold">
|
||||
<dt>Total com IVA</dt>
|
||||
<dd>{money(r.total_minor)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</Panel>
|
||||
{canDecide && (
|
||||
<Panel
|
||||
title="Registar decisão"
|
||||
description="A decisão fica associada à sua conta e ao histórico deste pedido."
|
||||
>
|
||||
<form
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
decision.post(
|
||||
`/requisicoes/${r.id}/decidir`,
|
||||
{
|
||||
onSuccess: () =>
|
||||
decision.reset(),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={decision.errors} />
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="decision">
|
||||
Decisão
|
||||
</Label>
|
||||
<select
|
||||
id="decision"
|
||||
className={controlClass}
|
||||
value={decision.data.decision}
|
||||
onChange={(e) =>
|
||||
decision.setData(
|
||||
'decision',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="approved">
|
||||
Aprovar etapa
|
||||
</option>
|
||||
<option value="rejected">
|
||||
Rejeitar pedido
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="comment">
|
||||
Comentário{' '}
|
||||
{decision.data.decision ===
|
||||
'rejected'
|
||||
? '(obrigatório)'
|
||||
: '(opcional)'}
|
||||
</Label>
|
||||
<textarea
|
||||
id="comment"
|
||||
className={`${controlClass} h-24 py-3`}
|
||||
required={
|
||||
decision.data.decision ===
|
||||
'rejected'
|
||||
}
|
||||
maxLength={2000}
|
||||
value={decision.data.comment}
|
||||
onChange={(e) =>
|
||||
decision.setData(
|
||||
'comment',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
disabled={decision.processing}
|
||||
variant={
|
||||
decision.data.decision ===
|
||||
'rejected'
|
||||
? 'destructive'
|
||||
: 'default'
|
||||
}
|
||||
>
|
||||
Confirmar decisão
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-6">
|
||||
<Panel title="Percurso de aprovação">
|
||||
{r.steps.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
As etapas serão calculadas pelo servidor
|
||||
quando submeter o pedido.
|
||||
</p>
|
||||
) : (
|
||||
<ol className="space-y-5">
|
||||
{r.steps.map((s) => (
|
||||
<li className="flex gap-3" key={s.id}>
|
||||
<span
|
||||
className={`flex size-8 shrink-0 items-center justify-center rounded-full ${s.decision === 'approved' ? 'bg-teal-100 text-teal-800 dark:bg-teal-950 dark:text-teal-200' : 'bg-muted text-muted-foreground'}`}
|
||||
>
|
||||
{s.decision === 'approved' ? (
|
||||
<Check className="size-4" />
|
||||
) : (
|
||||
<Circle className="size-3" />
|
||||
)}
|
||||
</span>
|
||||
<div>
|
||||
<p className="text-sm font-medium">
|
||||
{roleLabels[s.role]}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{s.decision === 'pending'
|
||||
? r.status ===
|
||||
'rejected'
|
||||
? 'Não realizada'
|
||||
: 'Aguarda decisão'
|
||||
: s.decision ===
|
||||
'approved'
|
||||
? 'Aprovada'
|
||||
: 'Rejeitada'}
|
||||
{s.approver_id
|
||||
? ` · Utilizador #${s.approver_id}`
|
||||
: ''}
|
||||
</p>
|
||||
{s.comment && (
|
||||
<p className="mt-2 text-sm whitespace-pre-wrap">
|
||||
{s.comment}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
{r.approval_snapshot?.rules_provisional && (
|
||||
<p className="mt-5 border-t pt-4 text-xs text-amber-700 dark:text-amber-400">
|
||||
Regras provisórias guardadas na submissão.
|
||||
Base:{' '}
|
||||
{r.approval_snapshot.approval_includes_tax
|
||||
? 'com'
|
||||
: 'sem'}{' '}
|
||||
IVA.
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
<Panel title="Histórico">
|
||||
<ol className="space-y-4">
|
||||
{audit.map((a) => (
|
||||
<li
|
||||
key={a.id}
|
||||
className="border-l-2 border-teal-600/30 pl-3"
|
||||
>
|
||||
<p className="text-sm font-medium">
|
||||
{actions[a.action] ?? a.action}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{date(a.created_at)} · Utilizador #
|
||||
{a.user_id}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Show.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Requisições', href: '/requisicoes' },
|
||||
{ title: 'Detalhe', href: '#' },
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user