Exemple #1
0
 /// <summary>
 /// Get BP Group
 /// </summary>
 /// <param name="group">group</param>
 public void SetBPGroup(MBPGroup group)
 {
     _group = group;
     if (_group == null)
     {
         return;
     }
     SetC_BP_Group_ID(_group.GetC_BP_Group_ID());
     if (_group.GetC_Dunning_ID() != 0)
     {
         SetC_Dunning_ID(_group.GetC_Dunning_ID());
     }
     if (_group.GetM_PriceList_ID() != 0)
     {
         SetM_PriceList_ID(_group.GetM_PriceList_ID());
     }
     if (_group.GetPO_PriceList_ID() != 0)
     {
         SetPO_PriceList_ID(_group.GetPO_PriceList_ID());
     }
     if (_group.GetM_DiscountSchema_ID() != 0)
     {
         SetM_DiscountSchema_ID(_group.GetM_DiscountSchema_ID());
     }
     if (_group.GetPO_DiscountSchema_ID() != 0)
     {
         SetPO_DiscountSchema_ID(_group.GetPO_DiscountSchema_ID());
     }
 }
Exemple #2
0
        /**
         *  Get Default MBPGroup
         *	@param ctx context
         *	@return MBPGroup
         */
        public static MBPGroup GetDefault(Ctx ctx)
        {
            int      AD_Client_ID = ctx.GetAD_Client_ID();
            int      key          = AD_Client_ID;
            MBPGroup retValue     = (MBPGroup)_cacheDefault[key];

            if (retValue != null)
            {
                return(retValue);
            }

            DataTable dt  = null;
            String    sql = "SELECT * FROM C_BP_Group g "
                            + "WHERE IsDefault='Y' AND AD_Client_ID= " + AD_Client_ID
                            + " ORDER BY IsActive DESC";
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();

                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MBPGroup(ctx, dr, null);
                    if (retValue.Get_ID() != 0)
                    {
                        _cacheDefault.Add(key, retValue);
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            if (retValue == null)
            {
                _log.Warning("No Default BP Group for AD_Client_ID=" + AD_Client_ID);
            }
            return(retValue);
        }
Exemple #3
0
 /// <summary>
 /// Before Save
 /// </summary>
 /// <param name="newRecord">new</param>
 /// <returns>true</returns>
 protected override bool BeforeSave(bool newRecord)
 {
     if (newRecord || Is_ValueChanged("C_BP_Group_ID"))
     {
         MBPGroup grp = GetBPGroup();
         if (grp == null)
         {
             log.SaveWarning("Error", Msg.ParseTranslation(GetCtx(), "@NotFound@:  @C_BP_Group_ID@"));
             return(false);
         }
         SetBPGroup(grp);        //	setDefaults
     }
     return(true);
 }
Exemple #4
0
 /// <summary>
 /// Get BP Group
 /// </summary>
 /// <returns>group</returns>
 public MBPGroup GetBPGroup()
 {
     if (_group == null)
     {
         if (GetC_BP_Group_ID() == 0)
         {
             _group = MBPGroup.GetDefault(GetCtx());
         }
         else
         {
             _group = MBPGroup.Get(GetCtx(), GetC_BP_Group_ID());
         }
     }
     return(_group);
 }
Exemple #5
0
        /**
         *  Get MBPGroup from Cache
         *	@param ctx context
         *	@param C_BP_Group_ID id
         *	@return MBPGroup
         */
        public static MBPGroup Get(Ctx ctx, int C_BP_Group_ID)
        {
            int      key      = C_BP_Group_ID;
            MBPGroup retValue = (MBPGroup)_cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MBPGroup(ctx, C_BP_Group_ID, null);
            if (retValue.Get_ID() != 0)
            {
                _cache.Add(key, retValue);
            }
            return(retValue);
        }
Exemple #6
0
        /**
         *  Get MBPGroup from Business Partner
         *	@param ctx context
         *	@param C_BPartner_ID business partner id
         *	@return MBPGroup
         */
        public static MBPGroup GetOfBPartner(Ctx ctx, int C_BPartner_ID)
        {
            MBPGroup  retValue = null;
            DataTable dt       = null;
            String    sql      = "SELECT * FROM C_BP_Group g "
                                 + "WHERE EXISTS (SELECT * FROM C_BPartner p "
                                 + "WHERE p.C_BPartner_ID=" + C_BPartner_ID + " AND p.C_BP_Group_ID=g.C_BP_Group_ID)";
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MBPGroup(ctx, dr, null);
                    int key = retValue.GetC_BP_Group_ID();
                    if (retValue.Get_ID() != 0)
                    {
                        _cache.Add(key, retValue);
                    }
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            return(retValue);
        }
Exemple #7
0
        /**
         *  Create BP, Contact, Location from Lead
         *	@return error message
         */
        public String CreateBP()
        {
            if (GetC_BPartner_ID() != 0 && GetAD_User_ID() != 0 && GetC_BPartner_Location_ID() == 0)
            {
                return("@AlreadyExists@: @C_BPartner_ID@ (ID=" + GetC_BPartner_ID() + ")");
            }

            //	BPartner
            if (GetC_BPartner_ID() == 0 &&
                (GetBPName() != null && GetBPName().Length > 0))
            {
                //	Existing User
                _user = GetUser();
                if (_user != null)
                {
                    if (_user.GetC_BPartner_ID() != 0)
                    {
                        SetRef_BPartner_ID(_user.GetC_BPartner_ID());
                        log.Info("Set to BPartner of User - " + _user);
                        return(CreateBPLocation());
                    }
                }
                //
                _bp = new MBPartner(GetCtx(), Get_TrxName());   //	Template
                _bp.SetAD_Org_ID(GetAD_Org_ID());
                //_bp.SetValue(GetBPName());
                _bp.SetName(GetBPName());
                _bp.SetIsCustomer(false);
                _bp.SetIsProspect(true);
                _bp.SetSOCreditStatus("O");
                // Check Removed as per Surya Sir's Decision BY Lokesh

                //_bp.SetC_Campaign_ID(GetC_Campaign_ID());
                //
                if (GetC_BP_Group_ID() == 0)
                {
                    // ShowMessage.Info("First Select Customer Group Then process again", true, null, null);
                    return(null);
                }
                else
                {
                    _bp.SetC_BP_Group_ID(GetC_BP_Group_ID());
                }
                MBPGroup gp = new MBPGroup(GetCtx(), GetC_BP_Group_ID(), Get_TrxName());
                _bp.SetM_PriceList_ID(gp.GetM_PriceList_ID());
                if (GetC_BP_Size_ID() != 0)
                {
                    _bp.SetC_BP_Size_ID(GetC_BP_Size_ID());
                }
                if (GetURL() != null)
                {
                    _bp.SetURL(GetURL());
                }
                if (GetC_BP_Status_ID() != 0)
                {
                    _bp.SetC_BP_Status_ID(GetC_BP_Status_ID());
                }
                if (GetC_IndustryCode_ID() != 0)
                {
                    _bp.SetC_IndustryCode_ID(GetC_IndustryCode_ID());
                }
                if (GetNAICS() != null)
                {
                    _bp.SetNAICS(GetNAICS());
                }
                if (GetDUNS() != null)
                {
                    _bp.SetDUNS(GetDUNS());
                }
                if (GetNumberEmployees() != 0)
                {
                    _bp.SetNumberEmployees(GetNumberEmployees());
                }
                if (GetSalesVolume() != 0)
                {
                    _bp.SetSalesVolume(GetSalesVolume());
                }
                if (GetSalesRep_ID() != 0)
                {
                    _bp.SetSalesRep_ID(GetSalesRep_ID());
                }
                if (GetC_Campaign_ID() != 0)
                {
                    _bp.SetC_Campaign_ID(GetC_Campaign_ID());
                }
                if (!_bp.Save())
                {
                    return("@SaveError@");
                }
                //	Update User
                if (_user != null && _user.GetC_BPartner_ID() == 0)
                {
                    _user.SetC_BPartner_ID(_bp.GetC_BPartner_ID());
                    _user.Save();
                }
                //	Save BP
                SetRef_BPartner_ID(_bp.GetC_BPartner_ID());
            }

            String error = CreateBPContact();

            if (error != null && error.Length > 0)
            {
                return(error);
            }
            CreateBPLocation();

            try
            {
                int    id    = _bp.GetC_BPartner_ID();
                string qry   = "Update c_bpartner set Description='' where c_bpartner_id=" + id;
                int    check = DB.ExecuteQuery(qry, null, Get_TrxName());
                string val   = _bp.GetValue();
                qry   = "Update c_bpartner set Value='" + val + GetBPName() + "' where c_bpartner_id=" + id;
                check = DB.ExecuteQuery(qry, null, Get_TrxName());

                if (GetR_InterestArea_ID() != 0)
                {
                    string      sql = "Select R_InterestArea_ID from vss_lead_interestarea where C_Lead_ID=" + GetC_Lead_ID();
                    IDataReader dr  = DB.ExecuteReader(sql, null, Get_TrxName());
                    while (dr.Read())
                    {
                        X_R_ContactInterest Prospect = new X_R_ContactInterest(GetCtx(), 0, Get_TrxName());
                        Prospect.SetR_InterestArea_ID(Util.GetValueOfInt(dr[0]));
                        Prospect.SetC_BPartner_ID(GetRef_BPartner_ID());
                        String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + GetRef_BPartner_ID();
                        int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query, null, Get_TrxName()));
                        Prospect.SetAD_User_ID(UserId);
                        query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + GetRef_BPartner_ID();

                        int Id = Util.GetValueOfInt(DB.ExecuteScalar(query, null, Get_TrxName()));
                        X_C_BPartner_Location loc = new X_C_BPartner_Location(GetCtx(), Id, Get_TrxName());
                        Prospect.SetC_BPartner_Location_ID(Id);
                        Prospect.SetPhone(loc.GetPhone());
                        Prospect.SetFax(loc.GetFax());

                        X_AD_User us = new X_AD_User(GetCtx(), UserId, Get_TrxName());
                        Prospect.SetC_Job_ID(us.GetC_Job_ID());
                        Prospect.SetSubscribeDate(DateTime.Today);
                        query = "Select Email from ad_user where ad_user_id= " + UserId;
                        String mail = Util.GetValueOfString(DB.ExecuteScalar(query, null, Get_TrxName()));
                        Prospect.SetEMail(mail);
                        if (Prospect.Save())
                        {
                        }
                    }
                    dr.Close();
                }
            }
            catch
            {
            }

            return(null);
        }