IDEMPIERE-5739 Allow Inventory Valuation Report for more than one warehouse (#1857)
This commit is contained in:
parent
03b4d0bf2f
commit
aa0f27f31a
|
@ -0,0 +1,18 @@
|
||||||
|
-- IDEMPIERE-5739 Allow Inventory Valuation Report for more than one warehouse
|
||||||
|
SELECT register_migration_script('202305262207_IDEMPIERE-5739.sql') FROM dual;
|
||||||
|
|
||||||
|
SET SQLBLANKLINES ON
|
||||||
|
SET DEFINE OFF
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:07:05 PM CEST
|
||||||
|
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203812,0,0,'Y',TO_TIMESTAMP('2023-05-26 22:06:31','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-05-26 22:06:31','YYYY-MM-DD HH24:MI:SS'),100,'M_Warehouse_IDs','Warehouses',NULL,NULL,'Storage Warehouses and Service Points','D','ed8c53b8-6032-4e6a-b226-07c2c7624d63')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:09:14 PM CEST
|
||||||
|
UPDATE AD_Process_Para SET IsActive='N', SeqNo=5, IsCentrallyMaintained='N',Updated=TO_TIMESTAMP('2023-05-26 22:09:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=230
|
||||||
|
;
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:09:19 PM CEST
|
||||||
|
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,AD_Reference_Value_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete,DateRangeOption,IsShowNegateButton) VALUES (200438,0,0,'Y',TO_TIMESTAMP('2023-05-26 22:09:19','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-05-26 22:09:19','YYYY-MM-DD HH24:MI:SS'),100,'Warehouses',180,10,200162,197,'N',1000,'N','M_Warehouse_IDs','Y','D',203812,'74c772f8-692e-4eea-9dff-24652fa878e9','N','N','D','N')
|
||||||
|
;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
-- IDEMPIERE-5739 Allow Inventory Valuation Report for more than one warehouse
|
||||||
|
SELECT register_migration_script('202305262207_IDEMPIERE-5739.sql') FROM dual;
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:07:05 PM CEST
|
||||||
|
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203812,0,0,'Y',TO_TIMESTAMP('2023-05-26 22:06:31','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-05-26 22:06:31','YYYY-MM-DD HH24:MI:SS'),100,'M_Warehouse_IDs','Warehouses',NULL,NULL,'Storage Warehouses and Service Points','D','ed8c53b8-6032-4e6a-b226-07c2c7624d63')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:09:14 PM CEST
|
||||||
|
UPDATE AD_Process_Para SET IsActive='N', SeqNo=5, IsCentrallyMaintained='N',Updated=TO_TIMESTAMP('2023-05-26 22:09:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=230
|
||||||
|
;
|
||||||
|
|
||||||
|
-- May 26, 2023, 10:09:19 PM CEST
|
||||||
|
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,AD_Reference_Value_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete,DateRangeOption,IsShowNegateButton) VALUES (200438,0,0,'Y',TO_TIMESTAMP('2023-05-26 22:09:19','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-05-26 22:09:19','YYYY-MM-DD HH24:MI:SS'),100,'Warehouses',180,10,200162,197,'N',1000,'N','M_Warehouse_IDs','Y','D',203812,'74c772f8-692e-4eea-9dff-24652fa878e9','N','N','D','N')
|
||||||
|
;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.compiere.process;
|
package org.compiere.process;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
|
@ -24,6 +25,7 @@ import org.compiere.model.MClient;
|
||||||
import org.compiere.model.MProcessPara;
|
import org.compiere.model.MProcessPara;
|
||||||
import org.compiere.model.MWarehouse;
|
import org.compiere.model.MWarehouse;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.TimeUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,8 +44,8 @@ public class InventoryValue extends SvrProcess
|
||||||
private int p_M_PriceList_Version_ID;
|
private int p_M_PriceList_Version_ID;
|
||||||
/** Valuation Date */
|
/** Valuation Date */
|
||||||
private Timestamp p_DateValue;
|
private Timestamp p_DateValue;
|
||||||
/** Warehouse */
|
/** Warehouses */
|
||||||
private int p_M_Warehouse_ID;
|
private int[] p_M_Warehouse_IDs;
|
||||||
/** Currency */
|
/** Currency */
|
||||||
private int p_C_Currency_ID;
|
private int p_C_Currency_ID;
|
||||||
/** Optional Cost Element */
|
/** Optional Cost Element */
|
||||||
|
@ -64,8 +66,8 @@ public class InventoryValue extends SvrProcess
|
||||||
p_M_PriceList_Version_ID = para[i].getParameterAsInt();
|
p_M_PriceList_Version_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals("DateValue"))
|
else if (name.equals("DateValue"))
|
||||||
p_DateValue = (Timestamp)para[i].getParameter();
|
p_DateValue = (Timestamp)para[i].getParameter();
|
||||||
else if (name.equals("M_Warehouse_ID"))
|
else if (name.equals("M_Warehouse_IDs"))
|
||||||
p_M_Warehouse_ID = para[i].getParameterAsInt();
|
p_M_Warehouse_IDs = para[i].getParameterAsIntArray();
|
||||||
else if (name.equals("C_Currency_ID"))
|
else if (name.equals("C_Currency_ID"))
|
||||||
p_C_Currency_ID = para[i].getParameterAsInt();
|
p_C_Currency_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals("M_CostElement_ID"))
|
else if (name.equals("M_CostElement_ID"))
|
||||||
|
@ -88,216 +90,212 @@ public class InventoryValue extends SvrProcess
|
||||||
*/
|
*/
|
||||||
protected String doIt() throws Exception
|
protected String doIt() throws Exception
|
||||||
{
|
{
|
||||||
if (log.isLoggable(Level.INFO)) log.info("M_Warehouse_ID=" + p_M_Warehouse_ID
|
if (log.isLoggable(Level.INFO)) log.info("M_Warehouse_IDs=" + Arrays.toString(p_M_Warehouse_IDs)
|
||||||
+ ",C_Currency_ID=" + p_C_Currency_ID
|
+ ",C_Currency_ID=" + p_C_Currency_ID
|
||||||
+ ",DateValue=" + p_DateValue
|
+ ",DateValue=" + p_DateValue
|
||||||
+ ",M_PriceList_Version_ID=" + p_M_PriceList_Version_ID
|
+ ",M_PriceList_Version_ID=" + p_M_PriceList_Version_ID
|
||||||
+ ",M_CostElement_ID=" + p_M_CostElement_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)
|
// Delete (just to be sure)
|
||||||
StringBuilder sql = new StringBuilder ("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID=");
|
final String sql0 = "DELETE FROM T_InventoryValue WHERE AD_PInstance_ID=?";
|
||||||
sql.append(getAD_PInstance_ID());
|
int no = DB.executeUpdateEx(sql0, new Object[] {getAD_PInstance_ID()}, get_TrxName());
|
||||||
int no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
|
||||||
|
MClient c = MClient.get(getCtx(), getAD_Client_ID());
|
||||||
|
MAcctSchema as = c.getAcctSchema();
|
||||||
|
String msg = "";
|
||||||
|
|
||||||
|
if (p_M_Warehouse_IDs == null) // process all warehouses
|
||||||
|
p_M_Warehouse_IDs = DB.getIDsEx(get_TrxName(), "SELECT M_Warehouse_ID FROM M_Warehouse WHERE AD_Client_ID=? AND IsActive='Y'", getAD_Client_ID());
|
||||||
|
|
||||||
|
for (int l_M_Warehouse_ID: p_M_Warehouse_IDs) {
|
||||||
|
MWarehouse wh = MWarehouse.get(getCtx(), l_M_Warehouse_ID);
|
||||||
|
|
||||||
// Insert Standard Costs
|
// Insert Standard Costs
|
||||||
sql = new StringBuilder ("INSERT INTO T_InventoryValue ")
|
final String sql1 = "INSERT INTO T_InventoryValue "
|
||||||
.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,")
|
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
|
||||||
.append(" AD_Client_ID, AD_Org_ID, CostStandard) ")
|
+ " AD_Client_ID, AD_Org_ID, CostStandard, T_InventoryValue_UU) "
|
||||||
.append("SELECT ").append(getAD_PInstance_ID())
|
+ "SELECT ? "
|
||||||
.append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,")
|
+ ", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
|
||||||
.append(" w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice ")
|
+ " w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice, generate_UUID() "
|
||||||
.append("FROM M_Warehouse w")
|
+ "FROM M_Warehouse w"
|
||||||
.append(" INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)")
|
+ " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
|
||||||
.append(" INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)")
|
+ " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
|
||||||
.append(" 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_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))"
|
||||||
.append(" INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') ")
|
+ " INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') "
|
||||||
.append("WHERE w.M_Warehouse_ID=").append(p_M_Warehouse_ID);
|
+ "WHERE w.M_Warehouse_ID=?";
|
||||||
int noInsertStd = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
int noInsertStd = DB.executeUpdateEx(sql1, new Object[] {getAD_PInstance_ID(), l_M_Warehouse_ID}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Inserted Std=" + noInsertStd);
|
if (log.isLoggable(Level.FINE)) log.fine("Inserted Std=" + noInsertStd);
|
||||||
|
|
||||||
// Insert addl Costs
|
// Insert addl Costs
|
||||||
int noInsertCost = 0;
|
int noInsertCost = 0;
|
||||||
if (p_M_CostElement_ID != 0)
|
if (p_M_CostElement_ID != 0)
|
||||||
{
|
{
|
||||||
sql = new StringBuilder ("INSERT INTO T_InventoryValue ")
|
final String sql2 = "INSERT INTO T_InventoryValue "
|
||||||
.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,")
|
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
|
||||||
.append(" AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID) ")
|
+ " AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID, T_InventoryValue_UU) "
|
||||||
.append("SELECT ").append(getAD_PInstance_ID())
|
+ "SELECT ?"
|
||||||
.append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,")
|
+ ", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
|
||||||
.append(" w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID ")
|
+ " w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID, generate_UUID() "
|
||||||
.append("FROM M_Warehouse w")
|
+ "FROM M_Warehouse w"
|
||||||
.append(" INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)")
|
+ " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
|
||||||
.append(" INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)")
|
+ " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
|
||||||
.append(" 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_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)) "
|
||||||
.append("WHERE w.M_Warehouse_ID=").append(p_M_Warehouse_ID)
|
+ "WHERE w.M_Warehouse_ID=?"
|
||||||
.append(" AND c.M_CostElement_ID=").append(p_M_CostElement_ID)
|
+ " AND c.M_CostElement_ID=?"
|
||||||
.append(" AND NOT EXISTS (SELECT * FROM T_InventoryValue iv ")
|
+ " AND NOT EXISTS (SELECT * FROM T_InventoryValue iv "
|
||||||
.append("WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID())
|
+ "WHERE iv.AD_PInstance_ID=?"
|
||||||
.append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID")
|
+ " AND iv.M_Warehouse_ID=w.M_Warehouse_ID"
|
||||||
.append(" AND iv.M_Product_ID=c.M_Product_ID")
|
+ " AND iv.M_Product_ID=c.M_Product_ID"
|
||||||
.append(" AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)");
|
+ " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)";
|
||||||
noInsertCost = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
noInsertCost = DB.executeUpdateEx(sql2.toString(), new Object[] {getAD_PInstance_ID(), l_M_Warehouse_ID, p_M_CostElement_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Inserted Cost=" + noInsertCost);
|
if (log.isLoggable(Level.FINE)) log.fine("Inserted Cost=" + noInsertCost);
|
||||||
// Update Std Cost Records
|
// Update Std Cost Records
|
||||||
sql = new StringBuilder ("UPDATE T_InventoryValue iv ")
|
final String sql3 = "UPDATE T_InventoryValue iv "
|
||||||
.append("SET (Cost, M_CostElement_ID)=")
|
+ "SET (Cost, M_CostElement_ID)="
|
||||||
.append("(SELECT c.CurrentCostPrice, c.M_CostElement_ID ")
|
+ "(SELECT c.CurrentCostPrice, c.M_CostElement_ID "
|
||||||
.append("FROM M_Warehouse w")
|
+ "FROM M_Warehouse w"
|
||||||
.append(" INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)")
|
+ " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
|
||||||
.append(" INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)")
|
+ " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
|
||||||
.append(" INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID")
|
+ " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID"
|
||||||
.append(" AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) ")
|
+ " AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) "
|
||||||
.append("WHERE c.M_CostElement_ID=").append(p_M_CostElement_ID)
|
+ "WHERE c.M_CostElement_ID=?"
|
||||||
.append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID")
|
+ " AND iv.M_Warehouse_ID=w.M_Warehouse_ID"
|
||||||
.append(" AND iv.M_Product_ID=c.M_Product_ID")
|
+ " AND iv.M_Product_ID=c.M_Product_ID"
|
||||||
.append(" AND iv.AD_PInstance_ID=? ")
|
+ " AND iv.AD_PInstance_ID=? "
|
||||||
.append(" AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID) ")
|
+ " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID) "
|
||||||
.append("WHERE EXISTS (SELECT * FROM T_InventoryValue ivv ")
|
+ "WHERE M_Warehouse_ID=? AND EXISTS (SELECT * FROM T_InventoryValue ivv "
|
||||||
.append("WHERE ivv.AD_PInstance_ID=").append(getAD_PInstance_ID())
|
+ "WHERE ivv.AD_PInstance_ID=?"
|
||||||
.append(" AND ivv.M_CostElement_ID IS NULL)");
|
+ " AND ivv.M_CostElement_ID IS NULL"
|
||||||
int noUpdatedCost = DB.executeUpdateEx(sql.toString(), new Object[] {getAD_PInstance_ID()}, get_TrxName());
|
+ " AND ivv.M_Warehouse_ID=?)";
|
||||||
|
int noUpdatedCost = DB.executeUpdateEx(sql3, new Object[] {p_M_CostElement_ID, getAD_PInstance_ID(), l_M_Warehouse_ID, getAD_PInstance_ID(), l_M_Warehouse_ID}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Updated Cost=" + noUpdatedCost);
|
if (log.isLoggable(Level.FINE)) log.fine("Updated Cost=" + noUpdatedCost);
|
||||||
}
|
}
|
||||||
if ((noInsertStd+noInsertCost) == 0)
|
if ((noInsertStd+noInsertCost) == 0)
|
||||||
return "No Costs found";
|
return "No Costs found in warehouse " + wh.getName();
|
||||||
|
|
||||||
// Update Constants
|
// Update Constants
|
||||||
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
|
Timestamp l_DateValue = new Timestamp(TimeUtil.addDays(TimeUtil.getDay(p_DateValue), 1).getTime() - 1); // 23:59:59 from param date
|
||||||
String myDate = p_DateValue.toString();
|
final String sql4 = "UPDATE T_InventoryValue SET DateValue=?,"
|
||||||
sql = new StringBuilder ("UPDATE T_InventoryValue SET DateValue=");
|
+ "M_PriceList_Version_ID=?,"
|
||||||
if (DB.isPostgreSQL())
|
+ "C_Currency_ID=?"
|
||||||
sql.append("TO_TIMESTAMP('");
|
+ " WHERE AD_PInstance_ID=? AND M_Warehouse_ID=?";
|
||||||
else
|
no = DB.executeUpdateEx(sql4.toString(), new Object[] {l_DateValue, p_M_PriceList_Version_ID, p_C_Currency_ID, getAD_PInstance_ID(), l_M_Warehouse_ID}, get_TrxName());
|
||||||
sql.append("TO_DATE('");
|
|
||||||
sql.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=").append(getAD_PInstance_ID());
|
|
||||||
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Constants=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("Constants=" + no);
|
||||||
|
|
||||||
// Get current QtyOnHand with ASI
|
// Get current QtyOnHand with ASI
|
||||||
sql = new StringBuilder ("UPDATE T_InventoryValue iv SET QtyOnHand = ")
|
final String sql5 = "UPDATE T_InventoryValue iv SET QtyOnHand = "
|
||||||
.append("(SELECT SUM(QtyOnHand) FROM M_StorageOnHand s")
|
+ "(SELECT SUM(QtyOnHand) FROM M_StorageOnHand s"
|
||||||
.append(" INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) ")
|
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
|
||||||
.append("WHERE iv.M_Product_ID=s.M_Product_ID")
|
+ "WHERE iv.M_Product_ID=s.M_Product_ID"
|
||||||
.append(" AND iv.M_Warehouse_ID=l.M_Warehouse_ID")
|
+ " AND iv.M_Warehouse_ID=l.M_Warehouse_ID"
|
||||||
.append(" AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) ")
|
+ " AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) "
|
||||||
.append("WHERE AD_PInstance_ID=").append(getAD_PInstance_ID())
|
+ "WHERE M_Warehouse_ID=? AND AD_PInstance_ID=?"
|
||||||
.append(" AND iv.M_AttributeSetInstance_ID<>0");
|
+ " AND iv.M_AttributeSetInstance_ID<>0";
|
||||||
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
no = DB.executeUpdateEx(sql5, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("QtHand with ASI=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("QtHand with ASI=" + no);
|
||||||
// Get current QtyOnHand without ASI
|
// Get current QtyOnHand without ASI
|
||||||
sql = new StringBuilder ("UPDATE T_InventoryValue iv SET QtyOnHand = ")
|
final String sql6 = "UPDATE T_InventoryValue iv SET QtyOnHand = "
|
||||||
.append("(SELECT SUM(QtyOnHand) FROM M_StorageOnHand s")
|
+ "(SELECT SUM(QtyOnHand) FROM M_StorageOnHand s"
|
||||||
.append(" INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) ")
|
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
|
||||||
.append("WHERE iv.M_Product_ID=s.M_Product_ID")
|
+ "WHERE iv.M_Product_ID=s.M_Product_ID"
|
||||||
.append(" AND iv.M_Warehouse_ID=l.M_Warehouse_ID) ")
|
+ " AND iv.M_Warehouse_ID=l.M_Warehouse_ID) "
|
||||||
.append("WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID())
|
+ "WHERE iv.M_Warehouse_ID=? AND iv.AD_PInstance_ID=?"
|
||||||
.append(" AND iv.M_AttributeSetInstance_ID=0");
|
+ " AND iv.M_AttributeSetInstance_ID=0";
|
||||||
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
no = DB.executeUpdateEx(sql6, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("QtHand w/o ASI=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("QtHand w/o ASI=" + no);
|
||||||
|
|
||||||
// Adjust for Valuation Date
|
// Adjust for Valuation Date
|
||||||
sql = new StringBuilder("UPDATE T_InventoryValue iv ")
|
final String sql7 = "UPDATE T_InventoryValue iv "
|
||||||
.append("SET QtyOnHand=")
|
+ "SET QtyOnHand="
|
||||||
.append("(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) ")
|
+ "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
|
||||||
.append("FROM M_Transaction t")
|
+ "FROM M_Transaction t"
|
||||||
.append(" INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) ")
|
+ " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
|
||||||
.append("WHERE t.M_Product_ID=iv.M_Product_ID")
|
+ "WHERE t.M_Product_ID=iv.M_Product_ID"
|
||||||
.append(" AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID")
|
+ " AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID"
|
||||||
.append(" AND t.MovementDate > iv.DateValue")
|
+ " AND t.MovementDate > iv.DateValue"
|
||||||
.append(" AND l.M_Warehouse_ID=iv.M_Warehouse_ID) ")
|
+ " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
|
||||||
.append("WHERE iv.M_AttributeSetInstance_ID<>0" )
|
+ "WHERE iv.M_AttributeSetInstance_ID<>0"
|
||||||
.append(" AND iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
|
+ " AND iv.M_Warehouse_ID=? AND iv.AD_PInstance_ID=?";
|
||||||
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
no = DB.executeUpdateEx(sql7, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Update with ASI=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("Update with ASI=" + no);
|
||||||
//
|
//
|
||||||
sql = new StringBuilder("UPDATE T_InventoryValue iv ")
|
final String sql8 = "UPDATE T_InventoryValue iv "
|
||||||
.append("SET QtyOnHand=")
|
+ "SET QtyOnHand="
|
||||||
.append("(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) ")
|
+ "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
|
||||||
.append("FROM M_Transaction t")
|
+ "FROM M_Transaction t"
|
||||||
.append(" INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) ")
|
+ " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
|
||||||
.append("WHERE t.M_Product_ID=iv.M_Product_ID")
|
+ "WHERE t.M_Product_ID=iv.M_Product_ID"
|
||||||
.append(" AND t.MovementDate > iv.DateValue")
|
+ " AND t.MovementDate > iv.DateValue"
|
||||||
.append(" AND l.M_Warehouse_ID=iv.M_Warehouse_ID) ")
|
+ " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
|
||||||
.append("WHERE iv.M_AttributeSetInstance_ID=0 ")
|
+ "WHERE iv.M_AttributeSetInstance_ID=0 "
|
||||||
.append("AND iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
|
+ "AND iv.M_Warehouse_ID=? AND iv.AD_PInstance_ID=?";
|
||||||
|
no = DB.executeUpdateEx(sql8, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
no = DB.executeUpdateEx(sql.toString(), get_TrxName());
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Update w/o ASI=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("Update w/o ASI=" + no);
|
||||||
|
|
||||||
// Delete Records w/o OnHand Qty
|
// Delete Records w/o OnHand Qty
|
||||||
sql = new StringBuilder("DELETE FROM T_InventoryValue ")
|
final String sql9 = "DELETE FROM T_InventoryValue "
|
||||||
.append("WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND AD_PInstance_ID=").append(getAD_PInstance_ID());
|
+ "WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND M_Warehouse_ID=? AND AD_PInstance_ID=?";
|
||||||
int noQty = DB.executeUpdateEx (sql.toString(), get_TrxName());
|
int noQty = DB.executeUpdateEx (sql9, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("NoQty Deleted=" + noQty);
|
if (log.isLoggable(Level.FINE)) log.fine("NoQty Deleted=" + noQty);
|
||||||
|
|
||||||
// Update Prices
|
// Update Prices
|
||||||
sql = new StringBuilder("UPDATE T_InventoryValue iv ")
|
final String sql10 = "UPDATE T_InventoryValue iv "
|
||||||
.append("SET PricePO = ")
|
+ "SET PricePO = "
|
||||||
.append("(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))")
|
+ "(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))"
|
||||||
.append(" FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID")
|
+ " FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID"
|
||||||
.append(" AND po.IsCurrentVendor='Y'), ")
|
+ " AND po.IsCurrentVendor='Y'), "
|
||||||
.append("PriceList = ")
|
+ "PriceList = "
|
||||||
.append("(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)")
|
+ "(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
|
||||||
.append(" FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp")
|
+ " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
|
||||||
.append(" WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID")
|
+ " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
|
||||||
.append(" AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID")
|
+ " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
|
||||||
.append(" AND plv.M_PriceList_ID=pl.M_PriceList_ID), ")
|
+ " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
|
||||||
.append("PriceStd = ")
|
+ "PriceStd = "
|
||||||
.append("(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)")
|
+ "(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
|
||||||
.append(" FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp")
|
+ " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
|
||||||
.append(" WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID")
|
+ " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
|
||||||
.append(" AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID")
|
+ " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
|
||||||
.append(" AND plv.M_PriceList_ID=pl.M_PriceList_ID), ")
|
+ " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
|
||||||
.append("PriceLimit = ")
|
+ "PriceLimit = "
|
||||||
.append("(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)")
|
+ "(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
|
||||||
.append(" FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp")
|
+ " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
|
||||||
.append(" WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID")
|
+ " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
|
||||||
.append(" AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID")
|
+ " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
|
||||||
.append(" AND plv.M_PriceList_ID=pl.M_PriceList_ID)")
|
+ " AND plv.M_PriceList_ID=pl.M_PriceList_ID)"
|
||||||
.append(" WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
|
+ " WHERE iv.M_Warehouse_ID=? AND iv.AD_PInstance_ID=?";
|
||||||
|
no = DB.executeUpdateEx (sql10, new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
no = DB.executeUpdateEx (sql.toString(), get_TrxName());
|
|
||||||
String msg = "";
|
|
||||||
if (no == 0)
|
if (no == 0)
|
||||||
msg = "No Prices";
|
msg = msg + " / No Prices in warehouse " + wh.getName();
|
||||||
|
|
||||||
// Convert if different Currency
|
// Convert if different Currency
|
||||||
if (as.getC_Currency_ID() != p_C_Currency_ID)
|
if (as.getC_Currency_ID() != p_C_Currency_ID)
|
||||||
{
|
{
|
||||||
sql = new StringBuilder ("UPDATE T_InventoryValue iv ")
|
final String sql11 = "UPDATE T_InventoryValue iv "
|
||||||
.append("SET CostStandard= ")
|
+ "SET CostStandard= "
|
||||||
.append("(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) ")
|
+ "(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
|
||||||
.append("FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=").append(as.getC_AcctSchema_ID()).append("),")
|
+ "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=?),"
|
||||||
.append(" Cost= ")
|
+ " Cost= "
|
||||||
.append("(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) ")
|
+ "(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
|
||||||
.append("FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=").append(as.getC_AcctSchema_ID()).append(") ")
|
+ "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=?) "
|
||||||
.append("WHERE iv.AD_PInstance_ID=").append(getAD_PInstance_ID());
|
+ "WHERE iv.M_Warehouse_ID=? AND iv.AD_PInstance_ID=?";
|
||||||
no = DB.executeUpdateEx (sql.toString(), get_TrxName());
|
no = DB.executeUpdateEx (sql11, new Object[] {as.getC_AcctSchema_ID(), as.getC_AcctSchema_ID(), l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Converted=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("Converted=" + no);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Values
|
// Update Values
|
||||||
StringBuilder dbeux = new StringBuilder("UPDATE T_InventoryValue SET ")
|
final String dbeux = "UPDATE T_InventoryValue SET "
|
||||||
.append("PricePOAmt = QtyOnHand * PricePO, ")
|
+ "PricePOAmt = QtyOnHand * PricePO, "
|
||||||
.append("PriceListAmt = QtyOnHand * PriceList, ")
|
+ "PriceListAmt = QtyOnHand * PriceList, "
|
||||||
.append("PriceStdAmt = QtyOnHand * PriceStd, ")
|
+ "PriceStdAmt = QtyOnHand * PriceStd, "
|
||||||
.append("PriceLimitAmt = QtyOnHand * PriceLimit, ")
|
+ "PriceLimitAmt = QtyOnHand * PriceLimit, "
|
||||||
.append("CostStandardAmt = QtyOnHand * CostStandard, ")
|
+ "CostStandardAmt = QtyOnHand * CostStandard, "
|
||||||
.append("CostAmt = QtyOnHand * Cost ")
|
+ "CostAmt = QtyOnHand * Cost "
|
||||||
.append("WHERE AD_PInstance_ID=").append(getAD_PInstance_ID()
|
+ "WHERE M_Warehouse_ID=? AND AD_PInstance_ID=?";
|
||||||
);
|
no = DB.executeUpdateEx(dbeux.toString(), new Object[] {l_M_Warehouse_ID, getAD_PInstance_ID()}, get_TrxName());
|
||||||
no = DB.executeUpdateEx(dbeux.toString(), get_TrxName());
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Calculation=" + no);
|
if (log.isLoggable(Level.FINE)) log.fine("Calculation=" + no);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
return msg;
|
return "@OK@";
|
||||||
} // doIt
|
} // doIt
|
||||||
|
|
||||||
} // InventoryValue
|
} // InventoryValue
|
||||||
|
|
Loading…
Reference in New Issue