} // getOfUser public static MUserPreference GetOfUser(PO user, bool createNew) { MUserPreference retValue = null; int AD_User_ID = (int)user.Get_Value("AD_User_ID"); String sql = "SELECT * FROM AD_UserPreference WHERE AD_User_ID='" + AD_User_ID + "'"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql); foreach (DataRow rs in ds.Tables[0].Rows) { retValue = new MUserPreference(user.GetCtx(), rs, null); } ds.Dispose(); } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } if (retValue == null && createNew) { retValue = new MUserPreference(user.GetCtx(), 0, null); retValue.SetClientOrg(user); retValue.SetAD_User_ID(AD_User_ID); retValue.Save(); } return(retValue); } // getOfUser
/// <summary> /// Get Organizations Of Client /// </summary> /// <param name="po">persistent object</param> /// <returns>array of orgs</returns> public static MOrg[] GetOfClient(PO po) { List <MOrg> list = new List <MOrg>(); String sql = "SELECT * FROM AD_Org WHERE AD_Client_ID=" + po.GetAD_Client_ID() + " ORDER BY Value"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0) { DataRow dr = null; int totCount = ds.Tables[0].Rows.Count; for (int i = 0; i < totCount; i++) { dr = ds.Tables[0].Rows[i]; list.Add(new MOrg(po.GetCtx(), dr, null)); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } MOrg[] retValue = new MOrg[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Parent Constructor /// </summary> /// <param name="partner">partner</param> public MUser(PO partner) : this(partner.GetCtx(), 0, partner.Get_TrxName()) { SetClientOrg(partner); SetC_BPartner_ID((int)partner.Get_Value("C_BPartner_ID")); SetName(partner.Get_Value("Name").ToString()); }
/// <summary> /// Is this an Item Product (vs. not a Service, a charge) /// </summary> /// <returns>true if product</returns> public bool IsItem() { if (_isItem != null) { return(Utility.Util.GetValueOfBool(_isItem));//.booleanValue(); } _isItem = false; if (GetM_Product_ID() != 0) { MProduct product = MProduct.Get(_po.GetCtx(), GetM_Product_ID()); if (product.Get_ID() == GetM_Product_ID() && product.IsItem()) { _isItem = true; } } return(Utility.Util.GetValueOfBool(_isItem));//.booleanValue(); }
/// <summary> ///New Constructor /// </summary> /// <param name="po">parent</param> /// <param name="C_ConversionType_ID">conversion type</param> /// <param name="C_Currency_ID">currency to</param> /// <param name="C_Currency_To_ID"></param> /// <param name="MultiplyRate">multiply rate</param> /// <param name="ValidFrom">valid from</param> public MConversionRate(PO po, int C_ConversionType_ID, int C_Currency_ID, int C_Currency_To_ID, Decimal multiplyRate, DateTime?validFrom) : this(po.GetCtx(), 0, po.Get_TrxName()) { //this(po.getCtx(), 0, po.get_TrxName()); SetClientOrg(po); SetC_ConversionType_ID(C_ConversionType_ID); SetC_Currency_ID(C_Currency_ID); SetC_Currency_To_ID(C_Currency_To_ID); SetMultiplyRate(multiplyRate); SetValidFrom(validFrom); }
} // getAll /// <summary> /// Execute Auto Assignment /// </summary> /// <param name="po">PO to be modified</param> /// <param name="newRecord">new</param> /// <returns>true if modified</returns> static public bool Execute(PO po, bool newRecord) { if (s_assignments == null) { s_assignments = GetAll(po.GetCtx()); } bool modified = false; for (int i = 0; i < s_assignments.Length; i++) { MAssignSet set = s_assignments[i]; if (!set.IsActive()) { continue; } // Check IDs if (po.Get_Table_ID() == set.GetAD_Table_ID() && (po.GetAD_Client_ID() == set.GetAD_Client_ID() || set.GetAD_Client_ID() == 0)) { // Check Timing String rule = set.GetAutoAssignRule(); if (!newRecord && rule.Equals(AUTOASSIGNRULE_CreateOnly)) { continue; } if (newRecord && (rule.Equals(AUTOASSIGNRULE_UpdateOnly) || rule.Equals(AUTOASSIGNRULE_UpdateIfNotProcessed))) { continue; } // Eliminate Processed if (rule.Equals(AUTOASSIGNRULE_CreateAndUpdateIfNotProcessed) || rule.Equals(AUTOASSIGNRULE_UpdateIfNotProcessed)) { int indexProcessed = po.Get_ColumnIndex("Processed"); if (indexProcessed != -1 && "Y".Equals(po.Get_Value(indexProcessed))) { continue; } } // if (set.ExecuteIt(po)) { modified = true; } } } return(modified); } // execute
/// <summary> /// New User Mail (no trx) /// </summary> /// <param name="po">persistent object</param> /// <param name="AD_User_ID">recipient user</param> /// <param name="mail">email</param> public MUserMail(PO po, int AD_User_ID, EMail mail) : this(po.GetCtx(), 0, null) { SetClientOrg(po); SetAD_User_ID(AD_User_ID); SetSubject(mail.GetSubject()); SetMailText(mail.GetMessageCRLF()); // if (mail.IsSentOK()) { SetMessageID(mail.GetMessageID()); } else { SetMessageID(mail.GetSentMsg()); SetIsDelivered(ISDELIVERED_No); } }
/** * Get active Material Cost Element for client * @param po parent * @return cost element array */ public static MCostElement[] GetCostingMethods(PO po) { List <MCostElement> list = new List <MCostElement>(); String sql = "SELECT * FROM M_CostElement " + "WHERE AD_Client_ID=@Client_ID" + " AND IsActive='Y' AND CostElementType='M' AND CostingMethod IS NOT NULL"; DataTable dt = null; //IDataReader idr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@Client_ID", po.GetAD_Client_ID()); //idr = DataBase.DB.ExecuteReader(sql, param, po.Get_TrxName()); DataSet ds = DataBase.DB.ExecuteDataset(sql, param, po.Get_TrxName()); dt = new DataTable(); dt = ds.Tables[0]; //idr.Close(); foreach (DataRow dr in dt.Rows) { list.Add(new MCostElement(po.GetCtx(), dr, po.Get_TrxName())); } } catch (Exception e) { //if (idr != null) // { // idr.Close(); //} _log.Log(Level.SEVERE, sql, e); } finally { dt = null; } MCostElement[] retValue = new MCostElement[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Parse Variable /// </summary> /// <param name="variable">variable</param> /// <param name="po">po object</param> /// <returns>translated variable or if not found the original tag</returns> private static string ParseVariable(String variable, PO po) { int index = po.Get_ColumnIndex(variable); if (index == -1) { return("@" + variable + "@"); // keep for next } // Object value = po.Get_Value(index); if (value == null) { return(""); } POInfo _poInfo = POInfo.GetPOInfo(po.GetCtx(), po.Get_Table_ID()); MColumn column = (new MTable(po.GetCtx(), po.Get_Table_ID(), null)).GetColumn(variable); if (column.GetAD_Reference_ID() == DisplayType.Location) { StringBuilder sb = new StringBuilder(); DataSet ds = DB.ExecuteDataset(@"SELECT l.address1, l.address2, l.address3, l.address4, l.city, CASE WHEN l.C_City_ID IS NOT NULL THEN ( SELECT NAME FROM C_City ct WHERE ct.C_City_ID=l.C_City_ID ) ELSE NULL END CityName, (SELECT NAME FROM C_Country c WHERE c.C_Country_ID=l.C_Country_ID ) AS CountryName FROM C_Location l WHERE l.C_Location_ID=" + value); if (ds != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["address1"] != null && ds.Tables[0].Rows[0]["address1"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address1"]).Append(","); } if (ds.Tables[0].Rows[0]["address2"] != null && ds.Tables[0].Rows[0]["address2"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address2"]).Append(","); } if (ds.Tables[0].Rows[0]["address3"] != null && ds.Tables[0].Rows[0]["address3"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address3"]).Append(","); } if (ds.Tables[0].Rows[0]["address4"] != null && ds.Tables[0].Rows[0]["address4"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address4"]).Append(","); } if (ds.Tables[0].Rows[0]["city"] != null && ds.Tables[0].Rows[0]["city"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["city"]).Append(","); } if (ds.Tables[0].Rows[0]["CityName"] != null && ds.Tables[0].Rows[0]["CityName"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["CityName"]).Append(","); } if (ds.Tables[0].Rows[0]["CountryName"] != null && ds.Tables[0].Rows[0]["CountryName"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["CountryName"]).Append(","); } return(sb.ToString().TrimEnd(',')); } else { return(""); } } //Get lookup display column name for ID if (_poInfo != null && _poInfo.getAD_Table_ID() == po.Get_Table_ID() && _poInfo.IsColumnLookup(index) && value != null) { VLookUpInfo lookup = _poInfo.GetColumnLookupInfo(index); //create lookup info for column DataSet ds = DB.ExecuteDataset(lookup.queryDirect.Replace("@key", DB.TO_STRING(value.ToString())), null); //Get Name from data if (ds != null && ds.Tables[0].Rows.Count > 0) { value = ds.Tables[0].Rows[0][2]; //Name Value } } if (column.GetAD_Reference_ID() == DisplayType.Date) { return(Util.GetValueOfDateTime(value).Value.Date.ToShortDateString()); } return(value.ToString()); }
/** * Get Material Cost Element or create it * @param po parent * @param CostingMethod method * @return cost element */ public static MCostElement GetMaterialCostElement(PO po, String CostingMethod) { if (CostingMethod == null || CostingMethod.Length == 0) { _log.Severe("No CostingMethod"); return(null); } // MCostElement retValue = null; String sql = "SELECT * FROM M_CostElement WHERE AD_Client_ID=" + po.GetAD_Client_ID() + " AND CostingMethod=@costingMethod ORDER BY AD_Org_ID"; DataTable dt = null; IDataReader idr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@costingMethod", CostingMethod); idr = DataBase.DB.ExecuteReader(sql, param, po.Get_TrxName()); dt = new DataTable(); dt.Load(idr); idr.Close(); //bool n = dr.next(); //jz to fix DB2 resultSet closed problem //if (n) foreach (DataRow dr in dt.Rows) { retValue = new MCostElement(po.GetCtx(), dr, po.Get_TrxName()); } //if (n && dr.next()) // s_log.warning("More then one Material Cost Element for CostingMethod=" + CostingMethod); } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { dt = null; } if (retValue != null) { return(retValue); } // Create New retValue = new MCostElement(po.GetCtx(), 0, po.Get_TrxName()); retValue.SetClientOrg(po.GetAD_Client_ID(), 0); String name = MRefList.GetListName(po.GetCtx(), COSTINGMETHOD_AD_Reference_ID, CostingMethod); if (name == null || name.Length == 0) { name = CostingMethod; } retValue.SetName(name); retValue.SetCostElementType(COSTELEMENTTYPE_Material); retValue.SetCostingMethod(CostingMethod); retValue.Save(); return(retValue); }
/// <summary> /// Create Organization level Sequence No from Serial No Control /// </summary> /// <param name="po"></param> /// <returns>Serial No</returns> public String CreateDefiniteSerNo(PO po) { Boolean isUseOrgLevel = Util.GetValueOfBool(Get_Value("IsOrgLevelSequence")); String orgColumn = Util.GetValueOfString(Get_Value("OrgColumn")); int startNo = GetStartNo(); int incrementNo = GetIncrementNo(); String prefix = GetPrefix(); String suffix = GetSuffix(); String selectSQL = null; // if Organization level check box is true, the Get Current next from Serila No tab. if (isUseOrgLevel) { selectSQL = "SELECT y.CurrentNext, s.CurrentNext, y.prefix, y.suffix " + "FROM M_SerNoCtl_No y, M_SerNoCtl s " + "WHERE y.M_SerNoCtl_ID = s.M_SerNoCtl_ID " + "AND s.M_SerNoCtl_ID = " + GetM_SerNoCtl_ID() + " AND y.AD_Org_ID = @param1" + " AND s.IsActive='Y' " + "ORDER BY s.AD_Client_ID DESC"; } else { selectSQL = "SELECT s.CurrentNext " + "FROM M_SerNoCtl s " + "WHERE s.M_SerNoCtl_ID = " + GetM_SerNoCtl_ID() + " AND s.IsActive='Y' " + "ORDER BY s.AD_Client_ID DESC"; } int docOrg_ID = 0; int next = -1; String updateSQL = ""; DataSet rs; try { if (po != null && orgColumn != null && orgColumn.Length > 0) { docOrg_ID = Util.GetValueOfInt(po.Get_Value(orgColumn)); } if (isUseOrgLevel) { selectSQL = selectSQL.Replace("@param1", docOrg_ID.ToString()); rs = DB.ExecuteDataset(selectSQL, null, null); // Check organization level document sequence settings and if exist then override general settings. if (rs != null && rs.Tables[0].Rows.Count > 0) { string _prefix = Convert.ToString(rs.Tables[0].Rows[0]["Prefix"]); string _suffix = Convert.ToString(rs.Tables[0].Rows[0]["suffix"]); // if any of these fields contains data, then override parent tab's data.... if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix)) { prefix = _prefix; suffix = _suffix; } } } else { rs = DB.ExecuteDataset(selectSQL, null, null); } if (rs != null && rs.Tables.Count > 0 && rs.Tables[0].Rows.Count > 0) { if (log.IsLoggable(Level.FINE)) { log.Fine("M_SerNoCtl_ID=" + GetM_SerNoCtl_ID()); } // Update current next on Serial No Control. if (isUseOrgLevel) { updateSQL = "UPDATE M_SerNoCtl_No SET CurrentNext = CurrentNext + " + incrementNo + " WHERE M_SerNoCtl_ID= " + GetM_SerNoCtl_ID() + " AND AD_Org_ID=" + docOrg_ID; } else { updateSQL = "UPDATE M_SerNoCtl SET CurrentNext = CurrentNext + " + incrementNo + " WHERE M_SerNoCtl_ID=" + GetM_SerNoCtl_ID(); } next = int.Parse(rs.Tables[0].Rows[0]["CurrentNext"].ToString()); if (DB.ExecuteQuery(updateSQL, null, null) < 0) { next = -2; } } else { // did not find Serial no . if (isUseOrgLevel) { // create Serial no (CurrentNo = StartNo + IncrementNo) for this Organization and return first number (=StartNo) next = startNo; X_M_SerNoCtl_No seqno = new X_M_SerNoCtl_No(po.GetCtx(), 0, null); seqno.SetM_SerNoCtl_ID(GetM_SerNoCtl_ID()); seqno.SetAD_Org_ID(docOrg_ID); seqno.SetCurrentNext(startNo + incrementNo); seqno.Save(); } else // standard { log.Warning("(Serial No)- no record found - " + GetName()); next = -2; } } } catch (Exception e) { log.Log(Level.SEVERE, "(Serial No)", e); next = -2; } // Error if (next < 0) { return(null); } // create DocumentNo StringBuilder doc = new StringBuilder(); if (prefix != null && prefix.Length > 0) { doc.Append(prefix); } doc.Append(next); if (suffix != null && suffix.Length > 0) { doc.Append(suffix); } String documentNo = doc.ToString(); return(documentNo); }
/// <summary> /// Process Document Value Workflow /// </summary> /// <param name="document">document</param> /// <param name="AD_Table_ID">table</param> /// <returns>true if WF started</returns> public bool Process(PO document, int AD_Table_ID) { _noCalled++; MWorkflow[] wfs = MWorkflow.GetDocValue(document.GetCtx(), document.GetAD_Client_ID(), AD_Table_ID); if (wfs == null || wfs.Length == 0) { return(false); } bool started = false; for (int i = 0; i < wfs.Length; i++) { MWorkflow wf = wfs[i]; // We have a Document Workflow String logic = wf.GetDocValueLogic(); if (logic == null || logic.Length == 0) { log.Severe("Workflow has no Logic - " + wf.GetName()); continue; } // Re-check: Document must be same Client as workflow if (wf.GetAD_Client_ID() != document.GetAD_Client_ID()) { continue; } // Check Logic bool sql = logic.StartsWith("SQL="); if (sql && !TestStart(wf, document)) { log.Fine("SQL Logic evaluated to false (" + logic + ")"); continue; } if (!sql && !Evaluator.EvaluateLogic(document, logic)) { log.Fine("Logic evaluated to false (" + logic + ")"); continue; } if (document.Get_Trx() != null) { ManageSkippedWF.Add(document.Get_Trx().SetUniqueTrxName(Trx.CreateTrxName("WFDV")), document); log.Severe("Not started: " + wf); continue; } // Start Workflow log.Fine(logic); int AD_Process_ID = 305; // HARDCODED ProcessInfo pi = new ProcessInfo(wf.GetName(), AD_Process_ID, AD_Table_ID, document.Get_ID()); pi.SetAD_User_ID(document.GetCtx().GetAD_User_ID()); pi.SetAD_Client_ID(document.GetAD_Client_ID()); // vinay bhatt for window id pi.SetAD_Window_ID(document.GetAD_Window_ID()); // wf.GetCtx().SetContext("#AD_Client_ID", pi.GetAD_Client_ID().ToString()); if (wf.Start(pi) != null) { log.Config(wf.GetName()); _noStarted++; started = true; } } return(started); }