Browse Source

implemented adding stock items to documents

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/document
Stephan Richter 4 hours ago
parent
commit
6bb03f4e04
  1. 9
      frontend/src/Components/Item.svelte
  2. 18
      frontend/src/routes/document/PositionSelector.svelte
  3. 8
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

9
frontend/src/Components/Item.svelte

@ -1,4 +1,5 @@
<script> <script>
import { t } from '../translations.svelte';
let { item, onclick } = $props(); let { item, onclick } = $props();
</script> </script>
@ -7,6 +8,12 @@
{#if item.properties} {#if item.properties}
<table> <table>
<tbody> <tbody>
{#if item.location.name}
<tr>
<th>{t('location')}</th>
<td>{item.location.name}</td>
</tr>
{/if}
{#each Object.entries(item.properties) as [idx,prop]} {#each Object.entries(item.properties) as [idx,prop]}
<tr> <tr>
<th>{prop.name}</th> <th>{prop.name}</th>
@ -16,6 +23,4 @@
</tbody> </tbody>
</table> </table>
{/if} {/if}
<!--<div>{@html item.description.rendered}</div> -->
<!-- <span>{item.unit_price/100} {item.currency} / {item.unit}</span> -->
</fieldset> </fieldset>

18
frontend/src/routes/document/PositionSelector.svelte

@ -29,14 +29,24 @@
} }
function itemSelected(item){ function itemSelected(item){
let unit_price = null;
let description = '';
for (let prop of item.properties) {
if (prop.name.toLowerCase().indexOf(t('price').toLowerCase())>-1){
unit_price = 100*prop.value.replace(',','.');
} else {
description += `* ${prop.name}: ${prop.value}\n`;
}
}
select({ select({
item_code : item.code, item_code : item.code,
title : item.name, title : item.name,
description : item.description.source, description : description,
amount : 1, amount : 1,
unit : item.unit, unit : t('pieces'),
unit_price : item.unit_price, unit_price : unit_price,
tax : item.tax tax : 0
}); });
} }

8
stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

@ -325,8 +325,12 @@ public class StockModule extends BaseHandler implements StockService {
if (!json.has(COMPANY_ID) || !(json.get(COMPANY_ID) instanceof Number company_id)) throw missingFieldException(COMPANY_ID); if (!json.has(COMPANY_ID) || !(json.get(COMPANY_ID) instanceof Number company_id)) throw missingFieldException(COMPANY_ID);
var company = companyService().get(company_id.longValue()); var company = companyService().get(company_id.longValue());
if (!companyService().membership(company_id.longValue(),user.id())) throw forbidden("You are not a member of {0}!", company.name()); if (!companyService().membership(company_id.longValue(),user.id())) throw forbidden("You are not a member of {0}!", company.name());
var items = stockDb.listItemsOf(company); var map = new HashMap<Long,Location>();
return sendContent(ex,items.stream().sorted(byName).map(Item::toMap)); var items = stockDb.listItemsOf(company)
.stream()
.peek(item -> item.location(map.computeIfAbsent(item.location().id(), k -> item.location().resolve()))).sorted(byName)
.map(Item::toMap);
return sendContent(ex,items);
} }
private boolean postLocation(UmbrellaUser user, HttpExchange ex) throws IOException { private boolean postLocation(UmbrellaUser user, HttpExchange ex) throws IOException {

Loading…
Cancel
Save