Example #1
0
        public String callprospect()
        {
            log.Info("C_Lead_ID=" + _C_Lead_ID);
            if (_C_Lead_ID == 0)
            {
                throw new Exception("@C_Lead_ID@ ID=0");
            }
            VAdvantage.Model.MLead lead = new VAdvantage.Model.MLead(GetCtx(), _C_Lead_ID, Get_TrxName());
            if (lead.Get_ID() != _C_Lead_ID)
            {
                throw new Exception("@NotFound@: @C_Lead_ID@ ID=" + _C_Lead_ID);
            }
            //
            String retValue = lead.CreateBP();

            if (retValue != null)
            {
                throw new SystemException(retValue);
            }
            lead.Save();
            //
            VAdvantage.Model.MBPartner bp = lead.GetBPartner();
            if (bp != null)
            {
                return("@C_BPartner_ID@: " + bp.GetName());
            }
            VAdvantage.Model.MUser user = lead.GetUser();
            if (user != null)
            {
                return("@AD_User_ID@: " + user.GetName());
            }
            return("@SaveError@");
        }       //	doIt
Example #2
0
        } //prepare

        protected override String DoIt()
        {
            int value = 0;

            VAdvantage.Model.MBPartner bp = new VAdvantage.Model.MBPartner(GetCtx(), C_Bpartner_ID, Get_TrxName());
            //BPartner.SetC_Greeting_ID(
            String sqlbp = "update c_bpartner set iscustomer='Y', isprospect='N' where c_bpartner_id=" + C_Bpartner_ID + "";

            value = DB.ExecuteQuery(sqlbp, null, Get_TrxName());
            if (value == -1)
            {
            }
            //bp.SetIsCustomer(true);
            //bp.SetIsProspect(false);

            return(Msg.GetMsg(GetCtx(), "AccountGenerated"));
        }
Example #3
0
        protected override string DoIt()
        {
            // Int32 value = 0;
            string msg = "";

            log.Info("C_Project_ID=" + _C_Project_ID);
            if (_C_Project_ID == 0)
            {
                throw new ArgumentException("C_Project_ID == 0");
            }

            VAdvantage.Model.MProject fromProject = new VAdvantage.Model.MProject(GetCtx(), _C_Project_ID, null);

            if (fromProject.GetGenerate_Quotation() == null)
            {
                throw new ArgumentException("No Generate Quotation found on Project.");
            }
            if (fromProject.GetGenerate_Quotation().Trim() == "Y")
            {
                throw new ArgumentException("Sales Quotation already generated");
            }
            VAdvantage.Model.MOrder order = new VAdvantage.Model.MOrder(GetCtx(), 0, null);
            C_Bpartner_id          = fromProject.GetC_BPartner_ID();
            C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID();
            C_BPartnerSR_ID        = fromProject.GetC_BPartnerSR_ID();
            //MBPartner bp = new MBPartner(GetCtx(), C_Bpartner_id, null);
            VAdvantage.Model.MBPartnerLocation bpartnerloc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, null);
            String currentdate = DateTime.Now.ToString();
            String sqlprjln    = " select c_projectline_id from c_projectline where c_project_id=" + _C_Project_ID + "";

            C_ProjectLine_ID = VAdvantage.Utility.Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln));
            if (C_ProjectLine_ID != 0)
            {
                order.SetDateOrdered(Convert.ToDateTime(currentdate));
                order.SetDatePromised(Convert.ToDateTime(currentdate));
                if (C_Bpartner_id != 0)
                {
                    order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID());
                    if (bpartnerloc.IsShipTo() == true)
                    {
                        order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID());
                        order.SetAD_User_ID(fromProject.GetAD_User_ID());
                    }
                    if (bpartnerloc.IsBillTo() == true)
                    {
                        order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID());
                        order.SetBill_User_ID(fromProject.GetAD_User_ID());
                    }
                }
                if (C_BPartnerSR_ID != 0)
                {
                    //String sqlcust = "update c_bpartner set iscustomer='Y', isprospect='N' where c_bpartner_id=" + C_BPartnerSR_ID + "";
                    //value = DB.ExecuteQuery(sqlcust, null, null);
                    //if (value == -1)
                    //{

                    //}
                    //bp.SetIsCustomer(true);
                    //bp.SetIsProspect(false);

                    order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID());
                    if (bpartnerloc.IsShipTo() == true)
                    {
                        order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID());
                        order.SetAD_User_ID(fromProject.GetAD_User_ID());
                    }
                    if (bpartnerloc.IsBillTo() == true)
                    {
                        order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID());
                        order.SetBill_User_ID(fromProject.GetAD_User_ID());
                    }
                }
                // String sql = "select c_doctype_id from c_doctype where docbasetype= 'SOO' and  = 'Sales Quotation'";
                String sql           = "select c_doctype_id from c_doctype where docbasetype = 'SOO' and docsubtypeso = 'ON' and isreturntrx = 'N' and ad_client_id = " + GetCtx().GetAD_Client_ID();
                int    Doctype_id    = VAdvantage.Utility.Util.GetValueOfInt(DB.ExecuteScalar(sql));
                int    MPriceList_id = Util.GetValueOfInt(fromProject.GetM_PriceList_ID());
                order.SetM_PriceList_ID(MPriceList_id);
                ////String sqlmpricelist = "select m_pricelist_id from m_pricelist where name='Export'";
                ////int MPriceList_id = VAdvantage.Utility.Util.GetValueOfInt(DB.ExecuteScalar(sqlmpricelist));
                //if (MPriceList_id == order.GetM_PriceList_ID())
                //{
                //    String sqlconversiontype = "select c_conversiontype_id from c_conversiontype where value = 'C'";
                //    int C_ConversionType_id = VAdvantage.Utility.Util.GetValueOfInt(DB.ExecuteScalar(sqlconversiontype));
                //    order.SetC_ConversionType_ID(C_ConversionType_id);
                //}
                order.SetC_Project_ID(GetRecord_ID());
                if (fromProject.GetSalesRep_ID() > 0)
                {
                    order.SetSalesRep_ID(fromProject.GetSalesRep_ID());
                }
                order.SetC_Currency_ID(fromProject.GetC_Currency_ID());
                if (C_Bpartner_id != 0)
                {
                    VAdvantage.Model.MBPartner bp = new VAdvantage.Model.MBPartner(GetCtx(), C_Bpartner_id, null);
                    if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0)
                    {
                        bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID());
                    }
                    bp.SetAD_Client_ID(fromProject.GetAD_Client_ID());
                    bp.SetAD_Org_ID(fromProject.GetAD_Org_ID());
                    if (bp.GetC_PaymentTerm_ID() != 0)
                    {
                        order.SetPaymentMethod(bp.GetPaymentRule());
                        order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID());
                    }

                    if (!bp.Save())
                    {
                        log.SaveError("CampaignIDNotSaved", "");
                        return(Msg.GetMsg(GetCtx(), "CampaignIDtNotSaved"));
                    }
                }
                else
                {
                    VAdvantage.Model.MBPartner bp = new VAdvantage.Model.MBPartner(GetCtx(), C_BPartnerSR_ID, null);
                    if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0)
                    {
                        bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID());
                    }
                    bp.SetAD_Client_ID(fromProject.GetAD_Client_ID());
                    bp.SetAD_Org_ID(fromProject.GetAD_Org_ID());
                    if (bp.GetC_PaymentTerm_ID() != 0)
                    {
                        order.SetPaymentMethod(bp.GetPaymentRule());
                        order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID());
                    }

                    if (!bp.Save())
                    {
                        log.SaveError("CampaignIDtNotSaved", "");
                        return(Msg.GetMsg(GetCtx(), "CampaignIDtNotSaved"));
                    }
                }
                //if (bp.GetC_PaymentTerm_ID() != 0)
                //{
                //    order.SetPaymentMethod(bp.GetPaymentRule());
                //    order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID());

                //}
                order.SetFreightCostRule("I");
                if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0)
                {
                    order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID());
                }
                order.SetDocStatus("IP");
                order.SetC_DocType_ID(Doctype_id);
                order.SetC_DocTypeTarget_ID(Doctype_id);
                order.SetIsSOTrx(true);
                if (!order.Save())
                {
                    log.SaveError("SaleOrdertNotSaved", "");
                    return(Msg.GetMsg(GetCtx(), "SaleOrdertNotSaved"));
                }
                //Order Lines
                int count = 0;
                VAdvantage.Model.MProjectLine[] lines = fromProject.GetLines();
                for (int i = 0; i < lines.Length; i++)
                {
                    VAdvantage.Model.MOrderLine ol = new VAdvantage.Model.MOrderLine(order);
                    ol.SetLine(lines[i].GetLine());
                    ol.SetDescription(lines[i].GetDescription());
                    ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true);
                    ol.SetQtyEntered(lines[i].GetPlannedQty());
                    ol.SetQtyOrdered(lines[i].GetPlannedQty());
                    ol.SetPriceEntered(lines[i].GetPlannedPrice());
                    ol.SetPriceActual(lines[i].GetPlannedPrice());
                    ol.SetPriceList(lines[i].GetPriceList());
                    if (ol.Save())
                    {
                        count++;
                    }
                }

                fromProject.SetRef_Order_ID(order.GetC_Order_ID());
                fromProject.SetGenerate_Quotation("Y");
                if (!fromProject.Save())
                {
                    log.SaveError("ProjectNotSaved", "");
                    return(Msg.GetMsg(GetCtx(), "ProjectNotSaved"));;
                }
                msg = Msg.GetMsg(GetCtx(), "QuotationGenerated");
            }
            else
            {
                msg = Msg.GetMsg(GetCtx(), "No Lines");
            }
            return(msg);
        }
Example #4
0
        protected override String DoIt()
        {
            if (S_Resource_id == 0)
            {
                throw new ArgumentException("C_Project_ID == 0");
            }
            VAdvantage.Model.MResource Resource = new VAdvantage.Model.MResource(GetCtx(), S_Resource_id, Get_Trx());
            string sql         = "select ProfileType from s_resource where s_resource_id=" + S_Resource_id + "";
            string ProfileType = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sql));

            VAdvantage.Model.X_AD_User user = new VAdvantage.Model.X_AD_User(GetCtx(), 0, Get_Trx());
            VAdvantage.Model.MBPartner bp   = new VAdvantage.Model.MBPartner(GetCtx(), C_Bpartner_ID, Get_Trx());
            if (ProfileType == "")
            {
                return(Msg.GetMsg(GetCtx(), "ProfileTypeNotSelected"));
            }
            else
            {
                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BP_Group_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "ResourceNotSelected"));
                }

                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_Role_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "RoleNotSelected"));
                }
                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_Location_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "AddressNotSelected"));
                }
                if (ProfileType == "I")
                {
                    if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) == 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from c_bpartner where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            bp.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            bp.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            bp.SetIsEmployee(true);
                            bp.SetName(Resource.GetName());
                            bp.SetEMail(Resource.GetEMail());
                            bp.SetMobile(Resource.GetMobile());
                            bp.SetC_Location_ID(Resource.GetC_Location_ID());
                            bp.SetC_BP_Group_ID(Resource.GetC_BP_Group_ID());
                            if (!bp.Save())
                            {
                                log.SaveError("BusinessPartnerNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerNotSaved"));
                            }

                            VAdvantage.Model.MBPartnerLocation bploc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), 0, Get_Trx());
                            bploc.SetAD_Client_ID(bp.GetAD_Client_ID());
                            bploc.SetAD_Org_ID(bp.GetAD_Org_ID());
                            bploc.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            bploc.SetPhone(Resource.GetMobile());
                            bploc.SetC_Location_ID(Resource.GetC_Location_ID());

                            if (!bploc.Save())
                            {
                                log.SaveError("BusinessPartnerLocationNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerLocationNotSaved,"));
                            }
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "BPNotSaved," + Resource.GetName() + "AlreadyExists!"));
                        }

                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }
                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                    else if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) != 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(Resource.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            //GenratePassword(usrname);
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                }
                else if (ProfileType == "E")
                {
                    if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) == 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from c_bpartner where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            bp.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            bp.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            bp.SetIsVendor(true);
                            bp.SetName(Resource.GetName());
                            bp.SetEMail(Resource.GetEMail());
                            bp.SetMobile(Resource.GetMobile());
                            bp.SetC_Location_ID(Resource.GetC_Location_ID());
                            //if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BP_Group_ID()) == 0)
                            // {
                            //  return Msg.GetMsg(GetCtx(), "plzselectresource");
                            // }
                            // else
                            // {
                            bp.SetC_BP_Group_ID(Resource.GetC_BP_Group_ID());
                            // }
                            if (!bp.Save())
                            {
                                log.SaveError("BusinessPartnerNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerNotSaved"));
                            }

                            VAdvantage.Model.MBPartnerLocation bploc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), 0, Get_Trx());
                            bploc.SetAD_Client_ID(bp.GetAD_Client_ID());
                            bploc.SetAD_Org_ID(bp.GetAD_Org_ID());
                            bploc.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            bploc.SetPhone(Resource.GetMobile());

                            // if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_Location_ID()) == 0)
                            // {
                            //     return Msg.GetMsg(GetCtx(), "Plz enter Address");
                            // }
                            // else
                            //{
                            bploc.SetC_Location_ID(Resource.GetC_Location_ID());
                            //}

                            if (!bploc.Save())
                            {
                                log.SaveError("BusinessPartnerLocationNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerLocationNotSaved,"));
                            }
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "BPNotSaved," + Resource.GetName() + "AlreadyExists!"));
                        }

                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            user.SetName(Resource.GetName());
                            user.SetEMail(Resource.GetEMail());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                    else if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) != 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(Resource.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                }
            }
            if (bp != null)
            {
                if (Util.GetValueOfInt(bp.GetC_BPartner_ID()) != 0)
                {
                    Resource.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                }
            }
            if (user != null)
            {
                if (Util.GetValueOfInt(user.GetAD_User_ID()) != 0)
                {
                    Resource.SetAD_User_ID(user.GetAD_User_ID());
                }
            }
            if (!Resource.Save())
            {
                log.SaveError("ResourceNotSaved", "");
                return(Msg.GetMsg(GetCtx(), "ResourceNotSaved"));
            }



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