use of org.compiere.model.MWarehouse in project adempiere by adempiere.
the class VMRPDetailed method selectAttributeSetInstance.
// prepareTable
/**
* filter by Attribute Set Instance
*/
private void selectAttributeSetInstance() {
int m_warehouse_id = getM_Warehouse_ID();
int m_product_id = getM_Product_ID();
if (m_product_id <= 0)
return;
MProduct product = MProduct.get(getCtx(), m_product_id);
MWarehouse wh = MWarehouse.get(getCtx(), m_warehouse_id);
String title = product.get_Translation(MProduct.COLUMNNAME_Name) + " - " + wh.get_Translation(MWarehouse.COLUMNNAME_Name);
// Yamel Senih FR [ 114 ] 2015-11-23
PAttributeInstance pai = new PAttributeInstance(m_frame.getCFrame(), title, m_warehouse_id, 0, m_product_id, 0);
if (pai.getM_AttributeSetInstance_ID() != -1) {
fAttrSetInstance_ID.setText(pai.getM_AttributeSetInstanceName());
fAttrSetInstance_ID.setValue(new Integer(pai.getM_AttributeSetInstance_ID()));
} else {
fAttrSetInstance_ID.setValue(Integer.valueOf(0));
}
}
use of org.compiere.model.MWarehouse in project adempiere by adempiere.
the class ReleaseInOutBound method createDistributionOrder.
/**
* get Out Bound Order Lines from Smart Browser
* @return
*/
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
{
StringBuilder whereClause = new StringBuilder();
whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
.setClient_ID()
.setParameters(getAD_PInstance_ID())
.list();
}*/
/**
* create Distribution Order to performance a Pick List
* @param outBoundOrderLine Out bound Line
* @return Quantity that was not covert for inventory
*/
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
WMRuleEngine engineRule = WMRuleEngine.get();
List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
int shipperId = 0;
BigDecimal qtySupply = BigDecimal.ZERO;
if (storageList != null && storageList.size() > 0) {
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
if (wsts == null || wsts.length == 0)
throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
if (partnerId == 0)
throw new NoBPartnerLinkedforOrgException(org);
MBPartner partner = MBPartner.get(getCtx(), partnerId);
if (orderDistribution == null) {
orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
orderDistribution.setC_BPartner_ID(partnerId);
if (getDocumentTypeId() > 0) {
orderDistribution.setC_DocType_ID(getDocumentTypeId());
} else {
orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
}
orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
if (getDocumentAction() != null)
orderDistribution.setDocAction(getDocumentAction());
else
orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
if (users == null || users.length == 0)
throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
orderDistribution.setDateOrdered(getToday());
orderDistribution.setDatePromised(getToday());
orderDistribution.setM_Shipper_ID(shipperId);
orderDistribution.setIsInDispute(false);
orderDistribution.setIsInTransit(false);
orderDistribution.setSalesRep_ID(getAD_User_ID());
orderDistribution.saveEx();
}
storageList.stream().forEach(storage -> {
MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
orderLine.setM_Locator_ID(storage.getM_Locator_ID());
orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
orderLine.setDateOrdered(getToday());
orderLine.setDatePromised(outBoundOrderLine.getPickDate());
orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
orderLine.setIsInvoiced(false);
orderLine.saveEx();
});
} else {
qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
}
return qtySupply;
}
use of org.compiere.model.MWarehouse in project adempiere by adempiere.
the class InventoryValue method doIt.
// prepare
/**
* Perform process.
* <pre>
* - Fill Table with QtyOnHand for Warehouse and Valuation Date
* - Perform Price Calculations
* </pre>
* @return Message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_Warehouse_ID=" + p_M_Warehouse_ID + ",C_Currency_ID=" + p_C_Currency_ID + ",DateValue=" + p_DateValue + ",M_PriceList_Version_ID=" + p_M_PriceList_Version_ID + ",M_CostElement_ID=" + p_M_CostElement_ID);
MWarehouse wh = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
MClient c = MClient.get(getCtx(), wh.getAD_Client_ID());
MAcctSchema as = c.getAcctSchema();
// Delete (just to be sure)
StringBuffer sql = new StringBuffer("DELETE T_InventoryValue WHERE AD_PInstance_ID=");
sql.append(getAD_PInstance_ID());
int no = DB.executeUpdateEx(sql.toString(), get_TrxName());
// Insert Standard Costs
sql = new StringBuffer("INSERT INTO T_InventoryValue " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID," + " AD_Client_ID, AD_Org_ID, CostStandard) " + "SELECT ").append(getAD_PInstance_ID()).append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID," + " w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID))" + " INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') " + "WHERE w.M_Warehouse_ID=").append(p_M_Warehouse_ID);
int noInsertStd = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Inserted Std=" + noInsertStd);
if (noInsertStd == 0)
return "No Standard Costs found";
// Insert addl Costs
int noInsertCost = 0;
if (p_M_CostElement_ID != 0) {
sql = new StringBuffer("INSERT INTO T_InventoryValue " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID," + " AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID) " + "SELECT ").append(getAD_PInstance_ID()).append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID," + " w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) " + "WHERE w.M_Warehouse_ID=").append(p_M_Warehouse_ID).append(" AND c.M_CostElement_ID=").append(p_M_CostElement_ID).append(" AND NOT EXISTS (SELECT * FROM T_InventoryValue iv " + "WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID()).append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID" + " AND iv.M_Product_ID=c.M_Product_ID" + " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)");
noInsertCost = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Inserted Cost=" + noInsertCost);
// Update Std Cost Records
sql = new StringBuffer("UPDATE T_InventoryValue iv " + "SET (Cost, M_CostElement_ID)=" + "(SELECT c.CurrentCostPrice, c.M_CostElement_ID " + "FROM M_Warehouse w" + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)" + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)" + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID" + " AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) " + "WHERE c.M_CostElement_ID=" + p_M_CostElement_ID + " AND iv.M_Warehouse_ID=w.M_Warehouse_ID" + " AND iv.M_Product_ID=c.M_Product_ID" + " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID) " + "WHERE EXISTS (SELECT * FROM T_InventoryValue ivv " + "WHERE ivv.AD_PInstance_ID=" + getAD_PInstance_ID() + " AND ivv.M_CostElement_ID IS NULL)");
int noUpdatedCost = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Updated Cost=" + noUpdatedCost);
}
if ((noInsertStd + noInsertCost) == 0)
return "No Costs found";
// Update Constants
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
String myDate = p_DateValue.toString();
sql = new StringBuffer("UPDATE T_InventoryValue SET ").append("DateValue=TO_DATE('").append(myDate.substring(0, 10)).append(" 23:59:59','YYYY-MM-DD HH24:MI:SS'),").append("M_PriceList_Version_ID=").append(p_M_PriceList_Version_ID).append(",").append("C_Currency_ID=").append(p_C_Currency_ID).append(" WHERE AD_PInstance_ID=" + getAD_PInstance_ID());
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Constants=" + no);
// Get current QtyOnHand with ASI
sql = new StringBuffer("UPDATE T_InventoryValue iv SET QtyOnHand = " + "(SELECT SUM(QtyOnHand) FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) " + "WHERE iv.M_Product_ID=s.M_Product_ID" + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID" + " AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) " + "WHERE AD_PInstance_ID=").append(getAD_PInstance_ID()).append(" AND iv.M_AttributeSetInstance_ID<>0");
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("QtHand with ASI=" + no);
// Get current QtyOnHand without ASI
sql = new StringBuffer("UPDATE T_InventoryValue iv SET QtyOnHand = " + "(SELECT SUM(QtyOnHand) FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) " + "WHERE iv.M_Product_ID=s.M_Product_ID" + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID) " + "WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID()).append(" AND iv.M_AttributeSetInstance_ID=0");
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("QtHand w/o ASI=" + no);
// Adjust for Valuation Date
sql = new StringBuffer("UPDATE T_InventoryValue iv " + "SET QtyOnHand=" + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) " + "FROM M_Transaction t" + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) " + "WHERE t.M_Product_ID=iv.M_Product_ID" + " AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID" + " AND t.MovementDate > iv.DateValue" + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) " + "WHERE iv.M_AttributeSetInstance_ID<>0" + " AND iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Update with ASI=" + no);
//
sql = new StringBuffer("UPDATE T_InventoryValue iv " + "SET QtyOnHand=" + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) " + "FROM M_Transaction t" + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) " + "WHERE t.M_Product_ID=iv.M_Product_ID" + " AND t.MovementDate > iv.DateValue" + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) " + "WHERE iv.M_AttributeSetInstance_ID=0 " + "AND iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Update w/o ASI=" + no);
// Delete Records w/o OnHand Qty
sql = new StringBuffer("DELETE T_InventoryValue " + "WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND AD_PInstance_ID=").append(getAD_PInstance_ID());
int noQty = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("NoQty Deleted=" + noQty);
// Update Prices
sql = new StringBuffer("UPDATE T_InventoryValue iv " + "SET PricePO = " + "(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))" + " FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID" + " AND po.IsCurrentVendor='Y'), " + "PriceList = " + "(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), " + "PriceStd = " + "(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), " + "PriceLimit = " + "(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)" + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp" + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID" + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID" + " AND plv.M_PriceList_ID=pl.M_PriceList_ID)" + " WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
String msg = "";
if (no == 0)
msg = "No Prices";
// Convert if different Currency
if (as.getC_Currency_ID() != p_C_Currency_ID) {
sql = new StringBuffer("UPDATE T_InventoryValue iv " + "SET CostStandard= " + "(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) " + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + as.getC_AcctSchema_ID() + ")," + " Cost= " + "(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) " + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + as.getC_AcctSchema_ID() + ") " + "WHERE iv.AD_PInstance_ID=" + getAD_PInstance_ID());
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
log.fine("Converted=" + no);
}
// Update Values
no = DB.executeUpdateEx("UPDATE T_InventoryValue SET " + "PricePOAmt = QtyOnHand * PricePO, " + "PriceListAmt = QtyOnHand * PriceList, " + "PriceStdAmt = QtyOnHand * PriceStd, " + "PriceLimitAmt = QtyOnHand * PriceLimit, " + "CostStandardAmt = QtyOnHand * CostStandard, " + "CostAmt = QtyOnHand * Cost " + "WHERE AD_PInstance_ID=" + getAD_PInstance_ID(), get_TrxName());
log.fine("Calculation=" + no);
//
return msg;
}
use of org.compiere.model.MWarehouse in project adempiere by adempiere.
the class MRPUpdate method doIt.
// prepare
/**
* doIT - run process
*/
protected String doIt() throws Exception {
String result = null;
ArrayList<Object> parameters = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
parameters.add(m_AD_Client_ID);
if (p_S_Resource_ID > 0) {
whereClause.append(" AND S_Resource_ID=?");
parameters.add(p_S_Resource_ID);
}
List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
if (plants.size() == 0) {
// TODO: translate
throw new AdempiereException("No plants found");
}
for (MResource plant : plants) {
log.info("Run MRP to Plant: " + plant.getName());
parameters = new ArrayList<Object>();
whereClause = new StringBuffer("AD_Client_ID=?");
parameters.add(m_AD_Client_ID);
if (p_AD_Org_ID > 0) {
whereClause.append(" AND AD_Org_ID=?");
parameters.add(p_AD_Org_ID);
}
List<MOrg> organizations = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
for (MOrg organization : organizations) {
log.info("Run MRP to Organization: " + organization.getName());
if (p_M_Warehouse_ID == 0) {
MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), organization.getAD_Org_ID());
for (MWarehouse w : ws) {
log.info("Run MRP to Wharehouse: " + w.getName());
deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
result = result + "<br>finish MRP to Warehouse " + w.getName();
}
} else {
log.info("Run MRP to Wharehouse: " + p_M_Warehouse_ID);
deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
}
result = result + "<br>finish MRP to Organization " + organization.getName();
}
result = result + "<br>finish MRP to Plant " + plant.getName();
}
if (Util.isEmpty(result, true)) {
// TODO: translate
return "No records found";
}
return Msg.getMsg(getCtx(), "ProcessOK");
}
use of org.compiere.model.MWarehouse in project adempiere by adempiere.
the class SearchServlet method outputWarehouses.
/**
* Output XML list of Warehouses
*
* @param ctx context
* @param out printWriter
* @param orgID organization ID
* @param warehouseID warehouse ID
* @param includeAny whether 'ANY' should be added to beginning of the list
*/
private void outputWarehouses(Properties ctx, PrintWriter out, int orgID, int warehouseID, boolean includeAny) {
out.println("<warehouses orgID='" + orgID + "'>");
if (includeAny) {
out.println("<warehouse id='-1'");
if (warehouseID == 0)
out.println(" selected='selected'");
out.println(">ANY</warehouse>");
}
for (MWarehouse warehouse : MWarehouse.getForOrg(ctx, orgID)) {
out.print("<warehouse id='" + warehouse.getM_Warehouse_ID() + "'");
if (warehouseID == warehouse.getM_Warehouse_ID())
out.print(" selected='selected'");
out.println(">" + Util.maskHTML(warehouse.getName()) + "</warehouse>");
}
out.println("</warehouses>");
}
Aggregations