/**
  * ************************************************************************ Create Missing
  * Document Types
  *
  * @param ctx context
  * @param AD_Client_ID client
  * @param sp server process
  * @param trx transaction
  */
 public static void createDocumentTypes(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) {
   s_log.info("AD_Client_ID=" + AD_Client_ID);
   String sql =
       "SELECT rl.Value, rl.Name "
           + "FROM AD_Ref_List rl "
           + "WHERE rl.AD_Reference_ID=183"
           + " AND rl.IsActive='Y' AND NOT EXISTS "
           + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, trx);
     pstmt.setInt(1, AD_Client_ID);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       String name = rs.getString(2);
       String value = rs.getString(1);
       s_log.config(name + "=" + value);
       MDocType dt = new MDocType(ctx, value, name, trx);
       if (dt.save()) {
         if (sp != null) sp.addLog(0, null, null, name);
         else s_log.fine(name);
       } else {
         if (sp != null) sp.addLog(0, null, null, "Not created: " + name);
         else s_log.warning("Not created: " + name);
       }
     }
   } catch (Exception e) {
     s_log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeResultSet(rs);
     DB.closeStatement(pstmt);
   }
 } //	createDocumentTypes
Example #2
0
 /**
  * After Save
  *
  * @param newRecord new
  * @param success success
  * @return success
  */
 @Override
 protected boolean afterSave(boolean newRecord, boolean success) {
   if (newRecord) {
     //	SELECT Value FROM AD_Ref_List WHERE AD_Reference_ID=183
     MDocType[] types = MDocType.getOfClient(getCtx());
     int count = 0;
     ArrayList<String> baseTypes = new ArrayList<String>();
     for (MDocType type : types) {
       String DocBaseType = type.getDocBaseType();
       if (baseTypes.contains(DocBaseType)) continue;
       MPeriodControl pc = new MPeriodControl(this, DocBaseType);
       if (pc.save()) count++;
       baseTypes.add(DocBaseType);
     }
     log.fine("PeriodControl #" + count);
   }
   return success;
 } //	afterSave