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:
@@ -44,6 +44,11 @@
|
||||
dataFim: ''
|
||||
});
|
||||
let selectedObjetos = $state<Id<'objetos'>[]>([]);
|
||||
type ObjetoAtaConfig = {
|
||||
quantidadeTotal: number | undefined;
|
||||
limitePercentual: number | undefined;
|
||||
};
|
||||
let objetosConfig = $state<Record<string, ObjetoAtaConfig>>({});
|
||||
let searchObjeto = $state('');
|
||||
let saving = $state(false);
|
||||
|
||||
@@ -73,6 +78,15 @@
|
||||
const linkedObjetos = await client.query(api.atas.getObjetos, { id: ata._id });
|
||||
selectedObjetos = linkedObjetos.map((o) => o._id);
|
||||
|
||||
const linkedConfigs = await client.query(api.atas.getObjetosConfig, { id: ata._id });
|
||||
objetosConfig = {};
|
||||
for (const cfg of linkedConfigs) {
|
||||
objetosConfig[String(cfg.objetoId)] = {
|
||||
quantidadeTotal: cfg.quantidadeTotal ?? undefined,
|
||||
limitePercentual: cfg.limitePercentual ?? 50
|
||||
};
|
||||
}
|
||||
|
||||
// Fetch attachments
|
||||
attachments = await client.query(api.atas.getDocumentos, { ataId: ata._id });
|
||||
} else {
|
||||
@@ -85,6 +99,7 @@
|
||||
dataFim: ''
|
||||
};
|
||||
selectedObjetos = [];
|
||||
objetosConfig = {};
|
||||
attachments = [];
|
||||
}
|
||||
attachmentFiles = [];
|
||||
@@ -97,11 +112,22 @@
|
||||
editingId = null;
|
||||
}
|
||||
|
||||
function getObjetoConfig(id: Id<'objetos'>): ObjetoAtaConfig {
|
||||
const key = String(id);
|
||||
if (!objetosConfig[key]) {
|
||||
objetosConfig[key] = { quantidadeTotal: 1, limitePercentual: 50 };
|
||||
}
|
||||
return objetosConfig[key];
|
||||
}
|
||||
|
||||
function toggleObjeto(id: Id<'objetos'>) {
|
||||
const key = String(id);
|
||||
if (selectedObjetos.includes(id)) {
|
||||
selectedObjetos = selectedObjetos.filter((oid) => oid !== id);
|
||||
delete objetosConfig[key];
|
||||
} else {
|
||||
selectedObjetos = [...selectedObjetos, id];
|
||||
objetosConfig[key] = { quantidadeTotal: 1, limitePercentual: 50 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,13 +150,37 @@
|
||||
}
|
||||
saving = true;
|
||||
try {
|
||||
const objetos = selectedObjetos.map((objetoId) => {
|
||||
const cfg = objetosConfig[String(objetoId)];
|
||||
if (
|
||||
!cfg ||
|
||||
cfg.quantidadeTotal === undefined ||
|
||||
!Number.isFinite(cfg.quantidadeTotal) ||
|
||||
cfg.quantidadeTotal <= 0
|
||||
) {
|
||||
throw new Error(
|
||||
'Informe a quantidade (maior que zero) para todos os objetos vinculados.'
|
||||
);
|
||||
}
|
||||
const limitePercentual =
|
||||
cfg.limitePercentual === undefined || !Number.isFinite(cfg.limitePercentual)
|
||||
? 50
|
||||
: cfg.limitePercentual;
|
||||
|
||||
return {
|
||||
objetoId,
|
||||
quantidadeTotal: cfg.quantidadeTotal,
|
||||
limitePercentual
|
||||
};
|
||||
});
|
||||
|
||||
const payload = {
|
||||
numero: formData.numero,
|
||||
numeroSei: formData.numeroSei,
|
||||
empresaId: formData.empresaId as Id<'empresas'>,
|
||||
dataInicio: formData.dataInicio || undefined,
|
||||
dataFim: formData.dataFim || undefined,
|
||||
objetosIds: selectedObjetos
|
||||
objetos
|
||||
};
|
||||
|
||||
let ataId: Id<'atas'>;
|
||||
@@ -537,6 +587,54 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if selectedObjetos.length > 0}
|
||||
<div class="border-base-300 border-t pt-4">
|
||||
<div class="font-semibold">Configuração por objeto</div>
|
||||
<p class="text-base-content/60 mt-1 text-xs">
|
||||
Defina a quantidade total do objeto na ata e o limite de uso em % (padrão 50%).
|
||||
</p>
|
||||
<div class="mt-3 max-h-52 space-y-3 overflow-y-auto">
|
||||
{#each selectedObjetos as objetoId (objetoId)}
|
||||
{@const obj = objetos.find((o) => o._id === objetoId)}
|
||||
{@const cfg = getObjetoConfig(objetoId)}
|
||||
<div class="border-base-300 rounded-lg border p-3">
|
||||
<div class="text-sm font-semibold">{obj?.nome || 'Objeto'}</div>
|
||||
<div class="mt-3 grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div class="form-control w-full">
|
||||
<label class="label" for={`qtd_${objetoId}`}>
|
||||
<span class="label-text text-xs font-semibold">Quantidade na ata</span
|
||||
>
|
||||
</label>
|
||||
<input
|
||||
id={`qtd_${objetoId}`}
|
||||
class="input input-bordered input-sm focus:input-primary w-full"
|
||||
type="number"
|
||||
min="1"
|
||||
required
|
||||
bind:value={cfg.quantidadeTotal}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control w-full">
|
||||
<label class="label" for={`limite_${objetoId}`}>
|
||||
<span class="label-text text-xs font-semibold">Limite (%)</span>
|
||||
</label>
|
||||
<input
|
||||
id={`limite_${objetoId}`}
|
||||
class="input input-bordered input-sm focus:input-primary w-full"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="50"
|
||||
bind:value={cfg.limitePercentual}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="border-base-300 border-t pt-4">
|
||||
<div class="font-semibold">Anexos</div>
|
||||
<div class="mt-2 space-y-2">
|
||||
|
||||
Reference in New Issue
Block a user