extended possibilities to edit transaction

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-04-10 16:08:03 +02:00
parent 0c6e5850d2
commit 9d9e2ed50b
3 changed files with 45 additions and 14 deletions

View File

@@ -159,10 +159,12 @@ public class AccountingModule extends BaseHandler implements AccountingService {
var transaction = accountDb.loadTransaction(transactionId); var transaction = accountDb.loadTransaction(transactionId);
LOG.log(WARNING,"Missing permission check in patchTransaction(…)!"); LOG.log(WARNING,"Missing permission check in patchTransaction(…)!");
var json = json(ex); var json = json(ex);
if (json.has(Field.AMOUNT)) transaction.amount(json.getDouble(Field.AMOUNT));
if (json.has(Field.DATE)) transaction.date(LocalDate.parse(json.getString(Field.DATE))); if (json.has(Field.DATE)) transaction.date(LocalDate.parse(json.getString(Field.DATE)));
if (json.has(Field.DESTINATION)) transaction.destination(IdOrString.of(json.getString(Field.DESTINATION)));
if (json.has(Field.PURPOSE)) transaction.purpose(json.getString(Field.PURPOSE)); if (json.has(Field.PURPOSE)) transaction.purpose(json.getString(Field.PURPOSE));
accountDb.save(transaction); if (json.has(Field.SOURCE)) transaction.source(IdOrString.of(json.getString(Field.SOURCE)));
return sendContent(ex,transaction); return sendContent(ex,accountDb.save(transaction));
} }
private boolean postEntry(UmbrellaUser user, HttpExchange ex) throws IOException { private boolean postEntry(UmbrellaUser user, HttpExchange ex) throws IOException {

View File

@@ -42,6 +42,12 @@ public class Transaction implements Mappable {
return amount; return amount;
} }
public Transaction amount(double newVal){
amount = newVal;
dirtyFields.add(Field.AMOUNT);
return this;
}
public Transaction clearDirtyState(){ public Transaction clearDirtyState(){
dirtyFields.clear(); dirtyFields.clear();
return this; return this;
@@ -65,6 +71,12 @@ public class Transaction implements Mappable {
return destination; return destination;
} }
public Transaction destination(IdOrString newVal){
destination = newVal;
dirtyFields.add(Field.DESTINATION);
return this;
}
public long id(){ public long id(){
return id; return id;
} }
@@ -99,6 +111,12 @@ public class Transaction implements Mappable {
return source; return source;
} }
public Transaction source(IdOrString newVal){
source = newVal;
dirtyFields.add(Field.SOURCE);
return this;
}
public Set<String> tags(){ public Set<String> tags(){
return tags; return tags;
} }

View File

@@ -4,6 +4,25 @@
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
let { account, transaction, users } = $props(); let { account, transaction, users } = $props();
async function setAmount(amount){
return await update({amount});
}
async function setDate(date){
return await update({date});
}
async function setDestination(destination){
return await update({destination});
}
async function setPurpose(purpose){
return await update({purpose});
}
async function setSource(source){
return await update({source});
}
async function update(changes){ async function update(changes){
let url = api('accounting/transaction/'+transaction.id); let url = api('accounting/transaction/'+transaction.id);
let res = await patch(url,changes); let res = await patch(url,changes);
@@ -14,14 +33,6 @@
error(res); error(res);
return false; return false;
} }
async function setDate(date){
return await update({date});
}
async function setPurpose(purpose){
return await update({purpose});
}
</script> </script>
<tr> <tr>
@@ -31,19 +42,19 @@
{#each Object.entries(users) as [id,user]} {#each Object.entries(users) as [id,user]}
<td class="amount"> <td class="amount">
{#if id == transaction.source.id} {#if id == transaction.source.id}
{(-transaction.amount).toFixed(2)}&nbsp;{account.currency} -<LineEditor type="number" wrapper="span" editable="true" value={(+transaction.amount).toFixed(2)} onSet={setAmount} />&nbsp;{account.currency}
{/if} {/if}
{#if id == transaction.destination.id} {#if id == transaction.destination.id}
{(+transaction.amount).toFixed(2)}&nbsp;{account.currency} <LineEditor type="number" wrapper="span" editable="true" value={(+transaction.amount).toFixed(2)} onSet={setAmount} />&nbsp;{account.currency}
{/if} {/if}
</td> </td>
{/each} {/each}
<td class="party"> <td class="party">
{#if !transaction.source.id} {#if !transaction.source.id}
{transaction.source.value} <LineEditor wrapper="span" editable="true" value={transaction.source.value} onSet={setSource} />
{/if} {/if}
{#if !transaction.destination.id} {#if !transaction.destination.id}
{transaction.destination.value} <LineEditor wrapper="span" editable="true" value={transaction.destination.value} onSet={setDestination} />
{/if} {/if}
</td> </td>
<td class="purpose"> <td class="purpose">