feat: enhance ata and objeto management by adding configuration options for quantity limits and usage tracking, improving data integrity and user feedback in pedidos

This commit is contained in:
2025-12-16 14:20:31 -03:00
parent fd2669aa4f
commit f90b27648f
8 changed files with 618 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import { api } from '@sgse-app/backend/convex/_generated/api';
import type { Doc, Id } from '@sgse-app/backend/convex/_generated/dataModel';
import type { FunctionReturnType } from 'convex/server';
import { useConvexClient, useQuery } from 'convex-svelte';
import { SvelteSet } from 'svelte/reactivity';
import { toast } from 'svelte-sonner';
@@ -54,7 +55,12 @@
type Modalidade = 'dispensa' | 'inexgibilidade' | 'adesao' | 'consumo';
function coerceModalidade(value: string): Modalidade {
if (value === 'dispensa' || value === 'inexgibilidade' || value === 'adesao' || value === 'consumo') {
if (
value === 'dispensa' ||
value === 'inexgibilidade' ||
value === 'adesao' ||
value === 'consumo'
) {
return value;
}
return 'consumo';
@@ -77,7 +83,8 @@
};
// Atas por objeto (carregadas sob demanda)
let atasPorObjeto = $state<Record<string, Array<Doc<'atas'>>>>({});
type AtasComLimite = FunctionReturnType<typeof api.objetos.getAtasComLimite>;
let atasPorObjeto = $state<Record<string, AtasComLimite>>({});
let editingItems = $state<Record<string, EditingItem>>({});
@@ -235,7 +242,9 @@
let solicitacaoDocsRequestId = $state<Id<'solicitacoesItens'> | null>(null);
let solicitacaoDocsSolicitadoPor = $state<Id<'funcionarios'> | null>(null);
let solicitacaoDocsTipo = $state<string | null>(null);
let solicitacaoDocs = $state<any[]>([]);
let solicitacaoDocs = $state<FunctionReturnType<typeof api.pedidos.listSolicitacaoDocumentos>>(
[]
);
let carregandoSolicitacaoDocs = $state(false);
let solicitacaoDocumentoDescricao = $state('');
@@ -651,19 +660,16 @@
async function loadAtasForObjeto(objetoId: string) {
if (atasPorObjeto[objetoId]) return;
try {
const linkedAtas = await client.query(api.objetos.getAtas, {
const linkedAtas = await client.query(api.objetos.getAtasComLimite, {
objetoId: objetoId as Id<'objetos'>
});
atasPorObjeto = {
...atasPorObjeto,
[objetoId]: linkedAtas
};
atasPorObjeto[objetoId] = linkedAtas;
} catch (e) {
console.error('Erro ao carregar atas para objeto', objetoId, e);
}
}
function getAtasForObjeto(objetoId: string): Array<Doc<'atas'>> {
function getAtasForObjeto(objetoId: string): AtasComLimite {
return atasPorObjeto[objetoId] || [];
}
@@ -1464,7 +1470,9 @@
<XCircle size={16} />
</button>
{:else}
<span class="ml-2 self-center text-xs text-gray-400">Aguardando Análise</span>
<span class="ml-2 self-center text-xs text-gray-400"
>Aguardando Análise</span
>
{/if}
</div>
</td>
@@ -1563,7 +1571,15 @@
>
<option value="">Nenhuma</option>
{#each getAtasForObjeto(newItem.objetoId) as ata (ata._id)}
<option value={ata._id}>Ata {ata.numero} (SEI: {ata.numeroSei})</option>
{@const isSelectedAta = String(ata._id) === newItem.ataId}
{@const reason = !ata.quantidadeTotal
? 'não configurada'
: ata.quantidadeUsada >= ata.limitePermitido
? 'limite atingido'
: null}
<option value={ata._id} disabled={ata.isLocked && !isSelectedAta}>
Ata {ata.numero} (SEI: {ata.numeroSei}){reason ? ` (${reason})` : ''}
</option>
{/each}
</select>
</div>
@@ -1810,7 +1826,16 @@
>
<option value="">Nenhuma</option>
{#each getAtasForObjeto(item.objetoId) as ata (ata._id)}
<option value={ata._id}>Ata {ata.numero} (SEI: {ata.numeroSei})</option>
{@const currentAtaId = ensureEditingItem(item).ataId}
{@const isSelectedAta = String(ata._id) === currentAtaId}
{@const reason = !ata.quantidadeTotal
? 'não configurada'
: ata.quantidadeUsada >= ata.limitePermitido
? 'limite atingido'
: null}
<option value={ata._id} disabled={ata.isLocked && !isSelectedAta}>
Ata {ata.numero} (SEI: {ata.numeroSei}){reason ? ` (${reason})` : ''}
</option>
{/each}
</select>
{:else if item.ataId}