Exemplo n.º 1
0
        /**
         *  Before Delete
         *	@return true if it can be deleted
         */
        protected override bool BeforeDelete()
        {
            //	Check Storage
            if (IsStocked() || PRODUCTTYPE_Item.Equals(GetProductType()))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal    OnHand   = Env.ZERO;
                Decimal    Ordered  = Env.ZERO;
                Decimal    Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand   = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered  = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                {
                    errMsg = "@QtyOnHand@ = " + OnHand;
                }
                if (Env.Signum(Ordered) != 0)
                {
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                }
                if (Env.Signum(Reserved) != 0)
                {
                    errMsg += " - @QtyReserved@" + Reserved;
                }
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return(false);
                }
            }
            //	delete costing
            MProductCosting[] costings = MProductCosting.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
            for (int i = 0; i < costings.Length; i++)
            {
                costings[i].Delete(true, Get_TrxName());
            }
            string sql = "DELETE FROM M_Cost WHERE M_Product_ID = " + Get_ID();
            int    no  = DB.ExecuteQuery(sql, null, Get_TrxName());

            if (no < 0)
            {
                return(false);
            }
            return(Delete_Accounting("M_Product_Acct"));
        }
Exemplo n.º 2
0
        /**
         *  Get Costing Of Product
         *	@param ctx context
         *	@param M_Product_ID product
         *	@param trxName trx
         *	@return array of costs
         */
        public static MProductCosting[] GetOfProduct(Ctx ctx, int M_Product_ID, Trx trxName)
        {
            String sql = "SELECT * FROM M_Product_Costing WHERE M_Product_ID=" + M_Product_ID;
            List <MProductCosting> list = new List <MProductCosting>();
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, trxName);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MProductCosting(ctx, dr, trxName));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            MProductCosting[] retValue = new MProductCosting[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Exemplo n.º 3
0
        /**
         *  Get Costing
         *	@param ctx context
         *	@param M_Product_ID product
         *	@param C_AcctSchema_ID as
         *	@param trxName trx
         *	@return array of costs
         */
        public static MProductCosting Get(Ctx ctx, int M_Product_ID,
                                          int C_AcctSchema_ID, Trx trxName)
        {
            MProductCosting retValue = null;
            String          sql      = "SELECT * FROM M_Product_Costing WHERE M_Product_ID=" + M_Product_ID + " AND C_AcctSchema_ID=" + C_AcctSchema_ID;
            DataTable       dt       = null;
            IDataReader     idr      = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, trxName);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MProductCosting(ctx, dr, trxName);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            return(retValue);
        }
Exemplo n.º 4
0
        /**
         *  After Save
         *	@param newRecord new
         *	@param success success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            //	Value/Name change in Account
            if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
            {
                MAccount.UpdateValueDescription(GetCtx(), "M_Product_ID=" + GetM_Product_ID(), Get_TrxName());
            }

            //	Name/Description Change in Asset	MAsset.setValueNameDescription
            if (!newRecord && (Is_ValueChanged("Name") || Is_ValueChanged("Description")))
            {
                //String sql = "UPDATE A_Asset a "
                //    + "SET (Name, Description)="
                //        + "(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60), p.Description "
                //        + "FROM M_Product p, C_BPartner bp "
                //        + "WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID) "
                //    + "WHERE IsActive='Y'"
                //    //	+ " AND GuaranteeDate > SysDate"
                //    + "  AND M_Product_ID=" + GetM_Product_ID();



                String sql = " UPDATE A_Asset a SET Name=(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60) FROM M_Product p, C_BPartner bp  WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)," +
                             "Description=(SELECT  p.Description FROM M_Product p, C_BPartner bp WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)" +
                             "WHERE IsActive='Y'  AND M_Product_ID=" + GetM_Product_ID();

                int no = 0;
                try
                {
                    no = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteQuery(sql, null, Get_TrxName()));
                }
                catch { }
                log.Fine("Asset Description updated #" + no);
            }

            //	New - Acct, Tree, Old Costing
            if (newRecord)
            {
                Insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
                                  "p.M_Product_Category_ID=" + GetM_Product_Category_ID());
                //
                MAcctSchema[] mass = MAcctSchema.GetClientAcctSchema(GetCtx(), GetAD_Client_ID(), Get_TrxName());
                for (int i = 0; i < mass.Length; i++)
                {
                    //	Old
                    MProductCosting pcOld = new MProductCosting(this, mass[i].GetC_AcctSchema_ID());
                    pcOld.Save();
                }
            }

            //	New Costing
            if (newRecord || Is_ValueChanged("M_Product_Category_ID"))
            {
                MCost.Create(this);
            }

            return(success);
        }
        /**
         * 	After Save
         *	@param newRecord new
         *	@param success success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
                return success;

            StringBuilder _sql = new StringBuilder("");
            //_sql.Append("Select count(*) from  ad_table where tablename like 'FRPT_Product_Category_Acct'");
            //_sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name)  = UPPER('FRPT_Product_Category_Acct')  AND OWNER LIKE '" + DB.GetSchema() + "'");
            _sql.Append(DBFunctionCollection.CheckTableExistence(DB.GetSchema(), "FRPT_Product_Category_Acct"));
            int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
            if (count > 0)
            {
                PO obj = null;
                //MFRPTProductAcct obj = null;
                int _MProduct_ID = GetM_Product_ID();
                int _PCategory_ID = GetM_Product_Category_ID();
                string sql = "SELECT L.VALUE FROM AD_REF_LIST L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where   r.name='FRPT_RelatedTo' and l.name='Product'";
                //"select VALUE from AD_Ref_List where name='Product'";
                string _RelatedToProduct = Convert.ToString(DB.ExecuteScalar(sql));
                //string _RelatedToProduct = X_FRPT_AcctDefault.FRPT_RELATEDTO_Product.ToString();

                _sql.Clear();
                _sql.Append("Select Count(*) From FRPT_Product_Acct  where M_Product_ID=" + _MProduct_ID + " AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID());
                int value = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                if (value < 1)
                {
                    _sql.Clear();
                    _sql.Append("Select  PCA.c_acctschema_id, PCA.c_validcombination_id, PCA.frpt_acctdefault_id From FRPT_product_category_acct PCA inner join frpt_acctdefault ACC ON acc.frpt_acctdefault_id= PCA.frpt_acctdefault_id where PCA.m_product_category_id=" + _PCategory_ID + " and acc.frpt_relatedto='" + _RelatedToProduct + "' AND PCA.IsActive = 'Y' AND PCA.AD_Client_ID = " + GetAD_Client_ID());
                    //_sql.Append("Select C_AcctSchema_ID, C_ValidCombination_ID, FRPT_AcctDefault_ID from FRPT_product_category_acct where m_product_category_id =" + _PCategory_ID);

                    DataSet ds = DB.ExecuteDataset(_sql.ToString());
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            //obj = new MFRPTProductAcct(GetCtx(), 0, null);
                            obj = MTable.GetPO(GetCtx(), "FRPT_Product_Acct", 0, null);
                            obj.Set_ValueNoCheck("AD_Org_ID", 0);
                            obj.Set_ValueNoCheck("M_Product_ID", _MProduct_ID);
                            obj.Set_ValueNoCheck("C_AcctSchema_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_AcctSchema_ID"]));
                            obj.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_ValidCombination_ID"]));
                            obj.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"]));
                            if (!obj.Save())
                            { }
                        }
                    }
                }
                // Change by mohit amortization process
                //int _CountVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_'  AND IsActive = 'Y'"));
                //if (_CountVA038 > 0)
                //{
                //    if (GetProductType() == "E" || GetProductType() == "S")
                //    {
                //        if (Util.GetValueOfInt(Get_Value("VA038_AmortizationTemplate_ID")) > 0)
                //        {
                //            DataSet _dsAcct = DB.ExecuteDataset("SELECT C_AcctSchema_ID, FRPT_AcctDefault_ID, C_VALIDCOMBINATION_ID, SEQNO FROM VA038_Amortization_Acct "
                //                              + "WHERE IsActive='Y' AND  VA038_AmortizationTemplate_ID=" + Util.GetValueOfInt(Get_Value("VA038_AmortizationTemplate_ID")));
                //            if (_dsAcct != null && _dsAcct.Tables[0].Rows.Count > 0)
                //            {
                //                for (int j = 0; j < _dsAcct.Tables[0].Rows.Count; j++)
                //                {
                //                    obj = MTable.GetPO(GetCtx(), "FRPT_Product_Acct", 0, null);
                //                    obj.Set_ValueNoCheck("AD_Org_ID", 0);
                //                    obj.Set_ValueNoCheck("M_Product_ID", _MProduct_ID);
                //                    obj.Set_ValueNoCheck("C_AcctSchema_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["C_AcctSchema_ID"]));
                //                    obj.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["C_ValidCombination_ID"]));
                //                    obj.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(_dsAcct.Tables[0].Rows[j]["FRPT_AcctDefault_ID"]));
                //                    if (!obj.Save())
                //                    { }
                //                }
                //            }
                //        }
                //    }
                //}
                // End amortization process
            }
            else
            {
                // By Amit
                //if (!success)
                //    return success;

                //	Value/Name change in Account
                if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
                    MAccount.UpdateValueDescription(GetCtx(), "M_Product_ID=" + GetM_Product_ID(), Get_TrxName());

                //	Name/Description Change in Asset	MAsset.setValueNameDescription
                if (!newRecord && (Is_ValueChanged("Name") || Is_ValueChanged("Description")))
                {
                    String sql = " UPDATE A_Asset a SET Name=(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60) FROM M_Product p, C_BPartner bp  WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)," +
              "Description=(SELECT  p.Description FROM M_Product p, C_BPartner bp WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)" +
              "WHERE IsActive='Y'  AND M_Product_ID=" + GetM_Product_ID();

                    int no = 0;
                    try
                    {
                        no = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteQuery(sql, null, Get_TrxName()));
                    }
                    catch { }
                    log.Fine("Asset Description updated #" + no);
                }
                //	New - Acct, Tree, Old Costing
                if (newRecord)
                {
                    if (String.IsNullOrEmpty(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) || Util.GetValueOfString(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) == "Y")
                    {
                        bool sucs = Insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
                              "p.M_Product_Category_ID=" + GetM_Product_Category_ID());

                        //Karan. work done to show message if data not saved in accounting tab. but will save data in current tab.
                        // Before this, data was being saved but giving message "record not saved".
                        if (!sucs)
                        {
                            log.SaveWarning("AcctNotSaved", "");
                        }
                    }

                    //
                    MAcctSchema[] mass = MAcctSchema.GetClientAcctSchema(GetCtx(), GetAD_Client_ID(), Get_TrxName());
                    for (int i = 0; i < mass.Length; i++)
                    {
                        //	Old
                        MProductCosting pcOld = new MProductCosting(this, mass[i].GetC_AcctSchema_ID());
                        pcOld.Save();
                    }
                }
                //	New Costing
                // by Amit 22-12-2015
                //if (newRecord || Is_ValueChanged("M_Product_Category_ID"))
                //{
                //    MCost.Create(this);
                //}
            }

            //22-12-2015
            //by Amit for creating records ffor product foe all Costing Element whose costing elemnt type is 'Material'
            //if (newRecord || Is_ValueChanged("M_Product_Category_ID"))
            //{
            //    MCost.CreateRecords(this);
            //}
            //20-12-2016
            //By Vivek Chauhan saving Nutrition value against product...........
            object ModuleId = DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VA019_' and isactive='Y'");
            if (ModuleId != null && ModuleId != DBNull.Value)
            {
                object objNDBNo = DB.ExecuteScalar("select va019_ndbno from M_Product where m_product_ID=" + GetM_Product_ID() + "");
                if (objNDBNo != null && objNDBNo != DBNull.Value)
                {
                    CallNutritionApi(Convert.ToString(objNDBNo), GetM_Product_ID());
                }
            }
            return success;
        }