Libero QA assurance:

* move MForecastLine class to org.compiere.model
* use getSQLValue*Ex instead of getSQLValue
* code refactoring & cleanup
* correct trxName usage
* improved exception handling
This commit is contained in:
teo_sarca 2009-01-08 12:19:57 +00:00
parent fb473ceeea
commit 6476744416
27 changed files with 1383 additions and 1552 deletions

View File

@ -0,0 +1,62 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
import org.compiere.model.MDocType;
import org.compiere.model.MRefList;
import org.compiere.util.Env;
import org.compiere.util.Util;
/**
* Throwed when desired document type was not found
* @author Teo Sarca, www.arhipac.ro
*/
public class DocTypeNotFoundException extends AdempiereException
{
private static final long serialVersionUID = 1L;
/** Doc Base Type */
private String m_docBaseType = null;
/**
* @param docBaseType Document Base Type (see MDocType.DOCBASETYPE_*)
* @param additionalInfo optional if there is some additional info
*/
public DocTypeNotFoundException(String docBaseType, String additionalInfo)
{
super(additionalInfo);
m_docBaseType = docBaseType;
}
public String getDocBaseType()
{
return m_docBaseType;
}
@Override
public String getMessage()
{
String additionalInfo = super.getMessage();
String docBaseTypeName = MRefList.getListName(Env.getCtx(), MDocType.DOCBASETYPE_AD_Reference_ID, getDocBaseType());
StringBuffer sb = new StringBuffer("@NotFound@ @C_DocType_ID@");
sb.append(" - @DocBaseType@ : " + docBaseTypeName);
if (!Util.isEmpty(additionalInfo, true))
{
sb.append(" (").append(additionalInfo).append(")");
}
return sb.toString();
}
}

View File

@ -0,0 +1,87 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
*****************************************************************************/
package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.eevolution.model.MPPMRP;
/**
* Forecast Line Model
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MForecastLine.java,v 1.11 2005/05/17 05:29:52 vpj-cd Exp $
*/
public class MForecastLine extends X_M_ForecastLine
{
private static final long serialVersionUID = 1L;
/**
* Standard Constructor
* @param ctx context
* @param M_ForecastLine_ID id
*/
public MForecastLine (Properties ctx, int M_ForecastLine_ID, String trxName)
{
super (ctx, M_ForecastLine_ID, trxName);
} // MForecastLine
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MForecastLine (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MRequisitionLine
/**
* After Save.
* Update Total on Header
* @param newRecord if new record
* @param success save was success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;
//begin e-evolution vpj-cd 10/30/2004
MPPMRP.M_ForecastLine(this,false);
//end e-evolution vpj-cd 10/30/2004
return true;
} // afterSave
/**
* After Delete
* @param success
* @return true/false
*/
protected boolean afterDelete (boolean success)
{
if (!success)
return success;
//begin e-evolution vpj-cd 10/30/2004
MPPMRP.M_ForecastLine(this,true);
//end e-evolution vpj-cd 10/30/2004
return true;
} // afterDelete
} // MForecastLine

View File

@ -669,7 +669,7 @@ public class MWFNode extends X_AD_WF_Node
public BigDecimal getCostForCostElementType(String CostElementType, int C_AcctSchema_ID,int M_CostType_ID,int AD_Org_ID,int setuptime, int duration)
{
MResource resource = (MResource) getS_Resource();
//get the rate and convert in second for this cost type element (Rsource, Burden)
//get the rate and convert in second for this cost type element (Resource, Burden)
MWorkflow workflow = getWorkflow();
double rate = resource.getResouceRate(C_AcctSchema_ID, M_CostType_ID,CostElementType, AD_Org_ID);
BigDecimal cost = Env.ZERO;
@ -678,7 +678,7 @@ public class MWFNode extends X_AD_WF_Node
return Env.ZERO;
}
int C_UOM_ID = DB.getSQLValue(get_TrxName(),"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , getS_Resource_ID());
int C_UOM_ID = DB.getSQLValueEx(get_TrxName(),"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , getS_Resource_ID());
MUOM uom = MUOM.get(getCtx(), C_UOM_ID);
if (uom.isHour())
{

View File

@ -0,0 +1,31 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.eevolution.exceptions;
import org.adempiere.exceptions.AdempiereException;
import org.eevolution.model.MPPOrderNode;
/**
* Throwed when we are trying to process/complete an Order Activity that is already processed/completed
* @author Teo Sarca, www.arhipac.ro
*/
public class ActivityProcessedException extends AdempiereException
{
private static final long serialVersionUID = 1L;
public ActivityProcessedException(MPPOrderNode activity)
{
super("Order Activity Already Processed - "+activity); // TODO: translate
}
}

View File

@ -138,10 +138,10 @@ public class CalloutOrder extends CalloutEngine
if (QtyBatchSize.equals(Env.ZERO))
Qty = Env.ONE;
else
Qty = p_QtyEntered.divide(QtyBatchSize , 0, BigDecimal.ROUND_UP);
Qty = p_QtyEntered.divide(QtyBatchSize, 0, RoundingMode.UP);
mTab.setValue(MPPOrder.COLUMNNAME_QtyBatchs, Qty);
mTab.setValue(MPPOrder.COLUMNNAME_QtyBatchSize, p_QtyEntered.divide(Qty , BigDecimal.ROUND_HALF_UP));
mTab.setValue(MPPOrder.COLUMNNAME_QtyBatchSize, QtyBatchSize);
return "";
}

View File

@ -12,12 +12,14 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
import java.util.Collection;
import org.compiere.model.MClient;
import org.compiere.model.MForecastLine;
import org.compiere.model.MInOut;
import org.compiere.model.MInOutLine;
import org.compiere.model.MOrder;
@ -27,30 +29,21 @@ import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger;
import org.compiere.util.Msg;
/**
* LiberoValidator
* Libero Validator
*
* @author Victor Perez
* @author Trifon Trifonov
* @author Victor Perez
* @author Trifon Trifonov
* <li>[ 2270421 ] Can not complete Shipment (Customer)</li>
*
* @version $Id: LiberoValidator.java,v 1 vpj-cd Exp $
* @author Teo Sarca, www.arhipac.ro
*/
public class LiberoValidator implements ModelValidator
{
/**
* Constructor.
* The class is instantiated when logging in and client is selected/known
*/
public LiberoValidator ()
{
super ();
} // LiberoValidator
/** Logger */
private CLogger log = CLogger.getCLogger(getClass());
/** Client */
@ -60,10 +53,13 @@ public class LiberoValidator implements ModelValidator
public void initialize (ModelValidationEngine engine, MClient client)
{
//client = null for global validator
if (client != null) {
if (client != null)
{
m_AD_Client_ID = client.getAD_Client_ID();
log.info(client.toString());
} else {
}
else
{
log.info("Initializing global validator: "+this.toString());
}
// Tables to be monitored
@ -80,217 +76,130 @@ 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(MOrder.Table_Name))
boolean isChange = (TYPE_AFTER_NEW == type || (TYPE_AFTER_CHANGE == type && MPPMRP.isChanged(po)));
boolean isDelete = (TYPE_BEFORE_DELETE == type);
boolean isCompleted = false;
boolean isVoided = false;
DocAction doc = null;
if (po instanceof DocAction)
{
doc = (DocAction)po;
}
else if (po instanceof MOrderLine)
{
doc = ((MOrderLine)po).getParent();
}
if (doc != null)
{
String docStatus = doc.getDocStatus();
isCompleted = DocAction.STATUS_InProgress.equals(docStatus)
|| DocAction.STATUS_Completed.equals(docStatus);
isVoided = DocAction.STATUS_Voided.equals(docStatus);
}
//
//
if (isDelete || isVoided)
{
MPPMRP.deleteMRP(po);
}
else if (po instanceof MOrder)
{
MOrder order = (MOrder)po;
//Create a planning supply when isPurchase Order
if (type == TYPE_AFTER_NEW && !order.isSOTrx())
// Create/Update a planning supply when isPurchase Order
// or when you change DatePromised or DocStatus and is Purchase Order
if (isChange && !order.isSOTrx())
{
MPPMRP.C_Order(order, false);
}
//Update MRP when you change DatePromised or DocStatus and is Purchase Order
else if (type == TYPE_AFTER_CHANGE && !order.isSOTrx())
// Update MRP when you change the status order to complete or in process for a sales order
// or you change DatePromised
else if (type == TYPE_AFTER_CHANGE && order.isSOTrx())
{
if ( order.is_ValueChanged(MOrder.COLUMNNAME_DatePromised)
|| order.is_ValueChanged(MOrder.COLUMNNAME_DocStatus))
MPPMRP.C_Order(order, false);
}
//Update MRP when you change the status order to complete or in process for a sales order or you change DatePromised
if (type == TYPE_AFTER_CHANGE && order.isSOTrx())
{
if ( order.is_ValueChanged(MOrder.COLUMNNAME_DatePromised)
|| order.is_ValueChanged(MOrder.COLUMNNAME_DocStatus)
|| order.getDocStatus().equals(MOrder.DOCSTATUS_InProgress)
|| order.getDocStatus().equals(MOrder.DOCSTATUS_Completed))
if (isCompleted || MPPMRP.isChanged(order))
{
MPPMRP.C_Order(order, false);
}
}
}
//
if (po.get_TableName().equals(MOrderLine.Table_Name))
else if (po instanceof MOrderLine && isChange)
{
MOrderLine ol = (MOrderLine)po;
MOrder order = ol.getParent();
//Create a planning supply when isPurchase Order
if (type == TYPE_AFTER_NEW && !order.isSOTrx())
// Create/Update a planning supply when isPurchase Order or you change relevant fields
if (!order.isSOTrx())
{
MPPMRP.C_OrderLine(ol, false);
}
// Update MRP when Sales Order have document status in process or complete and
// you change relevant fields
else if(order.isSOTrx() && isCompleted)
{
MPPMRP.C_OrderLine(ol, false);
//Update MRP when when isPurchase Order and you change DatePromised , Product , Qty Ordered, Qty Delivered
} else if (type == TYPE_AFTER_CHANGE && !order.isSOTrx()) {
if ( ol.is_ValueChanged(MOrderLine.COLUMNNAME_DatePromised)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_M_Product_ID)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_QtyOrdered)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_QtyDelivered)
)
MPPMRP.C_OrderLine(ol, false);
//Update MRP when Sales Order have document status in process or complete
//You change DatePromised , Product , Qty Ordered, Qty Delivered
} else if(type == TYPE_AFTER_CHANGE && order.isSOTrx()) {
if ( order.getDocStatus().equals(MOrder.DOCSTATUS_InProgress)
|| order.getDocStatus().equals(MOrder.DOCSTATUS_Completed))
{
if ( ol.is_ValueChanged(MOrderLine.COLUMNNAME_DatePromised)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_M_Product_ID)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_QtyOrdered)
|| ol.is_ValueChanged(MOrderLine.COLUMNNAME_QtyDelivered)
)
MPPMRP.C_OrderLine(ol, false);
}
}
}
if (po.get_TableName().equals(MOrderLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MOrderLine ol = (MOrderLine)po;
MPPMRP.C_OrderLine(ol, true);
}
if (po.get_TableName().equals(MRequisitionLine.Table_Name) )
//
else if (po instanceof MRequisitionLine && isChange)
{
MRequisitionLine rl = (MRequisitionLine)po;
if (type == TYPE_AFTER_NEW)
{
MPPMRP.M_RequisitionLine(rl, false);
}
if (type == TYPE_AFTER_CHANGE)
{
if ( rl.is_ValueChanged(MRequisitionLine.COLUMNNAME_M_Product_ID)
|| rl.is_ValueChanged(MRequisitionLine.COLUMNNAME_Qty))
MPPMRP.M_RequisitionLine(rl, false);
}
MPPMRP.M_RequisitionLine(rl, false);
}
if (po.get_TableName().equals(MRequisitionLine.Table_Name) && type == TYPE_BEFORE_DELETE )
{
MRequisitionLine ol = (MRequisitionLine)po;
MPPMRP.M_RequisitionLine(ol, true);
}
if (po.get_TableName().equals(MForecastLine.Table_Name))
//
else if (po instanceof MForecastLine && isChange)
{
MForecastLine fl = (MForecastLine)po;
if(type == TYPE_AFTER_NEW)
MPPMRP.M_ForecastLine(fl, false);
if (type == TYPE_AFTER_CHANGE)
{
if ( fl.is_ValueChanged(MForecastLine.COLUMNNAME_M_Product_ID)
|| fl.is_ValueChanged(MForecastLine.COLUMNNAME_Qty)
|| fl.is_ValueChanged(MForecastLine.COLUMNNAME_DatePromised)
)
MPPMRP.M_ForecastLine(fl, false);
}
MPPMRP.M_ForecastLine(fl, false);
}
if (po.get_TableName().equals(MForecastLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MForecastLine ol = (MForecastLine)po;
MPPMRP.M_ForecastLine(ol, true);
}
if (po.get_TableName().equals(MDDOrderLine.Table_Name))
//
else if (po instanceof MDDOrderLine && isChange)
{
MDDOrderLine ol = (MDDOrderLine)po;
if (type == TYPE_AFTER_NEW)
{
MPPMRP.DD_Order_Line(ol , false);
}
if (type == TYPE_AFTER_CHANGE) {
if ( ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_M_Product_ID)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_DatePromised)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_QtyOrdered)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_QtyDelivered)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_ConfirmedQty)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_M_Locator_ID)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_M_LocatorTo_ID)
|| ol.is_ValueChanged(MDDOrderLine.COLUMNNAME_ConfirmedQty))
MPPMRP.DD_Order_Line(ol, false);
}
MPPMRP.DD_Order_Line(ol , false);
}
if (po.get_TableName().equals(MDDOrderLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MDDOrderLine ol = (MDDOrderLine)po;
MPPMRP.DD_Order_Line(ol, true);
}
if (po.get_TableName().equals(MPPOrder.Table_Name))
//
else if (po instanceof MPPOrder && isChange)
{
MPPOrder order = (MPPOrder)po;
if (type == TYPE_AFTER_NEW) {
MPPMRP.PP_Order(order, false);
}
if (type == TYPE_AFTER_CHANGE) {
if ( order.is_ValueChanged(MPPOrder.COLUMNNAME_M_Product_ID)
|| order.is_ValueChanged(MPPOrder.COLUMNNAME_DatePromised)
|| order.is_ValueChanged(MPPOrder.COLUMNNAME_QtyOrdered)
|| order.is_ValueChanged(MPPOrder.COLUMNNAME_QtyDelivered)
|| order.is_ValueChanged(MPPOrder.COLUMNNAME_PP_Product_BOM_ID)
|| order.is_ValueChanged(MPPOrder.COLUMNNAME_AD_Workflow_ID))
MPPMRP.PP_Order(order, false);
}
MPPMRP.PP_Order(order, false);
}
if (po.get_TableName().equals(MPPOrder.Table_Name) && type == TYPE_BEFORE_DELETE)
//
else if (po instanceof MPPOrderBOMLine && isChange)
{
MPPOrder order = (MPPOrder)po;
MPPMRP.PP_Order(order, true);
MPPOrderBOMLine obl = (MPPOrderBOMLine)po;
MPPMRP.PP_Order_BOMLine(obl, false);
}
if (po.get_TableName().equals(MPPOrderBOMLine.Table_Name))
{
MPPOrderBOMLine ol = (MPPOrderBOMLine)po;
if (type == TYPE_AFTER_NEW) {
MPPMRP.PP_Order_BOMLine(ol, false);
}
if (type == TYPE_AFTER_CHANGE) {
if ( ol.is_ValueChanged(MPPOrderBOMLine.COLUMNNAME_M_Product_ID)
|| ol.is_ValueChanged(MPPOrderBOMLine.COLUMNNAME_M_Warehouse_ID)
|| ol.is_ValueChanged(MPPOrderBOMLine.COLUMNNAME_QtyEntered)
|| ol.is_ValueChanged(MPPOrderBOMLine.COLUMNNAME_QtyDelivered))
MPPMRP.PP_Order_BOMLine(ol, false);
}
}
if (po.get_TableName().equals(MPPOrderBOMLine.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MPPOrderBOMLine ol = (MPPOrderBOMLine)po;
MPPMRP.PP_Order_BOMLine(ol, true);
}
//
return null;
} // modelChange
public String docValidate (PO po, int timing)
{
log.info(po.get_TableName() + " Timing: "+timing);
if (po.get_TableName().equals(MInOut.Table_Name) && timing == TIMING_AFTER_COMPLETE)
if (po instanceof MInOut && timing == TIMING_AFTER_COMPLETE)
{
MInOut inout = (MInOut)po;
for (MInOutLine line : inout.getLines())
{
String whereClause = "C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL";
Collection<MOrderLine> olines = new Query(po.getCtx(), MOrderLine.Table_Name, whereClause, po.get_TrxName())
.setParameters(new Object[]{line.getC_OrderLine_ID()}).list();
for (MOrderLine oline: olines)
.setParameters(new Object[]{line.getC_OrderLine_ID()})
.list();
for (MOrderLine oline : olines)
{
if(oline.getQtyOrdered().compareTo(oline.getQtyDelivered()) >= 0)
{
MPPCostCollector cc = new MPPCostCollector(po.getCtx(), oline.getPP_Cost_Collector_ID(), po.get_TrxName());
cc.completeIt();
cc.setDocStatus(MPPCostCollector.DOCSTATUS_Completed);
String docStatus = cc.completeIt();
cc.setDocStatus(docStatus);
cc.setDocAction(MPPCostCollector.DOCACTION_Close);
cc.saveEx();
return Msg.translate(po.getCtx(), "PP_Order_ID")+":"+cc.getPPOrder().getDocumentNo()+Msg.translate(po.getCtx(),"PP_Order_Node_ID")+":"+cc.getPPOrderNode().getValue();
}
return Msg.translate(po.getCtx(), "PP_Order_ID")
+":"+cc.getPP_Order().getDocumentNo()
+Msg.translate(po.getCtx(),"PP_Order_Node_ID")
+":"+cc.getPP_Order_Node().getValue();
}
}
}
}
return null;

View File

@ -72,13 +72,14 @@ public class MHREmployee extends X_HR_Employee //--
whereClause.append(" AND e.IsActive=? ");
params.add(true);
if(p.getHR_Payroll_ID() != 0 && p.getHR_Period_ID() != 0) // this payroll not content periods, NOT IS a Regular Payroll > ogi-cd 28Nov2007
// This payroll not content periods, NOT IS a Regular Payroll > ogi-cd 28Nov2007
if(p.getHR_Payroll_ID() != 0 && p.getHR_Period_ID() != 0)
{
whereClause.append(" AND (e.HR_Payroll_ID IS NULL OR e.HR_Payroll_ID=?) " );
params.add(p.getHR_Payroll_ID());
}
// HR Period
if(p.getHR_Period_ID() != 0)
{
whereClause.append(" AND e.StartDate <=? ");
@ -90,7 +91,8 @@ public class MHREmployee extends X_HR_Employee //--
params.add(p.getDateAcct());
}
if (p.getHR_Department_ID() != 0) // Selected Department
// Selected Department
if (p.getHR_Department_ID() != 0)
{
whereClause.append(" AND e.HR_Department_ID =? ");
params.add(p.getHR_Department_ID());
@ -98,7 +100,8 @@ public class MHREmployee extends X_HR_Employee //--
whereClause.append(" ) "); // end select from HR_Employee
if (p.getC_BPartner_ID() != 0 ) // Selected Employee
// Selected Employee
if (p.getC_BPartner_ID() != 0)
{
whereClause.append(" AND C_BPartner_ID =? ");
params.add(p.getC_BPartner_ID());

View File

@ -18,24 +18,25 @@ package org.eevolution.model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.Adempiere;
import org.compiere.acct.Doc;
import org.compiere.model.MAcctSchema;
import org.adempiere.exceptions.DocTypeNotFoundException;
import org.adempiere.exceptions.FillMandatoryException;
import org.adempiere.exceptions.NoVendorForProductException;
import org.compiere.model.I_C_UOM;
import org.compiere.model.I_M_Product;
import org.compiere.model.MAttributeSetInstance;
import org.compiere.model.MBPartner;
import org.compiere.model.MClient;
import org.compiere.model.MDocType;
import org.compiere.model.MLocator;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MPeriod;
@ -43,19 +44,19 @@ import org.compiere.model.MProduct;
import org.compiere.model.MProductPO;
import org.compiere.model.MStorage;
import org.compiere.model.MTransaction;
import org.compiere.model.MUOM;
import org.compiere.model.MWarehouse;
import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
import org.compiere.model.Query;
import org.compiere.print.ReportEngine;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CCache;
import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.eevolution.exceptions.ActivityProcessedException;
/**
* PP Cost Collector Model
@ -79,10 +80,13 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
super (ctx, PP_Cost_Collector_ID,trxName);
if (PP_Cost_Collector_ID == 0)
{
setDocAction (DOCACTION_Complete); // CO
setC_DocType_ID(0);
setDocStatus (DOCSTATUS_Drafted); // DR
setDocAction (DOCACTION_Complete); // CO
setMovementDate (new Timestamp(System.currentTimeMillis())); // @#Date@
setIsActive(true);
setPosted (false);
setProcessing (false);
setProcessed (false);
}
} // MPPCostCollector
@ -111,6 +115,20 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
setDescription(desc + " | " + description);
} // addDescription
public void setC_DocTypeTarget_ID(String docBaseType)
{
MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), docBaseType);
if(doc == null)
{
throw new DocTypeNotFoundException(docBaseType, "");
}
else
{
setC_DocTypeTarget_ID(doc[0].get_ID());
}
}
// @Override
public void setProcessed (boolean processed)
{
@ -178,23 +196,23 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
// Operation Activity
if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl))
{
MPPOrderNode activity = getPPOrderNode();
if(activity.getDocStatus().equals(MPPOrderNode.DOCACTION_Complete))
MPPOrderNode activity = getPP_Order_Node();
if(MPPOrderNode.DOCACTION_Complete.equals(activity.getDocStatus()))
{
m_processMsg = "Activity was completed before";
return DocAction.STATUS_Invalid;
throw new ActivityProcessedException(activity);
}
if (activity.isSubcontracting())
{
if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_InProgress) && getDocStatus().equals(MPPCostCollector.DOCSTATUS_InProgress))
if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_InProgress)
&& getDocStatus().equals(MPPCostCollector.DOCSTATUS_InProgress))
{
return MPPOrderNode.DOCSTATUS_InProgress;
}
else if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_InProgress) && getDocStatus().equals(MPPCostCollector.DOCSTATUS_Drafted))
else if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_InProgress)
&& getDocStatus().equals(MPPCostCollector.DOCSTATUS_Drafted))
{
m_processMsg = "Activity was processed before";
return DocAction.STATUS_Invalid;
throw new ActivityProcessedException(activity);
}
createPOrder(activity);
}
@ -209,11 +227,11 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
if (MPPOrderNode.isLastNode(getCtx(), getPP_Order_Node_ID(), get_TrxName()))
{
String whereClause ="AND PP_Order_ID=? AND PP_Order_Node_ID<>?"
final String whereClause ="PP_Order_ID=? AND PP_Order_Node_ID<>?"
+" AND NOT EXISTS (SELECT 1 FROM PP_Cost_Collector cc "
+" WHERE cc.PP_Order_ID=PP_Order_Node.PP_Order_ID AND cc.PP_Order_Node_ID=PP_Order_Node.PP_Order_Node_ID)";
List<MPPOrderNode> nodes = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, this.get_TrxName())
+" WHERE cc.PP_Order_ID=PP_Order_Node.PP_Order_ID"
+" AND cc.PP_Order_Node_ID=PP_Order_Node.PP_Order_Node_ID)";
List<MPPOrderNode> nodes = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Order_ID(),getPP_Order_Node_ID()})
.setOnlyActiveRecords(true)
.list();
@ -226,10 +244,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
m_justPrepared = true;
if (!DOCACTION_Complete.equals(getDocAction()))
{
setDocAction(DOCACTION_Complete);
}
setDocAction(DOCACTION_Complete);
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
if (m_processMsg != null)
@ -296,7 +311,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
// Only for Production Issue records
if (isIssue())
{
checkMaterialPolicy(getPPOrderBOMLine(), getMovementQty());
checkMaterialPolicy(getPP_Order_BOMLine());
}
log.fine("Material Transaction");
@ -324,8 +339,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID,
QtyMA, QtyIssue, QtyReceipt, get_TrxName()))
{
m_processMsg = "Cannot correct Inventory (MA)";
return DocAction.STATUS_Invalid;
throw new AdempiereException(); //Cannot correct Inventory (MA)
}
// Create Transaction
@ -348,8 +362,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID,
Qty, QtyIssue, QtyReceipt, get_TrxName()))
{
m_processMsg = "Cannot correct Inventory";
return DocAction.STATUS_Invalid;
throw new AdempiereException(); // Cannot correct Inventory;
}
// FallBack: Create Transaction
@ -367,56 +380,61 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
if (isIssue())
{
// Update PP Order Line
MPPOrderBOMLine obomline = getPPOrderBOMLine();
if (obomline != null)
{
obomline.setQtyDelivered(obomline.getQtyDelivered().add(getMovementQty()));
obomline.setQtyScrap(obomline.getQtyScrap().add(getScrappedQty()));
obomline.setQtyReject(obomline.getQtyReject().add(getQtyReject()));
obomline.setDateDelivered(getMovementDate()); // overwrite=last
obomline.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID());
log.fine("OrderLine - Reserved=" + obomline.getQtyReserved() + ", Delivered=" + obomline.getQtyDelivered());
obomline.setQtyReserved(obomline.getQtyReserved().subtract(getMovementQty()));
obomline.saveEx();
log.fine("OrderLine -> Reserved="+obomline.getQtyReserved()+", Delivered="+obomline.getQtyDelivered());
}
MPPOrderBOMLine obomline = getPP_Order_BOMLine();
obomline.setQtyDelivered(obomline.getQtyDelivered().add(getMovementQty()));
obomline.setQtyScrap(obomline.getQtyScrap().add(getScrappedQty()));
obomline.setQtyReject(obomline.getQtyReject().add(getQtyReject()));
obomline.setDateDelivered(getMovementDate()); // overwrite=last
obomline.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID());
log.fine("OrderLine - Reserved=" + obomline.getQtyReserved() + ", Delivered=" + obomline.getQtyDelivered());
obomline.setQtyReserved(obomline.getQtyReserved().subtract(getMovementQty()));
obomline.saveEx();
log.fine("OrderLine -> Reserved="+obomline.getQtyReserved()+", Delivered="+obomline.getQtyDelivered());
}
else if (isReceipt())
if (isReceipt())
{
// Update PP Order
MPPOrder order = getPPOrder();
// Update PP Order Qtys
MPPOrder order = getPP_Order();
order.setQtyDelivered(order.getQtyDelivered().add(getMovementQty()));
order.setQtyScrap(order.getQtyScrap().add(getScrappedQty()));
order.setQtyReject(order.getQtyReject().add(getQtyReject()));
order.setDateDelivered(getMovementDate()); // overwrite=last
log.fine("OrderLine - Reserved=" + order.getQtyReserved() + ", Delivered=" + order.getQtyDelivered());
order.setQtyReserved(order.getQtyReserved().subtract(getMovementQty()));
//
// Update PP Order Dates
order.setDateDelivered(getMovementDate()); // overwrite=last
if (order.getDateStart() == null)
{
order.setDateStart(getMovementDate());
}
if (order.getQtyOpen().signum() <= 0)
{
order.setDateFinish(getMovementDate());
}
order.saveEx();
log.fine("Order -> Delivered=" + order.getQtyDelivered());
}
}
else if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl))
{
MPPOrderNode activity = getPPOrderNode();
MPPOrderNode activity = getPP_Order_Node();
if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_Completed))
{
m_processMsg = "Activity was completed before";
return DocAction.STATUS_Invalid;
throw new ActivityProcessedException(activity);
}
if(isSubcontracting())
{
String whereClause = "PP_Cost_Collector_ID =?";
String whereClause = MOrderLine.COLUMNNAME_PP_Cost_Collector_ID+"=?";
Collection<MOrderLine> olines = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{this.getPP_Cost_Collector_ID()}).list();
.setParameters(new Object[]{get_ID()})
.list();
String DocStatus = MPPOrderNode.DOCSTATUS_Completed;
StringBuffer msg = new StringBuffer("The quantity do not is complete for next Purchase Order :");
for (MOrderLine oline: olines)
for (MOrderLine oline : olines)
{
if(oline.getQtyDelivered().compareTo(oline.getQtyOrdered()) < 0)
{
DocStatus = MPPOrderNode.DOCSTATUS_InProgress;
}
msg.append(oline.getParent().getDocumentNo()).append(",");
}
@ -443,9 +461,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
activity.saveEx();
}
}
}
// for all lines
} // end Activity Control
//
setProcessed(true);
setDocAction(DOCACTION_Close);
setDocStatus(DOCSTATUS_Completed);
@ -488,7 +505,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
else
{
String whereClause = MPPOrderNode.COLUMNNAME_PP_Order_ID+"=?"
final String whereClause = MPPOrderNode.COLUMNNAME_PP_Order_ID+"=?"
+" AND ("+MPPOrderNode.COLUMNNAME_DocStatus+" IS NULL OR "+MPPOrderNode.COLUMNNAME_DocStatus+"<>?)";
List<MPPOrderNode> list = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, get_TrxName())
.setOnlyActiveRecords(true)
@ -631,10 +648,27 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
@Override
protected boolean beforeSave(boolean newRecord)
{
/*if (newRecord)
// Set default locator, if not set and we have the warehouse:
if (getM_Locator_ID() <= 0 && getM_Warehouse_ID() > 0)
{
setDocStatus(DOCSTATUS_InProgress);
}*/
MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID());
MLocator loc = wh.getDefaultLocator();
if (loc != null)
{
setM_Locator_ID(loc.get_ID());
}
}
//
if (isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl) && getPP_Order_Node_ID() <= 0)
{
throw new FillMandatoryException(COLUMNNAME_PP_Order_Node_ID);
}
//
if (isIssue() && getPP_Order_BOMLine_ID() <= 0)
{
throw new FillMandatoryException(COLUMNNAME_PP_Order_BOMLine_ID);
}
//
return true;
}
@ -656,7 +690,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
}
protected void completeNew(int PP_Order_ID)
@Deprecated
private void completeNew(int PP_Order_ID)
{
if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl))
{
@ -676,10 +711,10 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
/**
* Check Material Policy.
* Sets line ASI
* Check Material Policy.
* Sets line ASI
*/
private void checkMaterialPolicy(MPPOrderBOMLine line , BigDecimal qty)
private void checkMaterialPolicy(MPPOrderBOMLine line)
{
MPPOrderBOMLineMA.deleteOrderBOMLineMA(line.get_ID(), get_TrxName());
@ -689,6 +724,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
return;
}
BigDecimal qty = getMovementQty();
BigDecimal qtyASI = Env.ZERO ;
// Check Line
@ -749,7 +785,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
} // outgoing Trx
} // checkMaterialPolicy
public MPPOrderNode getPPOrderNode()
@Override
public MPPOrderNode getPP_Order_Node()
{
int node_id = getPP_Order_Node_ID();
if (node_id <= 0)
@ -765,9 +802,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
return m_orderNode;
}
public MPPOrderBOMLine getPPOrderBOMLine()
@Override
public MPPOrderBOMLine getPP_Order_BOMLine()
{
int id = getPP_Order_BOMLine_ID();
if (id <= 0)
@ -783,8 +819,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
return m_bomLine;
}
public MPPOrder getPPOrder()
@Override
public MPPOrder getPP_Order()
{
int id = getPP_Order_ID();
if (id <= 0)
@ -801,104 +837,114 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
/**
* Create Purchase Order (in case of Subcontracting)
* @param activity
*/
private void createPOrder(MPPOrderNode activity)
{
// create purchase order on complete
String whereClause = "PP_Order_ID=? AND PP_Order_Node_ID=? AND IsSubcontracting=?";
Collection<MPPOrderNodeProduct> subctracts = new Query(getCtx(),MPPOrderNodeProduct.Table_Name,whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Order_ID(), activity.getPP_Order_Node_ID(),"Y"})
.setOnlyActiveRecords(true)
.list();
int C_BPartner_ID = -1 ;
CCache<Integer,MOrder> orders = new CCache<Integer,MOrder>(MOrder.Table_Name, 5);
for (MPPOrderNodeProduct subctract: subctracts )
HashMap<Integer,MOrder> orders = new HashMap<Integer,MOrder>();
//
String whereClause = MPPOrderNodeProduct.COLUMNNAME_PP_Order_Node_ID+"=?"
+" AND "+MPPOrderNodeProduct.COLUMNNAME_IsSubcontracting+"=?";
Collection<MPPOrderNodeProduct> subcontracts = new Query(getCtx(), MPPOrderNodeProduct.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{activity.get_ID(), true})
.setOnlyActiveRecords(true)
.list();
for (MPPOrderNodeProduct subcontract : subcontracts)
{
MProduct product = MProduct.get(getCtx(), subctract.getM_Product_ID());
MProductPO m_product_po = null;
if(product.isPurchased() && product.getProductType().equals(MProduct.PRODUCTTYPE_Service))
//
// If Product is not Purchased or is not Service, then it is not a subcontracting candidate [SKIP]
MProduct product = MProduct.get(getCtx(), subcontract.getM_Product_ID());
if(product.isPurchased() && MProduct.PRODUCTTYPE_Service.equals(product.getProductType()))
{
C_BPartner_ID = activity.getC_BPartner_ID();
MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), get_TrxName());
for (MProductPO ppo : ppos)
{
if(C_BPartner_ID == ppo.getC_BPartner_ID())
{
C_BPartner_ID = ppo.getC_BPartner_ID();
m_product_po = ppo;
break;
}
if (ppo.isCurrentVendor() && ppo.getC_BPartner_ID() != 0)
{
C_BPartner_ID = ppo.getC_BPartner_ID();
m_product_po = ppo;
break;
}
}
if(C_BPartner_ID == -1)
throw new AdempiereException(Msg.getMsg(getCtx(), "no.vendor.was.found.for")+" "
+Msg.getMsg(getCtx(),"M_Product_ID") + ":" + product.getName());
Timestamp today = new Timestamp(System.currentTimeMillis());
Timestamp datePromised = TimeUtil.addDays(today, m_product_po.getDeliveryTime_Promised());
MOrder order = orders.get(C_BPartner_ID);
if(order == null)
{
order = new MOrder(getCtx(), 0, get_TrxName());
MBPartner vendor = new MBPartner (getCtx(), C_BPartner_ID, get_TrxName());
order.setBPartner(vendor);
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID();
order.setDatePromised(datePromised);
order.setDescription(getPPOrder().getDocumentNo());
order.setDocStatus(MOrder.DOCSTATUS_Drafted);
order.setDocAction(MOrder.DOCACTION_Complete);
order.setAD_User_ID(getAD_User_ID());
//order.setSalesRep_ID(getAD_User_ID());
order.saveEx();
setDescription(getDescription() == null ? order.getDocumentNo() :
getDescription().concat(Msg.translate(getCtx(), "C_Order_ID")+":"+order.getDocumentNo()));
orders.put(C_BPartner_ID, order);
}
BigDecimal QtyOrdered = Env.ZERO;
// Check Order Min
if(subctract.getQty().signum() > 0 && m_product_po.getOrder_Min().signum() > 0)
{
QtyOrdered = QtyOrdered.max(m_product_po.getOrder_Min());
}
// Check Order Pack
if (m_product_po.getOrder_Pack().signum() > 0 && QtyOrdered.signum() > 0)
{
QtyOrdered = m_product_po.getOrder_Pack().multiply(QtyOrdered.divide(m_product_po.getOrder_Pack(), 0 , BigDecimal.ROUND_UP));
}
MOrderLine oline = new MOrderLine(order);
oline.setM_Product_ID(product.getM_Product_ID());
oline.setDescription(activity.getDescription());
oline.setQty(QtyOrdered);
//line.setPrice(m_product_po.getPricePO());
//oline.setPriceList(m_product_po.getPriceList());
oline.setPP_Cost_Collector_ID(get_ID());
oline.setDatePromised(datePromised);
oline.saveEx();
setProcessed(true);
continue;
}
}
//
// Find Vendor and Product PO data
int C_BPartner_ID = activity.getC_BPartner_ID();
MProductPO product_po = null;
for (MProductPO ppo : MProductPO.getOfProduct(getCtx(), product.get_ID(), null))
{
if(C_BPartner_ID == ppo.getC_BPartner_ID())
{
C_BPartner_ID = ppo.getC_BPartner_ID();
product_po = ppo;
break;
}
if (ppo.isCurrentVendor() && ppo.getC_BPartner_ID() != 0)
{
C_BPartner_ID = ppo.getC_BPartner_ID();
product_po = ppo;
break;
}
}
if(C_BPartner_ID <= 0 || product_po == null)
{
throw new NoVendorForProductException(product.getName());
}
//
// Calculate Lead Time
Timestamp today = new Timestamp(System.currentTimeMillis());
Timestamp datePromised = TimeUtil.addDays(today, product_po.getDeliveryTime_Promised());
//
// Get/Create Purchase Order Header
MOrder order = orders.get(C_BPartner_ID);
if(order == null)
{
order = new MOrder(getCtx(), 0, get_TrxName());
MBPartner vendor = MBPartner.get(getCtx(), C_BPartner_ID);
order.setBPartner(vendor);
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID();
order.setDatePromised(datePromised);
order.setDescription(getPP_Order().getDocumentNo());
order.setDocStatus(MOrder.DOCSTATUS_Drafted);
order.setDocAction(MOrder.DOCACTION_Complete);
order.setAD_User_ID(getAD_User_ID());
//order.setSalesRep_ID(getAD_User_ID());
order.saveEx();
addDescription(Msg.translate(getCtx(), "C_Order_ID")+": "+order.getDocumentNo());
orders.put(C_BPartner_ID, order);
}
//
// Create Order Line:
BigDecimal QtyOrdered = subcontract.getQty();
// Check Order Min
if(product_po.getOrder_Min().signum() > 0)
{
QtyOrdered = QtyOrdered.max(product_po.getOrder_Min());
}
// Check Order Pack
if (product_po.getOrder_Pack().signum() > 0 && QtyOrdered.signum() > 0)
{
QtyOrdered = product_po.getOrder_Pack().multiply(QtyOrdered.divide(product_po.getOrder_Pack(), 0 , BigDecimal.ROUND_UP));
}
MOrderLine oline = new MOrderLine(order);
oline.setM_Product_ID(product.getM_Product_ID());
oline.setDescription(activity.getDescription());
oline.setQty(QtyOrdered);
//line.setPrice(m_product_po.getPricePO());
//oline.setPriceList(m_product_po.getPriceList());
oline.setPP_Cost_Collector_ID(get_ID());
oline.setDatePromised(datePromised);
oline.saveEx();
//
// TODO: Mark this as processed?
setProcessed(true);
} // each subcontracting line
}
@Override
public I_M_Product getM_Product()
{
return MProduct.get(getCtx(), getM_Product_ID());
}
@Override
public I_C_UOM getC_UOM()
{
return MUOM.get(getCtx(), getC_UOM_ID());
}
public boolean isIssue()
@ -942,7 +988,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
* @param args ignored
* @throws IOException
* @throws FileNotFoundException
*/
*
public static void main (String[] args) throws FileNotFoundException, IOException
{
@ -983,12 +1029,11 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
m_Ctx.setProperty("#AD_User_ID", new Integer(AD_User_ID_Value).toString());
m_Ctx.setProperty("#AD_Client_ID", new Integer(AD_Client_ID_Value).toString());
/*if (fileName_Value.length() < 1) {
throw new AdempiereException("Please specify path to Adempiere.properties file!");
}
System.setProperty("PropertyFile", fileName_Value);
*/
// if (fileName_Value.length() < 1) {
// throw new AdempiereException("Please specify path to Adempiere.properties file!");
// }
//
// System.setProperty("PropertyFile", fileName_Value);
//CLogMgt.setLevel(LogLevel_Value);
@ -1010,4 +1055,5 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
}
/**/
} // MPPCostCollector

View File

@ -18,10 +18,13 @@ package org.eevolution.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import org.compiere.model.MDocType;
import org.compiere.model.MForecastLine;
import org.compiere.model.MLocator;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
@ -30,11 +33,11 @@ import org.compiere.model.MRequisition;
import org.compiere.model.MRequisitionLine;
import org.compiere.model.MResource;
import org.compiere.model.MResourceType;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_C_DocType;
import org.compiere.model.X_M_Forecast;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
@ -53,6 +56,130 @@ public class MPPMRP extends X_PP_MRP
{
private static final long serialVersionUID = 1L;
private static CLogger s_log = CLogger.getCLogger(MPPMRP.class);
private static HashMap<String, String[]> s_sourceColumnNames = new HashMap<String, String[]>();
static
{
s_sourceColumnNames.put(MOrder.Table_Name, new String[]{
MOrder.COLUMNNAME_DatePromised,
MOrder.COLUMNNAME_DocStatus,
});
s_sourceColumnNames.put(MOrderLine.Table_Name, new String[]{
"AD_Org_ID",
MOrderLine.COLUMNNAME_DateOrdered,
MOrderLine.COLUMNNAME_DatePromised,
MOrderLine.COLUMNNAME_C_BPartner_ID,
MOrderLine.COLUMNNAME_M_Warehouse_ID,
MOrderLine.COLUMNNAME_M_Product_ID,
MOrderLine.COLUMNNAME_QtyOrdered,
MOrderLine.COLUMNNAME_QtyDelivered,
});
s_sourceColumnNames.put(MRequisition.Table_Name, new String[]{
MRequisition.COLUMNNAME_DateRequired,
MRequisition.COLUMNNAME_M_Warehouse_ID,
});
s_sourceColumnNames.put(MRequisitionLine.Table_Name, new String[]{
"AD_Org_ID",
MRequisitionLine.COLUMNNAME_M_Product_ID,
MRequisitionLine.COLUMNNAME_Qty,
MRequisitionLine.COLUMNNAME_C_OrderLine_ID, // QtyOrdered depends on that
});
s_sourceColumnNames.put(X_M_Forecast.Table_Name, new String[]{
});
s_sourceColumnNames.put(MForecastLine.Table_Name, new String[]{
"AD_Org_ID",
MForecastLine.COLUMNNAME_DatePromised,
MForecastLine.COLUMNNAME_M_Warehouse_ID,
MForecastLine.COLUMNNAME_M_Product_ID,
MForecastLine.COLUMNNAME_Qty,
});
s_sourceColumnNames.put(MDDOrderLine.Table_Name, new String[]{
"AD_Org_ID",
MDDOrderLine.COLUMNNAME_M_Product_ID,
MDDOrderLine.COLUMNNAME_DatePromised,
MDDOrderLine.COLUMNNAME_QtyOrdered,
MDDOrderLine.COLUMNNAME_QtyDelivered,
MDDOrderLine.COLUMNNAME_ConfirmedQty,
MDDOrderLine.COLUMNNAME_M_Locator_ID,
MDDOrderLine.COLUMNNAME_M_LocatorTo_ID,
MDDOrderLine.COLUMNNAME_ConfirmedQty,
});
s_sourceColumnNames.put(MPPOrder.Table_Name, new String[]{
"AD_Org_ID",
MPPOrder.COLUMNNAME_M_Product_ID,
MPPOrder.COLUMNNAME_DatePromised,
MPPOrder.COLUMNNAME_QtyOrdered,
MPPOrder.COLUMNNAME_QtyDelivered,
MPPOrder.COLUMNNAME_PP_Product_BOM_ID,
MPPOrder.COLUMNNAME_AD_Workflow_ID,
});
s_sourceColumnNames.put(MPPOrderBOMLine.Table_Name, new String[]{
MPPOrderBOMLine.COLUMNNAME_M_Product_ID,
MPPOrderBOMLine.COLUMNNAME_M_Warehouse_ID,
MPPOrderBOMLine.COLUMNNAME_QtyEntered,
MPPOrderBOMLine.COLUMNNAME_QtyDelivered,
});
}
/**
* Check if a persistent object is changed, from MRP point of view
* @param po MRP relevant PO (e.g. MOrder, MOrderLine, MPPOrder etc)
* @return true if object changed
*/
public static boolean isChanged(PO po)
{
String[] columnNames = s_sourceColumnNames.get(po.get_TableName());
if (columnNames == null || columnNames.length == 0)
{
return false;
}
for (String columnName : columnNames)
{
if (po.is_ValueChanged(columnName))
{
return true;
}
}
return false;
}
public static void deleteMRP(PO po)
{
String tableName = po.get_TableName();
int no = DB.executeUpdateEx("DELETE FROM "+Table_Name+" WHERE "+tableName+"_ID=? AND AD_Client_ID=?",
new Object[]{po.get_ID(), po.getAD_Client_ID()},
po.get_TrxName());
s_log.finest("Deleted "+tableName+" #"+no);
}
private static Query getQuery(PO po, String typeMRP, String orderType)
{
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer();
//
whereClause.append("AD_Client_ID=?");
params.add(po.getAD_Client_ID());
//
whereClause.append(" AND ").append(po.get_TableName()).append("_ID=?");
params.add(po.get_ID());
//
if (typeMRP != null)
{
whereClause.append(" AND ").append(COLUMNNAME_TypeMRP).append("=?");
params.add(typeMRP);
}
//
if (orderType != null)
{
whereClause.append(" AND ").append(COLUMNNAME_OrderType).append("=?");
params.add(orderType);
}
//
return new Query(po.getCtx(), Table_Name, whereClause.toString(), po.get_TrxName())
.setParameters(params);
}
/**************************************************************************
* Default Constructor
* @param ctx context
@ -122,15 +249,12 @@ public class MPPMRP extends X_PP_MRP
if (delete)
{
final String sql = "DELETE FROM PP_MRP WHERE M_ForecastLine_ID=? AND AD_Client_ID=?";
DB.executeUpdateEx(sql, new Object[]{fl.get_ID(), fl.getAD_Client_ID()}, trxName);
deleteMRP(fl);
return;
}
X_M_Forecast f = new X_M_Forecast(ctx, fl.getM_Forecast_ID(), trxName);
MPPMRP mrp = new Query(ctx, MPPMRP.Table_Name, "M_ForecastLine_ID=?", trxName)
.setParameters(new Object[]{fl.get_ID()})
.first();
MPPMRP mrp = getQuery(fl, null, null).firstOnly();
if (mrp == null)
{
mrp = new MPPMRP(ctx, 0, trxName);
@ -162,21 +286,14 @@ public class MPPMRP extends X_PP_MRP
*/
public static void C_Order(MOrder o, boolean delete)
{
String trxName = o.get_TrxName();
final String whereClause = COLUMNNAME_C_Order_ID+"=? AND AD_Client_ID=?";
Object[] params = new Object[]{o.get_ID(), o.getAD_Client_ID()};
if (delete)
{
final String sql = "DELETE FROM PP_MRP WHERE "+whereClause;
DB.executeUpdateEx(sql, params, trxName);
deleteMRP(o);
return;
}
MDocType dt = MDocType.get(o.getCtx(), o.getC_DocType_ID());
MDocType dt = MDocType.get(o.getCtx(), o.getC_DocTypeTarget_ID());
String DocSubTypeSO = dt.getDocSubTypeSO();
if(MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO) || !o.isSOTrx())
{
if((o.getDocStatus().equals(MOrder.DOCSTATUS_InProgress)
@ -193,9 +310,7 @@ public class MPPMRP extends X_PP_MRP
|| o.is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID)
)
{
List<MPPMRP> list = new Query(o.getCtx(), MPPMRP.Table_Name, whereClause, trxName)
.setParameters(params)
.list();
List<MPPMRP> list = getQuery(o, null, null).list();
for (MPPMRP mrp : list)
{
mrp.setC_Order(o);
@ -213,29 +328,22 @@ public class MPPMRP extends X_PP_MRP
*/
public static void C_OrderLine(MOrderLine ol, boolean delete)
{
Properties ctx = ol.getCtx();
String trxName = ol.get_TrxName();
final String whereClause = "AD_Client_ID = ? AND C_OrderLine_ID = ?";
Object[] params = new Object[]{ol.getAD_Client_ID(),ol.getC_OrderLine_ID()};
if (delete)
{
DB.executeUpdateEx("DELETE FROM PP_MRP WHERE "+whereClause, params, trxName);
MPPOrder order = new Query(ctx, MPPOrder.Table_Name, whereClause, trxName)
.setParameters(params)
.first();
deleteMRP(ol);
// Delete generated manufacturing order
MPPOrder order = MPPOrder.forC_OrderLine_ID(ol.getCtx(), ol.get_ID(), ol.get_TrxName());
if (order != null && !order.isProcessed())
{
order.deleteEx(true, trxName);
order.deleteEx(true);
}
return;
}
MPPMRP mrp = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
.setParameters(params)
.first();
MPPMRP mrp = getQuery(ol, null, null).firstOnly();
if(mrp == null)
{
mrp = new MPPMRP(ctx, 0, trxName);
mrp = new MPPMRP(ol.getCtx(), 0, ol.get_TrxName());
mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID());
}
mrp.setAD_Org_ID(ol.getAD_Org_ID());
@ -256,84 +364,64 @@ public class MPPMRP extends X_PP_MRP
String DocSubTypeSO = dt.getDocSubTypeSO();
if(MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO))
{
MPPOrder order = new Query(ctx, MPPOrder.Table_Name, whereClause, trxName)
.setParameters(params)
.first();
MPPOrder order = MPPOrder.forC_OrderLine_ID(ol.getCtx(), ol.get_ID(), ol.get_TrxName());
if (order == null)
{
String where = MPPProductBOM.COLUMNNAME_BOMType+"=?"
final String whereClause = MPPProductBOM.COLUMNNAME_BOMType+"=?"
+" AND "+MPPProductBOM.COLUMNNAME_M_Product_ID+"=?";
MPPProductBOM bom = new Query(ctx, MPPProductBOM.Table_Name, where, trxName)
MPPProductBOM bom = new Query(ol.getCtx(), MPPProductBOM.Table_Name, whereClause, null)
.setParameters(new Object[]{MPPProductBOM.BOMTYPE_Make_To_Order, ol.getM_Product_ID()})
.first();
.firstOnly();
MPPProductPlanning pp = null;
//Validate the BOM based in planning data
if(bom == null)
{
pp = MPPProductPlanning.find( ctx, ol.getAD_Org_ID() , 0, 0, ol.getM_Product_ID(), trxName);
pp = MPPProductPlanning.find(ol.getCtx(), ol.getAD_Org_ID(), 0, 0, ol.getM_Product_ID(), null);
if(pp != null)
{
if(pp.getPP_Product_BOM_ID() != 0)
bom = (MPPProductBOM) pp.getPP_Product_BOM();
if(bom != null && !MPPProductBOM.BOMTYPE_Make_To_Order.equals(bom.getBOMType()))
{
bom = (MPPProductBOM) pp.getPP_Product_BOM();
if(!bom.getBOMType().equals(MPPProductBOM.BOMTYPE_Make_To_Order))
bom = null;
bom = null;
}
}
}
if (bom != null)
{
MProduct product = MProduct.get(ctx,ol.getM_Product_ID());
String WhereClause = "ManufacturingResourceType = 'PT' AND IsManufacturingResource = 'Y' AND AD_Client_ID = ? AND M_Warehouse_ID = ?";
MResource m_resource = (MResource)MTable.get(ctx,MResource.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),ol.getM_Warehouse_ID()}, trxName);
MWorkflow m_workflow = MWorkflow.get(ctx, MWorkflow.getWorkflowSearchKey(ctx, product));
//Validate the workflow based in planning data
if(m_workflow == null)
{
if(pp != null && pp.getAD_Workflow_ID() != 0)
{
m_workflow = (MWorkflow) pp.getAD_Workflow();
}
}
if (m_resource != null && m_workflow != null)
{
MDocType[] doc = MDocType.getOfDocBaseType(ctx, X_C_DocType.DOCBASETYPE_ManufacturingOrder);
int C_DocType_ID = doc[0].getC_DocType_ID();
order = new MPPOrder(ctx, 0 , trxName);
order.setC_OrderLine_ID(ol.getC_OrderLine_ID());
order.setS_Resource_ID(m_resource.get_ID());
order.setM_Warehouse_ID(ol.getM_Warehouse_ID());
order.setM_Product_ID(ol.getM_Product_ID());
order.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
order.setPP_Product_BOM_ID(bom.get_ID());
order.setAD_Workflow_ID(m_workflow.get_ID());
order.setPlanner_ID(ol.getParent().getSalesRep_ID());
order.setLine(10);
order.setQtyDelivered(Env.ZERO);
order.setQtyReject(Env.ZERO);
order.setQtyScrap(Env.ZERO);
order.setDateOrdered(ol.getDateOrdered());
order.setDatePromised(ol.getDatePromised());
order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), (MPPMRP.getDays(ctx,m_resource.getS_Resource_ID(),m_workflow.getAD_Workflow_ID(), ol.getQtyOrdered(),ol.get_TrxName())).negate().intValue()));
order.setDateFinishSchedule(ol.getDatePromised());
order.setC_UOM_ID(ol.getC_UOM_ID());
order.setQty(ol.getQtyEntered());
order.setPosted(false);
order.setProcessed(false);
order.setC_DocTypeTarget_ID(C_DocType_ID);
order.setC_DocType_ID(C_DocType_ID);
order.setPriorityRule(MPPOrder.PRIORITYRULE_High);
order.saveEx();
order.prepareIt();
//order.setDocAction(MPPOrder.DOCSTATUS_Completed);
order.saveEx();
final MProduct product = MProduct.get(ol.getCtx(), ol.getM_Product_ID());
final int plant_id = MPPProductPlanning.getPlantForWarehouse(ol.getM_Warehouse_ID());
MWorkflow workflow = MWorkflow.get(ol.getCtx(), MWorkflow.getWorkflowSearchKey(ol.getCtx(), product));
//Validate the workflow based in planning data
if(workflow == null && pp != null)
{
workflow = pp.getAD_Workflow();
}
//
if (plant_id > 0 && workflow != null)
{
int duration = MPPMRP.getDays(ol.getCtx(), plant_id, workflow.get_ID(), ol.getQtyOrdered(), ol.get_TrxName()).intValue();
//
order = new MPPOrder(ol.getCtx(), 0 , ol.get_TrxName());
order.setC_OrderLine_ID(ol.getC_OrderLine_ID());
order.setS_Resource_ID(plant_id);
order.setM_Warehouse_ID(ol.getM_Warehouse_ID());
order.setM_Product_ID(ol.getM_Product_ID());
order.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
order.setPP_Product_BOM_ID(bom.get_ID());
order.setAD_Workflow_ID(workflow.get_ID());
order.setPlanner_ID(ol.getParent().getSalesRep_ID());
order.setLine(10);
order.setDateOrdered(ol.getDateOrdered());
order.setDatePromised(ol.getDatePromised());
order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), 0 - duration));
order.setDateFinishSchedule(ol.getDatePromised());
order.setC_UOM_ID(ol.getC_UOM_ID());
order.setQty(ol.getQtyOrdered());
order.setPriorityRule(MPPOrder.PRIORITYRULE_High);
order.saveEx();
order.prepareIt();
order.saveEx();
}
}
}
@ -370,18 +458,12 @@ public class MPPMRP extends X_PP_MRP
if (delete)
{
String sql = "DELETE FROM PP_MRP WHERE PP_Order_ID=? AND AD_Client_ID=?";
Object[] params = new Object[]{o.getPP_Order_ID(), o.getAD_Client_ID()};
DB.executeUpdateEx(sql, params, trxName);
deleteMRP(o);
return;
}
//
// Supply
final String whereClause = "TypeMRP=? AND OrderType=? AND AD_Client_ID=? AND PP_Order_ID=?";
MPPMRP mrpSupply = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
.setParameters(new Object[]{MPPMRP.TYPEMRP_Supply, MPPMRP.ORDERTYPE_ManufacturingOrder, o.getAD_Client_ID(), o.getPP_Order_ID()})
.first();
MPPMRP mrpSupply = getQuery(o, TYPEMRP_Supply, ORDERTYPE_ManufacturingOrder).firstOnly();
if(mrpSupply == null)
{
mrpSupply = new MPPMRP(ctx, 0, trxName);
@ -393,13 +475,10 @@ public class MPPMRP extends X_PP_MRP
mrpSupply.setM_Product_ID(o.getM_Product_ID());
mrpSupply.setM_Warehouse_ID(o.getM_Warehouse_ID());
mrpSupply.saveEx();
//
// Demand
List<MPPMRP> demand = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
.setParameters(new Object[]{MPPMRP.TYPEMRP_Demand, MPPMRP.ORDERTYPE_ManufacturingOrder, o.getAD_Client_ID(), o.getPP_Order_ID()})
.list();
for (MPPMRP mrpDemand : demand)
List<MPPMRP> mrpDemandList = getQuery(o, TYPEMRP_Demand, ORDERTYPE_ManufacturingOrder).list();
for (MPPMRP mrpDemand : mrpDemandList)
{
mrpDemand.setPP_Order(o);
mrpDemand.saveEx();
@ -411,31 +490,39 @@ public class MPPMRP extends X_PP_MRP
* @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 trxName = obl.get_TrxName();
Properties ctx = obl.getCtx();
if (delete)
{
final String sql = "DELETE FROM PP_MRP WHERE PP_Order_BOMLine_ID=? AND AD_Client_ID=?";
DB.executeUpdateEx(sql, new Object[]{obl.get_ID(), obl.getAD_Client_ID()}, trxName);
deleteMRP(obl);
return;
}
final String whereClause = "TypeMRP=? AND OrderType=? AND PP_Order_BOMLine_ID=? AND AD_Client_ID=?";
MPPMRP mrp = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
.setParameters(new Object[]{TYPEMRP_Demand, ORDERTYPE_ManufacturingOrder, obl.get_ID(), obl.getAD_Client_ID()})
.first();
MPPOrder o = obl.getParent();
//
String typeMRP = MPPMRP.TYPEMRP_Demand;
BigDecimal qty = obl.getQtyRequiered().subtract(obl.getQtyDelivered());
//
// By-Product support:
if (obl.isComponentType(MPPOrderBOMLine.COMPONENTTYPE_ByProduct))
{
// TODO: need to evaluate
deleteMRP(obl);
return;
// typeMRP = MPPMRP.TYPEMRP_Supply;
// qty = qty.negate();
}
//
MPPMRP mrp = getQuery(obl, typeMRP, ORDERTYPE_ManufacturingOrder).firstOnly();
if(mrp == null)
{
mrp = new MPPMRP(ctx, 0, trxName);
mrp.setAD_Org_ID(obl.getAD_Org_ID());
mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID());
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
}
mrp.setPP_Order(o);
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
mrp.setAD_Org_ID(obl.getAD_Org_ID());
mrp.setTypeMRP(typeMRP);
mrp.setPP_Order(obl.getParent());
mrp.setQty(qty);
mrp.setM_Product_ID(obl.getM_Product_ID());
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
mrp.saveEx();
@ -448,12 +535,9 @@ public class MPPMRP extends X_PP_MRP
*/
public static void DD_Order(MDDOrder o, boolean delete)
{
String sql = null;
String trxName = o.get_TrxName();
if (delete)
{
sql = "DELETE FROM PP_MRP WHERE DD_Order_ID = "+ o.getDD_Order_ID() +" AND AD_Client_ID = " + o.getAD_Client_ID();
DB.executeUpdateEx(sql, trxName);
deleteMRP(o);
return;
}
}
@ -465,20 +549,18 @@ public class MPPMRP extends X_PP_MRP
*/
public static void DD_Order_Line(MDDOrderLine ol, boolean delete)
{
String sql = null;
String trxName = ol.getParent().get_TrxName();
Properties m_ctx = ol.getCtx();
if (delete)
{
sql = "DELETE FROM PP_MRP WHERE DD_OrderLine_ID = "+ ol.getDD_OrderLine_ID() +" AND AD_Client_ID = " + ol.getAD_Client_ID();
DB.executeUpdateEx(sql ,trxName);
deleteMRP(ol);
return;
}
String whereClause = "TypeMRP = ? AND OrderType=? AND AD_Client_ID=? AND DD_OrderLine_ID = ?";
MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{MPPMRP.TYPEMRP_Demand,"DOO",ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName);
//
MPPMRP mrp = getQuery(ol, TYPEMRP_Demand, ORDERTYPE_DistributionOrder).firstOnly();
MLocator source = MLocator.get( m_ctx , ol.getM_Locator_ID());
MLocator target = MLocator.get( m_ctx , ol.getM_LocatorTo_ID());
if(mrp!=null)
if(mrp != null)
{
mrp.setAD_Org_ID(source.getAD_Org_ID());
mrp.setName("MRP");
@ -510,8 +592,7 @@ public class MPPMRP extends X_PP_MRP
mrp.saveEx();
}
whereClause ="TypeMRP=? AND OrderType=? AND AD_Client_ID=? AND DD_OrderLine_ID = ? ";
mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{MPPMRP.TYPEMRP_Supply,"DOO",ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName);
mrp = getQuery(ol, TYPEMRP_Supply, ORDERTYPE_DistributionOrder).firstOnly();
if(mrp!=null)
{
mrp.setAD_Org_ID(target.getAD_Org_ID());
@ -554,37 +635,30 @@ public class MPPMRP extends X_PP_MRP
*/
public static void M_RequisitionLine( MRequisitionLine rl , boolean delete)
{
String trxName = rl.get_TrxName();
Properties ctx = rl.getCtx();
final String whereClause = "M_RequisitionLine_ID=? AND AD_Client_ID=?";
Object[] params = new Object[]{rl.getM_RequisitionLine_ID(), rl.getAD_Client_ID()};
if (delete)
{
DB.executeUpdateEx("DELETE FROM PP_MRP WHERE "+whereClause, params, trxName);
deleteMRP(rl);
return;
}
MPPMRP mrp = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
.setParameters(params)
.first();
MPPMRP mrp = getQuery(rl, null, null).firstOnly();
MRequisition r = rl.getParent();
if (mrp == null)
{
mrp = new MPPMRP(ctx, 0, trxName);
mrp.setAD_Org_ID(r.getAD_Org_ID());
mrp = new MPPMRP(rl.getCtx(), 0, rl.get_TrxName());
mrp.setM_Requisition_ID(rl.getM_Requisition_ID());
mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID());
mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition);
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
mrp.setIsAvailable(true);
}
mrp.setAD_Org_ID(r.getAD_Org_ID());
mrp.setName("MRP");
mrp.setDescription(rl.getDescription());
mrp.setDateOrdered(r.getDateRequired());
mrp.setDatePromised(r.getDateRequired());
mrp.setDateStartSchedule(r.getDateRequired());
mrp.setDateFinishSchedule(r.getDateRequired());
mrp.setDateOrdered(r.getDateRequired());
mrp.setM_Product_ID(rl.getM_Product_ID());
mrp.setM_Warehouse_ID(r.getM_Warehouse_ID());
// We create a MRP record only for Not Ordered Qty. The Order will generate a MRP record for Ordered Qty.
@ -605,12 +679,9 @@ public class MPPMRP extends X_PP_MRP
*/
public static BigDecimal getQtyOnHand(Properties ctx, int M_Warehouse_ID ,int M_Product_ID,String trxName)
{
final String sql = "SELECT SUM(bomQtyOnHand (M_Product_ID,?,0)) AS OnHand FROM M_Product"
final String sql = "SELECT COALESCE(bomQtyOnHand (M_Product_ID,?,0),0) FROM M_Product"
+" WHERE AD_Client_ID=? AND M_Product_ID=?";
BigDecimal QtyOnHand = DB.getSQLValueBDEx(trxName, sql, new Object[]{M_Warehouse_ID,Env.getAD_Client_ID(ctx),M_Product_ID});
if (QtyOnHand == null)
QtyOnHand = Env.ZERO;
return QtyOnHand;
return DB.getSQLValueBDEx(trxName, sql, new Object[]{M_Warehouse_ID,Env.getAD_Client_ID(ctx),M_Product_ID});
}
/**
@ -624,9 +695,17 @@ public class MPPMRP extends X_PP_MRP
*/
public static BigDecimal getQtyReserved(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp To,String trxName)
{
StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP WHERE TypeMRP=? AND DocStatus IN ('IN','CO')");
sql.append(" AND OrderType IN ('SOO','MOP','DOO') AND AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?");
BigDecimal qty = DB.getSQLValueBDEx(trxName, sql.toString(), new Object[]{MPPMRP.TYPEMRP_Demand,Env.getAD_Client_ID(ctx), To , M_Warehouse_ID, M_Product_ID});
final String sql = "SELECT SUM(Qty) FROM PP_MRP WHERE "
+" TypeMRP=?"
+" AND DocStatus IN ('IN','CO')"
+" AND OrderType IN ('SOO','MOP','DOO')"
+" AND AD_Client_ID=? AND M_Warehouse_ID =? AND M_Product_ID=?"
+" AND DatePromised <=?";
BigDecimal qty = DB.getSQLValueBDEx(trxName, sql, new Object[]{
MPPMRP.TYPEMRP_Demand,
Env.getAD_Client_ID(ctx),M_Warehouse_ID, M_Product_ID,
To,
});
// SQL may return no rows or null
if (qty == null)
return Env.ZERO;

View File

@ -25,6 +25,7 @@ import java.util.List;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DocTypeNotFoundException;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MClient;
import org.compiere.model.MCost;
@ -67,65 +68,13 @@ public class MPPOrder extends X_PP_Order implements DocAction
/** Product */
private MProduct m_product = null;
/**
* Create new Order by copying
* @param ctx context
* @param C_Order_ID invoice
* @param dateDoc date of the document date
* @param counter create counter links
* @return Order
*/
public static MPPOrder copyFrom(MPPOrder from, Timestamp dateDoc, int C_DocTypeTarget_ID,
boolean isSOTrx, boolean counter)
public static MPPOrder forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName)
{
MPPOrder to = new MPPOrder(from.getCtx(), 0, "PP_Order");
PO.copyValues(from, to, from.getAD_Client_ID(), from.getAD_Org_ID());
to.setPP_Order_ID(0);
to.set_ValueNoCheck("DocumentNo", null);
//
to.setDocStatus(DOCSTATUS_Drafted); // Draft
to.setDocAction(DOCACTION_Prepare);
//
//to.setC_DocType_ID(this.C_DOCTYPE_ID_ManufacturingOrder);
//to.setC_DocTypeTarget_ID(C_DocTypeTarget_ID);
to.setIsSOTrx(isSOTrx);
//
to.setIsSelected(false);
/*to.setDateOrdered (dateDoc);
to.setDateAcct (dateDoc);
to.setDatePromised (dateDoc);
to.setDatePrinted(null);
to.setIsPrinted (false);
//*/
to.setIsApproved(false);
/*to.setIsCreditApproved(false);
to.setC_Payment_ID(0);
to.setC_CashLine_ID(0);
// Amounts are updated when adding lines
to.setGrandTotal(Env.ZERO);
to.setTotalLines(Env.ZERO);
//
to.setIsDelivered(false);
to.setIsInvoiced(false);
to.setIsSelfService(false);
to.setIsTransferred (false);*/
to.setPosted(false);
to.setProcessed(false);
/*if (counter)
to.setRef_Order_ID(from.getC_Order_ID());
else
to.setRef_Order_ID(0);
//
*/
to.saveEx();
/*if (counter)
from.setRef_Order_ID(to.getC_Order_ID());
return new Query(ctx, MPPOrder.Table_Name, COLUMNNAME_C_OrderLine_ID+"=?", trxName)
.setParameters(new Object[]{C_OrderLine_ID})
.firstOnly();
}
if (to.copyLinesFrom(from, counter) == 0)
throw new IllegalStateException("Could not create Order Lines");
*/
return to;
} // copyFrom
/**************************************************************************
* Default Constructor
@ -136,7 +85,11 @@ public class MPPOrder extends X_PP_Order implements DocAction
{
super(ctx, PP_Order_ID, trxName);
// New
if (PP_Order_ID == 0) {
if (PP_Order_ID == 0)
{
setQtyDelivered(Env.ZERO);
setQtyReject(Env.ZERO);
setQtyScrap(Env.ZERO);
setIsSelected(false);
setIsSOTrx(false);
setIsApproved(false);
@ -144,17 +97,10 @@ public class MPPOrder extends X_PP_Order implements DocAction
setProcessed(false);
setProcessing(false);
setPosted(false);
MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_ManufacturingOrder);
if(doc == null)
{
throw new IllegalArgumentException ("C_DocType_ID is mandatory.");
}
else
{
setC_DocType_ID(doc[0].getC_DocType_ID());
setC_DocTypeTarget_ID(doc[0].getC_DocType_ID());
}
//
setC_DocType_ID(0);
setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ManufacturingOrder);
//
//set_ValueNoCheck("DocumentNo", null);
setDocStatus(DOCSTATUS_Drafted);
setDocAction(DOCACTION_Prepare);
@ -229,18 +175,47 @@ public class MPPOrder extends X_PP_Order implements DocAction
/**
* Get BOM Lines of PP Order
* @param requery
* @return Order BOM Lines
*/
public MPPOrderBOMLine[] getLines()
public MPPOrderBOMLine[] getLines(boolean requery)
{
if (m_lines != null && !requery)
{
set_TrxName(m_lines, get_TrxName());
return m_lines;
}
String whereClause = MPPOrderBOMLine.COLUMNNAME_PP_Order_ID+"=?";
//
List<MPPOrderBOMLine> list = new Query(getCtx(), MPPOrderBOMLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Order_ID()})
.setOrderBy(MPPOrderBOMLine.COLUMNNAME_Line)
.list();
return list.toArray(new MPPOrderBOMLine[list.size()]);
} // getLines
m_lines = list.toArray(new MPPOrderBOMLine[list.size()]);
return m_lines;
}
private MPPOrderBOMLine[] m_lines = null;
/**
* Get BOM Lines of PP Order
* @return Order BOM Lines
*/
public MPPOrderBOMLine[] getLines()
{
return getLines(true);
}
public void setC_DocTypeTarget_ID(String docBaseType)
{
MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), docBaseType);
if(doc == null)
{
throw new DocTypeNotFoundException(docBaseType, "");
}
else
{
setC_DocTypeTarget_ID(doc[0].get_ID());
}
}
@Override
public void setProcessed(boolean processed)
@ -297,32 +272,9 @@ public class MPPOrder extends X_PP_Order implements DocAction
return false;
}
if( is_ValueChanged(MPPOrder.COLUMNNAME_QtyEntered) &&
getDocStatus().equals(MPPOrder.DOCSTATUS_Drafted))
if( is_ValueChanged(MPPOrder.COLUMNNAME_QtyEntered) && getDocStatus().equals(MPPOrder.DOCSTATUS_Drafted))
{
for(MPPOrderBOMLine line : getLines())
{
line.deleteEx(true);
}
MPPOrderBOM bom = getMPPOrderBOM();
if(bom != null)
bom.deleteEx(true, get_TrxName());
MPPOrderWorkflow PP_Order_Workflow = getMPPOrderWorkflow();
if (PP_Order_Workflow != null)
{
PP_Order_Workflow.setPP_Order_Node_ID(0);
PP_Order_Workflow.saveEx();
for(MPPOrderNode node : PP_Order_Workflow.getNodes(true, getAD_Client_ID()))
{
for(MPPOrderNodeNext next : node.getTransitions(getAD_Client_ID()))
{
next.deleteEx(true);
}
node.deleteEx(true);
}
PP_Order_Workflow.deleteEx(true);
}
deleteWorkflowAndBOM();
explotion();
}
if( is_ValueChanged(MPPOrder.COLUMNNAME_QtyEntered) && !getDocStatus().equals(MPPOrder.DOCSTATUS_Drafted))
@ -347,23 +299,37 @@ public class MPPOrder extends X_PP_Order implements DocAction
{
String whereClause = "PP_Order_ID=? AND AD_Client_ID=?";
Object[] params = new Object[]{get_ID(), getAD_Client_ID()};
// Delete Cost:
//
deletePO(MPPOrderCost.Table_Name, whereClause, params);
// Delete workflow:
DB.executeUpdateEx("UPDATE PP_Order_Workflow SET PP_Order_Node_ID=NULL WHERE "+whereClause, params, get_TrxName()); // Reset workflow start node
deletePO(X_PP_Order_Node_Asset.Table_Name, whereClause, params);
deletePO(X_PP_Order_Node_Product.Table_Name, whereClause, params);
deletePO(MPPOrderNodeNext.Table_Name, whereClause, params);
deletePO(MPPOrderNode.Table_Name, whereClause, params);
deletePO(MPPOrderWorkflow.Table_Name, whereClause, params);
// Delete BOM:
deletePO(MPPOrderBOMLine.Table_Name, whereClause, params);
deletePO(MPPOrderBOM.Table_Name, whereClause, params);
deleteWorkflowAndBOM();
}
return true;
} // beforeDelete
private void deleteWorkflowAndBOM()
{
// New record, nothing to do
if (get_ID() <= 0)
{
return;
}
//
String whereClause = "PP_Order_ID=? AND AD_Client_ID=?";
Object[] params = new Object[]{get_ID(), getAD_Client_ID()};
// Reset workflow start node
DB.executeUpdateEx("UPDATE PP_Order_Workflow SET PP_Order_Node_ID=NULL WHERE "+whereClause, params, get_TrxName());
// Delete workflow:
deletePO(X_PP_Order_Node_Asset.Table_Name, whereClause, params);
deletePO(X_PP_Order_Node_Product.Table_Name, whereClause, params);
deletePO(MPPOrderNodeNext.Table_Name, whereClause, params);
deletePO(MPPOrderNode.Table_Name, whereClause, params);
deletePO(MPPOrderWorkflow.Table_Name, whereClause, params);
// Delete BOM:
deletePO(MPPOrderBOMLine.Table_Name, whereClause, params);
deletePO(MPPOrderBOM.Table_Name, whereClause, params);
}
public boolean processIt(String processAction)
{
m_processMsg = null;
@ -651,13 +617,17 @@ public class MPPOrder extends X_PP_Order implements DocAction
return DocAction.STATUS_Completed;
} // completeIt
/**
* Check if the Quantity from all BOM Lines is available (QtyOnHand >= QtyRequired)
* @return true if entire Qty is available for this Order
*/
public boolean isAvailable()
{
String whereClause = "QtyOnHand - QtyRequiered < 0 AND PP_Order_ID=?";
boolean notAvailable = new Query(getCtx(), X_RV_PP_Order_Storage.Table_Name, whereClause, get_TrxName())
String whereClause = "QtyOnHand >= QtyRequiered AND PP_Order_ID=?";
boolean available = new Query(getCtx(), "RV_PP_Order_Storage", whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
.match();
return !notAvailable;
return available;
}
public boolean voidIt()
@ -879,7 +849,11 @@ public class MPPOrder extends X_PP_Order implements DocAction
.first();
}
public void explotion()
/**
* Create PP_Order_BOM from PP_Product_BOM.
* Create PP_Order_Workflow from AD_Workflow.
*/
private void explotion()
{
// Create BOM Head
MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
@ -924,28 +898,22 @@ public class MPPOrder extends X_PP_Order implements DocAction
for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID()))
{
MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node, get_TrxName());
MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
nodenext.setAD_Org_ID(getAD_Org_ID());
nodenext.saveEx();
}// for NodeNext
for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.get(getCtx(), AD_WF_Node.get_ID() , get_TrxName()))
for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID()))
{
MPPOrderNodeProduct nodeorderproduct = new MPPOrderNodeProduct(wfnp);
MPPOrderNodeProduct nodeorderproduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
nodeorderproduct.setAD_Org_ID(getAD_Org_ID());
nodeorderproduct.setPP_Order_ID(getPP_Order_ID());
nodeorderproduct.setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID());
nodeorderproduct.setPP_Order_Node_ID(PP_Order_Node.getPP_Order_Node_ID());
nodeorderproduct.saveEx();
}// for NodeNext
}
for (MPPWFNodeAsset wfna : MPPWFNodeAsset.get(getCtx(), AD_WF_Node.get_ID() , get_TrxName()))
for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID()))
{
MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna);
MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
nodeorderasset.setAD_Org_ID(getAD_Org_ID());
nodeorderasset.setPP_Order_ID(getPP_Order_ID());
nodeorderasset.setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID());
nodeorderasset.setPP_Order_Node_ID(PP_Order_Node.getPP_Order_Node_ID());
nodeorderasset.saveEx();
}
}// for node
@ -956,7 +924,8 @@ public class MPPOrder extends X_PP_Order implements DocAction
for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID()))
{
// set workflow start node
if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID())
{
PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
}
// set node next

View File

@ -17,34 +17,42 @@
package org.eevolution.model;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MProduct;
import org.compiere.model.MUOM;
import org.compiere.model.MWarehouse;
import org.compiere.model.Query;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* PP Order BOM Line Model.
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MOrderLine.java,v 1.22 2004/03/22 07:15:03 vpj-cd Exp $
* PP Order BOM Line Model.
*
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPOrderBOMLine extends X_PP_Order_BOMLine
{
private static final long serialVersionUID = 1L;
/**
* Default Constructor
* @param ctx context
* @param C_OrderLine_ID order line to load
*/
public MPPOrderBOMLine(Properties ctx, int PP_Order_BOMLine_ID,String trxName)
public static MPPOrderBOMLine forM_Product_ID(Properties ctx, int PP_Order_ID, int M_Product_ID, String trxName)
{
super (ctx, PP_Order_BOMLine_ID,trxName);
final String whereClause = COLUMNNAME_PP_Order_ID+"=? AND "+COLUMNNAME_M_Product_ID+"=?";
return new Query(ctx, Table_Name, whereClause, trxName)
.setParameters(new Object[]{PP_Order_ID, M_Product_ID})
.firstOnly();
}
public MPPOrderBOMLine(Properties ctx, int PP_Order_BOMLine_ID, String trxName)
{
super (ctx, PP_Order_BOMLine_ID, trxName);
if (PP_Order_BOMLine_ID == 0)
{
setQtyDelivered(Env.ZERO);
@ -57,11 +65,6 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
} // PP_Order_BOMLine_ID
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MPPOrderBOMLine(Properties ctx, ResultSet rs,String trxName)
{
super (ctx, rs,trxName);
@ -106,20 +109,27 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
setBackflushGroup(bomLine.getBackflushGroup());
}
/**
* Parent (PP_Order)
*/
private MPPOrder m_parent = null;
/** Qty used for exploding this BOM Line */
/**
* Qty used for exploding this BOM Line.
* When ComponentType is Phantom, it is set on beforeSave as QtyRequired and reset on afterSave.
*/
private BigDecimal m_qtyToExplode = null;
@Override
protected boolean beforeSave(boolean newRecord) {
protected boolean beforeSave(boolean newRecord)
{
// Get Line No
if (getLine() == 0)
{
String sql = "SELECT COALESCE(MAX("+COLUMNNAME_Line+"),0)+10 FROM "+Table_Name
+" WHERE "+COLUMNNAME_PP_Order_ID+"=?";
int ii = DB.getSQLValue (get_TrxName(), sql, getPP_Order_ID());
int ii = DB.getSQLValueEx (get_TrxName(), sql, getPP_Order_ID());
setLine (ii);
}
@ -147,15 +157,15 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
MProduct parent = MProduct.get(getCtx(), getM_Product_ID());
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(getCtx(), parent);
if (PP_Product_BOM_ID <= 0)
{
return true;
}
MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID);
if (bom != null)
{
MPPProductBOMLine[] PP_Product_BOMline = bom.getLines();
for(int i = 0 ; i < PP_Product_BOMline.length ; i++ )
for(MPPProductBOMLine PP_Product_BOMline : bom.getLines())
{
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline[i],
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline,
getPP_Order_ID(), getPP_Order_BOM_ID(),
getM_Warehouse_ID(),
get_TrxName());
@ -176,67 +186,159 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
return MProduct.get(getCtx(), getM_Product_ID());
}
@Override
public MUOM getC_UOM()
{
return MUOM.get(getCtx(), getC_UOM_ID());
}
@Override
public MWarehouse getM_Warehouse()
{
return MWarehouse.get(getCtx(), getM_Warehouse_ID());
}
/**
* Get Parent
* @return parent
* @return PP_Order
*/
public MPPOrder getParent()
{
if (m_parent == null)
m_parent = new MPPOrder(getCtx(), getPP_Order_ID(), get_TrxName());
int id = getPP_Order_ID();
if (id <= 0)
{
m_parent = null;
return null;
}
if (m_parent == null || m_parent.get_ID() != id)
{
m_parent = new MPPOrder(getCtx(), id, get_TrxName());
}
return m_parent;
} // getParent
public void setQtyOrdered(BigDecimal QtyOrdered)
{
// Set Qty Required
BigDecimal multiplier = Env.ZERO;
if (isQtyPercentage())
{
BigDecimal qty = getQtyBatch().multiply(QtyOrdered);
if (getComponentType().equals(COMPONENTTYPE_Component)
|| getComponentType().equals(COMPONENTTYPE_Phantom))
{
setQtyRequiered(qty.divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_UP));
}
else if (getComponentType().equals(COMPONENTTYPE_Packing))
{
setQtyRequiered(qty.divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_UP));
}
else if (getComponentType().equals(COMPONENTTYPE_Tools))
{
setQtyRequiered(getQtyBOM());
}
else
{
throw new AdempiereException("@NotSupported@ @ComponentType@ "+getComponentType());
}
multiplier = getQtyBatch().divide(Env.ONEHUNDRED, 8, RoundingMode.UP);
}
else
{
if (getComponentType().equals(COMPONENTTYPE_Component)
|| getComponentType().equals(COMPONENTTYPE_Phantom))
{
setQtyRequiered(getQtyBOM().multiply(QtyOrdered));
}
else if (getComponentType().equals(COMPONENTTYPE_Packing))
{
setQtyRequiered(getQtyBOM().multiply(QtyOrdered));
}
else if (getComponentType().equals(COMPONENTTYPE_Tools))
{
setQtyRequiered(getQtyBOM());
}
else
{
throw new AdempiereException("@NotSupported@ @ComponentType@ "+getComponentType());
}
multiplier = getQtyBOM();
}
BigDecimal qty = QtyOrdered.multiply(multiplier).setScale(8, RoundingMode.UP);
if (isComponentType(COMPONENTTYPE_Component,COMPONENTTYPE_Phantom
,COMPONENTTYPE_Packing
,COMPONENTTYPE_ByProduct))
{
setQtyRequiered(qty);
}
else if (isComponentType(COMPONENTTYPE_Tools))
{
setQtyRequiered(multiplier);
}
else
{
throw new AdempiereException("@NotSupported@ @ComponentType@ "+getComponentType());
}
//
// Set Scrap of Component
BigDecimal Scrap = getScrap();
if (Scrap.signum() != 0) {
if (Scrap.signum() != 0)
{
Scrap = Scrap.divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_UP);
setQtyRequiered(getQtyRequiered().divide(Env.ONE.subtract(Scrap), 8, BigDecimal.ROUND_HALF_UP));
}
}
/**
* @return Qty Open (Requiered - Delivered)
*/
public BigDecimal getQtyOpen()
{
return getQtyRequiered().subtract(getQtyDelivered());
}
/** Storage Qty On Hand */
private BigDecimal m_qtyOnHand = null;
/** Storage Qty Available */
private BigDecimal m_qtyAvailable = null;
/**
* Load Storage Info
* @param reload
*/
private void loadStorage(boolean reload)
{
if (!reload && m_qtyOnHand != null && m_qtyAvailable != null)
{
return;
}
//
final String sql = "SELECT "
+" bomQtyAvailable("+COLUMNNAME_M_Product_ID+", "+COLUMNNAME_M_Warehouse_ID+", 0)"
+",bomQtyOnHand("+COLUMNNAME_M_Product_ID+", "+COLUMNNAME_M_Warehouse_ID+", 0)"
+" FROM "+Table_Name
+" WHERE "+COLUMNNAME_PP_Order_BOMLine_ID+"=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
DB.setParameters(pstmt, new Object[]{get_ID()});
rs = pstmt.executeQuery();
if (rs.next())
{
m_qtyAvailable = rs.getBigDecimal(1);
m_qtyOnHand = rs.getBigDecimal(2);
}
}
catch (SQLException e)
{
throw new DBException(e, sql);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
}
/**
* @return storage Available Qty
*/
public BigDecimal getQtyAvailable()
{
loadStorage(false);
return m_qtyAvailable;
}
/**
* @return storage Qty On Hand
*/
public BigDecimal getQtyOnHand()
{
loadStorage(false);
return m_qtyOnHand;
}
/**
* @param componentTypes one or more component types
* @return true of Component Type is any of following types
*/
public boolean isComponentType(String ... componentTypes)
{
String currentType = getComponentType();
for (String type : componentTypes)
{
if (currentType.equals(type))
{
return true;
}
}
return false;
}
}

View File

@ -26,12 +26,10 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
/**
* Shipment Material Allocation
* Cost Collector Material Allocation
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPPOrderBOMLineMA.java,v 1.1 2005/04/01 05:59:48 vpj-cd Exp $
*
* @author Teo Sarca, http://www.arhipac.ro
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, http://www.arhipac.ro
*/
public class MPPOrderBOMLineMA extends X_PP_Order_BOMLineMA
{

View File

@ -16,33 +16,25 @@
*****************************************************************************/
package org.eevolution.model;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MColumn;
import org.compiere.model.MResource;
import org.compiere.model.MUOM;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWorkflow;
import org.jfree.util.Log;
/**
* PP Order Workflow Node Model
*
* @author Jorg Janke
* @version $Id: MWFNode.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
* PP Order Workflow Node Model
*
* @author Victor Perez, e-Evolution, S.C.
* @author Teo Sarca, http://www.arhipac.ro
*/
public class MPPOrderNode extends X_PP_Order_Node
@ -67,6 +59,19 @@ public class MPPOrderNode extends X_PP_Order_Node
return retValue;
} // get
/**
* @return true if this is last node
*/
public static boolean isLastNode(Properties ctx, int PP_Order_Node_ID, String trxName)
{
String whereClause = MPPOrderNodeNext.COLUMNNAME_PP_Order_Node_ID+"=?";
return false == new Query(ctx, MPPOrderNodeNext.Table_Name, whereClause, trxName)
.setOnlyActiveRecords(true)
.setParameters(new Object[]{PP_Order_Node_ID})
.match();
}
/** Cache */
private static CCache<Integer,MPPOrderNode> s_cache = new CCache<Integer,MPPOrderNode> (Table_Name, 50);
@ -196,8 +201,6 @@ public class MPPOrderNode extends X_PP_Order_Node
/** Next Modes */
private List<MPPOrderNodeNext> m_next = new ArrayList<MPPOrderNodeNext>();
/** Column */
private MColumn m_column = null;
/** Duration Base MS */
private long m_durationBaseMS = -1;
@ -207,22 +210,27 @@ public class MPPOrderNode extends X_PP_Order_Node
private void loadNext()
{
boolean splitAnd = SPLITELEMENT_AND.equals(getSplitElement());
String whereClause = "PP_Order_Node_ID=? ";
String whereClause = MPPOrderNodeNext.COLUMNNAME_PP_Order_Node_ID+"=?";
m_next = new Query(getCtx(), MPPOrderNodeNext.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
.setOnlyActiveRecords(true)
.setOrderBy(MPPOrderNodeNext.COLUMNNAME_SeqNo)
.list();
for (MPPOrderNodeNext next : m_next) {
for (MPPOrderNodeNext next : m_next)
{
next.setFromSplitAnd(splitAnd);
}
log.fine("#" + m_next.size());
} // loadNext
/**
* Set Qty Required and DurationRequired (Duration * qtyOrdered)
* @param qtyOrdered
*/
public void setQtyOrdered(BigDecimal qtyOrdered)
{
setQtyRequiered(qtyOrdered);
BigDecimal time = new BigDecimal(getDuration()).multiply(qtyOrdered);
BigDecimal time = BigDecimal.valueOf(getDuration()).multiply(qtyOrdered);
setDurationRequiered(time.intValue());
}
@ -243,146 +251,16 @@ public class MPPOrderNode extends X_PP_Order_Node
public MPPOrderNodeNext[] getTransitions(int AD_Client_ID)
{
ArrayList<MPPOrderNodeNext> list = new ArrayList<MPPOrderNodeNext>();
for (int i = 0; i < m_next.size(); i++)
for (MPPOrderNodeNext next : m_next)
{
MPPOrderNodeNext next = m_next.get(i);
if (next.getAD_Client_ID() == 0 || next.getAD_Client_ID() == AD_Client_ID)
{
list.add(next);
}
}
MPPOrderNodeNext[] retValue = new MPPOrderNodeNext [list.size()];
list.toArray(retValue);
return retValue;
return list.toArray(new MPPOrderNodeNext [list.size()]);
} // getNextNodes
/**
* Set Position
* @param position point
*/
public void setPosition (Point position)
{
setPosition(position.x, position.y);
} // setPosition
/**
* Set Position
* @param x x
* @param y y
*/
public void setPosition (int x, int y)
{
setXPosition(x);
setYPosition(y);
} // setPosition
/**
* Get Position
* @return position point
*/
public Point getPosition ()
{
return new Point (getXPosition(), getYPosition());
} // getPosition
/**
* Get Action Info
* @return info
*/
public String getActionInfo()
{
String action = getAction();
if (ACTION_AppsProcess.equals(action))
return "Process:AD_Process_ID=" + getAD_Process_ID();
else if (ACTION_DocumentAction.equals(action))
return "DocumentAction=" + getDocAction();
else if (ACTION_AppsReport.equals(action))
return "Report:AD_Process_ID=" + getAD_Process_ID();
else if (ACTION_AppsTask.equals(action))
return "Task:AD_Task_ID=" + getAD_Task_ID();
else if (ACTION_SetVariable.equals(action))
return "SetVariable:AD_Column_ID=" + getAD_Column_ID();
else if (ACTION_SubWorkflow.equals(action))
return "Workflow:PP_Order_Workflow_ID=" + getPP_Order_Workflow_ID();
else if (ACTION_UserChoice.equals(action))
return "UserChoice:AD_Column_ID=" + getAD_Column_ID();
else if (ACTION_UserWorkbench.equals(action))
return "Workbench:?";
else if (ACTION_UserForm.equals(action))
return "Form:AD_Form_ID=" + getAD_Form_ID();
else if (ACTION_UserWindow.equals(action))
return "Window:AD_Window_ID=" + getAD_Window_ID();
//else if (ACTION_WaitSleep.equals(action))
// return "Sleep:WaitTime=" + getWaitTime();
return "??";
} // getActionInfo
/**
* Get Attribute Name
* @see org.compiere.model.X_PP_Order_Node#getAttributeName()
* @return Attribute Name
*/
@Override
public String getAttributeName ()
{
if (getAD_Column_ID() == 0)
return super.getAttributeName();
// We have a column
String attribute = super.getAttributeName();
if (attribute != null && attribute.length() > 0)
return attribute;
setAttributeName(getColumn().getColumnName());
return super.getAttributeName ();
} // getAttributeName
/**
* Get Column
* @return column if valid
*/
public MColumn getColumn()
{
if (getAD_Column_ID() == 0)
return null;
if (m_column == null)
m_column = MColumn.get(getCtx(), getAD_Column_ID());
return m_column;
} // getColumn
/**
* Is this an Approval setp?
* @return true if User Approval
*/
public boolean isUserApproval()
{
if (!ACTION_UserChoice.equals(getAction()))
return false;
return getColumn() != null
&& "IsApproved".equals(getColumn().getColumnName());
} // isApproval
/**
* Is this a User Choice step?
* @return true if User Choice
*/
public boolean isUserChoice()
{
return ACTION_UserChoice.equals(getAction());
} // isUserChoice
/**
* Is this a Manual user step?
* @return true if Window/Form/Workbench
*/
public boolean isUserManual()
{
if (ACTION_UserForm.equals(getAction())
|| ACTION_UserWindow.equals(getAction())
|| ACTION_UserWorkbench.equals(getAction()))
return true;
return false;
} // isUserManual
/**
* Get Duration in ms
* @return duration in ms
@ -421,7 +299,7 @@ public class MPPOrderNode extends X_PP_Order_Node
} // getDurationCalendarField
/**
* Get Workflow
* Get Workflow (NoTrx)
* @return workflow
*/
public MPPOrderWorkflow getPPOrderWorkflow()
@ -438,126 +316,10 @@ public class MPPOrderNode extends X_PP_Order_Node
StringBuffer sb = new StringBuffer ("MPPOrderNode[");
sb.append(get_ID())
.append("-").append(getName())
.append(",Action=").append(getActionInfo())
.append ("]");
return sb.toString ();
} // toString
/**
* User String Representation
* @return info
*/
public String toStringX()
{
StringBuffer sb = new StringBuffer ("MPPOrderNode[");
sb.append(getName())
.append("-").append(getActionInfo())
.append("]");
return sb.toString ();
} // toStringX
@Override
protected boolean beforeSave (boolean newRecord)
{
String action = getAction();
if (action.equals(ACTION_WaitSleep))
{
;
}
else if (action.equals(ACTION_AppsProcess) || action.equals(ACTION_AppsReport))
{
if (getAD_Process_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Process_ID"));
return false;
}
}
else if (action.equals(ACTION_AppsTask))
{
if (getAD_Task_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Task_ID"));
return false;
}
}
else if (action.equals(ACTION_DocumentAction))
{
if (getDocAction() == null || getDocAction().length() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "DocAction"));
return false;
}
}
/*else if (action.equals(ACTION_EMail))
{
if (getR_MailText_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "R_MailText_ID"));
return false;
}
}*/
else if (action.equals(ACTION_SetVariable))
{
if (getAttributeValue() == null)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AttributeValue"));
return false;
}
}
else if (action.equals(ACTION_SubWorkflow))
{
if (getPP_Order_Workflow_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "PP_Order_Workflow_ID"));
return false;
}
}
else if (action.equals(ACTION_UserChoice))
{
if (getAD_Column_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Column_ID"));
return false;
}
}
else if (action.equals(ACTION_UserForm))
{
if (getAD_Form_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Form_ID"));
return false;
}
}
else if (action.equals(ACTION_UserWindow))
{
if (getAD_Window_ID() == 0)
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Window_ID"));
return false;
}
}
// else if (action.equals(ACTION_UserWorkbench))
// {
// && getAD_Workbench_ID() == 0)
// log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Workbench_ID"));
// return false;
// }
return true;
} // beforeSave
/**
* @return true if this is last node
*/
public static boolean isLastNode(Properties ctx, int PP_Order_Node_ID, String trxName)
{
String whereClause = MPPOrderNodeNext.COLUMNNAME_PP_Order_Node_ID+"=?";
return false == new Query(ctx, MPPOrderNodeNext.Table_Name, whereClause, trxName)
.setOnlyActiveRecords(true)
.setParameters(new Object[]{PP_Order_Node_ID})
.match();
}
/**
* Calculate the cost for this Activity using the Cost Element Type
* @param CostElementType Cost Element Type (Labor or Burden)
@ -581,7 +343,7 @@ public class MPPOrderNode extends X_PP_Order_Node
return Env.ZERO;
}
int C_UOM_ID = DB.getSQLValue(get_TrxName(),"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , getS_Resource_ID());
int C_UOM_ID = DB.getSQLValueEx(get_TrxName(),"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , getS_Resource_ID());
MUOM uom = MUOM.get(getCtx(), C_UOM_ID);
if (uom.isHour())
{
@ -597,4 +359,4 @@ public class MPPOrderNode extends X_PP_Order_Node
}
return cost;
}
} // M_WFNext
}

View File

@ -12,78 +12,50 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.compiere.model.Query;
/**
* Forcast Line Model
* Order Node Asset Model
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPPWFNodeAsset.java,v 1.11 2005/05/17 05:29:52 vpj-cd vpj-cd $
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPOrderNodeAsset extends X_PP_Order_Node_Asset
{
/**
* Standard Constructor
* @param ctx context
* @param M_ForecastLine_ID id
*/
private static final long serialVersionUID = 1L;
public MPPOrderNodeAsset (Properties ctx, int PP_Order_Node_Asset_ID, String trxName)
{
super (ctx, PP_Order_Node_Asset_ID, trxName);
if (PP_Order_Node_Asset_ID == 0)
{
}
}
public MPPOrderNodeAsset (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}
/**
* Create a new MPPOrderNodeAsset based in MPPWFNodeProduct
* @param np
* @param na
* @param PP_Order_Node
*/
public MPPOrderNodeAsset (MPPWFNodeAsset na)
public MPPOrderNodeAsset (MPPWFNodeAsset na, MPPOrderNode PP_Order_Node)
{
this(na.getCtx(), 0, na.get_TrxName());
this(PP_Order_Node.getCtx(), 0, PP_Order_Node.get_TrxName());
setClientOrg(PP_Order_Node);
//setSeqNo(na.getSeqNo());
setIsActive(na.isActive());
setA_Asset_ID(na.getA_Asset_ID());
//
setPP_Order_ID(PP_Order_Node.getPP_Order_ID());
setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID());
setPP_Order_Node_ID(PP_Order_Node.get_ID());
}
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MPPOrderNodeAsset (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MPPWFNodeAsset
/** Lines */
private static Collection<MPPOrderNodeAsset> m_lines = new ArrayList<MPPOrderNodeAsset>();
/**
* Get Lines
* @return array of lines
*/
public Collection<MPPOrderNodeAsset> getNodeAsset()
{
if(!m_lines.isEmpty())
return m_lines;
String whereClause = "PP_Order_Node_Asset_ID=? ";
m_lines = new Query(getCtx(), MPPOrderNodeAsset.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
.setOnlyActiveRecords(true)
//.setOrderBy(MPPOrderNodeAsset.COLUMNNAME_SeqNo)
.list();
return m_lines;
} // getLines
} // MPPWFNodeAsset
}

View File

@ -1,6 +1,5 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* Product: Adempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
@ -11,8 +10,9 @@
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
@ -23,11 +23,9 @@ import org.compiere.util.DB;
import org.compiere.wf.MWFNodeNext;
/**
* PP Order Workflow Node Next - Transition
*
* @author Jorg Janke
* @version $Id: MPPOrdeNodeNext.java,v 1.3 2006/10/06 00:42:24 jjanke Exp $
* PP Order Workflow Node Next - Transition
*
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, http://www.arhipac.ro
*/
public class MPPOrderNodeNext extends X_PP_Order_NodeNext
@ -73,22 +71,20 @@ public class MPPOrderNodeNext extends X_PP_Order_NodeNext
{
this(parent.getCtx(), 0, parent.get_TrxName());
setClientOrg(parent);
setPP_Order_Node_ID(parent.getPP_Order_Node_ID());
setPP_Order_ID(parent.getPP_Order_ID());
setPP_Order_Node_ID(parent.get_ID());
setPP_Order_Next_ID(PP_Order_Next_ID);
} // MPPOrderNodeNext
/**
* Peer constructor
* @param wfNodeNext
* @param PP_Order_Node
* @param parent
* @param trxName
*/
public MPPOrderNodeNext (MWFNodeNext wfNodeNext, MPPOrderNode PP_Order_Node, String trxName)
public MPPOrderNodeNext (MWFNodeNext wfNodeNext, MPPOrderNode parent)
{
this(wfNodeNext.getCtx(), 0, trxName);
setPP_Order_Node_ID(PP_Order_Node.get_ID());
setPP_Order_ID(PP_Order_Node.getPP_Order_ID());
setPP_Order_Next_ID(0);
this(parent, 0);
//
setAD_WF_Node_ID(wfNodeNext.getAD_WF_Node_ID());
setAD_WF_Next_ID(wfNodeNext.getAD_WF_Next_ID());
@ -104,21 +100,8 @@ public class MPPOrderNodeNext extends X_PP_Order_NodeNext
/** To (Join Element) is AND */
public Boolean m_toJoinAnd = null;
/**
* Set Client Org
* @param AD_Client_ID client
* @param AD_Org_ID org
*/
public void setClientOrg (int AD_Client_ID, int AD_Org_ID)
{
super.setClientOrg (AD_Client_ID, AD_Org_ID);
} // setClientOrg
/**
* String Representation
* @return info
*/
public String toString ()
@Override
public String toString()
{
StringBuffer sb = new StringBuffer ("MPPOrderNodeNext[");
sb.append(getSeqNo())
@ -181,8 +164,7 @@ public class MPPOrderNodeNext extends X_PP_Order_NodeNext
{
final String sql = "SELECT PP_Order_Node_ID FROM PP_Order_Node "
+ " WHERE PP_Order_ID=? AND AD_WF_Node_ID=? AND AD_Client_ID=?";
int id = DB.getSQLValue(get_TrxName(), sql, getPP_Order_ID(), getAD_WF_Next_ID(), getAD_Client_ID());
if (id > 0)
setPP_Order_Next_ID(id);
int id = DB.getSQLValueEx(get_TrxName(), sql, getPP_Order_ID(), getAD_WF_Next_ID(), getAD_Client_ID());
setPP_Order_Next_ID(id > 0 ? id : 0);
}
} // MPPOrderNodeNext

View File

@ -12,86 +12,54 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.compiere.model.Query;
/**
* Forcast Line Model
* Order Node Product Model
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPPWFNodeProduct.java,v 1.11 2005/05/17 05:29:52 vpj-cd vpj-cd $
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPOrderNodeProduct extends X_PP_Order_Node_Product
{
/**
* Standard Constructor
* @param ctx context
* @param M_ForecastLine_ID id
*/
private static final long serialVersionUID = 1L;
public MPPOrderNodeProduct (Properties ctx, int PP_WF_Order_Product_ID, String trxName)
{
super (ctx, PP_WF_Order_Product_ID, trxName);
if (PP_WF_Order_Product_ID == 0)
{
}
}
} // MQMSpecification
public MPPOrderNodeProduct (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}
/**
* Create a new MPPOrderNodeProduct based in MPPWFNodeProduct
* @param np
* @param PP_Order_Node order node
*/
public MPPOrderNodeProduct (MPPWFNodeProduct np)
public MPPOrderNodeProduct (MPPWFNodeProduct np, MPPOrderNode PP_Order_Node)
{
this(np.getCtx(), 0, np.get_TrxName());
this(PP_Order_Node.getCtx(), 0, PP_Order_Node.get_TrxName());
setClientOrg(PP_Order_Node);
setSeqNo(np.getSeqNo());
setIsActive(np.isActive());
setM_Product_ID(np.getM_Product_ID());
setQty(np.getQty());
setIsSubcontracting(np.isSubcontracting());
setYield(np.getYield());
//
setPP_Order_ID(PP_Order_Node.getPP_Order_ID());
setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID());
setPP_Order_Node_ID(PP_Order_Node.get_ID());
}
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MPPOrderNodeProduct (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MQMSpecification
/** Lines */
private static Collection<MPPOrderNodeProduct> m_lines = new ArrayList<MPPOrderNodeProduct>();
/**
*
* @param ctx
* @param AD_WF_Node_ID
* @param trxName
* @return
*/
public Collection<MPPOrderNodeProduct> getNodeProduct()
{
if(!m_lines.isEmpty())
return m_lines;
String whereClause = "PP_Order_Node_Product_ID=? ";
m_lines = new Query(getCtx(), MPPOrderNodeProduct.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
.setOnlyActiveRecords(true)
.setOrderBy(MPPOrderNodeProduct.COLUMNNAME_SeqNo)
.list();
return m_lines;
} // getMPPOrderNodeProduct
} // MPPWFNodeProduct
}

View File

@ -16,7 +16,6 @@
*****************************************************************************/
package org.eevolution.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
@ -28,7 +27,6 @@ import org.compiere.model.MClient;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWorkflow;
/**
@ -183,18 +181,19 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
public MPPOrderNode[] getNodes(boolean ordered, int AD_Client_ID)
{
if (ordered)
{
return getNodesInOrder(AD_Client_ID);
}
//
ArrayList<MPPOrderNode> list = new ArrayList<MPPOrderNode>();
for (int i = 0; i < m_nodes.size(); i++)
for (MPPOrderNode node : m_nodes)
{
MPPOrderNode node = m_nodes.get(i);
if (node.getAD_Client_ID() == 0 || node.getAD_Client_ID() == AD_Client_ID)
{
list.add(node);
}
}
MPPOrderNode[] retValue = new MPPOrderNode [list.size()];
list.toArray(retValue);
return retValue;
return list.toArray(new MPPOrderNode [list.size()]);
} // getNodes
/**
@ -207,17 +206,18 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
} // getFirstNode
/**
* Get Node with ID in Workflow
* Get Node with given ID
* @param PP_Order_Node_ID ID
* @return node or null
*/
public MPPOrderNode getNode (int PP_Order_Node_ID)
{
for (int i = 0; i < m_nodes.size(); i++)
for (MPPOrderNode node : m_nodes)
{
MPPOrderNode node = (MPPOrderNode)m_nodes.get(i);
if (node.getPP_Order_Node_ID() == PP_Order_Node_ID)
{
return node;
}
}
return null;
} // getNode
@ -232,21 +232,22 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
{
MPPOrderNode node = getNode(PP_Order_Node_ID);
if (node == null || node.getNextNodeCount() == 0)
return null;
//
MPPOrderNodeNext[] nexts = node.getTransitions(AD_Client_ID);
ArrayList<MPPOrderNode> list = new ArrayList<MPPOrderNode>();
for (int i = 0; i < nexts.length; i++)
{
MPPOrderNode next = getNode (nexts[i].getPP_Order_Next_ID());
return null;
}
//
ArrayList<MPPOrderNode> list = new ArrayList<MPPOrderNode>();
for (MPPOrderNodeNext nextTr : node.getTransitions(AD_Client_ID))
{
MPPOrderNode next = getNode (nextTr.getPP_Order_Next_ID());
if (next != null)
{
list.add(next);
}
}
// Return Nodes
MPPOrderNode[] retValue = new MPPOrderNode [list.size()];
list.toArray(retValue);
return retValue;
return list.toArray(new MPPOrderNode [list.size()]);
} // getNextNodes
/**

View File

@ -21,35 +21,30 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MProduct;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* PP Product BOM Model.
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $
* PP Product BOM Model.
*
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, http://www.arhipac.ro
*/
public class MPPProductBOM extends X_PP_Product_BOM
{
private static final long serialVersionUID = 1L;
/** Static Logger */
private static CLogger log = CLogger.getCLogger(MPPProductBOM.class);
/** Cache */
private static CCache<Integer,MPPProductBOM> s_cache = new CCache<Integer,MPPProductBOM>(Table_Name, 40, 5);
/** BOM Lines */
private List<MPPProductBOMLine> m_lines = null;
/**
* Load/Get Product BOM by ID (cached)
* Get Product BOM by ID (cached)
* @param ctx
* @param PP_Product_BOM_ID
* @return product bom
@ -62,110 +57,42 @@ public class MPPProductBOM extends X_PP_Product_BOM
if (bom != null)
return bom;
bom = new MPPProductBOM(ctx, PP_Product_BOM_ID, null);
if (bom.get_ID() == PP_Product_BOM_ID) {
if (bom.get_ID() == PP_Product_BOM_ID)
{
s_cache.put(PP_Product_BOM_ID, bom);
}
else {
else
{
bom = null;
}
return bom;
}
/**
* Default Constructor
* @param ctx context
* @param C_Order_ID order to load, (0 create new order)
* Get PP_Product_BOM_ID for given M_Product_ID
* @param M_Product_ID
* @return PP_Product_BOM_ID
*/
public MPPProductBOM(Properties ctx, int PP_Product_BOM_ID,String trxName)
public static int getBOMSearchKey(Properties ctx, MProduct product)
{
super (ctx, PP_Product_BOM_ID, trxName);
} // MPPProductBOM
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MPPProductBOM(Properties ctx, ResultSet rs,String trxName)
{
super (ctx, rs,trxName);
} // MOrder
/**
* Copy Lines From other BOM
* @param order order
* @return number of lines copied
*/
public int copyLinesFrom (MPPProductBOM bom)
{
if (bom == null)
return 0;
MPPProductBOMLine[] fromLines = bom.getLines();
int count = 0;
for (int i = 0; i < fromLines.length; i++)
{
MPPProductBOMLine line = new MPPProductBOMLine (this);
PO.copyValues(fromLines[i], line, getAD_Client_ID(), getAD_Org_ID());
line.setPP_Product_BOM_ID(getPP_Product_BOM_ID());
if (line.save(get_TrxName()))
count++;
}
if (fromLines.length != count)
log.log(Level.SEVERE,"copyLinesFrom - Line difference - From=" + fromLines.length + " <> Saved=" + count);
return count;
} // copyLinesFrom
/*************************************************************************/
/**
* BUG #104
* @param lines
*/
private void setLines(List<MPPProductBOMLine> lines)
{
this.lines = lines;
}
private List<MPPProductBOMLine> lines = null;
/**
* BUG #? - Does not persist objects!
* @param ctx
* @param from
* @param copyLines
* @return
*/
public static MPPProductBOM copyFrom(Properties ctx, MPPProductBOM from, boolean copyLines) {
MPPProductBOM newBom = new MPPProductBOM(ctx, 0,null);
PO.copyValues(from, newBom, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
newBom.setDocumentNo(null);
if (copyLines) {
List<MPPProductBOMLine> newLines = new ArrayList<MPPProductBOMLine>();
MPPProductBOMLine[] fromLines = from.getLines();
for (int i = 0; i < fromLines.length; i++) {
MPPProductBOMLine line = new MPPProductBOMLine(ctx, 0,null);
PO.copyValues(fromLines[i], line, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
newLines.add(line);
}
newBom.setLines(newLines);
}
return newBom;
int AD_Client_ID = Env.getAD_Client_ID(ctx);
String sql = "SELECT PP_Product_BOM_ID FROM PP_Product_BOM"
+" WHERE Value=? AND M_Product_ID=? AND AD_Client_ID=?";
return DB.getSQLValueEx(null, sql, product.getValue(), product.get_ID(), AD_Client_ID);
}
/**
* String Representation
* @return info
* Get BOM with Default Logic (Product = BOM Product and BOM Value = Product Value)
* @param product
* @param trxName
* @return product BOM
*/
public String toString ()
public static MPPProductBOM getDefault(MProduct product, String trxName)
{
StringBuffer sb = new StringBuffer ("MPP_ProductBOM[")
.append(get_ID()).append("-").append(getDocumentNo())
.append ("]");
return sb.toString ();
} // toString
return new Query(product.getCtx(), Table_Name, "M_Product_ID=? AND Value=?", trxName)
.setParameters(new Object[]{product.getM_Product_ID(), product.getValue()})
.first();
}
/**
* Get BOM for Product
@ -176,13 +103,13 @@ public class MPPProductBOM extends X_PP_Product_BOM
*/
public static MPPProductBOM get(MProduct product, int ad_org_id, String trxName)
{
MPPProductBOM bom = null;
MPPProductBOM bom = null;
Properties ctx = product.getCtx();
// find Default BOM in Product Data Planning
if (ad_org_id > 0 )
{
MPPProductPlanning pp = MPPProductPlanning.get(ctx, product.getAD_Client_ID(),ad_org_id, product.getM_Product_ID(), trxName);
if(pp != null && pp.getPP_Product_BOM_ID() > 0 )
if(pp != null && pp.getPP_Product_BOM_ID() > 0)
{
bom = new MPPProductBOM(ctx, pp.getPP_Product_BOM_ID(),trxName);
}
@ -194,8 +121,7 @@ public class MPPProductBOM extends X_PP_Product_BOM
}
return bom;
} // getBOM
}
/**
* Get BOM with valid dates for Product
@ -213,8 +139,19 @@ public class MPPProductBOM extends X_PP_Product_BOM
return bom;
}
return null;
}
} // getBOM
public MPPProductBOM(Properties ctx, int PP_Product_BOM_ID,String trxName)
{
super (ctx, PP_Product_BOM_ID, trxName);
}
public MPPProductBOM(Properties ctx, ResultSet rs,String trxName)
{
super (ctx, rs,trxName);
}
/**
* Get BOM Lines valid date for Product BOM
@ -223,10 +160,11 @@ public class MPPProductBOM extends X_PP_Product_BOM
*/
public MPPProductBOMLine[] getLines (Timestamp valid)
{
MPPProductBOMLine[] bomlines = getLines(); // All BOM Lines
List<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine>(); // Selected BOM Lines Only
for (MPPProductBOMLine bl : bomlines) {
if (bl.isValidFromTo(valid)) {
for (MPPProductBOMLine bl : getLines())
{
if (bl.isValidFromTo(valid))
{
list.add(bl);
}
}
@ -240,42 +178,17 @@ public class MPPProductBOM extends X_PP_Product_BOM
*/
public MPPProductBOMLine[] getLines()
{
if (this.lines == null)
if (this.m_lines == null)
{
final String whereClause = MPPProductBOMLine.COLUMNNAME_PP_Product_BOM_ID+"=?";
this.lines = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause, get_TrxName())
this.m_lines = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Product_BOM_ID()})
.setOrderBy(MPPProductBOMLine.COLUMNNAME_Line)
.list();
}
return this.lines.toArray(new MPPProductBOMLine[this.lines.size()]);
return this.m_lines.toArray(new MPPProductBOMLine[this.m_lines.size()]);
} // getLines
/**
* Get PP_Product_BOM_ID for given M_Product_ID
* @param M_Product_ID
* @return PP_Product_BOM_ID
*/
public static int getBOMSearchKey(Properties ctx, MProduct product)
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
String sql = "SELECT pb.PP_Product_BOM_ID FROM PP_Product_BOM pb"
+" WHERE pb.Value = ? AND pb.M_Product_ID=? AND pb.AD_Client_ID = ?";
return DB.getSQLValue(null, sql, product.getValue(), product.get_ID(), AD_Client_ID);
}
/**
* Get BOM with Default Logic (Product = BOM Product and BOM Value = Product Value)
* @param product
* @param trxName
* @return product BOM
*/
public static MPPProductBOM getDefault(MProduct product, String trxName) {
return new Query(product.getCtx(), Table_Name, "M_Product_ID=? AND Value=?", trxName)
.setParameters(new Object[]{product.getM_Product_ID(), product.getValue()})
.first();
}
public boolean isValidFromTo(Timestamp date)
{
Timestamp validFrom = getValidFrom();
@ -289,7 +202,8 @@ public class MPPProductBOM extends X_PP_Product_BOM
}
@Override
protected boolean afterDelete(boolean success) {
protected boolean afterDelete(boolean success)
{
if (!success)
return false;
@ -298,7 +212,8 @@ public class MPPProductBOM extends X_PP_Product_BOM
}
@Override
protected boolean afterSave(boolean newRecord, boolean success) {
protected boolean afterSave(boolean newRecord, boolean success)
{
if (!success)
return false;
@ -311,13 +226,21 @@ public class MPPProductBOM extends X_PP_Product_BOM
private void updateProduct()
{
int count = new Query(getCtx(), Table_Name, "M_Product_ID=? AND IsActive=?", get_TrxName())
.setParameters(new Object[]{getM_Product_ID(), "Y"})
int count = new Query(getCtx(), Table_Name, COLUMNNAME_M_Product_ID+"=?", get_TrxName())
.setParameters(new Object[]{getM_Product_ID()})
.setOnlyActiveRecords(true)
.count();
MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
product.setIsBOM(count > 0);
product.saveEx();
}
@Override
public String toString ()
{
StringBuffer sb = new StringBuffer ("MPP_ProductBOM[")
.append(get_ID()).append("-").append(getDocumentNo())
.append ("]");
return sb.toString ();
}
} // MPPProductBOM

View File

@ -12,6 +12,7 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
@ -38,10 +39,9 @@ import org.compiere.util.Env;
* l.setQty(wbl.getQuantity());;
* l.saveEx();
* </code>
* @author Victor Perez www.e-evolution.com
* @version $Id: MOrderLine.java,v 1.22 2004/03/22 07:15:03 vpj-cd Exp $
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPProductBOMLine extends X_PP_Product_BOMLine
{
@ -108,7 +108,7 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
{
final String sql = "SELECT COALESCE(MAX("+COLUMNNAME_Line+"),0) + 10 FROM "+Table_Name
+" WHERE "+COLUMNNAME_PP_Product_BOM_ID+"=?";
int line = DB.getSQLValue(get_TrxName(), sql, getPP_Product_BOM_ID());
int line = DB.getSQLValueEx(get_TrxName(), sql, getPP_Product_BOM_ID());
setLine(line);
}
@ -141,7 +141,8 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
}
}
class ProductLowLevelCalculator {
class ProductLowLevelCalculator
{
private Hashtable<Integer, Integer> tableproduct = new Hashtable<Integer, Integer>();
private Properties m_ctx = null;
private String m_trxName = null;
@ -180,17 +181,15 @@ class ProductLowLevelCalculator {
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
String sql = new String(
"SELECT pboml.PP_Product_BOMLine_ID FROM PP_Product_BOMLine pboml"
+ " WHERE pboml.IsActive= 'Y' AND pboml.AD_Client_ID = ? AND pboml.M_Product_ID = ? ");
String sql = "SELECT PP_Product_BOMLine_ID FROM PP_Product_BOMLine"
+ " WHERE IsActive=? AND AD_Client_ID=? AND M_Product_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, m_trxName);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, M_Product_ID);
DB.setParameters(pstmt, new Object[]{true, AD_Client_ID, M_Product_ID});
rs = pstmt.executeQuery();
while (rs.next())
{
@ -212,10 +211,10 @@ class ProductLowLevelCalculator {
{
throw new DBException(e);
}
finally {
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
rs = null; pstmt = null;
}
return parent;
}
@ -228,17 +227,16 @@ class ProductLowLevelCalculator {
*/
private DefaultMutableTreeNode icomponent(int AD_Client_ID, int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom)
{
String sql =
final String sql =
"SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml"
+ " INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
+ " WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pboml.AD_Client_ID =? AND pboml.PP_Product_BOMLine_ID = ? ";
+ " WHERE pbom.IsActive=? AND pboml.IsActive=? AND pboml.AD_Client_ID=? AND pboml.PP_Product_BOMLine_ID=? ";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, m_trxName);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, PP_Product_BOMLine_ID);
DB.setParameters(pstmt, new Object[]{true, true, AD_Client_ID, PP_Product_BOMLine_ID});
rs = pstmt.executeQuery();
while (rs.next())
{
@ -246,7 +244,9 @@ class ProductLowLevelCalculator {
{
//BOM Loop Error
if (!tableproduct(rs.getInt(1), rs.getInt(3)))
{
bom.add(iparent(AD_Client_ID, rs.getInt(1), rs.getInt(3)));
}
else
{
throw new AdempiereException("Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")");
@ -265,10 +265,10 @@ class ProductLowLevelCalculator {
{
throw new DBException(e);
}
finally {
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
rs = null; pstmt = null;
}
return null;
}
@ -281,14 +281,11 @@ class ProductLowLevelCalculator {
*/
private boolean tableproduct(int M_Product_ID, int PP_Product_BOM_ID)
{
Integer p = new Integer(M_Product_ID);
Integer bom = new Integer(PP_Product_BOM_ID);
if (tableproduct.containsKey(p))
if (tableproduct.containsKey(M_Product_ID))
{
return true;
}
tableproduct.put(p, bom);
tableproduct.put(M_Product_ID, PP_Product_BOM_ID);
return false;
}
}

View File

@ -16,6 +16,7 @@
*****************************************************************************/
package org.eevolution.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
@ -27,13 +28,12 @@ import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWorkflow;
/**
* Product Data Planning
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPProductPlannning.java,v 1.4 2004/05/13 06:05:22 vpj-cd Exp $
* Product Data Planning
*
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPProductPlanning extends X_PP_Product_Planning
@ -72,7 +72,7 @@ public class MPPProductPlanning extends X_PP_Product_Planning
}
/**
* Get Data Product Planning to Organization
* Get Data Product Planning to Organization
* @param ctx Context
* @param ad_org_id Organization ID
* @param m_product_id Product ID
@ -83,19 +83,17 @@ public class MPPProductPlanning extends X_PP_Product_Planning
int m_product_id,
String trxname)
{
int m_M_Warehouse_ID = MOrgInfo.get(ctx, ad_org_id).getM_Warehouse_ID();
if(m_M_Warehouse_ID <= 0)
int M_Warehouse_ID = MOrgInfo.get(ctx, ad_org_id).getM_Warehouse_ID();
if(M_Warehouse_ID <= 0)
{
return null;
}
int S_Resource_ID = getPlantForWarehouse(M_Warehouse_ID);
if (S_Resource_ID <= 0)
return null;
// Get plant resource for warehouse. If more than one resource is found, first will be used
final String sql = "SELECT MIN(S_Resource_ID) FROM S_Resource"
+" WHERE IsManufacturingResource=? AND ManufacturingResourceType=?"
+" AND AD_Client_ID=? AND M_Warehouse_ID= ?";
int m_S_Resource_ID = DB.getSQLValue(trxname, sql, "Y", MResource.MANUFACTURINGRESOURCETYPE_Plant, ad_client_id, m_M_Warehouse_ID);
if (m_S_Resource_ID <= 0)
return null;
return get(ctx, ad_client_id,ad_org_id, m_M_Warehouse_ID, m_S_Resource_ID, m_product_id, trxname);
return get(ctx, ad_client_id,ad_org_id, M_Warehouse_ID, S_Resource_ID, m_product_id, trxname);
}
/**
@ -115,7 +113,8 @@ public class MPPProductPlanning extends X_PP_Product_Planning
{
log.info("AD_Client_ID=" + ad_client_id + " AD_Org_ID=" + ad_org_id + " M_Product_ID=" + m_product_id + " M_Warehouse_ID=" + m_warehouse_id + " S_Resource_ID=" + s_resource_id );
String sql_warehouse = COLUMNNAME_M_Warehouse_ID+"=?";
if(m_warehouse_id == 0) {
if(m_warehouse_id == 0)
{
sql_warehouse += " OR "+COLUMNNAME_M_Warehouse_ID+" IS NULL";
}
@ -127,7 +126,7 @@ public class MPPProductPlanning extends X_PP_Product_Planning
return new Query(ctx, MPPProductPlanning.Table_Name, whereClause, trxname)
.setParameters(new Object[]{ad_client_id, ad_org_id, m_product_id, m_warehouse_id, s_resource_id})
.first();
.firstOnly();
}
@ -158,6 +157,26 @@ public class MPPProductPlanning extends X_PP_Product_Planning
.first();
}
public static int getPlantForWarehouse(int M_Warehouse_ID)
{
// Get plant resource for warehouse. If more than one resource is found, first will be used
final String sql = "SELECT MIN("+MResource.COLUMNNAME_S_Resource_ID+")"
+" FROM "+MResource.Table_Name
+" WHERE "+MResource.COLUMNNAME_IsManufacturingResource+"=?"
+" AND "+MResource.COLUMNNAME_ManufacturingResourceType+"=?"
+" AND "+MResource.COLUMNNAME_M_Warehouse_ID+"=?";
int plant_id = DB.getSQLValueEx(null, sql, true, MResource.MANUFACTURINGRESOURCETYPE_Plant, M_Warehouse_ID);
return plant_id;
}
/**
* @return Qty On Hand
*/
public BigDecimal getQtyOnHand()
{
return MPPMRP.getQtyOnHand(getCtx(), getM_Warehouse_ID(), getM_Product_ID(), get_TrxName());
}
@Override
protected boolean beforeSave(boolean newRecord)
{
@ -171,6 +190,18 @@ public class MPPProductPlanning extends X_PP_Product_Planning
return true;
}
@Override
public MPPProductBOM getPP_Product_BOM()
{
return MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
}
@Override
public MWorkflow getAD_Workflow()
{
return MWorkflow.get(getCtx(), getAD_Workflow_ID());
}
public void dump()
{
if (!CLogMgt.isLevelInfo())
@ -184,9 +215,8 @@ public class MPPProductPlanning extends X_PP_Product_Planning
log.info(" Network Distribution: " + getDD_NetworkDistribution_ID());
log.info("Delivery Time Promised: " + getDeliveryTime_Promised());
log.info(" TransfertTime: " + getTransfertTime ());
log.info(" Max Order: " + getOrder_Max());
log.info(" Min Order: " + getOrder_Min());
log.info(" Pack Order: " + getOrder_Pack());
log.info(" Order Min/Max: " + getOrder_Min() + " / " + getOrder_Max());
log.info(" Order Pack: " + getOrder_Pack());
log.info(" Safety Stock: " + getSafetyStock());
log.info(" Order Period: " + getOrder_Period());
log.info(" Order Policy: " + getOrder_Policy());

View File

@ -12,71 +12,62 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.compiere.model.Query;
import org.compiere.util.CCache;
/**
* Forcast Line Model
* Workflow Node Asset Model
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPPWFNodeAsset.java,v 1.11 2005/05/17 05:29:52 vpj-cd vpj-cd $
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPWFNodeAsset extends X_PP_WF_Node_Asset
public class MPPWFNodeAsset extends X_PP_WF_Node_Asset
{
private static final long serialVersionUID = 1L;
/** Cache */
private static CCache<Integer, Collection<MPPWFNodeAsset>>
s_cache = new CCache<Integer, Collection<MPPWFNodeAsset>>(Table_Name, 20);
/**
* Standard Constructor
* @param ctx context
* @param M_ForecastLine_ID id
* @return array of node assets
*/
public static Collection<MPPWFNodeAsset> forAD_WF_Node_ID(Properties ctx, int AD_WF_Node_ID)
{
Collection<MPPWFNodeAsset> lines = s_cache.get(AD_WF_Node_ID);
if (lines != null)
{
return lines;
}
final String whereClause = COLUMNNAME_AD_WF_Node_ID+"=?";
lines = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{AD_WF_Node_ID})
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_SeqNo)
.list();
s_cache.put(AD_WF_Node_ID, lines);
return lines;
}
public MPPWFNodeAsset (Properties ctx, int PP_WF_Node_Asset_ID, String trxName)
{
super (ctx, PP_WF_Node_Asset_ID, trxName);
if (PP_WF_Node_Asset_ID == 0)
{
}
}
} // MQMSpecification
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MPPWFNodeAsset (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MPPWFNodeAsset
/** Lines */
private static Collection <MPPWFNodeAsset> m_lines = new ArrayList<MPPWFNodeAsset>();
/**
*
* @param ctx
* @param AD_WF_Node_ID
* @param trxName
* @return
*/
public static Collection<MPPWFNodeAsset> get(Properties ctx, int AD_WF_Node_ID , String trxName)
{
if(!m_lines.isEmpty())
return m_lines;
String whereClause = "AD_WF_Node_ID=? ";
m_lines = new Query(ctx, MPPWFNodeAsset.Table_Name, whereClause, trxName)
.setParameters(new Object[]{AD_WF_Node_ID})
.setOnlyActiveRecords(true)
//.setOrderBy(MPPOrderNodeAsset.COLUMNNAME_SeqNo)
.list();
return m_lines;
} // getLines
} // MPPWFNodeAsset
}
}

View File

@ -12,67 +12,80 @@
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
* Teo Sarca, www.arhipac.ro *
*****************************************************************************/
package org.eevolution.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.DB;
/**
* Forcast Line Model
* Workflow Node Product Model
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPPWFNodeProduct.java,v 1.11 2005/05/17 05:29:52 vpj-cd vpj-cd $
* @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPWFNodeProduct extends X_PP_WF_Node_Product
public class MPPWFNodeProduct extends X_PP_WF_Node_Product
{
private static final long serialVersionUID = 1L;
/** Cache */
private static CCache<Integer, Collection<MPPWFNodeProduct>>
s_cache = new CCache<Integer, Collection<MPPWFNodeProduct>>(Table_Name, 20);
/**
* Standard Constructor
* @param ctx context
* @param M_ForecastLine_ID id
* @return array of node products
*/
public static Collection<MPPWFNodeProduct> forAD_WF_Node_ID(Properties ctx, int AD_WF_Node_ID)
{
Collection<MPPWFNodeProduct> lines = s_cache.get(AD_WF_Node_ID);
if (lines != null)
{
return lines;
}
final String whereClause = COLUMNNAME_AD_WF_Node_ID+"=?";
lines = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{AD_WF_Node_ID})
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_SeqNo)
.list();
s_cache.put(AD_WF_Node_ID, lines);
return lines;
}
public MPPWFNodeProduct (Properties ctx, int PP_WF_Node_Product_ID, String trxName)
{
super (ctx, PP_WF_Node_Product_ID, trxName);
if (PP_WF_Node_Product_ID == 0)
{
}
}
} // MQMSpecification
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MPPWFNodeProduct (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MQMSpecification
}
/** Lines */
private static Collection <MPPWFNodeProduct> m_lines = new ArrayList<MPPWFNodeProduct>();
/**
* Get Lines
* @return array of lines
*/
public static Collection<MPPWFNodeProduct> get(Properties ctx, int AD_WF_Node_ID , String trxName)
@Override
protected boolean beforeSave(boolean newRecord)
{
if(!m_lines.isEmpty())
return m_lines;
if (getSeqNo() == 0)
{
final String sql = "SELECT COALESCE(MAX("+COLUMNNAME_SeqNo+"),0)+10 FROM "+Table_Name+" WHERE "
+" "+COLUMNNAME_AD_WF_Node_ID+"=?"
+" AND "+COLUMNNAME_PP_WF_Node_Product_ID+"<>?";
int seqNo = DB.getSQLValueEx(get_TrxName(), sql, getAD_WF_Node_ID(), get_ID());
setSeqNo(seqNo);
}
//
return true;
}
String whereClause = "AD_WF_Node_ID=?";
m_lines = new Query(ctx, MPPWFNodeProduct.Table_Name, whereClause, trxName)
.setParameters(new Object[]{AD_WF_Node_ID})
.setOnlyActiveRecords(true)
.setOrderBy(MPPWFNodeProduct.COLUMNNAME_SeqNo)
.list();
return m_lines;
} // getMPPOrderNodeProduct
} // MPPWFNodeProduct

View File

@ -1,109 +0,0 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* This program is free software;
you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program;
if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.eevolution.model;
/** Generated Model - DO NOT CHANGE */
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.util.KeyNamePair;
/** Generated Model for RV_PP_Order_Storage
* @author Adempiere (generated)
* @version Release 3.1.5 - $Id$ */
public class X_RV_PP_Order_Storage extends PO
{
/** Standard Constructor
@param ctx context
@param RV_PP_Order_Storage_ID id
@param trxName transaction
*/
public X_RV_PP_Order_Storage (Properties ctx, int RV_PP_Order_Storage_ID, String trxName)
{
super (ctx, RV_PP_Order_Storage_ID, trxName);
/** if (RV_PP_Order_Storage_ID == 0)
{
setRV_PP_Order_Storage_ID (0);
}
*/
}
/** Load Constructor
@param ctx context
@param rs result set
@param trxName transaction
*/
public X_RV_PP_Order_Storage (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
}
/** AD_Table_ID=50057 */
public static final int Table_ID=MTable.getTable_ID("RV_PP_Order_Storage");
/** TableName=RV_PP_Order_Storage */
public static final String Table_Name="RV_PP_Order_Storage";
protected static KeyNamePair Model = new KeyNamePair(Table_ID,"RV_PP_Order_Storage");
protected BigDecimal accessLevel = BigDecimal.valueOf(3);
/** AccessLevel
@return 3 - Client - Org
*/
protected int get_AccessLevel()
{
return accessLevel.intValue();
}
/** Load Meta Data
@param ctx context
@return PO Info
*/
protected POInfo initPO (Properties ctx)
{
POInfo poi = POInfo.getPOInfo (ctx, Table_ID);
return poi;
}
/** Info
@return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("X_RV_PP_Order_Storage[").append(get_ID()).append("]");
return sb.toString();
}
/** Set RV_PP_Order_Storage.
@param RV_PP_Order_Storage_ID RV_PP_Order_Storage */
public void setRV_PP_Order_Storage_ID (int RV_PP_Order_Storage_ID)
{
if (RV_PP_Order_Storage_ID < 1) throw new IllegalArgumentException ("RV_PP_Order_Storage_ID is mandatory.");
set_ValueNoCheck ("RV_PP_Order_Storage_ID", Integer.valueOf(RV_PP_Order_Storage_ID));
}
/** Get RV_PP_Order_Storage.
@return RV_PP_Order_Storage */
public int getRV_PP_Order_Storage_ID()
{
Integer ii = (Integer)get_Value("RV_PP_Order_Storage_ID");
if (ii == null) return 0;
return ii.intValue();
}
/** Column name RV_PP_Order_Storage_ID */
public static final String COLUMNNAME_RV_PP_Order_Storage_ID = "RV_PP_Order_Storage_ID";
}

View File

@ -97,7 +97,10 @@ public class CRPReasoner
params.add(Env.getAD_Client_ID(getCtx()));
// Skip voided, reversed and closed orders:
whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_DocStatus).append(" NOT IN ('VO', 'RE', 'CL')");
whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_DocStatus).append(" NOT IN (?,?,?)");
params.add(MPPOrder.DOCSTATUS_Voided);
params.add(MPPOrder.DOCSTATUS_Reversed);
params.add(MPPOrder.DOCSTATUS_Closed);
// For given resource (if any)
@ -124,7 +127,9 @@ public class CRPReasoner
params.add(r.get_ID());
final String whereClause =
// Checks the requested resource id directly on order node, not on resource id of the order
"PP_Order_ID IN (SELECT PP_Order_ID FROM PP_Order_Node WHERE S_Resource_ID=?"
"EXISTS (SELECT 1 FROM PP_Order_Node WHERE "
+" PP_Order_Node.PP_Order_ID=PP_Order.PP_Order_ID"
+" AND S_Resource_ID=?"
// ... and only the orders running on given day
+" AND "+getSQLDayRestriction(dateTime, r, params)
+")"
@ -168,6 +173,13 @@ public class CRPReasoner
return r.getResourceType().isAvailable();
}
/**
* Get Next/Previous Available Date
* @param t
* @param dateTime
* @param isScheduleBackward
* @return
*/
private Timestamp getAvailableDate(MResourceType t, Timestamp dateTime, boolean isScheduleBackward)
{
Timestamp date = TimeUtil.trunc(dateTime, TimeUtil.TRUNC_DAY);

View File

@ -77,8 +77,8 @@ public class CRP extends SvrProcess {
}
}
protected String doIt() throws Exception {
protected String doIt() throws Exception
{
return runCRP();
}
@ -122,7 +122,8 @@ public class CRP extends SvrProcess {
log.fine("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
if(resource== null)
// Skip this node if there is no resource
if(resource == null)
{
nodeId = owf.getNext(nodeId, getAD_Client_ID());
continue;
@ -145,6 +146,7 @@ public class CRP extends SvrProcess {
date = node.getDateFinishSchedule();
nodeId = owf.getNext(nodeId, getAD_Client_ID());
}
// Update order finish date
if (node != null && node.getDateFinishSchedule()!= null)
{
order.setDateFinishSchedule(node.getDateFinishSchedule());
@ -163,7 +165,8 @@ public class CRP extends SvrProcess {
log.fine("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
if(resource== null)
// Skip this node if there is no resource
if(resource == null)
{
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
continue;
@ -186,14 +189,15 @@ public class CRP extends SvrProcess {
date = node.getDateStartSchedule();
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
}
if (node != null && node.getDateFinishSchedule()!= null)
// Update order start date
if (node != null && node.getDateStartSchedule() != null)
{
order.setDateStartSchedule(node.getDateStartSchedule()) ;
}
}
else
{
throw new AdempiereException("@Unknown scheduling method - "+p_ScheduleType);
throw new AdempiereException("Unknown scheduling method - "+p_ScheduleType);
}
order.saveEx(get_TrxName());
@ -210,7 +214,7 @@ public class CRP extends SvrProcess {
// ... its static single parts ...
long totalDuration =
//node.getQueuingTime()
node.getSetupTimeRequiered() // Use the present required setup time to notice later changes
+ node.getSetupTimeRequiered() // Use the present required setup time to notice later changes
+ node.getMovingTime()
+ node.getWaitingTime()
;
@ -222,7 +226,7 @@ public class CRP extends SvrProcess {
return (long)(totalDuration * commonBase * 1000);
}
private Timestamp scheduleForward(Timestamp start, long nodeDuration, MResource r, MResourceType t)
private Timestamp scheduleForward(Timestamp start, long nodeDurationMillis, MResource r, MResourceType t)
{
Timestamp end = null;
int iteration = 0; // statistical interation count
@ -242,39 +246,40 @@ public class CRP extends SvrProcess {
long availableDayDuration = dayEnd.getTime() - dayStart.getTime();
// The work can be finish on this day.
if(availableDayDuration >= nodeDuration)
if(availableDayDuration >= nodeDurationMillis)
{
end = new Timestamp(dayStart.getTime() + nodeDuration);
nodeDuration = 0;
end = new Timestamp(dayStart.getTime() + nodeDurationMillis);
nodeDurationMillis = 0;
break;
}
// Otherwise recall with next day and the remained node duration.
else
{
start = TimeUtil.addDays(TimeUtil.getDayBorder(start, null, false), 1);
nodeDuration -= availableDayDuration;
nodeDurationMillis -= availableDayDuration;
}
iteration++;
} while (nodeDuration > 0);
} while (nodeDurationMillis > 0);
return end;
}
private Timestamp scheduleBackward(Timestamp end, long nodeDuration, MResource r, MResourceType t)
private Timestamp scheduleBackward(Timestamp end, long nodeDurationMillis, MResource r, MResourceType t)
{
log.fine("--> ResourceType " + t);
Timestamp start = null;
int iteration = 0; // statistical interation count
int iteration = 0; // statistical iteration count
do
{
log.fine("--> end " +end);
log.fine("--> nodeDuration=" +nodeDuration);
log.fine("--> end=" + end);
log.fine("--> nodeDuration=" + nodeDurationMillis);
end = reasoner.getAvailableDate(r, end, true);
Timestamp dayEnd = t.getDayEnd(end);
Timestamp dayStart = t.getDayStart(end);
log.fine("--> dayEnd=" + dayEnd + ", dayStart=" + dayStart);
log.fine("--> dayStart=" + dayStart + ", dayEnd=" + dayEnd);
// If working has already began at this day and the value is in the range of the
// resource's availability, switch end time to the given again
if(end.before(dayEnd) && end.after(dayStart))
@ -287,26 +292,26 @@ public class CRP extends SvrProcess {
log.fine("--> availableDayDuration " + availableDayDuration);
// The work can be finish on this day.
if(availableDayDuration >= nodeDuration)
if(availableDayDuration >= nodeDurationMillis)
{
log.fine("--> availableDayDuration >= nodeDuration true " + availableDayDuration + "|" + nodeDuration );
start = new Timestamp(dayEnd.getTime() - nodeDuration);
nodeDuration = 0;
log.fine("--> availableDayDuration >= nodeDuration true " + availableDayDuration + "|" + nodeDurationMillis );
start = new Timestamp(dayEnd.getTime() - nodeDurationMillis);
nodeDurationMillis = 0;
break;
}
// Otherwise recall with previous day and the remained node duration.
else
{
log.fine("--> availableDayDuration >= nodeDuration false " + availableDayDuration + "|" + nodeDuration );
log.fine("--> nodeDuration-availableDayDuration " + (nodeDuration-availableDayDuration) );
log.fine("--> availableDayDuration >= nodeDuration false " + availableDayDuration + "|" + nodeDurationMillis );
log.fine("--> nodeDuration-availableDayDuration " + (nodeDurationMillis-availableDayDuration) );
end = TimeUtil.addDays(TimeUtil.getDayBorder(end, null, true), -1);
nodeDuration -= availableDayDuration;
nodeDurationMillis -= availableDayDuration;
}
//
iteration++;
}
while(nodeDuration > 0);
while(nodeDurationMillis > 0);
log.fine(" --> start=" + start + " <---------------------------------------- ");
return start;

View File

@ -371,9 +371,9 @@ public class MRP extends SvrProcess
}
// New Product
if (product == null || product.get_ID() != rs.getInt("M_Product_ID"))
if (product == null || product.get_ID() != rs.getInt(MPPMRP.COLUMNNAME_M_Product_ID))
{
product = MProduct.get(getCtx(), rs.getInt("M_Product_ID"));
product = MProduct.get(getCtx(), rs.getInt(MPPMRP.COLUMNNAME_M_Product_ID));
log.info("Calculte Plan to this Product:" + product.getName());
//if exist QtyGrossReq of last Demand verify plan

View File

@ -59,24 +59,22 @@ public class RollupBillOfMaterial extends SvrProcess
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
for (ProcessInfoParameter para : getParameter())
{
String name = para[i].getParameterName();
String name = para.getParameterName();
if (para[i].getParameter() == null)
if (para.getParameter() == null)
;
else if (name.equals("AD_Org_ID"))
p_AD_Org_ID = para[i].getParameterAsInt();
p_AD_Org_ID = para.getParameterAsInt();
else if (name.equals(MAcctSchema.COLUMNNAME_C_AcctSchema_ID))
p_C_AcctSchema_ID = para[i].getParameterAsInt();
p_C_AcctSchema_ID = para.getParameterAsInt();
else if (name.equals(MCostType.COLUMNNAME_M_CostType_ID))
p_M_CostType_ID = para[i].getParameterAsInt();
p_M_CostType_ID = para.getParameterAsInt();
else if (name.equals(MProduct.COLUMNNAME_M_Product_ID))
p_M_Product_ID = para[i].getParameterAsInt();
p_M_Product_ID = para.getParameterAsInt();
else if (name.equals(MProduct.COLUMNNAME_M_Product_Category_ID))
p_M_Product_Category_ID = para[i].getParameterAsInt();
p_M_Product_Category_ID = para.getParameterAsInt();
else
log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name);
}