/** * Get Accessible Goals * * @param ctx context * @return array of goals */ public static MGoal[] getGoals(Ctx ctx) { ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo"; sql = MRole.getDefault(ctx, false) .addAccessSQL(sql, "PA_Goal", false, true); // RW to restrict Access PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeStatement(pstmt); DB.closeResultSet(rs); } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getGoals
/** * Get Accessible Goals * * @param ctx context * @return array of goals */ public static MGoal[] getGoals(Properties ctx) { ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo"; sql = Env.getUserRolePermissions(ctx) .addAccessSQL(sql, "PA_Goal", false, true); // RW to restrict Access PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.error(sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getGoals
/** * Get User Goals * * @param ctx context * @param AD_User_ID user * @return array of goals */ public static MGoal[] getUserGoals(Ctx ctx) { int AD_Role_ID = ctx.getAD_Role_ID(); MRole role = MRole.get(ctx, AD_Role_ID); int AD_User_ID = ctx.getAD_User_ID(); if (AD_User_ID < 0) return getTestGoals(ctx); ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal g " + "WHERE IsActive='Y'" + " AND AD_Client_ID=?" // #1 + " AND ("; if (!role.isWebStoreRole()) sql += " (AD_User_ID IS NULL AND AD_Role_ID IS NULL) OR "; sql += " AD_User_ID=?" // #2 + " OR EXISTS (SELECT * FROM AD_User_Roles ur " + "WHERE ?=ur.AD_User_ID AND g.AD_Role_ID=ur.AD_Role_ID AND ur.IsActive='Y')) " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); pstmt.setInt(1, ctx.getAD_Client_ID()); pstmt.setInt(2, AD_User_ID); pstmt.setInt(3, AD_User_ID); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getUserGoals
/** * Get Multiplier from Scope to Display * * @param goal goal * @return null if error or multiplier */ public static BigDecimal getMultiplier(MGoal goal) { String MeasureScope = goal.getMeasureScope(); String MeasureDisplay = goal.getMeasureDisplay(); if (MeasureDisplay == null || MeasureScope.equals(MeasureDisplay)) return Env.ONE; // 1:1 if (MeasureScope.equals(MEASURESCOPE_Total) || MeasureDisplay.equals(MEASUREDISPLAY_Total)) return null; // Error BigDecimal Multiplier = null; if (MeasureScope.equals(MEASURESCOPE_Year)) { if (MeasureDisplay.equals(MEASUREDISPLAY_Quarter)) Multiplier = new BigDecimal(1.0 / 4.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Month)) Multiplier = new BigDecimal(1.0 / 12.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Week)) Multiplier = new BigDecimal(1.0 / 52.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Day)) Multiplier = new BigDecimal(1.0 / 364.0); } else if (MeasureScope.equals(MEASURESCOPE_Quarter)) { if (MeasureDisplay.equals(MEASUREDISPLAY_Year)) Multiplier = new BigDecimal(4.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Month)) Multiplier = new BigDecimal(1.0 / 3.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Week)) Multiplier = new BigDecimal(1.0 / 13.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Day)) Multiplier = new BigDecimal(1.0 / 91.0); } else if (MeasureScope.equals(MEASURESCOPE_Month)) { if (MeasureDisplay.equals(MEASUREDISPLAY_Year)) Multiplier = new BigDecimal(12.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Quarter)) Multiplier = new BigDecimal(3.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Week)) Multiplier = new BigDecimal(1.0 / 4.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Day)) Multiplier = new BigDecimal(1.0 / 30.0); } else if (MeasureScope.equals(MEASURESCOPE_Week)) { if (MeasureDisplay.equals(MEASUREDISPLAY_Year)) Multiplier = new BigDecimal(52.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Quarter)) Multiplier = new BigDecimal(13.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Month)) Multiplier = new BigDecimal(4.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Day)) Multiplier = new BigDecimal(1.0 / 7.0); } else if (MeasureScope.equals(MEASURESCOPE_Day)) { if (MeasureDisplay.equals(MEASUREDISPLAY_Year)) Multiplier = new BigDecimal(364.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Quarter)) Multiplier = new BigDecimal(91.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Month)) Multiplier = new BigDecimal(30.0); else if (MeasureDisplay.equals(MEASUREDISPLAY_Week)) Multiplier = new BigDecimal(7.0); } return Multiplier; } // getMultiplier
/** * Get User Goals * * @param ctx context * @param AD_User_ID user * @return array of goals */ public static MGoal[] getUserGoals(Properties ctx, int AD_User_ID) { if (AD_User_ID < 0) return getTestGoals(ctx); ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal g " + "WHERE IsActive='Y'" + " AND AD_Client_ID=?" // #1 + " AND ((AD_User_ID IS NULL AND AD_Role_ID IS NULL)" + " OR AD_User_ID=?" // #2 + " OR EXISTS (SELECT * FROM AD_User_Roles ur " + "WHERE ur.AD_User_ID=? AND g.AD_Role_ID=ur.AD_Role_ID AND ur.IsActive='Y')) " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, Env.getAD_Client_ID(ctx)); pstmt.setInt(2, AD_User_ID); pstmt.setInt(3, AD_User_ID); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.error(sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getUserGoals