@@ -62,6 +62,11 @@ export default function AuditMetadata({ filters, events }: Props) {
|
||||
resultados dos filtros, sem conteúdos privados,
|
||||
documentos ou valores anteriores e posteriores.
|
||||
</p>
|
||||
<p className="mt-2 text-sm">
|
||||
Preservação integral dos processos e da auditoria, sem
|
||||
eliminação automática, conforme decisão da Tempo.
|
||||
Consultar ou exportar não elimina o histórico.
|
||||
</p>
|
||||
<details className="my-4 rounded border p-3">
|
||||
<summary>Filtrar eventos</summary>
|
||||
<form
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { CompanyDetailsSettings } from '@/components/company-details-settings';
|
||||
import type { CompanyDetails } from '@/components/company-details-settings';
|
||||
import { CompanyAdministrativeLocation } from '@/components/administrative-location';
|
||||
import type { GeographyDescription } from '@/components/administrative-location';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
@@ -167,6 +169,8 @@ function Assignment({
|
||||
);
|
||||
}
|
||||
export default function Parameters({
|
||||
companyDetails,
|
||||
companyDetailsReady,
|
||||
ready,
|
||||
geographyEnabled = false,
|
||||
geography = null,
|
||||
@@ -191,6 +195,8 @@ export default function Parameters({
|
||||
workContextConfiguration,
|
||||
enabledWorkContexts = [],
|
||||
}: {
|
||||
companyDetails: CompanyDetails | null;
|
||||
companyDetailsReady: boolean;
|
||||
ready: boolean;
|
||||
geographyEnabled?: boolean;
|
||||
geography?: GeographyDescription;
|
||||
@@ -301,6 +307,11 @@ export default function Parameters({
|
||||
tasks={workflowTasks}
|
||||
/>
|
||||
)}
|
||||
<CompanyDetailsSettings
|
||||
details={companyDetails}
|
||||
ready={companyDetailsReady && ready}
|
||||
version={version}
|
||||
/>
|
||||
{!ready ? (
|
||||
<Panel title="Instalação pendente">
|
||||
<p>
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import AgreementOrderBindings, {
|
||||
type OrderAgreementBinding,
|
||||
type OrderAgreementOption,
|
||||
type OrderAgreementLine,
|
||||
} from '@/components/agreement-order-bindings';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import {
|
||||
@@ -14,6 +19,10 @@ import { money, roleLabels, date } from '@/types/procurement';
|
||||
import type { MatrixRow, PurchaseAward } from '@/types/purchase';
|
||||
|
||||
type Props = {
|
||||
agreementOrderLimitsReady?: boolean;
|
||||
agreementOptions?: OrderAgreementOption[];
|
||||
agreementLines?: OrderAgreementLine[];
|
||||
agreementSearch?: string;
|
||||
requisition: { id: number; number: string };
|
||||
comparison: {
|
||||
rows: MatrixRow[];
|
||||
@@ -37,6 +46,10 @@ export default function Award({
|
||||
canIssue,
|
||||
order,
|
||||
recommendation,
|
||||
agreementOrderLimitsReady = false,
|
||||
agreementOptions = [],
|
||||
agreementLines = [],
|
||||
agreementSearch = '',
|
||||
}: Props) {
|
||||
const selection = useForm({
|
||||
quotation_id: '',
|
||||
@@ -45,7 +58,9 @@ export default function Award({
|
||||
delivery_location: '',
|
||||
});
|
||||
const decision = useForm({ decision: 'approved', comment: '' });
|
||||
const issue = useForm({});
|
||||
const issue = useForm({
|
||||
agreement_bindings: [] as OrderAgreementBinding[],
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<Head title={`Adjudicação · ${requisition.number}`} />
|
||||
@@ -415,6 +430,22 @@ export default function Award({
|
||||
description="O servidor revalida a matriz, os conflitos e as aprovações. A ordem emitida mantém um retrato dos dados e não pode ser reescrita."
|
||||
>
|
||||
<FormErrors errors={issue.errors} />
|
||||
{agreementOrderLimitsReady && (
|
||||
<AgreementOrderBindings
|
||||
key={requisition.id}
|
||||
requestId={requisition.id}
|
||||
lines={agreementLines}
|
||||
options={agreementOptions}
|
||||
value={issue.data.agreement_bindings}
|
||||
onChange={(value) =>
|
||||
issue.setData(
|
||||
'agreement_bindings',
|
||||
value,
|
||||
)
|
||||
}
|
||||
initialSearch={agreementSearch}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
className="mt-4"
|
||||
disabled={issue.processing}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { AgreementOrderLimitSummary } from '@/components/agreement-order-bindings';
|
||||
import type { FrozenOrderAgreement } from '@/types/purchase';
|
||||
import { Printer } from 'lucide-react';
|
||||
import { EvidenceBrief } from '@/components/evidence-brief';
|
||||
import type { EvidenceBriefData } from '@/components/evidence-brief';
|
||||
@@ -59,6 +61,7 @@ type ComparisonRow = {
|
||||
weights: Record<string, number>;
|
||||
};
|
||||
type Report = {
|
||||
agreement_limits?: Record<string, FrozenOrderAgreement>;
|
||||
generated_at: string;
|
||||
generated_by: string;
|
||||
company: string;
|
||||
@@ -720,6 +723,9 @@ export default function ReviewReport({
|
||||
</p>
|
||||
</div>
|
||||
</Panel>
|
||||
<AgreementOrderLimitSummary
|
||||
bindings={report.agreement_limits}
|
||||
/>
|
||||
<Panel
|
||||
title="Recepção, facturas e registos de pagamento"
|
||||
id="report-fulfilment"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { AgreementOrderLimitSummary } from '@/components/agreement-order-bindings';
|
||||
import { Printer } from 'lucide-react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import { QuotationCommercialTerms } from '@/components/quotation-commercial-terms';
|
||||
@@ -242,6 +243,9 @@ export default function OrderShow({
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
<AgreementOrderLimitSummary
|
||||
bindings={snapshot.agreement_bindings}
|
||||
/>
|
||||
<Panel title="Fundamento e matriz congelada">
|
||||
{snapshot.comparison_policy && (
|
||||
<ComparisonPolicySummary
|
||||
|
||||
@@ -19,7 +19,7 @@ type Row = {
|
||||
needed_by: string | null;
|
||||
department: string | null;
|
||||
requester: string | null;
|
||||
total_minor: string;
|
||||
total_minor: string | null;
|
||||
quotations_count: number;
|
||||
order_number: string | null;
|
||||
};
|
||||
@@ -31,7 +31,8 @@ type Filters = {
|
||||
to?: string;
|
||||
department_id?: string | number;
|
||||
};
|
||||
const estimate = (minor: string) => {
|
||||
const estimate = (minor: string | null) => {
|
||||
if (minor === null) return 'Por completar';
|
||||
const digits = minor.padStart(3, '0');
|
||||
return `${digits.slice(0, -2)},${digits.slice(-2)} MZN`;
|
||||
};
|
||||
|
||||
@@ -89,6 +89,7 @@ export default function RequisitionForm({
|
||||
stockItems = [],
|
||||
defaultTaxRate = '16.00',
|
||||
catalogue,
|
||||
incompleteDraftsAvailable = false,
|
||||
}: {
|
||||
costCenters: CostCenter[];
|
||||
requisition: Requisition | null;
|
||||
@@ -97,37 +98,57 @@ export default function RequisitionForm({
|
||||
stockItems?: { id: number; code: string; name: string; unit: string }[];
|
||||
defaultTaxRate?: string;
|
||||
catalogue?: CatalogueOptions;
|
||||
incompleteDraftsAvailable?: boolean;
|
||||
}) {
|
||||
const ready = usePage().props.internalRequisitionReady === true;
|
||||
const prepared = requisition?.draft_input?.values;
|
||||
const preparedLines = prepared?.items?.map(
|
||||
(row) =>
|
||||
Object.fromEntries(
|
||||
Object.keys(emptyLine(defaultTaxRate)).map((key) => [
|
||||
key,
|
||||
key === 'key'
|
||||
? crypto.randomUUID()
|
||||
: String(row[key] ?? ''),
|
||||
]),
|
||||
) as Line,
|
||||
);
|
||||
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 ?? '',
|
||||
justification: requisition?.justification ?? '',
|
||||
items: requisition?.items.map((i) => ({
|
||||
source_line_id: i.id ? String(i.id) : '',
|
||||
catalogue_entry_id: i.catalogue_entry_id
|
||||
? String(i.catalogue_entry_id)
|
||||
: '',
|
||||
catalogue_version: i.catalogue_snapshot
|
||||
? String(i.catalogue_snapshot.version)
|
||||
: '',
|
||||
catalogue_code: i.catalogue_snapshot?.code ?? '',
|
||||
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),
|
||||
equipment_id: i.equipment_id ? String(i.equipment_id) : '',
|
||||
spare_part_id: i.spare_part_id ? String(i.spare_part_id) : '',
|
||||
production_area: i.production_area ?? '',
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
cost_center_id:
|
||||
prepared?.cost_center_id != null
|
||||
? String(prepared.cost_center_id)
|
||||
: requisition?.cost_center_id != null
|
||||
? String(requisition.cost_center_id)
|
||||
: '',
|
||||
priority: prepared?.priority ?? requisition?.priority ?? 'normal',
|
||||
needed_by: prepared?.needed_by ?? requisition?.needed_by ?? '',
|
||||
justification:
|
||||
prepared?.justification ?? requisition?.justification ?? '',
|
||||
items: preparedLines ??
|
||||
requisition?.items.map((i) => ({
|
||||
source_line_id: i.id ? String(i.id) : '',
|
||||
catalogue_entry_id: i.catalogue_entry_id
|
||||
? String(i.catalogue_entry_id)
|
||||
: '',
|
||||
catalogue_version: i.catalogue_snapshot
|
||||
? String(i.catalogue_snapshot.version)
|
||||
: '',
|
||||
catalogue_code: i.catalogue_snapshot?.code ?? '',
|
||||
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),
|
||||
equipment_id: i.equipment_id ? String(i.equipment_id) : '',
|
||||
spare_part_id: i.spare_part_id ? String(i.spare_part_id) : '',
|
||||
production_area: i.production_area ?? '',
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
});
|
||||
const formElement = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
@@ -171,6 +192,7 @@ export default function RequisitionForm({
|
||||
<form
|
||||
ref={formElement}
|
||||
data-context-save
|
||||
noValidate={incompleteDraftsAvailable}
|
||||
className="space-y-6"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -191,6 +213,15 @@ export default function RequisitionForm({
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{incompleteDraftsAvailable && (
|
||||
<p className="rounded-lg border p-4 text-sm">
|
||||
Pode guardar esta preparação mesmo com campos em
|
||||
falta. Os valores conhecidos são conferidos; os
|
||||
montantes incompletos ficam por completar. A
|
||||
submissão só fica disponível depois de completar o
|
||||
pedido.
|
||||
</p>
|
||||
)}
|
||||
{costCenters.length === 0 && (
|
||||
<div
|
||||
role="alert"
|
||||
@@ -198,7 +229,9 @@ export default function RequisitionForm({
|
||||
>
|
||||
O seu departamento ainda não tem centros de custo.
|
||||
Peça ao administrador para criar um antes de
|
||||
registar pedidos.
|
||||
{incompleteDraftsAvailable
|
||||
? 'submeter pedidos. Pode guardar a preparação enquanto aguarda.'
|
||||
: 'registar pedidos.'}
|
||||
</div>
|
||||
)}
|
||||
<Panel
|
||||
@@ -687,17 +720,22 @@ export default function RequisitionForm({
|
||||
Total estimado com IVA{' '}
|
||||
<strong className="ml-3 text-lg">
|
||||
{money(
|
||||
Number.isFinite(estimate)
|
||||
form.data.items.length > 0 &&
|
||||
form.data.items.every(
|
||||
(line) =>
|
||||
line.quantity !== '' &&
|
||||
line.unit_price !== '' &&
|
||||
line.tax_rate !== '',
|
||||
) &&
|
||||
Number.isFinite(estimate)
|
||||
? estimate
|
||||
: 0,
|
||||
: null,
|
||||
)}
|
||||
</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">
|
||||
@@ -714,7 +752,9 @@ export default function RequisitionForm({
|
||||
</Button>
|
||||
<Button
|
||||
disabled={
|
||||
form.processing || costCenters.length === 0
|
||||
form.processing ||
|
||||
(!incompleteDraftsAvailable &&
|
||||
costCenters.length === 0)
|
||||
}
|
||||
>
|
||||
<Save className="size-4" />
|
||||
|
||||
@@ -74,6 +74,10 @@ export default function Show({
|
||||
href: string | null;
|
||||
destination: string;
|
||||
equipment: { code: string; description: string } | null;
|
||||
production?: {
|
||||
reference: string | null;
|
||||
verification: 'user_supplied';
|
||||
};
|
||||
remaining_milli: number;
|
||||
}[];
|
||||
} | null;
|
||||
@@ -169,6 +173,8 @@ export default function Show({
|
||||
</>
|
||||
)}{' '}
|
||||
· Utilização: {o.destination}
|
||||
{o.production &&
|
||||
` · Insumos para produção${o.production.reference ? ` · Referência declarada: ${o.production.reference}` : ''}`}
|
||||
{o.equipment
|
||||
? ` · Equipamento ${o.equipment.code} · ${o.equipment.description}`
|
||||
: ''}{' '}
|
||||
@@ -209,87 +215,89 @@ export default function Show({
|
||||
<Panel title="Regra de comparação deste processo">
|
||||
<ComparisonPolicySummary policy={comparisonPolicy} />
|
||||
</Panel>
|
||||
{r.items.some((i) => i.purchase_type === 'equipment') && (
|
||||
<Panel title="Validação técnica do equipamento">
|
||||
<p className="mb-4 text-sm">
|
||||
Responsável da área, distinto do solicitante.
|
||||
Finanças é obrigatória para qualquer valor. A
|
||||
adjudicação e a emissão exigem regra de investimento
|
||||
vigente, com duas aprovações administrativas, e
|
||||
reserva em dotação de investimento. Sem estas
|
||||
condições permanecem bloqueadas. O orçamento ainda
|
||||
não é validado; documentos de desenvolvimento não
|
||||
autorizam compras reais.
|
||||
</p>
|
||||
{technical?.reviews.map((t) => (
|
||||
<p
|
||||
key={t.id}
|
||||
className="mb-3 rounded-lg border p-3 text-sm"
|
||||
>
|
||||
{t.decision === 'approved'
|
||||
? 'Validado'
|
||||
: 'Rejeitado'}{' '}
|
||||
por {t.snapshot.reviewer.name} ·{' '}
|
||||
{t.basis_hash === technical.basis_hash
|
||||
? 'Versão actual'
|
||||
: 'Versão anterior, decisão preservada'}{' '}
|
||||
· {t.reason}
|
||||
{!r.draft_input?.incomplete &&
|
||||
r.items.some((i) => i.purchase_type === 'equipment') && (
|
||||
<Panel title="Validação técnica do equipamento">
|
||||
<p className="mb-4 text-sm">
|
||||
Responsável da área, distinto do solicitante.
|
||||
Finanças é obrigatória para qualquer valor. A
|
||||
adjudicação e a emissão exigem regra de
|
||||
investimento vigente, com duas aprovações
|
||||
administrativas, e reserva em dotação de
|
||||
investimento. Sem estas condições permanecem
|
||||
bloqueadas. O orçamento ainda não é validado;
|
||||
documentos de desenvolvimento não autorizam
|
||||
compras reais.
|
||||
</p>
|
||||
))}
|
||||
{technical?.canReview && (
|
||||
<form
|
||||
className="grid gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
review.transform((d) => ({
|
||||
...d,
|
||||
basis_hash: technical.basis_hash,
|
||||
}));
|
||||
review.post(
|
||||
`/requisicoes/${r.id}/validacao-tecnica`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<select
|
||||
aria-label="Decisão técnica"
|
||||
className={controlClass}
|
||||
value={review.data.decision}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'decision',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
{technical?.reviews.map((t) => (
|
||||
<p
|
||||
key={t.id}
|
||||
className="mb-3 rounded-lg border p-3 text-sm"
|
||||
>
|
||||
<option value="approved">
|
||||
Validar tecnicamente
|
||||
</option>
|
||||
<option value="rejected">
|
||||
Rejeitar tecnicamente
|
||||
</option>
|
||||
</select>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Fundamento técnico
|
||||
<textarea
|
||||
required
|
||||
{t.decision === 'approved'
|
||||
? 'Validado'
|
||||
: 'Rejeitado'}{' '}
|
||||
por {t.snapshot.reviewer.name} ·{' '}
|
||||
{t.basis_hash === technical.basis_hash
|
||||
? 'Versão actual'
|
||||
: 'Versão anterior, decisão preservada'}{' '}
|
||||
· {t.reason}
|
||||
</p>
|
||||
))}
|
||||
{technical?.canReview && (
|
||||
<form
|
||||
className="grid gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
review.transform((d) => ({
|
||||
...d,
|
||||
basis_hash: technical.basis_hash,
|
||||
}));
|
||||
review.post(
|
||||
`/requisicoes/${r.id}/validacao-tecnica`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<select
|
||||
aria-label="Decisão técnica"
|
||||
className={controlClass}
|
||||
value={review.data.reason}
|
||||
value={review.data.decision}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'reason',
|
||||
'decision',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FormErrors errors={review.errors} />
|
||||
<Button disabled={review.processing}>
|
||||
Registar decisão técnica
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
>
|
||||
<option value="approved">
|
||||
Validar tecnicamente
|
||||
</option>
|
||||
<option value="rejected">
|
||||
Rejeitar tecnicamente
|
||||
</option>
|
||||
</select>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Fundamento técnico
|
||||
<textarea
|
||||
required
|
||||
className={controlClass}
|
||||
value={review.data.reason}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'reason',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FormErrors errors={review.errors} />
|
||||
<Button disabled={review.processing}>
|
||||
Registar decisão técnica
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
{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
|
||||
@@ -302,32 +310,49 @@ export default function Show({
|
||||
.
|
||||
</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`,
|
||||
)
|
||||
}
|
||||
{canEdit &&
|
||||
(r.draft_input?.incomplete ? (
|
||||
<div role="status" className="rounded-xl border p-5">
|
||||
<p>
|
||||
Rascunho incompleto guardado. Os montantes estão
|
||||
por completar; não há submissão nem reserva
|
||||
orçamental. As linhas anteriormente completas
|
||||
não representam esta preparação.
|
||||
</p>
|
||||
<Link
|
||||
className="mt-3 inline-block underline"
|
||||
href={`/requisicoes/${r.id}/editar`}
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
Continuar a preparação
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<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">
|
||||
@@ -337,8 +362,9 @@ export default function Show({
|
||||
Centro de custo
|
||||
</dt>
|
||||
<dd className="mt-1 font-medium">
|
||||
{r.cost_center?.code} ·{' '}
|
||||
{r.cost_center?.name}
|
||||
{r.cost_center
|
||||
? `${r.cost_center.code} · ${r.cost_center.name}`
|
||||
: 'Por completar'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
@@ -367,85 +393,106 @@ export default function Show({
|
||||
</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>
|
||||
{i.equipment_id && (
|
||||
<p className="mt-1 text-xs">
|
||||
Equipamento #
|
||||
{i.equipment_id} ·
|
||||
Peça #
|
||||
{i.spare_part_id}
|
||||
{i.downtime_started_at &&
|
||||
` · Paragem: ${i.downtime_started_at} UTC`}
|
||||
</p>
|
||||
)}
|
||||
{i.production_area && (
|
||||
<p className="mt-1 text-xs">
|
||||
Área de destino:{' '}
|
||||
{i.production_area}
|
||||
</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>
|
||||
{r.draft_input?.incomplete ? (
|
||||
<Panel title="Linhas em preparação">
|
||||
<p>
|
||||
Os valores ainda não estão completos. Abra
|
||||
«Continuar a preparação» para recuperar as
|
||||
linhas guardadas. Não são apresentados
|
||||
totais estimados nem linhas antigas como
|
||||
valores desta preparação.
|
||||
</p>
|
||||
</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>
|
||||
))}
|
||||
</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>
|
||||
</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>
|
||||
{i.equipment_id && (
|
||||
<p className="mt-1 text-xs">
|
||||
Equipamento #
|
||||
{i.equipment_id}{' '}
|
||||
· Peça #
|
||||
{
|
||||
i.spare_part_id
|
||||
}
|
||||
{i.downtime_started_at &&
|
||||
` · Paragem: ${i.downtime_started_at} UTC`}
|
||||
</p>
|
||||
)}
|
||||
{i.production_area && (
|
||||
<p className="mt-1 text-xs">
|
||||
Área de destino:{' '}
|
||||
{
|
||||
i.production_area
|
||||
}
|
||||
</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>
|
||||
<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>
|
||||
<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"
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Group = {
|
||||
key: string;
|
||||
title: string;
|
||||
records: {
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
data: { id: number; title: string; detail: string; href: string }[];
|
||||
};
|
||||
};
|
||||
const statuses: Record<string, string> = {
|
||||
draft: 'Rascunho',
|
||||
pending: 'Pendente',
|
||||
approved: 'Aprovada',
|
||||
rejected: 'Rejeitada',
|
||||
cancelled: 'Cancelada',
|
||||
issued: 'Emitida',
|
||||
active: 'Activo',
|
||||
inactive: 'Inactivo',
|
||||
};
|
||||
export default function ProcurementSearch({
|
||||
term,
|
||||
groups,
|
||||
}: {
|
||||
term: string;
|
||||
groups: Group[];
|
||||
}) {
|
||||
const form = useForm({ q: term });
|
||||
return (
|
||||
<>
|
||||
<Head title="Pesquisar processos" />
|
||||
<div className="mx-auto grid w-full max-w-7xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras"
|
||||
title="Pesquisar processos"
|
||||
description="Procure processos e cadastros de Compras a partir de um único local, dentro do seu acesso actual."
|
||||
/>
|
||||
<Panel
|
||||
title="Pesquisa transversal de Compras"
|
||||
description="Pesquise requisições, ordens, fornecedores, recepções, equipamentos, artigos e armazéns por referência, necessidade, nome, código ou NUIT. Esta entrega ainda não pesquisa Pessoas, facturas, conteúdo de anexos ou arquivos externos."
|
||||
>
|
||||
<form
|
||||
className="flex flex-wrap items-end gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.get('/compras/pesquisa', {
|
||||
preserveState: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label
|
||||
className="grid min-w-0 flex-1 gap-2"
|
||||
htmlFor="procurement-search"
|
||||
>
|
||||
Texto a procurar
|
||||
<input
|
||||
className={controlClass}
|
||||
id="procurement-search"
|
||||
type="search"
|
||||
minLength={2}
|
||||
maxLength={100}
|
||||
value={form.data.q}
|
||||
onChange={(e) =>
|
||||
form.setData('q', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>Pesquisar</Button>
|
||||
</form>
|
||||
<FormErrors errors={form.errors} />
|
||||
</Panel>
|
||||
{term.trim().length < 2 && (
|
||||
<p role="status">
|
||||
Introduza pelo menos dois caracteres para pesquisar.
|
||||
</p>
|
||||
)}
|
||||
{groups.map((group) => (
|
||||
<Panel
|
||||
key={group.key}
|
||||
title={`${group.title} (${group.records.total})`}
|
||||
>
|
||||
{group.records.data.length === 0 ? (
|
||||
<p>Nenhum resultado no seu âmbito de acesso.</p>
|
||||
) : (
|
||||
<ul className="divide-y">
|
||||
{group.records.data.map((record) => (
|
||||
<li
|
||||
key={record.id}
|
||||
className="flex min-w-0 flex-wrap justify-between gap-3 py-3"
|
||||
>
|
||||
<Link
|
||||
className="min-w-0 font-medium break-words underline"
|
||||
href={record.href}
|
||||
>
|
||||
{record.title}
|
||||
</Link>
|
||||
<span>
|
||||
{statuses[record.detail] ??
|
||||
record.detail}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<nav
|
||||
aria-label={`Páginas de ${group.title}`}
|
||||
className="mt-4 flex flex-wrap items-center gap-4"
|
||||
>
|
||||
<span>
|
||||
Página {group.records.current_page} de{' '}
|
||||
{group.records.last_page}
|
||||
</span>
|
||||
{group.records.prev_page_url && (
|
||||
<Link href={group.records.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{group.records.next_page_url && (
|
||||
<Link href={group.records.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ type Line = {
|
||||
quantity: string;
|
||||
use: string;
|
||||
equipment_id: string;
|
||||
production_reference: string;
|
||||
};
|
||||
type Snapshot = {
|
||||
requester: { name: string };
|
||||
@@ -31,6 +32,10 @@ type Snapshot = {
|
||||
use: string;
|
||||
destination: string;
|
||||
equipment: { code: string; description: string } | null;
|
||||
production?: {
|
||||
reference: string | null;
|
||||
verification: 'user_supplied';
|
||||
};
|
||||
}[];
|
||||
};
|
||||
type Props = {
|
||||
@@ -68,6 +73,7 @@ const blank = (): Line => ({
|
||||
quantity: '',
|
||||
use: 'internal',
|
||||
equipment_id: '',
|
||||
production_reference: '',
|
||||
});
|
||||
export default function Requests(props: Props) {
|
||||
const filters = useForm({
|
||||
@@ -429,6 +435,8 @@ export default function Requests(props: Props) {
|
||||
line(index, {
|
||||
use: e.target.value,
|
||||
equipment_id: '',
|
||||
production_reference:
|
||||
'',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -439,8 +447,38 @@ export default function Requests(props: Props) {
|
||||
<option value="equipment">
|
||||
Em equipamento
|
||||
</option>
|
||||
<option value="production">
|
||||
Insumos para produção
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{row.use === 'production' && (
|
||||
<label>
|
||||
Referência de produção (se
|
||||
disponível)
|
||||
<input
|
||||
className={controlClass}
|
||||
maxLength={120}
|
||||
value={
|
||||
row.production_reference
|
||||
}
|
||||
onChange={(e) =>
|
||||
line(index, {
|
||||
production_reference:
|
||||
e.target
|
||||
.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Ordem, lote ou
|
||||
actividade indicada por
|
||||
si. Não é conferida num
|
||||
sistema de produção
|
||||
externo.
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
{row.use === 'equipment' && (
|
||||
<label>
|
||||
Equipamento de destino
|
||||
@@ -617,6 +655,16 @@ export default function Requests(props: Props) {
|
||||
{item.equipment
|
||||
? `Equipamento ${item.equipment.code} · ${item.equipment.description}`
|
||||
: item.destination}
|
||||
{item.use === 'production' && (
|
||||
<span>
|
||||
{' '}
|
||||
· Insumos para produção
|
||||
{item.production
|
||||
?.reference
|
||||
? ` · Referência declarada: ${item.production.reference}`
|
||||
: ''}
|
||||
</span>
|
||||
)}
|
||||
{record.progress && (
|
||||
<span>
|
||||
{' '}
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { InventoryPagination } from '@/components/inventory';
|
||||
import { date, money } from '@/types/procurement';
|
||||
|
||||
type Filters = { search: string; validity: string; expires_by: string };
|
||||
export type AgreementFollowupRow = {
|
||||
currency?: string | null;
|
||||
max_order_value_minor?: number | null;
|
||||
periodicity_days?: number | null;
|
||||
approved_articles?: number;
|
||||
articles_href?: string;
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
reference: string | null;
|
||||
supplier: string | null;
|
||||
item_code: string | null;
|
||||
item: string | null;
|
||||
warehouse: string | null;
|
||||
valid_from: string | null;
|
||||
valid_until: string | null;
|
||||
validity: string;
|
||||
approved_policies: number;
|
||||
href: string;
|
||||
policies_href: string;
|
||||
};
|
||||
type Props = {
|
||||
kind?: 'agreement' | 'contract';
|
||||
asOf: string;
|
||||
filters: Filters;
|
||||
errors?: Record<string, string>;
|
||||
records: {
|
||||
data: AgreementFollowupRow[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
all: 'Todas as situações',
|
||||
current: 'Vigentes',
|
||||
expired: 'Expirados',
|
||||
future: 'Por iniciar',
|
||||
unknown: 'Datas indeterminadas',
|
||||
};
|
||||
export default function AgreementFollowup({
|
||||
kind = 'agreement',
|
||||
asOf,
|
||||
filters,
|
||||
records,
|
||||
errors = {},
|
||||
}: Props) {
|
||||
const [draft, setDraft] = useState(filters);
|
||||
const csv = new URLSearchParams({
|
||||
...filters,
|
||||
...(kind === 'contract' ? { kind } : {}),
|
||||
}).toString();
|
||||
const contracts = kind === 'contract';
|
||||
const title = contracts
|
||||
? 'Vigência dos contratos globais'
|
||||
: 'Vigência dos acordos';
|
||||
return (
|
||||
<>
|
||||
<Head title={title} />
|
||||
<div className="mx-auto max-w-7xl space-y-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras · Fornecimento"
|
||||
title={title}
|
||||
description={`Últimas versões aprovadas, consultadas em ${date(asOf)}.`}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
A vigência não comprova, por si só, elegibilidade do
|
||||
fornecedor ou autorização de compra. Consultar não renova
|
||||
acordos nem altera políticas de reposição.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-4 text-sm">
|
||||
<Link
|
||||
href={`/compras/fornecimento?view=${contracts ? 'contracts' : 'agreements'}`}
|
||||
className="underline"
|
||||
>
|
||||
{contracts
|
||||
? 'Voltar aos contratos'
|
||||
: 'Voltar aos acordos'}
|
||||
</Link>
|
||||
<a
|
||||
href={`/compras/acordos/vigencia.csv?${csv}`}
|
||||
className="underline"
|
||||
>
|
||||
Descarregar todos os resultados em CSV
|
||||
</a>
|
||||
</div>
|
||||
<Panel
|
||||
title={
|
||||
contracts ? 'Encontrar contratos' : 'Encontrar acordos'
|
||||
}
|
||||
>
|
||||
<form
|
||||
className="grid gap-4 md:grid-cols-3"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
router.get('/compras/acordos/vigencia', {
|
||||
...draft,
|
||||
...(contracts ? { kind } : {}),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Referência, fornecedor, artigo ou armazém
|
||||
<Input
|
||||
maxLength={100}
|
||||
value={draft.search}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
search: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Situação de vigência
|
||||
<select
|
||||
className={controlClass}
|
||||
value={draft.validity}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
validity: event.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
{Object.entries(states).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Vigência termina até
|
||||
<Input
|
||||
type="date"
|
||||
value={draft.expires_by}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
expires_by: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex items-center gap-4">
|
||||
<Button type="submit">Aplicar filtros</Button>
|
||||
<Link
|
||||
href={
|
||||
contracts
|
||||
? '/compras/acordos/vigencia?kind=contract'
|
||||
: '/compras/acordos/vigencia'
|
||||
}
|
||||
className="text-sm underline"
|
||||
>
|
||||
Limpar filtros
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
<div className="mt-4">
|
||||
<FormErrors errors={errors} />
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted-foreground">
|
||||
Escolha a data-limite conforme a conferência pretendida.
|
||||
O filtro por data não inclui acordos sem data de fim
|
||||
conhecida. O CSV usa os filtros já aplicados.
|
||||
</p>
|
||||
</Panel>
|
||||
<Panel
|
||||
title={`${records.total} ${contracts ? 'contrato(s)' : 'acordo(s)'} encontrado(s)`}
|
||||
>
|
||||
<div className="divide-y">
|
||||
{records.data.map((record) => (
|
||||
<article
|
||||
key={record.record_key}
|
||||
className="space-y-2 py-4 text-sm"
|
||||
>
|
||||
<div className="flex flex-wrap justify-between gap-2">
|
||||
<h2 className="font-semibold">
|
||||
{record.reference ??
|
||||
'Referência não disponível'}{' '}
|
||||
· versão {record.version}
|
||||
</h2>
|
||||
<span>
|
||||
{states[record.validity] ??
|
||||
'Datas indeterminadas'}
|
||||
</span>
|
||||
</div>
|
||||
<p>
|
||||
{record.supplier ??
|
||||
'Fornecedor não disponível'}{' '}
|
||||
{!contracts && (
|
||||
<>
|
||||
{' '}
|
||||
·{' '}
|
||||
{record.item_code ??
|
||||
'Código não disponível'}{' '}
|
||||
·{' '}
|
||||
{record.item ??
|
||||
'Artigo não disponível'}{' '}
|
||||
·{' '}
|
||||
{record.warehouse ??
|
||||
'Armazém não disponível'}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
{contracts ? (
|
||||
<p>
|
||||
Limite global por ordem:{' '}
|
||||
{record.max_order_value_minor ===
|
||||
null ||
|
||||
record.max_order_value_minor ===
|
||||
undefined
|
||||
? 'Não definido'
|
||||
: record.currency
|
||||
? money(
|
||||
record.max_order_value_minor,
|
||||
record.currency,
|
||||
)
|
||||
: `${record.max_order_value_minor} centavos (moeda indisponível)`}
|
||||
. Cada ordem pode usar o limite
|
||||
completo. Periodicidade prevista:{' '}
|
||||
{record.periodicity_days === null ||
|
||||
record.periodicity_days === undefined
|
||||
? 'Não definida'
|
||||
: `${record.periodicity_days} dias`}
|
||||
. Não gera ordens automáticas.
|
||||
</p>
|
||||
) : null}
|
||||
<p>
|
||||
Início:{' '}
|
||||
{record.valid_from
|
||||
? date(record.valid_from)
|
||||
: 'Não disponível'}{' '}
|
||||
· Fim:{' '}
|
||||
{record.valid_until
|
||||
? date(record.valid_until)
|
||||
: 'Não disponível'}
|
||||
</p>
|
||||
{contracts ? (
|
||||
<p>
|
||||
{record.approved_articles ?? 0}{' '}
|
||||
artigo(s) aprovado(s) ligado(s). A
|
||||
contagem não substitui a conferência da
|
||||
versão, moeda e vigência na emissão.
|
||||
</p>
|
||||
) : (
|
||||
<p>
|
||||
{record.approved_policies} política(s)
|
||||
aprovada(s) ligada(s). Confira a versão
|
||||
adoptada e a vigência antes de
|
||||
interpretar o prazo de reposição.
|
||||
</p>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Link
|
||||
className="underline"
|
||||
href={record.href}
|
||||
>
|
||||
{contracts
|
||||
? 'Conferir contrato'
|
||||
: 'Conferir acordo'}
|
||||
</Link>
|
||||
<Link
|
||||
className="underline"
|
||||
href={
|
||||
contracts
|
||||
? (record.articles_href ??
|
||||
record.href)
|
||||
: record.policies_href
|
||||
}
|
||||
>
|
||||
{contracts
|
||||
? 'Consultar artigos ligados'
|
||||
: 'Consultar políticas ligadas'}
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
{records.data.length === 0 && (
|
||||
<p className="py-5 text-sm text-muted-foreground">
|
||||
{contracts
|
||||
? 'Não existem contratos aprovados que correspondam aos filtros.'
|
||||
: 'Não existem acordos aprovados que correspondam aos filtros.'}
|
||||
</p>
|
||||
)}
|
||||
<InventoryPagination page={records} />
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import CorrectionSourceSearch from '@/components/correction-source-search';
|
||||
import SupplyPagination, {
|
||||
type SupplyPageInfo,
|
||||
@@ -14,6 +15,7 @@ import SupplyPagination, {
|
||||
|
||||
type Data = Record<string, string | number | boolean | null>;
|
||||
type SupplyRecord = {
|
||||
kind?: string;
|
||||
canApprove?: boolean;
|
||||
canReturn?: boolean;
|
||||
canSuspend?: boolean;
|
||||
@@ -25,6 +27,12 @@ type SupplyRecord = {
|
||||
reason: string;
|
||||
created_at: string;
|
||||
snapshot: {
|
||||
contract?: {
|
||||
id: number;
|
||||
record_key: string;
|
||||
reference: string;
|
||||
version: number;
|
||||
};
|
||||
item?: { code: string; name: string; unit: string };
|
||||
warehouse?: { name: string };
|
||||
supplier?: { name: string };
|
||||
@@ -67,6 +75,11 @@ type Projection = {
|
||||
series?: { date: string; balance_milli: number }[];
|
||||
};
|
||||
type Props = {
|
||||
orderLimitsReady?: boolean;
|
||||
linkedAgreementKey?: string | null;
|
||||
linkedContractKey?: string | null;
|
||||
contractSearch?: string;
|
||||
contracts?: SupplyRecord[];
|
||||
agreementSearch?: string;
|
||||
agreementFormKey?: string | null;
|
||||
orderSearch?: string;
|
||||
@@ -117,6 +130,7 @@ const states: Record<string, string> = {
|
||||
released: 'Libertação comprovada',
|
||||
};
|
||||
const titles: Record<string, string> = {
|
||||
contracts: 'Contratos com vários artigos',
|
||||
agreements: 'Fornecimento habitual',
|
||||
calendar: 'Reposição e calendário',
|
||||
imports: 'Importações',
|
||||
@@ -126,6 +140,8 @@ const quantity = (value: number | undefined) =>
|
||||
? '—'
|
||||
: (value / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
|
||||
const labels: Record<string, string> = {
|
||||
periodicity_days: 'Periodicidade prevista em dias',
|
||||
contract_version: 'Versão do contrato global',
|
||||
forecast_method: 'Método de procura',
|
||||
history_min_days: 'Mínimo de dias históricos',
|
||||
history_max_age_days: 'Idade máxima do período',
|
||||
@@ -148,6 +164,9 @@ const labels: Record<string, string> = {
|
||||
valid_until: 'Vigente até',
|
||||
currency: 'Moeda',
|
||||
price_minor: 'Preço por unidade',
|
||||
max_order_value_minor: 'Valor máximo por ordem com impostos',
|
||||
max_order_quantity_milli: 'Quantidade máxima por ordem',
|
||||
order_limit_basis: 'Aplicação dos limites',
|
||||
reference: 'Referência documental',
|
||||
jurisdiction: 'Jurisdição',
|
||||
origin_country: 'País de origem',
|
||||
@@ -163,10 +182,38 @@ const values: Record<string, string> = {
|
||||
internal: 'Uso interno e reposição',
|
||||
local: 'Compra local',
|
||||
import: 'Importação directa',
|
||||
per_order: 'Por ordem, sem acumulação entre ordens',
|
||||
};
|
||||
function PreservedData({ record }: { record: SupplyRecord }) {
|
||||
return (
|
||||
<dl className="mt-3 grid gap-2 text-sm md:grid-cols-2">
|
||||
{record.kind === 'contract' && (
|
||||
<div>
|
||||
<dt className="font-medium">Artigos do contrato</dt>
|
||||
<dd>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/fornecimento?view=agreements&linked_contract_key=${record.record_key}`}
|
||||
>
|
||||
Consultar artigos e limites associados
|
||||
</Link>
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{record.snapshot.contract && (
|
||||
<div>
|
||||
<dt className="font-medium">Contrato global associado</dt>
|
||||
<dd>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/fornecimento?view=contracts&record_id=${record.snapshot.contract.id}`}
|
||||
>
|
||||
{record.snapshot.contract.reference} · versão{' '}
|
||||
{record.snapshot.contract.version}
|
||||
</Link>
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{Object.entries(record.data)
|
||||
.filter(([key]) => key in labels)
|
||||
.map(([key, value]) => (
|
||||
@@ -174,10 +221,13 @@ function PreservedData({ record }: { record: SupplyRecord }) {
|
||||
<dt className="font-medium">{labels[key]}</dt>
|
||||
<dd>
|
||||
{value === null || value === ''
|
||||
? 'Por recolher'
|
||||
? key.startsWith('max_order_')
|
||||
? 'Não definido'
|
||||
: 'Por recolher'
|
||||
: key.endsWith('_milli')
|
||||
? quantity(Number(value))
|
||||
: key === 'price_minor'
|
||||
: key === 'price_minor' ||
|
||||
key === 'max_order_value_minor'
|
||||
? (Number(value) / 100).toFixed(2)
|
||||
: typeof value === 'boolean'
|
||||
? value
|
||||
@@ -224,30 +274,44 @@ function Preparation({
|
||||
pack: '1',
|
||||
basis: '',
|
||||
}
|
||||
: props.kind === 'agreement'
|
||||
: props.kind === 'contract'
|
||||
? {
|
||||
stock_item_id: '',
|
||||
warehouse_id: '',
|
||||
supplier_id: '',
|
||||
habitual: true,
|
||||
origin: 'local',
|
||||
reference: '',
|
||||
currency: 'MZN',
|
||||
valid_from: '',
|
||||
valid_until: '',
|
||||
currency: 'MZN',
|
||||
price: '',
|
||||
lead_days: '',
|
||||
reference: '',
|
||||
periodicity_days: '',
|
||||
order_limit_amount: '',
|
||||
}
|
||||
: {
|
||||
purchase_order_id: '',
|
||||
purpose: 'internal',
|
||||
jurisdiction: '',
|
||||
origin_country: '',
|
||||
dispatch_country: '',
|
||||
incoterm: '',
|
||||
regime: '',
|
||||
expected_usable_on: '',
|
||||
};
|
||||
: props.kind === 'agreement'
|
||||
? {
|
||||
stock_item_id: '',
|
||||
warehouse_id: '',
|
||||
supplier_id: '',
|
||||
habitual: true,
|
||||
origin: 'local',
|
||||
valid_from: '',
|
||||
valid_until: '',
|
||||
currency: 'MZN',
|
||||
price: '',
|
||||
lead_days: '',
|
||||
reference: '',
|
||||
contract_key: '',
|
||||
...(props.orderLimitsReady
|
||||
? { order_limit_amount: '', order_limit_quantity: '' }
|
||||
: {}),
|
||||
}
|
||||
: {
|
||||
purchase_order_id: '',
|
||||
purpose: 'internal',
|
||||
jurisdiction: '',
|
||||
origin_country: '',
|
||||
dispatch_country: '',
|
||||
incoterm: '',
|
||||
regime: '',
|
||||
expected_usable_on: '',
|
||||
};
|
||||
if (record) {
|
||||
Object.assign(defaults, record.data);
|
||||
for (const key of [
|
||||
@@ -270,6 +334,19 @@ function Preparation({
|
||||
record.data.price_minor === null
|
||||
? ''
|
||||
: Number(record.data.price_minor) / 100;
|
||||
if (props.orderLimitsReady) {
|
||||
for (const [field, key, scale] of [
|
||||
['order_limit_amount', 'max_order_value_minor', 2],
|
||||
['order_limit_quantity', 'max_order_quantity_milli', 3],
|
||||
] as const) {
|
||||
const value = record.data[key];
|
||||
const digits = String(value ?? 0).padStart(scale + 1, '0');
|
||||
defaults[field] =
|
||||
value === null || value === undefined
|
||||
? ''
|
||||
: `${digits.slice(0, -scale)}.${digits.slice(-scale)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
const form = useForm({
|
||||
operation_key: crypto.randomUUID(),
|
||||
@@ -297,6 +374,7 @@ function Preparation({
|
||||
'/compras/fornecimento',
|
||||
{
|
||||
view: 'calendar',
|
||||
linked_agreement_key: props.linkedAgreementKey || undefined,
|
||||
records_page: props.recordPagination?.current_page,
|
||||
...(props.focusRecordId
|
||||
? { record_id: props.focusRecordId }
|
||||
@@ -323,6 +401,7 @@ function Preparation({
|
||||
'/compras/fornecimento',
|
||||
{
|
||||
view: 'calendar',
|
||||
linked_agreement_key: props.linkedAgreementKey || undefined,
|
||||
records_page: props.recordPagination?.current_page,
|
||||
...(props.focusRecordId
|
||||
? { record_id: props.focusRecordId }
|
||||
@@ -521,30 +600,165 @@ function Preparation({
|
||||
</details>
|
||||
)}
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{props.kind === 'import' ? (
|
||||
select('purchase_order_id', 'Ordem de compra', props.orders)
|
||||
) : (
|
||||
<>
|
||||
{select(
|
||||
'stock_item_id',
|
||||
'Artigo e unidade',
|
||||
props.items,
|
||||
)}
|
||||
{select('warehouse_id', 'Armazém', props.warehouses)}
|
||||
</>
|
||||
)}
|
||||
{props.kind === 'import'
|
||||
? select(
|
||||
'purchase_order_id',
|
||||
'Ordem de compra',
|
||||
props.orders,
|
||||
)
|
||||
: props.kind !== 'contract' && (
|
||||
<>
|
||||
{select(
|
||||
'stock_item_id',
|
||||
'Artigo e unidade',
|
||||
props.items,
|
||||
)}
|
||||
{select(
|
||||
'warehouse_id',
|
||||
'Armazém',
|
||||
props.warehouses,
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{props.kind !== 'agreement' &&
|
||||
props.kind !== 'contract' &&
|
||||
choice('purpose', 'Finalidade', [
|
||||
['internal', 'Uso interno e reposição'],
|
||||
['resale', 'Revenda'],
|
||||
])}
|
||||
{props.kind !== 'import' &&
|
||||
props.kind !== 'contract' &&
|
||||
choice('origin', 'Origem do fornecimento', [
|
||||
['local', 'Compra local'],
|
||||
['import', 'Importação directa'],
|
||||
])}
|
||||
{props.kind === 'contract' && (
|
||||
<>
|
||||
<p className="text-sm md:col-span-2">
|
||||
Cada ordem pode usar o limite global completo. Os
|
||||
limites de quantidade são definidos nos artigos
|
||||
associados. A periodicidade é informativa e não gera
|
||||
encomendas automáticas.
|
||||
</p>
|
||||
{select(
|
||||
'supplier_id',
|
||||
'Fornecedor validado',
|
||||
props.suppliers,
|
||||
)}
|
||||
{field('reference', 'Referência do contrato')}
|
||||
{field('valid_from', 'Vigente desde', 'date')}
|
||||
{field('valid_until', 'Vigente até', 'date')}
|
||||
{field('currency', 'Moeda')}
|
||||
{field(
|
||||
'order_limit_amount',
|
||||
'Limite global por ordem, com impostos (vazio: não definido)',
|
||||
'number',
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'periodicity_days',
|
||||
'Periodicidade prevista em dias (opcional)',
|
||||
'number',
|
||||
true,
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{props.kind === 'agreement' && (
|
||||
<>
|
||||
{props.orderLimitsReady && (
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="block text-sm">
|
||||
Contrato aprovado (opcional)
|
||||
<select
|
||||
className={controlClass}
|
||||
value={String(
|
||||
form.data.data.contract_key ?? '',
|
||||
)}
|
||||
onChange={(e) =>
|
||||
form.setData('data', {
|
||||
...form.data.data,
|
||||
contract_key: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Sem contrato global associado
|
||||
</option>
|
||||
{form.data.data.contract_key &&
|
||||
!(props.contracts ?? []).some(
|
||||
(c) =>
|
||||
c.record_key ===
|
||||
form.data.data.contract_key,
|
||||
) && (
|
||||
<option
|
||||
value={String(
|
||||
form.data.data
|
||||
.contract_key,
|
||||
)}
|
||||
disabled
|
||||
>
|
||||
Contrato indisponível —
|
||||
volte a conferir
|
||||
</option>
|
||||
)}
|
||||
{(props.contracts ?? []).map((c) => (
|
||||
<option
|
||||
key={c.record_key}
|
||||
value={c.record_key}
|
||||
>
|
||||
{String(c.data.reference)} ·
|
||||
versão {c.version} ·{' '}
|
||||
{String(c.data.currency)} ·{' '}
|
||||
{String(
|
||||
c.snapshot.supplier?.name ??
|
||||
'',
|
||||
)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
aria-label="Pesquisar contratos"
|
||||
placeholder="Referência ou fornecedor"
|
||||
defaultValue={props.contractSearch ?? ''}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
router.get(
|
||||
'/compras/fornecimento',
|
||||
{
|
||||
view: 'agreements',
|
||||
linked_contract_key:
|
||||
props.linkedContractKey ||
|
||||
undefined,
|
||||
contract_search:
|
||||
e.currentTarget.value,
|
||||
selected_contract_key:
|
||||
form.data.data
|
||||
.contract_key ||
|
||||
undefined,
|
||||
},
|
||||
{
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
only: [
|
||||
'contracts',
|
||||
'contractSearch',
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs">
|
||||
Pesquise com Enter. A escolha não altera os
|
||||
campos: confirme fornecedor, moeda e
|
||||
vigência do artigo, contida na do contrato.
|
||||
O limite global soma todos os artigos
|
||||
ligados nesta ordem.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{select(
|
||||
'supplier_id',
|
||||
'Fornecedor validado',
|
||||
@@ -554,6 +768,28 @@ function Preparation({
|
||||
{field('valid_from', 'Vigente desde', 'date')}
|
||||
{field('valid_until', 'Vigente até', 'date')}
|
||||
{field('currency', 'Moeda')}
|
||||
{props.orderLimitsReady && (
|
||||
<div className="space-y-3 rounded border p-3">
|
||||
<p className="text-sm">
|
||||
Limites por ordem: cada ordem pode usar o
|
||||
limite completo. Não há saldo acumulado
|
||||
entre ordens. Deixe vazio quando não houver
|
||||
limite.
|
||||
</p>
|
||||
{field(
|
||||
'order_limit_amount',
|
||||
'Valor máximo por ordem, com impostos, na moeda do acordo',
|
||||
'number',
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'order_limit_quantity',
|
||||
'Quantidade máxima por ordem, na unidade do artigo',
|
||||
'number',
|
||||
true,
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{field(
|
||||
'price',
|
||||
'Preço por unidade do artigo',
|
||||
@@ -1126,6 +1362,58 @@ export default function SupplyIndex(props: Props) {
|
||||
title={titles[props.view]}
|
||||
description="Seleccione os cadastros existentes e registe apenas os dados novos desta etapa. A finalidade e a origem são independentes."
|
||||
/>
|
||||
{(props.kind === 'agreement' ||
|
||||
props.kind === 'policy' ||
|
||||
props.kind === 'contract') && (
|
||||
<Link
|
||||
href={
|
||||
props.kind === 'contract'
|
||||
? '/compras/acordos/vigencia?kind=contract'
|
||||
: '/compras/acordos/vigencia'
|
||||
}
|
||||
className="inline-block text-sm underline"
|
||||
>
|
||||
{props.kind === 'contract'
|
||||
? 'Acompanhar vigência dos contratos globais'
|
||||
: 'Acompanhar vigência dos acordos'}
|
||||
</Link>
|
||||
)}
|
||||
{props.orderLimitsReady && (
|
||||
<Link
|
||||
href={
|
||||
props.kind === 'contract'
|
||||
? '/compras/fornecimento?view=agreements'
|
||||
: '/compras/fornecimento?view=contracts'
|
||||
}
|
||||
className="inline-block text-sm underline"
|
||||
>
|
||||
{props.kind === 'contract'
|
||||
? 'Preparar artigos e limites individuais'
|
||||
: 'Contratos com vários artigos e limite global'}
|
||||
</Link>
|
||||
)}
|
||||
{props.linkedContractKey && (
|
||||
<p className="rounded border p-3 text-sm">
|
||||
Artigos ligados ao contrato seleccionado.{' '}
|
||||
<Link
|
||||
className="underline"
|
||||
href="/compras/fornecimento?view=agreements"
|
||||
>
|
||||
Ver todos os acordos
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
{props.linkedAgreementKey && (
|
||||
<p className="rounded border p-3 text-sm">
|
||||
Políticas ligadas ao acordo seleccionado.{' '}
|
||||
<Link
|
||||
className="underline"
|
||||
href="/compras/fornecimento?view=calendar"
|
||||
>
|
||||
Ver todas as políticas
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
{!props.ready && (
|
||||
<p role="status">
|
||||
A instalação deste incremento ainda está pendente.
|
||||
|
||||
Reference in New Issue
Block a user