Ejemplo n.º 1
0
 /**
  * Return Array of Regions of Country
  *
  * @param ctx context
  * @param C_Country_ID country
  * @return MRegion Array
  */
 public static MRegion[] getRegions(Ctx ctx, int C_Country_ID) {
   if (s_regions.isEmpty()) loadAllRegions(ctx);
   ArrayList<MRegion> list = new ArrayList<MRegion>();
   Iterator<MRegion> it = s_regions.values().iterator();
   while (it.hasNext()) {
     MRegion r = it.next();
     if (r.getC_Country_ID() == C_Country_ID) list.add(r);
   }
   //  Sort it
   MRegion[] retValue = new MRegion[list.size()];
   list.toArray(retValue);
   Arrays.sort(retValue, new MRegion(ctx, 0, null));
   return retValue;
 } //	getRegions
Ejemplo n.º 2
0
  /**
   * gets all Periods in the Range
   *
   * @param startPeriod
   * @param endPeriod
   * @param calendar_ID
   * @return MPeriod[]
   */
  public static MPeriod[] getAllPeriodsInRange(
      MPeriod startPeriod, MPeriod endPeriod, int calendar_ID, Ctx ctx, Trx trx) {
    if ((startPeriod.getC_Calendar_ID() != calendar_ID)
        || (endPeriod.getC_Calendar_ID() != calendar_ID)) {
      log.saveError("Error", "Periods do not belong to the calendar");
      return null;
    }

    ArrayList<MPeriod> periods = new ArrayList<MPeriod>();
    String sql =
        "SELECT * FROM C_Period WHERE "
            + "C_Period.IsActive='Y' AND PeriodType='S' "
            + "AND C_Period.C_Year_ID IN "
            + "(SELECT C_Year_ID FROM C_Year WHERE C_Year.C_Calendar_ID = ? ) "
            + // calendar_ID
            "AND ((C_Period.C_Year_ID * 1000) + C_Period.PeriodNo) BETWEEN"
            + " (? * 1000 + ?) AND (? * 1000 + ? )"
            + // start Period year ID, Period Number , End Period Year ID, Period Number
            " ORDER BY C_Period.C_Year_ID ASC, C_Period.PeriodNo ASC";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, trx);
      pstmt.setInt(1, calendar_ID);
      pstmt.setInt(2, startPeriod.getC_Year_ID());
      pstmt.setInt(3, startPeriod.getPeriodNo());
      pstmt.setInt(4, endPeriod.getC_Year_ID());
      pstmt.setInt(5, endPeriod.getPeriodNo());
      rs = pstmt.executeQuery();
      while (rs.next()) periods.add(new MPeriod(ctx, rs, trx));
    } catch (Exception e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
    MPeriod[] retValue = new MPeriod[periods.size()];
    periods.toArray(retValue);
    return retValue;
  }
Ejemplo n.º 3
0
 /**
  * Get Period Control
  *
  * @param requery requery
  * @return period controls
  */
 public MPeriodControl[] getPeriodControls(boolean requery) {
   if (m_controls != null && !requery) return m_controls;
   //
   ArrayList<MPeriodControl> list = new ArrayList<MPeriodControl>();
   String sql = "SELECT * FROM C_PeriodControl " + "WHERE C_Period_ID=?";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, get_Trx());
     pstmt.setInt(1, getC_Period_ID());
     rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MPeriodControl(getCtx(), rs, get_Trx()));
   } catch (Exception e) {
     log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeResultSet(rs);
     DB.closeStatement(pstmt);
   }
   m_controls = new MPeriodControl[list.size()];
   list.toArray(m_controls);
   return m_controls;
 } //	getPeriodControls