Beispiel #1
0
        /// <summary>
        /// Get BOM Lines for Product given a specific BOM
        /// </summary>
        /// <param name="bom">BOM</param>
        /// <returns>array of BOMProducts.</returns>
        /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        public static MBOMProduct[] GetBOMLines(MBOM bom)
        {
            String             sql  = "SELECT * FROM M_BOMProduct WHERE M_BOM_ID=" + bom.GetM_BOM_ID() + " AND IsActive='Y' ORDER BY Line";
            List <MBOMProduct> list = new List <MBOMProduct>();
            IDataReader        idr  = null;

            try
            {
                DataTable dt = new DataTable();
                idr = DB.ExecuteReader(sql, null, bom.Get_Trx());
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MBOMProduct(bom.GetCtx(), dr, bom.Get_Trx()));
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            //
            MBOMProduct[] retValue = new MBOMProduct[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Beispiel #2
0
        /// <summary>
        /// Get Products of BOM
        /// </summary>
        /// <param name="bom">bom</param>
        /// <returns>array of BOM Products</returns>
        public static MBOMProduct[] GetOfBOM(MBOM bom)
        {
            List <MBOMProduct> list = new List <MBOMProduct>();
            String             sql  = "SELECT * FROM M_BOMProduct WHERE M_BOM_ID=@bomid ORDER BY SeqNo";

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@bomid", bom.GetM_BOM_ID());
                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, bom.Get_Trx());
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MBOMProduct(bom.GetCtx(), dr, bom.Get_Trx()));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            MBOMProduct[] retValue = new MBOMProduct[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Beispiel #3
0
        /// <summary>
        /// Get BOM Lines for Product. Default to Current Active, Master BOM
        /// BOM Lines are Ordered By Ascending Order of Product Names.
        /// </summary>
        /// <param name="product">product</param>
        /// <param name="bomType">bomtype</param>
        /// <param name="bomUse">bomuse</param>
        /// <param name="isAscending">true if ascending, false if descending</param>
        /// <returns>array of BOMs</returns>
        /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        public static MBOMProduct[] GetBOMLinesOrderByProductName(MProduct product, String bomType, String bomUse, Boolean isAscending)
        {
            // return lines for Current Active, Master BOM
            String sql = "SELECT M_BOM_ID FROM M_BOM WHERE M_Product_ID= " + product.GetM_Product_ID() +
                         "AND BOMType ='" + bomType + "' AND BOMUse ='" + bomUse + "' AND IsActive = 'Y'";
            Trx         trx   = product.Get_Trx();
            int         bomID = 0;
            IDataReader idr   = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, trx);
                if (idr.Read())
                {
                    bomID = Util.GetValueOfInt(idr[0]);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            return(GetBOMLinesOrderByProductName(MBOM.Get(product.GetCtx(), bomID), isAscending));
        }
Beispiel #4
0
        }       //	Get

        /**
         *  Get BOMs Of Product
         *	@param ctx context
         *	@param M_Product_ID product
         *	@param trxName trx
         *	@param whereClause optional WHERE clause w/o AND
         *	@return array of BOMs
         */
        public static MBOM[] GetOfProduct(Ctx ctx, int M_Product_ID,
                                          Trx trxName, String whereClause)
        {
            List <MBOM> list = new List <MBOM>();
            String      sql  = "SELECT * FROM M_BOM WHERE IsActive = 'Y' AND M_Product_ID=" + M_Product_ID;

            if (whereClause != null && whereClause.Length > 0)
            {
                sql += " AND " + whereClause;
            }
            //PreparedStatement pstmt = null;
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                //pstmt = DataBase.prepareStatement (sql, trxName);
                //pstmt.SetInt (1, M_Product_ID);
                //ResultSet rs = pstmt.executeQuery ();
                idr = DataBase.DB.ExecuteReader(sql, null, trxName);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();

                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MBOM(ctx, dr, trxName));
                }
                //rs.close ();
                //pstmt.close ();
                //pstmt = null;
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }
            //try
            //{
            //    if (pstmt != null)
            //        pstmt.close ();
            //    pstmt = null;
            //}
            //catch (Exception e)
            //{
            //    pstmt = null;
            //}

            MBOM[] retValue = new MBOM[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }       //	GetOfProduct
Beispiel #5
0
 /// <summary>
 /// Get Component BOM
 /// </summary>
 /// <returns>MBOM</returns>
 /// <writer>raghu</writer>
 /// <date>08-march-2011</date>
 public MBOM GetComponentBOM()
 {
     if (_componentBOM == null && GetM_ProductBOMVersion_ID() != 0)
     {
         _componentBOM = MBOM.Get(GetCtx(), GetM_ProductBOMVersion_ID());
     }
     return(_componentBOM);
 }
Beispiel #6
0
 /// <summary>
 /// Get Parent
 /// </summary>
 /// <returns>parent</returns>
 public MBOM GetBOM()
 {
     if (_bom == null && GetM_BOM_ID() != 0)
     {
         _bom = MBOM.Get(GetCtx(), GetM_BOM_ID());
     }
     return(_bom);
 }
Beispiel #7
0
        /**
         *  Get BOM from Cache
         *	@param ctx context
         *	@param M_BOM_ID id
         *	@return MBOM
         */
        public static MBOM Get(Ctx ctx, int M_BOM_ID)
        {
            int  key      = M_BOM_ID;
            MBOM retValue = (MBOM)_cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MBOM(ctx, M_BOM_ID, null);
            if (retValue.Get_ID() != 0)
            {
                _cache.Add(key, retValue);
            }
            return(retValue);
        }       //	Get
        //*****Manfacturing
        /// <summary>
        /// After Delete
        /// </summary>
        /// <param name="success">success</param>
        /// <returns>true</returns>
        /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        protected override Boolean AfterDelete(Boolean success)
        {
            //MBOMProduct[] lines = MBOMProduct.GetBOMLines(GetBOM());
            //if (lines == null || 0 == lines.Length || (1 == lines.Length && lines[0].GetM_BOMProduct_ID() == GetM_BOMProduct_ID()))
            //{
            // when we delete any record, then make isverfied as false on product
            MBOM     _bom    = new MBOM(GetCtx(), GetM_BOM_ID(), Get_Trx());
            MProduct product = MProduct.Get(GetCtx(), _bom.GetM_Product_ID());

            product.SetIsVerified(false);
            if (!product.Save(Get_Trx()))
            {
                return(false);
            }
            //}
            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// Get BOM Lines for Product given a specific BOM
        /// The result is Ordered By Product Name.
        /// </summary>
        /// <param name="bom">Bom</param>
        /// <param name="isAscending">true is ascending, false if descending</param>
        /// <returns>array of BOMProducts.</returns>
        ///  /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        public static MBOMProduct[] GetBOMLinesOrderByProductName(MBOM bom, Boolean isAscending)
        {
            StringBuilder sql = new StringBuilder("SELECT * FROM M_BOMProduct WHERE M_BOM_ID=" + bom.GetM_BOM_ID() + " AND IsActive='Y'");

            if (isAscending)
            {
                sql.Append(" ORDER BY getProductName(M_ProductBOM_ID)");
            }
            else
            {
                sql.Append(" ORDER BY getProductName(M_ProductBOM_ID) DESC");
            }
            List <MBOMProduct> list = new List <MBOMProduct>();
            IDataReader        idr  = null;

            try
            {
                idr = DB.ExecuteReader(sql.ToString(), null, bom.Get_Trx());
                DataTable dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list.Add(new MBOMProduct(bom.GetCtx(), dt.Rows[i], bom.Get_Trx()));
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql.ToString(), e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            //
            MBOMProduct[] retValue = new MBOMProduct[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Beispiel #10
0
 /// <summary>
 /// After Save
 /// </summary>
 /// <param name="newRecord"></param>
 /// <param name="success"></param>
 /// <returns>success</returns>
 /// <writer>raghu</writer>
 /// <date>08-march-2011</date>
 protected override Boolean AfterSave(Boolean newRecord, Boolean success)
 {
     //	BOM Component Line was changed
     if (newRecord || Is_ValueChanged("M_ProductBOM_ID") || Is_ValueChanged("M_ProductBOMVersion_ID") || Is_ValueChanged("IsActive"))
     {
         MBOM mbom = new MBOM(GetCtx(), GetM_BOM_ID(), Get_Trx());
         //	Invalidate BOM
         MProduct product = new MProduct(GetCtx(), mbom.GetM_Product_ID(), Get_Trx());
         if (Get_Trx() != null)
         {
             product.Load(Get_Trx());
         }
         if (product.IsVerified())
         {
             product.SetIsVerified(false);
             product.Save(Get_Trx());
         }
         //	Invalidate Products where BOM is used
     }
     return(success);
 }
        }       //	GetRequests

        /**
         *  Before Save
         *	@param newRecord new
         *	@return true/false
         */
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            //	Have at least one
            if (GetM_BOM_ID() == 0 && GetM_ChangeNotice_ID() == 0)
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@NotFound@: @M_BOM_ID@ / @M_ChangeNotice_ID@"));
                return(false);
            }

            //	Derive ChangeNotice from BOM if defined
            if (newRecord && GetM_BOM_ID() != 0 && GetM_ChangeNotice_ID() == 0)
            {
                MBOM bom = new MBOM(GetCtx(), GetM_BOM_ID(), Get_Trx());
                if (bom.GetM_ChangeNotice_ID() != 0)
                {
                    SetM_BOM_ID(bom.GetM_ChangeNotice_ID());
                }
            }

            return(true);
        }       //	beforeSave
Beispiel #12
0
        /**
         *  Perform process.
         *  @return Message
         *  @throws Exception
         */
        //@Override
        protected override String DoIt()
        {
            if (0 == p_M_WorkOrderTransaction_ID)
            {
                throw new Exception("@FillMandatory@ @M_WorkOrderTransaction_ID@");
            }
            ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction woTxn = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(GetCtx(), p_M_WorkOrderTransaction_ID, Get_TrxName());
            ViennaAdvantage.Model.MVAMFGMWorkOrder         wo    = new ViennaAdvantage.Model.MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName());

            VAdvantage.Model.MBOM bom         = new VAdvantage.Model.MBOM(GetCtx(), wo.GetM_BOM_ID(), Get_TrxName());
            MBOMProduct[]         BOMproducts = MBOMProduct.GetOfBOM(bom);
            for (int i = 0; i < BOMproducts.Length; i++)
            {
                string  prodensity = "SELECT nvl(GOM01_DENSITY,0) FROM VAMFG_M_WorkOrder WHERE VAMFG_M_WorkOrder_ID =" + woTxn.GetVAMFG_M_WorkOrder_ID();
                decimal DenQty     = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prodensity));
                if (DenQty == 0)
                {
                    DenQty = 1;
                }

                MBOMProduct BOMproduct = BOMproducts[i];
                decimal     qtyReqd    = (p_Qty * BOMproduct.GetBOMQty()) * DenQty;

                //string qry = "SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID)   FROM M_Transaction  WHERE movementdate = " +
                //            " (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(woTxn.GetVAMFG_DateTrx(), true) + " AND  M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() +
                //            " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND  M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() +
                //            " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND AD_Org_ID = " + woTxn.GetAD_Org_ID() + " AND  M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() +
                //            " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID();
                //decimal CurrentQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(qry));
                //if (CurrentQty < qtyReqd)
                //{
                //    ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx());
                //    return "Insufficient qty in warehouse for : " + product.GetName();
                //}

                VAdvantage.Model.MStorage st = VAdvantage.Model.MStorage.Get(Env.GetCtx(), woTxn.GetM_Locator_ID(), BOMproduct.GetM_ProductBOM_ID(), BOMproduct.GetM_AttributeSetInstance_ID(), Get_TrxName());
                if (st == null)
                {
                    ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx());
                    return("Insufficient qty in warehouse for : " + product.GetName());
                }
                decimal CurrentQty = st.GetQtyOnHand();
                if (CurrentQty < qtyReqd)
                {
                    ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx());
                    return("Insufficient qty in warehouse for : " + product.GetName());
                }
            }

            if (p_Qty == 0)
            {
                //MVAMFGMWorkOrder wo = new MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName());
                // p_Qty = wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled());
                string prdOrdQry = "SELECT SUM(wkt.VAMFG_QtyEntered) AS ProdOrder FROM VAMFG_M_WrkOdrTransaction wkt WHERE wkt.VAMFG_WorkOrderTxnType ='CI' AND wkt.M_Product_ID = "
                                   + woTxn.GetM_Product_ID() + " AND wkt.VAMFG_M_Workorder_ID = " + woTxn.GetVAMFG_M_WorkOrder_ID() + " AND wkt.DocStatus ='CO'";

                Decimal ProdOrdQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prdOrdQry, null, Get_TrxName()));
                p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (ProdOrdQty));
                //p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (wo.GetVAMFG_QtyAssembled()));

                //log.Info ("@Quantity@ = " + wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled().add(wo.GetVAMFG_QtyScrapped())));
                log.Info("@Quantity@ = " + Decimal.Subtract(wo.GetVAMFG_QtyEntered(), Decimal.Add(wo.GetVAMFG_QtyAssembled(), (wo.GetVAMFG_QtyScrapped()))));
            }

            //woTxn.SetVAMFG_QtyEntered(p_Qty.setScale(MUOM.GetPrecision(GetCtx(), woTxn.GetC_UOM_ID()), Decimal.ROUND_HALF_UP));
            woTxn.SetVAMFG_QtyEntered(Decimal.Round((p_Qty), VAdvantage.Model.MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero));
            // Added by Bharat on 20/12/2016 to Set Density and Liter values for production execution Process of Gulf Oil.
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("GOM01_", out mInfo))
            {
                woTxn.SetGOM01_Density(wo.GetGOM01_Density());
                Decimal qtyKg = Decimal.Multiply(wo.GetGOM01_Density(), woTxn.GetVAMFG_QtyEntered());
                woTxn.SetGOM01_Quantity(Decimal.Round((qtyKg), MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero));
            }
            woTxn.Save();

            ViennaAdvantage.Process.MWorkOrderTxnUtil prodTxnLines = new ViennaAdvantage.Process.MWorkOrderTxnUtil(true);
            // Done by Bharat on 24 Jan 2018 to delete lines as when process runs multiple times it creates duplicate lines.
            int no = DB.ExecuteQuery("DELETE FROM VAMFG_M_WrkOdrTrnsctionLine WHERE VAMFG_M_WrkOdrTransaction_ID = " + p_M_WorkOrderTransaction_ID, null, Get_TrxName());

            ViennaAdvantage.Model.MVAMFGMWrkOdrTrnsctionLine[] wotlines = prodTxnLines.GenerateComponentTxnLine(GetCtx(), p_M_WorkOrderTransaction_ID, p_Qty,
                                                                                                                X_VAMFG_M_WorkOrderComponent.VAMFG_SUPPLYTYPE_Push, Get_TrxName());

            if (wotlines != null && wotlines.Length > 0)
            {
                return("Generated " + wotlines.Length + " line(s) for component(s): " + VLogger.RetrieveInfo().GetName());
            }
            else
            {
                return("Generated 0 lines for components.");
            }
        }
Beispiel #13
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="bom">product</param>
 public MBOMProduct(MBOM bom)
     : this(bom.GetCtx(), 0, bom.Get_Trx())
 {
     _bom = bom;
 }
Beispiel #14
0
 /// <summary>
 /// Set component BOM
 /// </summary>
 /// <param name="M_ProductBOMVersion_ID">product ID</param>
 /// <writer>raghu</writer>
 /// <date>08-march-2011</date>
 public new  void SetM_ProductBOMVersion_ID(int M_ProductBOMVersion_ID)
 {
     base.SetM_ProductBOMVersion_ID(M_ProductBOMVersion_ID);
     _componentBOM = null;
 }