vpj-cd 2008-07-08 05:37:21 +00:00
parent c4118eb34c
commit b9d6775bf6
12 changed files with 686 additions and 655 deletions

View File

@ -35,7 +35,7 @@ public class CalloutMRP extends CalloutEngine
/** Debug Steps */
private boolean steps = false;
public String OrderLine(Properties ctx, int WindowNo,GridTab mTab, GridField mField, Object value)
public String OrderLine(Properties ctx, int WindowNo,GridTab mTab, GridField mField, Object value)
{
setCalloutActive(true);
String sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.C_OrderLine_ID = ? ");

View File

@ -39,7 +39,7 @@ import org.compiere.util.KeyNamePair;
/** Generated Interface for PP_MRP
* @author Trifon Trifonov (generated)
* @version Release 3.5.1a
* @version Release 3.5.0
*/
public interface I_PP_MRP
{

View File

@ -38,7 +38,7 @@ import org.compiere.util.KeyNamePair;
/** Generated Interface for T_MRP_CRP
* @author Trifon Trifonov (generated)
* @version Release 3.5.1a
* @version Release 3.5.0
*/
public interface I_T_MRP_CRP
{

View File

@ -67,7 +67,10 @@ public class LiberoValidator implements ModelValidator
engine.addModelChange(MRequisitionLine.Table_Name, this);
engine.addModelChange(MClient.Table_Name, this);
engine.addModelChange(X_M_ForecastLine.Table_Name, this);
//engine.addModelChange(MDDOrderLine.Table_Name, this);
engine.addModelChange(MDDOrder.Table_Name, this);
engine.addModelChange(MDDOrderLine.Table_Name, this);
engine.addModelChange(MPPOrder.Table_Name, this);
engine.addModelChange(MPPOrderBOMLine.Table_Name, this);
} // initialize
/**
@ -82,54 +85,78 @@ public class LiberoValidator implements ModelValidator
public String modelChange (PO po, int type) throws Exception
{
log.info(po.get_TableName() + " Type: "+type);
if (po.get_TableName().equals(MOrderLine.Table_Name) && ( type == TYPE_NEW || type == TYPE_AFTER_CHANGE ))
if (po.get_TableName().equals(MOrderLine.Table_Name) && ( type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE ))
{
MOrderLine ol = (MOrderLine)po;
org.eevolution.model.MPPMRP.C_OrderLine(ol, false);
MPPMRP.C_OrderLine(ol, false);
log.info(po.toString());
}
if (po.get_TableName().equals(MOrderLine.Table_Name) && type == TYPE_DELETE)
if (po.get_TableName().equals(MOrderLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MOrderLine ol = (MOrderLine)po;
org.eevolution.model.MPPMRP.C_OrderLine(ol, true);
log.info(po.toString());
}
if (po.get_TableName().equals(MRequisitionLine.Table_Name) && (type == TYPE_NEW || type == TYPE_AFTER_CHANGE ))
if (po.get_TableName().equals(MRequisitionLine.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE ))
{
MRequisitionLine rl = (MRequisitionLine)po;
org.eevolution.model.MPPMRP.M_RequisitionLine(rl, false);
MPPMRP.M_RequisitionLine(rl, false);
log.info(po.toString());
}
if (po.get_TableName().equals(MRequisitionLine.Table_Name) && type == TYPE_DELETE )
if (po.get_TableName().equals(MRequisitionLine.Table_Name) && type == TYPE_BEFORE_DELETE )
{
MRequisitionLine ol = (MRequisitionLine)po;
org.eevolution.model.MPPMRP.M_RequisitionLine(ol, true);
MPPMRP.M_RequisitionLine(ol, true);
log.info(po.toString());
}
if (po.get_TableName().equals(X_M_ForecastLine.Table_Name) && (type == TYPE_NEW || type == TYPE_AFTER_CHANGE ))
if (po.get_TableName().equals(X_M_ForecastLine.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE ))
{
X_M_ForecastLine ol = (X_M_ForecastLine)po;
org.eevolution.model.MPPMRP.M_ForecastLine(ol, false);
MPPMRP.M_ForecastLine(ol, false);
log.info(po.toString());
}
if (po.get_TableName().equals(X_M_ForecastLine.Table_Name) && type == TYPE_DELETE)
if (po.get_TableName().equals(X_M_ForecastLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
X_M_ForecastLine ol = (X_M_ForecastLine)po;
org.eevolution.model.MPPMRP.M_ForecastLine(ol, true);
MPPMRP.M_ForecastLine(ol, true);
log.info(po.toString());
}
/*if (po.get_TableName().equals(MDDOrderLine.Table_Name) && (type == TYPE_NEW || type == TYPE_AFTER_CHANGE ))
if (po.get_TableName().equals(MDDOrderLine.Table_Name) && (type == TYPE_AFTER_NEW|| type == TYPE_AFTER_CHANGE ))
{
MDDOrderLine ol = (MDDOrderLine)po;
org.eevolution.model.MPPMRP.DD_Order_Line(ol , false);
MPPMRP.DD_Order_Line(ol , false);
log.info(po.toString());
}
if (po.get_TableName().equals(MDDOrderLine.Table_Name) && type == TYPE_DELETE)
if (po.get_TableName().equals(MDDOrderLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
X_M_ForecastLine ol = (X_M_ForecastLine)po;
org.eevolution.model.MPPMRP.M_ForecastLine(ol, true);
MDDOrderLine ol = (MDDOrderLine)po;
MPPMRP.DD_Order_Line(ol, true);
log.info(po.toString());
}*/
}
if (po.get_TableName().equals(MPPOrder.Table_Name) && (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE ))
{
MPPOrder o = (MPPOrder)po;
MPPMRP.PP_Order(o, false);
log.info(po.toString());
}
if (po.get_TableName().equals(MPPOrder.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MPPOrder o = (MPPOrder)po;
MPPMRP.PP_Order(o, true);
log.info(po.toString());
}
if (po.get_TableName().equals(MPPOrderBOMLine.Table_Name) && (type == TYPE_AFTER_NEW|| type == TYPE_AFTER_CHANGE ))
{
MPPOrderBOMLine ol = (MPPOrderBOMLine)po;
MPPMRP.PP_Order_BOMLine(ol, false);
log.info(po.toString());
}
if (po.get_TableName().equals(MPPOrderBOMLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MPPOrderBOMLine ol = (MPPOrderBOMLine)po;
MPPMRP.PP_Order_BOMLine(ol, true);
log.info(po.toString());
}
return null;
} // modelChange

View File

@ -55,7 +55,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
MDDOrder to = new MDDOrder (from.getCtx(), 0, trxName);
to.set_TrxName(trxName);
PO.copyValues(from, to, from.getAD_Client_ID(), from.getAD_Org_ID());
to.set_ValueNoCheck ("C_Order_ID", I_ZERO);
to.set_ValueNoCheck ("DD_Order_ID", I_ZERO);
to.set_ValueNoCheck ("DocumentNo", null);
//
to.setDocStatus (DOCSTATUS_Drafted); // Draft
@ -76,14 +76,14 @@ public class MDDOrder extends X_DD_Order implements DocAction
to.setPosted (false);
to.setProcessed (false);
if (counter)
to.setRef_Order_ID(from.getC_Order_ID());
to.setRef_Order_ID(from.getDD_Order_ID());
else
to.setRef_Order_ID(0);
//
if (!to.save(trxName))
throw new IllegalStateException("Could not create Order");
if (counter)
from.setRef_Order_ID(to.getC_Order_ID());
from.setRef_Order_ID(to.getDD_Order_ID());
if (to.copyLinesFrom(from, counter, copyASI) == 0)
throw new IllegalStateException("Could not create Order Lines");
@ -95,14 +95,14 @@ public class MDDOrder extends X_DD_Order implements DocAction
/**************************************************************************
* Default Constructor
* @param ctx context
* @param C_Order_ID order to load, (0 create new order)
* @param DD_Order_ID order to load, (0 create new order)
* @param trxName trx name
*/
public MDDOrder(Properties ctx, int C_Order_ID, String trxName)
public MDDOrder(Properties ctx, int DD_Order_ID, String trxName)
{
super (ctx, C_Order_ID, trxName);
super (ctx, DD_Order_ID, trxName);
// New
if (C_Order_ID == 0)
if (DD_Order_ID == 0)
{
setDocStatus(DOCSTATUS_Drafted);
setDocAction (DOCACTION_Prepare);
@ -314,8 +314,8 @@ public class MDDOrder extends X_DD_Order implements DocAction
// Default Invoice/Payment Rule
ss = bp.getInvoiceRule();
if (ii != 0)
setSalesRep_ID(ii);
//if (ii != 0)
// setSalesRep_ID(ii);
// Set Locations
@ -361,7 +361,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
{
MDDOrderLine line = new MDDOrderLine (this);
PO.copyValues(fromLines[i], line, getAD_Client_ID(), getAD_Org_ID());
line.setDD_Order_ID(getC_Order_ID());
line.setDD_Order_ID(getDD_Order_ID());
line.setOrder(this);
// References
if (!copyASI)
@ -443,7 +443,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
*/
public File createPDF (File file)
{
ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, getC_Order_ID());
ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, getDD_Order_ID());
if (re == null)
return null;
return re.getPDF(file);
@ -461,7 +461,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
public MDDOrderLine[] getLines (String whereClause, String orderClause)
{
ArrayList<MDDOrderLine> list = new ArrayList<MDDOrderLine> ();
StringBuffer sql = new StringBuffer("SELECT * FROM C_OrderLine WHERE C_Order_ID=? ");
StringBuffer sql = new StringBuffer("SELECT * FROM DD_OrderLine WHERE DD_Order_ID=? ");
if (whereClause != null)
sql.append(whereClause);
if (orderClause != null)
@ -470,7 +470,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
try
{
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_Order_ID());
pstmt.setInt(1, getDD_Order_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
@ -572,7 +572,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Order_ID());
pstmt.setInt(1, getDD_Order_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MMovement(getCtx(), rs, get_TrxName()));
@ -621,17 +621,6 @@ public class MDDOrder extends X_DD_Order implements DocAction
setDocAction (DocAction, false);
} // setDocAction
/**
* Set DocAction
* @param DocAction doc oction
* @param forceCreation force creation
*/
public void setDocAction (String DocAction, boolean forceCreation)
{
super.setDocAction (DocAction);
m_forceCreation = forceCreation;
} // setDocAction
/**
* Set Processed.
* Propergate to Lines/Taxes
@ -644,7 +633,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
return;
String set = "SET Processed='"
+ (processed ? "Y" : "N")
+ "' WHERE C_Order_ID=" + getC_Order_ID();
+ "' WHERE DD_Order_ID=" + getDD_Order_ID();
int noLine = DB.executeUpdate("UPDATE DD_OrderLine " + set, get_TrxName());
m_lines = null;
log.fine("setProcessed - " + processed + " - Lines=" + noLine);
@ -718,12 +707,12 @@ public class MDDOrder extends X_DD_Order implements DocAction
// Default Sales Rep
if (getSalesRep_ID() == 0)
/*if (getSalesRep_ID() == 0)
{
int ii = Env.getContextAsInt(getCtx(), "#SalesRep_ID");
if (ii != 0)
setSalesRep_ID (ii);
}
}*/
return true;
} // beforeSave
@ -778,6 +767,18 @@ public class MDDOrder extends X_DD_Order implements DocAction
}
} // afterSaveSync
/**
* Set DocAction
* @param DocAction doc oction
* @param forceCreation force creation
*/
public void setDocAction (String DocAction, boolean forceCreation)
{
super.setDocAction (DocAction);
m_forceCreation = forceCreation;
} // setDocAction
/**
* Before Delete
* @return true of it can be deleted
@ -790,21 +791,8 @@ public class MDDOrder extends X_DD_Order implements DocAction
getLines();
for (int i = 0; i < m_lines.length; i++)
{
if (!m_lines[i].beforeDelete())
return false;
m_lines[i].delete(true);
}
int[] ids = PO.getAllIDs("DD_OrderLine", "DD_Order_ID="+get_ID()+ " AND AD_Client_ID="+ getAD_Client_ID(), get_TrxName());
for(int i = 0; i < ids.length; i++)
{
PO po = new MDDOrderLine(Env.getCtx(), ids[i], get_TrxName());
boolean ok = po.delete(true);
if(!ok) {
return ok;
}
}
return true;
} // beforeDelete
@ -900,7 +888,7 @@ public class MDDOrder extends X_DD_Order implements DocAction
+ "WHERE pas.MandatoryType" + mandatoryType
+ " AND ol.M_AttributeSetInstance_ID IS NULL"
+ " AND ol.DD_Order_ID=?";
int no = DB.getSQLValue(get_TrxName(), sql, getC_Order_ID());
int no = DB.getSQLValue(get_TrxName(), sql, getDD_Order_ID());
if (no != 0)
{
m_processMsg = "@LinesWithoutProductAttribute@ (" + no + ")";

View File

@ -652,8 +652,6 @@ public class MDDOrderLine extends X_DD_OrderLine
if (!success)
return success;
MPPMRP.DD_Order_Line(this, false);
return true;
} // afterSave
@ -666,9 +664,7 @@ public class MDDOrderLine extends X_DD_OrderLine
{
if (!success)
return success;
MPPMRP.DD_Order_Line(this, true);
return true;
} // afterDelete

View File

@ -212,7 +212,7 @@ public class MPPMRP extends X_PP_MRP
String sql = null;
String trxName = ol.getParent().get_TrxName();
if (delete)
{
{
sql = "DELETE FROM PP_MRP WHERE C_OrderLine_ID = "+ ol.getC_OrderLine_ID() +" AND AD_Client_ID = " + ol.getAD_Client_ID();
DB.executeUpdate(sql ,trxName);
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());
@ -359,163 +359,192 @@ public class MPPMRP extends X_PP_MRP
return mrp.getPP_MRP_ID();
}
public static int PP_Order(MPPOrder o)
public static void PP_Order(MPPOrder o, boolean delete)
{
String trxName = o.get_TrxName();
String sql = null;
String trxName = o.get_TrxName();
Properties m_ctx = o.getCtx();
if (delete)
{
sql = "DELETE FROM PP_MRP WHERE PP_Order_ID = "+ o.getPP_Order_ID() +" AND AD_Client_ID = " + o.getAD_Client_ID();
DB.executeUpdate(sql ,trxName);
return;
}
String sql = new String("SELECT * FROM PP_MRP WHERE Type = 'S' AND TypeMRP='MOP' AND PP_Order_ID = ? ");
MPPMRP mrp = null;
sql = new String("SELECT * FROM PP_MRP WHERE Type = 'S' AND TypeMRP='MOP' AND PP_Order_ID = ? ");
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(Env.getCtx(), rs ,trxName);
mrp.setDescription(o.getDescription());
mrp.setName("MRP");
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(o.getM_Product_ID());
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
if (!records)
{
mrp = new MPPMRP(Env.getCtx(), 0, trxName);
mrp.setPP_Order_ID(o.getPP_Order_ID());
mrp.setDescription(o.getDescription());
mrp.setName("MRP");
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateStartSchedule());
mrp.setM_Product_ID(o.getM_Product_ID());
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setType("S");
mrp.setTypeMRP("MOP");
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
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())
{
X_PP_Order_BOMLine ol = new X_PP_Order_BOMLine(Env.getCtx(),rs,trxName);
PP_Order_BOMLine(ol,o);
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
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.setName(o.getDocumentNo());
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(o.getM_Product_ID());
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
if (!records)
{
mrp = new MPPMRP(Env.getCtx(), 0, trxName);
mrp.setPP_Order_ID(o.getPP_Order_ID());
mrp.setDescription(o.getDescription());
mrp.setName(o.getDocumentNo());
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateStartSchedule());
mrp.setM_Product_ID(o.getM_Product_ID());
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setType("S");
mrp.setTypeMRP("MOP");
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
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 mrp.getPP_MRP_ID();
return ;
}
public static int PP_Order_BOMLine(X_PP_Order_BOMLine obl,X_PP_Order o)
public static void PP_Order_BOMLine(MPPOrderBOMLine obl,boolean delete)
{
String trxName = o.get_TrxName();
String sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.Type = 'D' AND mrp.TypeMRP='MOP' AND mrp.PP_Order_BOMLine_ID = ? ");
//String sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.Type = 'D' AND mrp.PP_Order_BOMLine_ID = ? ");
MPPMRP 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(Env.getCtx(), rs,trxName);
mrp.setName("MRP");
mrp.setDescription(o.getDescription());
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(obl.getM_Product_ID());
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
if (!records)
{
mrp = new MPPMRP(Env.getCtx(), 0,trxName);
//MOrder o = new MOrder(Env.getCtx(), ol.getC_Order_ID());
mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID());
mrp.setName("MRP");
mrp.setDescription(o.getDescription());
mrp.setPP_Order_ID(o.getPP_Order_ID());
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(obl.getM_Product_ID());
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.setType("D");
mrp.setTypeMRP("MOP");
mrp.save();
}
rs.close();
pstmt.close();
String sql = null;
String trxName = obl.getParent().get_TrxName();
Properties m_ctx = obl.getCtx();
if (delete)
{
sql = "DELETE FROM PP_MRP WHERE PP_Order_BOMLine_ID = "+ obl.getPP_Order_BOMLine_ID() +" AND AD_Client_ID = " + obl.getAD_Client_ID();
DB.executeUpdate(sql ,trxName);
return;
}
sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.Type = 'D' AND mrp.TypeMRP='MOP' AND mrp.PP_Order_BOMLine_ID = ? ");
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
return mrp.getPP_MRP_ID();
MPPOrder o = obl.getParent();
MPPMRP 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.setDescription(o.getDescription());
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(obl.getM_Product_ID());
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.save();
}
if (!records)
{
mrp = new MPPMRP(m_ctx , 0,trxName);
mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID());
mrp.setName(o.getDocumentNo());
mrp.setDescription(o.getDescription());
mrp.setPP_Order_ID(o.getPP_Order_ID());
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
mrp.setDatePromised(o.getDatePromised());
mrp.setDateOrdered(o.getDateOrdered());
mrp.setDateStartSchedule(o.getDateStartSchedule());
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
mrp.setM_Product_ID(obl.getM_Product_ID());
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.setS_Resource_ID(o.getS_Resource_ID());
mrp.setDocStatus(o.getDocStatus());
mrp.setType("D");
mrp.setTypeMRP("MOP");
mrp.save();
}
rs.close();
pstmt.close();
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "doIt - " + sql , ex);
}
return;
}
public static void DD_Order(MDDOrder o, boolean delete)
{
String sql = null;
String trxName = o.get_TrxName();
Properties m_ctx = o.getCtx();
if (delete)
{
sql = "DELETE FROM PP_MRP WHERE DD_Order_ID = "+ o.getDD_Order_ID() +" AND AD_Client_ID = " + o.getAD_Client_ID();
DB.executeUpdate(sql ,trxName);
return;
}
}
public static void DD_Order_Line(MDDOrderLine ol, boolean delete)
{

View File

@ -505,361 +505,323 @@ public class MPPOrder extends X_PP_Order implements DocAction {
* @param newRecord new
* @return save
*/
protected boolean afterSave(boolean newRecord, boolean success) {
if (!newRecord)
{
MPPMRP.PP_Order(this);
return success;
}
//X_PP_Order PP_Order = new X_PP_Order(getCtx(),getPP_Order_ID() , get_TrxName());
//MPPMRP.PP_Order(PP_Order ,get_TrxName());
log.fine("afterSave - MPPOrder Query ok");
setC_DocType_ID(0);
// Create BOM Head
MPPProductBOM PP_Product_BOM = new MPPProductBOM(getCtx(), getPP_Product_BOM_ID(),get_TrxName());
boolean ValidFromBOM = true;
boolean ValidToBOM = true;
if (PP_Product_BOM.getValidFrom() != null)
{
ValidFromBOM = getDateStartSchedule().compareTo(PP_Product_BOM.getValidFrom()) >= 0 ? true : false;
}
if (PP_Product_BOM.getValidTo() != null )
{
ValidToBOM = getDateStartSchedule().compareTo(PP_Product_BOM.getValidTo()) <= 0 ? true : false;
}
if(ValidFromBOM && ValidToBOM)
{
MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(getCtx(), 0,get_TrxName());
PP_Order_BOM.setPP_Order_ID(getPP_Order_ID());
//PP_Order_BOM.setPP_Product_BOM_ID(PP_Product_BOM.getPP_Product_BOM_ID());
PP_Order_BOM.setBOMType(PP_Product_BOM.getBOMType());
PP_Order_BOM.setBOMUse(PP_Product_BOM.getBOMUse());
PP_Order_BOM.setM_ChangeNotice_ID(PP_Product_BOM.getM_ChangeNotice_ID());
PP_Order_BOM.setHelp(PP_Product_BOM.getHelp());
PP_Order_BOM.setCopyFrom(PP_Product_BOM.getCopyFrom());
PP_Order_BOM.setProcessing(PP_Product_BOM.isProcessing());
//PP_Order_BOM(PP_Product_BOM.getHelp());
PP_Order_BOM.setDescription(PP_Product_BOM.getDescription());
PP_Order_BOM.setM_AttributeSetInstance_ID(PP_Product_BOM.getM_AttributeSetInstance_ID());
PP_Order_BOM.setM_Product_ID(PP_Product_BOM.getM_Product_ID());
PP_Order_BOM.setName(PP_Product_BOM.getName());
PP_Order_BOM.setRevision(PP_Product_BOM.getRevision());
PP_Order_BOM.setValidFrom(PP_Product_BOM.getValidFrom());
PP_Order_BOM.setValidTo(PP_Product_BOM.getValidTo());
PP_Order_BOM.setValue(PP_Product_BOM.getValue());
PP_Order_BOM.setDocumentNo(PP_Product_BOM.getDocumentNo());
PP_Order_BOM.setC_UOM_ID(PP_Product_BOM.getC_UOM_ID());
PP_Order_BOM.save(get_TrxName());
//Create BOM List ---------------------------------------------------------
MPPProductBOMLine[] PP_Product_BOMline = PP_Product_BOM.getLines();
for (int i = 0 ; i < PP_Product_BOMline.length ; i ++)
{
boolean ValidFromBOMLine = true;
boolean ValidToBOMLine = true;
if (PP_Product_BOMline[i].getValidFrom() != null)
{
ValidFromBOMLine = getDateStartSchedule().compareTo(PP_Product_BOMline[i].getValidFrom()) >= 0 ? true : false;
}
if (PP_Product_BOMline[i].getValidTo() != null )
{
ValidToBOMLine = getDateStartSchedule().compareTo(PP_Product_BOMline[i].getValidTo()) <= 0 ? true : false;
}
//MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(getCtx(),0,trx.getTrxName());
if(ValidFromBOMLine && ValidToBOMLine)
{
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(getCtx(),0,get_TrxName());
PP_Order_BOMLine.setM_ChangeNotice_ID(PP_Product_BOMline[i].getM_ChangeNotice_ID());
PP_Order_BOMLine.setHelp(PP_Product_BOMline[i].getHelp());
PP_Order_BOMLine.setAssay(PP_Product_BOMline[i].getAssay());
PP_Order_BOMLine.setQtyBatch(PP_Product_BOMline[i].getQtyBatch());
PP_Order_BOMLine.setQtyBOM(PP_Product_BOMline[i].getQtyBOM());
PP_Order_BOMLine.setIsQtyPercentage(PP_Product_BOMline[i].isQtyPercentage());
PP_Order_BOMLine.setComponentType(PP_Product_BOMline[i].getComponentType());
PP_Order_BOMLine.setC_UOM_ID(PP_Product_BOMline[i].getC_UOM_ID());
PP_Order_BOMLine.setForecast(PP_Product_BOMline[i].getForecast());
PP_Order_BOMLine.setIsCritical(PP_Product_BOMline[i].isCritical());
PP_Order_BOMLine.setIssueMethod(PP_Product_BOMline[i].getIssueMethod());
PP_Order_BOMLine.setLine(MPPOrder.getLines(getPP_Order_ID()).length+10);
PP_Order_BOMLine.setLeadTimeOffset(PP_Product_BOMline[i].getLeadTimeOffset());
PP_Order_BOMLine.setM_AttributeSetInstance_ID(PP_Product_BOMline[i].getM_AttributeSetInstance_ID());
PP_Order_BOMLine.setPP_Order_BOM_ID(PP_Order_BOM.getPP_Order_BOM_ID());
PP_Order_BOMLine.setPP_Order_ID(getPP_Order_ID());
PP_Order_BOMLine.setM_Product_ID(PP_Product_BOMline[i].getM_Product_ID());
PP_Order_BOMLine.setScrap(PP_Product_BOMline[i].getScrap());
PP_Order_BOMLine.setValidFrom(PP_Product_BOMline[i].getValidFrom());
PP_Order_BOMLine.setValidTo(PP_Product_BOMline[i].getValidTo());
PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
PP_Order_BOMLine.setBackflushGroup(PP_Product_BOMline[i].getBackflushGroup());
BigDecimal QtyOrdered = getQtyOrdered();
System.out.println("PP_Order_BOMLine.getQtyBOM()" + PP_Order_BOMLine.getQtyBOM()+ "PP_Product_BOMline[i].getQtyBOM()"+ PP_Product_BOMline[i].getQtyBOM());
if (PP_Order_BOMLine.isQtyPercentage())
{
BigDecimal qty = PP_Order_BOMLine.getQtyBatch().multiply(QtyOrdered);
if( PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Packing))
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,qty.ROUND_UP));
if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Phantom))
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,qty.ROUND_UP));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Tools))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM());
}
else
{
if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Phantom))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM().multiply(QtyOrdered));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Packing))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM().multiply(QtyOrdered));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Tools))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM());
}
//System.out.println("Cantidad Requerida" + PP_Order_BOMLine.getQtyRequiered());
// Set Scrap of Component
BigDecimal Scrap = PP_Order_BOMLine.getScrap();
if (!Scrap.equals(Env.ZERO))
{
Scrap = Scrap.divide(new BigDecimal(100),8,BigDecimal.ROUND_UP);
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyRequiered().divide( Env.ONE.subtract(Scrap) , 8 ,BigDecimal.ROUND_HALF_UP ));
}
//System.out.println("Cantidad Requerida" + PP_Order_BOMLine.getQtyRequiered());
PP_Order_BOMLine.save(get_TrxName());
} // end if From / To component
MPPOrderBOMLine[] lines = getLines(getPP_Order_ID());
for (int l = 0 ; l < lines.length ; l ++)
{
if(lines[l].getComponentType().equals(MPPProductBOMLine.COMPONENTTYPE_Phantom))
{
lines[l].setQtyRequiered(Env.ZERO);
lines[l].save(get_TrxName());
}
}
} // end Create Order BOM
} // end if From / To parent
//MPPMRP.PP_Order(PP_Order ,get_TrxName());
// Create Workflow (Routing & Process
MWorkflow AD_Workflow = new MWorkflow(getCtx() , getAD_Workflow_ID(),get_TrxName());
boolean ValidFromWF = true;
boolean ValidToWF = true;
if (AD_Workflow.getValidFrom() != null)
{
ValidFromWF = getDateStartSchedule().compareTo(AD_Workflow.getValidFrom()) >= 0 ? true : false;
}
if (AD_Workflow.getValidTo() != null && getDateStartSchedule() != null)
{
ValidToWF = getDateStartSchedule().compareTo(AD_Workflow.getValidTo()) <= 0 ? true : false;
}
if(ValidFromWF && ValidToWF)
{
MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(getCtx(),0,get_TrxName());
PP_Order_Workflow.setValue(AD_Workflow.getValue());
//PP_Order_Workflow.setQtyBatchSize(AD_Workflow.getQtyBatchSize());
PP_Order_Workflow.setWorkflowType(AD_Workflow.getWorkflowType());
PP_Order_Workflow.setQtyBatchSize(AD_Workflow.getQtyBatchSize());
PP_Order_Workflow.setName(AD_Workflow.getName());
PP_Order_Workflow.setAccessLevel(AD_Workflow.getAccessLevel());
PP_Order_Workflow.setAuthor(AD_Workflow.getAuthor());
PP_Order_Workflow.setDurationUnit(AD_Workflow.getDurationUnit());
PP_Order_Workflow.setDuration(AD_Workflow.getDuration());
PP_Order_Workflow.setEntityType(AD_Workflow.getEntityType()); // U
PP_Order_Workflow.setIsDefault(AD_Workflow.isDefault());
PP_Order_Workflow.setPublishStatus(AD_Workflow.getPublishStatus()); // U
PP_Order_Workflow.setVersion(AD_Workflow.getVersion());
PP_Order_Workflow.setCost(AD_Workflow.getCost());
PP_Order_Workflow.setWaitingTime(AD_Workflow.getWaitingTime());
PP_Order_Workflow.setWorkingTime(AD_Workflow.getWorkingTime());
PP_Order_Workflow.setAD_WF_Responsible_ID(AD_Workflow.getAD_WF_Responsible_ID());
PP_Order_Workflow.setAD_Workflow_ID(AD_Workflow.getAD_Workflow_ID());
PP_Order_Workflow.setLimit(AD_Workflow.getLimit());
PP_Order_Workflow.setPP_Order_ID(getPP_Order_ID());
PP_Order_Workflow.setPriority(AD_Workflow.getPriority());
PP_Order_Workflow.setValidateWorkflow(AD_Workflow.getValidateWorkflow());
PP_Order_Workflow.setS_Resource_ID(AD_Workflow.getS_Resource_ID());
PP_Order_Workflow.setQueuingTime(AD_Workflow.getQueuingTime());
PP_Order_Workflow.setSetupTime(AD_Workflow.getSetupTime());
PP_Order_Workflow.setMovingTime(AD_Workflow.getMovingTime());
PP_Order_Workflow.setProcessType(AD_Workflow.getProcessType());
PP_Order_Workflow.save(get_TrxName());
//PP_Order_Workflow.set
MWFNode[] AD_WF_Node = AD_Workflow.getNodes(false,getAD_Client_ID());
if(AD_WF_Node != null)
{
for (int g = 0 ; g < AD_WF_Node.length ; g ++)
{
boolean ValidFromNode = true;
boolean ValidToNode = true;
//if (AD_WF_Node[g].getValidFrom() != null )
if (AD_WF_Node[g].getValidFrom() != null)
{
ValidFromNode = getDateStartSchedule().compareTo(AD_WF_Node[g].getValidFrom()) >= 0 ? true : false;
}
if (AD_WF_Node[g].getValidTo() != null )
{
ValidToNode = getDateStartSchedule().compareTo(AD_WF_Node[g].getValidTo()) <= 0 ? true : false;
}
if (ValidFromNode && ValidToNode)
{
MPPOrderNode PP_Order_Node = new MPPOrderNode(getCtx(),0,get_TrxName());
PP_Order_Node.setAction(AD_WF_Node[g].getAction());
PP_Order_Node.setAD_WF_Node_ID(AD_WF_Node[g].getAD_WF_Node_ID());
PP_Order_Node.setAD_WF_Responsible_ID(AD_WF_Node[g].getAD_WF_Responsible_ID());
PP_Order_Node.setAD_Workflow_ID(AD_WF_Node[g].getAD_Workflow_ID());
PP_Order_Node.setCost(AD_WF_Node[g].getCost());
PP_Order_Node.setDuration(AD_WF_Node[g].getDuration());
PP_Order_Node.setEntityType(AD_WF_Node[g].getEntityType());
PP_Order_Node.setIsCentrallyMaintained(AD_WF_Node[g].isCentrallyMaintained());
PP_Order_Node.setJoinElement(AD_WF_Node[g].getJoinElement()); // X
PP_Order_Node.setLimit(AD_WF_Node[g].getLimit());
PP_Order_Node.setPP_Order_ID(getPP_Order_ID());
PP_Order_Node.setPP_Order_Workflow_ID(PP_Order_Workflow.getPP_Order_Workflow_ID());
PP_Order_Node.setName(AD_WF_Node[g].getName());
PP_Order_Node.setPriority(AD_WF_Node[g].getPriority());
PP_Order_Node.setSplitElement(AD_WF_Node[g].getSplitElement()); // X
PP_Order_Node.setSubflowExecution (AD_WF_Node[g].getSubflowExecution());
PP_Order_Node.setValue(AD_WF_Node[g].getValue());
PP_Order_Node.setS_Resource_ID(AD_WF_Node[g].getS_Resource_ID());
PP_Order_Node.setSetupTime(AD_WF_Node[g].getSetupTime());
PP_Order_Node.setSetupTimeRequiered(AD_WF_Node[g].getSetupTime());
BigDecimal time = new BigDecimal(AD_WF_Node[g].getDuration()).multiply(getQtyOrdered());
PP_Order_Node.setDurationRequiered(time.intValue());
PP_Order_Node.setMovingTime(AD_WF_Node[g].getMovingTime());
PP_Order_Node.setWaitingTime(AD_WF_Node[g].getWaitingTime());
PP_Order_Node.setWorkingTime(AD_WF_Node[g].getWorkingTime());;
PP_Order_Node.setQueuingTime(AD_WF_Node[g].getQueuingTime());
PP_Order_Node.setXPosition(AD_WF_Node[g].getXPosition());
PP_Order_Node.setYPosition(AD_WF_Node[g].getYPosition());
PP_Order_Node.setDocAction(AD_WF_Node[g].getDocAction());
PP_Order_Node.setAD_Column_ID(AD_WF_Node[g].getAD_Column_ID());
PP_Order_Node.setAD_Form_ID(AD_WF_Node[g].getAD_Form_ID());
PP_Order_Node.setAD_Image_ID(AD_WF_Node[g].getAD_Image_ID());
PP_Order_Node.setAD_Window_ID(AD_WF_Node[g].getAD_Window_ID());
PP_Order_Node.setAD_Process_ID(AD_WF_Node[g].getAD_Process_ID());
PP_Order_Node.setAttributeName(AD_WF_Node[g].getAttributeName());
PP_Order_Node.setAttributeValue(AD_WF_Node[g].getAttributeValue());
PP_Order_Node.setC_BPartner_ID(AD_WF_Node[g].getC_BPartner_ID());
PP_Order_Node.setStartMode(AD_WF_Node[g].getStartMode());
PP_Order_Node.setFinishMode(AD_WF_Node[g].getFinishMode());
PP_Order_Node.setValidFrom(AD_WF_Node[g].getValidFrom());
PP_Order_Node.setValidTo(AD_WF_Node[g].getValidTo());
PP_Order_Node.save(get_TrxName());
MWFNodeNext[] AD_WF_NodeNext = AD_WF_Node[g].getTransitions(getAD_Client_ID());
System.out.println("AD_WF_NodeNext"+AD_WF_NodeNext.length);
if(AD_WF_NodeNext != null)
{
for (int n = 0; n < AD_WF_NodeNext.length; n++)
{
MPPOrderNodeNext PP_Order_NodeNext = new MPPOrderNodeNext(getCtx(),0,get_TrxName());
PP_Order_NodeNext.setAD_WF_Node_ID(AD_WF_NodeNext[n].getAD_WF_Node_ID());
PP_Order_NodeNext.setAD_WF_Next_ID(AD_WF_NodeNext[n].getAD_WF_Next_ID());
PP_Order_NodeNext.setPP_Order_Node_ID(PP_Order_Node.getPP_Order_Node_ID());
PP_Order_NodeNext.setPP_Order_Next_ID(0);
PP_Order_NodeNext.setDescription(AD_WF_NodeNext[n].getDescription());
PP_Order_NodeNext.setEntityType(AD_WF_NodeNext[n].getEntityType());
PP_Order_NodeNext.setIsStdUserWorkflow(AD_WF_NodeNext[n].isStdUserWorkflow());
PP_Order_NodeNext.setPP_Order_ID (getPP_Order_ID());
PP_Order_NodeNext.setSeqNo(AD_WF_NodeNext[n].getSeqNo());
PP_Order_NodeNext.setTransitionCode(AD_WF_NodeNext[n].getTransitionCode());
PP_Order_NodeNext.save(get_TrxName());
}// end for Node Next
}
}// end for Node
//set transition for order
MPPOrderWorkflow OrderWorkflow = new MPPOrderWorkflow(getCtx(),PP_Order_Workflow.getPP_Order_Workflow_ID(),get_TrxName());
MPPOrderNode[] OrderNodes = OrderWorkflow.getNodes(false , getAD_Client_ID());
//System.out.println("-----------------------OrderNodes"+OrderNodes.length);
if(OrderNodes != null)
{
PP_Order_Workflow.setPP_Order_Node_ID(OrderNodes[0].getPP_Order_Node_ID());
for (int h = 0 ; h < OrderNodes.length ; h ++)
{
MPPOrderNodeNext[] nexts = OrderNodes[h].getTransitions(getAD_Client_ID());
//System.out.println("----------------------PP_Order_NodeNext"+nexts.length);
if(nexts != null)
{
System.out.println("Node Transition" + nexts.length);
for (int x = 0; x < nexts.length; x++)
{
String sql = "SELECT PP_Order_Node_ID FROM PP_Order_Node WHERE PP_Order_ID = ? AND AD_WF_Node_ID = ? AND AD_Client_ID=?";
try
{
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt(1, nexts[x].getPP_Order_ID());
pstmt.setInt(2, nexts[x].getAD_WF_Next_ID());
pstmt.setInt(3, nexts[x].getAD_Client_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
nexts[x].setPP_Order_Next_ID(rs.getInt(1));
nexts[x].save(get_TrxName());
}
rs.close();
pstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE,"doIt - " + sql, e);
}
}// end for Node Next
}
}
}
}// end from / to Node
} // end from /to Workflow
PP_Order_Workflow.save(get_TrxName());
}
MPPMRP.PP_Order(this);
return true;
protected boolean afterSave(boolean newRecord, boolean success)
{
if (!newRecord)
{
return success;
}
log.fine("afterSave - MPPOrder Query ok");
setC_DocType_ID(0);
// Create BOM Head
MPPProductBOM PP_Product_BOM = new MPPProductBOM(getCtx(), getPP_Product_BOM_ID(),get_TrxName());
boolean ValidFromBOM = true;
boolean ValidToBOM = true;
if (PP_Product_BOM.getValidFrom() != null)
ValidFromBOM = getDateStartSchedule().compareTo(PP_Product_BOM.getValidFrom()) >= 0 ? true : false;
if (PP_Product_BOM.getValidTo() != null )
ValidToBOM = getDateStartSchedule().compareTo(PP_Product_BOM.getValidTo()) <= 0 ? true : false;
if(ValidFromBOM && ValidToBOM)
{
MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(getCtx(), 0 , get_TrxName());
PP_Order_BOM.setPP_Order_ID(getPP_Order_ID());
PP_Order_BOM.setBOMType(PP_Product_BOM.getBOMType());
PP_Order_BOM.setBOMUse(PP_Product_BOM.getBOMUse());
PP_Order_BOM.setM_ChangeNotice_ID(PP_Product_BOM.getM_ChangeNotice_ID());
PP_Order_BOM.setHelp(PP_Product_BOM.getHelp());
PP_Order_BOM.setCopyFrom(PP_Product_BOM.getCopyFrom());
PP_Order_BOM.setProcessing(PP_Product_BOM.isProcessing());
PP_Order_BOM.setHelp(PP_Product_BOM.getHelp());
PP_Order_BOM.setDescription(PP_Product_BOM.getDescription());
PP_Order_BOM.setM_AttributeSetInstance_ID(PP_Product_BOM.getM_AttributeSetInstance_ID());
PP_Order_BOM.setM_Product_ID(PP_Product_BOM.getM_Product_ID());
PP_Order_BOM.setName(PP_Product_BOM.getName());
PP_Order_BOM.setRevision(PP_Product_BOM.getRevision());
PP_Order_BOM.setValidFrom(PP_Product_BOM.getValidFrom());
PP_Order_BOM.setValidTo(PP_Product_BOM.getValidTo());
PP_Order_BOM.setValue(PP_Product_BOM.getValue());
PP_Order_BOM.setDocumentNo(PP_Product_BOM.getDocumentNo());
PP_Order_BOM.setC_UOM_ID(PP_Product_BOM.getC_UOM_ID());
PP_Order_BOM.save();
MPPProductBOMLine[] PP_Product_BOMline = PP_Product_BOM.getLines();
for (int i = 0 ; i < PP_Product_BOMline.length ; i ++)
{
boolean ValidFromBOMLine = true;
boolean ValidToBOMLine = true;
if (PP_Product_BOMline[i].getValidFrom() != null)
ValidFromBOMLine = getDateStartSchedule().compareTo(PP_Product_BOMline[i].getValidFrom()) >= 0 ? true : false;
if (PP_Product_BOMline[i].getValidTo() != null )
ValidToBOMLine = getDateStartSchedule().compareTo(PP_Product_BOMline[i].getValidTo()) <= 0 ? true : false;
if(ValidFromBOMLine && ValidToBOMLine)
{
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(getCtx(),0,get_TrxName());
PP_Order_BOMLine.setM_ChangeNotice_ID(PP_Product_BOMline[i].getM_ChangeNotice_ID());
PP_Order_BOMLine.setHelp(PP_Product_BOMline[i].getHelp());
PP_Order_BOMLine.setAssay(PP_Product_BOMline[i].getAssay());
PP_Order_BOMLine.setQtyBatch(PP_Product_BOMline[i].getQtyBatch());
PP_Order_BOMLine.setQtyBOM(PP_Product_BOMline[i].getQtyBOM());
PP_Order_BOMLine.setIsQtyPercentage(PP_Product_BOMline[i].isQtyPercentage());
PP_Order_BOMLine.setComponentType(PP_Product_BOMline[i].getComponentType());
PP_Order_BOMLine.setC_UOM_ID(PP_Product_BOMline[i].getC_UOM_ID());
PP_Order_BOMLine.setForecast(PP_Product_BOMline[i].getForecast());
PP_Order_BOMLine.setIsCritical(PP_Product_BOMline[i].isCritical());
PP_Order_BOMLine.setIssueMethod(PP_Product_BOMline[i].getIssueMethod());
PP_Order_BOMLine.setLine(MPPOrder.getLines(getPP_Order_ID()).length+10);
PP_Order_BOMLine.setLeadTimeOffset(PP_Product_BOMline[i].getLeadTimeOffset());
PP_Order_BOMLine.setM_AttributeSetInstance_ID(PP_Product_BOMline[i].getM_AttributeSetInstance_ID());
PP_Order_BOMLine.setPP_Order_BOM_ID(PP_Order_BOM.getPP_Order_BOM_ID());
PP_Order_BOMLine.setPP_Order_ID(getPP_Order_ID());
PP_Order_BOMLine.setM_Product_ID(PP_Product_BOMline[i].getM_Product_ID());
PP_Order_BOMLine.setScrap(PP_Product_BOMline[i].getScrap());
PP_Order_BOMLine.setValidFrom(PP_Product_BOMline[i].getValidFrom());
PP_Order_BOMLine.setValidTo(PP_Product_BOMline[i].getValidTo());
PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
PP_Order_BOMLine.setBackflushGroup(PP_Product_BOMline[i].getBackflushGroup());
BigDecimal QtyOrdered = getQtyOrdered();
log.log(Level.INFO, "PP_Order_BOMLine.getQtyBOM()" + PP_Order_BOMLine.getQtyBOM()+ "PP_Product_BOMline[i].getQtyBOM()"+ PP_Product_BOMline[i].getQtyBOM());
if (PP_Order_BOMLine.isQtyPercentage())
{
BigDecimal qty = PP_Order_BOMLine.getQtyBatch().multiply(QtyOrdered);
if( PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Packing))
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,qty.ROUND_UP));
if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Phantom))
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,qty.ROUND_UP));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Tools))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM());
}
else
{
if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Phantom))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM().multiply(QtyOrdered));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Packing))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM().multiply(QtyOrdered));
else if (PP_Order_BOMLine.getComponentType().equals(PP_Order_BOMLine.COMPONENTTYPE_Tools))
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyBOM());
}
// Set Scrap of Component
BigDecimal Scrap = PP_Order_BOMLine.getScrap();
if (!Scrap.equals(Env.ZERO))
{
Scrap = Scrap.divide(new BigDecimal(100),8,BigDecimal.ROUND_UP);
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyRequiered().divide( Env.ONE.subtract(Scrap) , 8 ,BigDecimal.ROUND_HALF_UP ));
}
PP_Order_BOMLine.save(get_TrxName());
} // end if From / To component
MPPOrderBOMLine[] lines = getLines(getPP_Order_ID());
for (int l = 0 ; l < lines.length ; l ++)
{
if(lines[l].getComponentType().equals(MPPProductBOMLine.COMPONENTTYPE_Phantom))
{
lines[l].setQtyRequiered(Env.ZERO);
lines[l].save();
}
}
} // end Create Order BOM
} // end if From / To parent
// Create Workflow (Routing & Process
MWorkflow AD_Workflow = new MWorkflow(getCtx() , getAD_Workflow_ID(),get_TrxName());
boolean ValidFromWF = true;
boolean ValidToWF = true;
if (AD_Workflow.getValidFrom() != null)
ValidFromWF = getDateStartSchedule().compareTo(AD_Workflow.getValidFrom()) >= 0 ? true : false;
if (AD_Workflow.getValidTo() != null && getDateStartSchedule() != null)
ValidToWF = getDateStartSchedule().compareTo(AD_Workflow.getValidTo()) <= 0 ? true : false;
if(ValidFromWF && ValidToWF)
{
MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(getCtx(),0,get_TrxName());
PP_Order_Workflow.setValue(AD_Workflow.getValue());
PP_Order_Workflow.setWorkflowType(AD_Workflow.getWorkflowType());
PP_Order_Workflow.setQtyBatchSize(AD_Workflow.getQtyBatchSize());
PP_Order_Workflow.setName(AD_Workflow.getName());
PP_Order_Workflow.setAccessLevel(AD_Workflow.getAccessLevel());
PP_Order_Workflow.setAuthor(AD_Workflow.getAuthor());
PP_Order_Workflow.setDurationUnit(AD_Workflow.getDurationUnit());
PP_Order_Workflow.setDuration(AD_Workflow.getDuration());
PP_Order_Workflow.setEntityType(AD_Workflow.getEntityType());
PP_Order_Workflow.setIsDefault(AD_Workflow.isDefault());
PP_Order_Workflow.setPublishStatus(AD_Workflow.getPublishStatus());
PP_Order_Workflow.setVersion(AD_Workflow.getVersion());
PP_Order_Workflow.setCost(AD_Workflow.getCost());
PP_Order_Workflow.setWaitingTime(AD_Workflow.getWaitingTime());
PP_Order_Workflow.setWorkingTime(AD_Workflow.getWorkingTime());
PP_Order_Workflow.setAD_WF_Responsible_ID(AD_Workflow.getAD_WF_Responsible_ID());
PP_Order_Workflow.setAD_Workflow_ID(AD_Workflow.getAD_Workflow_ID());
PP_Order_Workflow.setLimit(AD_Workflow.getLimit());
PP_Order_Workflow.setPP_Order_ID(getPP_Order_ID());
PP_Order_Workflow.setPriority(AD_Workflow.getPriority());
PP_Order_Workflow.setValidateWorkflow(AD_Workflow.getValidateWorkflow());
PP_Order_Workflow.setS_Resource_ID(AD_Workflow.getS_Resource_ID());
PP_Order_Workflow.setQueuingTime(AD_Workflow.getQueuingTime());
PP_Order_Workflow.setSetupTime(AD_Workflow.getSetupTime());
PP_Order_Workflow.setMovingTime(AD_Workflow.getMovingTime());
PP_Order_Workflow.setProcessType(AD_Workflow.getProcessType());
PP_Order_Workflow.save();
MWFNode[] AD_WF_Node = AD_Workflow.getNodes(false,getAD_Client_ID());
if(AD_WF_Node != null)
{
for (int g = 0 ; g < AD_WF_Node.length ; g ++)
{
boolean ValidFromNode = true;
boolean ValidToNode = true;
if (AD_WF_Node[g].getValidFrom() != null)
ValidFromNode = getDateStartSchedule().compareTo(AD_WF_Node[g].getValidFrom()) >= 0 ? true : false;
if (AD_WF_Node[g].getValidTo() != null )
ValidToNode = getDateStartSchedule().compareTo(AD_WF_Node[g].getValidTo()) <= 0 ? true : false;
if (ValidFromNode && ValidToNode)
{
MPPOrderNode PP_Order_Node = new MPPOrderNode(getCtx(),0,get_TrxName());
PP_Order_Node.setAction(AD_WF_Node[g].getAction());
PP_Order_Node.setAD_WF_Node_ID(AD_WF_Node[g].getAD_WF_Node_ID());
PP_Order_Node.setAD_WF_Responsible_ID(AD_WF_Node[g].getAD_WF_Responsible_ID());
PP_Order_Node.setAD_Workflow_ID(AD_WF_Node[g].getAD_Workflow_ID());
PP_Order_Node.setCost(AD_WF_Node[g].getCost());
PP_Order_Node.setDuration(AD_WF_Node[g].getDuration());
PP_Order_Node.setEntityType(AD_WF_Node[g].getEntityType());
PP_Order_Node.setIsCentrallyMaintained(AD_WF_Node[g].isCentrallyMaintained());
PP_Order_Node.setJoinElement(AD_WF_Node[g].getJoinElement()); // X
PP_Order_Node.setLimit(AD_WF_Node[g].getLimit());
PP_Order_Node.setPP_Order_ID(getPP_Order_ID());
PP_Order_Node.setPP_Order_Workflow_ID(PP_Order_Workflow.getPP_Order_Workflow_ID());
PP_Order_Node.setName(AD_WF_Node[g].getName());
PP_Order_Node.setPriority(AD_WF_Node[g].getPriority());
PP_Order_Node.setSplitElement(AD_WF_Node[g].getSplitElement()); // X
PP_Order_Node.setSubflowExecution (AD_WF_Node[g].getSubflowExecution());
PP_Order_Node.setValue(AD_WF_Node[g].getValue());
PP_Order_Node.setS_Resource_ID(AD_WF_Node[g].getS_Resource_ID());
PP_Order_Node.setSetupTime(AD_WF_Node[g].getSetupTime());
PP_Order_Node.setSetupTimeRequiered(AD_WF_Node[g].getSetupTime());
BigDecimal time = new BigDecimal(AD_WF_Node[g].getDuration()).multiply(getQtyOrdered());
PP_Order_Node.setDurationRequiered(time.intValue());
PP_Order_Node.setMovingTime(AD_WF_Node[g].getMovingTime());
PP_Order_Node.setWaitingTime(AD_WF_Node[g].getWaitingTime());
PP_Order_Node.setWorkingTime(AD_WF_Node[g].getWorkingTime());;
PP_Order_Node.setQueuingTime(AD_WF_Node[g].getQueuingTime());
PP_Order_Node.setXPosition(AD_WF_Node[g].getXPosition());
PP_Order_Node.setYPosition(AD_WF_Node[g].getYPosition());
PP_Order_Node.setDocAction(AD_WF_Node[g].getDocAction());
PP_Order_Node.setAD_Column_ID(AD_WF_Node[g].getAD_Column_ID());
PP_Order_Node.setAD_Form_ID(AD_WF_Node[g].getAD_Form_ID());
PP_Order_Node.setAD_Image_ID(AD_WF_Node[g].getAD_Image_ID());
PP_Order_Node.setAD_Window_ID(AD_WF_Node[g].getAD_Window_ID());
PP_Order_Node.setAD_Process_ID(AD_WF_Node[g].getAD_Process_ID());
PP_Order_Node.setAttributeName(AD_WF_Node[g].getAttributeName());
PP_Order_Node.setAttributeValue(AD_WF_Node[g].getAttributeValue());
PP_Order_Node.setC_BPartner_ID(AD_WF_Node[g].getC_BPartner_ID());
PP_Order_Node.setStartMode(AD_WF_Node[g].getStartMode());
PP_Order_Node.setFinishMode(AD_WF_Node[g].getFinishMode());
PP_Order_Node.setValidFrom(AD_WF_Node[g].getValidFrom());
PP_Order_Node.setValidTo(AD_WF_Node[g].getValidTo());
PP_Order_Node.save();
MWFNodeNext[] AD_WF_NodeNext = AD_WF_Node[g].getTransitions(getAD_Client_ID());
log.log(Level.INFO, "AD_WF_NodeNext"+AD_WF_NodeNext.length);
if(AD_WF_NodeNext != null)
{
for (int n = 0; n < AD_WF_NodeNext.length; n++)
{
MPPOrderNodeNext PP_Order_NodeNext = new MPPOrderNodeNext(getCtx(),0,get_TrxName());
PP_Order_NodeNext.setAD_WF_Node_ID(AD_WF_NodeNext[n].getAD_WF_Node_ID());
PP_Order_NodeNext.setAD_WF_Next_ID(AD_WF_NodeNext[n].getAD_WF_Next_ID());
PP_Order_NodeNext.setPP_Order_Node_ID(PP_Order_Node.getPP_Order_Node_ID());
PP_Order_NodeNext.setPP_Order_Next_ID(0);
PP_Order_NodeNext.setDescription(AD_WF_NodeNext[n].getDescription());
PP_Order_NodeNext.setEntityType(AD_WF_NodeNext[n].getEntityType());
PP_Order_NodeNext.setIsStdUserWorkflow(AD_WF_NodeNext[n].isStdUserWorkflow());
PP_Order_NodeNext.setPP_Order_ID (getPP_Order_ID());
PP_Order_NodeNext.setSeqNo(AD_WF_NodeNext[n].getSeqNo());
PP_Order_NodeNext.setTransitionCode(AD_WF_NodeNext[n].getTransitionCode());
PP_Order_NodeNext.save();
}// end for Node Next
}
}// end for Node
//set transition for order
MPPOrderWorkflow OrderWorkflow = new MPPOrderWorkflow(getCtx(),PP_Order_Workflow.getPP_Order_Workflow_ID(),get_TrxName());
MPPOrderNode[] OrderNodes = OrderWorkflow.getNodes(false , getAD_Client_ID());
if(OrderNodes != null)
{
PP_Order_Workflow.setPP_Order_Node_ID(OrderNodes[0].getPP_Order_Node_ID());
for (int h = 0 ; h < OrderNodes.length ; h ++)
{
MPPOrderNodeNext[] nexts = OrderNodes[h].getTransitions(getAD_Client_ID());
if(nexts != null)
{
log.log(Level.INFO, "Node Transition" + nexts.length);
for (int x = 0; x < nexts.length; x++)
{
String sql = "SELECT PP_Order_Node_ID FROM PP_Order_Node WHERE PP_Order_ID = ? AND AD_WF_Node_ID = ? AND AD_Client_ID=?";
try
{
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt(1, nexts[x].getPP_Order_ID());
pstmt.setInt(2, nexts[x].getAD_WF_Next_ID());
pstmt.setInt(3, nexts[x].getAD_Client_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
nexts[x].setPP_Order_Next_ID(rs.getInt(1));
nexts[x].save();
}
DB.close(rs);
DB.close(pstmt);
}
catch (Exception e)
{
log.log(Level.SEVERE,"doIt - " + sql, e);
}
}// end for Node Next
}
}
}
}// end from / to Node
} // end from /to Workflow
PP_Order_Workflow.save(get_TrxName());
}
return true;
} // beforeSave
protected boolean beforeDelete()
{
// OrderBOMLine
if (getDocStatus().equals(DOCSTATUS_Drafted) || getDocStatus().equals(this.DOCSTATUS_InProgress))
{
@ -948,20 +910,7 @@ public class MPPOrder extends X_PP_Order implements DocAction {
return ok;
}
}
ids = PO.getAllIDs("PP_MRP", "PP_Order_ID="+get_ID()+ " AND AD_Client_ID="+ getAD_Client_ID(), get_TrxName());
for(int i = 0; i < ids.length; i++)
{
po = new MPPMRP(Env.getCtx(), ids[i], get_TrxName());
ok = po.delete(true);
if(!ok) {
return ok;
}
}
}
} //return true;
return true;
} // beforeDelete

View File

@ -29,7 +29,7 @@ import org.compiere.util.KeyNamePair;
/** Generated Model for PP_MRP
* @author Adempiere (generated)
* @version Release 3.5.1a - $Id$ */
* @version Release 3.5.0 - $Id$ */
public class X_PP_MRP extends PO implements I_PP_MRP, I_Persistent
{

View File

@ -29,11 +29,14 @@ import org.compiere.model.MLocator;
import org.compiere.model.MMessage;
import org.compiere.model.MNote;
import org.compiere.model.MOrg;
import org.compiere.model.MBPartner;
import org.compiere.model.MProduct;
import org.compiere.model.MProductPO;
import org.compiere.model.MRequisition;
import org.compiere.model.MRequisitionLine;
import org.compiere.model.MResource;
import org.compiere.model.MSequence;
import org.compiere.model.MTable;
import org.compiere.model.MWarehouse;
import org.compiere.model.PO;
import org.compiere.process.ProcessInfoParameter;
@ -62,7 +65,7 @@ public class MRP extends SvrProcess
private int p_AD_Org_ID = 0;
private int p_S_Resource_ID = 0 ;
private int p_M_Warehouse_ID= 0;
private boolean p_IsRequiredDRP = true;
private boolean p_IsRequiredDRP = false;
private String p_Version = "1";
private String result = "";
@ -77,6 +80,8 @@ public class MRP extends SvrProcess
private BigDecimal QtyScheduledReceipts = Env.ZERO;
private Timestamp DatePromisedFrom = null;
private Timestamp DatePromisedTo = null;
private Timestamp Today = new Timestamp (System.currentTimeMillis());
private Timestamp Date_Planning_Horizon = null;
private int DocTypeReq = 0;
private int DocTypeMO = 0;
@ -92,8 +97,6 @@ public class MRP extends SvrProcess
Planner_ID = Integer.parseInt(Env.getContext(getCtx(), "#AD_User_ID"));
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
@ -107,7 +110,9 @@ public class MRP extends SvrProcess
}
else if (name.equals("S_Resource_ID"))
{
p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue();
p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue();
MResource r = new MResource(getCtx(),p_S_Resource_ID, get_TrxName());
Date_Planning_Horizon = TimeUtil.addDays(Today, r.getPlanningHorizon());
}
else if (name.equals("M_Warehouse_ID"))
{
@ -115,7 +120,7 @@ public class MRP extends SvrProcess
}
else if (name.equals("IsRequiredDRP"))
{
p_IsRequiredDRP = ((String)para[i].getParameter()).equals('Y');
p_IsRequiredDRP = "Y".equals((String)para[i].getParameter());
}
else if (name.equals("Version"))
{
@ -169,8 +174,8 @@ public class MRP extends SvrProcess
DocTypeDO = doc[0].getC_DocType_ID();
log.info("Type Document to Requisition:"+ DocTypeReq);
log.info("Type Document to MO:" + DocTypeMO);
log.info("Type Document to MO:" + DocTypeDO);
log.info("Type Document to Manufacturing Order:" + DocTypeMO);
log.info("Type Document to Distribution Order:" + DocTypeDO);
if(p_M_Warehouse_ID==0)
{
MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID);
@ -199,12 +204,12 @@ public class MRP extends SvrProcess
*/
public boolean deleteMRP(int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID)
{
// Delete Manufacturing Order with Status Draft or Close from MRP Table
String sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'MOP' AND DocStatus IN ('DR','CL') AND AD_Client_ID=" + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID + " AND M_Warehouse_ID="+M_Warehouse_ID;
// Delete Manufacturing Order with Close Status from MRP Table
String sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'MOP' AND DocStatus='CL' AND AD_Client_ID=" + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID + " AND M_Warehouse_ID="+M_Warehouse_ID;
DB.executeUpdate(sql, get_TrxName());
// Delete Requisition with Status Draft from MRP Table
sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'POR' AND DocStatus='DR' AND AD_Client_ID = " + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID+ " AND M_Warehouse_ID="+M_Warehouse_ID;
// Delete Requisition with Status Close from MRP Table
sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'POR' AND DocStatus='CL' AND AD_Client_ID = " + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID+ " AND M_Warehouse_ID="+M_Warehouse_ID;
DB.executeUpdate(sql, get_TrxName());
// Delete Action Notice
@ -215,26 +220,25 @@ public class MRP extends SvrProcess
if (p_IsRequiredDRP)
{
//Delete Distribution Order with Status Draft or Close from MRP Table
sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'DOO' AND DocStatus='DR' AND AD_Client_ID = " + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID+ " AND M_Warehouse_ID="+M_Warehouse_ID;
DB.executeUpdate(sql, get_TrxName());
//Delete Distribution Order with Status Draft or Close from MRP Table
//TODO The
//Delete Distribution Order with Draft Status
sql = "SELECT o.DD_Order_ID FROM DD_Order o WHERE o.DocStatus = 'DR' AND o.AD_Client_ID = ? AND AD_Org_ID=?";
sql = "SELECT MAX(o.DD_Order_ID) FROM DD_Order o INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID) INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_LocatorTo_ID) WHERE o.DocStatus = 'DR' AND o.AD_Client_ID = ? AND o.AD_Org_ID=? AND l.M_Warehouse_ID=? GROUP BY o.DD_Order_ID";
try
{
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql , get_TrxName());
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, AD_Org_ID);
pstmt.setInt(3, M_Warehouse_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
MDDOrder order = new MDDOrder(getCtx(), rs.getInt(1) , get_TrxName());
order.delete(true);
}
rs.close();
pstmt.close();
DB.close(rs);
DB.close(pstmt);
}
catch (Exception e)
@ -257,8 +261,8 @@ public class MRP extends SvrProcess
MPPOrder order = new MPPOrder(getCtx(), rs.getInt(1) , get_TrxName());
order.delete(true);
}
rs.close();
pstmt.close();
DB.close(rs);
DB.close(pstmt);
}
catch (Exception e)
@ -316,8 +320,7 @@ public class MRP extends SvrProcess
{
//String sql = "SELECT LowLevel FROM PP_MRP mrp INNER JOIN M_Product p ON (p.M_Product_ID = mrp.M_Product_ID) WHERE mrp.M_Warehouse_ID = ? ORDER BY p.LowLevel DESC ";
MProduct product = null;
Timestamp DatePromised = null;
Timestamp Today = new Timestamp (System.currentTimeMillis());
Timestamp DatePromised = null;
String sql = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
@ -343,9 +346,15 @@ public class MRP extends SvrProcess
sql = "SELECT p.M_Product_ID ,p.Name , p.LowLevel , mrp.Qty , mrp.DatePromised, mrp.Type , mrp.TypeMRP , mrp.DateOrdered , mrp.M_Warehouse_ID , mrp.PP_MRP_ID , mrp.DateStartSchedule , mrp.DateFinishSchedule"
+" FROM PP_MRP mrp"
+" INNER JOIN M_Product p ON (p.M_Product_ID = mrp.M_Product_ID)"
+" WHERE mrp.Type='D' AND COALESCE(p.LowLevel,0) = "+ index + " AND mrp.AD_Client_ID = " + AD_Client_ID + " AND mrp.AD_Org_ID=" + AD_Org_ID +" AND M_Warehouse_ID=" +M_Warehouse_ID
+" WHERE mrp.Type='D' AND mrp.AD_Client_ID = ? AND mrp.AD_Org_ID=? AND M_Warehouse_ID=? AND "
+" mrp.DatePromised <= ? AND COALESCE(p.LowLevel,0) = ? "
+" ORDER BY p.LowLevel DESC , p.M_Product_ID , mrp.DatePromised ";
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, AD_Org_ID);
pstmt.setInt(3, M_Warehouse_ID);
pstmt.setTimestamp(4, Date_Planning_Horizon);
pstmt.setInt(5, index);
rs = pstmt.executeQuery();
while (rs.next())
{
@ -498,11 +507,19 @@ public class MRP extends SvrProcess
log.info(" Planner: " + m_product_planning.getPlanner_ID());
log.info("Product:" + product.getName());
log.info("PP_Product_BOM_ID:" + m_product_planning.getPP_Product_BOM_ID() + " DD_NetworkDistribution_ID:"+m_product_planning.getDD_NetworkDistribution_ID() +" S_Resource_ID:"+ m_product_planning.getS_Resource_ID() + " TransfertTime:"+m_product_planning.getTransfertTime ()+ " Planner ID:"+ m_product_planning.getPlanner_ID() );
//Find the BOM to this Pruct
//Find the BOM to this Product
if (m_product_planning.getPP_Product_BOM_ID() == 0 && product.isBOM())
{
m_product_planning.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(m_product_planning.getM_Product_ID()));
}
}
if (m_product_planning.getPlanner_ID() == 0 )
{
m_product_planning.setPlanner_ID(Planner_ID);
}
if(m_product_planning.getM_Warehouse_ID() == 0 )
{
m_product_planning.setM_Warehouse_ID(M_Warehouse_ID);
}
}
else
{
@ -516,27 +533,31 @@ public class MRP extends SvrProcess
//Find Vendor
if(product.isPurchased())
{
int C_BPartner_ID = 0;
MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), get_TrxName());
for (int i = 0; i < ppos.length; i++)
{
if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0)
if (!p_IsRequiredDRP)
{
if(product.isPurchased())
{
int C_BPartner_ID = 0;
MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), get_TrxName());
for (int i = 0; i < ppos.length; i++)
{
C_BPartner_ID = ppos[i].getC_BPartner_ID();
m_product_planning.setDeliveryTime_Promised(new BigDecimal(ppos[i].getDeliveryTime_Promised()));
m_product_planning.setOrder_Min(ppos[i].getOrder_Min());
m_product_planning.setOrder_Pack(ppos[i].getOrder_Pack());
if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0)
{
C_BPartner_ID = ppos[i].getC_BPartner_ID();
m_product_planning.setDeliveryTime_Promised(new BigDecimal(ppos[i].getDeliveryTime_Promised()));
m_product_planning.setOrder_Min(ppos[i].getOrder_Min());
m_product_planning.setOrder_Pack(ppos[i].getOrder_Pack());
}
}
if(C_BPartner_ID == 0)
m_product_planning.setIsCreatePlan(false);
}
if(C_BPartner_ID == 0)
m_product_planning.setIsCreatePlan(false);
}
if (m_product_planning.getAD_Workflow_ID() == 0 )
log.info("Error: Do not exist workflow");
if (product.isBOM())
{
if (m_product_planning.getAD_Workflow_ID() == 0 )
log.info("Error: Do not exist workflow");
}
}
if (m_product_planning.getOrder_Policy() == null)
m_product_planning.setOrder_Policy(MPPProductPlanning.ORDER_POLICY_LoteForLote);
@ -606,7 +627,7 @@ public class MRP extends SvrProcess
// Note : the variables DemandDateStartSchedule , DemandDateFinishSchedule are same DatePromised to Demands Sales Order Type
Timestamp Today = new Timestamp (System.currentTimeMillis());
log.info("Create Plan ....");
log.info("Create Plan ...");
BigDecimal DecimalYield = new BigDecimal(m_product_planning.getYield()/100);
if (!DecimalYield.equals(Env.ZERO))
@ -688,17 +709,20 @@ public class MRP extends SvrProcess
{
MDDNetworkDistribution network = new MDDNetworkDistribution(getCtx(),m_product_planning.getDD_NetworkDistribution_ID(), get_TrxName());
MDDNetworkDistributionLine[] network_lines = network.getLines(p_M_Warehouse_ID);
//Get the distribution lines
MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID());
int M_Shipper_ID = 0;
MDDOrder order = null;
for (MDDNetworkDistributionLine network_line : network_lines)
{
//get supply source warehouse and locator
MWarehouse source = MWarehouse.get(getCtx(), network_line.getM_WarehouseSource_ID());
MWarehouse target = MWarehouse.get(getCtx(), network_line.getM_Warehouse_ID());
MLocator locator = MLocator.getDefault(source);
//get supply target warehouse and locator
MWarehouse target = MWarehouse.get(getCtx(), network_line.getM_Warehouse_ID());
MLocator locator_to = MLocator.getDefault(target);
//get the transfer time
BigDecimal transfertTime = network_line.getTransfertTime();
if(transfertTime.compareTo(Env.ZERO) <= 0)
{
@ -709,58 +733,75 @@ public class MRP extends SvrProcess
{
log.info("Do not exist default Locator for Warehouse" );
MMessage MRP=MMessage.get(Env.getCtx(), "DRP-001");
MNote note = new MNote(getCtx(), MRP.getAD_Message_ID (), m_product_planning.getPlanner_ID(),MPPMRP.Table_ID, PP_MPR_ID,product.getValue() + " " + product.getName(),Msg.getMsg(getCtx(), MRP.getValue()),get_TrxName());
MNote note = new MNote(getCtx(), MRP.getAD_Message_ID(), m_product_planning.getPlanner_ID(),MPPMRP.Table_ID, PP_MPR_ID,product.getValue() + " " + product.getName(),Msg.getMsg(getCtx(), MRP.getValue()),get_TrxName());
note.save();
continue;
}
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), target.getAD_Org_ID());
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID());
if (wsts.length <= 0)
{
log.info("Do not exist Warehouse to this Organization");
log.info("Do not exist Warehouse in Transit for this Organization");
MMessage MRP=MMessage.get(Env.getCtx(), "DRP-010");
MNote note = new MNote(getCtx(), MRP.getAD_Message_ID (), m_product_planning.getPlanner_ID(),MPPMRP.Table_ID, PP_MPR_ID,product.getValue() + " " + product.getName(),Msg.getMsg(getCtx(), MRP.getValue()),get_TrxName());
note.save();
continue;
}
if(network_line.getM_Shipper_ID()==0)
{
log.info("Do not exist Shipper for Create Distribution Order");
MMessage MRP=MMessage.get(Env.getCtx(), "DRP-030");
MNote note = new MNote(getCtx(), MRP.getAD_Message_ID (), m_product_planning.getPlanner_ID(),MPPMRP.Table_ID, PP_MPR_ID,product.getValue() + " " + product.getName(),Msg.getMsg(getCtx(), MRP.getValue()),get_TrxName());
note.save();
continue;
}
if(M_Shipper_ID != network_line.getM_Shipper_ID())
{
// //Org Must be linked to BPartner
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID());
int C_BPartner_ID = org.getLinkedC_BPartner_ID(get_TrxName());
MBPartner bp = null;
if (C_BPartner_ID == 0)
{
log.info("Org targer do not linked to BPartner");
log.info("Organization targer do not linked with BPartner");
MMessage MRP=MMessage.get(Env.getCtx(), "DRP-020");
MNote note = new MNote(getCtx(), MRP.getAD_Message_ID (), m_product_planning.getPlanner_ID(),MPPMRP.Table_ID, PP_MPR_ID,product.getValue() + " " + product.getName(),Msg.getMsg(getCtx(), MRP.getValue()),get_TrxName());
note.save();
continue;
}
order = new MDDOrder(getCtx() , 0 , get_TrxName());
bp = new MBPartner(getCtx(),C_BPartner_ID,get_TrxName());
// Try found some order with Shipper , Business Partner and Doc Status = Draft
// Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule
String date = DB.TO_DATE(DemandDateStartSchedule);
order = (MDDOrder) MTable.get(getCtx(), MDDOrder.Table_Name).getPO("M_Shipper_ID ="+M_Shipper_ID+" AND C_BPartner_ID="+bp.getC_BPartner_ID() +" AND DatePromised=" + date + " AND DocStatus='DR'", get_TrxName());
if (order==null)
order = new MDDOrder(getCtx() , 0 , get_TrxName());
order.setAD_Org_ID(target.getAD_Org_ID());
order.setDocumentNo(MSequence.getDocumentNo(DocTypeDO,get_TrxName(),false));
order.setC_BPartner_ID(C_BPartner_ID);
//order.setAD_User_ID(bp.getPrimaryAD_User_ID());
order.setAD_User_ID(m_product_planning.getPlanner_ID());
order.setC_DocType_ID(DocTypeDO);
order.setM_Warehouse_ID(wsts[0].getM_Warehouse_ID());
order.setDocAction(MDDOrder.DOCACTION_Complete);
order.setDateOrdered(Today);
//order.setDatePromised(TimeUtil.addDays(DemandDateStartSchedule , (m_product_planning.getDeliveryTime_Promised().add(transfertTime)).negate().intValue()));
order.setDatePromised(DemandDateStartSchedule);
order.setM_Shipper_ID(network_line.getM_Shipper_ID());
order.setIsInDispute(false);
order.setIsInTransit(false);
//order.setSalesRep_ID(m_product_planning.getPlanner_ID());
order.setSalesRep_ID(bp.getPrimaryAD_User_ID());
order.save();
M_Shipper_ID = network_line.getM_Shipper_ID();
}
BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
BigDecimal QtyOrdered = QtyPlanned; //.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
MDDOrderLine oline = new MDDOrderLine(getCtx(), 0 , get_TrxName());
oline.setDD_Order_ID(order.getDD_Order_ID());

View File

@ -108,12 +108,13 @@ public class MRPUpdate extends SvrProcess
String where = "";
if (AD_Org_ID > 0 )
where = " AND AD_Org_ID=" + AD_Org_ID;
where += " AND AD_Org_ID=" + AD_Org_ID;
if (M_Warehouse_ID > 0 )
where = " AND M_Warehouse_ID=" + M_Warehouse_ID;
where += " AND M_Warehouse_ID=" + M_Warehouse_ID;
String sql = "DELETE FROM PP_MRP WHERE TypeMRP = 'MOP' AND AD_Client_ID=" + m_AD_Client_ID + where;
DB.executeUpdate(sql, trx.getTrxName());
trx.commit();
sql = "DELETE FROM PP_MRP mrp WHERE mrp.TypeMRP = 'FCT' AND mrp.AD_Client_ID = " + m_AD_Client_ID+ where;
DB.executeUpdate(sql,trx.getTrxName());
@ -220,7 +221,7 @@ public class MRPUpdate extends SvrProcess
+"nextval('pp_mrp_id') , null,"
+"t.qty, 'D', 'FCT', t.updated, t.updatedby, f.Name,"
+"t.ad_client_id "
+"FROM M_ForecastLine t INNER JOIN M_Forecast f ON (f.M_Forecast_ID=t.M_Forecast_ID) WHERE t.AD_Client_ID="+ AD_Client_ID;
+"FROM M_ForecastLine t INNER JOIN M_Forecast f ON (f.M_Forecast_ID=t.M_Forecast_ID) WHERE t.Qty > 0 AND t.AD_Client_ID="+ AD_Client_ID;
String where = "";

View File

@ -125,7 +125,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
Log.log(Level.SEVERE, "VMRPDetailed.init", e);
}
executeQuery();
//executeQuery();
} // init
@ -211,7 +211,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
public void setValue(Object arg0)
{
super.setValue(arg0);
executeQuery();
//executeQuery();
};
};
@ -224,7 +224,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
{
super.setValue(arg0);
executeQuery();
//executeQuery();
};
};
@ -304,7 +304,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
public void setValue(Object arg0)
{
super.setValue(arg0);
executeQuery();
//executeQuery();
};
};
lResource_ID.setLabelFor(fResource_ID);
@ -316,7 +316,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
public void setValue(Object arg0)
{
super.setValue(arg0);
executeQuery();
//executeQuery();
};
};
lPlanner_ID.setLabelFor(fPlanner_ID);
@ -328,7 +328,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
public void setValue(Object arg0)
{
super.setValue(arg0);
executeQuery();
//executeQuery();
};
};
lWarehouse_ID.setLabelFor(fWarehouse_ID);
@ -417,7 +417,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
public void setValue(Object arg0) {
super.setValue(arg0);
fAttrSetInstance_ID.setValue(new Integer(0));
executeQuery();
//executeQuery();
};
};
//AttributeSet Button
@ -463,7 +463,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
{
selectAttributeSetInstance();
executeQuery();
//executeQuery();
}
});
@ -759,9 +759,9 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
{
zoom();
}
else
else if (cmd.equals(ConfirmPanel.A_REFRESH))
{
executeQuery();
executeQuery();
}
m_frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
@ -1213,7 +1213,7 @@ public class VMRPDetailed extends CPanel implements FormPanel, ActionListener, V
sql.append( " FROM ").append(from);
//
StringBuffer where = new StringBuffer("PP_MRP.DocStatus IN ('IP','CO','DR') AND PP_MRP.IsActive='Y' and PP_MRP.Qty!=0 ");
StringBuffer where = new StringBuffer("PP_MRP.DocStatus IN ('DR','IP','CO') AND PP_MRP.IsActive='Y' and PP_MRP.Qty!=0 ");
sql.append(" WHERE ").append(where.toString());
if (!staticWhere.equals(""))
sql.append(staticWhere);