commit13
This commit is contained in:
@@ -0,0 +1,807 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Fields = Record<string, string | number | boolean | null>;
|
||||
type Application = {
|
||||
operation_id: number;
|
||||
reference: string;
|
||||
quantity_milli: number;
|
||||
};
|
||||
type RecordVersion = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
state: string;
|
||||
data: Fields & { applications?: Application[] };
|
||||
reason: string;
|
||||
created_at: string;
|
||||
snapshot: {
|
||||
effective_allocated_milli?: number;
|
||||
reversed_operations?: number[];
|
||||
item: { name: string; code: string; unit: string };
|
||||
warehouse: { name: string };
|
||||
substitute?: { name: string; code: string; unit: string };
|
||||
order?: { number: string };
|
||||
};
|
||||
};
|
||||
type Source = {
|
||||
id: number;
|
||||
label: string;
|
||||
stock_item_id: number | null;
|
||||
quantity_milli: number;
|
||||
reference?: string;
|
||||
needed_on?: string;
|
||||
};
|
||||
type Props = {
|
||||
kind: 'reservation' | 'delivery' | 'alternative';
|
||||
ready: boolean;
|
||||
canPrepare: boolean;
|
||||
canReview: boolean;
|
||||
eligible: Record<string, boolean>;
|
||||
pending: Record<string, number>;
|
||||
reversedOperations?: number[];
|
||||
records: RecordVersion[];
|
||||
history: Record<string, RecordVersion[]>;
|
||||
items: { id: number; name: string; code: string; unit: string }[];
|
||||
warehouses: { id: number; name: string; code: string }[];
|
||||
requestLines: Source[];
|
||||
orderLines: Source[];
|
||||
operations: {
|
||||
id: number;
|
||||
reference: string;
|
||||
stock_item_id: number;
|
||||
warehouse_id: number;
|
||||
quantity_milli: number;
|
||||
}[];
|
||||
};
|
||||
const titles = {
|
||||
reservation: 'Reservas de necessidades',
|
||||
delivery: 'Entregas confirmadas',
|
||||
alternative: 'Alternativas técnicas',
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
draft: 'Em análise técnica',
|
||||
returned: 'Devolvida para correcção',
|
||||
approved: 'Validada tecnicamente',
|
||||
suspended: 'Suspensa',
|
||||
active: 'Activa',
|
||||
cancelled: 'Cancelada',
|
||||
fulfilled: 'Satisfeita por saídas',
|
||||
};
|
||||
const compatibility: Record<string, string> = {
|
||||
equivalent: 'Equivalente técnica',
|
||||
conditional: 'Substituição condicionada',
|
||||
incompatible: 'Não compatível',
|
||||
pending: 'Pendente de análise',
|
||||
};
|
||||
const quantity = (milli: number) =>
|
||||
(milli / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
const defaults: Fields = {
|
||||
stock_item_id: '',
|
||||
warehouse_id: '',
|
||||
...(props.kind === 'alternative'
|
||||
? {
|
||||
substitute_id: '',
|
||||
application: '',
|
||||
compatibility: 'pending',
|
||||
conditions: '',
|
||||
evidence: '',
|
||||
factor_numerator: 1,
|
||||
factor_denominator: 1,
|
||||
valid_until: '',
|
||||
}
|
||||
: props.kind === 'reservation'
|
||||
? {
|
||||
requisition_item_id: '',
|
||||
quantity: '',
|
||||
needed_on: '',
|
||||
additional: false,
|
||||
reference: '',
|
||||
}
|
||||
: {
|
||||
purchase_order_item_id: '',
|
||||
quantity: '',
|
||||
expected_on: '',
|
||||
confirmed_on: '',
|
||||
evidence: '',
|
||||
}),
|
||||
};
|
||||
if (old) {
|
||||
for (const key of Object.keys(defaults))
|
||||
if (key in old.data) defaults[key] = old.data[key];
|
||||
if (old.data.quantity_milli !== undefined)
|
||||
defaults.quantity = Number(old.data.quantity_milli) / 1000;
|
||||
}
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
action: 'save',
|
||||
reason: '',
|
||||
data: defaults,
|
||||
});
|
||||
const update = (key: string, value: Fields[string]) =>
|
||||
form.setData('data', { ...form.data.data, [key]: value });
|
||||
const field = (
|
||||
key: string,
|
||||
label: string,
|
||||
type = 'text',
|
||||
optional = false,
|
||||
) => (
|
||||
<label className="grid gap-1 text-sm">
|
||||
{label}
|
||||
{optional && ' (opcional)'}
|
||||
<input
|
||||
className={controlClass}
|
||||
type={type}
|
||||
required={!optional}
|
||||
min={type === 'number' ? 0 : undefined}
|
||||
step={type === 'number' ? '0.001' : undefined}
|
||||
maxLength={type === 'text' ? 4000 : undefined}
|
||||
value={String(form.data.data[key] ?? '')}
|
||||
onChange={(e) => update(key, e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
const selector = (
|
||||
key: string,
|
||||
label: string,
|
||||
entries: { id: number; label: string }[],
|
||||
) => (
|
||||
<label className="grid gap-1 text-sm">
|
||||
{label}
|
||||
<select
|
||||
required
|
||||
className={controlClass}
|
||||
value={String(form.data.data[key])}
|
||||
onChange={(e) => update(key, e.target.value)}
|
||||
>
|
||||
<option value="">Seleccionar cadastro existente</option>
|
||||
{entries.map((entry) => (
|
||||
<option value={entry.id} key={entry.id}>
|
||||
{entry.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
const sources =
|
||||
props.kind === 'delivery' ? props.orderLines : props.requestLines;
|
||||
return (
|
||||
<form
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.transform((input) => {
|
||||
const data = { ...input.data };
|
||||
if (props.kind !== 'alternative') {
|
||||
data.quantity_milli = Math.round(
|
||||
Number(data.quantity) * 1000,
|
||||
);
|
||||
delete data.quantity;
|
||||
}
|
||||
return { ...input, data };
|
||||
});
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
form.setData('operation_key', crypto.randomUUID()),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{props.kind !== 'alternative' && (
|
||||
<label className="grid gap-1 text-sm">
|
||||
{props.kind === 'delivery'
|
||||
? 'Linha da ordem emitida'
|
||||
: 'Reutilizar necessidade aprovada (opcional)'}
|
||||
<select
|
||||
required={props.kind === 'delivery'}
|
||||
className={controlClass}
|
||||
value={String(
|
||||
form.data.data[
|
||||
props.kind === 'delivery'
|
||||
? 'purchase_order_item_id'
|
||||
: 'requisition_item_id'
|
||||
],
|
||||
)}
|
||||
onChange={(e) => {
|
||||
const source = sources.find(
|
||||
(s) => s.id === Number(e.target.value),
|
||||
);
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
[props.kind === 'delivery'
|
||||
? 'purchase_order_item_id'
|
||||
: 'requisition_item_id']:
|
||||
e.target.value,
|
||||
...(source
|
||||
? {
|
||||
...(source.stock_item_id
|
||||
? {
|
||||
stock_item_id:
|
||||
source.stock_item_id,
|
||||
}
|
||||
: {}),
|
||||
quantity:
|
||||
source.quantity_milli / 1000,
|
||||
...(source.reference
|
||||
? {
|
||||
reference:
|
||||
source.reference,
|
||||
needed_on:
|
||||
source.needed_on ??
|
||||
'',
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
{props.kind === 'delivery'
|
||||
? 'Seleccionar ordem e linha'
|
||||
: 'Necessidade nova sem requisição anterior'}
|
||||
</option>
|
||||
{sources.map((source) => (
|
||||
<option key={source.id} value={source.id}>
|
||||
{source.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{selector(
|
||||
'stock_item_id',
|
||||
'Artigo e unidade',
|
||||
props.items.map((i) => ({
|
||||
id: i.id,
|
||||
label: `${i.code} · ${i.name} (${i.unit})`,
|
||||
})),
|
||||
)}
|
||||
{selector(
|
||||
'warehouse_id',
|
||||
'Armazém de destino ou utilização',
|
||||
props.warehouses.map((w) => ({
|
||||
id: w.id,
|
||||
label: `${w.code} · ${w.name}`,
|
||||
})),
|
||||
)}
|
||||
{props.kind === 'alternative' ? (
|
||||
<>
|
||||
{selector(
|
||||
'substitute_id',
|
||||
'Artigo substituto — neste sentido',
|
||||
props.items
|
||||
.filter(
|
||||
(i) =>
|
||||
i.id !==
|
||||
Number(form.data.data.stock_item_id),
|
||||
)
|
||||
.map((i) => ({
|
||||
id: i.id,
|
||||
label: `${i.code} · ${i.name} (${i.unit})`,
|
||||
})),
|
||||
)}
|
||||
{field(
|
||||
'application',
|
||||
'Aplicação ou equipamento autorizado',
|
||||
)}
|
||||
<label className="grid gap-1 text-sm">
|
||||
Resultado da análise
|
||||
<select
|
||||
className={controlClass}
|
||||
value={String(form.data.data.compatibility)}
|
||||
onChange={(e) =>
|
||||
update('compatibility', e.target.value)
|
||||
}
|
||||
>
|
||||
{Object.entries(compatibility).map(
|
||||
([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{key === 'equivalent'
|
||||
? 'Equivalente — a validar'
|
||||
: label}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
{form.data.data.compatibility === 'conditional' &&
|
||||
field(
|
||||
'conditions',
|
||||
'Condições obrigatórias de utilização',
|
||||
)}
|
||||
{field(
|
||||
'evidence',
|
||||
'Referência das especificações comparadas e evidência técnica',
|
||||
)}
|
||||
{field('valid_until', 'Validade da análise', 'date')}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{field(
|
||||
'quantity',
|
||||
props.kind === 'delivery'
|
||||
? 'Quantidade acumulada confirmada na linha (inclui recepções anteriores)'
|
||||
: 'Quantidade na unidade do artigo',
|
||||
'number',
|
||||
)}
|
||||
{props.kind === 'reservation' ? (
|
||||
<>
|
||||
{field(
|
||||
'needed_on',
|
||||
'Data da necessidade',
|
||||
'date',
|
||||
)}
|
||||
{!form.data.data.requisition_item_id &&
|
||||
field(
|
||||
'reference',
|
||||
'Referência única da necessidade',
|
||||
)}
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(
|
||||
form.data.data.additional,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
update(
|
||||
'additional',
|
||||
e.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
Procura adicional à previsão habitual
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{field(
|
||||
'expected_on',
|
||||
'Disponível para utilização em',
|
||||
'date',
|
||||
)}
|
||||
{field(
|
||||
'confirmed_on',
|
||||
'Data da confirmação do fornecedor',
|
||||
'date',
|
||||
)}
|
||||
{field(
|
||||
'evidence',
|
||||
'Referência da confirmação recebida',
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{props.kind === 'alternative' && (
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Conversão técnica de quantidades
|
||||
</summary>
|
||||
<p className="my-3 text-sm text-muted-foreground">
|
||||
Quantidade do substituto = quantidade original ×
|
||||
numerador ÷ denominador. O factor pertence apenas a esta
|
||||
relação e necessita da validação técnica.
|
||||
</p>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{field('factor_numerator', 'Numerador', 'number')}
|
||||
{field('factor_denominator', 'Denominador', 'number')}
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
<label className="grid gap-1 text-sm">
|
||||
Fundamento da preparação ou alteração
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
value={form.data.reason}
|
||||
onChange={(e) => form.setData('reason', e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing || !props.ready}>
|
||||
Guardar{' '}
|
||||
{props.kind === 'alternative'
|
||||
? 'análise para validação'
|
||||
: 'registo'}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
const reopened =
|
||||
props.kind === 'reservation' &&
|
||||
record.state === 'fulfilled' &&
|
||||
(props.pending[record.record_key] ?? 0) > 0;
|
||||
const [action, setAction] = useState('');
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: record.record_key,
|
||||
version: record.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { stock_operation_id: '', quantity_milli: 0 },
|
||||
quantity: '',
|
||||
});
|
||||
const choices =
|
||||
props.kind === 'alternative'
|
||||
? props.canReview
|
||||
? record.state === 'approved'
|
||||
? [['suspend', 'Suspender aprovação']]
|
||||
: ['draft', 'returned'].includes(record.state)
|
||||
? [
|
||||
['approve', 'Validar análise'],
|
||||
['return', 'Devolver para correcção'],
|
||||
]
|
||||
: []
|
||||
: []
|
||||
: (record.state === 'active' || reopened) && props.canReview
|
||||
? [
|
||||
...(props.kind === 'reservation'
|
||||
? [['fulfil', 'Associar saída efectiva']]
|
||||
: []),
|
||||
['cancel', 'Cancelar pendência'],
|
||||
]
|
||||
: [];
|
||||
return (
|
||||
<div className="mt-4 space-y-3">
|
||||
{props.canPrepare &&
|
||||
(props.kind === 'alternative'
|
||||
? ['draft', 'returned'].includes(record.state)
|
||||
: record.state === 'active' || reopened) && (
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Rever os dados desta preparação
|
||||
</summary>
|
||||
<Prepare props={props} old={record} />
|
||||
</details>
|
||||
)}
|
||||
{choices.length > 0 && (
|
||||
<label className="grid gap-1 text-sm">
|
||||
Acção da minha responsabilidade
|
||||
<select
|
||||
className={controlClass}
|
||||
value={action}
|
||||
onChange={(e) => {
|
||||
setAction(e.target.value);
|
||||
form.setData('action', e.target.value);
|
||||
}}
|
||||
>
|
||||
<option value="">Seleccionar acção</option>
|
||||
{choices.map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{action && (
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.transform((input) => ({
|
||||
...input,
|
||||
data: {
|
||||
...input.data,
|
||||
quantity_milli: Math.round(
|
||||
Number(input.quantity) * 1000,
|
||||
),
|
||||
},
|
||||
}));
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{action === 'fulfil' && (
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Saída já registada
|
||||
<select
|
||||
required
|
||||
className={controlClass}
|
||||
value={form.data.data.stock_operation_id}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
stock_operation_id: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Seleccionar saída existente
|
||||
</option>
|
||||
{props.operations
|
||||
.filter(
|
||||
(o) =>
|
||||
o.stock_item_id ===
|
||||
Number(
|
||||
record.data
|
||||
.stock_item_id,
|
||||
) &&
|
||||
o.warehouse_id ===
|
||||
Number(
|
||||
record.data
|
||||
.warehouse_id,
|
||||
),
|
||||
)
|
||||
.map((o) => (
|
||||
<option key={o.id} value={o.id}>
|
||||
{o.reference} ·{' '}
|
||||
{quantity(o.quantity_milli)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Quantidade satisfeita nesta saída
|
||||
<input
|
||||
className={controlClass}
|
||||
type="number"
|
||||
step="0.001"
|
||||
min="0.001"
|
||||
required
|
||||
value={form.data.quantity}
|
||||
onChange={(e) =>
|
||||
form.setData('quantity', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
<label className="grid gap-1 text-sm">
|
||||
Fundamento da decisão
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>Confirmar</Button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Facts({
|
||||
record: r,
|
||||
pending,
|
||||
reversed,
|
||||
}: {
|
||||
record: RecordVersion;
|
||||
pending?: number;
|
||||
reversed?: number[];
|
||||
}) {
|
||||
const corrected = reversed ?? r.snapshot.reversed_operations ?? [];
|
||||
const applied =
|
||||
r.snapshot.effective_allocated_milli ??
|
||||
r.data.applications?.reduce((sum, a) => sum + a.quantity_milli, 0) ??
|
||||
0;
|
||||
return (
|
||||
<div className="space-y-2 text-sm">
|
||||
{r.snapshot.substitute && (
|
||||
<>
|
||||
<p>
|
||||
Substituto:{' '}
|
||||
<strong>
|
||||
{r.snapshot.substitute.code} ·{' '}
|
||||
{r.snapshot.substitute.name}
|
||||
</strong>
|
||||
</p>
|
||||
<p>
|
||||
{compatibility[String(r.data.compatibility)]} ·
|
||||
Aplicação: {String(r.data.application)}
|
||||
</p>
|
||||
<p>
|
||||
Válida até {String(r.data.valid_until)} · Conversão:{' '}
|
||||
{String(r.data.factor_numerator)} /{' '}
|
||||
{String(r.data.factor_denominator)}
|
||||
</p>
|
||||
{r.data.conditions && (
|
||||
<p>Condições: {String(r.data.conditions)}</p>
|
||||
)}
|
||||
<p>Evidência: {String(r.data.evidence)}</p>
|
||||
</>
|
||||
)}
|
||||
{r.data.quantity_milli !== undefined && (
|
||||
<p>
|
||||
{r.snapshot.order
|
||||
? 'Quantidade acumulada confirmada: '
|
||||
: 'Quantidade: '}
|
||||
<strong>
|
||||
{quantity(Number(r.data.quantity_milli))}{' '}
|
||||
{r.snapshot.item.unit}
|
||||
</strong>
|
||||
{r.data.applications &&
|
||||
` · Pendente: ${quantity(pending ?? Number(r.data.quantity_milli) - applied)}`}
|
||||
</p>
|
||||
)}
|
||||
{r.data.needed_on && (
|
||||
<p>
|
||||
Necessária em {String(r.data.needed_on)} ·{' '}
|
||||
{r.data.additional
|
||||
? 'Procura adicional'
|
||||
: 'Incluída na previsão habitual'}{' '}
|
||||
· {String(r.data.reference)}
|
||||
</p>
|
||||
)}
|
||||
{r.data.expected_on && (
|
||||
<p>
|
||||
{r.snapshot.order?.number} · Disponibilidade prevista:{' '}
|
||||
{String(r.data.expected_on)} · Confirmação de{' '}
|
||||
{String(r.data.confirmed_on)}
|
||||
</p>
|
||||
)}
|
||||
{r.data.applications?.map((a, i) => (
|
||||
<p key={i}>
|
||||
Saída {a.reference}: {quantity(a.quantity_milli)}{' '}
|
||||
{r.snapshot.item.unit}
|
||||
{corrected.includes(a.operation_id) &&
|
||||
' · Estornada; não satisfaz a pendência actual'}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Coordination(props: Props) {
|
||||
return (
|
||||
<>
|
||||
<Head title={titles[props.kind]} />
|
||||
<div className="space-y-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras · Fornecimento e reposição"
|
||||
title={titles[props.kind]}
|
||||
description={
|
||||
props.kind === 'alternative'
|
||||
? 'Relações direccionais por artigo, aplicação e local. A validação num sentido não autoriza o sentido inverso.'
|
||||
: props.kind === 'reservation'
|
||||
? 'Necessidades conhecidas por artigo e local, satisfeitas por saídas já registadas no armazém.'
|
||||
: 'Confirmações do fornecedor sobre ordens existentes. Apenas as quantidades pendentes entram no calendário.'
|
||||
}
|
||||
/>
|
||||
{!props.ready && (
|
||||
<p role="status">Instalação do fornecimento pendente.</p>
|
||||
)}
|
||||
<Panel title="Responsabilidade desta etapa">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{props.kind === 'alternative'
|
||||
? 'A equipa técnica prepara a análise; um validador independente decide. Relações pendentes, incompatíveis, expiradas ou suspensas ficam excluídas das alternativas elegíveis. Uma substituição condicionada exige confirmação das condições na utilização.'
|
||||
: props.kind === 'reservation'
|
||||
? 'Armazém reserva e associa saídas efectivas. A afectação não repete a saída nem altera o stock físico. A reserva pendente entra na sua data e não duplica a procura já prevista.'
|
||||
: 'Compras regista a confirmação e as alterações de prazo. Armazém regista a recepção no circuito existente. Mercadoria importada retida fica fora das entradas utilizáveis do calendário.'}
|
||||
</p>
|
||||
</Panel>
|
||||
{props.canPrepare && (
|
||||
<Panel
|
||||
title={
|
||||
props.kind === 'alternative'
|
||||
? 'Preparar análise técnica'
|
||||
: props.kind === 'reservation'
|
||||
? 'Reservar uma necessidade'
|
||||
: 'Confirmar uma entrega'
|
||||
}
|
||||
>
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Abrir preparação
|
||||
</summary>
|
||||
<Prepare props={props} />
|
||||
</details>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.length === 0 && (
|
||||
<Panel title="Sem registos">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Ainda não existem registos para a sua empresa nesta
|
||||
área.
|
||||
</p>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.map((r) => (
|
||||
<Panel
|
||||
key={r.id}
|
||||
title={`${r.snapshot.item.code} · ${r.snapshot.item.name}`}
|
||||
description={`${r.snapshot.warehouse.name} · ${states[r.state]} · Versão ${r.version}`}
|
||||
>
|
||||
<Facts
|
||||
record={r}
|
||||
pending={
|
||||
props.kind === 'reservation'
|
||||
? props.pending[r.record_key]
|
||||
: undefined
|
||||
}
|
||||
reversed={props.reversedOperations}
|
||||
/>
|
||||
{props.kind === 'reservation' &&
|
||||
r.state === 'fulfilled' &&
|
||||
(props.pending[r.record_key] ?? 0) > 0 && (
|
||||
<p className="mt-2 text-sm font-medium">
|
||||
Pendência reaberta por estorno de saída. A
|
||||
associação anterior permanece no histórico.
|
||||
</p>
|
||||
)}
|
||||
{props.kind === 'delivery' && r.state === 'active' && (
|
||||
<p className="mt-2 text-sm font-medium">
|
||||
Ainda por receber:{' '}
|
||||
{quantity(props.pending[r.record_key] ?? 0)}{' '}
|
||||
{r.snapshot.item.unit}
|
||||
</p>
|
||||
)}
|
||||
{props.kind === 'alternative' && (
|
||||
<p className="mt-3 text-sm font-medium">
|
||||
{props.eligible[r.record_key]
|
||||
? 'Equivalência vigente para esta aplicação e sentido'
|
||||
: 'Excluída da utilização automática; consulte estado, condições, validade e cadastro'}
|
||||
</p>
|
||||
)}
|
||||
<p className="mt-3 text-sm text-muted-foreground">
|
||||
{r.reason}
|
||||
</p>
|
||||
<Actions props={props} record={r} />
|
||||
<details className="mt-4">
|
||||
<summary className="cursor-pointer text-sm">
|
||||
Histórico preservado
|
||||
</summary>
|
||||
<ol className="mt-3 space-y-4">
|
||||
{props.history[r.record_key]?.map((h) => (
|
||||
<li
|
||||
className="border-l-2 pl-4 text-sm"
|
||||
key={h.id}
|
||||
>
|
||||
<p className="font-medium">
|
||||
Versão {h.version} ·{' '}
|
||||
{states[h.state]} ·{' '}
|
||||
{new Date(
|
||||
h.created_at,
|
||||
).toLocaleString('pt-MZ')}
|
||||
</p>
|
||||
<p className="mb-2">{h.reason}</p>
|
||||
<Facts record={h} />
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</details>
|
||||
</Panel>
|
||||
))}
|
||||
<p className="flex flex-wrap gap-5 text-sm">
|
||||
<Link
|
||||
className="underline"
|
||||
href="/compras/fornecimento?view=calendar"
|
||||
>
|
||||
Reposição e calendário
|
||||
</Link>
|
||||
<Link className="underline" href="/stock/operacoes">
|
||||
Saídas e inventários
|
||||
</Link>
|
||||
<Link className="underline" href="/recepcoes">
|
||||
Recepções
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,580 @@
|
||||
import { Head, useForm } from '@inertiajs/react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Analysis = {
|
||||
days: number;
|
||||
total_milli: number;
|
||||
daily_mean_milli: string;
|
||||
active_days: number;
|
||||
zero_balance_days: number;
|
||||
negative_balance_days: number;
|
||||
invalid_issue: boolean;
|
||||
opening_milli: number;
|
||||
movement_count: number;
|
||||
movement_types: Record<string, number>;
|
||||
convention: string;
|
||||
series: {
|
||||
date: string;
|
||||
consumption_milli: number;
|
||||
balance_milli: number;
|
||||
}[];
|
||||
};
|
||||
type HistoryRecord = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
state: string;
|
||||
reason: string;
|
||||
created_at: string;
|
||||
data: {
|
||||
stock_item_id: number;
|
||||
warehouse_id: number;
|
||||
purpose: string;
|
||||
period_from: string;
|
||||
period_until: string;
|
||||
quality: string;
|
||||
pattern: string;
|
||||
};
|
||||
snapshot: {
|
||||
item: { code: string; name: string; unit: string };
|
||||
warehouse: { name: string };
|
||||
analysis: Analysis;
|
||||
contributors: number[];
|
||||
actor: { name: string };
|
||||
};
|
||||
};
|
||||
type Props = {
|
||||
ready: boolean;
|
||||
actorId: number;
|
||||
canPrepare: boolean;
|
||||
canReview: boolean;
|
||||
records: HistoryRecord[];
|
||||
history: Record<string, HistoryRecord[]>;
|
||||
items: { id: number; code: string; name: string; unit: string }[];
|
||||
warehouses: { id: number; code: string; name: string }[];
|
||||
defaultPeriod: { from: string; until: string };
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
draft: 'Para conferência',
|
||||
returned: 'Devolvida para actualização',
|
||||
approved: 'Análise conferida',
|
||||
suspended: 'Análise suspensa',
|
||||
};
|
||||
const quality: Record<string, string> = {
|
||||
unknown: 'Cobertura por confirmar',
|
||||
complete: 'Cobertura completa sem procura oculta conhecida',
|
||||
incomplete: 'Período incompleto ou âmbito misto não separado',
|
||||
stockout: 'Ruptura ou procura não satisfeita conhecida',
|
||||
};
|
||||
const patterns: Record<string, string> = {
|
||||
unknown: 'Padrão por confirmar',
|
||||
regular: 'Regular — média simples aplicável',
|
||||
seasonal: 'Sazonal — exige método próprio',
|
||||
intermittent: 'Intermitente — exige método próprio',
|
||||
};
|
||||
const movementNames: Record<string, string> = {
|
||||
issue: 'Saídas de consumo',
|
||||
receipt_in: 'Recepções',
|
||||
transfer_in: 'Transferências de entrada',
|
||||
transfer_out: 'Transferências de saída',
|
||||
adjustment: 'Ajustes',
|
||||
adjustment_in: 'Ajustes de entrada por lote',
|
||||
adjustment_out: 'Ajustes de saída por lote',
|
||||
supplier_return: 'Devoluções ao fornecedor',
|
||||
write_off: 'Abates físicos',
|
||||
reversal_in: 'Estornos de entrada',
|
||||
reversal_out: 'Estornos de saída',
|
||||
count: 'Contagens',
|
||||
};
|
||||
const qty = (milli: number | string, mean = false) =>
|
||||
(Number(milli) / 1000).toLocaleString('pt-MZ', {
|
||||
maximumFractionDigits: mean ? 9 : 3,
|
||||
});
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: HistoryRecord }) {
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
action: 'save',
|
||||
reason: '',
|
||||
data: {
|
||||
stock_item_id: old ? String(old.data.stock_item_id) : '',
|
||||
warehouse_id: old ? String(old.data.warehouse_id) : '',
|
||||
purpose: old?.data.purpose ?? 'internal',
|
||||
period_from: old?.data.period_from ?? props.defaultPeriod.from,
|
||||
period_until: old?.data.period_until ?? props.defaultPeriod.until,
|
||||
quality: old?.data.quality ?? 'unknown',
|
||||
pattern: old?.data.pattern ?? 'unknown',
|
||||
},
|
||||
});
|
||||
const select = (
|
||||
key: keyof typeof form.data.data,
|
||||
label: string,
|
||||
options: [string, string][],
|
||||
disabled = false,
|
||||
) => (
|
||||
<label className="grid gap-1 text-sm">
|
||||
{label}
|
||||
<select
|
||||
className={controlClass}
|
||||
required
|
||||
disabled={disabled}
|
||||
value={form.data.data[key]}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
{options.map(([value, text]) => (
|
||||
<option key={value} value={value}>
|
||||
{text}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<form
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/history', {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{select(
|
||||
'stock_item_id',
|
||||
'Artigo existente',
|
||||
[
|
||||
['', 'Seleccionar artigo'],
|
||||
...props.items.map(
|
||||
(i) =>
|
||||
[
|
||||
String(i.id),
|
||||
`${i.code} · ${i.name} (${i.unit})`,
|
||||
] as [string, string],
|
||||
),
|
||||
],
|
||||
Boolean(old),
|
||||
)}
|
||||
{select(
|
||||
'warehouse_id',
|
||||
'Local de armazenamento',
|
||||
[
|
||||
['', 'Seleccionar armazém'],
|
||||
...props.warehouses.map(
|
||||
(w) =>
|
||||
[String(w.id), `${w.code} · ${w.name}`] as [
|
||||
string,
|
||||
string,
|
||||
],
|
||||
),
|
||||
],
|
||||
Boolean(old),
|
||||
)}
|
||||
{select(
|
||||
'purpose',
|
||||
'Finalidade dos consumos analisados',
|
||||
[
|
||||
['internal', 'Uso interno e reposição'],
|
||||
['resale', 'Revenda'],
|
||||
],
|
||||
Boolean(old),
|
||||
)}
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Desde
|
||||
<input
|
||||
type="date"
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.data.period_from}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
period_from: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Até (dia completo)
|
||||
<input
|
||||
type="date"
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.data.period_until}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
period_until: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{select(
|
||||
'quality',
|
||||
'Cobertura do histórico',
|
||||
Object.entries(quality),
|
||||
)}
|
||||
{select(
|
||||
'pattern',
|
||||
'Padrão observado',
|
||||
Object.entries(patterns),
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
O sistema calcula os valores a partir dos movimentos. Confirme a
|
||||
finalidade e a cobertura do período; quando as saídas misturam
|
||||
finalidades sem separação, assinale cobertura incompleta.
|
||||
</p>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Evidências e fundamento da cobertura/padrão
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(e) => form.setData('reason', e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing || !props.ready}>
|
||||
Calcular e guardar análise para conferência
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function Facts({
|
||||
record: r,
|
||||
series = false,
|
||||
}: {
|
||||
record: HistoryRecord;
|
||||
series?: boolean;
|
||||
}) {
|
||||
const a = r.snapshot.analysis;
|
||||
return (
|
||||
<div className="space-y-3 text-sm">
|
||||
<p>
|
||||
{r.data.period_from} a {r.data.period_until} · {a.days} dias
|
||||
corridos ·{' '}
|
||||
{r.data.purpose === 'resale' ? 'Revenda' : 'Uso interno'}
|
||||
</p>
|
||||
<div className="grid gap-3 md:grid-cols-4">
|
||||
<p>
|
||||
Consumo registado
|
||||
<br />
|
||||
<strong>
|
||||
{qty(a.total_milli)} {r.snapshot.item.unit}
|
||||
</strong>
|
||||
</p>
|
||||
<p>
|
||||
Média observada por dia
|
||||
<br />
|
||||
<strong>
|
||||
{qty(a.daily_mean_milli, true)} {r.snapshot.item.unit}
|
||||
</strong>
|
||||
</p>
|
||||
<p>
|
||||
Dias com consumo
|
||||
<br />
|
||||
<strong>
|
||||
{a.active_days} de {a.days}
|
||||
</strong>
|
||||
</p>
|
||||
<p>
|
||||
Saldo final nulo
|
||||
<br />
|
||||
<strong>{a.zero_balance_days} dias</strong>
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
{quality[r.data.quality]} · {patterns[r.data.pattern]}
|
||||
</p>
|
||||
{(a.invalid_issue ||
|
||||
a.negative_balance_days > 0 ||
|
||||
a.opening_milli < 0) && (
|
||||
<p className="font-medium">
|
||||
Foram detectadas inconsistências de movimentos ou saldos
|
||||
negativos. Reconcilie o razão antes de reutilizar a média.
|
||||
</p>
|
||||
)}
|
||||
{a.total_milli === 0 && (
|
||||
<p className="font-medium">
|
||||
Não há consumo registado neste período. Só é considerado
|
||||
consumo zero confirmado após conferência da cobertura
|
||||
completa; ausência de saídas não prova ausência de procura.
|
||||
</p>
|
||||
)}
|
||||
{r.state === 'approved' &&
|
||||
(r.data.quality !== 'complete' ||
|
||||
r.data.pattern !== 'regular') && (
|
||||
<p className="font-medium">
|
||||
A análise está conferida, mas não pode alimentar
|
||||
automaticamente uma média simples. Mantém-se o
|
||||
planeamento manual ou por necessidades conhecidas.
|
||||
</p>
|
||||
)}
|
||||
{series && (
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Consultar dias e movimentos considerados
|
||||
</summary>
|
||||
<div className="mt-3 space-y-3">
|
||||
<p>{a.convention}</p>
|
||||
<p>
|
||||
{a.movement_count} movimentos no período ·{' '}
|
||||
{Object.entries(a.movement_types)
|
||||
.map(
|
||||
([type, count]) =>
|
||||
`${movementNames[type] ?? 'Outro movimento'}: ${count}`,
|
||||
)
|
||||
.join(' · ') || 'Sem movimentos no período'}
|
||||
</p>
|
||||
<p className="text-muted-foreground">
|
||||
Dias sem saída entram no denominador. Saldo final
|
||||
positivo não prova ausência de rupturas durante o
|
||||
dia; a conferência humana verifica lacunas e procura
|
||||
não satisfeita.
|
||||
</p>
|
||||
<div className="max-h-72 overflow-auto">
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="text-left">Data</th>
|
||||
<th className="text-right">Consumo</th>
|
||||
<th className="text-right">
|
||||
Saldo final
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{a.series.map((day) => (
|
||||
<tr key={day.date}>
|
||||
<td>{day.date}</td>
|
||||
<td className="text-right">
|
||||
{qty(day.consumption_milli)}
|
||||
</td>
|
||||
<td className="text-right">
|
||||
{qty(day.balance_milli)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Decision({
|
||||
props,
|
||||
record: r,
|
||||
}: {
|
||||
props: Props;
|
||||
record: HistoryRecord;
|
||||
}) {
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: r.record_key,
|
||||
version: r.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { confirm_scope: false },
|
||||
});
|
||||
const independent = !r.snapshot.contributors.includes(props.actorId);
|
||||
return (
|
||||
<div className="mt-4 space-y-4">
|
||||
{props.canPrepare && ['draft', 'returned'].includes(r.state) && (
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Actualizar análise e evidências
|
||||
</summary>
|
||||
<Prepare props={props} old={r} />
|
||||
</details>
|
||||
)}
|
||||
{props.canReview && independent && r.state !== 'suspended' && (
|
||||
<>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Decisão da minha responsabilidade
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.action}
|
||||
onChange={(e) =>
|
||||
form.setData('action', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccionar acção</option>
|
||||
{r.state === 'approved' ? (
|
||||
<option value="suspend">
|
||||
Suspender reutilização
|
||||
</option>
|
||||
) : (
|
||||
<>
|
||||
<option value="approve">
|
||||
Conferir e aprovar análise
|
||||
</option>
|
||||
<option value="return">
|
||||
Devolver para correcção
|
||||
</option>
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
{form.data.action && (
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/history', {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{form.data.action === 'approve' && (
|
||||
<label className="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={form.data.data.confirm_scope}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
confirm_scope: e.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Conferi os movimentos, a finalidade, a
|
||||
cobertura declarada, o padrão e a existência
|
||||
de rupturas ou procura oculta. A ausência de
|
||||
movimentos não foi tomada automaticamente
|
||||
como consumo zero.
|
||||
</label>
|
||||
)}
|
||||
<label className="grid gap-1 text-sm">
|
||||
Fundamento da decisão
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>
|
||||
Confirmar decisão
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function History(props: Props) {
|
||||
return (
|
||||
<>
|
||||
<Head title="Histórico de consumo" />
|
||||
<div className="space-y-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Armazém · Reposição"
|
||||
title="Histórico de consumo"
|
||||
description="Reutilizar as saídas reais do razão, analisar um período fechado e conferir a qualidade antes de o aplicar numa política."
|
||||
/>
|
||||
<Panel title="Responsabilidades">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
O preparador selecciona artigo, local e período. Os
|
||||
valores são calculados pelo sistema. Outra pessoa
|
||||
confere cobertura e padrão. A política escolhe a análise
|
||||
aprovada e define o mínimo de dias e a idade máxima
|
||||
admissível; sazonalidade, intermitência e dados
|
||||
incompletos mantêm percurso manual.
|
||||
</p>
|
||||
</Panel>
|
||||
{!props.ready && (
|
||||
<p role="status">Instalação do fornecimento pendente.</p>
|
||||
)}
|
||||
{props.canPrepare && (
|
||||
<Panel title="Analisar período existente">
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Seleccionar artigo e período
|
||||
</summary>
|
||||
<Prepare props={props} />
|
||||
</details>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.length === 0 && (
|
||||
<Panel title="Sem análises">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Ainda não foi conferido um período. O sistema mantém
|
||||
a previsão histórica indisponível; não atribui
|
||||
consumo zero por falta de dados.
|
||||
</p>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.map((r) => (
|
||||
<Panel
|
||||
key={r.id}
|
||||
title={`${r.snapshot.item.code} · ${r.snapshot.item.name}`}
|
||||
description={`${r.snapshot.warehouse.name} · ${states[r.state]} · Versão ${r.version}`}
|
||||
>
|
||||
<Facts record={r} series />
|
||||
<p className="mt-3 text-sm">{r.reason}</p>
|
||||
<Decision props={props} record={r} />
|
||||
<details className="mt-4">
|
||||
<summary className="cursor-pointer text-sm">
|
||||
Histórico de análises e decisões
|
||||
</summary>
|
||||
<ol className="mt-3 space-y-4">
|
||||
{props.history[r.record_key]?.map((h) => (
|
||||
<li
|
||||
key={h.id}
|
||||
className="border-l-2 pl-4 text-sm"
|
||||
>
|
||||
<p className="font-medium">
|
||||
Versão {h.version} ·{' '}
|
||||
{states[h.state]} ·{' '}
|
||||
{h.snapshot.actor.name} ·{' '}
|
||||
{new Date(
|
||||
h.created_at,
|
||||
).toLocaleString('pt-MZ')}
|
||||
</p>
|
||||
<p className="my-2">{h.reason}</p>
|
||||
<Facts record={h} />
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</details>
|
||||
</Panel>
|
||||
))}
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Uma análise conferida pode ser seleccionada pelo responsável
|
||||
pelas políticas. A consulta do razão e a configuração de
|
||||
políticas seguem as permissões próprias desses menus.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,713 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Policy = {
|
||||
key: string;
|
||||
version: number;
|
||||
label: string;
|
||||
issue: string | null;
|
||||
quantity_milli?: number;
|
||||
delivery_on?: string | null;
|
||||
unit_price?: string | null;
|
||||
tax_rate?: string | null;
|
||||
unit?: string;
|
||||
};
|
||||
type Suggestion = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
state: string;
|
||||
reason: string;
|
||||
created_at: string;
|
||||
data: {
|
||||
policy_key: string;
|
||||
policy_version: number;
|
||||
quantity_milli: number;
|
||||
delivery_on: string;
|
||||
unit_price: string;
|
||||
tax_rate: string;
|
||||
manual_plan: boolean;
|
||||
price_source: string;
|
||||
tax_source: string;
|
||||
requisition_id?: number;
|
||||
requisition_number?: string;
|
||||
};
|
||||
snapshot: {
|
||||
forecast_history?: {
|
||||
available: boolean;
|
||||
reason?: string | null;
|
||||
period_from: string;
|
||||
period_until: string;
|
||||
version: number;
|
||||
analysis: { days: number; daily_mean_milli: string };
|
||||
};
|
||||
item: { code: string; name: string; unit: string };
|
||||
warehouse: { name: string };
|
||||
contributors: number[];
|
||||
reviewed_by?: number;
|
||||
actor: { name: string };
|
||||
prepared_on: string;
|
||||
balance: { quantity: number; version: number };
|
||||
events: {
|
||||
reservations: { date: string; quantity: number }[];
|
||||
receipts: { date: string; quantity: number }[];
|
||||
warnings: string[];
|
||||
};
|
||||
policy: { purpose: string; origin: string };
|
||||
projection: {
|
||||
lot_warning?: string;
|
||||
usable_milli?: number;
|
||||
available: boolean;
|
||||
risk_date?: string;
|
||||
request_date?: string;
|
||||
order_date?: string;
|
||||
series?: { date: string; balance_milli: number }[];
|
||||
};
|
||||
};
|
||||
};
|
||||
type Props = {
|
||||
actorId: number;
|
||||
ready: boolean;
|
||||
records: Suggestion[];
|
||||
policies: Policy[];
|
||||
canPrepare: boolean;
|
||||
canReview: boolean;
|
||||
canConvert: boolean;
|
||||
excess: Record<string, boolean>;
|
||||
costCenters: { id: number; code: string; name: string }[];
|
||||
requestLinks: Record<string, { id: number; number: string }>;
|
||||
history: Record<string, Suggestion[]>;
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
draft: 'Para conferência',
|
||||
returned: 'Devolvida para actualização',
|
||||
approved: 'Aprovada para requisitar',
|
||||
cancelled: 'Cancelada',
|
||||
converted: 'Requisição criada — em acompanhamento',
|
||||
closed: 'Acompanhamento encerrado',
|
||||
};
|
||||
const quantity = (value: number) =>
|
||||
(value / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
const [selected, setSelected] = useState(old?.data.policy_key ?? '');
|
||||
const option = props.policies.find((p) => p.key === selected);
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
action: 'save',
|
||||
reason: '',
|
||||
data: {
|
||||
policy_key: old?.data.policy_key ?? '',
|
||||
unit_price: option?.unit_price ?? old?.data.unit_price ?? '',
|
||||
tax_rate: option?.tax_rate ?? old?.data.tax_rate ?? '',
|
||||
quantity: old?.data.manual_plan
|
||||
? String(old.data.quantity_milli / 1000)
|
||||
: '',
|
||||
delivery_on: old?.data.manual_plan ? old.data.delivery_on : '',
|
||||
},
|
||||
});
|
||||
return (
|
||||
<form
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.transform((input) => ({
|
||||
...input,
|
||||
data: {
|
||||
policy_key: input.data.policy_key,
|
||||
unit_price: input.data.unit_price || null,
|
||||
tax_rate: input.data.tax_rate || null,
|
||||
quantity_milli:
|
||||
input.data.quantity === ''
|
||||
? null
|
||||
: Math.round(
|
||||
Number(input.data.quantity) * 1000,
|
||||
),
|
||||
delivery_on: input.data.delivery_on || null,
|
||||
},
|
||||
}));
|
||||
form.post('/compras/fornecimento/suggestion', {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<label className="grid gap-1 text-sm">
|
||||
Artigo e local com política aprovada
|
||||
<select
|
||||
required
|
||||
disabled={Boolean(old)}
|
||||
className={controlClass}
|
||||
value={selected}
|
||||
onChange={(e) => {
|
||||
const p = props.policies.find(
|
||||
(o) => o.key === e.target.value,
|
||||
);
|
||||
setSelected(e.target.value);
|
||||
form.setData('data', {
|
||||
policy_key: e.target.value,
|
||||
unit_price: p?.unit_price ?? '',
|
||||
tax_rate: p?.tax_rate ?? '',
|
||||
quantity: '',
|
||||
delivery_on: '',
|
||||
});
|
||||
}}
|
||||
>
|
||||
<option value="">Seleccionar política existente</option>
|
||||
{props.policies.map((p) => (
|
||||
<option key={p.key} value={p.key}>
|
||||
{p.label}
|
||||
</option>
|
||||
))}
|
||||
{old && !option && (
|
||||
<option value={old.data.policy_key}>
|
||||
{old.snapshot.item.code} · política de origem
|
||||
indisponível
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
{option?.issue && (
|
||||
<p role="status" className="text-sm">
|
||||
{option.issue}
|
||||
</p>
|
||||
)}
|
||||
{option && !option.issue && (
|
||||
<div className="rounded-lg bg-muted p-4 text-sm">
|
||||
<p>
|
||||
Proposta calculada:{' '}
|
||||
<strong>
|
||||
{quantity(option.quantity_milli ?? 0)} {option.unit}
|
||||
</strong>{' '}
|
||||
· Receber em{' '}
|
||||
<strong>
|
||||
{option.delivery_on ?? 'data manual por definir'}
|
||||
</strong>
|
||||
</p>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
O servidor volta a conferir as fontes ao guardar. O
|
||||
cálculo não cria requisição, ordem ou movimento de
|
||||
stock.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Estimativa por unidade em MZN
|
||||
<input
|
||||
className={controlClass}
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.01"
|
||||
required
|
||||
value={form.data.data.unit_price}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
unit_price: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{option?.unit_price
|
||||
? 'Preenchida a partir do acordo; uma alteração fica fundamentada.'
|
||||
: 'Indique a estimativa e a fonte no fundamento abaixo.'}
|
||||
</span>
|
||||
</label>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Taxa de IVA da estimativa (%)
|
||||
<input
|
||||
className={controlClass}
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
step="0.01"
|
||||
required
|
||||
value={form.data.data.tax_rate}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
tax_rate: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Valor configurado da empresa quando disponível; confirme
|
||||
a aplicação ao artigo.
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Propor quantidade ou data diferentes
|
||||
</summary>
|
||||
<p className="my-3 text-sm text-muted-foreground">
|
||||
Deixe em branco para reutilizar o cálculo actual. Alterações
|
||||
ficam identificadas e exigem conferência explícita.
|
||||
</p>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Quantidade manual
|
||||
<input
|
||||
className={controlClass}
|
||||
type="number"
|
||||
min="0.001"
|
||||
step="0.001"
|
||||
value={form.data.data.quantity}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
quantity: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Data manual de recepção
|
||||
<input
|
||||
className={controlClass}
|
||||
type="date"
|
||||
value={form.data.data.delivery_on}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
delivery_on: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</details>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Fundamento e fontes das estimativas
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(e) => form.setData('reason', e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
disabled={
|
||||
form.processing ||
|
||||
!props.ready ||
|
||||
!option ||
|
||||
Boolean(option.issue)
|
||||
}
|
||||
>
|
||||
Guardar sugestão para conferência
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function Facts({
|
||||
record: r,
|
||||
detailed = false,
|
||||
}: {
|
||||
record: Suggestion;
|
||||
detailed?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="grid gap-3 md:grid-cols-4">
|
||||
<p>
|
||||
Quantidade
|
||||
<br />
|
||||
<strong>
|
||||
{quantity(r.data.quantity_milli)} {r.snapshot.item.unit}
|
||||
</strong>
|
||||
</p>
|
||||
<p>
|
||||
Receber em
|
||||
<br />
|
||||
<strong>{r.data.delivery_on}</strong>
|
||||
</p>
|
||||
<p>
|
||||
Estimativa por unidade
|
||||
<br />
|
||||
<strong>{r.data.unit_price} MZN</strong>
|
||||
</p>
|
||||
<p>
|
||||
IVA da estimativa
|
||||
<br />
|
||||
<strong>{r.data.tax_rate}%</strong>
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-muted-foreground">
|
||||
{r.snapshot.policy.purpose === 'resale'
|
||||
? 'Revenda'
|
||||
: 'Uso interno'}{' '}
|
||||
·{' '}
|
||||
{r.snapshot.policy.origin === 'import'
|
||||
? 'Importação directa'
|
||||
: 'Compra local'}{' '}
|
||||
· Política versão {r.data.policy_version} · Preparação de{' '}
|
||||
{r.snapshot.prepared_on}
|
||||
</p>
|
||||
<p>
|
||||
Preço:{' '}
|
||||
{r.data.price_source === 'agreement'
|
||||
? 'reutilizado do acordo'
|
||||
: 'estimativa manual fundamentada'}{' '}
|
||||
· IVA:{' '}
|
||||
{r.data.tax_source === 'company_default'
|
||||
? 'configuração da empresa'
|
||||
: 'taxa confirmada manualmente'}
|
||||
</p>
|
||||
{r.snapshot.projection.lot_warning && (
|
||||
<p className="font-medium">
|
||||
{r.snapshot.projection.lot_warning} Utilizável no cálculo:{' '}
|
||||
{quantity(r.snapshot.projection.usable_milli ?? 0)}.
|
||||
</p>
|
||||
)}
|
||||
{r.snapshot.forecast_history && (
|
||||
<p>
|
||||
{r.snapshot.forecast_history.available
|
||||
? `Média histórica preservada: ${r.snapshot.forecast_history.period_from} a ${r.snapshot.forecast_history.period_until}, ${r.snapshot.forecast_history.analysis.days} dias, versão ${r.snapshot.forecast_history.version}.`
|
||||
: `Histórico indisponível no cálculo: ${r.snapshot.forecast_history.reason}`}
|
||||
</p>
|
||||
)}
|
||||
{r.data.manual_plan && (
|
||||
<p className="font-medium">
|
||||
Quantidade/data propostas manualmente ou procura habitual
|
||||
incompleta.
|
||||
</p>
|
||||
)}
|
||||
{r.snapshot.events.warnings.map((w) => (
|
||||
<p key={w} className="font-medium">
|
||||
{w}
|
||||
</p>
|
||||
))}
|
||||
{detailed && (
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Base preservada da previsão
|
||||
</summary>
|
||||
<div className="mt-3 space-y-2">
|
||||
<p>
|
||||
Stock físico no cálculo:{' '}
|
||||
{quantity(r.snapshot.balance.quantity)}{' '}
|
||||
{r.snapshot.item.unit}
|
||||
</p>
|
||||
<p>
|
||||
{r.snapshot.events.reservations.length} reservas
|
||||
pendentes · {r.snapshot.events.receipts.length}{' '}
|
||||
entregas utilizáveis confirmadas
|
||||
</p>
|
||||
<p>
|
||||
Iniciar requisição até{' '}
|
||||
{r.snapshot.projection.request_date ??
|
||||
'data manual'}{' '}
|
||||
· Emitir ordem até{' '}
|
||||
{r.snapshot.projection.order_date ?? 'data manual'}
|
||||
</p>
|
||||
<div className="max-h-64 overflow-auto">
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="text-left">Data</th>
|
||||
<th className="text-right">
|
||||
Saldo sem a nova reposição
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.snapshot.projection.series?.map(
|
||||
(day) => (
|
||||
<tr key={day.date}>
|
||||
<td>{day.date}</td>
|
||||
<td className="text-right">
|
||||
{quantity(
|
||||
day.balance_milli,
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Decisions({ props, record: r }: { props: Props; record: Suggestion }) {
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: r.record_key,
|
||||
version: r.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { cost_center_id: '', confirm_exception: false },
|
||||
});
|
||||
const independent = !r.snapshot.contributors.includes(props.actorId);
|
||||
const choices: [string, string][] = [];
|
||||
if (props.canReview && independent) {
|
||||
if (
|
||||
['draft', 'returned'].includes(r.state) &&
|
||||
!props.excess[r.record_key]
|
||||
)
|
||||
choices.push(['approve', 'Aprovar para requisitar']);
|
||||
if (['draft', 'approved'].includes(r.state))
|
||||
choices.push(['return', 'Devolver para actualização']);
|
||||
if (r.state === 'converted')
|
||||
choices.push(['close', 'Conferir e encerrar acompanhamento']);
|
||||
}
|
||||
if (props.canPrepare && ['draft', 'returned'].includes(r.state))
|
||||
choices.push(['cancel', 'Cancelar sugestão pendente']);
|
||||
if (
|
||||
props.canConvert &&
|
||||
r.state === 'approved' &&
|
||||
r.snapshot.reviewed_by !== props.actorId
|
||||
)
|
||||
choices.push(['convert', 'Criar requisição a partir desta aprovação']);
|
||||
return (
|
||||
<div className="mt-4 space-y-4">
|
||||
{props.excess[r.record_key] && (
|
||||
<p className="text-sm font-medium">
|
||||
A quantidade excede o máximo no horizonte. Reveja
|
||||
quantidade, calendário ou política antes da aprovação.
|
||||
</p>
|
||||
)}
|
||||
{props.canPrepare && ['draft', 'returned'].includes(r.state) && (
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Actualizar fontes e preparação
|
||||
</summary>
|
||||
<Prepare props={props} old={r} />
|
||||
</details>
|
||||
)}
|
||||
{choices.length > 0 && (
|
||||
<label className="grid gap-1 text-sm">
|
||||
Acção da minha responsabilidade
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.action}
|
||||
onChange={(e) => form.setData('action', e.target.value)}
|
||||
>
|
||||
<option value="">Seleccionar acção</option>
|
||||
{choices.map(([key, label]) => (
|
||||
<option value={key} key={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{form.data.action && (
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/suggestion', {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{form.data.action === 'approve' &&
|
||||
(r.data.manual_plan ||
|
||||
r.snapshot.events.warnings.length > 0) && (
|
||||
<label className="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={form.data.data.confirm_exception}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
confirm_exception: e.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Conferi a proposta manual ou as pendências e
|
||||
fundamento a decisão abaixo.
|
||||
</label>
|
||||
)}
|
||||
{form.data.action === 'convert' && (
|
||||
<>
|
||||
<label className="grid gap-1 text-sm">
|
||||
Centro de custo do meu departamento
|
||||
<select
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.data.cost_center_id}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
cost_center_id: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Seleccionar centro existente
|
||||
</option>
|
||||
{props.costCenters.map((center) => (
|
||||
<option
|
||||
value={center.id}
|
||||
key={center.id}
|
||||
>
|
||||
{center.code} · {center.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Será criado um único rascunho com o artigo do
|
||||
catálogo, quantidade, data e estimativas
|
||||
aprovadas. A requisição mantém as aprovações,
|
||||
controlo orçamental e etapas de compra
|
||||
habituais.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<label className="grid gap-1 text-sm">
|
||||
{form.data.action === 'convert'
|
||||
? 'Justificação da requisição'
|
||||
: 'Fundamento da decisão'}
|
||||
<textarea
|
||||
className="rounded-lg border p-3"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>Confirmar</Button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Suggestions(props: Props) {
|
||||
return (
|
||||
<>
|
||||
<Head title="Sugestões de reposição" />
|
||||
<div className="space-y-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras · Reposição"
|
||||
title="Sugestões de reposição"
|
||||
description="Preparar, conferir e requisitar a partir dos dados já registados. Cada sugestão conserva o cálculo e as fontes utilizados."
|
||||
/>
|
||||
<Panel title="Responsabilidades">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
O preparador reúne a proposta; outra pessoa confere. O
|
||||
solicitante autorizado converte a aprovação numa
|
||||
requisição do seu departamento. A pessoa que conferiu
|
||||
não se torna autora dessa requisição. Uma necessidade em
|
||||
acompanhamento mantém a ligação ao documento existente.
|
||||
</p>
|
||||
</Panel>
|
||||
{!props.ready && (
|
||||
<p role="status">Instalação do fornecimento pendente.</p>
|
||||
)}
|
||||
{props.canPrepare && (
|
||||
<Panel title="Preparar sugestão">
|
||||
<details>
|
||||
<summary className="cursor-pointer font-medium">
|
||||
Seleccionar artigo e política
|
||||
</summary>
|
||||
<Prepare props={props} />
|
||||
</details>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.length === 0 && (
|
||||
<Panel title="Sem sugestões">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
O cálculo do calendário não cria documentos
|
||||
automaticamente. Um preparador autorizado pode
|
||||
guardar uma sugestão para conferência.
|
||||
</p>
|
||||
</Panel>
|
||||
)}
|
||||
{props.records.map((r) => (
|
||||
<Panel
|
||||
key={r.id}
|
||||
title={`${r.snapshot.item.code} · ${r.snapshot.item.name}`}
|
||||
description={`${r.snapshot.warehouse.name} · ${states[r.state]} · Versão ${r.version}`}
|
||||
>
|
||||
<Facts record={r} detailed />
|
||||
<p className="mt-3 text-sm">{r.reason}</p>
|
||||
{r.data.requisition_id && (
|
||||
<p className="mt-3 text-sm font-medium">
|
||||
{props.requestLinks[
|
||||
String(r.data.requisition_id)
|
||||
] ? (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${r.data.requisition_id}`}
|
||||
>
|
||||
Abrir {r.data.requisition_number}
|
||||
</Link>
|
||||
) : (
|
||||
`Documento criado: ${r.data.requisition_number}. A consulta segue as permissões da requisição.`
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<Decisions props={props} record={r} />
|
||||
<details className="mt-4">
|
||||
<summary className="cursor-pointer text-sm">
|
||||
Histórico de preparação e decisões
|
||||
</summary>
|
||||
<ol className="mt-3 space-y-4">
|
||||
{props.history[r.record_key]?.map((h) => (
|
||||
<li
|
||||
className="border-l-2 pl-4 text-sm"
|
||||
key={h.id}
|
||||
>
|
||||
<p className="font-medium">
|
||||
Versão {h.version} ·{' '}
|
||||
{states[h.state]} ·{' '}
|
||||
{h.snapshot.actor.name} ·{' '}
|
||||
{new Date(
|
||||
h.created_at,
|
||||
).toLocaleString('pt-MZ')}
|
||||
</p>
|
||||
<p className="my-2">{h.reason}</p>
|
||||
<Facts record={h} />
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</details>
|
||||
</Panel>
|
||||
))}
|
||||
<p className="flex flex-wrap gap-5 text-sm">
|
||||
<Link
|
||||
className="underline"
|
||||
href="/compras/fornecimento?view=calendar"
|
||||
>
|
||||
Reposição e calendário
|
||||
</Link>
|
||||
<Link className="underline" href="/requisicoes">
|
||||
Requisições
|
||||
</Link>
|
||||
<Link
|
||||
className="underline"
|
||||
href="/administracao/parametrizacao"
|
||||
>
|
||||
Perfis e responsabilidades
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user