@@ -1,5 +1,5 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { Head, Link, useForm, usePage, useRemember } from '@inertiajs/react';
|
||||
import type { ComponentProps } from 'react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import { QuotationCommercialTerms } from '@/components/quotation-commercial-terms';
|
||||
@@ -19,6 +19,8 @@ import {
|
||||
QuotationExchangePanel,
|
||||
} from '@/components/quotation-exchange-panel';
|
||||
import type { ExchangeBasis } from '@/components/quotation-exchange-panel';
|
||||
import { QuotationEvaluationForm } from '@/components/quotation-evaluation-form';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
|
||||
type Item = {
|
||||
id: number;
|
||||
@@ -64,7 +66,7 @@ type Quote = {
|
||||
ineligibility_reasons: string[];
|
||||
commercial_terms: CommercialTerms | null;
|
||||
};
|
||||
export default function Comparison({
|
||||
function ComparisonContent({
|
||||
requisition,
|
||||
quotations,
|
||||
suppliers,
|
||||
@@ -82,6 +84,7 @@ export default function Comparison({
|
||||
id: number;
|
||||
number: string;
|
||||
justification: string;
|
||||
process_version?: number;
|
||||
items: Item[];
|
||||
};
|
||||
quotations: Quote[];
|
||||
@@ -97,9 +100,17 @@ export default function Comparison({
|
||||
exchangeAvailable?: boolean;
|
||||
canRecordExchange?: boolean;
|
||||
}) {
|
||||
const [adding, setAdding] = useState(prepare && canCreate);
|
||||
const [selected, setSelected] = useState<number | null>(focusQuotationId);
|
||||
const form = useForm({
|
||||
const actor = usePage().props.auth?.user;
|
||||
const historyKey = `quotation-preparation:${actor?.tenant_id}:${actor?.id}:${requisition.id}:${requisition.process_version ?? 0}`;
|
||||
const [adding, setAdding] = useRemember(
|
||||
prepare && canCreate,
|
||||
`${historyKey}:adding`,
|
||||
);
|
||||
const [selected, setSelected] = useRemember<number | null>(
|
||||
focusQuotationId,
|
||||
`${historyKey}:selected`,
|
||||
);
|
||||
const form = useForm(historyKey, {
|
||||
currency: 'MZN',
|
||||
supplier_id: '',
|
||||
reference: '',
|
||||
@@ -114,13 +125,10 @@ export default function Comparison({
|
||||
discount_value: '0',
|
||||
})),
|
||||
});
|
||||
const evaluation = useForm({
|
||||
quality: '5',
|
||||
history: '5',
|
||||
payment: '5',
|
||||
comment: '',
|
||||
no_conflict: false,
|
||||
});
|
||||
const preparationRef = usePreparationDirty(
|
||||
form.isDirty,
|
||||
adding && canCreate,
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Head title={`Cotações · ${requisition.number}`} />
|
||||
@@ -217,6 +225,7 @@ export default function Comparison({
|
||||
description="Valores na moeda seleccionada, com duas casas decimais. Quantidades e IVA herdados da requisição. Desconto por unidade antes do IVA; preço líquido arredondado ao centavo antes de multiplicar pela quantidade. Preencha todas as linhas."
|
||||
>
|
||||
<form
|
||||
ref={preparationRef}
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -247,6 +256,17 @@ export default function Comparison({
|
||||
}
|
||||
>
|
||||
<option value="MZN">MZN</option>
|
||||
{form.data.currency !== 'MZN' &&
|
||||
!exchangeRates.some(
|
||||
(rate) =>
|
||||
rate.currency ===
|
||||
form.data.currency,
|
||||
) && (
|
||||
<option value={form.data.currency}>
|
||||
{form.data.currency} · taxa
|
||||
indisponível nesta consulta
|
||||
</option>
|
||||
)}
|
||||
{exchangeRates.map((rate) => (
|
||||
<option
|
||||
key={rate.id}
|
||||
@@ -275,6 +295,22 @@ export default function Comparison({
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{form.data.supplier_id !== '' &&
|
||||
!suppliers.some(
|
||||
(supplier) =>
|
||||
String(supplier.id) ===
|
||||
form.data.supplier_id,
|
||||
) && (
|
||||
<option
|
||||
value={
|
||||
form.data
|
||||
.supplier_id
|
||||
}
|
||||
>
|
||||
Fornecedor preservado ·
|
||||
confirme a elegibilidade
|
||||
</option>
|
||||
)}
|
||||
{suppliers.map((s) => (
|
||||
<option value={s.id} key={s.id}>
|
||||
{s.name}
|
||||
@@ -508,6 +544,7 @@ export default function Comparison({
|
||||
{exchangeAvailable && (
|
||||
<QuotationExchangePanel
|
||||
requisitionId={requisition.id}
|
||||
processVersion={requisition.process_version ?? 0}
|
||||
rates={exchangeRates}
|
||||
canRecord={canRecordExchange}
|
||||
/>
|
||||
@@ -602,8 +639,6 @@ export default function Comparison({
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setSelected(q.id);
|
||||
evaluation.reset();
|
||||
evaluation.clearErrors();
|
||||
}}
|
||||
>
|
||||
Detalhe
|
||||
@@ -685,106 +720,11 @@ export default function Comparison({
|
||||
</div>
|
||||
))}
|
||||
{q.canEvaluate && (
|
||||
<form
|
||||
className="mt-5 space-y-4 border-t pt-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
evaluation.post(
|
||||
`/cotacoes/${q.id}/avaliar`,
|
||||
{
|
||||
onSuccess: () =>
|
||||
evaluation.reset(),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors
|
||||
errors={evaluation.errors}
|
||||
/>
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
{(
|
||||
[
|
||||
[
|
||||
'quality',
|
||||
'Qualidade técnica',
|
||||
],
|
||||
[
|
||||
'history',
|
||||
'Histórico (5 para novo)',
|
||||
],
|
||||
[
|
||||
'payment',
|
||||
'Condições de pagamento',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<div
|
||||
className="space-y-2"
|
||||
key={key}
|
||||
>
|
||||
<Label htmlFor={key}>
|
||||
{label} · 0 a 10
|
||||
</Label>
|
||||
<Input
|
||||
id={key}
|
||||
type="number"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.01"
|
||||
required
|
||||
value={
|
||||
evaluation.data[key]
|
||||
}
|
||||
onChange={(e) =>
|
||||
evaluation.setData(
|
||||
key,
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Label htmlFor="comment">
|
||||
Fundamento da avaliação
|
||||
</Label>
|
||||
<textarea
|
||||
id="comment"
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
value={evaluation.data.comment}
|
||||
onChange={(e) =>
|
||||
evaluation.setData(
|
||||
'comment',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
<label className="flex items-start gap-3 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={
|
||||
evaluation.data.no_conflict
|
||||
}
|
||||
onChange={(e) =>
|
||||
evaluation.setData(
|
||||
'no_conflict',
|
||||
e.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
Declaro não ter conflito de
|
||||
interesses e confirmo a minha
|
||||
avaliação independente.
|
||||
</label>
|
||||
<Button
|
||||
disabled={evaluation.processing}
|
||||
>
|
||||
Registar avaliação
|
||||
</Button>
|
||||
</form>
|
||||
<QuotationEvaluationForm
|
||||
key={`${actor?.tenant_id}:${actor?.id}:${requisition.id}:${q.id}`}
|
||||
requisitionId={requisition.id}
|
||||
quotationId={q.id}
|
||||
/>
|
||||
)}
|
||||
</Panel>
|
||||
</div>
|
||||
@@ -793,6 +733,17 @@ export default function Comparison({
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default function Comparison(
|
||||
props: ComponentProps<typeof ComparisonContent>,
|
||||
) {
|
||||
const actor = usePage().props.auth?.user;
|
||||
return (
|
||||
<ComparisonContent
|
||||
key={`${actor?.tenant_id}:${actor?.id}:${props.requisition.id}:${props.requisition.process_version ?? 0}`}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Comparison.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Cotações', href: '/cotacoes' },
|
||||
|
||||
Reference in New Issue
Block a user