Bring in Manufacturing Light code from Adaxa / Paul Bowden
This commit is contained in:
parent
32dfad5dd7
commit
8c40f00c5a
|
@ -25,6 +25,8 @@ import org.compiere.util.Env;
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: CalloutProduction.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
* @version $Id: CalloutProduction.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||||
|
*
|
||||||
|
* @contrib Paul Bowden (adaxa) set locator from product
|
||||||
*/
|
*/
|
||||||
public class CalloutProduction extends CalloutEngine
|
public class CalloutProduction extends CalloutEngine
|
||||||
{
|
{
|
||||||
|
@ -44,6 +46,7 @@ public class CalloutProduction extends CalloutEngine
|
||||||
Integer M_Product_ID = (Integer)value;
|
Integer M_Product_ID = (Integer)value;
|
||||||
if (M_Product_ID == null || M_Product_ID.intValue() == 0)
|
if (M_Product_ID == null || M_Product_ID.intValue() == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
// Set Attribute
|
// Set Attribute
|
||||||
if (Env.getContextAsInt(ctx, WindowNo, Env.TAB_INFO, "M_Product_ID") == M_Product_ID.intValue()
|
if (Env.getContextAsInt(ctx, WindowNo, Env.TAB_INFO, "M_Product_ID") == M_Product_ID.intValue()
|
||||||
&& Env.getContextAsInt(ctx, WindowNo, Env.TAB_INFO, "M_AttributeSetInstance_ID") != 0)
|
&& Env.getContextAsInt(ctx, WindowNo, Env.TAB_INFO, "M_AttributeSetInstance_ID") != 0)
|
||||||
|
@ -54,6 +57,14 @@ public class CalloutProduction extends CalloutEngine
|
||||||
{
|
{
|
||||||
mTab.setValue("M_AttributeSetInstance_ID", null);
|
mTab.setValue("M_AttributeSetInstance_ID", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MProduct product = MProduct.get(ctx, M_Product_ID);
|
||||||
|
if ( product != null )
|
||||||
|
{
|
||||||
|
if ( product.getM_Locator_ID() > 0)
|
||||||
|
mTab.setValue("M_Locator_ID", product.getM_Locator_ID());
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
} // product
|
} // product
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class M_Production_Run extends SvrProcess {
|
||||||
for (X_M_ProductionPlan pp :lines)
|
for (X_M_ProductionPlan pp :lines)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!production.isCreated())
|
if (!"Y".equals(production.getIsCreated()) )
|
||||||
{
|
{
|
||||||
int line = 100;
|
int line = 100;
|
||||||
int no = DB.executeUpdateEx("DELETE M_ProductionLine WHERE M_ProductionPlan_ID = ?", new Object[]{pp.getM_ProductionPlan_ID()},get_TrxName());
|
int no = DB.executeUpdateEx("DELETE M_ProductionLine WHERE M_ProductionPlan_ID = ?", new Object[]{pp.getM_ProductionPlan_ID()},get_TrxName());
|
||||||
|
@ -184,9 +184,9 @@ public class M_Production_Run extends SvrProcess {
|
||||||
}
|
}
|
||||||
} // Production Plan
|
} // Production Plan
|
||||||
|
|
||||||
if(!production.isCreated())
|
if(!"Y".equals(production.getIsCreated()) )
|
||||||
{
|
{
|
||||||
production.setIsCreated(true);
|
production.setIsCreated("Y");
|
||||||
production.saveEx();
|
production.saveEx();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -620,12 +620,12 @@ public class DocLine
|
||||||
} // isProductionBOM
|
} // isProductionBOM
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Production Plan
|
* Get Production Header
|
||||||
* @return M_ProductionPlan_ID
|
* @return M_Production_ID
|
||||||
*/
|
*/
|
||||||
public int getM_ProductionPlan_ID()
|
public int getM_Production_ID()
|
||||||
{
|
{
|
||||||
int index = p_po.get_ColumnIndex("M_ProductionPlan_ID");
|
int index = p_po.get_ColumnIndex("M_Production_ID");
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
Integer ii = (Integer)p_po.get_Value(index);
|
Integer ii = (Integer)p_po.get_Value(index);
|
||||||
|
@ -633,7 +633,7 @@ public class DocLine
|
||||||
return ii.intValue();
|
return ii.intValue();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} // getM_ProductionPlan_ID
|
} // getM_Production_ID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Order Line Reference
|
* Get Order Line Reference
|
||||||
|
|
|
@ -23,7 +23,9 @@ import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.model.MAccount;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
|
import org.compiere.model.MAcctSchemaDefault;
|
||||||
import org.compiere.model.MCostDetail;
|
import org.compiere.model.MCostDetail;
|
||||||
import org.compiere.model.ProductCost;
|
import org.compiere.model.ProductCost;
|
||||||
import org.compiere.model.X_M_Production;
|
import org.compiere.model.X_M_Production;
|
||||||
|
@ -79,30 +81,16 @@ public class Doc_Production extends Doc
|
||||||
{
|
{
|
||||||
ArrayList<DocLine> list = new ArrayList<DocLine>();
|
ArrayList<DocLine> list = new ArrayList<DocLine>();
|
||||||
// Production
|
// Production
|
||||||
// -- ProductionPlan
|
// -- ProductionLine - the real level
|
||||||
// -- -- ProductionLine - the real level
|
|
||||||
String sqlPP = "SELECT * FROM M_ProductionPlan pp "
|
|
||||||
+ "WHERE pp.M_Production_ID=? "
|
|
||||||
+ "ORDER BY pp.Line";
|
|
||||||
String sqlPL = "SELECT * FROM M_ProductionLine pl "
|
String sqlPL = "SELECT * FROM M_ProductionLine pl "
|
||||||
+ "WHERE pl.M_ProductionPlan_ID=? "
|
+ "WHERE pl.M_Production_ID=? "
|
||||||
+ "ORDER BY pl.Line";
|
+ "ORDER BY pl.Line";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmtPP = DB.prepareStatement(sqlPP, getTrxName());
|
|
||||||
pstmtPP.setInt(1, get_ID());
|
|
||||||
ResultSet rsPP = pstmtPP.executeQuery();
|
|
||||||
//
|
|
||||||
while (rsPP.next())
|
|
||||||
{
|
|
||||||
int M_Product_ID = rsPP.getInt("M_Product_ID");
|
|
||||||
int M_ProductionPlan_ID = rsPP.getInt("M_ProductionPlan_ID");
|
|
||||||
//
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PreparedStatement pstmtPL = DB.prepareStatement(sqlPL, getTrxName());
|
PreparedStatement pstmtPL = DB.prepareStatement(sqlPL, getTrxName());
|
||||||
pstmtPL.setInt(1, M_ProductionPlan_ID);
|
pstmtPL.setInt(1,get_ID());
|
||||||
ResultSet rsPL = pstmtPL.executeQuery();
|
ResultSet rsPL = pstmtPL.executeQuery();
|
||||||
while (rsPL.next())
|
while (rsPL.next())
|
||||||
{
|
{
|
||||||
|
@ -115,7 +103,7 @@ public class Doc_Production extends Doc
|
||||||
DocLine docLine = new DocLine (line, this);
|
DocLine docLine = new DocLine (line, this);
|
||||||
docLine.setQty (line.getMovementQty(), false);
|
docLine.setQty (line.getMovementQty(), false);
|
||||||
// Identify finished BOM Product
|
// Identify finished BOM Product
|
||||||
docLine.setProductionBOM(line.getM_Product_ID() == M_Product_ID);
|
docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID());
|
||||||
//
|
//
|
||||||
log.fine(docLine.toString());
|
log.fine(docLine.toString());
|
||||||
list.add (docLine);
|
list.add (docLine);
|
||||||
|
@ -127,15 +115,7 @@ public class Doc_Production extends Doc
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sqlPL, ee);
|
log.log(Level.SEVERE, sqlPL, ee);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rsPP.close();
|
|
||||||
pstmtPP.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sqlPP, e);
|
|
||||||
}
|
|
||||||
// Return Array
|
|
||||||
DocLine[] dl = new DocLine[list.size()];
|
DocLine[] dl = new DocLine[list.size()];
|
||||||
list.toArray(dl);
|
list.toArray(dl);
|
||||||
return dl;
|
return dl;
|
||||||
|
@ -175,6 +155,7 @@ public class Doc_Production extends Doc
|
||||||
// Calculate Costs
|
// Calculate Costs
|
||||||
BigDecimal costs = null;
|
BigDecimal costs = null;
|
||||||
|
|
||||||
|
/* adaxa-pb don't use cost details
|
||||||
// MZ Goodwill
|
// MZ Goodwill
|
||||||
// if Production CostDetail exist then get Cost from Cost Detail
|
// if Production CostDetail exist then get Cost from Cost Detail
|
||||||
MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?",
|
MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?",
|
||||||
|
@ -182,28 +163,48 @@ public class Doc_Production extends Doc
|
||||||
if (cd != null)
|
if (cd != null)
|
||||||
costs = cd.getAmt();
|
costs = cd.getAmt();
|
||||||
else
|
else
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
if (line.isProductionBOM())
|
int variedHeader = 0;
|
||||||
|
BigDecimal variance = null;
|
||||||
|
costs = line.getProductCosts(as, line.getAD_Org_ID(), false);
|
||||||
|
if (line.isProductionBOM() && line.getM_Production_ID() != variedHeader )
|
||||||
{
|
{
|
||||||
// Get BOM Cost - Sum of individual lines
|
// Get BOM Cost - Sum of individual lines
|
||||||
BigDecimal bomCost = Env.ZERO;
|
BigDecimal bomCost = Env.ZERO;
|
||||||
for (int ii = 0; ii < p_lines.length; ii++)
|
for (int ii = 0; ii < p_lines.length; ii++)
|
||||||
{
|
{
|
||||||
DocLine line0 = p_lines[ii];
|
DocLine line0 = p_lines[ii];
|
||||||
if (line0.getM_ProductionPlan_ID() != line.getM_ProductionPlan_ID())
|
if (line0.getM_Production_ID() != line.getM_Production_ID())
|
||||||
continue;
|
continue;
|
||||||
|
//pb changed this 20/10/06
|
||||||
if (!line0.isProductionBOM())
|
if (!line0.isProductionBOM())
|
||||||
bomCost = bomCost.add(line0.getProductCosts(as, line.getAD_Org_ID(), false));
|
bomCost = bomCost.add(line0.getProductCosts(as, line.getAD_Org_ID(), false).setScale(2,BigDecimal.ROUND_HALF_UP));
|
||||||
}
|
}
|
||||||
costs = bomCost.negate();
|
variance = (costs.setScale(2,BigDecimal.ROUND_HALF_UP)).subtract(bomCost.negate());
|
||||||
// [ 1965015 ] Posting not balanced when is producing more than 1 product - Globalqss 2008/06/26
|
//TODO use currency precision instead of hardcoded 2
|
||||||
X_M_ProductionPlan mpp = new X_M_ProductionPlan(getCtx(), line.getM_ProductionPlan_ID(), getTrxName());
|
// get variance account
|
||||||
if (line.getQty() != mpp.getProductionQty()) {
|
int validCombination = MAcctSchemaDefault.get(getCtx(),
|
||||||
// if the line doesn't correspond with the whole qty produced then apply prorate
|
as.get_ID()).getP_RateVariance_Acct();
|
||||||
// costs = costs * line_qty / production_qty
|
MAccount base = MAccount.get(getCtx(), validCombination);
|
||||||
costs = costs.multiply(line.getQty());
|
MAccount account = MAccount.get(getCtx(),as.getAD_Client_ID(),as.getAD_Org_ID(),
|
||||||
costs = costs.divide(mpp.getProductionQty(), as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
|
as.get_ID(), base.getAccount_ID(), 0,0,0,0,0,0,0,0,0,0,0,0,0,0);
|
||||||
}
|
//
|
||||||
|
// only post variance if it's not zero
|
||||||
|
if (variance.compareTo(new BigDecimal("0.00")) != 0)
|
||||||
|
{
|
||||||
|
//post variance
|
||||||
|
fl = fact.createLine(line,
|
||||||
|
account,
|
||||||
|
as.getC_Currency_ID(), variance.negate());
|
||||||
|
fl.setQty(Env.ZERO);
|
||||||
|
if (fl == null)
|
||||||
|
{
|
||||||
|
p_Error = "Couldn't post variance " + line.getLine() + " - " + line;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// costs = bomCost.negate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
costs = line.getProductCosts(as, line.getAD_Org_ID(), false);
|
costs = line.getProductCosts(as, line.getAD_Org_ID(), false);
|
||||||
|
|
Loading…
Reference in New Issue