private boolean updateCalculatedGoals(){
  if (!MEASURETYPE_Calculated.equals(getMeasureType()))   return false;
  MGoal[] goals=MGoal.getMeasureGoals(getCtx(),getPA_Measure_ID());
  for (int i=0; i < goals.length; i++) {
    MGoal goal=goals[i];
    MRole role=null;
    if (goal.getAD_Role_ID() != 0)     role=MRole.get(getCtx(),goal.getAD_Role_ID());
 else     if (goal.getAD_User_ID() != 0) {
      MUser user=MUser.get(getCtx(),goal.getAD_User_ID());
      MRole[] roles=user.getRoles(goal.getAD_Org_ID());
      if (roles.length > 0)       role=roles[0];
    }
    if (role == null)     role=MRole.getDefault(getCtx(),false);
    MMeasureCalc mc=MMeasureCalc.get(getCtx(),getPA_MeasureCalc_ID());
    if (mc == null || mc.get_ID() == 0 || mc.get_ID() != getPA_MeasureCalc_ID()) {
      log.log(Level.SEVERE,"Not found PA_MeasureCalc_ID=" + getPA_MeasureCalc_ID());
      return false;
    }
    String sql=mc.getSqlPI(goal.getRestrictions(false),goal.getMeasureScope(),getMeasureDataType(),null,role);
    BigDecimal ManualActual=DB.getSQLValueBD(null,sql,new Object[]{});
    if (ManualActual == null) {
      ManualActual=Env.ZERO;
      log.fine("No Value = " + sql);
    }
    goal.setMeasureActual(ManualActual);
    goal.save(get_TrxName());
  }
  return true;
}

private boolean updateCalculatedGoals ( ) { if ( ! MEASURETYPE_Calculated . equals ( getMeasureType ( ) ) ) return false ; MGoal [ ] goals = MGoal . getMeasureGoals ( getCtx ( ) , getPA_Measure_ID ( ) ) ; for ( int i = 0 ; i < goals . length ; i ++ ) { MGoal goal = goals [ i ] ; MRole role = null ; if ( goal . getAD_Role_ID ( ) != 0 ) role = MRole . get ( getCtx ( ) , goal . getAD_Role_ID ( ) ) ; else if ( goal . getAD_User_ID ( ) != 0 ) { MUser user = MUser . get ( getCtx ( ) , goal . getAD_User_ID ( ) ) ; MRole [ ] roles = user . getRoles ( goal . getAD_Org_ID ( ) ) ; if ( roles . length > 0 ) role = roles [ 0 ] ; } if ( role == null ) role = MRole . getDefault ( getCtx ( ) , false ) ; MMeasureCalc mc = MMeasureCalc . get ( getCtx ( ) , getPA_MeasureCalc_ID ( ) ) ; if ( mc == null || mc . get_ID ( ) == 0 || mc . get_ID ( ) != getPA_MeasureCalc_ID ( ) ) { log . log ( Level . SEVERE , "Not found PA_MeasureCalc_ID=" + getPA_MeasureCalc_ID ( ) ) ; return false ; } String sql = mc . getSqlPI ( goal . getRestrictions ( false ) , goal . getMeasureScope ( ) , getMeasureDataType ( ) , null , role ) ; BigDecimal ManualActual = DB . getSQLValueBD ( null , sql , new Object [ ] { } ) ; if ( ManualActual == null ) { ManualActual = Env . ZERO ; log . fine ( "No Value = " + sql ) ; } goal . setMeasureActual ( ManualActual ) ; goal . save ( get_TrxName ( ) ) ; } return true ; }
update / save goals with calculation
