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:
@@ -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 { Plus, Trash2, X, Info } from 'lucide-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -32,7 +33,7 @@
|
||||
acaoId?: Id<'acoes'>;
|
||||
ataId?: Id<'atas'>;
|
||||
ataNumero?: string; // For display
|
||||
ata?: Doc<'atas'>; // Full ata object for details
|
||||
ata?: FunctionReturnType<typeof api.objetos.getAtasComLimite>[number]; // dados mínimos p/ exibir detalhes
|
||||
};
|
||||
|
||||
let selectedItems = $state<SelectedItem[]>([]);
|
||||
@@ -55,7 +56,8 @@
|
||||
ataId: ''
|
||||
});
|
||||
|
||||
let availableAtas = $state<Doc<'atas'>[]>([]);
|
||||
type AtasComLimite = FunctionReturnType<typeof api.objetos.getAtasComLimite>;
|
||||
let availableAtas = $state<AtasComLimite>([]);
|
||||
|
||||
// Item Details Modal
|
||||
let showDetailsModal = $state(false);
|
||||
@@ -73,7 +75,7 @@
|
||||
|
||||
async function openItemModal(objeto: Doc<'objetos'>) {
|
||||
// Fetch linked Atas for this object
|
||||
const linkedAtas = await client.query(api.objetos.getAtas, { objetoId: objeto._id });
|
||||
const linkedAtas = await client.query(api.objetos.getAtasComLimite, { objetoId: objeto._id });
|
||||
availableAtas = linkedAtas;
|
||||
|
||||
itemConfig = {
|
||||
@@ -226,11 +228,11 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildPedidoHref(pedido: (typeof existingPedidos)[0]) {
|
||||
function buildPedidoHref(pedido: (typeof existingPedidos)[0]): `/pedidos/${string}` {
|
||||
const matchedItem = getFirstMatchingSelectedItem(pedido);
|
||||
|
||||
if (!matchedItem) {
|
||||
return resolve(`/pedidos/${pedido._id}`);
|
||||
return `/pedidos/${pedido._id}` as `/pedidos/${string}`;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams();
|
||||
@@ -246,7 +248,7 @@
|
||||
params.set('ata', matchedItem.ataId);
|
||||
}
|
||||
|
||||
return resolve(`/pedidos/${pedido._id}?${params.toString()}`);
|
||||
return `/pedidos/${pedido._id}?${params.toString()}` as `/pedidos/${string}`;
|
||||
}
|
||||
|
||||
async function checkExisting() {
|
||||
@@ -505,25 +507,21 @@
|
||||
<p class="mb-3 font-semibold text-yellow-900">Pedidos similares encontrados:</p>
|
||||
<ul class="space-y-2">
|
||||
{#each existingPedidos as pedido (pedido._id)}
|
||||
{@const first = getFirstMatchingSelectedItem(pedido)}
|
||||
<li class="flex flex-col rounded-lg bg-white px-4 py-3 shadow-sm">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="space-y-1">
|
||||
<p class="text-sm font-medium text-gray-900">
|
||||
Pedido {pedido.numeroSei || 'sem número SEI'} — {formatStatus(pedido.status)}
|
||||
</p>
|
||||
{#if getFirstMatchingSelectedItem(pedido)}
|
||||
{#key pedido._id}
|
||||
{#if getFirstMatchingSelectedItem(pedido)}
|
||||
<span
|
||||
class={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold ${getModalidadeBadgeClasses(
|
||||
getFirstMatchingSelectedItem(pedido).modalidade
|
||||
)}`}
|
||||
>
|
||||
Modalidade:{' '}
|
||||
{formatModalidade(getFirstMatchingSelectedItem(pedido).modalidade)}
|
||||
</span>
|
||||
{/if}
|
||||
{/key}
|
||||
{#if first}
|
||||
<span
|
||||
class={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold ${getModalidadeBadgeClasses(
|
||||
first.modalidade
|
||||
)}`}
|
||||
>
|
||||
Modalidade: {formatModalidade(first.modalidade)}
|
||||
</span>
|
||||
{/if}
|
||||
{#if getMatchingInfo(pedido)}
|
||||
<p class="mt-1 text-xs text-blue-700">
|
||||
@@ -532,7 +530,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<a
|
||||
href={buildPedidoHref(pedido)}
|
||||
href={resolve(buildPedidoHref(pedido))}
|
||||
class="text-sm font-medium text-blue-600 hover:text-blue-800"
|
||||
>
|
||||
Abrir
|
||||
@@ -637,7 +635,14 @@
|
||||
>
|
||||
<option value="">Nenhuma</option>
|
||||
{#each availableAtas as ata (ata._id)}
|
||||
<option value={ata._id}>Ata {ata.numero} (SEI: {ata.numeroSei})</option>
|
||||
{@const reason = !ata.quantidadeTotal
|
||||
? 'não configurada'
|
||||
: ata.quantidadeUsada >= ata.limitePermitido
|
||||
? 'limite atingido'
|
||||
: null}
|
||||
<option value={ata._id} disabled={ata.isLocked}>
|
||||
Ata {ata.numero} (SEI: {ata.numeroSei}){reason ? ` (${reason})` : ''}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user