/** * Get Counter document for document type * @param ctx context * @param C_DocType_ID base document * @return counter document C_DocType_ID or 0 or -1 if no counter doc */ public static int GetCounterDocType_ID(Ctx ctx, int C_DocType_ID) { // Direct Relationship MDocTypeCounter dtCounter = GetCounterDocType(ctx, C_DocType_ID); if (dtCounter != null) { if (!dtCounter.IsCreateCounter() || !dtCounter.IsValid()) { return(-1); } return(dtCounter.GetCounter_C_DocType_ID()); } // Indirect Relationship int Counter_C_DocType_ID = 0; MDocType dt = MDocType.Get(ctx, C_DocType_ID); if (!dt.IsCreateCounter()) { return(-1); } String cDocBaseType = "";// = getCounterDocBaseType(dt.getDocBaseType()); if (cDocBaseType == null) { return(0); } MDocType[] counters = MDocType.GetOfDocBaseType(ctx, cDocBaseType); for (int i = 0; i < counters.Length; i++) { MDocType counter = counters[i]; if (counter.IsDefaultCounterDoc()) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); break; } if (counter.IsDefault()) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); } else if (i == 0) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); } } return(Counter_C_DocType_ID); }
public bool ReActivateIt() { try { log.Info(ToString()); MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); String DocSubTypeSO = dt.GetDocSubTypeSO(); // Replace Prepay with POS to revert all doc if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO)) { MDocType newDT = null; MDocType[] dts = MDocType.GetOfClient(GetCtx()); for (int i = 0; i < dts.Length; i++) { MDocType type = dts[i]; if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(type.GetDocSubTypeSO())) { if (type.IsDefault() || newDT == null) { newDT = type; } } } if (newDT == null) { return(false); } else { SetC_DocType_ID(newDT.GetC_DocType_ID()); //SetIsReturnTrx(newDT.IsReturnTrx()); } } // PO - just re-open //if (!IsSOTrx()) //{ // log.Info("Existing documents not modified - " + dt); //} // Reverse Direct Documents else if (MDocType.DOCSUBTYPESO_OnCreditOrder.Equals(DocSubTypeSO) || // (W)illCall(I)nvoice MDocType.DOCSUBTYPESO_WarehouseOrder.Equals(DocSubTypeSO) || // (W)illCall(P)ickup MDocType.DOCSUBTYPESO_POSOrder.Equals(DocSubTypeSO)) // (W)alkIn(R)eceipt { if (!CreateReversals()) { return(false); } } else { log.Info("Existing documents not modified - SubType=" + DocSubTypeSO); } SetDocAction(DOCACTION_Complete); SetProcessed(false); } catch { //ShowMessage.Error("MOrder", null, "SetBPartner"); } 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"); } //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> /// 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); }
/// <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(); }