Refactory and Improve in write code

This commit is contained in:
vpj-cd 2008-08-15 09:19:59 +00:00
parent 1d9d823ec0
commit 7172287be8
3 changed files with 380 additions and 586 deletions

View File

@ -34,6 +34,7 @@ import org.compiere.model.MRequisitionLine;
import org.compiere.model.MResource; import org.compiere.model.MResource;
import org.compiere.model.MResourceType; import org.compiere.model.MResourceType;
import org.compiere.model.MSequence; import org.compiere.model.MSequence;
import org.compiere.model.MTable;
import org.compiere.model.MWarehouse; import org.compiere.model.MWarehouse;
import org.compiere.model.X_C_DocType; import org.compiere.model.X_C_DocType;
import org.compiere.model.X_M_Forecast; import org.compiere.model.X_M_Forecast;
@ -53,14 +54,11 @@ import org.compiere.wf.MWorkflow;
*/ */
public class MPPMRP extends X_PP_MRP public class MPPMRP extends X_PP_MRP
{ {
/** Cache */
//private static CCache s_cache = new CCache ("M_Product_Costing", 20);
/************************************************************************** /**************************************************************************
* Default Constructor * Default Constructor
* @param ctx context * @param ctx context
* @param M_Product_Costing_ID id * @param PP_MRP_ID id
* @param trxName Transaction Name
*/ */
public MPPMRP(Properties ctx, int PP_MRP_ID,String trxName) public MPPMRP(Properties ctx, int PP_MRP_ID,String trxName)
{ {
@ -68,16 +66,6 @@ public class MPPMRP extends X_PP_MRP
if (PP_MRP_ID == 0) if (PP_MRP_ID == 0)
{ {
setDateSimulation(new Timestamp (System.currentTimeMillis())); setDateSimulation(new Timestamp (System.currentTimeMillis()));
/*
setC_AcctSchema_ID(0);
setCostCumAmt();
setCostCumQty();
setCostLLAmt();
setCostTLAmt();
setM_Product_ID();
setM_Warehouse_ID();
setPP_Cost_Element_ID();
stS_Resource_ID();*/
} }
} // MPPMRP } // MPPMRP
@ -99,49 +87,33 @@ public class MPPMRP extends X_PP_MRP
if (!newRecord) if (!newRecord)
return success; return success;
/*MPPProductPlanning pp = MPPProductPlanning.getSupplyWarehouse( Env.getCtx() , getAD_Org_ID() , getM_Product_ID() , getM_Warehouse_ID());
if(pp != null)
{
setS_Resource_ID(pp.getS_Resource_ID());
setPlanner_ID(pp.getPlanner_ID());
} */
return true; return true;
} }
public static int M_ForecastLine(X_M_ForecastLine fl,boolean delete) /**
* Create MRP record based in Forecast Line
* @param X_M_ForecastLine Forecast Line
* @param delete Indicate if this record is delete
*/
public static void M_ForecastLine(X_M_ForecastLine fl,boolean delete)
{ {
String sql = null; String sql = null;
String trxName = fl.get_TrxName(); String trxName = fl.get_TrxName();
Properties m_ctx =fl.getCtx();
if (delete) if (delete)
{ {
sql = "DELETE FROM PP_MRP WHERE M_ForecastLine_ID = "+ fl.getM_ForecastLine_ID() +" AND AD_Client_ID = " + fl.getAD_Client_ID(); sql = "DELETE FROM PP_MRP WHERE M_ForecastLine_ID = "+ fl.getM_ForecastLine_ID() +" AND AD_Client_ID = " + fl.getAD_Client_ID();
DB.executeUpdate(sql, trxName); DB.executeUpdate(sql, trxName);
return 0; return;
} }
MPPMRP mrp = null; MWarehouse[] w = MWarehouse.getForOrg(m_ctx,fl.getAD_Org_ID());
//MPeriod period = new MPeriod(Env.getCtx(),fl.getC_Period_ID(),null); X_M_Forecast f = new X_M_Forecast(m_ctx,fl.getM_Forecast_ID(), trxName);
MWarehouse[] w = MWarehouse.getForOrg(Env.getCtx(),fl.getAD_Org_ID()); String WhereClause = "M_ForecastLine_ID=?";
MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{fl.getM_ForecastLine_ID()}, trxName);
if(mrp!=null)
X_M_Forecast f = new X_M_Forecast(Env.getCtx(),fl.getM_Forecast_ID(), trxName);
sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.M_ForecastLine_ID = ? ");
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, fl.getM_ForecastLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(Env.getCtx(), rs.getInt(1),trxName);
mrp.setAD_Org_ID(fl.getAD_Org_ID()); mrp.setAD_Org_ID(fl.getAD_Org_ID());
mrp.setDescription(f.getDescription()); mrp.setDescription(f.getDescription());
mrp.setName("MRP"); mrp.setName("MRP");
@ -159,10 +131,8 @@ public class MPPMRP extends X_PP_MRP
mrp.setDateOrdered(mrp.getDatePromised()); mrp.setDateOrdered(mrp.getDatePromised());
mrp.setM_Product_ID(fl.getM_Product_ID()); mrp.setM_Product_ID(fl.getM_Product_ID());
int M_Warehouse_ID = fl.getM_Warehouse_ID(); int M_Warehouse_ID = fl.getM_Warehouse_ID();
if(M_Warehouse_ID == 0) if(M_Warehouse_ID == 0)
{ {
//int M_Warehouse_ID = DB.getSQLValue(null,"SELECT M_Warehouse_ID FROM ", fl.getAD_Org_ID());
mrp.setM_Warehouse_ID(w[0].getM_Warehouse_ID()); mrp.setM_Warehouse_ID(w[0].getM_Warehouse_ID());
} }
else else
@ -170,12 +140,11 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Warehouse_ID(M_Warehouse_ID); mrp.setM_Warehouse_ID(M_Warehouse_ID);
} }
mrp.setDocStatus("IP"); mrp.setDocStatus("IP");
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP(Env.getCtx(), 0,trxName); mrp = new MPPMRP(m_ctx, 0,trxName);
mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID()); mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID());
mrp.setAD_Org_ID(fl.getAD_Org_ID()); mrp.setAD_Org_ID(fl.getAD_Org_ID());
mrp.setName("MRP"); mrp.setName("MRP");
@ -195,26 +164,21 @@ public class MPPMRP extends X_PP_MRP
mrp.setDocStatus("IP"); mrp.setDocStatus("IP");
mrp.setOrderType(MPPMRP.ORDERTYPE_Forecast); mrp.setOrderType(MPPMRP.ORDERTYPE_Forecast);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
mrp.save(); mrp.saveEx();
} }
rs.close(); return;
pstmt.close();
} }
catch (SQLException ex)
{ /**
log.log(Level.SEVERE, "doIt - " + sql , ex); * Create MRP record based in Order Line
} * @param MOrderLine
* @param delete Indicate if this record is delete
return mrp.getPP_MRP_ID(); * @return
} */
public static void C_OrderLine(MOrderLine ol, boolean delete)
public static int C_OrderLine(MOrderLine ol, boolean delete)
{ {
Properties m_ctx = ol.getCtx();
String sql = null; String sql = null;
String trxName = ol.getParent().get_TrxName(); String trxName = ol.getParent().get_TrxName();
if (delete) if (delete)
@ -224,28 +188,16 @@ public class MPPMRP extends X_PP_MRP
int PP_Order_ID = DB.getSQLValue(trxName,"SELECT PP_Order_ID FROM PP_Order o WHERE o.AD_Client_ID = ? AND o.C_OrderLine_ID = ? ", ol.getAD_Client_ID(),ol.getC_OrderLine_ID()); int PP_Order_ID = DB.getSQLValue(trxName,"SELECT PP_Order_ID FROM PP_Order o WHERE o.AD_Client_ID = ? AND o.C_OrderLine_ID = ? ", ol.getAD_Client_ID(),ol.getC_OrderLine_ID());
if (PP_Order_ID != -1 ) if (PP_Order_ID != -1 )
{ {
MPPOrder order = new MPPOrder(Env.getCtx(), PP_Order_ID,trxName); MPPOrder order = new MPPOrder(m_ctx, PP_Order_ID,trxName);
if (MPPOrder.DOCSTATUS_Completed != order.getDocStatus() || MPPOrder.DOCSTATUS_Closed != order.getDocStatus()) if (MPPOrder.DOCSTATUS_Completed != order.getDocStatus() || MPPOrder.DOCSTATUS_Closed != order.getDocStatus())
order.delete(true,trxName); order.delete(true,trxName);
} }
return 0; return;
} }
String WhereClause = "AD_Client_ID = ? AND C_OrderLine_ID = ?";
MPPMRP mrp = null; MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),ol.getC_OrderLine_ID()}, trxName);
sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.C_OrderLine_ID = ? "); if(mrp!=null)
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, ol.getC_OrderLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(Env.getCtx(), rs.getInt(1),trxName);
mrp.setDescription(ol.getDescription()); mrp.setDescription(ol.getDescription());
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
@ -256,12 +208,11 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Product_ID(ol.getM_Product_ID()); mrp.setM_Product_ID(ol.getM_Product_ID());
mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID());
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP(Env.getCtx(), 0,trxName); mrp = new MPPMRP(m_ctx, 0,trxName);
mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID()); mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID());
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setDescription(ol.getDescription()); mrp.setDescription(ol.getDescription());
@ -274,7 +225,6 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Product_ID(ol.getM_Product_ID()); mrp.setM_Product_ID(ol.getM_Product_ID());
mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID());
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
if (ol.getParent().isSOTrx()) if (ol.getParent().isSOTrx())
{ {
mrp.setOrderType(MPPMRP.ORDERTYPE_SalesOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_SalesOrder);
@ -285,48 +235,36 @@ public class MPPMRP extends X_PP_MRP
mrp.setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
} }
mrp.save(); mrp.saveEx();
} }
rs.close(); MPPOrder order = (MPPOrder) MTable.get(m_ctx, MPPOrder.Table_ID).getPO("AD_Client_ID = ? AND C_OrderLine_ID = ? ", new Object[]{ol.getAD_Client_ID(),ol.getC_OrderLine_ID()},trxName);
pstmt.close(); if (order == null )
}
catch (SQLException ex)
{ {
log.log(Level.SEVERE, "doIt - " + sql , ex); MProduct product = MProduct.get(m_ctx,ol.getM_Product_ID());
} WhereClause = "AD_Client_ID = ? AND Value = ?";
MPPProductBOM bom = (MPPProductBOM) MTable.get(m_ctx, MPPProductBOM.Table_ID).getPO(WhereClause,new Object[]{ ol.getAD_Client_ID(),product.getValue()}, trxName);
if (bom != null)
int PP_Order_ID = DB.getSQLValue(trxName,"SELECT PP_Order_ID FROM PP_Order o WHERE o.AD_Client_ID = ? AND o.C_OrderLine_ID = ? ", ol.getAD_Client_ID(),ol.getC_OrderLine_ID());
if (PP_Order_ID == -1 )
{ {
MProduct product = MProduct.get(Env.getCtx(),ol.getM_Product_ID()); if (bom.getBOMType().equals(MPPProductBOM.BOMTYPE_Make_To_Order))
int PP_Product_BOM_ID = DB.getSQLValue(trxName,"SELECT PP_Product_BOM_ID FROM PP_Product_BOM bom WHERE bom.AD_Client_ID = ? AND bom.Value = ? ", ol.getAD_Client_ID(),product.getValue());
if (PP_Product_BOM_ID != -1)
{ {
X_PP_Product_BOM bom = new X_PP_Product_BOM(Env.getCtx(),PP_Product_BOM_ID, trxName); WhereClause = "ManufacturingResourceType = 'PT' AND IsManufacturingResource = 'Y' AND AD_Client_ID = ? AND M_Warehouse_ID = ?";
if (bom.getBOMType().equals(bom.BOMTYPE_Make_To_Order)) MResource m_resource = (MResource)MTable.get(m_ctx,MResource.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),ol.getM_Warehouse_ID()}, trxName);
WhereClause = "AD_Client_ID = ? AND Value = ?";
MWorkflow m_workflow = (MWorkflow)MTable.get(m_ctx,MWorkflow.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),product.getValue()}, trxName);
if (m_resource != null && m_workflow != null)
{ {
int S_Resource_ID = DB.getSQLValue(trxName,"SELECT S_Resource_ID FROM S_Resource r WHERE r.ManufacturingResourceType = 'PT' AND r.IsManufacturingResource = 'Y' AND r.AD_Client_ID = ? AND r.M_Warehouse_ID = ? " MDocType[] doc = MDocType.getOfDocBaseType(m_ctx,X_C_DocType.DOCBASETYPE_ManufacturingOrder);
//+ "AND ROWNUM = 1"
, ol.getAD_Client_ID(),ol.getM_Warehouse_ID());
int AD_Workflow_ID = DB.getSQLValue(trxName,"SELECT AD_Workflow_ID FROM AD_Workflow wf WHERE wf.AD_Client_ID = ? AND wf.Value = ? ", ol.getAD_Client_ID(),product.getValue());
if (S_Resource_ID != -1 && AD_Workflow_ID != -1)
{
MDocType[] doc = MDocType.getOfDocBaseType(Env.getCtx(),X_C_DocType.DOCBASETYPE_ManufacturingOrder);
int C_DocType_ID = doc[0].getC_DocType_ID(); int C_DocType_ID = doc[0].getC_DocType_ID();
//int C_DocType_ID = MPPMRP.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder, false); order = new MPPOrder(m_ctx, 0 , trxName);
MPPOrder order = new MPPOrder(Env.getCtx(), 0 , trxName);
order.setC_OrderLine_ID(ol.getC_OrderLine_ID()); order.setC_OrderLine_ID(ol.getC_OrderLine_ID());
order.setDocumentNo(MSequence.getDocumentNo(C_DocType_ID,trxName,true)); order.setDocumentNo(MSequence.getDocumentNo(C_DocType_ID,trxName,true));
order.setS_Resource_ID(S_Resource_ID); order.setS_Resource_ID(m_resource.getS_Resource_ID());
order.setM_Warehouse_ID(ol.getM_Warehouse_ID()); order.setM_Warehouse_ID(ol.getM_Warehouse_ID());
order.setM_Product_ID(ol.getM_Product_ID()); order.setM_Product_ID(ol.getM_Product_ID());
order.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID()); order.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
order.setPP_Product_BOM_ID(PP_Product_BOM_ID); order.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
order.setAD_Workflow_ID(AD_Workflow_ID); order.setAD_Workflow_ID(m_workflow.getAD_Workflow_ID());
//order.setPlanner_ID(SupplyPlanner_ID); //order.setPlanner_ID(SupplyPlanner_ID);
order.setLine(10); order.setLine(10);
order.setQtyDelivered(Env.ZERO); order.setQtyDelivered(Env.ZERO);
@ -334,7 +272,7 @@ public class MPPMRP extends X_PP_MRP
order.setQtyScrap(Env.ZERO); order.setQtyScrap(Env.ZERO);
order.setDateOrdered(ol.getDateOrdered()); order.setDateOrdered(ol.getDateOrdered());
order.setDatePromised(ol.getDatePromised()); order.setDatePromised(ol.getDatePromised());
order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), (MPPMRP.getDays(S_Resource_ID,AD_Workflow_ID, ol.getQtyOrdered())).negate().intValue())); order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), (MPPMRP.getDays(m_ctx,m_resource.getS_Resource_ID(),m_workflow.getAD_Workflow_ID(), ol.getQtyOrdered(),ol.get_TrxName())).negate().intValue()));
order.setDateFinishSchedule(ol.getDatePromised()); order.setDateFinishSchedule(ol.getDatePromised());
order.setQtyEntered(ol.getQtyEntered()); order.setQtyEntered(ol.getQtyEntered());
order.setQtyOrdered(ol.getQtyOrdered()); order.setQtyOrdered(ol.getQtyOrdered());
@ -343,11 +281,11 @@ public class MPPMRP extends X_PP_MRP
order.setProcessed(false); order.setProcessed(false);
order.setC_DocTypeTarget_ID(C_DocType_ID); order.setC_DocTypeTarget_ID(C_DocType_ID);
order.setC_DocType_ID(C_DocType_ID); order.setC_DocType_ID(C_DocType_ID);
order.setPriorityRule(order.PRIORITYRULE_High); order.setPriorityRule(MPPOrder.PRIORITYRULE_High);
order.save(trxName); order.save(trxName);
order.prepareIt(); order.prepareIt();
order.setDocAction(order.DOCSTATUS_Completed); order.setDocAction(MPPOrder.DOCSTATUS_Completed);
order.save(); order.saveEx();
} }
} }
} }
@ -355,18 +293,22 @@ public class MPPMRP extends X_PP_MRP
else else
{ {
MPPOrder order = new MPPOrder(Env.getCtx(), PP_Order_ID , trxName); if (MPPOrder.DOCSTATUS_Completed != order.getDocStatus() || MPPOrder.DOCSTATUS_Closed != order.getDocStatus())
if (order.DOCSTATUS_Completed != order.getDocStatus() || order.DOCSTATUS_Closed != order.getDocStatus())
{ {
order.setQtyEntered(ol.getQtyEntered()); order.setQtyEntered(ol.getQtyEntered());
order.setDatePromised(ol.getDatePromised()); order.setDatePromised(ol.getDatePromised());
order.save(); order.saveEx();
} }
} }
return mrp.getPP_MRP_ID(); return;
} }
/**
* Create MRP record based in Manufacturing Order
* @param MPPOrder Manufacturing Order
* @param delete Indicate if this record is delete
*/
public static void PP_Order(MPPOrder o, boolean delete) public static void PP_Order(MPPOrder o, boolean delete)
{ {
@ -379,24 +321,10 @@ public class MPPMRP extends X_PP_MRP
DB.executeUpdate(sql ,trxName); DB.executeUpdate(sql ,trxName);
return; return;
} }
String WhereClause = "TypeMRP = 'S' AND OrderType='MOP' AND AD_Client_ID=? AND PP_Order_ID = ?";
MPPMRP mrp = (MPPMRP)MTable.get(m_ctx,MPPMRP.Table_ID).getPO(WhereClause, new Object[]{o.getAD_Client_ID() , o.getPP_Order_ID()}, trxName);
sql = new String("SELECT * FROM PP_MRP WHERE TypeMRP = 'S' AND OrderType='MOP' AND PP_Order_ID = ? "); if(mrp != null)
MPPMRP mrp = null;
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql,trxName);
pstmt.setInt(1, o.getPP_Order_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(m_ctx, rs ,trxName);
mrp.setDescription(o.getDescription()); mrp.setDescription(o.getDescription());
mrp.setName(o.getDocumentNo()); mrp.setName(o.getDocumentNo());
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
@ -408,12 +336,11 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID()); mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus()); mrp.setDocStatus(o.getDocStatus());
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP(Env.getCtx(), 0, trxName); mrp = new MPPMRP(m_ctx, 0, trxName);
mrp.setPP_Order_ID(o.getPP_Order_ID()); mrp.setPP_Order_ID(o.getPP_Order_ID());
mrp.setDescription(o.getDescription()); mrp.setDescription(o.getDescription());
mrp.setName(o.getDocumentNo()); mrp.setName(o.getDocumentNo());
@ -428,43 +355,17 @@ public class MPPMRP extends X_PP_MRP
mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
mrp.setDocStatus(o.getDocStatus()); mrp.setDocStatus(o.getDocStatus());
mrp.save(); mrp.saveEx();
} }
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
/*sql = new String("SELECT * FROM PP_Order_BOMLine bl WHERE bl.PP_Order_ID= ? ");
pstmt = null;
try
{
pstmt = DB.prepareStatement (sql,trxName);
pstmt.setInt(1, o.getPP_Order_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next())
{
MPPOrderBOMLine ol = new MPPOrderBOMLine(Env.getCtx(),rs,trxName);
PP_Order_BOMLine(ol,false);
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}*/
return ; return ;
} }
/**
* Create MRP record based in Manufacturing Order BOM Line
* @param MPPOrderBOMLine Order BOM Line
* @param delete indicate if this record is delete
*/
public static void PP_Order_BOMLine(MPPOrderBOMLine obl,boolean delete) public static void PP_Order_BOMLine(MPPOrderBOMLine obl,boolean delete)
{ {
String sql = null; String sql = null;
@ -477,21 +378,11 @@ public class MPPMRP extends X_PP_MRP
return; return;
} }
sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'D' AND mrp.OrderType='MOP' AND mrp.PP_Order_BOMLine_ID = ? "); String WhereClause = "TypeMRP = 'D' AND OrderType='MOP' AND AD_Client_ID=? AND PP_Order_BOMLine_ID = ? ";
MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{obl.getAD_Client_ID(),obl.getPP_Order_BOMLine_ID()}, trxName);
MPPOrder o = obl.getParent(); MPPOrder o = obl.getParent();
MPPMRP mrp = null; if(mrp!=null)
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, obl.getPP_Order_BOMLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(m_ctx , rs,trxName);
mrp.setName(o.getDocumentNo()); mrp.setName(o.getDocumentNo());
mrp.setDescription(o.getDescription()); mrp.setDescription(o.getDescription());
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered())); mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
@ -503,10 +394,9 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID()); mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus()); mrp.setDocStatus(o.getDocStatus());
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP(m_ctx , 0,trxName); mrp = new MPPMRP(m_ctx , 0,trxName);
mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID()); mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID());
@ -524,23 +414,17 @@ public class MPPMRP extends X_PP_MRP
mrp.setDocStatus(o.getDocStatus()); mrp.setDocStatus(o.getDocStatus());
mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
mrp.save(); mrp.saveEx();
} }
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
return; return;
} }
/**
* Create MRP record based in Distribution Order
* @param MDDOrder Distribution Order
* @param delete Indicate if this record is delete
*/
public static void DD_Order(MDDOrder o, boolean delete) public static void DD_Order(MDDOrder o, boolean delete)
{ {
String sql = null; String sql = null;
@ -554,6 +438,11 @@ public class MPPMRP extends X_PP_MRP
} }
} }
/**
* Create MRP record based in Distribution Order Line
* @param MDDOrderLine Distribution Order Line
* @param delete Indicate if this record is delete
*/
public static void DD_Order_Line(MDDOrderLine ol, boolean delete) public static void DD_Order_Line(MDDOrderLine ol, boolean delete)
{ {
String sql = null; String sql = null;
@ -565,22 +454,12 @@ public class MPPMRP extends X_PP_MRP
DB.executeUpdate(sql ,trxName); DB.executeUpdate(sql ,trxName);
return; return;
} }
String whereClause = "TypeMRP = 'D' AND OrderType='DOO' AND AD_Client_ID=? AND DD_OrderLine_ID = ?";
sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'D' AND mrp.OrderType='DOO' AND mrp.DD_OrderLine_ID = ? "); MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName);
MPPMRP mrp = null;
MLocator source = MLocator.get( m_ctx , ol.getM_Locator_ID()); MLocator source = MLocator.get( m_ctx , ol.getM_Locator_ID());
MLocator target = MLocator.get( m_ctx , ol.getM_LocatorTo_ID()); MLocator target = MLocator.get( m_ctx , ol.getM_LocatorTo_ID());
PreparedStatement pstmt = null; if(mrp!=null)
try
{ {
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, ol.getDD_OrderLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(m_ctx , rs, trxName);
mrp.setAD_Org_ID(source.getAD_Org_ID()); mrp.setAD_Org_ID(source.getAD_Org_ID());
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setDescription(ol.getDescription()); mrp.setDescription(ol.getDescription());
@ -590,12 +469,11 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Product_ID(ol.getM_Product_ID()); mrp.setM_Product_ID(ol.getM_Product_ID());
mrp.setM_Warehouse_ID(source.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(source.getM_Warehouse_ID());
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP( m_ctx , 0 ,trxName); mrp = new MPPMRP(m_ctx , 0 ,trxName);
mrp.setAD_Org_ID(source.getAD_Org_ID()); mrp.setAD_Org_ID(source.getAD_Org_ID());
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setDescription(ol.getDescription()); mrp.setDescription(ol.getDescription());
@ -609,33 +487,13 @@ public class MPPMRP extends X_PP_MRP
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
mrp.save(); mrp.saveEx();
} }
whereClause ="TypeMRP='S' AND OrderType='DOO' AND AD_Client_ID=? AND DD_OrderLine_ID = ? ";
rs.close(); mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName);
pstmt.close(); if(mrp!=null)
}
catch (SQLException ex)
{ {
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'S' AND mrp.OrderType='DOO' AND mrp.DD_OrderLine_ID = ? ");
pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, ol.getDD_OrderLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP( m_ctx , rs, trxName);
mrp.setAD_Org_ID(target.getAD_Org_ID()); mrp.setAD_Org_ID(target.getAD_Org_ID());
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setDescription(ol.getDescription()); mrp.setDescription(ol.getDescription());
@ -647,8 +505,7 @@ public class MPPMRP extends X_PP_MRP
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
mrp.save(); mrp.save();
} }
else
if (!records)
{ {
mrp = new MPPMRP( m_ctx , 0,trxName); mrp = new MPPMRP( m_ctx , 0,trxName);
mrp.setAD_Org_ID(target.getAD_Org_ID()); mrp.setAD_Org_ID(target.getAD_Org_ID());
@ -664,50 +521,34 @@ public class MPPMRP extends X_PP_MRP
mrp.setDocStatus(ol.getParent().getDocStatus()); mrp.setDocStatus(ol.getParent().getDocStatus());
mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
mrp.save(); mrp.saveEx();
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
} }
return; return;
} }
/**
public static int M_RequisitionLine( MRequisitionLine rl , boolean delete) * Create MRP record based in Requisition Line
* @param MRequisitionLine Requisition Line
* @param delete Indicate if this record is delete
*/
public static void M_RequisitionLine( MRequisitionLine rl , boolean delete)
{ {
String sql = null; String sql = null;
String trxName = rl.get_TrxName(); String trxName = rl.get_TrxName();
Properties m_ctx = rl.getCtx();
if (delete) if (delete)
{ {
sql = "DELETE FROM PP_MRP WHERE M_RequisitionLine_ID = "+ rl.getM_RequisitionLine_ID() +" AND AD_Client_ID = " + rl.getAD_Client_ID(); sql = "DELETE FROM PP_MRP WHERE M_RequisitionLine_ID = "+ rl.getM_RequisitionLine_ID() +" AND AD_Client_ID = " + rl.getAD_Client_ID();
DB.executeUpdate(sql,trxName); //reorder by hamed DB.executeUpdate(sql,trxName); //reorder by hamed
return 0; return;
} }
sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.M_RequisitionLine_ID = ? "); String whereClause = new String("AD_Client_ID=? AND M_RequisitionLine_ID = ? ");
MRequisition r = new MRequisition(Env.getCtx(), rl.getM_Requisition_ID(),trxName); MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{rl.getAD_Client_ID(),rl.getM_RequisitionLine_ID()}, trxName);
MPPMRP mrp = null; MRequisition r = new MRequisition(m_ctx, rl.getM_Requisition_ID(),trxName);
if(mrp!=null)
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql,trxName);
pstmt.setInt(1, rl.getM_RequisitionLine_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(Env.getCtx(), rs,trxName);
mrp.setName("MRP"); mrp.setName("MRP");
mrp.setDescription(rl.getDescription()); mrp.setDescription(rl.getDescription());
mrp.setQty(rl.getQty()); mrp.setQty(rl.getQty());
@ -718,12 +559,11 @@ public class MPPMRP extends X_PP_MRP
mrp.setM_Product_ID(rl.getM_Product_ID()); mrp.setM_Product_ID(rl.getM_Product_ID());
mrp.setM_Warehouse_ID(r.getM_Warehouse_ID()); mrp.setM_Warehouse_ID(r.getM_Warehouse_ID());
mrp.setDocStatus(r.getDocStatus()); mrp.setDocStatus(r.getDocStatus());
mrp.save(); mrp.saveEx();
} }
else
if (!records)
{ {
mrp = new MPPMRP(Env.getCtx(), 0,trxName); mrp = new MPPMRP(m_ctx, 0,trxName);
mrp.setM_Requisition_ID(rl.getM_Requisition_ID()); mrp.setM_Requisition_ID(rl.getM_Requisition_ID());
mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID()); mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID());
mrp.setName("MRP"); mrp.setName("MRP");
@ -739,117 +579,71 @@ public class MPPMRP extends X_PP_MRP
mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition); mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
mrp.setIsAvailable(true); mrp.setIsAvailable(true);
mrp.save(); mrp.saveEx();
}
return;
} }
rs.close(); /**
pstmt.close(); * Create MRP record based in Requisition
* @param MRequisitio Requisition
} * @param delete Indicate if this record is delete
catch (SQLException ex) */
{ public static void M_Requisition(MRequisition r)
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
return mrp.getPP_MRP_ID();
}
public static int M_Requisition( MRequisition r)
{ {
String trxName = r.get_TrxName(); String trxName = r.get_TrxName();
String sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.M_Requisition_ID = ? "); String WhereClause = "AD_Client_ID=? AND M_Requisition_ID=?";
MPPMRP mrp = (MPPMRP)MTable.get(r.getCtx(),MRequisition.Table_ID).getPO(WhereClause, new Object[]{r.getAD_Client_ID(), r.getM_Requisition_ID()},trxName);
MPPMRP mrp = null; if(mrp!=null)
PreparedStatement pstmt = null;
try
{ {
pstmt = DB.prepareStatement (sql,trxName);
pstmt.setInt(1, r.getM_Requisition_ID());
ResultSet rs = pstmt.executeQuery ();
boolean records = false;
while (rs.next())
{
records = true;
mrp = new MPPMRP(Env.getCtx(), rs ,trxName);
mrp.setDocStatus(r.getDocStatus()); mrp.setDocStatus(r.getDocStatus());
mrp.save(); mrp.saveEx();
} }
return;
rs.close();
pstmt.close();
} }
catch (SQLException ex)
/**
* Get Qty Onhand
* @param AD_Client_ID
* @param M_Warehouse_ID
* @param M_Product_ID
* @return
*/
public static BigDecimal getQtyOnHand(int AD_Client_ID, int M_Warehouse_ID ,int M_Product_ID,String trxName)
{ {
log.log(Level.SEVERE, "doIt - " + sql , ex); String sql = "SELECT SUM(bomQtyOnHand (M_Product_ID ,"+M_Warehouse_ID+",0)) AS OnHand FROM M_Product WHERE AD_Client_ID=? AND M_Product_ID=?";
BigDecimal QtyOnHand = DB.getSQLValueBD(trxName, sql, new Object[]{AD_Client_ID,M_Product_ID});
if (QtyOnHand == null)
QtyOnHand = Env.ZERO;
return QtyOnHand;
} }
return mrp.getPP_MRP_ID(); public static int getMaxLowLevel(Properties ctx, String trxName)
}
public static BigDecimal getOnHand(int AD_Client_ID, int M_Warehouse_ID ,int M_Product_ID)
{
BigDecimal OnHand = Env.ZERO;
String sql = "SELECT SUM(bomQtyOnHand (M_Product_ID ,"+M_Warehouse_ID+",0)) AS OnHand FROM M_Product WHERE AD_Client_ID="+AD_Client_ID+" AND M_Product_ID=" + M_Product_ID;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
while (rs.next())
{
OnHand = rs.getBigDecimal("OnHand");
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
return null;
}
if (OnHand == null)
OnHand = Env.ZERO;
return OnHand;
}
public static int getMaxLowLevel(Properties ctx)
{ {
int LowLevel = 0; int LowLevel = 0;
int AD_Client_ID = Env.getAD_Client_ID(ctx); int AD_Client_ID = Env.getAD_Client_ID(ctx);
// //
String sql = "SELECT MAX("+MProduct.COLUMNNAME_LowLevel+") FROM M_Product" String sql = "SELECT MAX("+MProduct.COLUMNNAME_LowLevel+") FROM M_Product"
+" WHERE AD_Client_ID=? AND "+MProduct.COLUMNNAME_LowLevel+" IS NOT NULL"; +" WHERE AD_Client_ID=? AND "+MProduct.COLUMNNAME_LowLevel+" IS NOT NULL";
LowLevel = DB.getSQLValue(null, sql, AD_Client_ID); LowLevel = DB.getSQLValue(trxName, sql, AD_Client_ID);
return LowLevel + 1; return LowLevel + 1;
} }
public static BigDecimal getDays(int S_Resource_ID, int AD_Workflow_ID, BigDecimal QtyOrdered) public static BigDecimal getDays(Properties ctx ,int S_Resource_ID, int AD_Workflow_ID, BigDecimal QtyOrdered, String trxName)
{ {
if (S_Resource_ID == 0) if (S_Resource_ID == 0)
return Env.ZERO; return Env.ZERO;
MResource S_Resource = MResource.get(Env.getCtx(),S_Resource_ID); MResource S_Resource = MResource.get(ctx,S_Resource_ID);
MResourceType S_ResourceType = MResourceType.get(Env.getCtx(),S_Resource.getS_ResourceType_ID()); MResourceType S_ResourceType = MResourceType.get(ctx,S_Resource.getS_ResourceType_ID());
BigDecimal AvailableDayTime = Env.ZERO; BigDecimal AvailableDayTime = Env.ZERO;
int AvailableDays = 0; int AvailableDays = 0;
long hours = 0; long hours = 0;
if (S_ResourceType.isDateSlot()) if (S_ResourceType.isDateSlot())
AvailableDayTime = new BigDecimal(getHoursAvailable(S_ResourceType.getTimeSlotStart(),S_ResourceType.getTimeSlotEnd())); AvailableDayTime = new BigDecimal(getHoursAvailable(S_ResourceType.getTimeSlotStart(),S_ResourceType.getTimeSlotEnd()));
else else
@ -879,7 +673,7 @@ public class MPPMRP extends X_PP_MRP
if (S_ResourceType.isOnSunday()) if (S_ResourceType.isOnSunday())
AvailableDays =+ 1; AvailableDays =+ 1;
MWorkflow wf = new MWorkflow(Env.getCtx(),AD_Workflow_ID,null); MWorkflow wf = new MWorkflow(ctx,AD_Workflow_ID,trxName);
BigDecimal RequiredTime = Env.ZERO ;//wf.getQueuingTime().add(wf.getSetupTime()).add(wf.getDuration().multiply(QtyOrdered)).add(wf.getWaitingTime()).add(wf.getMovingTime()); BigDecimal RequiredTime = Env.ZERO ;//wf.getQueuingTime().add(wf.getSetupTime()).add(wf.getDuration().multiply(QtyOrdered)).add(wf.getWaitingTime()).add(wf.getMovingTime());
// Weekly Factor // Weekly Factor

View File

@ -335,7 +335,7 @@ public class MRP extends SvrProcess
//String Order_Policy = MPPProductPlanning.ORDER_POLICY_LoteForLote; //String Order_Policy = MPPProductPlanning.ORDER_POLICY_LoteForLote;
int lowlevel = MPPMRP.getMaxLowLevel(getCtx()); int lowlevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
int Level = lowlevel; int Level = lowlevel;
log.info("Low Level Is :"+lowlevel); log.info("Low Level Is :"+lowlevel);
// Calculate MRP for all levels // Calculate MRP for all levels
@ -569,7 +569,7 @@ public class MRP extends SvrProcess
//QtyOnHand = getOnHand(M_Product_ID); //QtyOnHand = getOnHand(M_Product_ID);
QtyProjectOnHand = MPPMRP.getOnHand(AD_Client_ID , m_product_planning.getM_Warehouse_ID() , m_product_planning.getM_Product_ID()); QtyProjectOnHand = MPPMRP.getQtyOnHand(AD_Client_ID , m_product_planning.getM_Warehouse_ID() , m_product_planning.getM_Product_ID(), get_TrxName());
if(QtyProjectOnHand == null) if(QtyProjectOnHand == null)
QtyProjectOnHand = Env.ZERO; QtyProjectOnHand = Env.ZERO;
@ -933,7 +933,7 @@ public class MRP extends SvrProcess
order.setDatePromised(DemandDateStartSchedule); order.setDatePromised(DemandDateStartSchedule);
if (m_product_planning.getDeliveryTime_Promised().compareTo(Env.ZERO) == 0) if (m_product_planning.getDeliveryTime_Promised().compareTo(Env.ZERO) == 0)
order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (MPPMRP.getDays(order.getS_Resource_ID(),order.getAD_Workflow_ID(), QtyPlanned).add(m_product_planning.getTransfertTime())).negate().intValue())); order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (MPPMRP.getDays(order.getCtx(),order.getS_Resource_ID(),order.getAD_Workflow_ID(), QtyPlanned,order.get_TrxName()).add(m_product_planning.getTransfertTime())).negate().intValue()));
else else
order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(m_product_planning.getTransfertTime())).negate().intValue())); order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(m_product_planning.getTransfertTime())).negate().intValue()));
order.setDateFinishSchedule(DemandDateStartSchedule); order.setDateFinishSchedule(DemandDateStartSchedule);

View File

@ -107,7 +107,7 @@ public class RollupBillOfMaterial extends SvrProcess
protected String doIt() throws Exception protected String doIt() throws Exception
{ {
int lowlevel = MPPMRP.getMaxLowLevel(getCtx()); int lowlevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
// Calculate Rollup for all levels // Calculate Rollup for all levels
for (int index = lowlevel ; index >= 0 ; index--) for (int index = lowlevel ; index >= 0 ; index--)
{ {