feat(MemberOrder): add budget field to MemberOrder and MemberOrderHistory models
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 41s

- Introduced a new budget field in both MemberOrder and MemberOrderHistory models to track budget amounts.
- Updated memberOrderService to handle budget in serialization and normalization processes.
- Enhanced OrdersPanel component to include budget input and display in the UI.
- Added German localization for the new budget term to ensure consistency across languages.
This commit is contained in:
Torsten Schulz (local)
2026-04-22 08:53:57 +02:00
parent 41bbf81958
commit 1d67b68b44
6 changed files with 51 additions and 9 deletions

View File

@@ -20,10 +20,12 @@ const serializeOrder = (order) => {
const plain = typeof order.toJSON === 'function' ? order.toJSON() : { ...order };
const cost = normalizeAmount(plain.cost);
const paidAmount = normalizeAmount(plain.paidAmount);
const budget = normalizeAmount(plain.budget);
return {
...plain,
cost,
paidAmount,
budget,
openAmount: Math.max(0, Number((cost - paidAmount).toFixed(2)))
};
};
@@ -32,10 +34,12 @@ const serializeHistoryEntry = (entry) => {
const plain = typeof entry.toJSON === 'function' ? entry.toJSON() : { ...entry };
const cost = normalizeAmount(plain.cost);
const paidAmount = normalizeAmount(plain.paidAmount);
const budget = normalizeAmount(plain.budget);
return {
...plain,
cost,
paidAmount,
budget,
openAmount: Math.max(0, Number((cost - paidAmount).toFixed(2)))
};
};
@@ -64,7 +68,8 @@ class MemberOrderService {
status: order.status,
changedAt: new Date(),
cost: normalizeAmount(order.cost),
paidAmount: normalizeAmount(order.paidAmount)
paidAmount: normalizeAmount(order.paidAmount),
budget: normalizeAmount(order.budget)
}, transaction ? { transaction } : undefined);
}
@@ -105,6 +110,7 @@ class MemberOrderService {
const status = ORDER_STATUSES.includes(payload?.status) ? payload.status : 'requested';
const cost = normalizeAmount(payload?.cost);
const paidAmount = normalizeAmount(payload?.paidAmount);
const budget = normalizeAmount(payload?.budget);
if (!item) {
return {
@@ -121,7 +127,8 @@ class MemberOrderService {
orderDate: new Date(),
statusDate: new Date(),
cost,
paidAmount
paidAmount,
budget
});
await this._createHistorySnapshot(order);
@@ -171,6 +178,7 @@ class MemberOrderService {
const nextStatus = payload?.status && ORDER_STATUSES.includes(payload.status) ? payload.status : order.status;
const nextCost = payload?.cost != null ? normalizeAmount(payload.cost) : normalizeAmount(order.cost);
const nextPaidAmount = payload?.paidAmount != null ? normalizeAmount(payload.paidAmount) : normalizeAmount(order.paidAmount);
const nextBudget = payload?.budget != null ? normalizeAmount(payload.budget) : normalizeAmount(order.budget);
if (nextItem && nextItem !== order.item) {
order.item = nextItem;
@@ -189,6 +197,10 @@ class MemberOrderService {
order.paidAmount = nextPaidAmount;
changed = true;
}
if (nextBudget !== normalizeAmount(order.budget)) {
order.budget = nextBudget;
changed = true;
}
if (!changed) {
const existing = await this.getMemberOrders(userToken, clubId, memberId);