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