示例#1
0
        protected override String DoIt()
        {
            VAdvantage.Model.X_C_Lead lead = new VAdvantage.Model.X_C_Lead(GetCtx(), _C_Lead_ID, Get_Trx());
            if (!(R_InterestArea_ID > 0))
            {
                return(Msg.GetMsg(GetCtx(), "NoInterestAreaIsSelected"));
            }

            if (lead.GetC_BPartner_ID() != 0)
            {
                VAdvantage.Model.X_R_ContactInterest customer = new VAdvantage.Model.X_R_ContactInterest(GetCtx(), 0, Get_Trx());
                customer.SetR_InterestArea_ID(R_InterestArea_ID);
                customer.SetC_BPartner_ID(lead.GetC_BPartner_ID());
                String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + lead.GetC_BPartner_ID();
                int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query));
                customer.SetAD_User_ID(UserId);
                query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + lead.GetC_BPartner_ID();

                int Id = Util.GetValueOfInt(DB.ExecuteScalar(query));
                VAdvantage.Model.X_C_BPartner_Location loc = new VAdvantage.Model.X_C_BPartner_Location(GetCtx(), Id, Get_Trx());
                customer.SetC_BPartner_Location_ID(Id);
                customer.SetPhone(loc.GetPhone());
                customer.SetFax(loc.GetFax());

                VAdvantage.Model.X_AD_User us = new VAdvantage.Model.X_AD_User(GetCtx(), UserId, Get_Trx());
                customer.SetC_Job_ID(us.GetC_Job_ID());
                customer.SetSubscribeDate(DateTime.Today);
                query = "Select Email from ad_user where ad_user_id= " + UserId;
                String mail = Util.GetValueOfString(DB.ExecuteScalar(query));
                customer.SetEMail(mail);
                if (!customer.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(customer.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
            else if (lead.GetRef_BPartner_ID() != 0)
            {
                VAdvantage.Model.X_R_ContactInterest Prospect = new VAdvantage.Model.X_R_ContactInterest(GetCtx(), 0, Get_Trx());
                Prospect.SetR_InterestArea_ID(R_InterestArea_ID);
                Prospect.SetC_BPartner_ID(lead.GetRef_BPartner_ID());
                String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + lead.GetRef_BPartner_ID();
                int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query));
                Prospect.SetAD_User_ID(UserId);
                query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + lead.GetRef_BPartner_ID();

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

                VAdvantage.Model.X_AD_User us = new VAdvantage.Model.X_AD_User(GetCtx(), UserId, Get_Trx());
                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));
                Prospect.SetEMail(mail);
                if (!Prospect.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(Prospect.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
            else
            {
                VAdvantage.Model.X_vss_lead_interestarea Ilead = new VAdvantage.Model.X_vss_lead_interestarea(GetCtx(), 0, Get_Trx());
                Ilead.SetC_Lead_ID(lead.GetC_Lead_ID());
                Ilead.SetR_InterestArea_ID(R_InterestArea_ID);
                Ilead.SetAD_User_ID(lead.GetAD_User_ID());
                Ilead.SetBPName(lead.GetBPName());
                Ilead.SetEMail(lead.GetEMail());
                Ilead.SetPhone(lead.GetPhone());
                Ilead.SetFax(lead.GetFax());
                Ilead.SetAddress1(lead.GetAddress1());
                Ilead.SetAddress2(lead.GetAddress2());
                Ilead.SetC_City_ID(lead.GetC_City_ID());
                Ilead.SetCity(lead.GetCity());
                Ilead.SetC_Region_ID(lead.GetC_Region_ID());
                Ilead.SetRegionName(lead.GetRegionName());
                Ilead.SetC_Country_ID(lead.GetC_Country_ID());
                Ilead.SetPostal(lead.GetPostal());
                Ilead.SetSubscribeDate(DateTime.Today);
                if (!Ilead.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(Ilead.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
        }
        protected override String DoIt()
        {
            VAdvantage.Model.X_C_Lead lead = new VAdvantage.Model.X_C_Lead(GetCtx(), _C_Lead_ID, Get_TrxName());
            //  lead.GetRef_BPartner_ID()))
            int ExCustomer = lead.GetC_BPartner_ID();
            int Pospect    = lead.GetRef_BPartner_ID();



            if (ExCustomer != 0)
            {
                VAdvantage.Model.X_C_Project opp = new VAdvantage.Model.X_C_Project(GetCtx(), 0, Get_TrxName());
                opp.SetC_Lead_ID(lead.GetC_Lead_ID());
                opp.SetC_BPartner_ID(lead.GetC_BPartner_ID());
                opp.SetSalesRep_ID(lead.GetSalesRep_ID());
                opp.SetDateContract(DateTime.Today);
                opp.SetC_Campaign_ID(lead.GetC_Campaign_ID());
                //opp.SetR_Source_ID (lead.GetR_Source_ID());
                // opp.SetOpportunityStatus("N");
                opp.SetAD_User_ID(lead.GetAD_User_ID());
                VAdvantage.Model.X_C_BPartner          bp  = new VAdvantage.Model.X_C_BPartner(GetCtx(), ExCustomer, Get_TrxName());
                VAdvantage.Model.X_C_BPartner_Location loc = new VAdvantage.Model.X_C_BPartner_Location(GetCtx(), ExCustomer, Get_TrxName());

                opp.SetName(bp.GetName());;
                opp.SetC_BPartner_Location_ID(loc.GetC_BPartner_Location_ID());
                opp.SetIsOpportunity(true);

                if (opp.Save())
                {
                    lead.SetC_Project_ID(opp.GetC_Project_ID());
                    lead.Save();
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateDone"));
                }
                else
                {
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
                }
            }
            if (Pospect != 0)
            {
                VAdvantage.Model.X_C_Project opp = new VAdvantage.Model.X_C_Project(GetCtx(), 0, Get_TrxName());
                opp.SetC_Lead_ID(lead.GetC_Lead_ID());
                opp.SetC_BPartnerSR_ID(lead.GetRef_BPartner_ID());
                opp.SetSalesRep_ID(lead.GetSalesRep_ID());
                opp.SetDateContract(DateTime.Today);
                opp.SetC_Campaign_ID(lead.GetC_Campaign_ID());
                // opp.SetR_Source_ID (lead.GetR_Source_ID());
                //opp.SetOpportunityStatus ("N");
                // opp.SetAD_Client_ID(GetAD_Client_ID());
                opp.SetAD_User_ID(lead.GetAD_User_ID());
                VAdvantage.Model.X_C_BPartner bp = new VAdvantage.Model.X_C_BPartner(GetCtx(), Pospect, Get_TrxName());
                //X_C_BPartner_Location loc = new X_C_BPartner_Location(GetCtx(), Pospect, Get_TrxName());

                opp.SetName(bp.GetName());
                opp.SetC_BPartner_Location_ID(lead.GetC_BPartner_Location_ID());
                opp.SetIsOpportunity(true);

                if (opp.Save())
                {
                    lead.SetC_Project_ID(opp.GetC_Project_ID());
                    lead.Save();
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateDone"));
                }
                else
                {
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
                }
            }
            if (ExCustomer == 0 && Pospect == 0)
            {
                //CallProcess(_C_Lead_ID);
                callprospect();
                return(DoIt());
            }

            return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
        }