private int findPLV(int M_PriceList_ID){
  Timestamp priceDate=null;
  String dateStr=Env.getContext(Env.getCtx(),p_WindowNo,"DateOrdered");
  if (dateStr != null && dateStr.length() > 0)   priceDate=Env.getContextAsDate(Env.getCtx(),p_WindowNo,"DateOrdered");
 else {
    dateStr=Env.getContext(Env.getCtx(),p_WindowNo,"DateInvoiced");
    if (dateStr != null && dateStr.length() > 0)     priceDate=Env.getContextAsDate(Env.getCtx(),p_WindowNo,"DateInvoiced");
  }
  if (priceDate == null)   priceDate=new Timestamp(System.currentTimeMillis());
  log.config("M_PriceList_ID=" + M_PriceList_ID + " - "+ priceDate);
  int retValue=0;
  String sql="SELECT plv.M_PriceList_Version_ID, plv.ValidFrom " + "FROM M_PriceList pl, M_PriceList_Version plv " + "WHERE pl.M_PriceList_ID=plv.M_PriceList_ID"+ " AND plv.IsActive='Y'"+ " AND pl.M_PriceList_ID=? "+ "ORDER BY plv.ValidFrom DESC";
  try {
    PreparedStatement pstmt=DB.prepareStatement(sql,null);
    pstmt.setInt(1,M_PriceList_ID);
    ResultSet rs=pstmt.executeQuery();
    while (rs.next() && retValue == 0) {
      Timestamp plDate=rs.getTimestamp(2);
      if (!priceDate.before(plDate))       retValue=rs.getInt(1);
    }
    rs.close();
    pstmt.close();
  }
 catch (  SQLException e) {
    log.log(Level.SEVERE,sql,e);
  }
  Env.setContext(Env.getCtx(),p_WindowNo,"M_PriceList_Version_ID",retValue);
  return retValue;
}

private int findPLV ( int M_PriceList_ID ) { Timestamp priceDate = null ; String dateStr = Env . getContext ( Env . getCtx ( ) , p_WindowNo , "DateOrdered" ) ; if ( dateStr != null && dateStr . length ( ) > 0 ) priceDate = Env . getContextAsDate ( Env . getCtx ( ) , p_WindowNo , "DateOrdered" ) ; else { dateStr = Env . getContext ( Env . getCtx ( ) , p_WindowNo , "DateInvoiced" ) ; if ( dateStr != null && dateStr . length ( ) > 0 ) priceDate = Env . getContextAsDate ( Env . getCtx ( ) , p_WindowNo , "DateInvoiced" ) ; } if ( priceDate == null ) priceDate = new Timestamp ( System . currentTimeMillis ( ) ) ; log . config ( "M_PriceList_ID=" + M_PriceList_ID + " - " + priceDate ) ; int retValue = 0 ; String sql = "SELECT plv.M_PriceList_Version_ID, plv.ValidFrom " + "FROM M_PriceList pl, M_PriceList_Version plv " + "WHERE pl.M_PriceList_ID=plv.M_PriceList_ID" + " AND plv.IsActive='Y'" + " AND pl.M_PriceList_ID=? " + "ORDER BY plv.ValidFrom DESC" ; try { PreparedStatement pstmt = DB . prepareStatement ( sql , null ) ; pstmt . setInt ( 1 , M_PriceList_ID ) ; ResultSet rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) && retValue == 0 ) { Timestamp plDate = rs . getTimestamp ( 2 ) ; if ( ! priceDate . before ( plDate ) ) retValue = rs . getInt ( 1 ) ; } rs . close ( ) ; pstmt . close ( ) ; } catch ( SQLException e ) { log . log ( Level . SEVERE , sql , e ) ; } Env . setContext ( Env . getCtx ( ) , p_WindowNo , "M_PriceList_Version_ID" , retValue ) ; return retValue ; }
find price list version and update context
