/// <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()); }