Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 747f829ded | |||
| 9417c60346 | |||
| f8db846369 | |||
| dee494f7ca | |||
| a261d8eb9b | |||
| dbd84f193e | |||
| fa395b5a33 | |||
| 854cdded3d | |||
| 71309011a0 | |||
| 4ded399972 | |||
| 8392edf408 | |||
| 9c80e0d77c |
@@ -5,11 +5,14 @@ import de.srsoftware.umbrella.core.model.Account;
|
|||||||
import de.srsoftware.umbrella.core.model.Transaction;
|
import de.srsoftware.umbrella.core.model.Transaction;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AccountDb {
|
public interface AccountDb {
|
||||||
void dropTransactionTag(long transactionId, String tag);
|
void dropTransactionTag(long transactionId, String tag);
|
||||||
|
|
||||||
|
Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount);
|
||||||
|
|
||||||
Collection<Account> listAccounts(long userId);
|
Collection<Account> listAccounts(long userId);
|
||||||
|
|
||||||
Collection<String> listTags(long accountId, String source, String destination);
|
Collection<String> listTags(long accountId, String source, String destination);
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
|||||||
var head = path.pop();
|
var head = path.pop();
|
||||||
return switch (head) {
|
return switch (head) {
|
||||||
case null -> postEntry(user.get(),ex);
|
case null -> postEntry(user.get(),ex);
|
||||||
case DESTINATIONS -> postSearchDestinations(user.get(),ex);
|
case DESTINATIONS -> postSearchDestinations(user.get(),ex);
|
||||||
case PURPOSES -> postSearchPurposes(user.get(),ex);
|
case PURPOSES -> postSearchPurposes(user.get(),ex);
|
||||||
case SOURCES -> postSearchSources(user.get(),ex);
|
case SOURCES -> postSearchSources(user.get(),ex);
|
||||||
default -> {
|
default -> {
|
||||||
@@ -295,6 +295,22 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
|||||||
return sendContent(ex,newAccount != null ? newAccount : transaction);
|
return sendContent(ex,newAccount != null ? newAccount : transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean postGetLastTransaction(long accountId, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
|
var json = json(ex);
|
||||||
|
if (!json.has(Field.SOURCE)) throw missingField(Field.SOURCE);
|
||||||
|
if (!(json.get(Field.SOURCE) instanceof JSONObject src)) throw invalidField(Field.SOURCE,JSON);
|
||||||
|
var source = src.get(src.has(Field.ID) ? Field.ID : Field.DISPLAY).toString();
|
||||||
|
if (!json.has(Field.DESTINATION)) throw missingField(Field.DESTINATION);
|
||||||
|
if (!(json.get(Field.DESTINATION) instanceof JSONObject dst)) throw invalidField(Field.SOURCE,JSON);
|
||||||
|
var dest = dst.get(dst.has(Field.ID) ? Field.ID : Field.DISPLAY).toString();
|
||||||
|
if (!json.has(Field.AMOUNT)) throw missingField(Field.AMOUNT);
|
||||||
|
if (!(json.get(Field.AMOUNT) instanceof Number amt)) throw invalidField(Field.AMOUNT,Text.NUMBER);
|
||||||
|
var amount = amt.doubleValue();
|
||||||
|
|
||||||
|
var transaction = accountDb.lastTransaction(accountId, source, dest, amount);
|
||||||
|
return transaction.isPresent() ? sendContent(ex,transaction.get()) : notFound(ex);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean postSearchDestinations(UmbrellaUser user, HttpExchange ex) throws IOException {
|
public boolean postSearchDestinations(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
return sendContent(ex,searchOptions(user, Field.DESTINATION, body(ex)));
|
return sendContent(ex,searchOptions(user, Field.DESTINATION, body(ex)));
|
||||||
}
|
}
|
||||||
@@ -327,7 +343,9 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean postToAccount(long accountId, Path path, UmbrellaUser user, HttpExchange ex) throws IOException {
|
private boolean postToAccount(long accountId, Path path, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
return switch (path.pop()) {
|
var head = path.pop();
|
||||||
|
return switch (head) {
|
||||||
|
case PURPOSES -> postGetLastTransaction(accountId,user,ex);
|
||||||
case TAGS -> postSearchTags(accountId,user,ex);
|
case TAGS -> postSearchTags(accountId,user,ex);
|
||||||
case null, default -> super.doPost(path,ex);
|
case null, default -> super.doPost(path,ex);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package de.srsoftware.umbrella.accounting;
|
package de.srsoftware.umbrella.accounting;
|
||||||
|
|
||||||
import static de.srsoftware.tools.NotImplemented.notImplemented;
|
import static de.srsoftware.tools.NotImplemented.notImplemented;
|
||||||
|
import static de.srsoftware.tools.Optionals.nullable;
|
||||||
import static de.srsoftware.tools.jdbc.Condition.*;
|
import static de.srsoftware.tools.jdbc.Condition.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.*;
|
import static de.srsoftware.tools.jdbc.Query.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||||
@@ -130,6 +131,29 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount) {
|
||||||
|
try {
|
||||||
|
var rs = select(ALL).from(TABLE_TRANSACTIONS)
|
||||||
|
.where(ACCOUNT,equal(accountId)).where(SOURCE,equal(source)).where(DESTINATION,equal(dest)).where(AMOUNT,equal(amount))
|
||||||
|
.sort(ID+" DESC")
|
||||||
|
.limit(1)
|
||||||
|
.exec(db);
|
||||||
|
Transaction ta = null;
|
||||||
|
if (rs.next()) ta = Transaction.of(rs);
|
||||||
|
rs.close();
|
||||||
|
if (ta != null){
|
||||||
|
var tags = ta.tags();
|
||||||
|
rs = select(TAG).from(TABLE_TAGS_TRANSACTIONS).leftJoin(TAG_ID,TABLE_TAGS,ID).where(TRANSACTION_ID,equal(ta.id())).exec(db);
|
||||||
|
while (rs.next()) tags.add(rs.getString(1));
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
return nullable(ta);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw failedToSearchDb(t(Text.ACCOUNTING));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashSet<Account> listAccounts(long userId) {
|
public HashSet<Account> listAccounts(long userId) {
|
||||||
try {
|
try {
|
||||||
@@ -271,7 +295,7 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
|||||||
}
|
}
|
||||||
} else if (transaction.isDirty()) {
|
} else if (transaction.isDirty()) {
|
||||||
try {
|
try {
|
||||||
if (transaction.amount() == 0) {
|
if (transaction.amount() == 0 || transaction.source().isEmpty() || transaction.destination().isEmpty()) {
|
||||||
delete().from(TABLE_TRANSACTIONS).where(Field.ID, equal(transaction.id())).where(ACCOUNT, equal(transaction.accountId())).execute(db);
|
delete().from(TABLE_TRANSACTIONS).where(Field.ID, equal(transaction.id())).where(ACCOUNT, equal(transaction.accountId())).execute(db);
|
||||||
} else {
|
} else {
|
||||||
replaceInto(TABLE_TRANSACTIONS, Field.ID, Field.ACCOUNT, Field.TIMESTAMP, Field.SOURCE, Field.DESTINATION, Field.AMOUNT, Field.DESCRIPTION)
|
replaceInto(TABLE_TRANSACTIONS, Field.ID, Field.ACCOUNT, Field.TIMESTAMP, Field.SOURCE, Field.DESTINATION, Field.AMOUNT, Field.DESCRIPTION)
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import de.srsoftware.umbrella.core.constants.Field;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static de.srsoftware.tools.Optionals.isSet;
|
||||||
|
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||||
|
|
||||||
public class IdOrString implements Mappable {
|
public class IdOrString implements Mappable {
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String value;
|
private final String value;
|
||||||
@@ -52,6 +55,10 @@ public class IdOrString implements Mappable {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return id == null && !isSet(value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return value;
|
return value;
|
||||||
@@ -60,4 +67,4 @@ public class IdOrString implements Mappable {
|
|||||||
public String value(){
|
public String value(){
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<span class="autocomplete">
|
<span class="autocomplete">
|
||||||
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} />
|
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} {id} />
|
||||||
{#if candidates && candidates.length > 0}
|
{#if candidates && candidates.length > 0}
|
||||||
<ul bind:this={list_elem} class="suggestions">
|
<ul bind:this={list_elem} class="suggestions">
|
||||||
{#each candidates as candidate,i}
|
{#each candidates as candidate,i}
|
||||||
|
|||||||
@@ -155,5 +155,8 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<Display classes={{editable}} markdown={value} {onclick} {oncontextmenu} title={t('right_click_to_edit')} wrapper={type} />
|
<Display classes={{editable}} markdown={value} {onclick} {oncontextmenu} title={t('right_click_to_edit')} wrapper={type} />
|
||||||
|
{#if !value.display}
|
||||||
|
<button onclick={oncontextmenu}>{t('add_object',{object:t('content')})}</button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -42,7 +42,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function focusOnEnter(ev,id){
|
function focusOnEnter(ev,id){
|
||||||
if (ev.key == 'Enter') document.getElementById(id).focus();
|
if (ev.key == 'Enter') {
|
||||||
|
proposePurpose();
|
||||||
|
document.getElementById(id).focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAccountTags(text){
|
async function getAccountTags(text){
|
||||||
@@ -93,6 +96,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function proposePurpose(){
|
||||||
|
const source = entry.source;
|
||||||
|
const destination = entry.destination;
|
||||||
|
const amount = entry.amount;
|
||||||
|
const url = api(`accounting/${account.id}/purposes`);
|
||||||
|
const res = await post(url,{source,destination,amount});
|
||||||
|
if (res.ok) {
|
||||||
|
yikes();
|
||||||
|
var lastTransaction = await res.json();
|
||||||
|
entry.purpose = { display: lastTransaction.purpose};
|
||||||
|
entry.tags = lastTransaction.tags;
|
||||||
|
} else error(res);
|
||||||
|
}
|
||||||
|
|
||||||
async function save(){
|
async function save(){
|
||||||
let data = {
|
let data = {
|
||||||
...entry,
|
...entry,
|
||||||
|
|||||||
@@ -200,9 +200,10 @@
|
|||||||
<LineEditor bind:value={project.name} editable={true} onSet={val => update({name:val})} />
|
<LineEditor bind:value={project.name} editable={true} onSet={val => update({name:val})} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick={kanban}>{t('show_kanban')}</button>
|
{t('options')}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
<button onclick={kanban}><span class="symbol"></span> {t('show_kanban')}</button>
|
||||||
<button onclick={toggleSettings}><span class="symbol"></span> {t('settings')}</button>
|
<button onclick={toggleSettings}><span class="symbol"></span> {t('settings')}</button>
|
||||||
</div>
|
</div>
|
||||||
<div>{t('state')}</div>
|
<div>{t('state')}</div>
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import de.srsoftware.umbrella.core.BaseDb;
|
|||||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
public class SqliteDb extends BaseDb implements JournalDb{
|
public class SqliteDb extends BaseDb implements JournalDb{
|
||||||
public SqliteDb(Connection connection) {
|
public SqliteDb(Connection connection) {
|
||||||
@@ -33,13 +35,14 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
|||||||
var sql = """
|
var sql = """
|
||||||
CREATE TABLE IF NOT EXISTS {0} (
|
CREATE TABLE IF NOT EXISTS {0} (
|
||||||
{1} INTEGER PRIMARY KEY,
|
{1} INTEGER PRIMARY KEY,
|
||||||
{2} INTEGER,
|
{2} LONG NOT NULL,
|
||||||
{3} VARCHAR(255) NOT NULL,
|
{3} INTEGER,
|
||||||
{4} VARCHAR(16) NOT NULL,
|
{4} VARCHAR(255) NOT NULL,
|
||||||
{5} TEXT
|
{5} VARCHAR(16) NOT NULL,
|
||||||
|
{6} TEXT
|
||||||
);
|
);
|
||||||
""";
|
""";
|
||||||
sql = format(sql,TABLE_JOURNAL,ID,USER_ID,MODULE,ACTION,DESCRIPTION);
|
sql = format(sql,TABLE_JOURNAL,ID,TIMESTAMP,USER_ID,MODULE,ACTION,DESCRIPTION);
|
||||||
try {
|
try {
|
||||||
db.prepareStatement(sql).execute();
|
db.prepareStatement(sql).execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -50,8 +53,9 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
|||||||
@Override
|
@Override
|
||||||
public void logEvent(Event<?> event) {
|
public void logEvent(Event<?> event) {
|
||||||
try {
|
try {
|
||||||
insertInto(TABLE_JOURNAL,USER_ID,MODULE,ACTION,DESCRIPTION)
|
var timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
|
||||||
.values(event.initiator().id(), event.module(), event.eventType(), event.describe())
|
insertInto(TABLE_JOURNAL,TIMESTAMP,USER_ID,MODULE,ACTION,DESCRIPTION)
|
||||||
|
.values(timestamp,event.initiator().id(), event.module(), event.eventType(), event.describe())
|
||||||
.execute(db).close();
|
.execute(db).close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw databaseException(ERROR_WRITE_EVENT,event.eventType(),event.initiator().name());
|
throw databaseException(ERROR_WRITE_EVENT,event.eventType(),event.initiator().name());
|
||||||
|
|||||||
@@ -192,6 +192,8 @@
|
|||||||
"items": "Artikel",
|
"items": "Artikel",
|
||||||
|
|
||||||
"join_objects" : "{objects} zusammenführen",
|
"join_objects" : "{objects} zusammenführen",
|
||||||
|
|
||||||
|
"kanban": "Kanban",
|
||||||
"key": "Suchbegriff",
|
"key": "Suchbegriff",
|
||||||
|
|
||||||
"language": "Sprache",
|
"language": "Sprache",
|
||||||
@@ -307,6 +309,7 @@
|
|||||||
"project ({id})": "Projekt ({id})",
|
"project ({id})": "Projekt ({id})",
|
||||||
"Project '{project}' was edited": "Projekt '{project}' wurde bearbeitet",
|
"Project '{project}' was edited": "Projekt '{project}' wurde bearbeitet",
|
||||||
"projects": "Projekte",
|
"projects": "Projekte",
|
||||||
|
"Projects": "Projekte",
|
||||||
"properties": "Eigenschaften",
|
"properties": "Eigenschaften",
|
||||||
"property": "Eigenschaft",
|
"property": "Eigenschaft",
|
||||||
"purpose": "Zweck",
|
"purpose": "Zweck",
|
||||||
|
|||||||
@@ -192,6 +192,8 @@
|
|||||||
"items": "items",
|
"items": "items",
|
||||||
|
|
||||||
"join_objects" : "join {objects}",
|
"join_objects" : "join {objects}",
|
||||||
|
|
||||||
|
"kanban": "Kanban",
|
||||||
"key": "search term",
|
"key": "search term",
|
||||||
|
|
||||||
"language": "language",
|
"language": "language",
|
||||||
@@ -307,6 +309,7 @@
|
|||||||
"project ({id})": "project ({id})",
|
"project ({id})": "project ({id})",
|
||||||
"Project '{project}' was edited": "Project '{project}' was edited",
|
"Project '{project}' was edited": "Project '{project}' was edited",
|
||||||
"projects": "projects",
|
"projects": "projects",
|
||||||
|
"Projects": "projects",
|
||||||
"properties": "properties",
|
"properties": "properties",
|
||||||
"property": "property",
|
"property": "property",
|
||||||
"purpose": "purpose",
|
"purpose": "purpose",
|
||||||
|
|||||||
Reference in New Issue
Block a user