first working version where transactions can be stored

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-04-03 00:52:13 +02:00
parent d4aaa24aaa
commit a933ced8d8
9 changed files with 155 additions and 89 deletions

View File

@@ -4,18 +4,23 @@
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
let { id } = $props();
let account = $state(null);
import EntryForm from './add_entry.svelte';
let { id } = $props();
let account = $state(null);
let transactions = [];
let users = {};
async function load(){
let url = api(`accounting/${id}`);
let res = await get(url);
if (res.ok) {
yikes();
let json = await res.json();
let json = await res.json();
transactions = json.transactions;
account = json.account;
users = json.user_list;
account = json.account;
console.log(users);
} else error(res);
}
@@ -28,9 +33,10 @@
<thead>
<tr>
<th>{t('date')}</th>
<th>{t('source')}</th>
<th>{t('destination')}</th>
<th>{t('amount')}</th>
{#each Object.entries(users) as [id,user]}
<th>{user.name}</th>
{/each}
<th>{t('other party')}</th>
<th>{t('purpose')}</th>
</tr>
</thead>
@@ -38,13 +44,30 @@
{#each transactions as transaction, i}
<tr>
<td>{transaction.date}</td>
<td>{transaction.source}</td>
<td>{transaction.destination}</td>
<td>{transaction.amount} {account.currency}</td>
{#each Object.entries(users) as [id,user]}
<td>
{#if id == transaction.source.id}
{-transaction.amount} {account.currency}
{/if}
{#if id == transaction.destination.id}
{transaction.amount} {account.currency}
{/if}
</td>
{/each}
<td>
{#if !transaction.source.id}
{transaction.source.value}
{/if}
{#if !transaction.destination.id}
{transaction.destination.value}
{/if}
</td>
<td>{transaction.purpose}</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>
<EntryForm {account} />
{/if}

View File

@@ -7,18 +7,19 @@
import { user } from '../../user.svelte';
import Autocomplete from '../../Components/Autocomplete.svelte';
let { new_account = false } = $props();
let defaultAccount = {
id : 0,
name : '',
currency : ''
};
let { account = defaultAccount, new_account = false } = $props();
let entry = $state({
account : {
id : 0,
name : '',
currency : ''
},
account,
date : new Date().toISOString().substring(0, 10),
source : {
display: user.name,
user_id: user.id
id: user.id
},
destination : {},
amount : 0.0,
@@ -26,6 +27,19 @@
});
let router = useTinyRouter();
async function getUsers(text){
var url = api('user/search');
var res = await post(url,text);
if (res.ok){
yikes();
const input = await res.json();
return Object.values(input).map(user => { return {...user, display: user.name}});
} else {
error(res);
return {};
}
}
async function save(){
let data = {
...entry,
@@ -68,10 +82,10 @@
<input type="date" value={entry.date} />
<span>{t('source')}</span>
<Autocomplete bind:candidate={entry.source} />
<Autocomplete bind:candidate={entry.source} getCandidates={getUsers} />
<span>{t('destination')}</span>
<Autocomplete bind:candidate={entry.destination} />
<Autocomplete bind:candidate={entry.destination} getCandidates={getUsers} />
<span>{t('amount')}</span>
<span>

View File

@@ -1,5 +1,5 @@
<script>
import {api} from '../../urls.svelte'
import {api, post} from '../../urls.svelte'
import { error, yikes } from '../../warn.svelte';
import {t} from '../../translations.svelte';
@@ -14,11 +14,7 @@
async function getCandidates(text){
const url = api('user/search');
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : text
});
const resp = await post(url,text);
if (resp.ok){
yikes();
const input = await resp.json();

View File

@@ -35,7 +35,7 @@ export function post(url,data){
return fetch(url,{
credentials : 'include',
method : 'POST',
body : JSON.stringify(data)
body : typeof data === 'string' ? data : JSON.stringify(data)
});
}