RollupBillOfMaterial:
* organized imports * fixed indentation
This commit is contained in:
parent
e801453f0d
commit
9426884b5d
|
@ -16,23 +16,24 @@
|
||||||
|
|
||||||
package org.eevolution.process;
|
package org.eevolution.process;
|
||||||
|
|
||||||
import java.util.logging.*;
|
import java.math.BigDecimal;
|
||||||
import java.math.*;
|
import java.util.ArrayList;
|
||||||
import java.sql.*;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.MCost;
|
||||||
import org.compiere.util.*;
|
import org.compiere.model.MCostElement;
|
||||||
import org.compiere.wf.MWorkflow;
|
import org.compiere.model.MCostType;
|
||||||
import org.compiere.process.*;
|
import org.compiere.model.MProduct;
|
||||||
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.process.ProcessInfoParameter;
|
||||||
|
import org.compiere.process.SvrProcess;
|
||||||
|
import org.compiere.util.Env;
|
||||||
import org.eevolution.model.MPPMRP;
|
import org.eevolution.model.MPPMRP;
|
||||||
import org.eevolution.model.MPPProductBOM;
|
import org.eevolution.model.MPPProductBOM;
|
||||||
import org.eevolution.model.MPPProductBOMLine;
|
import org.eevolution.model.MPPProductBOMLine;
|
||||||
import org.eevolution.model.MPPProductPlanning;
|
import org.eevolution.model.MPPProductPlanning;
|
||||||
import org.eevolution.model.QueryDB;
|
|
||||||
|
|
||||||
import com.sun.org.apache.bcel.internal.generic.RETURN;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Roll-UP Bill of Material
|
* Roll-UP Bill of Material
|
||||||
|
@ -42,26 +43,26 @@ import com.sun.org.apache.bcel.internal.generic.RETURN;
|
||||||
*/
|
*/
|
||||||
public class RollupBillOfMaterial extends SvrProcess
|
public class RollupBillOfMaterial extends SvrProcess
|
||||||
{
|
{
|
||||||
/* Organization */
|
/* Organization */
|
||||||
private int p_AD_Org_ID = 0;
|
private int p_AD_Org_ID = 0;
|
||||||
/* Account Schema */
|
/* Account Schema */
|
||||||
private int p_C_AcctSchema_ID = 0;
|
private int p_C_AcctSchema_ID = 0;
|
||||||
/* Cost Type */
|
/* Cost Type */
|
||||||
private int p_M_CostType_ID = 0;
|
private int p_M_CostType_ID = 0;
|
||||||
/* Product */
|
/* Product */
|
||||||
private int p_M_Product_ID = 0;
|
private int p_M_Product_ID = 0;
|
||||||
/* Product Category */
|
/* Product Category */
|
||||||
private int p_M_Product_Category_ID=0;
|
private int p_M_Product_Category_ID=0;
|
||||||
|
|
||||||
|
private int Elementtypeint=0;
|
||||||
|
|
||||||
private int Elementtypeint=0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare - e.g., get Parameters.
|
* Prepare - e.g., get Parameters.
|
||||||
*/
|
*/
|
||||||
protected void prepare()
|
protected void prepare()
|
||||||
{
|
{
|
||||||
ProcessInfoParameter[] para = getParameter();
|
ProcessInfoParameter[] para = getParameter();
|
||||||
|
|
||||||
for (int i = 0; i < para.length; i++)
|
for (int i = 0; i < para.length; i++)
|
||||||
{
|
{
|
||||||
String name = para[i].getParameterName();
|
String name = para[i].getParameterName();
|
||||||
|
@ -70,15 +71,15 @@ public class RollupBillOfMaterial extends SvrProcess
|
||||||
;
|
;
|
||||||
else if (name.equals("AD_Org_ID"))
|
else if (name.equals("AD_Org_ID"))
|
||||||
p_AD_Org_ID = para[i].getParameterAsInt();
|
p_AD_Org_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals(MAcctSchema.COLUMNNAME_C_AcctSchema_ID))
|
else if (name.equals(MAcctSchema.COLUMNNAME_C_AcctSchema_ID))
|
||||||
p_C_AcctSchema_ID = para[i].getParameterAsInt();
|
p_C_AcctSchema_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals(MCostType.COLUMNNAME_M_CostType_ID))
|
else if (name.equals(MCostType.COLUMNNAME_M_CostType_ID))
|
||||||
p_M_CostType_ID = para[i].getParameterAsInt();
|
p_M_CostType_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals(MProduct.COLUMNNAME_M_Product_ID))
|
else if (name.equals(MProduct.COLUMNNAME_M_Product_ID))
|
||||||
p_M_Product_ID = para[i].getParameterAsInt();
|
p_M_Product_ID = para[i].getParameterAsInt();
|
||||||
else if (name.equals(MProduct.COLUMNNAME_M_Product_Category_ID))
|
else if (name.equals(MProduct.COLUMNNAME_M_Product_Category_ID))
|
||||||
p_M_Product_Category_ID = para[i].getParameterAsInt();
|
p_M_Product_Category_ID = para[i].getParameterAsInt();
|
||||||
else
|
else
|
||||||
log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name);
|
log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name);
|
||||||
}
|
}
|
||||||
} // prepare
|
} // prepare
|
||||||
|
@ -88,155 +89,155 @@ public class RollupBillOfMaterial extends SvrProcess
|
||||||
* @return info
|
* @return info
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected String doIt() throws Exception
|
protected String doIt() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
int m_LowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
|
int m_LowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
|
||||||
// Cost Roll-up for all levels
|
// Cost Roll-up for all levels
|
||||||
for (int index = m_LowLevel ; index >= 0 ; index--)
|
for (int index = m_LowLevel ; index >= 0 ; index--)
|
||||||
{
|
{
|
||||||
StringBuffer whereClause = new StringBuffer("AD_Client_ID=? AND LowLevel=? AND ProductType='"+MProduct.PRODUCTTYPE_Item+"'");
|
StringBuffer whereClause = new StringBuffer("AD_Client_ID=? AND LowLevel=? AND ProductType='"+MProduct.PRODUCTTYPE_Item+"'");
|
||||||
|
|
||||||
List<Object> params = new ArrayList<Object>();
|
List<Object> params = new ArrayList<Object>();
|
||||||
params.add(getAD_Client_ID());
|
params.add(getAD_Client_ID());
|
||||||
params.add(m_LowLevel);
|
params.add(m_LowLevel);
|
||||||
if (p_M_Product_ID > 0) {
|
if (p_M_Product_ID > 0) {
|
||||||
whereClause.append(" AND p.M_Product_ID=?");
|
whereClause.append(" AND p.M_Product_ID=?");
|
||||||
params.add(p_M_Product_ID);
|
params.add(p_M_Product_ID);
|
||||||
}
|
}
|
||||||
if (p_M_Product_Category_ID > 0){
|
if (p_M_Product_Category_ID > 0){
|
||||||
whereClause.append(" AND p.M_Product_Category_ID=?");
|
whereClause.append(" AND p.M_Product_Category_ID=?");
|
||||||
params.add(p_M_Product_ID);
|
params.add(p_M_Product_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MProduct> products = new Query(getCtx(),MProduct.Table_Name, whereClause.toString(), get_TrxName())
|
List<MProduct> products = new Query(getCtx(),MProduct.Table_Name, whereClause.toString(), get_TrxName())
|
||||||
.setParameters(params).list();
|
.setParameters(params).list();
|
||||||
|
|
||||||
for (MProduct product : products)
|
for (MProduct product : products)
|
||||||
{
|
{
|
||||||
|
|
||||||
MCost[] costs = MCost.getCosts(getCtx(),getAD_Client_ID(), p_AD_Org_ID , product.getM_Product_ID() , p_M_CostType_ID , p_C_AcctSchema_ID , get_TrxName());
|
MCost[] costs = MCost.getCosts(getCtx(),getAD_Client_ID(), p_AD_Org_ID , product.getM_Product_ID() , p_M_CostType_ID , p_C_AcctSchema_ID , get_TrxName());
|
||||||
for (MCost cost : costs )
|
for (MCost cost : costs )
|
||||||
{
|
{
|
||||||
log.info("Calculate Lower Cost for :"+ product.getName());
|
log.info("Calculate Lower Cost for :"+ product.getName());
|
||||||
MCostElement element = new MCostElement(getCtx(), cost.getM_CostElement_ID(),get_TrxName());
|
MCostElement element = new MCostElement(getCtx(), cost.getM_CostElement_ID(),get_TrxName());
|
||||||
// check if element cost is of Material Type
|
// check if element cost is of Material Type
|
||||||
log.info("Element Cost:"+ element.getName());
|
log.info("Element Cost:"+ element.getName());
|
||||||
if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Material))
|
if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Material))
|
||||||
{
|
{
|
||||||
BigDecimal Material = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Material , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Material = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Material , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
log.info("Material Cost Low Level:" + Material);
|
log.info("Material Cost Low Level:" + Material);
|
||||||
cost.setCurrentCostPriceLL(Material);
|
cost.setCurrentCostPriceLL(Material);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Resource))
|
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Resource))
|
||||||
{
|
{
|
||||||
BigDecimal Labor = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Resource, p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Labor = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Resource, p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
log.info("Labor Cost Low Level:" + Labor);
|
log.info("Labor Cost Low Level:" + Labor);
|
||||||
cost.setCurrentCostPriceLL(Labor);
|
cost.setCurrentCostPriceLL(Labor);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_BurdenMOverhead))
|
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_BurdenMOverhead))
|
||||||
{
|
{
|
||||||
BigDecimal Burder = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_BurdenMOverhead , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Burder = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_BurdenMOverhead , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
log.info("Burden Cost Low Level:" + Burder);
|
log.info("Burden Cost Low Level:" + Burder);
|
||||||
cost.setCurrentCostPriceLL(Burder);
|
cost.setCurrentCostPriceLL(Burder);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Overhead))
|
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Overhead))
|
||||||
{
|
{
|
||||||
BigDecimal Overhead = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Overhead , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Overhead = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Overhead , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
log.info("Overhead Cost Low Level:" + Overhead);
|
log.info("Overhead Cost Low Level:" + Overhead);
|
||||||
cost.setCurrentCostPriceLL(Overhead);
|
cost.setCurrentCostPriceLL(Overhead);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_OutsideProcessing))
|
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_OutsideProcessing))
|
||||||
{
|
{
|
||||||
BigDecimal Subcontract = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_OutsideProcessing , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Subcontract = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_OutsideProcessing , p_AD_Org_ID , product , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
log.info("Subcontract Cost Low Level:" + Subcontract);
|
log.info("Subcontract Cost Low Level:" + Subcontract);
|
||||||
cost.setCurrentCostPriceLL(Subcontract);
|
cost.setCurrentCostPriceLL(Subcontract);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}
|
}
|
||||||
/* TODO Comment for future implementation
|
/* TODO Comment for future implementation
|
||||||
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Distribution))
|
else if (element.getCostElementType().equals(MCostElement.COSTELEMENTTYPE_Distribution))
|
||||||
{
|
{
|
||||||
|
|
||||||
BigDecimal Distribution = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Distribution , p_AD_Org_ID , M_Product_ID , p_M_CostType_ID , p_C_AcctSchema_ID);
|
BigDecimal Distribution = getCurrentCostPriceLL(MCostElement.COSTELEMENTTYPE_Distribution , p_AD_Org_ID , M_Product_ID , p_M_CostType_ID , p_C_AcctSchema_ID);
|
||||||
cost.setCurrentCostPriceLL(Distribution);
|
cost.setCurrentCostPriceLL(Distribution);
|
||||||
cost.saveEx();
|
cost.saveEx();
|
||||||
}*/
|
}*/
|
||||||
} //Costs
|
} //Costs
|
||||||
} //Products
|
} //Products
|
||||||
}
|
}
|
||||||
return "@OK@";
|
return "@OK@";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** get the sum Current Cost Price Level Low for this Cost Element Type
|
|
||||||
* @param CostElementType Cost Element Type (Material,Labor,Overhead,Burden)
|
/** get the sum Current Cost Price Level Low for this Cost Element Type
|
||||||
* @param AD_Org_ID Organization
|
* @param CostElementType Cost Element Type (Material,Labor,Overhead,Burden)
|
||||||
* @param MProduct Product
|
* @param AD_Org_ID Organization
|
||||||
* @param M_CostType_ID Cost Type
|
* @param MProduct Product
|
||||||
* @param C_AcctSchema_ID Account Schema
|
* @param M_CostType_ID Cost Type
|
||||||
* @return CurrentCostPriceLL Sum Current Cost Price Level Low for this Cost Element Type
|
* @param C_AcctSchema_ID Account Schema
|
||||||
*/
|
* @return CurrentCostPriceLL Sum Current Cost Price Level Low for this Cost Element Type
|
||||||
private BigDecimal getCurrentCostPriceLL(String CostElementType , int AD_Org_ID , MProduct product , int M_CostType_ID , int C_AcctSchema_ID)
|
*/
|
||||||
{
|
private BigDecimal getCurrentCostPriceLL(String CostElementType , int AD_Org_ID , MProduct product , int M_CostType_ID , int C_AcctSchema_ID)
|
||||||
log.info("getCurrentCostPriceLL.ElementType"+CostElementType);
|
{
|
||||||
BigDecimal m_cost = Env.ZERO;
|
log.info("getCurrentCostPriceLL.ElementType"+CostElementType);
|
||||||
MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), getAD_Client_ID(), AD_Org_ID , 0 , 0 , product.getM_Product_ID(), get_TrxName());
|
BigDecimal m_cost = Env.ZERO;
|
||||||
|
MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), getAD_Client_ID(), AD_Org_ID , 0 , 0 , product.getM_Product_ID(), get_TrxName());
|
||||||
int PP_Product_BOM_ID = 0;
|
|
||||||
if(pp != null )
|
int PP_Product_BOM_ID = 0;
|
||||||
PP_Product_BOM_ID = pp.getPP_Product_BOM_ID();
|
if(pp != null )
|
||||||
else
|
PP_Product_BOM_ID = pp.getPP_Product_BOM_ID();
|
||||||
PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(getCtx(), product);
|
else
|
||||||
|
PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(getCtx(), product);
|
||||||
if(PP_Product_BOM_ID <= 0)
|
|
||||||
return Env.ZERO;
|
if(PP_Product_BOM_ID <= 0)
|
||||||
|
return Env.ZERO;
|
||||||
MPPProductBOM bom = new MPPProductBOM(getCtx(), PP_Product_BOM_ID , get_TrxName());
|
|
||||||
if (bom == null)
|
MPPProductBOM bom = new MPPProductBOM(getCtx(), PP_Product_BOM_ID , get_TrxName());
|
||||||
return null;
|
if (bom == null)
|
||||||
|
return null;
|
||||||
MPPProductBOMLine[] bomlines = bom.getLines();
|
|
||||||
for (MPPProductBOMLine bomline : bomlines)
|
MPPProductBOMLine[] bomlines = bom.getLines();
|
||||||
{
|
for (MPPProductBOMLine bomline : bomlines)
|
||||||
// get the rate for this resource
|
{
|
||||||
MCost[] costs = MCost.getCosts(getCtx() , getAD_Client_ID(), p_AD_Org_ID , product.getM_Product_ID() , p_M_CostType_ID , p_C_AcctSchema_ID , get_TrxName());
|
// get the rate for this resource
|
||||||
for (MCost cost : costs)
|
MCost[] costs = MCost.getCosts(getCtx() , getAD_Client_ID(), p_AD_Org_ID , product.getM_Product_ID() , p_M_CostType_ID , p_C_AcctSchema_ID , get_TrxName());
|
||||||
{
|
for (MCost cost : costs)
|
||||||
MCostElement element = new MCostElement(getCtx(), cost.getM_CostElement_ID(), get_TrxName());
|
{
|
||||||
// check if element cost is of type Labor
|
MCostElement element = new MCostElement(getCtx(), cost.getM_CostElement_ID(), get_TrxName());
|
||||||
if (element.getCostElementType().equals(CostElementType))
|
// check if element cost is of type Labor
|
||||||
{
|
if (element.getCostElementType().equals(CostElementType))
|
||||||
BigDecimal QtyPercentage = bomline.getQtyBatch().divide(new BigDecimal(100),8,BigDecimal.ROUND_UP);
|
{
|
||||||
BigDecimal QtyBOM = bomline.getQtyBOM();
|
BigDecimal QtyPercentage = bomline.getQtyBatch().divide(new BigDecimal(100),8,BigDecimal.ROUND_UP);
|
||||||
BigDecimal Scrap = bomline.getScrap();
|
BigDecimal QtyBOM = bomline.getQtyBOM();
|
||||||
Scrap = Scrap.divide(new BigDecimal(100),4,BigDecimal.ROUND_UP); //convert to decimal
|
BigDecimal Scrap = bomline.getScrap();
|
||||||
BigDecimal QtyTotal = Env.ZERO;
|
Scrap = Scrap.divide(new BigDecimal(100),4,BigDecimal.ROUND_UP); //convert to decimal
|
||||||
if (bomline.isQtyPercentage())
|
BigDecimal QtyTotal = Env.ZERO;
|
||||||
QtyTotal = QtyPercentage.divide( Env.ONE.subtract(Scrap) , 4 ,BigDecimal.ROUND_HALF_UP );
|
if (bomline.isQtyPercentage())
|
||||||
else
|
QtyTotal = QtyPercentage.divide( Env.ONE.subtract(Scrap) , 4 ,BigDecimal.ROUND_HALF_UP );
|
||||||
QtyTotal = QtyBOM.divide( Env.ONE.subtract(Scrap) , 4 ,BigDecimal.ROUND_HALF_UP );
|
else
|
||||||
|
QtyTotal = QtyBOM.divide( Env.ONE.subtract(Scrap) , 4 ,BigDecimal.ROUND_HALF_UP );
|
||||||
m_cost = m_cost.add(cost.getCurrentCostPriceLL().multiply(QtyTotal));
|
|
||||||
log.info("Cost Element:"+element.getName() + "Total Cost Element:" + m_cost + "QtyPercentage:" + QtyPercentage + "QtyBOM" + QtyBOM) ;
|
m_cost = m_cost.add(cost.getCurrentCostPriceLL().multiply(QtyTotal));
|
||||||
}
|
log.info("Cost Element:"+element.getName() + "Total Cost Element:" + m_cost + "QtyPercentage:" + QtyPercentage + "QtyBOM" + QtyBOM) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Try find planning Data for this product and get % Yield to calculate cost
|
}
|
||||||
MPPProductPlanning pps = MPPProductPlanning.find(getCtx(), getAD_Client_ID() , AD_Org_ID , 0 , 0 , product.getM_Product_ID(), get_TrxName());
|
// Try find planning Data for this product and get % Yield to calculate cost
|
||||||
if (pps != null)
|
MPPProductPlanning pps = MPPProductPlanning.find(getCtx(), getAD_Client_ID() , AD_Org_ID , 0 , 0 , product.getM_Product_ID(), get_TrxName());
|
||||||
{
|
if (pps != null)
|
||||||
int Yield = pps.getYield();
|
{
|
||||||
if(Yield != 0)
|
int Yield = pps.getYield();
|
||||||
{
|
if(Yield != 0)
|
||||||
|
{
|
||||||
BigDecimal DecimalYield = new BigDecimal(Yield/100);
|
BigDecimal DecimalYield = new BigDecimal(Yield/100);
|
||||||
if (!DecimalYield.equals(Env.ZERO))
|
if (!DecimalYield.equals(Env.ZERO))
|
||||||
m_cost = m_cost.divide(DecimalYield, 4 ,BigDecimal.ROUND_HALF_UP);
|
m_cost = m_cost.divide(DecimalYield, 4 ,BigDecimal.ROUND_HALF_UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_cost;
|
return m_cost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue