extended possibilities to edit transaction
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -159,10 +159,12 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
var transaction = accountDb.loadTransaction(transactionId);
|
||||
LOG.log(WARNING,"Missing permission check in patchTransaction(…)!");
|
||||
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.DESTINATION)) transaction.destination(IdOrString.of(json.getString(Field.DESTINATION)));
|
||||
if (json.has(Field.PURPOSE)) transaction.purpose(json.getString(Field.PURPOSE));
|
||||
accountDb.save(transaction);
|
||||
return sendContent(ex,transaction);
|
||||
if (json.has(Field.SOURCE)) transaction.source(IdOrString.of(json.getString(Field.SOURCE)));
|
||||
return sendContent(ex,accountDb.save(transaction));
|
||||
}
|
||||
|
||||
private boolean postEntry(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
|
||||
@@ -42,6 +42,12 @@ public class Transaction implements Mappable {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Transaction amount(double newVal){
|
||||
amount = newVal;
|
||||
dirtyFields.add(Field.AMOUNT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Transaction clearDirtyState(){
|
||||
dirtyFields.clear();
|
||||
return this;
|
||||
@@ -65,6 +71,12 @@ public class Transaction implements Mappable {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public Transaction destination(IdOrString newVal){
|
||||
destination = newVal;
|
||||
dirtyFields.add(Field.DESTINATION);
|
||||
return this;
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
@@ -99,6 +111,12 @@ public class Transaction implements Mappable {
|
||||
return source;
|
||||
}
|
||||
|
||||
public Transaction source(IdOrString newVal){
|
||||
source = newVal;
|
||||
dirtyFields.add(Field.SOURCE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<String> tags(){
|
||||
return tags;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,25 @@
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
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){
|
||||
let url = api('accounting/transaction/'+transaction.id);
|
||||
let res = await patch(url,changes);
|
||||
@@ -14,14 +33,6 @@
|
||||
error(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function setDate(date){
|
||||
return await update({date});
|
||||
}
|
||||
|
||||
async function setPurpose(purpose){
|
||||
return await update({purpose});
|
||||
}
|
||||
</script>
|
||||
|
||||
<tr>
|
||||
@@ -31,19 +42,19 @@
|
||||
{#each Object.entries(users) as [id,user]}
|
||||
<td class="amount">
|
||||
{#if id == transaction.source.id}
|
||||
{(-transaction.amount).toFixed(2)} {account.currency}
|
||||
-<LineEditor type="number" wrapper="span" editable="true" value={(+transaction.amount).toFixed(2)} onSet={setAmount} /> {account.currency}
|
||||
{/if}
|
||||
{#if id == transaction.destination.id}
|
||||
{(+transaction.amount).toFixed(2)} {account.currency}
|
||||
<LineEditor type="number" wrapper="span" editable="true" value={(+transaction.amount).toFixed(2)} onSet={setAmount} /> {account.currency}
|
||||
{/if}
|
||||
</td>
|
||||
{/each}
|
||||
<td class="party">
|
||||
{#if !transaction.source.id}
|
||||
← {transaction.source.value}
|
||||
← <LineEditor wrapper="span" editable="true" value={transaction.source.value} onSet={setSource} />
|
||||
{/if}
|
||||
{#if !transaction.destination.id}
|
||||
→ {transaction.destination.value}
|
||||
→ <LineEditor wrapper="span" editable="true" value={transaction.destination.value} onSet={setDestination} />
|
||||
{/if}
|
||||
</td>
|
||||
<td class="purpose">
|
||||
|
||||
Reference in New Issue
Block a user