Compare commits
3
Commits
75927c4395
...
767e918aa5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
767e918aa5 | ||
|
|
f2ff18f19b | ||
|
|
c148800e72 |
@@ -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}
|
||||
|
||||
@@ -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)}
|
||||
|
||||
@@ -207,9 +207,8 @@ 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));
|
||||
if (fulltext) {
|
||||
@@ -219,6 +218,7 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
for (var key : keys) query.where(NAME,like("%"+key+"%"));
|
||||
}
|
||||
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,6 +230,29 @@ 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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -463,8 +463,9 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user