Can attach multiple inbox entries to movements at once

This commit is contained in:
2025-05-15 19:40:07 +02:00
parent 5aa954dca2
commit 0f6447155b
7 changed files with 232 additions and 27 deletions

View File

@ -242,9 +242,13 @@ function InboxTable(p: {
);
if (!targetAccount) return;
const entries = p.entries.filter((m) => rowSelectionModel.includes(m.id));
// Find the entry to map
const entries = p.entries.filter(
(m) => rowSelectionModel.includes(m.id) && !m.movement_id
);
const movements: Movement[][] = [];
// Search for applicable movements
for (const [num, e] of entries.entries()) {
loadingMessage.show(
`Searching for proper movements ${num}/${entries.length}`
@ -277,8 +281,43 @@ function InboxTable(p: {
setAttachMultipleMovements(undefined);
};
const handlePerformAttachMultiple = (mapping: (number | undefined)[]) => {
console.info(attachMultipleEntries, attachMultipleMovements, mapping);
const handlePerformAttachMultiple = async (
mapping: (Movement | undefined)[]
) => {
try {
for (const [num, entry] of attachMultipleEntries!.entries()) {
loadingMessage.show(`Attaching ${num} of ${mapping.length}`);
const movement = mapping[num];
if (!movement) continue;
await Promise.all([
// Update movement
MovementApi.Update({
...movement,
file_id: entry?.file_id,
}),
// Update inbox entries
InboxApi.Update({
...entry!,
movement_id: movement.id,
}),
]);
}
setAttachMultipleEntries(undefined);
setAttachMultipleMovements(undefined);
snackbar("Mapping successfully performed!");
p.onReload(false);
} catch (e) {
console.error("Performing mapping...", e);
alert(`Failed to perform mapping! ${e}`);
} finally {
loadingMessage.hide();
}
};
// Delete multiple inbox entries