/// <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");
            }
            //JID_1799 fromCreateSo is true if DOCBASETYPE='BOO'
            VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null,
                                                                                dt.GetDocBaseType().Equals(MDocBaseType.DOCBASETYPE_BLANKETSALESORDER) ? true : false); //	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());
        }
        /// <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");
            //}
            //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);
            //if (dt.Get_ID() == 0)
            //{
            //    throw new ArgumentException("No DocType");
            //}
            //if (_DateDoc == null)
            //{
            //    _DateDoc = DateTime.Now;
            //  //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis()));
            //}
            ////
            //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc,
            //    dt.GetC_DocType_ID(), false, true, null);		//	copy ASI
            //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            //bool OK = newOrder.Save ();
            //if (!OK)
            //{
            //    throw new Exception("Could not create new Order");
            //}
            ////
            //if (_IsCloseDocument)
            //{
            //    MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //    original.SetDocAction(MOrder.DOCACTION_Complete);
            //    original.ProcessIt(MOrder.DOCACTION_Complete);
            //    original.Save();
            //    original.SetDocAction(MOrder.DOCACTION_Close);
            //    original.ProcessIt(MOrder.DOCACTION_Close);
            //    original.Save();
            //}
            ////
            //return dt.GetName() + ": " + newOrder.GetDocumentNo();


            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());
            MOrder newOrder = MOrder.CopyFrom(from, _DateDoc,
                                              dt.GetC_DocType_ID(), false, true, null, true);//Pass optional parameter as True that we are going to create Order from Create Sales Order Process on Sales Quotation window---Neha

            newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            //Update New Order Refrence From Sales Qutation in Sales order
            newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));
            int C_Bpartner_ID = newOrder.GetC_BPartner_ID();

            newOrder.Set_Value("IsSalesQuotation", false);

            // 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)
            {
                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());
                //Edited by Arpit Rai on 8th of Nov,2017
                if (original.GetDocStatus() != "CO") //to check if document is already completed
                {
                    original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete);
                    original.SetDocAction(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());
        }
        /// <summary>Add Sales Order Header for VA077 Module</summary>
        /// <param name="destinationorg">Destination Orgnaization id</param>
        /// <param name="orgId">Organization Id</param>
        /// <returns>bool</returns>
        public bool AddHeader(int destinationorg, int orgId)
        {
            VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID);
            MOrder newOrder = new VAdvantage.Model.MOrder(GetCtx(), 0, Get_Trx());

            VAdvantage.Model.MOrder morder = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            newOrder.SetAD_Client_ID(GetAD_Client_ID());
            if (destinationorg != 0)
            {
                newOrder.SetAD_Org_ID(destinationorg);
            }
            else
            {
                newOrder.SetAD_Org_ID(orgId);
            }
            newOrder.SetC_BPartner_ID(morder.GetC_BPartner_ID());
            newOrder.SetC_BPartner_Location_ID(morder.GetC_BPartner_Location_ID());
            newOrder.SetAD_User_ID(morder.GetAD_User_ID());
            newOrder.SetBill_BPartner_ID(morder.GetBill_BPartner_ID());
            newOrder.SetAD_OrgTrx_ID(morder.GetAD_OrgTrx_ID());
            newOrder.SetBill_Location_ID(morder.GetBill_Location_ID());
            newOrder.SetBill_User_ID(morder.GetBill_User_ID());
            newOrder.SetM_PriceList_ID(morder.GetM_PriceList_ID());
            newOrder.SetC_Currency_ID(morder.GetC_Currency_ID());
            newOrder.SetSalesRep_ID(morder.GetSalesRep_ID());
            newOrder.SetDescription(morder.GetDescription());
            //newOrder.SetM_Warehouse_ID(morder.GetM_Warehouse_ID());
            newOrder.SetC_PaymentTerm_ID(morder.GetC_PaymentTerm_ID());
            newOrder.SetC_Payment_ID(morder.GetC_Payment_ID());
            newOrder.SetVA009_PaymentMethod_ID(morder.GetVA009_PaymentMethod_ID());
            newOrder.SetC_IncoTerm_ID(morder.GetC_IncoTerm_ID());
            newOrder.SetC_Campaign_ID(morder.GetC_Campaign_ID());
            newOrder.SetC_ProjectRef_ID(morder.GetC_Campaign_ID());
            newOrder.SetGrandTotal(morder.GetGrandTotal());
            newOrder.SetTotalLines(morder.GetTotalLines());
            newOrder.Set_Value("VA077_HistoricContractDate", morder.Get_Value("VA077_HistoricContractDate"));
            newOrder.Set_Value("VA077_ChangeStartDate", morder.Get_Value("VA077_ChangeStartDate"));
            newOrder.Set_Value("VA077_ContractCPStartDate", morder.Get_Value("VA077_ContractCPStartDate"));
            newOrder.Set_Value("VA077_ContractCPEndDate", morder.Get_Value("VA077_ContractCPEndDate"));
            newOrder.Set_Value("VA077_PartialAmtCatchUp", morder.Get_Value("VA077_PartialAmtCatchUp"));
            newOrder.Set_Value("VA077_PartialAmtCatchUp", morder.Get_Value("VA077_PartialAmtCatchUp"));
            newOrder.Set_Value("VA077_OldAnnualContractTotal", morder.Get_Value("VA077_OldAnnualContractTotal"));
            newOrder.Set_Value("VA077_AdditionalAnnualCharge", morder.Get_Value("VA077_AdditionalAnnualCharge"));
            newOrder.Set_Value("VA077_NewAnnualContractTotal", morder.Get_Value("VA077_NewAnnualContractTotal"));
            newOrder.Set_Value("VA077_OrderRef", morder.Get_Value("VA077_OrderRef"));
            newOrder.Set_Value("VA077_SalesCoWorkerPer", morder.Get_Value("VA077_SalesCoWorkerPer"));
            newOrder.Set_Value("VA077_TotalMarginAmt", morder.Get_Value("VA077_TotalMarginAmt"));
            newOrder.Set_Value("VA077_SalesCoWorker", morder.Get_Value("VA077_SalesCoWorker"));
            newOrder.Set_Value("VA077_TotalPurchaseAmt", morder.Get_Value("VA077_TotalPurchaseAmt"));
            newOrder.Set_Value("VA077_TotalSalesAmt", morder.Get_Value("VA077_TotalSalesAmt"));
            newOrder.Set_Value("VA077_MarginPercent", morder.Get_Value("VA077_MarginPercent"));
            newOrder.Set_Value("VA077_IsLegalEntity", morder.Get_Value("VA077_IsLegalEntity"));
            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(morder.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(morder.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 = " + morder.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())
                    {
                        Get_Trx().Rollback();
                        log.SaveError("Error on " + project.Get_TableName(), "");
                    }
                }
                if (dt.GetDocBaseType() == "BOO")
                {
                    morder.SetC_Order_Blanket(newOrder.GetC_Order_ID());
                }
                else
                {
                    morder.SetRef_Order_ID(newOrder.GetC_Order_ID());
                }
                newid     = newOrder.GetC_Order_ID();
                neworg_id = newOrder.GetAD_Org_ID();
                morder.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())
                {
                    Get_Trx().Rollback();
                    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();
            }

            docNo = newOrder.GetDocumentNo();
            return(true);
        }
        /// <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");
            }

            //Develop by Deekshant For check VA077 Module For spilt the Sales Order
            if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_"))
            {
                //Check Destination Organization in c_orderline
                string  str = "SELECT DISTINCT(VA077_DestinationOrg), AD_Org_Id FROM C_OrderLine WHERE C_Order_ID=" + _C_Order_ID;
                DataSet dts = DB.ExecuteDataset(str, null, Get_Trx());
                if (dts != null && dts.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
                    {
                        int destinationorg = Util.GetValueOfInt(dts.Tables[0].Rows[i]["VA077_DestinationOrg"]);
                        // VAdvantage.Model.MOrder newOrder = new VAdvantage.Model.MOrder(GetCtx(), 0, Get_Trx());
                        int orgId = Util.GetValueOfInt(dts.Tables[0].Rows[i]["AD_Org_Id"]);
                        AddHeader(destinationorg, orgId);
                        Addline(destinationorg, orgId);
                    }
                }
            }
            else
            {
                //JID_1799 fromCreateSo is true if DOCBASETYPE='BOO'
                VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null,
                                                                                    dt.GetDocBaseType().Equals(MDocBaseType.DOCBASETYPE_BLANKETSALESORDER) ? true : false); //	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();
                }
                docNo = newOrder.GetDocumentNo();
            }
            //+ ": " + newOrder.GetDocumentNo()
            return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + docNo);
        }
Exemple #5
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");
            //}
            //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);
            //if (dt.Get_ID() == 0)
            //{
            //    throw new ArgumentException("No DocType");
            //}
            //if (_DateDoc == null)
            //{
            //    _DateDoc = DateTime.Now;
            //  //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis()));
            //}
            ////
            //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc,
            //    dt.GetC_DocType_ID(), false, true, null);		//	copy ASI
            //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            //bool OK = newOrder.Save ();
            //if (!OK)
            //{
            //    throw new Exception("Could not create new Order");
            //}
            ////
            //if (_IsCloseDocument)
            //{
            //    MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //    original.SetDocAction(MOrder.DOCACTION_Complete);
            //    original.ProcessIt(MOrder.DOCACTION_Complete);
            //    original.Save();
            //    original.SetDocAction(MOrder.DOCACTION_Close);
            //    original.ProcessIt(MOrder.DOCACTION_Close);
            //    original.Save();
            //}
            ////
            //return dt.GetName() + ": " + newOrder.GetDocumentNo();


            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);
            //Update New Order Refrence From Sales Qutation in Sales order
            newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));
            int    C_Bpartner_ID = newOrder.GetC_BPartner_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)
            {
                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();
        }