final StringBuilder sb = new StringBuilder();
sb.append("ExternalPOS with ");
sb.append(" CLIENT_ID=" + clientId);
sb.append(", ORG_ID=" + orgId);
sb.append(", POS_ID=" + posId + "not defined");
throw new OBException(sb.toString());
} else {
final StringBuilder sPro = new StringBuilder();
boolean incPro = false;
for (final BaseOBObject b : obq1.list()) {
final ExternalPOS ePos = (ExternalPOS) b;
warehouseId = ePos.getWarehouse().getId();
if (ePos.getIncludedProduct().equals("N")) {
incPro = true;
sPro.append("(''");
for (final ExternalPOSProduct p : ePos
.getExternalPOSProductList()) {
sPro.append(", '" + p.getProduct().getId() + "'");
}
sPro.append(")");
}
}
final StringBuilder invWhere = new StringBuilder();
invWhere.append("storageBin.id in (select lo.id from Locator lo");
invWhere.append(" where lo.warehouse.id='" + warehouseId + "')");
invWhere.append(" and uOM.id='100'");
if (incPro) {
invWhere.append(" and product.id in " + sPro);
}
invWhere.append(" and " + defWclause);
final OBQuery<BaseOBObject> obq2 = OBDal.getInstance().createQuery(
"MaterialMgmtStorageDetail", invWhere.toString());
obq2.setFilterOnReadableClients(false);
obq2.setFilterOnReadableOrganization(false);
final List<BaseOBObject> l1 = obq2.list();
final Map<String, BigDecimal> keyUnits = new HashMap<String, BigDecimal>();
final List<BaseOBObject> delIndex = new ArrayList<BaseOBObject>();
final Map<String, String> keyStorageId = new HashMap<String, String>();
int i = 0;
for (final BaseOBObject b : l1) {
final StorageDetail sd = (StorageDetail) b;
final String proId = sd.getProduct().getId();
final String attSet = sd.getAttributeSetValue().getId();
final BigDecimal units = sd.getQuantityOnHand();
final String key = proId + "_" + attSet;
if (keyUnits.containsKey(key)) {
final BigDecimal sum = units.add(keyUnits.get(key));
keyUnits.put(key, sum);
delIndex.add(b);
} else {
keyStorageId.put(key, sd.getId());
keyUnits.put(key, units);
}
i++;
}
l1.removeAll(delIndex);
final StringWriter sw = new StringWriter();
exc.setOutput(sw);
exc.process(l1);
final String xml2 = sw.toString();
try {
doc = DocumentHelper.parseText(xml2);
for (final String s : keyStorageId.keySet()) {
final String stoId = keyStorageId.get(s);
final Element sel = (Element) doc
.selectSingleNode("/ob:Openbravo/MaterialMgmtStorageDetail[@id="
+ stoId + "]");
sel.element("quantityOnHand").setText(
keyUnits.get(s).toString());
}
} catch (final DocumentException e) {
throw new OBException("Error parsing xml " + e.getMessage());
}
return doc;
}
}