diff --git a/base/src/org/adempiere/exceptions/DocTypeNotFoundException.java b/base/src/org/adempiere/exceptions/DocTypeNotFoundException.java
new file mode 100644
index 0000000000..c366ca1e50
--- /dev/null
+++ b/base/src/org/adempiere/exceptions/DocTypeNotFoundException.java
@@ -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();
+ }
+
+
+}
diff --git a/base/src/org/compiere/model/MForecastLine.java b/base/src/org/compiere/model/MForecastLine.java
new file mode 100644
index 0000000000..2b0e1178b2
--- /dev/null
+++ b/base/src/org/compiere/model/MForecastLine.java
@@ -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
diff --git a/base/src/org/compiere/wf/MWFNode.java b/base/src/org/compiere/wf/MWFNode.java
index 51c9d87b5f..9eb955422d 100644
--- a/base/src/org/compiere/wf/MWFNode.java
+++ b/base/src/org/compiere/wf/MWFNode.java
@@ -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())
{
diff --git a/base/src/org/eevolution/exceptions/ActivityProcessedException.java b/base/src/org/eevolution/exceptions/ActivityProcessedException.java
new file mode 100644
index 0000000000..640e7c6d1f
--- /dev/null
+++ b/base/src/org/eevolution/exceptions/ActivityProcessedException.java
@@ -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
+ }
+}
diff --git a/base/src/org/eevolution/model/CalloutOrder.java b/base/src/org/eevolution/model/CalloutOrder.java
index 50c5fff351..0745178529 100644
--- a/base/src/org/eevolution/model/CalloutOrder.java
+++ b/base/src/org/eevolution/model/CalloutOrder.java
@@ -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 "";
}
diff --git a/base/src/org/eevolution/model/LiberoValidator.java b/base/src/org/eevolution/model/LiberoValidator.java
index 97c37a067d..db8897eb91 100644
--- a/base/src/org/eevolution/model/LiberoValidator.java
+++ b/base/src/org/eevolution/model/LiberoValidator.java
@@ -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
*
[ 2270421 ] Can not complete Shipment (Customer)
- *
- * @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 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;
diff --git a/base/src/org/eevolution/model/MHREmployee.java b/base/src/org/eevolution/model/MHREmployee.java
index 0a37ed4648..0e6e2d2d0a 100644
--- a/base/src/org/eevolution/model/MHREmployee.java
+++ b/base/src/org/eevolution/model/MHREmployee.java
@@ -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());
diff --git a/base/src/org/eevolution/model/MPPCostCollector.java b/base/src/org/eevolution/model/MPPCostCollector.java
index c0305a33df..03e91f438b 100644
--- a/base/src/org/eevolution/model/MPPCostCollector.java
+++ b/base/src/org/eevolution/model/MPPCostCollector.java
@@ -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
@@ -110,6 +114,20 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
else
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 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 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 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)
+ 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 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
@@ -748,8 +784,9 @@ 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)
@@ -764,10 +801,9 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
m_orderNode.set_TrxName(get_TrxName());
return m_orderNode;
}
-
-
- public MPPOrderBOMLine getPPOrderBOMLine()
+ @Override
+ public MPPOrderBOMLine getPP_Order_BOMLine()
{
int id = getPP_Order_BOMLine_ID();
if (id <= 0)
@@ -782,9 +818,9 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
m_bomLine.set_TrxName(get_TrxName());
return m_bomLine;
}
-
- public MPPOrder getPPOrder()
+ @Override
+ public MPPOrder getPP_Order()
{
int id = getPP_Order_ID();
if (id <= 0)
@@ -800,105 +836,115 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
return m_pporder;
}
-
/**
* 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 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 orders = new CCache(MOrder.Table_Name, 5);
-
-
- for (MPPOrderNodeProduct subctract: subctracts )
+ HashMap orders = new HashMap();
+ //
+ String whereClause = MPPOrderNodeProduct.COLUMNNAME_PP_Order_Node_ID+"=?"
+ +" AND "+MPPOrderNodeProduct.COLUMNNAME_IsSubcontracting+"=?";
+ Collection 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))
- {
- 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);
+ //
+ // 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()))
+ {
+ 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);
@@ -1009,5 +1054,6 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
}
- }
+ }
+ /**/
} // MPPCostCollector
diff --git a/base/src/org/eevolution/model/MPPMRP.java b/base/src/org/eevolution/model/MPPMRP.java
index 4b08980f4c..c96f1d984e 100644
--- a/base/src/org/eevolution/model/MPPMRP.java
+++ b/base/src/org/eevolution/model/MPPMRP.java
@@ -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;
@@ -52,7 +55,131 @@ import org.compiere.wf.MWorkflow;
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 s_sourceColumnNames = new HashMap();
+ 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