Exemplo n.º 1
0
        protected override String DoIt()
        {
            string      Sql = "Select C_Lead_ID From C_Lead where SalesRep_ID=" + FromSalesRep_ID + " and isactive='Y' and Ad_Org_id=" + GetCtx().GetAD_Org_ID();
            IDataReader dr  = DB.ExecuteReader(Sql);

            try
            {
                while (dr.Read())
                {
                    VAdvantage.Model.X_C_Lead lead = new VAdvantage.Model.X_C_Lead(GetCtx(), Util.GetValueOfInt(dr[0]), null);
                    lead.SetSalesRep_ID(ToSalesRep_ID);
                    lead.Save();
                    {
                    }
                }

                dr.Close();

                Sql = "Select C_Project_ID From C_Project where SalesRep_ID=" + FromSalesRep_ID + " and isactive='Y' and Ad_Org_id=" + GetCtx().GetAD_Org_ID();
                dr  = DB.ExecuteReader(Sql);
                while (dr.Read())
                {
                    VAdvantage.Model.X_C_Project Project = new VAdvantage.Model.X_C_Project(GetCtx(), Util.GetValueOfInt(dr[0]), null);
                    Project.SetSalesRep_ID(ToSalesRep_ID);
                    Project.Save();
                    {
                    }
                }
                dr.Close();

                Sql = "Select C_BPartner_ID From C_BPartner where SalesRep_ID=" + FromSalesRep_ID + " and isactive='Y' and Ad_Org_id=" + GetCtx().GetAD_Org_ID();
                dr  = DB.ExecuteReader(Sql);
                while (dr.Read())
                {
                    VAdvantage.Model.X_C_BPartner BP = new VAdvantage.Model.X_C_BPartner(GetCtx(), Util.GetValueOfInt(dr[0]), null);
                    BP.SetSalesRep_ID(ToSalesRep_ID);
                    BP.Save();
                    {
                    }
                }
                dr.Close();
                return(Msg.GetMsg(GetCtx(), "RecordsTransferedSuccessfully"));;
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
                return(Msg.GetMsg(GetCtx(), "RecordsnotTransfered"));;
            }
        }
        protected override string DoIt()
        {
            String   opportunity     = "";
            int      Customer        = 0;
            int      User            = 0;
            int      Location        = 0;
            DateTime?startDate       = null;
            int      Pricelist       = 0;
            int      Currency        = 0;
            int      c_bpartner_id   = 0;
            int      c_bpartnerSR_id = 0;

            String sql = "select bp.iscustomer,bp.isprospect,bp.name,bp.c_bpartner_id,au.ad_user_id, bpl.c_bpartner_location_id"
                         + " from c_bpartner bp left join c_bpartner_location bpl on(bpl.c_bpartner_id= bp.c_bpartner_id)"
                         + " left JOIN ad_user au on(au.c_bpartner_id= bp.c_bpartner_id) where bp.c_bpartner_id=" + "1001892" + " and bp.ad_client_id=" + GetCtx().GetAD_Client_ID();
            IDataReader idr  = null;
            IDataReader idr1 = null;

            try
            {
                idr = DB.ExecuteReader(sql);
                if (idr.Read())
                {
                    Customer    = Util.GetValueOfInt(idr["C_BPartner_ID"]);
                    opportunity = Util.GetValueOfString(idr["Name"]);
                    User        = Util.GetValueOfInt(idr["AD_User_ID"]);
                    Location    = Util.GetValueOfInt(idr["C_BPartner_Location_ID"]);
                    startDate   = Util.GetValueOfDateTime(System.DateTime.Now);
                    if (Util.GetValueOfString(idr["IsCustomer"]) == "Y")
                    {
                        c_bpartner_id = Util.GetValueOfInt(idr["C_BPartner_ID"]);
                    }
                    else if (Util.GetValueOfString(idr["IsProspect"]) == "Y")
                    {
                        c_bpartnerSR_id = Util.GetValueOfInt(idr["C_BPartner_ID"]);
                    }
                    sql = "select mp.m_pricelist_id,cc.c_currency_id from m_pricelist_version mpv join m_pricelist mp on(mp.m_pricelist_id=mpv.m_pricelist_id) join c_currency cc on(cc.c_currency_id= mp.c_currency_id) where mpv.m_pricelist_version_id=" + _M_PriceList_Version_ID + " and mp.ad_client_id=" + GetCtx().GetAD_Client_ID();

                    idr1 = DB.ExecuteReader(sql);
                    if (idr1.Read())
                    {
                        Pricelist = Util.GetValueOfInt(idr1["M_PriceList_ID"]);
                        Currency  = Util.GetValueOfInt(idr1["C_Currency_ID"]);
                    }
                    idr1.Close();

                    int Owner = Util.GetValueOfInt(GetCtx().GetAD_User_ID());
                    //Util.GetValueOfString(GetCtx().GetAD_User_ID());

                    VAdvantage.Model.X_C_Project opp = new VAdvantage.Model.X_C_Project(GetCtx(), 0, Get_TrxName());
                    opp.SetIsOpportunity(true);
                    opp.SetName(opportunity);
                    opp.SetC_BPartner_ID(c_bpartner_id);
                    opp.SetC_BPartnerSR_ID(c_bpartnerSR_id);
                    opp.SetAD_User_ID(User);
                    opp.SetSalesRep_ID(Owner);
                    opp.SetDateContract(startDate.Value.Date);
                    opp.SetC_BPartner_Location_ID(Location);
                    opp.SetC_Campaign_ID(_C_Campaign_ID);
                    opp.SetProbability(_Probability);
                    opp.SetM_PriceList_Version_ID(_M_PriceList_Version_ID);
                    opp.SetC_Currency_ID(Currency);
                    opp.SetM_PriceList_ID(Pricelist);
                    opp.Save();
                }
                idr.Close();

                return("Opportunity Generated");
            }
            catch
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                if (idr1 != null)
                {
                    idr1.Close();
                    idr1 = null;
                }
                return("****Error****");
            }
        }
Exemplo n.º 3
0
        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(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 (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);
                if (lead.GetBPName() == null)
                {
                    return(Msg.GetMsg(GetCtx(), "Company Name, Prospect or Bpartner is Mandatory to fill"));
                }
                callprospect();
                return(DoIt());
            }

            return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (clear text)</returns>
        protected override String DoIt()
        {
            log.Info("C_Order_ID=" + _C_Order_ID
                     + ", C_DocType_ID=" + _C_DocType_ID
                     + ", CloseDocument=" + _IsCloseDocument);
            if (_C_Order_ID == 0)
            {
                throw new ArgumentException("No Order");
            }
            VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID);
            if (dt.Get_ID() == 0)
            {
                throw new ArgumentException("No DocType");
            }
            if (_DateDoc == null)
            {
                _DateDoc = Util.GetValueOfDateTime(DateTime.Now);
            }
            //
            VAdvantage.Model.MOrder from     = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc,
                                                                                dt.GetC_DocType_ID(), false, true, null); //	copy ASI
            newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            int C_Bpartner_ID = newOrder.GetC_BPartner_ID();

            //Update New Order Refrence From Sales Qutation in Sales order
            newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));
            String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + "  where ref_order_id=" + _C_Order_ID + "";
            int    value = DB.ExecuteQuery(sqlbp, null, Get_Trx());
            bool   OK    = newOrder.Save();

            if (!OK)
            {
                throw new Exception("Could not create new Order");
            }
            if (OK)
            {
                string sql          = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID();
                int    C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                if (C_Project_ID != 0)
                {
                    VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx());
                    project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID());
                    project.SetC_BPartnerSR_ID(0);
                    if (!project.Save())
                    {
                    }
                }
                from.SetRef_Order_ID(newOrder.GetC_Order_ID());
                from.Save();
                int bp = newOrder.GetC_BPartner_ID();
                VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx());
                prosp.SetIsCustomer(true);
                prosp.SetIsProspect(false);
                prosp.Save();
            }

            //
            if (_IsCloseDocument)
            {
                VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
                original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete);
                original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete);
                original.Save();
                original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.Save();
            }
            //

            return(Msg.GetMsg(GetCtx(), "OrderCreatedSuuccessfully"));
            //return dt.GetName() + ": " + newOrder.GetDocumentNo();
        }
        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.SetAD_Client_ID(lead.GetAD_Client_ID());
                opp.SetAD_Org_ID(lead.GetAD_Org_ID());
                opp.SetC_Lead_ID(lead.GetC_Lead_ID());
                opp.SetC_BPartner_ID(lead.GetC_BPartner_ID());

                // Addde by Bharat on 19 Feb 2018 to set Ref Partner/Prospect
                if (opp.Get_ColumnIndex("Ref_BPartner_ID") > 0)
                {
                    opp.SetRef_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(lead.GetC_BPartner_Location_ID());
                opp.SetIsOpportunity(true);
                /*Vivek*/
                opp.SetC_EnquiryRdate(lead.GetC_EnquiryRdate());
                if (lead.GetC_ProposalDdate() != null)
                {
                    opp.SetC_ProposalDdate(Convert.ToDateTime(lead.GetC_ProposalDdate()).ToLocalTime());
                }
                else
                {
                    opp.SetC_ProposalDdate(lead.GetC_ProposalDdate());
                }
                if (opp.Save())
                {
                    lead.SetC_Project_ID(opp.GetC_Project_ID());
                    lead.Save();
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateDone"));
                }
                else
                {
                    return(GetRetrievedError(opp, "OpprtunityGenerateNotDone"));
                    //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.SetAD_Client_ID(lead.GetAD_Client_ID());
                opp.SetAD_Org_ID(lead.GetAD_Org_ID());
                opp.SetC_Lead_ID(lead.GetC_Lead_ID());
                opp.SetC_BPartnerSR_ID(lead.GetRef_BPartner_ID());
                // Addde by Bharat on 19 Feb 2018 to set Ref Partner/Prospect
                if (opp.Get_ColumnIndex("Ref_BPartner_ID") > 0)
                {
                    opp.SetRef_BPartner_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);
                /*Vivek*/
                opp.SetC_EnquiryRdate(lead.GetC_EnquiryRdate());
                if (lead.GetC_ProposalDdate() != null)
                {
                    opp.SetC_ProposalDdate(Convert.ToDateTime(lead.GetC_ProposalDdate()).ToLocalTime());
                }
                else
                {
                    opp.SetC_ProposalDdate(lead.GetC_ProposalDdate());
                }
                if (opp.Save())
                {
                    lead.SetC_Project_ID(opp.GetC_Project_ID());
                    lead.Save();
                    return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateDone"));
                }
                else
                {
                    return(GetRetrievedError(opp, "OpprtunityGenerateNotDone"));
                    //return Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone");
                }
            }
            if (ExCustomer == 0 && Pospect == 0)
            {
                //CallProcess(_C_Lead_ID);
                if (lead.GetBPName() == null)
                {
                    return(Msg.GetMsg(GetCtx(), "Company Name, Prospect or Bpartner is Mandatory to fill"));
                }
                callprospect();
                return(DoIt());
            }

            return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
        }
Exemplo n.º 6
0
        protected override string DoIt()
        {
            VAdvantage.Model.X_C_BPartner partner = new VAdvantage.Model.X_C_BPartner(GetCtx(), GetRecord_ID(), null);

            string _BPName = partner.GetName();

            string  _sql = "Select C_Lead_ID From C_Lead Where BPName='" + _BPName + "'  AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID();
            DataSet ds   = new DataSet();

            ds = DB.ExecuteDataset(_sql.ToString());
            if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    _C_Lead_ID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Lead_ID"]);
                    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 (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();

                            bp.SetCreateProject("Y");
                            if (bp.Save())
                            {
                            }

                            return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateDone"));
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "OpprtunityGenerateNotDone"));
                        }
                    }
                    //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(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");

                    //    }
                    //}
                }
            }
            return("");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (clear text)</returns>
        protected override String DoIt()
        {
            log.Info("C_Order_ID=" + _C_Order_ID
                     + ", C_DocType_ID=" + _C_DocType_ID
                     + ", CloseDocument=" + _IsCloseDocument);
            if (_C_Order_ID == 0)
            {
                throw new ArgumentException("No Order");
            }
            VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID);
            if (dt.Get_ID() == 0)
            {
                throw new ArgumentException("No DocType");
            }
            if (_DateDoc == null)
            {
                _DateDoc = Util.GetValueOfDateTime(DateTime.Now);
            }
            //
            VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            if (from.GetDocStatus() != "DR" && from.GetDocStatus() != "IP" && from.GetDocStatus() != "CO")
            {
                throw new Exception("Order Closed");
            }
            VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc,
                                                                                dt.GetC_DocType_ID(), false, true, null); //	copy ASI
            newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            int C_Bpartner_ID = newOrder.GetC_BPartner_ID();

            newOrder.Set_Value("IsSalesQuotation", false);

            // Added by Bharat on 05 Jan 2018 to set Values on Blanket Sales Order from Sales Quotation.
            if (dt.GetDocBaseType() == "BOO")
            {
                newOrder.Set_Value("IsBlanketTrx", true);
            }
            else   // Added by Bharat on 29 March 2018 to set Blanket Order zero in case of Sales order Creation.
            {
                newOrder.SetC_Order_Blanket(0);
            }
            if (newOrder.Get_ColumnIndex("C_Order_Quotation") > 0)
            {
                newOrder.SetC_Order_Quotation(_C_Order_ID);
            }

            //Update New Order Refrence From Sales Qutation in Sales order
            newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));

            // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation

            if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0)
            {
                newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID());
            }

            String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + "  where ref_order_id=" + _C_Order_ID + "";
            int    value = DB.ExecuteQuery(sqlbp, null, Get_Trx());
            bool   OK    = newOrder.Save();

            if (!OK)
            {
                //return GetReterivedError( newOrder,  "Could not create new Order");
                throw new Exception("Could not create new Order");
            }
            if (OK)
            {
                string sql          = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID();
                int    C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                if (C_Project_ID != 0)
                {
                    VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx());
                    project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID());
                    project.SetC_BPartnerSR_ID(0);
                    if (!project.Save())
                    {
                        log.SaveError("Error on " + project.Get_TableName(), "");
                    }
                }
                if (dt.GetDocBaseType() == "BOO")
                {
                    from.SetC_Order_Blanket(newOrder.GetC_Order_ID());
                }
                else
                {
                    from.SetRef_Order_ID(newOrder.GetC_Order_ID());
                }
                from.Save();
                int bp = newOrder.GetC_BPartner_ID();
                VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx());
                prosp.SetIsCustomer(true);
                prosp.SetIsProspect(false);
                if (!prosp.Save())
                {
                    log.SaveError("Error on " + prosp.Get_TableName(), "");
                }
            }

            //
            if (_IsCloseDocument)
            {
                VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
                //Edited by Arpit Rai on 8th of Nov,2017
                if (original.GetDocStatus() != "CO") //to check if document is already completed
                {
                    original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete);
                    original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete);
                    original.Save();
                }
                //Arpit
                original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.Save();
            }
            //
            return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + newOrder.GetDocumentNo());
        }