Compare commits

..
Author SHA1 Message Date
StephanRichter 767e918aa5 gui improvements
Build Docker Image / Clean-Registry (push) Successful in 6s
Build Docker Image / Docker-Build (push) Successful in 2m52s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-07-27 08:40:37 +02:00
StephanRichter f2ff18f19b implemented search on in stock locations
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-07-23 13:30:06 +02:00
StephanRichter c148800e72 preparing location search 2026-07-23 08:47:50 +02:00
14 changed files with 82 additions and 260 deletions
@@ -16,7 +16,7 @@ public interface AccountDb {
Collection<UmbrellaUser> getMembers(long accountId);
Optional<Transaction> lastTransaction(long accountId, String source, String destination, Double amount);
Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount);
Collection<Account> listAccounts(long userId);
@@ -311,11 +311,12 @@ public class AccountingModule extends BaseHandler implements AccountingService {
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);
String destination = dst.has(Field.ID) ? dst.get(Field.ID).toString() : dst.has(Field.DISPLAY) ? dst.get(Field.DISPLAY).toString() : null;
Double amount = null;
if (json.has(Field.AMOUNT) && json.get(Field.AMOUNT) instanceof Number amt) amount = amt.doubleValue();
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, destination, amount);
var transaction = accountDb.lastTransaction(accountId, source, dest, amount);
return transaction.isPresent() ? sendContent(ex,transaction.get()) : notFound(ex);
}
@@ -173,42 +173,22 @@ public class SqliteDb extends BaseDb implements AccountDb {
}
@Override
public Optional<Transaction> lastTransaction(long accountId, String source, String destination, Double amount) {
public Optional<Transaction> lastTransaction(long accountId, String source, String dest, double amount) {
try {
var query = select(ALL).from(TABLE_TRANSACTIONS).where(ACCOUNT,equal(accountId));
if (source != null) query = query.where(SOURCE,equal(source));
if (destination != null) query = query.where(DESTINATION,equal(destination));
if (amount != null) query = query.where(AMOUNT,equal(amount));
var rs = query.sort(ID+" DESC").limit(1).exec(db);
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 && amount != null) { // try to search by amount, ignore source and dest
rs = select(ALL).from(TABLE_TRANSACTIONS).where(ACCOUNT, equal(accountId)).where(AMOUNT, equal(amount))
.sort(ID + " DESC").limit(1).exec(db);
if (rs.next()) ta = Transaction.of(rs);
rs.close();
}
if (ta == null && source != null && destination != null) { // try to search by amount, ignore source and dest
rs = select(ALL).from(TABLE_TRANSACTIONS)
.where(SOURCE,equal(source))
.where(DESTINATION,equal(destination))
.where(ACCOUNT, equal(accountId))
.sort(ID + " DESC").limit(1).exec(db);
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));
@@ -4,7 +4,7 @@
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import EntryForm from './add_entry_new.svelte';
import EntryForm from './add_entry.svelte';
import Transaction from './transaction.svelte';
let { id } = $props();
@@ -173,5 +173,5 @@
</table>
</fieldset>
<EntryForm {account} {onSave} {users} />
<EntryForm {account} {onSave} />
{/if}
@@ -1,205 +0,0 @@
<script>
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte';
import { api, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { user } from '../../user.svelte';
import Autocomplete from '../../Components/Autocomplete.svelte';
import Tags from '../tags/TagList.svelte';
let defaultAccount = {
id : 0,
name : '',
currency : ''
};
let { account = defaultAccount, new_account = false, onSave = () => {}, users } = $props();
let entry = $state({
account,
date : new Date().toISOString().substring(0, 10),
source : {
display: user.name,
id: user.id
},
destination : {},
amount : 0.0,
purpose : {},
tags : []
});
let router = useTinyRouter();
async function dst_selected(destination){
destination = JSON.parse(JSON.stringify(destination));
let source = JSON.parse(JSON.stringify(entry.source));
const url = api(`accounting/${entry.account.id}/tags`)
const res = await post(url,{source,destination});
if (res.ok) {
yikes();
const json = await res.json();
await proposePurpose();
entry.tags = json;
} else error(res);
}
function focusOnEnter(ev,id){
if (ev.key == 'Enter') {
proposePurpose();
document.getElementById(id).focus();
}
}
async function getAccountTags(text){
if (!text) return [];
const url = api(`accounting/${entry.account.id}/tags`)
return await getProposals(text,url);
}
async function getDestinations(text){
const url = api('accounting/destinations');
return await getProposals(text,url);
}
async function getProposals(text,url){
const res = await post(url,text);
if (res.ok){
yikes();
const input = await res.json();
return Object.values(input).map(mapDisplay);
} else {
error(res);
return {};
}
}
async function getPurposes(text) {
const url = api('accounting/purposes');
return await getProposals(text,url);
}
async function getSources(text){
const url = api('accounting/sources');
return await getProposals(text,url);
}
function gotoTags(purpose){
document.getElementById('new_tag_input');
}
function mapDisplay(object){
if (object.display){
return object;
} else if (object.name) {
return {...object, display: object.name};
} else {
return { display : object }
}
}
async function proposePurpose(){
console.log('proposePurpose()');
const amount = entry.amount;
const source = entry.source;
const destination = entry.destination;
const url = api(`accounting/${account.id}/purposes`);
const res = await post(url,{source,destination,amount});
if (res.ok) {
yikes();
var lastTransaction = await res.json();
console.log({lastTransaction,users:JSON.parse(JSON.stringify(users))});
entry.purpose = { display: lastTransaction.purpose};
entry.tags = lastTransaction.tags;
if (lastTransaction.source.value){
if (users[lastTransaction.source.value]){
let user = users[lastTransaction.source.value];
entry.source = { id : +lastTransaction.source.value, display : user.name };
} else entry.source = { display: lastTransaction.source.value };
}
if (lastTransaction.destination.value){
if (users[lastTransaction.destination.value]){
let user = users[lastTransaction.destination.value];
entry.destination = { id : +lastTransaction.destination.value, display : user.name };
} else entry.destination = { display: lastTransaction.destination.value };
}
} else error(res);
}
async function save(){
let data = {
...entry,
purpose: entry.purpose.display
}
let url = api('accounting');
let res = await post(url, data);
if (res.ok) {
yikes();
if (new_account){
router.navigate('/accounting');
return;
}
//entry.tags = [];
onSave();
document.getElementById('date-input').focus();
} else error(res);
}
</script>
<style>
hr{
grid-column: 1 / -1;
margin: 0.5rem 0;
border: 0;
height: 1px;
align-self: center;
background: red;
}
</style>
<fieldset class="grid2 new_transaction">
{#if new_account}
<legend>{t('create_new_object',{object:t('account')})}</legend>
<span style="display:none"></span>
<span>{t('account name')}</span>
<span>
<input type="text" bind:value={entry.account.name} />
</span>
<span>{t('currency')}</span>
<span>
<input type="text" bind:value={entry.account.currency} />
</span>
<hr/>
<span style="grid-column-end: span 2">{t('first transaction')}</span>
{:else}
<legend>{t('add_object',{object:t('transaction')})}</legend>
<span style="display:none"></span>
{/if}
<span>{t('date')}</span>
<span>
<input type="date" bind:value={entry.date} id="date-input" />
</span>
<span>{t('amount')}</span>
<span>
<input type="number" bind:value={entry.amount} onkeyup={e => focusOnEnter(e,'source-input')} />&nbsp;{entry.account.currency}
</span>
<span>{t('source')}</span>
<Autocomplete bind:candidate={entry.source} getCandidates={getSources} id="source-input" />
<span>{t('destination')}</span>
<Autocomplete bind:candidate={entry.destination} getCandidates={getDestinations} onSelect={dst_selected} />
<span>{t('purpose')}</span>
<Autocomplete bind:candidate={entry.purpose} getCandidates={getPurposes} onCommit={gotoTags} id="purpose_input" />
<span>{t('tags')}</span>
<Tags getCandidates={getAccountTags} module={null} bind:tags={entry.tags} onEmptyCommit={save} />
<span></span>
<span>
<button onclick={save}>{t('save')}</button>
</span>
</fieldset>
+15 -1
View File
@@ -265,8 +265,10 @@
<legend>
{t('stock')}
</legend>
{#if Object.keys(stock.items).length }
{t('items')}
<ul>
{#each Object.values(stock) as item}
{#each Object.values(stock.items) as item}
<li>
<a href="/stock/{item.owner.type}/{item.owner.id}/item/{item.owner_number}" {onclick} >
{item.name} [{t('code')}: <span class="code">{item.code}</span>]
@@ -275,6 +277,18 @@
</li>
{/each}
</ul>
{/if}
{#if Object.keys(stock.locations).length}
{t('locations')}
<ul>
{#each Object.values(stock.locations) as loc (loc.id)}
<li>
<a href="/stock/location/{loc.id}">{loc.name}</a>
<br/> {@html loc.description.rendered}
</li>
{/each}
</ul>
{/if}
</fieldset>
{/if}
{#if times}
+1 -1
View File
@@ -102,7 +102,7 @@
<ul>
{#each locations as location}
<li onclick={e => toggleChildren(e, location)}
class="{location.locations?'expanded':'collapsed'} {location.highlight?'highlight':null}"
class="{location.locations?'expanded':'collapsed'} {location.highlight?'highlight':null} {selected && selected.id == location.id?'selected':null}"
draggable={true}
ondragover={e => drag_over(e,location)}
ondrop={e => onDrop(e,location)}
-4
View File
@@ -130,10 +130,6 @@
onMount(load);
</script>
<svelte:head>
<title>Umbrella {t('Easylist')}: {tag}</title>
</svelte:head>
<h2>{t('tasks_for_tag',{tag:decodeURI(tag)})}</h2>
<div class="easylist">
@@ -132,7 +132,7 @@ public class SqliteDb extends BaseDb implements StockDb {
private void createItemsTable() {
try {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255) NOT NULL, {3} TEXT, {4} VARCHAR(255))";
sql = format(sql, TABLE_ITEMS, ID, Field.CODE, NAME, LOCATION_ID);
sql = format(sql, TABLE_ITEMS, ID, Field.CODE, NAME, LOCATION_ID);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw failedToCreateTable(TABLE_ITEMS).causedBy(e);
@@ -142,7 +142,7 @@ public class SqliteDb extends BaseDb implements StockDb {
private void createItemPropsTable() {
try {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} INT NOT NULL, {2} INT NOT NULL, {3} VARCHAR(255) NOT NULL, PRIMARY KEY({1}, {2}))";
sql = format(sql, TABLE_ITEM_PROPERTIES, ITEM_ID, PROPERTY_ID,VALUE);
sql = format(sql, TABLE_ITEM_PROPERTIES, ITEM_ID, PROPERTY_ID,VALUE);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw failedToCreateTable(TABLE_ITEM_PROPERTIES).causedBy(e);
@@ -152,7 +152,7 @@ public class SqliteDb extends BaseDb implements StockDb {
private void createLocationsTable() {
try {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255) DEFAULT NULL, {3} VARCHAR(255) NOT NULL, {4} TEXT)";
sql = format(sql, TABLE_LOCATIONS, ID, LOCATION_ID, NAME, DESCRIPTION);
sql = format(sql, TABLE_LOCATIONS, ID, LOCATION_ID, NAME, DESCRIPTION);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw failedToCreateTable(TABLE_LOCATIONS).causedBy(e);
@@ -162,7 +162,7 @@ public class SqliteDb extends BaseDb implements StockDb {
private void createPropertiesTable() {
try {
var sql = "CREATE TABLE IF NOT EXISTS {0} ( {1} INTEGER PRIMARY KEY, {2} VARCHAR(255) NOT NULL, {3} INT NOT NULL, {4} VARCHAR(255))";
sql = format(sql, TABLE_PROPERTIES, ID, NAME, TYPE, UNIT);
sql = format(sql, TABLE_PROPERTIES, ID, NAME, TYPE, UNIT);
db.prepareStatement(sql).execute();
} catch (SQLException e) {
throw failedToCreateTable(TABLE_PROPERTIES).causedBy(e);
@@ -207,18 +207,18 @@ public class SqliteDb extends BaseDb implements StockDb {
}
@Override
public Map<Long, Item> find(Collection<Owner> owners, Collection<String> keys, boolean fulltext) {
public Map<Long, Item> findItems(Collection<Owner> owners, Collection<String> keys, boolean fulltext) {
try {
var items = new HashMap<Long,Item>();
var ownerCodes = owners.stream().map(Owner::dbCode).toArray();
var query = select(ALL).from(TABLE_ITEMS).where(OWNER, in(ownerCodes));
var query = select(ALL).from(TABLE_ITEMS).where(OWNER, in(ownerCodes));
if (fulltext) {
query.leftJoin(ID,TABLE_ITEM_PROPERTIES,ITEM_ID);
for (var key : keys) query.where(format("CONCAT({0},\" \",{1},\" \",{2})", NAME, DESCRIPTION,VALUE),like("%"+key+"%"));
} else {
for (var key : keys) query.where(NAME,like("%"+key+"%"));
}
var rs = query.exec(db);
var rs = query.exec(db);
var items = new HashMap<Long,Item>();
while (rs.next()){
var item = Item.of(rs);
items.put(item.id(),item);
@@ -230,10 +230,33 @@ public class SqliteDb extends BaseDb implements StockDb {
}
}
@Override
public Map<Long, Location> findLocations(Collection<Owner> owners, Collection<String> keys, boolean fulltext) {
try {
var ownerCodes = owners.stream().map(Owner::dbCode).toArray();
var query = select(ALL).from(TABLE_LOCATIONS).where(OWNER, in(ownerCodes));
if (fulltext) {
for (var key : keys) query.where(format("CONCAT({0},\" \",{1})", NAME, DESCRIPTION), like("%" + key + "%"));
} else {
for (var key : keys) query.where(NAME, like("%" + key + "%"));
}
var rs = query.exec(db);
var locations = new HashMap<Long, Location>();
while (rs.next()) {
var location = DbLocation.of(rs);
locations.put(location.id(), location);
}
rs.close();
return locations;
} catch (SQLException e){
throw databaseException(FAILED_TO_LIST_ENTITIES, TYPE,t(LOCATIONS)).causedBy(e);
}
}
@Override
public Collection<DbLocation> listChildLocations(long parentId) {
try {
var rs = select(ALL).from(TABLE_LOCATIONS).where(PARENT_LOCATION_ID,equal(parentId)).exec(db);
var rs = select(ALL).from(TABLE_LOCATIONS).where(PARENT_LOCATION_ID,equal(parentId)).exec(db);
var list = new ArrayList<DbLocation>();
while (rs.next()) list.add(DbLocation.of(rs));
rs.close();
@@ -246,7 +269,7 @@ public class SqliteDb extends BaseDb implements StockDb {
@Override
public Collection<DbLocation> listCompanyLocations(Company company) {
try {
var rs = select(ALL).from(TABLE_LOCATIONS).where(OWNER,equal(company.dbCode())).where(PARENT_LOCATION_ID,isNull()).exec(db);
var rs = select(ALL).from(TABLE_LOCATIONS).where(OWNER,equal(company.dbCode())).where(PARENT_LOCATION_ID,isNull()).exec(db);
var list = new ArrayList<DbLocation>();
while (rs.next()) list.add(DbLocation.of(rs));
rs.close();
@@ -10,7 +10,8 @@ import java.util.Map;
public interface StockDb {
Property addNewProperty(long itemId, String name, Object value, String unit);
Location delete(DbLocation location);
Map<Long, Item> find(Collection<Owner> owners, Collection<String> keys, boolean fulltext);
Map<Long, Item> findItems(Collection<Owner> owners, Collection<String> keys, boolean fulltext);
Map<Long, Location> findLocations(Collection<Owner> owners, Collection<String> keys, boolean fulltext);
Collection<DbLocation> listChildLocations(long parentId);
Collection<DbLocation> listCompanyLocations(Company company);
Collection<Item> listItemsAt(Location location);
@@ -459,12 +459,13 @@ public class StockModule extends BaseHandler implements StockService {
private boolean postSearch(UmbrellaUser user, HttpExchange ex) throws IOException {
var json = json(ex);
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingField(KEY);
var keys = Arrays.asList(key.split(" "));
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
var keys = Arrays.asList(key.split(" "));
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
Set<Owner> owners = new HashSet<>(companyService().listCompaniesOf(user).values());
owners.add(user);
var items = stockDb.find(owners,keys,fulltext);
return sendContent(ex,mapValues(items));
var items = stockDb.findItems(owners,keys,fulltext);
var locations = stockDb.findLocations(owners,keys,fulltext);
return sendContent(ex,Map.of("items",mapValues(items),"locations",mapValues(locations)));
}
@Override
@@ -349,6 +349,10 @@ tr:hover .taglist .tag button {
border-top-color: red;
}
.locations .selected span{
background: brown;
color: yellow;
}
@media screen and (max-width: 900px) {
#app nav a{
background: black;
@@ -345,6 +345,10 @@ code,
border-top-color: gold;
}
.locations .selected span{
background: gold;
color: black;
}
@media screen and (max-width: 900px) {
#app nav a{
background: black;
@@ -296,7 +296,10 @@ tr:hover .taglist .tag button {
border-top-color: blue;
}
.locations .selected span{
background: #afffff;
color: black;
}
@media screen and (max-width: 900px) {
#app nav a{
background: white;