Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 747f829ded | |||
| 4ded399972 | |||
| 8392edf408 | |||
| 9c80e0d77c |
@@ -53,10 +53,8 @@ jobs:
|
||||
run: |
|
||||
TAGS="$(curl -s -u "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASS }}" https://${{ secrets.REGISTRY_PATH }}/v2/umbrella/tags/list | jq -r ".tags[]")"
|
||||
COUNT=$(echo "$TAGS" | wc -l)
|
||||
echo found $COUNT tags: $TAGS
|
||||
if [ $COUNT -gt 10 ]; then
|
||||
REMAIN=$((COUNT - 10))
|
||||
echo $REMAIN tags will be kept!
|
||||
echo "$TAGS" | head -n $REMAIN > /tmp/old_tags
|
||||
else
|
||||
echo less than 10 tags, skipping cleanup
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
description = "Umbrella : Accounting"
|
||||
|
||||
dependencies{
|
||||
implementation(project(":bus"))
|
||||
implementation(project(":core"))
|
||||
}
|
||||
@@ -3,19 +3,14 @@ package de.srsoftware.umbrella.accounting;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Account;
|
||||
import de.srsoftware.umbrella.core.model.Transaction;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface AccountDb {
|
||||
Transaction dropTransaction(Transaction transaction);
|
||||
|
||||
void dropTransactionTag(long transactionId, String tag);
|
||||
|
||||
Collection<UmbrellaUser> getMembers(long accountId);
|
||||
|
||||
Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount);
|
||||
|
||||
Collection<Account> listAccounts(long userId);
|
||||
|
||||
@@ -6,10 +6,11 @@ import static de.srsoftware.umbrella.accounting.Constants.CONFIG_DATABASE;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.tagService;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.CREATE;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
@@ -22,8 +23,6 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import de.srsoftware.umbrella.messagebus.events.TransactionEvent;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -53,7 +52,6 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
case TRANSACTION -> {
|
||||
try {
|
||||
var transaction = accountDb.loadTransaction(Long.parseLong(path.pop()));
|
||||
if (!accountDb.getMembers(transaction.accountId()).contains(user.get())) throw forbidden("You are not allowed to access account {id}",Field.ID,transaction.accountId());
|
||||
yield dropTransaction(transaction, user.get(), path, ex);
|
||||
} catch (NumberFormatException ignored) {
|
||||
yield super.doDelete(path,ex);
|
||||
@@ -127,7 +125,6 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
default -> {
|
||||
try {
|
||||
var accountId = Long.parseLong(head);
|
||||
if (!accountDb.getMembers(accountId).contains(user.get())) throw forbidden("You are not allowed to access account {id}",Field.ID,accountId);
|
||||
yield postToAccount(accountId,path,user.get(),ex);
|
||||
} catch (NumberFormatException ignored) {
|
||||
yield super.doPost(path,ex);
|
||||
@@ -140,22 +137,16 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dropTransaction(Transaction transaction, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var dropped = accountDb.dropTransaction(transaction);
|
||||
messageBus().dispatch(new TransactionEvent(user,dropped,Event.EventType.DELETE));
|
||||
return sendContent(ex,dropped);
|
||||
}
|
||||
|
||||
public boolean dropTransaction(Transaction transaction, UmbrellaUser user, Path path, HttpExchange ex) throws IOException {
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
case TAG -> dropTransactionTag(user,transaction,ex);
|
||||
case null -> dropTransaction(transaction,user,ex);
|
||||
default -> super.doDelete(path,ex);
|
||||
case null, default -> super.doDelete(path,ex);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean dropTransactionTag(UmbrellaUser user, Transaction transaction, HttpExchange ex) throws IOException {
|
||||
LOG.log(WARNING,"Missing permission check in AccountModule.dropTransactionTag!");
|
||||
var json = json(ex);
|
||||
if (!json.has(Field.TAG)) throw missingField(Field.TAG);
|
||||
var tag = json.getString(Field.TAG);
|
||||
@@ -185,15 +176,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
}
|
||||
|
||||
private boolean getAccount(UmbrellaUser user, long accountId, HttpExchange ex) throws IOException {
|
||||
if (!accountDb.getMembers(accountId).contains(user)) throw forbidden("You are not allowed to access account {id}",Field.ID,accountId);
|
||||
return sendContent(ex, loadAccount(accountId));
|
||||
}
|
||||
|
||||
private boolean getAccounts(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
return sendContent(ex,accountDb.listAccounts(user.id()).stream().map(Account::toMap));
|
||||
}
|
||||
|
||||
public AccountData loadAccount(long accountId){
|
||||
LOG.log(WARNING,"Missing authorization check in AccountingModule.getAccount(…)!");
|
||||
var account = accountDb.loadAccount(accountId);
|
||||
var transactions = accountDb.loadTransactions(account);
|
||||
var userMap = new HashMap<Long,UmbrellaUser>();
|
||||
@@ -210,9 +193,20 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
if (!userMap.containsKey(userId)) userMap.put(destination.id(),userService().loadUser(userId));
|
||||
}
|
||||
}
|
||||
return AccountData.of(account, transactions, userMap);
|
||||
|
||||
return sendContent(ex, Map.of(
|
||||
Field.ACCOUNT,account.toMap(),
|
||||
Field.TRANSACTIONS,transactions.stream().map(Transaction::toMap).toList(),
|
||||
Field.USER_LIST,mapValues(userMap)
|
||||
));
|
||||
}
|
||||
|
||||
private boolean getAccounts(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
return sendContent(ex,accountDb.listAccounts(user.id()).stream().map(Account::toMap));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static boolean noNumbers(String s){
|
||||
try {
|
||||
Long.parseLong(s);
|
||||
@@ -224,8 +218,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
|
||||
private boolean patchTransaction(UmbrellaUser user, long transactionId, HttpExchange ex) throws IOException {
|
||||
var transaction = accountDb.loadTransaction(transactionId);
|
||||
if (!accountDb.getMembers(transaction.accountId()).contains(user)) throw forbidden("You are not allowed to access account {id}",Field.ID,transaction.accountId());
|
||||
var oldData = transaction.toMap();
|
||||
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)));
|
||||
@@ -233,9 +226,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
if (json.has(Field.PURPOSE)) transaction.purpose(json.getString(Field.PURPOSE));
|
||||
if (json.has(Field.SOURCE)) transaction.source(IdOrString.of(json.getString(Field.SOURCE)));
|
||||
if (json.has(Field.TAG)) transaction.tags().add(json.getString(Field.TAG));
|
||||
var patched = accountDb.save(transaction);
|
||||
messageBus().dispatch(new TransactionEvent(user,patched,oldData));
|
||||
return sendContent(ex,patched);
|
||||
return sendContent(ex,accountDb.save(transaction));
|
||||
}
|
||||
|
||||
private boolean postEntry(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
@@ -300,7 +291,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
|
||||
|
||||
var transaction = accountDb.save(new Transaction(0,accountId,dateTime,source,destination,amount.doubleValue(),purpose,tags));
|
||||
messageBus().dispatch(new TransactionEvent(user,transaction, CREATE));
|
||||
|
||||
return sendContent(ex,newAccount != null ? newAccount : transaction);
|
||||
}
|
||||
|
||||
@@ -336,6 +327,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
}
|
||||
|
||||
private boolean postSearchTags(long accountId, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
LOG.log(WARNING,"Missing authorization check in AccountingModule.getAccount(…)!");
|
||||
var key = body(ex);
|
||||
if (!key.trim().startsWith("{")) { // search tags that contain value of body
|
||||
var tags = accountDb.searchTagsContaining(key, accountId);
|
||||
|
||||
@@ -7,7 +7,6 @@ import static de.srsoftware.tools.jdbc.Condition.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.accounting.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
@@ -20,7 +19,6 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.model.Account;
|
||||
import de.srsoftware.umbrella.core.model.Transaction;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -119,21 +117,6 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
||||
}
|
||||
}
|
||||
|
||||
public Transaction dropTransaction(Transaction transaction){
|
||||
try {
|
||||
db.setAutoCommit(false);
|
||||
Query.delete().from(TABLE_TAGS_TRANSACTIONS).where(TRANSACTION_ID,equal(transaction.id())).execute(db);
|
||||
Query.delete().from(TABLE_TRANSACTIONS).where(ID,equal(transaction.id())).execute(db);
|
||||
db.setAutoCommit(true);
|
||||
return transaction;
|
||||
} catch (SQLException e){
|
||||
try {
|
||||
db.rollback();
|
||||
} catch (SQLException ignored){};
|
||||
throw failedToDropObject(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropTransactionTag(long transactionId, String tag) {
|
||||
try {
|
||||
@@ -148,27 +131,6 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<UmbrellaUser> getMembers(long accountId) {
|
||||
try {
|
||||
var userIds = new HashSet<Long>();
|
||||
var rs = select("DISTINCT "+ SOURCE).from(TABLE_TRANSACTIONS).where(ACCOUNT,equal(accountId)).exec(db);
|
||||
while (rs.next()) try {
|
||||
userIds.add(Long.parseLong(rs.getString(1)));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
rs.close();
|
||||
rs = select("DISTINCT "+ DESTINATION).from(TABLE_TRANSACTIONS).where(ACCOUNT,equal(accountId)).exec(db);
|
||||
while (rs.next()) try {
|
||||
userIds.add(Long.parseLong(rs.getString(1)));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
rs.close();
|
||||
var us = userService();
|
||||
return userIds.stream().map(us::loadUser).toList();
|
||||
} catch (SQLException e) {
|
||||
throw failedToLoadMembers(Text.ACCOUNT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount) {
|
||||
try {
|
||||
@@ -333,9 +295,13 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
||||
}
|
||||
} else if (transaction.isDirty()) {
|
||||
try {
|
||||
replaceInto(TABLE_TRANSACTIONS, Field.ID, Field.ACCOUNT, Field.TIMESTAMP, Field.SOURCE, Field.DESTINATION, Field.AMOUNT, Field.DESCRIPTION)
|
||||
.values(transaction.id(), transaction.accountId(), timestamp, transaction.source().value(), transaction.destination().value(), transaction.amount(), transaction.purpose())
|
||||
.execute(db).close();
|
||||
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);
|
||||
} else {
|
||||
replaceInto(TABLE_TRANSACTIONS, Field.ID, Field.ACCOUNT, Field.TIMESTAMP, Field.SOURCE, Field.DESTINATION, Field.AMOUNT, Field.DESCRIPTION)
|
||||
.values(transaction.id(), transaction.accountId(), timestamp, transaction.source().value(), transaction.destination().value(), transaction.amount(), transaction.purpose())
|
||||
.execute(db).close();
|
||||
}
|
||||
return transaction.clearDirtyState();
|
||||
} catch (SQLException e) {
|
||||
throw failedToStoreObject(transaction);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class MessageApi extends BaseHandler{
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEvent(PrintWriter out, Event<?> event) {
|
||||
private void sendEvent(PrintWriter out, Event event) {
|
||||
if (event == null) return;
|
||||
out.print("event: ");
|
||||
out.println(event.eventType());
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.accountingService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Module;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.model.Transaction;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransactionEvent extends Event<Transaction> {
|
||||
private Collection<UmbrellaUser> audience;
|
||||
|
||||
public TransactionEvent(UmbrellaUser initiator, Transaction transaction, EventType type) {
|
||||
super(initiator, Module.ACCOUNTING, transaction, type);
|
||||
audience = null;
|
||||
}
|
||||
|
||||
public TransactionEvent(UmbrellaUser initiator, Transaction transaction, Map<String, Object> oldData){
|
||||
super(initiator,Module.ACCOUNTING,transaction,oldData);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<UmbrellaUser> audience() {
|
||||
if (audience == null) audience = accountingService().loadAccount(payload().accountId()).userMap().values();
|
||||
return audience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable describe() {
|
||||
var user = initiator().name();
|
||||
var type = t(Text.TRANSACTION);
|
||||
var entity = payload().purpose();
|
||||
return switch (eventType()){
|
||||
case CREATE -> describeDetail();
|
||||
case DELETE -> describeDetail();
|
||||
case UPDATE -> describeUpdate();
|
||||
case null, default -> t("TODO"); // TODO
|
||||
};
|
||||
}
|
||||
|
||||
private Translatable describeUpdate() {
|
||||
var head = t("Changes in {type} '{entity}':\n\n{body}",Field.TYPE,t(Text.TRANSACTION),Field.ENTITY,oldData().get(PURPOSE),BODY,diff().orElse(""));
|
||||
return t("{head}\n\n{link}","head",head,"link",link());
|
||||
}
|
||||
|
||||
private Translatable describeDetail(){
|
||||
var tr = payload();
|
||||
|
||||
var message = "{source}: {source_name}\n{destination}: {dest_name}\n{amount}: {value}\n{purpose}: {purpose_val}\n\n{link}";
|
||||
return t(message,SOURCE,t(Text.SOURCE), "source_name",tr.source(), DESTINATION,t(Text.DESTINATION),"dest_name",tr.destination(), AMOUNT,t(Text.AMOUNT), VALUE,tr.amount(), PURPOSE,t(Text.PURPOSE),"purpose_val",tr.purpose(),"link",link());
|
||||
}
|
||||
|
||||
private Translatable link() {
|
||||
return t("You can view/edit this transaction at {base_url}/account/{id}", ID, payload().accountId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translatable subject() {
|
||||
var user = initiator().name();
|
||||
var entity = payload().purpose();
|
||||
return switch (eventType()){
|
||||
case CREATE -> t("{user} added a new transaction: {entity}", USER,user, ENTITY, entity);
|
||||
case DELETE -> t("The transaction '{entity}' has been deleted by {user}",Field.ENTITY, entity, USER, user);
|
||||
case UPDATE -> t("{user} updated the transaction '{entity}'", USER,user, ENTITY, oldData().get(PURPOSE));
|
||||
case null, default -> t("TODO"); // TODO
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -53,10 +53,6 @@ public class ModuleRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public static AccountingService accountingService() {
|
||||
return singleton.accountingService;
|
||||
}
|
||||
|
||||
public static BookmarkService bookmarkService(){
|
||||
return singleton.bookmarkService;
|
||||
}
|
||||
|
||||
@@ -1,32 +1,5 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.api;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.Account;
|
||||
import de.srsoftware.umbrella.core.model.Transaction;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AccountingService {
|
||||
public record AccountData(Account account, List<Transaction> transactions, HashMap<Long, UmbrellaUser> userMap) implements Mappable {
|
||||
public static AccountData of(Account account, List<Transaction> transactions, HashMap<Long, UmbrellaUser> userMap) {
|
||||
return new AccountData(account, transactions, userMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(
|
||||
Field.ACCOUNT,account.toMap(),
|
||||
Field.TRANSACTIONS,transactions.stream().map(Transaction::toMap).toList(),
|
||||
Field.USER_LIST,mapValues(userMap)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AccountData loadAccount(long accountId);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ public class Field {
|
||||
public static final String EDITOR = "editor";
|
||||
public static final String EMAIL = "email";
|
||||
public static final String END_TIME = "end_time";
|
||||
public static final String ENTITY = "entity";
|
||||
public static final String ENTITY_ID = "entity_id";
|
||||
public static final String EST_TIME = "est_time";
|
||||
public static final String EVALUATION = "evaluation";
|
||||
|
||||
@@ -7,7 +7,6 @@ package de.srsoftware.umbrella.core.constants;
|
||||
public class Text {
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String ACCOUNTING = "accounting";
|
||||
public static final String AMOUNT = "amount";
|
||||
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String BOOKMARKS = "bookmarks";
|
||||
@@ -22,7 +21,6 @@ public class Text {
|
||||
public static final String CUSTOMER = "customer";
|
||||
public static final String CUSTOMER_SETTINGS = "customer settings";
|
||||
|
||||
public static final String DESTINATION = "destination";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENTS = "documents";
|
||||
public static final String DOCUMENT_TYPE_ID = "document type id";
|
||||
@@ -62,7 +60,6 @@ public class Text {
|
||||
public static final String PROJECT_WITH_ID = "project ({id})";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
public static final String PURPOSE = "purpose";
|
||||
|
||||
public static final String RECEIVER = "receiver";
|
||||
public static final String RECEIVERS = "receivers";
|
||||
@@ -72,7 +69,6 @@ public class Text {
|
||||
public static final String SERVICE_WITH_ID = "service ({id})";
|
||||
public static final String SESSION = "session";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String STOCK = "stock";
|
||||
public static final String STRING = "string";
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.isSet;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.isSet;
|
||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||
|
||||
public class IdOrString implements Mappable {
|
||||
private final Long id;
|
||||
private final String value;
|
||||
|
||||
@@ -16,7 +16,6 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.AMOUNT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.CUSTOMER;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.DOCUMENT;
|
||||
|
||||
@@ -9,7 +9,6 @@ import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.translator;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.FALLBACK_LANG;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.AMOUNT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.CUSTOMER;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.NUMBER;
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
color: orange;
|
||||
border: 1px solid orange;
|
||||
border-radius: 5px;
|
||||
z-index: 65;
|
||||
z-index: 50;
|
||||
list-style: none;
|
||||
padding: 4px;
|
||||
margin: 0;
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
{/if}
|
||||
{:else}
|
||||
<Display classes={{editable}} markdown={value} {onclick} {oncontextmenu} title={t('right_click_to_edit')} wrapper={type} />
|
||||
{#if !value.rendered}
|
||||
{#if !value.display}
|
||||
<button onclick={oncontextmenu}>{t('add_object',{object:t('content')})}</button>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { api, eventStream, get } from '../../urls.svelte';
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
let { id } = $props();
|
||||
let account = $state(null);
|
||||
let eventSource = null;
|
||||
let filter = $state([]);
|
||||
let transactions = $state([]);
|
||||
let filtered = $derived(transactions.filter(t => checker(t.tags,filter)));
|
||||
@@ -28,6 +27,7 @@
|
||||
if (!transaction.destination.id) sums[0] += transaction.amount;
|
||||
if (!transaction.source.id) sums[0] -= transaction.amount;
|
||||
}
|
||||
window.setTimeout(scrollToBottom,100);
|
||||
return sums;
|
||||
}
|
||||
|
||||
@@ -50,30 +50,6 @@
|
||||
filter = filter.filter(x => x != tag.toLowerCase());
|
||||
}
|
||||
|
||||
function handleCreateEvent(evt){
|
||||
const event_data = JSON.parse(evt.data);
|
||||
const new_transaction = event_data.transaction;
|
||||
transactions.push(new_transaction);
|
||||
window.setTimeout(scrollToBottom,100);
|
||||
}
|
||||
|
||||
function handleDeleteEvent(evt){
|
||||
const event_data = JSON.parse(evt.data);
|
||||
transactions = transactions.filter(t => t.id != event_data.transaction.id);
|
||||
}
|
||||
|
||||
function handleUpdateEvent(evt){
|
||||
const event_data = JSON.parse(evt.data);
|
||||
const updated_transaction = event_data.transaction;
|
||||
for (var idx in transactions){
|
||||
if (transactions[idx].id == updated_transaction.id) {
|
||||
updated_transaction.tags = transactions[idx].tags;
|
||||
transactions[idx] = updated_transaction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function load(){
|
||||
let url = api(`accounting/${id}`);
|
||||
let res = await get(url);
|
||||
@@ -83,15 +59,11 @@
|
||||
transactions = json.transactions;
|
||||
users = json.user_list;
|
||||
account = json.account;
|
||||
try {
|
||||
eventSource = eventStream(handleCreateEvent,handleUpdateEvent,handleDeleteEvent);
|
||||
} catch (ignored) {}
|
||||
window.setTimeout(scrollToBottom,100);
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
function onSave(){
|
||||
// load();
|
||||
load();
|
||||
}
|
||||
|
||||
function scrollToBottom(){
|
||||
@@ -135,7 +107,6 @@
|
||||
<th>{t('other party')}</th>
|
||||
<th>{t('purpose')}</th>
|
||||
<th>{t('tags')}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -157,7 +128,7 @@
|
||||
<br/>
|
||||
{sums[0].toFixed(2)} {account.currency}
|
||||
</td>
|
||||
<td colspan="3"></td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -8,16 +8,6 @@
|
||||
let { account, addToFilter = tag => {}, transaction, users } = $props();
|
||||
let hidden = $state(false);
|
||||
|
||||
function deleteTransaction(ev){
|
||||
if (confirm(t('confirm_delete',{element:transaction.purpose}))){
|
||||
const url = api(`accounting/transaction/${transaction.id}`);
|
||||
const res = drop(url);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
} else error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async function dropTag(tag){
|
||||
var url = api(`accounting/transaction/${transaction.id}/tag`)
|
||||
var res = await drop(url,{tag});
|
||||
@@ -137,8 +127,5 @@
|
||||
<Autocomplete {getCandidates} {onCommit} />
|
||||
</span>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<button class="symbol" onclick={deleteTransaction}></button>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
@@ -13,6 +13,8 @@ import de.srsoftware.umbrella.core.BaseDb;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
public class SqliteDb extends BaseDb implements JournalDb{
|
||||
public SqliteDb(Connection connection) {
|
||||
@@ -33,13 +35,14 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
||||
var sql = """
|
||||
CREATE TABLE IF NOT EXISTS {0} (
|
||||
{1} INTEGER PRIMARY KEY,
|
||||
{2} INTEGER,
|
||||
{3} VARCHAR(255) NOT NULL,
|
||||
{4} VARCHAR(16) NOT NULL,
|
||||
{5} TEXT
|
||||
{2} LONG NOT NULL,
|
||||
{3} INTEGER,
|
||||
{4} VARCHAR(255) NOT NULL,
|
||||
{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 {
|
||||
db.prepareStatement(sql).execute();
|
||||
} catch (SQLException e) {
|
||||
@@ -50,8 +53,9 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
||||
@Override
|
||||
public void logEvent(Event<?> event) {
|
||||
try {
|
||||
insertInto(TABLE_JOURNAL,USER_ID,MODULE,ACTION,DESCRIPTION)
|
||||
.values(event.initiator().id(), event.module(), event.eventType(), event.describe())
|
||||
var timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
|
||||
insertInto(TABLE_JOURNAL,TIMESTAMP,USER_ID,MODULE,ACTION,DESCRIPTION)
|
||||
.values(timestamp,event.initiator().id(), event.module(), event.eventType(), event.describe())
|
||||
.execute(db).close();
|
||||
} catch (SQLException e) {
|
||||
throw databaseException(ERROR_WRITE_EVENT,event.eventType(),event.initiator().name());
|
||||
|
||||
@@ -7,7 +7,6 @@ import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.PERMISSION;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.SETTINGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.SOURCE;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TAGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.PROJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.*;
|
||||
|
||||
@@ -397,7 +397,6 @@
|
||||
"The task '{task}' has been created": "Die Aufgabe '{task}' wurde angelegt",
|
||||
"The task '{task}' has been deleted": "Die Aufgabe '{task}' wurde gelöscht",
|
||||
"The task '{task}' has been deleted by {user}": "Die Aufgabe '{task}' wurde von {user} gelöscht",
|
||||
"The transaction '{entity}' has been deleted by {user}": "Der Umsatz „{entity}“ wurde von {user} gelöscht",
|
||||
"The wiki page '{name}' has been created": "Die Wiki-Seite „{name}“ wurde angelegt",
|
||||
"The wiki page '{name}' has been deleted": "Die Wiki-Seite „{name}“ wurde gelöscht.",
|
||||
"The wiki page '{page}' has been deleted by {user}": "Die Wiki-Seite „{page}“ wurde durch {user} gelöscht.",
|
||||
@@ -429,8 +428,6 @@
|
||||
"upload_file": "Datei hochladen",
|
||||
"user": "Benutzer",
|
||||
"user ({id})": "Benutzer ({id})",
|
||||
"{user} added a new transaction: {entity}": "{user} hat einen neuen Umsatz hinzugefügt: {entity}",
|
||||
"{user} updated the transaction '{entity}'": "{user} hat den Umsatz „{entity}“ aktualisiert",
|
||||
"user_list": "Benutzer-Liste",
|
||||
"user_module" : "Umbrella User-Verwaltung",
|
||||
"user profile": "Benutzer-Profil",
|
||||
@@ -458,7 +455,6 @@
|
||||
"wiki_pages": "Wiki-Seiten",
|
||||
|
||||
"year": "Jahr",
|
||||
"You can view/edit this transaction at {base_url}/account/{id}": "Du kannst diese transaktion unter {base_url}/account/{id} ansehen",
|
||||
"You can view/edit this project at {base_url}/project/{id}/view": "Du kannst dieses Projekt unter {base_url}/project/{id}/view ansehen/bearbeiten.",
|
||||
"You can view/edit this task at {base_url}/task/{id}/view": "Du kannst diese Aufgabe unter {base_url}/task/{id}/view ansehen/bearbeiten.",
|
||||
"You can view/edit this wiki page at {base_url}/wiki/{id}/view": "Du kannst diese Wiki-Seite unter {base_url}/wiki/{id}/view ansehen/bearbeiten.",
|
||||
|
||||
@@ -397,7 +397,6 @@
|
||||
"The task '{task}' has been created": "The task '{task}' has been created",
|
||||
"The task '{task}' has been deleted": "The task '{task}' has been deleted",
|
||||
"The task '{task}' has been deleted by {user}": "The task '{task}' has been deleted by {user}",
|
||||
"The transaction '{entity}' has been deleted by {user}": "The transaction '{entity}' has been deleted by {user}",
|
||||
"The wiki page '{name}' has been created": "The wiki page '{name}' has been created",
|
||||
"The wiki page '{name}' has been deleted": "The wiki page '{name}' has been deleted",
|
||||
"The wiki page '{page}' has been deleted by {user}": "The wiki page '{page}' has been deleted by {user}",
|
||||
@@ -429,8 +428,6 @@
|
||||
"upload_file": "upload file",
|
||||
"user": "user",
|
||||
"user ({id})": "user ({id})",
|
||||
"{user} added a new transaction: {entity}": "{user} added a new transaction: {entity}",
|
||||
"{user} updated the transaction '{entity}'": "{user} updated the transaction '{entity}'",
|
||||
"user_list": "user list",
|
||||
"user_module" : "Umbrella user management",
|
||||
"user profile": "User profile",
|
||||
@@ -458,11 +455,10 @@
|
||||
"wiki_pages": "wiki pages",
|
||||
|
||||
"year": "year",
|
||||
"You have been added to the new project '{project}', created by {user}:\n\n{body}": "You have been added to the new project '{project}', created by {user}:\n\n{body}",
|
||||
"You can view/edit this transaction at {base_url}/account/{id}": "Du kannst diese transaktion unter {base_url}/account/{id} ansehen",
|
||||
"You can view/edit this project at {base_url}/project/{id}/view": "You can view/edit this project at {base_url}/project/{id}/view",
|
||||
"You can view/edit this task at {base_url}/task/{id}/view": "You can view/edit this task at {base_url}/task/{id}/view",
|
||||
"You can view/edit this wiki page at {base_url}/wiki/{id}/view": "You can view/edit this wiki page at {base_url}/wiki/{id}/view",
|
||||
"You have been added to the new project '{project}', created by {user}:\n\n{body}": "You have been added to the new project '{project}', created by {user}:\n\n{body}",
|
||||
"You may change your notification settings at {base_url}/message/settings": "You may change your notification settings at {base_url}/message/settings .",
|
||||
"Your token to create a new password" : "Your token to create a new password",
|
||||
"your_profile": "your profile"
|
||||
|
||||
Reference in New Issue
Block a user