feat: Implement Ata de Registro de Preços management and linking to objetos and pedidos

This commit is contained in:
2025-12-02 23:29:42 -03:00
parent 8a50fb6f61
commit 4d29501849
7 changed files with 200 additions and 20 deletions

View File

@@ -7,12 +7,15 @@
const client = useConvexClient();
// Reactive query
// Reactive queries
const objetosQuery = useQuery(api.objetos.list, {});
let objetos = $derived(objetosQuery.data || []);
let loading = $derived(objetosQuery.isLoading);
let error = $derived(objetosQuery.error?.message || null);
const atasQuery = useQuery(api.atas.list, {});
let atas = $derived(atasQuery.data || []);
// Modal state
let showModal = $state(false);
let editingId: string | null = $state(null);
@@ -23,13 +26,16 @@
codigoEfisco: '',
codigoCatmat: '',
codigoCatserv: '',
unidade: ''
unidade: '',
atas: [] as Id<'atas'>[]
});
let saving = $state(false);
function openModal(objeto?: Doc<'objetos'>) {
async function openModal(objeto?: Doc<'objetos'>) {
if (objeto) {
editingId = objeto._id;
// Fetch linked Atas
const linkedAtas = await client.query(api.objetos.getAtas, { objetoId: objeto._id });
formData = {
nome: objeto.nome,
valorEstimado: maskCurrencyBRL(objeto.valorEstimado || ''),
@@ -37,7 +43,8 @@
codigoEfisco: objeto.codigoEfisco || '',
codigoCatmat: objeto.codigoCatmat || '',
codigoCatserv: objeto.codigoCatserv || '',
unidade: objeto.unidade || ''
unidade: objeto.unidade || '',
atas: linkedAtas.map((a) => a._id)
};
} else {
editingId = null;
@@ -48,7 +55,8 @@
codigoEfisco: '',
codigoCatmat: '',
codigoCatserv: '',
unidade: ''
unidade: '',
atas: []
};
}
showModal = true;
@@ -70,7 +78,8 @@
codigoEfisco: formData.codigoEfisco,
codigoCatmat: formData.codigoCatmat || undefined,
codigoCatserv: formData.codigoCatserv || undefined,
unidade: formData.unidade
unidade: formData.unidade,
atas: formData.atas
};
if (editingId) {
@@ -97,6 +106,14 @@
alert('Erro ao excluir: ' + (e as Error).message);
}
}
function toggleAtaSelection(ataId: Id<'atas'>) {
if (formData.atas.includes(ataId)) {
formData.atas = formData.atas.filter((id) => id !== ataId);
} else {
formData.atas = [...formData.atas, ataId];
}
}
</script>
<div class="container mx-auto p-6">
@@ -303,6 +320,31 @@
/>
</div>
<div class="mb-6">
<label class="mb-2 block text-sm font-bold text-gray-700" for="atas">
Vincular Atas
</label>
<div class="max-h-40 overflow-y-auto rounded border p-2">
{#each atas as ata (ata._id)}
<div class="mb-2 flex items-center">
<input
type="checkbox"
id={`ata-${ata._id}`}
checked={formData.atas.includes(ata._id)}
onchange={() => toggleAtaSelection(ata._id)}
class="mr-2 h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<label for={`ata-${ata._id}`} class="text-sm text-gray-700">
{ata.numero} ({ata.numeroSei})
</label>
</div>
{/each}
{#if atas.length === 0}
<p class="text-sm text-gray-500">Nenhuma ata disponível.</p>
{/if}
</div>
</div>
<div class="flex items-center justify-end">
<button
type="button"