static public MPrintFormat createFromTable(Properties ctx,int AD_Table_ID,int AD_PrintFormat_ID){
  int AD_Client_ID=Env.getAD_Client_ID(ctx);
  s_log.info("AD_Table_ID=" + AD_Table_ID + " - AD_Client_ID="+ AD_Client_ID);
  MPrintFormat pf=new MPrintFormat(ctx,AD_PrintFormat_ID,null);
  pf.setAD_Table_ID(AD_Table_ID);
  String sql="SELECT TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID,"+ " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID,"+ " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID "+ "FROM AD_Table t, AD_Client c"+ " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')"+ " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')"+ " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y'),"+ " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp "+ "WHERE t.AD_Table_ID=? AND c.AD_Client_ID=?"+ " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
  boolean error=true;
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,null);
    pstmt.setInt(1,AD_Table_ID);
    pstmt.setInt(2,AD_Client_ID);
    rs=pstmt.executeQuery();
    if (rs.next()) {
      String TableName=rs.getString(1);
      String ColumnName=TableName + "_ID";
      String s=ColumnName;
      if (!ColumnName.equals("T_Report_ID")) {
        s=Msg.translate(ctx,ColumnName);
        if (ColumnName.equals(s))         s=Msg.translate(ctx,TableName);
      }
      int count=rs.getInt(2);
      if (count > 0)       s+="_" + (count + 1);
      pf.setName(s);
      pf.setAD_PrintColor_ID(rs.getInt(3));
      pf.setAD_PrintFont_ID(rs.getInt(4));
      pf.setAD_PrintPaper_ID(rs.getInt(5));
      error=false;
    }
 else     s_log.log(Level.SEVERE,"No info found " + AD_Table_ID);
  }
 catch (  SQLException e) {
    s_log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  if (error)   return null;
  if (!pf.save())   return null;
  pf.setItems(createItems(ctx,pf));
  return pf;
}

static public MPrintFormat createFromTable ( Properties ctx , int AD_Table_ID , int AD_PrintFormat_ID ) { int AD_Client_ID = Env . getAD_Client_ID ( ctx ) ; s_log . info ( "AD_Table_ID=" + AD_Table_ID + " - AD_Client_ID=" + AD_Client_ID ) ; MPrintFormat pf = new MPrintFormat ( ctx , AD_PrintFormat_ID , null ) ; pf . setAD_Table_ID ( AD_Table_ID ) ; String sql = "SELECT TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID " + "FROM AD_Table t, AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + "WHERE t.AD_Table_ID=? AND c.AD_Client_ID=?" + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'" ; boolean error = true ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , null ) ; pstmt . setInt ( 1 , AD_Table_ID ) ; pstmt . setInt ( 2 , AD_Client_ID ) ; rs = pstmt . executeQuery ( ) ; if ( rs . next ( ) ) { String TableName = rs . getString ( 1 ) ; String ColumnName = TableName + "_ID" ; String s = ColumnName ; if ( ! ColumnName . equals ( "T_Report_ID" ) ) { s = Msg . translate ( ctx , ColumnName ) ; if ( ColumnName . equals ( s ) ) s = Msg . translate ( ctx , TableName ) ; } int count = rs . getInt ( 2 ) ; if ( count > 0 ) s += "_" + ( count + 1 ) ; pf . setName ( s ) ; pf . setAD_PrintColor_ID ( rs . getInt ( 3 ) ) ; pf . setAD_PrintFont_ID ( rs . getInt ( 4 ) ) ; pf . setAD_PrintPaper_ID ( rs . getInt ( 5 ) ) ; error = false ; } else s_log . log ( Level . SEVERE , "No info found " + AD_Table_ID ) ; } catch ( SQLException e ) { s_log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( error ) return null ; if ( ! pf . save ( ) ) return null ; pf . setItems ( createItems ( ctx , pf ) ) ; return pf ; }
create mprintformat for table
