diff --git a/base/src/org/eevolution/model/MPPCostCollector.java b/base/src/org/eevolution/model/MPPCostCollector.java index dcbd438f12..e4f33e1065 100644 --- a/base/src/org/eevolution/model/MPPCostCollector.java +++ b/base/src/org/eevolution/model/MPPCostCollector.java @@ -48,7 +48,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction super (ctx, PP_Cost_Collector_ID,trxName); if (PP_Cost_Collector_ID == 0) { - // setC_DocType_ID (0); + // setC_DocType_ID (0); setDocAction (DOCACTION_Complete); // CO setDocStatus (DOCSTATUS_Drafted); // DR //setIsApproved (false); @@ -69,7 +69,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction super (ctx, rs,trxName); } // MMovement - + /** * Add to Description * @param description text @@ -82,7 +82,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction else setDescription(desc + " | " + description); } // addDescription - + /** * Set Processed. * Propergate to Lines/Taxes @@ -100,8 +100,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction //m_lines = null; log.fine("setProcessed - " + processed + " - Lines=" + noLine); } // setProcessed - - + + /************************************************************************** * Process document * @param processAction document action @@ -113,7 +113,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction DocumentEngine engine = new DocumentEngine (this, getDocStatus()); return engine.processIt (processAction, getDocAction()); } // processIt - + /** Process Message */ private String m_processMsg = null; /** Just Prepared Flag */ @@ -129,7 +129,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction setProcessing(false); return true; } // unlockIt - + /** * Invalidate Document * @return true if success @@ -140,7 +140,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction setDocAction(DOCACTION_Prepare); return true; } // invalidateIt - + /** * Prepare Document * @return new status (In Progress or Invalid) @@ -157,92 +157,92 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction m_processMsg = "@PeriodClosed@"; return DocAction.STATUS_Invalid; } - - + + m_justPrepared = true; if (!DOCACTION_Complete.equals(getDocAction())) setDocAction(DOCACTION_Complete); return DocAction.STATUS_InProgress; } // prepareIt - + /** * Approve Document * @return true if success */ - + public boolean approveIt() { log.info("approveIt - " + toString()); //setIsApproved(true); return true; } // approveIt - + /** * Reject Approval * @return true if success */ - + public boolean rejectIt() { log.info("rejectIt - " + toString()); //setIsApproved(false); return true; } // rejectIt - + /** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ public String completeIt() { - // Re-Check - if (!m_justPrepared) - { - String status = prepareIt(); - if (!DocAction.STATUS_InProgress.equals(status)) - return status; - } - + // Re-Check + if (!m_justPrepared) + { + String status = prepareIt(); + if (!DocAction.STATUS_InProgress.equals(status)) + return status; + } - MProduct product = new MProduct (getCtx(),getM_Product_ID(),get_TrxName()); - // Qty & Type - String MovementType = getMovementType(); - - BigDecimal QtyIssue = Env.ZERO; - BigDecimal QtyReceipt = Env.ZERO; - - BigDecimal Qty = getMovementQty(); - if (MovementType.charAt(1) == '-') - { - Qty = Qty.negate(); - QtyIssue = Qty; - } - else - { - QtyReceipt = Qty.negate(); - } - - // Update Order Line - MPPOrderBOMLine obomline = null; - if (getPP_Order_BOMLine_ID()!= 0) - { - obomline = new MPPOrderBOMLine(getCtx(),getPP_Order_BOMLine_ID(),get_TrxName()); - } - - log.info(" Qty=" + getMovementQty()); - //Operation activity begin - MDocType doctype = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); - if(!doctype.equals(MDocType.DOCBASETYPE_ManufacturingOperationActivity)) - { + MProduct product = new MProduct (getCtx(),getM_Product_ID(),get_TrxName()); + + // Qty & Type + String MovementType = getMovementType(); + + BigDecimal QtyIssue = Env.ZERO; + BigDecimal QtyReceipt = Env.ZERO; + + BigDecimal Qty = getMovementQty(); + if (MovementType.charAt(1) == '-') + { + Qty = Qty.negate(); + QtyIssue = Qty; + } + else + { + QtyReceipt = Qty.negate(); + } + + // Update Order Line + MPPOrderBOMLine obomline = null; + if (getPP_Order_BOMLine_ID()!= 0) + { + obomline = new MPPOrderBOMLine(getCtx(),getPP_Order_BOMLine_ID(),get_TrxName()); + } + + log.info(" Qty=" + getMovementQty()); + //Operation activity begin + MDocType doctype = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); + if(!doctype.equals(MDocType.DOCBASETYPE_ManufacturingOperationActivity)) + { // Stock Movement if (product != null - && product.isStocked() ) + && product.isStocked() ) { //Ignore the Material Policy when is Reverse Correction checkMaterialPolicy( obomline, getMovementQty()); - + log.fine("Material Transaction"); MTransaction mtrx = null; int reservationAttributeSetInstance_ID = getM_AttributeSetInstance_ID(); @@ -250,12 +250,12 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction if (getM_AttributeSetInstance_ID() == 0) { MPPOrderBOMLineMA mas[] = MPPOrderBOMLineMA.get(getCtx(), - getPP_Cost_Collector_ID(), get_TrxName()); + getPP_Cost_Collector_ID(), get_TrxName()); for (int j = 0; j < mas.length; j++) { MPPOrderBOMLineMA ma = mas[j]; BigDecimal QtyMA = ma.getMovementQty(); - + if (MovementType.charAt(1) == '-') { QtyMA = QtyMA.negate(); @@ -263,93 +263,93 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction } else { - QtyReceipt = QtyMA.negate(); + QtyReceipt = QtyMA.negate(); } - - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), - getM_Locator_ID(), - getM_Product_ID(), - ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, - QtyMA, QtyIssue, QtyReceipt, get_TrxName())) - { - m_processMsg = "Cannot correct Inventory (MA)"; - return DocAction.STATUS_Invalid; - } - - // Create Transaction - mtrx = new MTransaction (getCtx(), this.getAD_Org_ID() , - MovementType,getM_Locator_ID(), - getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), - QtyMA, getMovementDate(), get_TrxName()); - - mtrx.setPP_Order_ID(getPP_Order_ID()); - mtrx.setPP_Order_BOMLine_ID(getPP_Order_BOMLine_ID()); - if (!mtrx.save(get_TrxName())) - { - m_processMsg = "Could not create Material Transaction (MA)"; - return DocAction.STATUS_Invalid; - } - + + if (!MStorage.add(getCtx(), getM_Warehouse_ID(), + getM_Locator_ID(), + getM_Product_ID(), + ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, + QtyMA, QtyIssue, QtyReceipt, get_TrxName())) + { + m_processMsg = "Cannot correct Inventory (MA)"; + return DocAction.STATUS_Invalid; + } + + // Create Transaction + mtrx = new MTransaction (getCtx(), this.getAD_Org_ID() , + MovementType,getM_Locator_ID(), + getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), + QtyMA, getMovementDate(), get_TrxName()); + + mtrx.setPP_Order_ID(getPP_Order_ID()); + mtrx.setPP_Order_BOMLine_ID(getPP_Order_BOMLine_ID()); + if (!mtrx.save(get_TrxName())) + { + m_processMsg = "Could not create Material Transaction (MA)"; + return DocAction.STATUS_Invalid; + } + } } // sLine.getM_AttributeSetInstance_ID() != 0 if (mtrx == null) { // Fallback: Update Storage - - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), - getM_Locator_ID(), - getM_Product_ID(), - getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, Qty, QtyIssue, QtyReceipt, get_TrxName())) - { - m_processMsg = "Cannot correct Inventory"; - return DocAction.STATUS_Invalid; - } + if (!MStorage.add(getCtx(), getM_Warehouse_ID(), + getM_Locator_ID(), + getM_Product_ID(), + getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, Qty, QtyIssue, QtyReceipt, get_TrxName())) + { + m_processMsg = "Cannot correct Inventory"; + return DocAction.STATUS_Invalid; + } // FallBack: Create Transaction - - mtrx = new MTransaction (getCtx(),getAD_Org_ID(),MovementType,getM_Locator_ID(),getM_Product_ID(),getM_AttributeSetInstance_ID(), Qty, getMovementDate(), get_TrxName()); - mtrx.setPP_Order_ID(getPP_Order_ID()); - mtrx.setPP_Order_BOMLine_ID(getPP_Order_BOMLine_ID()); - if (!mtrx.save(get_TrxName())) - { - m_processMsg = "Could not create Material Transaction"; - return DocAction.STATUS_Invalid; - } - + + mtrx = new MTransaction (getCtx(),getAD_Org_ID(),MovementType,getM_Locator_ID(),getM_Product_ID(),getM_AttributeSetInstance_ID(), Qty, getMovementDate(), get_TrxName()); + mtrx.setPP_Order_ID(getPP_Order_ID()); + mtrx.setPP_Order_BOMLine_ID(getPP_Order_BOMLine_ID()); + if (!mtrx.save(get_TrxName())) + { + m_processMsg = "Could not create Material Transaction"; + return DocAction.STATUS_Invalid; + } + } - + } // stock movement - + if (MovementType.charAt(1) == '-') { - // Update Order Line - if (getPP_Order_BOMLine_ID()!= 0) - { - - obomline = new MPPOrderBOMLine(getCtx(),getPP_Order_BOMLine_ID(),get_TrxName()); - 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())); - - if (!obomline.save(get_TrxName())) + // Update Order Line + if (getPP_Order_BOMLine_ID()!= 0) { - m_processMsg = "Could not update Order Line"; - return DocAction.STATUS_Invalid; + + obomline = new MPPOrderBOMLine(getCtx(),getPP_Order_BOMLine_ID(),get_TrxName()); + 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())); + + if (!obomline.save(get_TrxName())) + { + m_processMsg = "Could not update Order Line"; + return DocAction.STATUS_Invalid; + } + else + log.fine("OrderLine -> Reserved=" + obomline.getQtyReserved() + + ", Delivered=" + obomline.getQtyDelivered()); } - else - log.fine("OrderLine -> Reserved=" + obomline.getQtyReserved() - + ", Delivered=" + obomline.getQtyDelivered()); - } } else if (MovementType.charAt(1) == '+') { MPPOrder order = new MPPOrder(getCtx(), getPP_Order_ID(),get_TrxName()); order.setQtyDelivered(order.getQtyDelivered().add(getMovementQty())); - order.setQtyScrap(order.getQtyScrap().add(getScrappedQty())); - order.setQtyReject(order.getQtyReject().add(getQtyReject())); + 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())); @@ -361,276 +361,276 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction else log.fine("Order -> Delivered=" + order.getQtyDelivered()); } - // //fjv e-evolution Operation Activity Report begin - } - // I need refactory this code because can be improve Victor perez - if(doctype.equals(MDocType.DOCBASETYPE_ManufacturingOperationActivity)) - { - MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); - onodeact.setDocStatus("CO"); - onodeact.setQtyScrap(onodeact.getQtyScrap().add(getScrappedQty())); - onodeact.setQtyReject(onodeact.getQtyReject().add(getQtyReject())); - onodeact.setQtyDelivered(onodeact.getQtyDelivered().add(getMovementQty())); - onodeact.setDurationReal(onodeact.getDurationReal()+getDurationReal().intValue()); - onodeact.setSetupTimeReal(onodeact.getSetupTimeReal()+getSetupTimeReal().intValue()); - onodeact.save(); + // //fjv e-evolution Operation Activity Report begin + } + // I need refactory this code because can be improve Victor perez + if(doctype.equals(MDocType.DOCBASETYPE_ManufacturingOperationActivity)) + { + MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); + onodeact.setDocStatus("CO"); + onodeact.setQtyScrap(onodeact.getQtyScrap().add(getScrappedQty())); + onodeact.setQtyReject(onodeact.getQtyReject().add(getQtyReject())); + onodeact.setQtyDelivered(onodeact.getQtyDelivered().add(getMovementQty())); + onodeact.setDurationReal(onodeact.getDurationReal()+getDurationReal().intValue()); + onodeact.setSetupTimeReal(onodeact.getSetupTimeReal()+getSetupTimeReal().intValue()); + onodeact.save(); - ArrayList list = new ArrayList(); - int count =0; - try - { - StringBuffer sql=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=? Order By Value"); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmt.setInt(1, getPP_Order_ID()); - //pstmt.setInt(2, m_M_PriceList_ID); - ResultSet rs = pstmt.executeQuery(); - //while (!m_calculated && rsplv.next()) - while (rs.next()) - { + ArrayList list = new ArrayList(); + int count =0; + try + { + StringBuffer sql=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=? Order By Value"); + PreparedStatement pstmt = DB.prepareStatement(sql.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmt.setInt(1, getPP_Order_ID()); + //pstmt.setInt(2, m_M_PriceList_ID); + ResultSet rs = pstmt.executeQuery(); + //while (!m_calculated && rsplv.next()) + while (rs.next()) + { - Integer nodeid = new Integer(rs.getInt(1)); - list.add(count,nodeid.toString()); + Integer nodeid = new Integer(rs.getInt(1)); + list.add(count,nodeid.toString()); - count++; + count++; - } - rs.close(); - pstmt.close(); - } - catch (SQLException enode) - { - } - boolean ultimonodo = false; - - for (int v =0 ; v < list.size(); v++) - { - if (list.get(v).equals(new Integer(getPP_Order_Node_ID()).toString())) - { - //String nextnode = new String(list.get(v+1)); - try - { - StringBuffer sqlnn=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_NodeNext WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID=?"); - PreparedStatement pstmtnn = DB.prepareStatement(sqlnn.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmtnn.setInt(1, getPP_Order_ID()); - pstmtnn.setInt(2, getPP_Order_Node_ID()); - ResultSet rsnn = pstmtnn.executeQuery(); - //while (!m_calculated && rsplv.next()) - System.out.println("***** SQL ultm nodo " +sqlnn.toString()); - if (rsnn.next()) - { - - ultimonodo=false; - - + } + rs.close(); + pstmt.close(); + } + catch (SQLException enode) + { + } + boolean ultimonodo = false; - } - else - { - ultimonodo=true; - } - rsnn.close(); - pstmtnn.close(); - } - catch (SQLException enodenn) - { - } - if (!ultimonodo) - { - //System.out.println("***** No ES EL ULTIMO NODO"); - } - else - { - try - { - StringBuffer sql1=new StringBuffer("SELECT DocStatus,PP_Order_Node_ID,DurationRequiered FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID!=?"); - PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmt1.setInt(1, getPP_Order_ID()); - pstmt1.setInt(2, getPP_Order_Node_ID()); - ResultSet rs1 = pstmt1.executeQuery(); - //while (!m_calculated && rsplv.next()) - // System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); - while (rs1.next()) - { -// System.out.println("***** Nodo " +rs1.getInt(2) +" status " +rs1.getString(1)); -// if(!rs1.getString(1).equals("CL")) -// { -// -// MPPOrderNode onodenext =new MPPOrderNode(Env.getCtx(),rs1.getInt(2),get_TrxName()); -// onodenext.setDocStatus("CL"); -// onodenext.save(); -// } - createnewnode(rs1.getInt(2),rs1.getBigDecimal(3)); + for (int v =0 ; v < list.size(); v++) + { + if (list.get(v).equals(new Integer(getPP_Order_Node_ID()).toString())) + { + //String nextnode = new String(list.get(v+1)); + try + { + StringBuffer sqlnn=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_NodeNext WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID=?"); + PreparedStatement pstmtnn = DB.prepareStatement(sqlnn.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmtnn.setInt(1, getPP_Order_ID()); + pstmtnn.setInt(2, getPP_Order_Node_ID()); + ResultSet rsnn = pstmtnn.executeQuery(); + //while (!m_calculated && rsplv.next()) + System.out.println("***** SQL ultm nodo " +sqlnn.toString()); + if (rsnn.next()) + { - } - rs1.close(); - pstmt1.close(); - - - } - catch (SQLException enode) - { - } - } - } + ultimonodo=false; - } - - // crear orden de compra al cmpletar - int p_PP_Order_Node_ID=0; - BigDecimal m_MovementQty=Env.ZERO; - try - { - StringBuffer sql=new StringBuffer("SELECT PP_Order_Node_ID,MovementQty FROM PP_Cost_Collector WHERE IsActive='Y' AND AD_Client_ID=? and PP_Cost_Collector_ID=? "); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(),null); - pstmt.setInt(1, getAD_Client_ID()); - pstmt.setInt(2, getPP_Cost_Collector_ID()); - //pstmt.setInt(2, m_M_PriceList_ID); - ResultSet rs = pstmt.executeQuery(); - //while (!m_calculated && rsplv.next()) - while (rs.next()) - { - p_PP_Order_Node_ID= rs.getInt(1); - m_MovementQty=rs.getBigDecimal(2); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - } - + } + else + { + ultimonodo=true; + } + rsnn.close(); + pstmtnn.close(); + } + catch (SQLException enodenn) + { + } + if (!ultimonodo) + { + //System.out.println("***** No ES EL ULTIMO NODO"); + } + else + { + try + { + StringBuffer sql1=new StringBuffer("SELECT DocStatus,PP_Order_Node_ID,DurationRequiered FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID!=?"); + PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmt1.setInt(1, getPP_Order_ID()); + pstmt1.setInt(2, getPP_Order_Node_ID()); + ResultSet rs1 = pstmt1.executeQuery(); + //while (!m_calculated && rsplv.next()) + // System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); + while (rs1.next()) + { +// System.out.println("***** Nodo " +rs1.getInt(2) +" status " +rs1.getString(1)); +// if(!rs1.getString(1).equals("CL")) +// { - // if(isSubcontracting()) - // { - int M_Product_ID =0; - String salvado=""; - BigDecimal DeliveryTime=Env.ZERO; - try - { - StringBuffer plv=new StringBuffer("SELECT M_Product_ID FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_Node_ID=? "); - PreparedStatement pstmtplv = DB.prepareStatement(plv.toString(),null); - pstmtplv.setInt(1, p_PP_Order_Node_ID); - //pstmt.setInt(2, m_M_PriceList_ID); - ResultSet rsplv = pstmtplv.executeQuery(); - //while (!m_calculated && rsplv.next()) - if (rsplv.next()) - { - M_Product_ID= rsplv.getInt(1); - } - rsplv.close(); - pstmtplv.close(); - } - catch (SQLException e) - { - } +// MPPOrderNode onodenext =new MPPOrderNode(Env.getCtx(),rs1.getInt(2),get_TrxName()); +// onodenext.setDocStatus("CL"); +// onodenext.save(); +// } + createnewnode(rs1.getInt(2),rs1.getBigDecimal(3)); - if (M_Product_ID==0) - { - salvado="No hay un servicio asociado a este subcontrato"; - return salvado; - } - else - { - try - { - StringBuffer pp=new StringBuffer("SELECT DeliveryTime_Promised FROM PP_Product_Planning WHERE IsActive='Y' AND M_Product_ID=? "); - PreparedStatement pstmtpp = DB.prepareStatement(pp.toString(),null); - pstmtpp.setInt(1, M_Product_ID); - //pstmt.setInt(2, m_M_PriceList_ID); - ResultSet rspp = pstmtpp.executeQuery(); - //while (!m_calculated && rsplv.next()) - if (rspp.next()) - { - DeliveryTime= rspp.getBigDecimal(1); - } - rspp.close(); - pstmtpp.close(); - } - catch (SQLException e) - { - } - } - // MPPProfileBOM profileorder = new MPPProfileBOM(Env.getCtx(),m_PP_ProfileBOM_ID); - int m_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID")); - int m_AD_Org_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Org_ID")); - - int C_BPartner_ID=0; - try - { - StringBuffer sqlpo=new StringBuffer("SELECT C_BPartner_ID FROM M_Product_PO WHERE IsActive='Y' AND M_Product_ID=? "); - PreparedStatement pstmtpo = DB.prepareStatement(sqlpo.toString(),null); - pstmtpo.setInt(1, M_Product_ID); - //pstmt.setInt(2, m_M_PriceList_ID); - ResultSet rspo = pstmtpo.executeQuery(); - //while (!m_calculated && rsplv.next()) - while (rspo.next()) - { - C_BPartner_ID= rspo.getInt(1); - } - rspo.close(); - pstmtpo.close(); - } - catch (SQLException epo) - { - } + } + rs1.close(); + pstmt1.close(); - if (C_BPartner_ID==0) - { - salvado="No hay un proveedor asociado a este servicio de subcontrato"; - return salvado; - } - MPPOrder mpcorder = new MPPOrder(Env.getCtx(),getPP_Order_ID(),get_TrxName()); - String documentno = mpcorder.getDocumentNo(); - Timestamp today=new Timestamp(System.currentTimeMillis()); + } + catch (SQLException enode) + { + } + } + } + + } + + // crear orden de compra al cmpletar + int p_PP_Order_Node_ID=0; + BigDecimal m_MovementQty=Env.ZERO; + + try + { + StringBuffer sql=new StringBuffer("SELECT PP_Order_Node_ID,MovementQty FROM PP_Cost_Collector WHERE IsActive='Y' AND AD_Client_ID=? and PP_Cost_Collector_ID=? "); + PreparedStatement pstmt = DB.prepareStatement(sql.toString(),null); + pstmt.setInt(1, getAD_Client_ID()); + pstmt.setInt(2, getPP_Cost_Collector_ID()); + //pstmt.setInt(2, m_M_PriceList_ID); + ResultSet rs = pstmt.executeQuery(); + //while (!m_calculated && rsplv.next()) + while (rs.next()) + { + p_PP_Order_Node_ID= rs.getInt(1); + m_MovementQty=rs.getBigDecimal(2); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + } + + + + // if(isSubcontracting()) + // { + int M_Product_ID =0; + String salvado=""; + BigDecimal DeliveryTime=Env.ZERO; + try + { + StringBuffer plv=new StringBuffer("SELECT M_Product_ID FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_Node_ID=? "); + PreparedStatement pstmtplv = DB.prepareStatement(plv.toString(),null); + pstmtplv.setInt(1, p_PP_Order_Node_ID); + //pstmt.setInt(2, m_M_PriceList_ID); + ResultSet rsplv = pstmtplv.executeQuery(); + //while (!m_calculated && rsplv.next()) + if (rsplv.next()) + { + M_Product_ID= rsplv.getInt(1); + } + rsplv.close(); + pstmtplv.close(); + } + catch (SQLException e) + { + } + + if (M_Product_ID==0) + { + salvado="No hay un servicio asociado a este subcontrato"; + return salvado; + } + else + { + try + { + StringBuffer pp=new StringBuffer("SELECT DeliveryTime_Promised FROM PP_Product_Planning WHERE IsActive='Y' AND M_Product_ID=? "); + PreparedStatement pstmtpp = DB.prepareStatement(pp.toString(),null); + pstmtpp.setInt(1, M_Product_ID); + //pstmt.setInt(2, m_M_PriceList_ID); + ResultSet rspp = pstmtpp.executeQuery(); + //while (!m_calculated && rsplv.next()) + if (rspp.next()) + { + DeliveryTime= rspp.getBigDecimal(1); + } + rspp.close(); + pstmtpp.close(); + } + catch (SQLException e) + { + } + } + // MPPProfileBOM profileorder = new MPPProfileBOM(Env.getCtx(),m_PP_ProfileBOM_ID); + int m_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID")); + int m_AD_Org_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Org_ID")); + + int C_BPartner_ID=0; + try + { + StringBuffer sqlpo=new StringBuffer("SELECT C_BPartner_ID FROM M_Product_PO WHERE IsActive='Y' AND M_Product_ID=? "); + PreparedStatement pstmtpo = DB.prepareStatement(sqlpo.toString(),null); + pstmtpo.setInt(1, M_Product_ID); + //pstmt.setInt(2, m_M_PriceList_ID); + ResultSet rspo = pstmtpo.executeQuery(); + //while (!m_calculated && rsplv.next()) + while (rspo.next()) + { + C_BPartner_ID= rspo.getInt(1); + } + rspo.close(); + pstmtpo.close(); + } + catch (SQLException epo) + { + } + + if (C_BPartner_ID==0) + { + salvado="No hay un proveedor asociado a este servicio de subcontrato"; + return salvado; + } + MPPOrder mpcorder = new MPPOrder(Env.getCtx(),getPP_Order_ID(),get_TrxName()); + String documentno = mpcorder.getDocumentNo(); + + Timestamp today=new Timestamp(System.currentTimeMillis()); + + MOrder order = new MOrder(Env.getCtx(),0,get_TrxName()); + order.setC_BPartner_ID(C_BPartner_ID); + order.setIsSOTrx(false); + order.setC_DocTypeTarget_ID(); + order.setDatePromised(TimeUtil.addDays(today, DeliveryTime.intValue())); + order.setDescription(documentno); + if (order.save()) + { + MOrderLine oline = new MOrderLine(order); + oline.setM_Product_ID(M_Product_ID); + oline.setQtyEntered(m_MovementQty); + oline.setQtyOrdered(m_MovementQty); + oline.setDatePromised(TimeUtil.addDays(today, DeliveryTime.intValue())); + if(oline.save()) + { + MOrderLine oline1 = new MOrderLine(order); + oline1.setPriceEntered(oline.getPriceActual()); + oline1.setQtyOrdered(oline.getQtyEntered()); + oline1.save(); + } + + MPPCostCollector cc = new MPPCostCollector(Env.getCtx(),getPP_Cost_Collector_ID(),get_TrxName()); + cc.setProcessing(true); + cc.setDescription(order.getDocumentNo()); + cc.save(); + } + else + { + return DocAction.STATUS_Invalid; + } + //fjv e-evolution Operation Activity Report end +// } + } - MOrder order = new MOrder(Env.getCtx(),0,get_TrxName()); - order.setC_BPartner_ID(C_BPartner_ID); - order.setIsSOTrx(false); - order.setC_DocTypeTarget_ID(); - order.setDatePromised(TimeUtil.addDays(today, DeliveryTime.intValue())); - order.setDescription(documentno); - if (order.save()) - { - MOrderLine oline = new MOrderLine(order); - oline.setM_Product_ID(M_Product_ID); - oline.setQtyEntered(m_MovementQty); - oline.setQtyOrdered(m_MovementQty); - oline.setDatePromised(TimeUtil.addDays(today, DeliveryTime.intValue())); - if(oline.save()) - { - MOrderLine oline1 = new MOrderLine(order); - oline1.setPriceEntered(oline.getPriceActual()); - oline1.setQtyOrdered(oline.getQtyEntered()); - oline1.save(); - } - MPPCostCollector cc = new MPPCostCollector(Env.getCtx(),getPP_Cost_Collector_ID(),get_TrxName()); - cc.setProcessing(true); - cc.setDescription(order.getDocumentNo()); - cc.save(); - } - else - { - return DocAction.STATUS_Invalid; - } - //fjv e-evolution Operation Activity Report end -// } - } - - // for all lines setProcessed(true); setDocAction(DOCACTION_Close); - setDocStatus(DOCSTATUS_Completed); //fjv e-evolution add field Docstatus + setDocStatus(DOCSTATUS_Completed); //fjv e-evolution add field Docstatus return DocAction.STATUS_Completed; } // completeIt - + /** * Post Document - nothing * @return true if success @@ -640,7 +640,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("postIt - " + toString()); return false; } // postIt - + /** * Void Document. * @return true if success @@ -650,7 +650,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("voidIt - " + toString()); return false; } // voidIt - + /** * Close Document. * @return true if success @@ -660,113 +660,113 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("closeIt - " + toString()); // Close Not delivered Qty - // fjviejo e-evolution operation activity - boolean ultimonodo=false; - try - { - StringBuffer sqlnn=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_NodeNext WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID=?"); - PreparedStatement pstmtnn = DB.prepareStatement(sqlnn.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmtnn.setInt(1, getPP_Order_ID()); - pstmtnn.setInt(2, getPP_Order_Node_ID()); - ResultSet rsnn = pstmtnn.executeQuery(); - //while (!m_calculated && rsplv.next()) - System.out.println("***** SQL ultm nodo " +sqlnn.toString()); - if (rsnn.next()) - { - - ultimonodo=false; - - + // fjviejo e-evolution operation activity + boolean ultimonodo=false; + try + { + StringBuffer sqlnn=new StringBuffer("SELECT PP_Order_Node_ID FROM PP_Order_NodeNext WHERE IsActive='Y' AND PP_Order_ID=? and PP_Order_Node_ID=?"); + PreparedStatement pstmtnn = DB.prepareStatement(sqlnn.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmtnn.setInt(1, getPP_Order_ID()); + pstmtnn.setInt(2, getPP_Order_Node_ID()); + ResultSet rsnn = pstmtnn.executeQuery(); + //while (!m_calculated && rsplv.next()) + System.out.println("***** SQL ultm nodo " +sqlnn.toString()); + if (rsnn.next()) + { - } - else - { - ultimonodo=true; - } - rsnn.close(); - pstmtnn.close(); - } - catch (SQLException enodenn) - { - } - - if(!ultimonodo) - { - - MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); - onodeact.setDocStatus("CL"); - // onodeact.setAction(DOCACTION_None); - onodeact.save(); - try - { - StringBuffer sql1=new StringBuffer("SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID=? AND PP_Order_Node_ID=?"); - PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmt1.setInt(1, getPP_Order_ID()); - pstmt1.setInt(2, getPP_Order_Node_ID()); - ResultSet rs1 = pstmt1.executeQuery(); - //while (!m_calculated && rsplv.next()) - //System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); - while (rs1.next()) - { - MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rs1.getInt(1),get_TrxName()); - costcoll.setDocStatus("CL"); - costcoll.setDocAction(DOCACTION_None); - costcoll.save(); - - } - rs1.close(); - pstmt1.close(); - - - } - catch (SQLException enode1) - { - } - } - else - { - try - { - StringBuffer sql1=new StringBuffer("SELECT DocStatus,PP_Order_Node_ID,DurationRequiered FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=?"); - PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); - // pstmt.setInt(1, AD_Client_ID); - pstmt1.setInt(1, getPP_Order_ID()); - //pstmt1.setInt(2, getPP_Order_Node_ID()); - ResultSet rs1 = pstmt1.executeQuery(); - //while (!m_calculated && rsplv.next()) - //System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); - while (rs1.next()) - { - System.out.println("***** Nodo " +rs1.getInt(2) +" status " +rs1.getString(1)); - if(!rs1.getString(1).equals("CL")) - { - - MPPOrderNode onodenext =new MPPOrderNode(Env.getCtx(),rs1.getInt(2),get_TrxName()); - onodenext.setDocStatus("CL"); - onodenext.save(); - - - } - + ultimonodo=false; - } - rs1.close(); - pstmt1.close(); - - - } - catch (SQLException enode) - { - } - closenew(getPP_Order_ID(),getPP_Order_Node_ID()); - } - // fjviejo e-evolution operation activity end + + + } + else + { + ultimonodo=true; + } + rsnn.close(); + pstmtnn.close(); + } + catch (SQLException enodenn) + { + } + + if(!ultimonodo) + { + + MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); + onodeact.setDocStatus("CL"); + // onodeact.setAction(DOCACTION_None); + onodeact.save(); + try + { + StringBuffer sql1=new StringBuffer("SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID=? AND PP_Order_Node_ID=?"); + PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmt1.setInt(1, getPP_Order_ID()); + pstmt1.setInt(2, getPP_Order_Node_ID()); + ResultSet rs1 = pstmt1.executeQuery(); + //while (!m_calculated && rsplv.next()) + //System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); + while (rs1.next()) + { + MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rs1.getInt(1),get_TrxName()); + costcoll.setDocStatus("CL"); + costcoll.setDocAction(DOCACTION_None); + costcoll.save(); + + } + rs1.close(); + pstmt1.close(); + + + } + catch (SQLException enode1) + { + } + } + else + { + try + { + StringBuffer sql1=new StringBuffer("SELECT DocStatus,PP_Order_Node_ID,DurationRequiered FROM PP_Order_Node WHERE IsActive='Y' AND PP_Order_ID=?"); + PreparedStatement pstmt1 = DB.prepareStatement(sql1.toString(),null); + // pstmt.setInt(1, AD_Client_ID); + pstmt1.setInt(1, getPP_Order_ID()); + //pstmt1.setInt(2, getPP_Order_Node_ID()); + ResultSet rs1 = pstmt1.executeQuery(); + //while (!m_calculated && rsplv.next()) + //System.out.println("***** SQL1 " +sql1 + " variable " +getPP_Order_ID()); + while (rs1.next()) + { + System.out.println("***** Nodo " +rs1.getInt(2) +" status " +rs1.getString(1)); + if(!rs1.getString(1).equals("CL")) + { + + MPPOrderNode onodenext =new MPPOrderNode(Env.getCtx(),rs1.getInt(2),get_TrxName()); + onodenext.setDocStatus("CL"); + onodenext.save(); + + + } + + + } + rs1.close(); + pstmt1.close(); + + + } + catch (SQLException enode) + { + } + closenew(getPP_Order_ID(),getPP_Order_Node_ID()); + } + // fjviejo e-evolution operation activity end setDocAction(DOCACTION_None); return true; } // closeIt - + /** * Reverse Correction * @return false @@ -776,7 +776,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("reverseCorrectIt - " + toString()); return false; } // reverseCorrectionIt - + /** * Reverse Accrual - none * @return false @@ -786,7 +786,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("reverseAccrualIt - " + toString()); return false; } // reverseAccrualIt - + /** * Re-activate * @return false @@ -796,8 +796,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.info("reActivateIt - " + toString()); return false; } // reActivateIt - - + + /************************************************************************* * Get Summary * @return Summary of Document @@ -815,7 +815,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction sb.append(" - ").append(getDescription()); return sb.toString(); } // getSummary - + /** * Get Process Message * @return clear text error message @@ -824,7 +824,7 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction { return m_processMsg; } // getProcessMsg - + /** * Get Document Owner (Responsible) * @return AD_User_ID @@ -840,8 +840,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction */ public int getC_Currency_ID() { - // MPriceList pl = MPriceList.get(getCtx(), getM_PriceList_ID()); - // return pl.getC_Currency_ID(); + // MPriceList pl = MPriceList.get(getCtx(), getM_PriceList_ID()); + // return pl.getC_Currency_ID(); return 0; } @@ -853,13 +853,13 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction { return new BigDecimal(0); } // getApprovalAmt - - /** - * Create PDF - * @return File or null - */ - public File createPDF () - { + + /** + * Create PDF + * @return File or null + */ + public File createPDF () + { try { File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf"); @@ -870,9 +870,9 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction log.severe("Could not create PDF - " + e.getMessage()); } return null; - } // getPDF - - /** + } // getPDF + + /** * Create PDF file * @param file output file * @return file if success @@ -884,8 +884,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction return null; return re.getPDF(file); } // createPDF - - /** + + /** * Get Document Info * @return document info (untranslated) */ @@ -894,260 +894,260 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction org.compiere.model.MDocType dt = org.compiere.model.MDocType.get(getCtx(), getC_DocType_ID()); return dt.getName() + " " + getDocumentNo(); } // getDocumentInfo - - public String getDocumentNo() - { - return ""; - } - - protected void createnewnode(int node, BigDecimal duration) - { - - - //fjv e-evolution Operation Activity Report begin - try - { - String sqlar="SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+getPP_Order_ID() +" and PP_Order_Node_ID="+node; - PreparedStatement pstmtar = DB.prepareStatement(sqlar,null); - // pstmt.setInt(1, AD_Client_ID); - // pstmtar.setInt(1, getPP_Order_ID()); - //pstmtar.setInt(2, rs1.getInt(2)); - // System.out.println("***** SQLar " +sqlar + " variables " +getPP_Order_ID() +" nodo "+node); - ResultSet rsar = pstmtar.executeQuery(); - - //while (!m_calculated && rsplv.next()) - if(rsar.next()) - { - // System.out.println("***** NODO Ya Existe"); - } - else - { - // System.out.println("***** ENTRA AL eLSE "); - MPPCostCollector costnew = new MPPCostCollector(Env.getCtx(),0,get_TrxName()); - costnew.setPP_Order_ID(getPP_Order_ID()); - costnew.setC_DocTypeTarget_ID(getC_DocTypeTarget_ID()); - costnew.setC_DocType_ID(getC_DocType_ID()); - costnew.setS_Resource_ID(getS_Resource_ID()); - costnew.setM_Warehouse_ID(getM_Warehouse_ID()); - costnew.setM_Locator_ID(getM_Locator_ID()); - costnew.setM_Product_ID(getM_Product_ID()); - costnew.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID()); - costnew.setPP_Order_Workflow_ID(getPP_Order_Workflow_ID()); - costnew.setAD_User_ID(getAD_User_ID()); - costnew.setMovementDate(getMovementDate()); - costnew.setDateAcct(getDateAcct()); - costnew.setPP_Order_Node_ID(node); - costnew.setMovementQty(getMovementQty()); - costnew.setDurationReal(duration); - //costnew.setDurationUnit(getDurationUnit()); - costnew.setMovementType(getMovementType()); - costnew.save(); - // costnew.completeIt(); - - } - - rsar.close(); - pstmtar.close(); - - } - catch (SQLException exnode) - { - } - //completenew(getPP_Order_ID(),node); - //fjv e-evolution Operation Activity Report end - - - } - - protected boolean beforeSave(boolean newRecord) { - - - - //fjv e-evolution Operation Activity Report begin -// MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); -// onodeact.setDocStatus("IP"); -// onodeact.save(); - if (newRecord) - setDocStatus("IP"); - - //fjv e-evolution Operation Activity Report end - - return true; - } - - protected boolean afterSave(boolean newRecord, boolean success) { - + + public String getDocumentNo() + { + return ""; + } + + protected void createnewnode(int node, BigDecimal duration) + { + + + //fjv e-evolution Operation Activity Report begin + try + { + String sqlar="SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+getPP_Order_ID() +" and PP_Order_Node_ID="+node; + PreparedStatement pstmtar = DB.prepareStatement(sqlar,null); + // pstmt.setInt(1, AD_Client_ID); + // pstmtar.setInt(1, getPP_Order_ID()); + //pstmtar.setInt(2, rs1.getInt(2)); + // System.out.println("***** SQLar " +sqlar + " variables " +getPP_Order_ID() +" nodo "+node); + ResultSet rsar = pstmtar.executeQuery(); + + //while (!m_calculated && rsplv.next()) + if(rsar.next()) + { + // System.out.println("***** NODO Ya Existe"); + } + else + { + // System.out.println("***** ENTRA AL eLSE "); + MPPCostCollector costnew = new MPPCostCollector(Env.getCtx(),0,get_TrxName()); + costnew.setPP_Order_ID(getPP_Order_ID()); + costnew.setC_DocTypeTarget_ID(getC_DocTypeTarget_ID()); + costnew.setC_DocType_ID(getC_DocType_ID()); + costnew.setS_Resource_ID(getS_Resource_ID()); + costnew.setM_Warehouse_ID(getM_Warehouse_ID()); + costnew.setM_Locator_ID(getM_Locator_ID()); + costnew.setM_Product_ID(getM_Product_ID()); + costnew.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID()); + costnew.setPP_Order_Workflow_ID(getPP_Order_Workflow_ID()); + costnew.setAD_User_ID(getAD_User_ID()); + costnew.setMovementDate(getMovementDate()); + costnew.setDateAcct(getDateAcct()); + costnew.setPP_Order_Node_ID(node); + costnew.setMovementQty(getMovementQty()); + costnew.setDurationReal(duration); + //costnew.setDurationUnit(getDurationUnit()); + costnew.setMovementType(getMovementType()); + costnew.save(); + // costnew.completeIt(); + + } + + rsar.close(); + pstmtar.close(); + + } + catch (SQLException exnode) + { + } + //completenew(getPP_Order_ID(),node); + //fjv e-evolution Operation Activity Report end + + + } + + protected boolean beforeSave(boolean newRecord) { + + + + //fjv e-evolution Operation Activity Report begin +// MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); +// onodeact.setDocStatus("IP"); +// onodeact.save(); + if (newRecord) + setDocStatus("IP"); + + //fjv e-evolution Operation Activity Report end + + return true; + } + + protected boolean afterSave(boolean newRecord, boolean success) { + if (!newRecord) return success; - - //fjv e-evolution Operation Activity Report begin - MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); - onodeact.setDocStatus("IP"); - //onodeact.setAD_WF_Node_ID(getPP_Order_Workflow_ID()); - onodeact.save(); - - // setDocStatus("IP"); - - //fjv e-evolution Operation Activity Report end - - return true; - } //aftersave - protected void closenew(int order, int node) - { - try - { - String sqlcom="SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+order; - PreparedStatement pstmtcom = DB.prepareStatement(sqlcom,null); - // pstmt.setInt(1, AD_Client_ID); - // pstmtar.setInt(1, getPP_Order_ID()); - //pstmtar.setInt(2, rs1.getInt(2)); - System.out.println("***** SQLar " +sqlcom + " variables " +order +" nodo "+node); - ResultSet rscom = pstmtcom.executeQuery(); - while(rscom.next()) - { - MDocType doc = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); - String doct =""; - doct=doc.getDocBaseType(); - if(doct.equals("MOA")) - { - MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rscom.getInt(1),get_TrxName()); - costcoll.setDocStatus("CL"); - costcoll.setDocAction(DOCACTION_None); - costcoll.save(); - } - } - } - catch (SQLException excom) - { - } - } - - protected void completenew(int order, int node) - { - try - { - String sqlcom="SELECT PP_Cost_Collector_ID,DocStatus FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+order; - PreparedStatement pstmtcom = DB.prepareStatement(sqlcom,null); - // pstmt.setInt(1, AD_Client_ID); - // pstmtar.setInt(1, getPP_Order_ID()); - //pstmtar.setInt(2, rs1.getInt(2)); - System.out.println("***** SQLar " +sqlcom + " variables " +order +" nodo "+node); - ResultSet rscom = pstmtcom.executeQuery(); - while(rscom.next()) - { - MDocType doc = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); - String doct =""; - doct=doc.getDocBaseType(); - if(doct.equals("MOA")) - { - if(!rscom.getString(2).equals("C0") && !rscom.getString(2).equals("CL")) - { - MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rscom.getInt(1),get_TrxName()); - costcoll.completeIt(); - } - } - } - } - catch (SQLException excom) - { - } - } - - /** - * Check Material Policy. - * (NOT USED) - * Sets line ASI - */ - private void checkMaterialPolicy(MPPOrderBOMLine line , BigDecimal qty) - { - int no = MPPOrderBOMLineMA.deleteOrderBOMLineMA(line.getPP_Order_BOMLine_ID(), get_TrxName()); - if (no > 0) - log.config("Delete old #" + no); - - - // Check Line - boolean needSave = false; - BigDecimal qtyASI = Env.ZERO ; - // Attribute Set Instance - if (line.getM_AttributeSetInstance_ID() == 0) - { - MProduct product = MProduct.get(getCtx(), line.getM_Product_ID()); - if (qty.signum() > 0) // Incoming Trx - { - MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName()); - asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID()); - if (!asi.save()) - { - throw new IllegalStateException("Error try create ASI Reservation"); - } - if (asi.save()) - { - line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID()); - needSave = true; - } - } - else // Outgoing Trx - { - String MMPolicy = product.getMMPolicy(); - MStorage[] storages = MStorage.getAllWithASI(getCtx(), - line.getM_Product_ID(), line.getM_Locator_ID(), - MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName()); - BigDecimal qtyToDeliver = qty.negate(); - - - for (MStorage storage: storages) - { - //consume ASI Zero - if (storage.getM_AttributeSetInstance_ID() == 0) - { - qtyASI = qtyASI.add(storage.getQtyOnHand()); - qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); - continue; - } - - if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0) - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, - storage.getM_AttributeSetInstance_ID(), - qtyToDeliver); - if (!ma.save()) - { - throw new IllegalStateException("Error try create ASI Reservation"); - } - qtyToDeliver = Env.ZERO; - log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); - //return; - } - else - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, - storage.getM_AttributeSetInstance_ID(), - storage.getQtyOnHand()); - if (!ma.save()) - { - throw new IllegalStateException("Error try create ASI Reservation"); - } - qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); - log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); - } - } - - // No AttributeSetInstance found for remainder - if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0) - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, 0 , qtyToDeliver.add(qtyASI)); - - if (!ma.save()) - ; - log.fine("##: " + ma); - } - } // outgoing Trx - - if (needSave && !line.save()) - log.severe("NOT saved " + line); - } // for all lines - } // checkMaterialPolicy - + //fjv e-evolution Operation Activity Report begin + MPPOrderNode onodeact =new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),null); + onodeact.setDocStatus("IP"); + //onodeact.setAD_WF_Node_ID(getPP_Order_Workflow_ID()); + onodeact.save(); + + // setDocStatus("IP"); + + //fjv e-evolution Operation Activity Report end + + return true; + } //aftersave + protected void closenew(int order, int node) + { + try + { + String sqlcom="SELECT PP_Cost_Collector_ID FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+order; + PreparedStatement pstmtcom = DB.prepareStatement(sqlcom,null); + // pstmt.setInt(1, AD_Client_ID); + // pstmtar.setInt(1, getPP_Order_ID()); + //pstmtar.setInt(2, rs1.getInt(2)); + System.out.println("***** SQLar " +sqlcom + " variables " +order +" nodo "+node); + ResultSet rscom = pstmtcom.executeQuery(); + while(rscom.next()) + { + MDocType doc = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); + String doct =""; + doct=doc.getDocBaseType(); + if(doct.equals("MOA")) + { + MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rscom.getInt(1),get_TrxName()); + costcoll.setDocStatus("CL"); + costcoll.setDocAction(DOCACTION_None); + costcoll.save(); + } + } + } + catch (SQLException excom) + { + } + } + + protected void completenew(int order, int node) + { + try + { + String sqlcom="SELECT PP_Cost_Collector_ID,DocStatus FROM PP_Cost_Collector WHERE IsActive='Y' AND PP_Order_ID="+order; + PreparedStatement pstmtcom = DB.prepareStatement(sqlcom,null); + // pstmt.setInt(1, AD_Client_ID); + // pstmtar.setInt(1, getPP_Order_ID()); + //pstmtar.setInt(2, rs1.getInt(2)); + System.out.println("***** SQLar " +sqlcom + " variables " +order +" nodo "+node); + ResultSet rscom = pstmtcom.executeQuery(); + while(rscom.next()) + { + MDocType doc = new MDocType(Env.getCtx(),getC_DocType_ID(),get_TrxName()); + String doct =""; + doct=doc.getDocBaseType(); + if(doct.equals("MOA")) + { + if(!rscom.getString(2).equals("C0") && !rscom.getString(2).equals("CL")) + { + MPPCostCollector costcoll = new MPPCostCollector(Env.getCtx(),rscom.getInt(1),get_TrxName()); + costcoll.completeIt(); + } + } + } + } + catch (SQLException excom) + { + } + } + + /** + * Check Material Policy. + * (NOT USED) + * Sets line ASI + */ + private void checkMaterialPolicy(MPPOrderBOMLine line , BigDecimal qty) + { + int no = MPPOrderBOMLineMA.deleteOrderBOMLineMA(line.getPP_Order_BOMLine_ID(), get_TrxName()); + if (no > 0) + log.config("Delete old #" + no); + + + // Check Line + boolean needSave = false; + BigDecimal qtyASI = Env.ZERO ; + // Attribute Set Instance + if (line.getM_AttributeSetInstance_ID() == 0) + { + MProduct product = MProduct.get(getCtx(), line.getM_Product_ID()); + if (qty.signum() > 0) // Incoming Trx + { + MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName()); + asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID()); + if (!asi.save()) + { + throw new IllegalStateException("Error try create ASI Reservation"); + } + if (asi.save()) + { + line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID()); + needSave = true; + } + } + else // Outgoing Trx + { + String MMPolicy = product.getMMPolicy(); + MStorage[] storages = MStorage.getAllWithASI(getCtx(), + line.getM_Product_ID(), line.getM_Locator_ID(), + MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName()); + BigDecimal qtyToDeliver = qty.negate(); + + + for (MStorage storage: storages) + { + //consume ASI Zero + if (storage.getM_AttributeSetInstance_ID() == 0) + { + qtyASI = qtyASI.add(storage.getQtyOnHand()); + qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); + continue; + } + + if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0) + { + MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, + storage.getM_AttributeSetInstance_ID(), + qtyToDeliver); + if (!ma.save()) + { + throw new IllegalStateException("Error try create ASI Reservation"); + } + qtyToDeliver = Env.ZERO; + log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); + //return; + } + else + { + MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, + storage.getM_AttributeSetInstance_ID(), + storage.getQtyOnHand()); + if (!ma.save()) + { + throw new IllegalStateException("Error try create ASI Reservation"); + } + qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); + log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); + } + } + + // No AttributeSetInstance found for remainder + if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0) + { + MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, 0 , qtyToDeliver.add(qtyASI)); + + if (!ma.save()) + ; + log.fine("##: " + ma); + } + } // outgoing Trx + + if (needSave && !line.save()) + log.severe("NOT saved " + line); + } // for all lines + + } // checkMaterialPolicy + } // MMovement