commit14
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
@@ -33,6 +33,7 @@ type Evaluation = {
|
||||
created_at: string;
|
||||
};
|
||||
type Quote = {
|
||||
canEvaluate: boolean;
|
||||
id: number;
|
||||
reference: string;
|
||||
supplier: { name: string };
|
||||
@@ -56,7 +57,8 @@ export default function Comparison({
|
||||
quotations,
|
||||
suppliers,
|
||||
canCreate,
|
||||
canEvaluate,
|
||||
focusQuotationId = null,
|
||||
prepare = false,
|
||||
ready,
|
||||
topIds,
|
||||
comparisonPolicy,
|
||||
@@ -71,13 +73,14 @@ export default function Comparison({
|
||||
suppliers: { id: number; name: string }[];
|
||||
canCreate: boolean;
|
||||
canEvaluate: boolean;
|
||||
focusQuotationId?: number | null;
|
||||
prepare?: boolean;
|
||||
ready: boolean;
|
||||
topIds: number[];
|
||||
comparisonPolicy: ComparisonPolicy;
|
||||
}) {
|
||||
const { auth } = usePage().props;
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [selected, setSelected] = useState<number | null>(null);
|
||||
const [adding, setAdding] = useState(prepare && canCreate);
|
||||
const [selected, setSelected] = useState<number | null>(focusQuotationId);
|
||||
const form = useForm({
|
||||
supplier_id: '',
|
||||
reference: '',
|
||||
@@ -188,265 +191,273 @@ export default function Comparison({
|
||||
selecção deve ficar fundamentada na adjudicação.
|
||||
</p>
|
||||
)}
|
||||
{adding && (
|
||||
<Panel
|
||||
title="Nova proposta"
|
||||
description="MZN · 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
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post(
|
||||
`/requisicoes/${requisition.id}/cotacoes`,
|
||||
{
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setAdding(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
}}
|
||||
{canCreate && adding && (
|
||||
<div id="quotation-create">
|
||||
<Panel
|
||||
title="Nova proposta"
|
||||
description="MZN · 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."
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="supplier">
|
||||
Fornecedor activo
|
||||
</Label>
|
||||
<select
|
||||
id="supplier"
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.supplier_id}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'supplier_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{suppliers.map((s) => (
|
||||
<option value={s.id} key={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{(
|
||||
[
|
||||
[
|
||||
'reference',
|
||||
'Referência do fornecedor',
|
||||
'text',
|
||||
],
|
||||
[
|
||||
'delivery_days',
|
||||
'Prazo de entrega (dias)',
|
||||
'number',
|
||||
],
|
||||
['valid_until', 'Válida até', 'date'],
|
||||
[
|
||||
'payment_terms',
|
||||
'Condições de pagamento',
|
||||
'text',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label, type]) => (
|
||||
<div className="space-y-2" key={key}>
|
||||
<Label htmlFor={key}>{label}</Label>
|
||||
<Input
|
||||
id={key}
|
||||
type={type}
|
||||
min={
|
||||
type === 'number'
|
||||
? 1
|
||||
: undefined
|
||||
}
|
||||
<form
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post(
|
||||
`/requisicoes/${requisition.id}/cotacoes`,
|
||||
{
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setAdding(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="supplier">
|
||||
Fornecedor activo
|
||||
</Label>
|
||||
<select
|
||||
id="supplier"
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data[key]}
|
||||
value={form.data.supplier_id}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
key,
|
||||
'supplier_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{suppliers.map((s) => (
|
||||
<option value={s.id} key={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
{requisition.items.map((i, index) => (
|
||||
<div
|
||||
className="grid items-center gap-3 rounded-lg border p-4 md:grid-cols-2"
|
||||
key={i.id}
|
||||
>
|
||||
<div>
|
||||
<strong className="text-sm">
|
||||
{(
|
||||
[
|
||||
[
|
||||
'reference',
|
||||
'Referência do fornecedor',
|
||||
'text',
|
||||
],
|
||||
[
|
||||
'delivery_days',
|
||||
'Prazo de entrega (dias)',
|
||||
'number',
|
||||
],
|
||||
[
|
||||
'valid_until',
|
||||
'Válida até',
|
||||
'date',
|
||||
],
|
||||
[
|
||||
'payment_terms',
|
||||
'Condições de pagamento',
|
||||
'text',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label, type]) => (
|
||||
<div className="space-y-2" key={key}>
|
||||
<Label htmlFor={key}>{label}</Label>
|
||||
<Input
|
||||
id={key}
|
||||
type={type}
|
||||
min={
|
||||
type === 'number'
|
||||
? 1
|
||||
: undefined
|
||||
}
|
||||
required
|
||||
value={form.data[key]}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
key,
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
{requisition.items.map((i, index) => (
|
||||
<div
|
||||
className="grid items-center gap-3 rounded-lg border p-4 md:grid-cols-2"
|
||||
key={i.id}
|
||||
>
|
||||
<div>
|
||||
<strong className="text-sm">
|
||||
{i.description}
|
||||
</strong>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{i.quantity} unidades · IVA{' '}
|
||||
{i.tax_rate}%
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label
|
||||
htmlFor={`price-${i.id}`}
|
||||
>
|
||||
Preço unitário antes de
|
||||
desconto e IVA (MZN)
|
||||
</Label>
|
||||
<Input
|
||||
id={`price-${i.id}`}
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.01"
|
||||
required
|
||||
value={
|
||||
form.data.items[index]
|
||||
.unit_price
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
unit_price:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<fieldset className="space-y-4 rounded-lg border p-4">
|
||||
<legend className="px-2 font-medium">
|
||||
Descontos unitários antes do IVA
|
||||
</legend>
|
||||
{requisition.items.map((i, index) => (
|
||||
<div
|
||||
key={i.id}
|
||||
className="grid gap-3 md:grid-cols-3"
|
||||
>
|
||||
<span className="text-sm">
|
||||
{i.description}
|
||||
</strong>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{i.quantity} unidades · IVA{' '}
|
||||
{i.tax_rate}%
|
||||
</p>
|
||||
</span>
|
||||
<label className="text-sm">
|
||||
Tipo de desconto
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
form.data.items[index]
|
||||
.discount_type
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
discount_type:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
discount_value:
|
||||
'0',
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="none">
|
||||
Sem desconto
|
||||
</option>
|
||||
<option value="percent">
|
||||
Percentagem (%)
|
||||
</option>
|
||||
<option value="amount">
|
||||
Valor por unidade (MZN)
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="text-sm">
|
||||
{form.data.items[index]
|
||||
.discount_type === 'percent'
|
||||
? 'Percentagem (%)'
|
||||
: 'Valor unitário (MZN)'}
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
required
|
||||
disabled={
|
||||
form.data.items[index]
|
||||
.discount_type ===
|
||||
'none'
|
||||
}
|
||||
max={
|
||||
form.data.items[index]
|
||||
.discount_type ===
|
||||
'percent'
|
||||
? '100'
|
||||
: '1000000000'
|
||||
}
|
||||
value={
|
||||
form.data.items[index]
|
||||
.discount_value
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
discount_value:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`price-${i.id}`}>
|
||||
Preço unitário antes de desconto
|
||||
e IVA (MZN)
|
||||
</Label>
|
||||
<Input
|
||||
id={`price-${i.id}`}
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.01"
|
||||
required
|
||||
value={
|
||||
form.data.items[index]
|
||||
.unit_price
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
unit_price:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<fieldset className="space-y-4 rounded-lg border p-4">
|
||||
<legend className="px-2 font-medium">
|
||||
Descontos unitários antes do IVA
|
||||
</legend>
|
||||
{requisition.items.map((i, index) => (
|
||||
<div
|
||||
key={i.id}
|
||||
className="grid gap-3 md:grid-cols-3"
|
||||
>
|
||||
<span className="text-sm">
|
||||
{i.description}
|
||||
</span>
|
||||
<label className="text-sm">
|
||||
Tipo de desconto
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
form.data.items[index]
|
||||
.discount_type
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
discount_type:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
discount_value:
|
||||
'0',
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="none">
|
||||
Sem desconto
|
||||
</option>
|
||||
<option value="percent">
|
||||
Percentagem (%)
|
||||
</option>
|
||||
<option value="amount">
|
||||
Valor por unidade (MZN)
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="text-sm">
|
||||
{form.data.items[index]
|
||||
.discount_type === 'percent'
|
||||
? 'Percentagem (%)'
|
||||
: 'Valor unitário (MZN)'}
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
required
|
||||
disabled={
|
||||
form.data.items[index]
|
||||
.discount_type ===
|
||||
'none'
|
||||
}
|
||||
max={
|
||||
form.data.items[index]
|
||||
.discount_type ===
|
||||
'percent'
|
||||
? '100'
|
||||
: '1000000000'
|
||||
}
|
||||
value={
|
||||
form.data.items[index]
|
||||
.discount_value
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(line, k) =>
|
||||
k === index
|
||||
? {
|
||||
...line,
|
||||
discount_value:
|
||||
e
|
||||
.target
|
||||
.value,
|
||||
}
|
||||
: line,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
</fieldset>
|
||||
<label className="flex items-start gap-3 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={form.data.no_conflict}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'no_conflict',
|
||||
e.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
Declaro que não tenho conflito de interesses com
|
||||
este fornecedor.
|
||||
</label>
|
||||
<Button disabled={form.processing}>
|
||||
Guardar proposta
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
))}
|
||||
</fieldset>
|
||||
<label className="flex items-start gap-3 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
required
|
||||
checked={form.data.no_conflict}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'no_conflict',
|
||||
e.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
Declaro que não tenho conflito de interesses
|
||||
com este fornecedor.
|
||||
</label>
|
||||
<Button disabled={form.processing}>
|
||||
Guardar proposta
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
</div>
|
||||
)}
|
||||
<Panel
|
||||
title="Matriz de comparação"
|
||||
@@ -544,62 +555,60 @@ export default function Comparison({
|
||||
{quotations
|
||||
.filter((q) => q.id === selected)
|
||||
.map((q) => (
|
||||
<Panel
|
||||
key={q.id}
|
||||
title={`${q.supplier.name} · ${q.reference}`}
|
||||
description={`Pagamento: ${q.payment_terms}`}
|
||||
>
|
||||
{q.ineligibility_reasons.length > 0 && (
|
||||
<ul className="mb-4 list-disc pl-5 text-sm text-amber-800 dark:text-amber-300">
|
||||
{q.ineligibility_reasons.map((reason) => (
|
||||
<li key={reason}>{reason}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<QuotationCommercialTerms
|
||||
terms={q.commercial_terms}
|
||||
/>
|
||||
<div className="space-y-3">
|
||||
{q.items.map((i) => (
|
||||
<p className="text-sm" key={i.id}>
|
||||
{i.description} · {i.quantity} ×{' '}
|
||||
{money(i.unit_price_minor)} · total com
|
||||
IVA {money(i.total_minor)}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
<h3 className="mt-6 mb-3 font-semibold">
|
||||
Avaliações registadas
|
||||
</h3>
|
||||
{q.evaluations.map((ev) => (
|
||||
<div
|
||||
key={ev.id}
|
||||
className="mb-3 rounded-lg border p-4 text-sm"
|
||||
>
|
||||
<strong>
|
||||
Avaliador #{ev.evaluator_id}
|
||||
</strong>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Registada em{' '}
|
||||
{new Date(ev.created_at).toLocaleString(
|
||||
'pt-MZ',
|
||||
<div key={q.id} id={`quotation-${q.id}`}>
|
||||
<Panel
|
||||
title={`${q.supplier.name} · ${q.reference}`}
|
||||
description={`Pagamento: ${q.payment_terms}`}
|
||||
>
|
||||
{q.ineligibility_reasons.length > 0 && (
|
||||
<ul className="mb-4 list-disc pl-5 text-sm text-amber-800 dark:text-amber-300">
|
||||
{q.ineligibility_reasons.map(
|
||||
(reason) => (
|
||||
<li key={reason}>{reason}</li>
|
||||
),
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
Qualidade {ev.quality} · histórico{' '}
|
||||
{ev.history} · pagamento {ev.payment}
|
||||
</p>
|
||||
<p className="mt-2 whitespace-pre-wrap text-muted-foreground">
|
||||
{ev.comment}
|
||||
</p>
|
||||
</ul>
|
||||
)}
|
||||
<QuotationCommercialTerms
|
||||
terms={q.commercial_terms}
|
||||
/>
|
||||
<div className="space-y-3">
|
||||
{q.items.map((i) => (
|
||||
<p className="text-sm" key={i.id}>
|
||||
{i.description} · {i.quantity} ×{' '}
|
||||
{money(i.unit_price_minor)} · total
|
||||
com IVA {money(i.total_minor)}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
{canEvaluate &&
|
||||
q.eligible &&
|
||||
!q.conflict_blocked &&
|
||||
!q.evaluations.some(
|
||||
(ev) => ev.evaluator_id === auth.user.id,
|
||||
) && (
|
||||
<h3 className="mt-6 mb-3 font-semibold">
|
||||
Avaliações registadas
|
||||
</h3>
|
||||
{q.evaluations.map((ev) => (
|
||||
<div
|
||||
key={ev.id}
|
||||
className="mb-3 rounded-lg border p-4 text-sm"
|
||||
>
|
||||
<strong>
|
||||
Avaliador #{ev.evaluator_id}
|
||||
</strong>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Registada em{' '}
|
||||
{new Date(
|
||||
ev.created_at,
|
||||
).toLocaleString('pt-MZ')}
|
||||
</p>
|
||||
<p>
|
||||
Qualidade {ev.quality} · histórico{' '}
|
||||
{ev.history} · pagamento{' '}
|
||||
{ev.payment}
|
||||
</p>
|
||||
<p className="mt-2 whitespace-pre-wrap text-muted-foreground">
|
||||
{ev.comment}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
{q.canEvaluate && (
|
||||
<form
|
||||
className="mt-5 space-y-4 border-t pt-5"
|
||||
onSubmit={(e) => {
|
||||
@@ -701,7 +710,8 @@ export default function Comparison({
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
</Panel>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user