143 lines
6.2 KiB
TypeScript
143 lines
6.2 KiB
TypeScript
import { Link } from '@inertiajs/react';
|
|
import { Panel } from '@/components/procurement';
|
|
import { money, roleLabels } from '@/types/procurement';
|
|
|
|
export type OrderPartFrame = {
|
|
requisition: { id: number; number: string };
|
|
department: { name: string };
|
|
cost_center: { code: string; name: string };
|
|
quotation: { reference: string; currency: string; payment_terms: string };
|
|
award: {
|
|
delivery_date: string;
|
|
delivery_location: string;
|
|
justification?: string;
|
|
};
|
|
native_preparation: {
|
|
approved_reference?: { subtotal_minor: number; total_minor: number };
|
|
items: {
|
|
quotation_item_id: number;
|
|
description: string;
|
|
quantity_milli: number;
|
|
approved_quantity_milli?: number;
|
|
total_minor: number;
|
|
}[];
|
|
};
|
|
approval_rules?: { approval_includes_tax: boolean };
|
|
final_approvals?: {
|
|
id: number;
|
|
role: string;
|
|
approver_id: number | null;
|
|
decision: string;
|
|
}[];
|
|
};
|
|
|
|
export function OrderPartsSummary({ sources }: { sources: OrderPartFrame[] }) {
|
|
if (sources.length === 0) return null;
|
|
return (
|
|
<Panel
|
|
title={
|
|
sources.length === 1
|
|
? 'Origem da parcela emitida'
|
|
: 'Origens preservadas na ordem'
|
|
}
|
|
>
|
|
<p className="mb-4">
|
|
Cada linha conserva a adjudicação original. Quantidades e IVA
|
|
usam os arredondamentos cumulativos da origem; o documento
|
|
mostra apenas as parcelas emitidas nesta ordem.
|
|
</p>
|
|
<div className="grid min-w-0 gap-4">
|
|
{sources.map((source) => (
|
|
<section
|
|
key={source.requisition.id}
|
|
className="grid min-w-0 gap-2 rounded-lg border p-4"
|
|
>
|
|
<h3 className="font-semibold">
|
|
<Link
|
|
href={`/requisicoes/${source.requisition.id}`}
|
|
className="underline"
|
|
>
|
|
{source.requisition.number}
|
|
</Link>
|
|
</h3>
|
|
<p className="break-words">
|
|
{source.department.name} · {source.cost_center.code}{' '}
|
|
· {source.cost_center.name}
|
|
</p>
|
|
<p className="break-words">
|
|
Proposta {source.quotation.reference} · Pagamento:{' '}
|
|
{source.quotation.payment_terms}
|
|
</p>
|
|
<p className="break-words">
|
|
Entrega: {source.award.delivery_date} ·{' '}
|
|
{source.award.delivery_location}
|
|
</p>
|
|
{source.native_preparation.approved_reference && (
|
|
<p>
|
|
Base aprovada da origem:{' '}
|
|
{money(
|
|
source.approval_rules
|
|
?.approval_includes_tax === false
|
|
? source.native_preparation
|
|
.approved_reference.subtotal_minor
|
|
: source.native_preparation
|
|
.approved_reference.total_minor,
|
|
'MZN',
|
|
)}{' '}
|
|
(
|
|
{source.approval_rules
|
|
?.approval_includes_tax === false
|
|
? 'sem IVA'
|
|
: 'com IVA'}
|
|
).
|
|
</p>
|
|
)}
|
|
{source.award.justification && (
|
|
<p className="break-words whitespace-pre-wrap">
|
|
Fundamento: {source.award.justification}
|
|
</p>
|
|
)}
|
|
<Link
|
|
href={`/requisicoes/${source.requisition.id}/adjudicacao`}
|
|
className="underline"
|
|
>
|
|
Consultar a adjudicação desta origem
|
|
</Link>
|
|
{(source.final_approvals ?? []).map((step) => (
|
|
<p key={step.id} className="text-sm">
|
|
{Object.entries(roleLabels).find(
|
|
([role]) => role === step.role,
|
|
)?.[1] ?? step.role}{' '}
|
|
·{' '}
|
|
{step.decision === 'approved'
|
|
? 'Aprovado'
|
|
: step.decision === 'rejected'
|
|
? 'Rejeitado'
|
|
: 'Pendente'}{' '}
|
|
· Interveniente #{step.approver_id}
|
|
</p>
|
|
))}
|
|
{source.native_preparation.items.map((line) => (
|
|
<p
|
|
key={line.quotation_item_id}
|
|
className="break-words"
|
|
>
|
|
{line.description}: emitido{' '}
|
|
{line.quantity_milli / 1000}
|
|
{line.approved_quantity_milli === undefined
|
|
? ''
|
|
: ` de ${line.approved_quantity_milli / 1000} aprovado(s)`}{' '}
|
|
·{' '}
|
|
{money(
|
|
line.total_minor,
|
|
source.quotation.currency,
|
|
)}
|
|
</p>
|
|
))}
|
|
</section>
|
|
))}
|
|
</div>
|
|
</Panel>
|
|
);
|
|
}
|