1 14 package org.compiere.process; 15 16 import java.sql.*; 17 import java.math.*; 18 19 import org.compiere.model.*; 20 import org.compiere.util.*; 21 22 30 public class DocumentTypeVerify extends SvrProcess 31 { 32 33 37 protected void prepare() 38 { 39 } 41 47 protected String doIt() throws Exception 48 { 49 createDocumentTypes(); 50 createPeriodControls(); 51 return ""; 52 } 54 57 private void createDocumentTypes() 58 { 59 String sql = "SELECT rl.Value, rl.Name " 60 + "FROM AD_Ref_List rl " 61 + "WHERE rl.AD_Reference_ID=183" 62 + " AND rl.IsActive='Y' AND NOT EXISTS" 63 + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)"; 64 PreparedStatement pstmt = null; 65 try 66 { 67 pstmt = DB.prepareCall(sql); 68 pstmt.setInt(1, getAD_Client_ID()); 69 ResultSet rs = pstmt.executeQuery(); 70 while (rs.next()) 71 { 72 String name = rs.getString(2); 73 MDocType dt = new MDocType (getCtx(), rs.getString(1), name); 74 if (dt.save()) 75 addLog (0, null, null, name); 76 else 77 addLog (0, null, null, "Not created: " + name); 78 } 79 rs.close(); 80 pstmt.close(); 81 pstmt = null; 82 } 83 catch (Exception e) 84 { 85 log.error("createDocumentTypes", e); 86 } 87 try 88 { 89 if (pstmt != null) 90 pstmt.close(); 91 pstmt = null; 92 } 93 catch (Exception e) 94 { 95 pstmt = null; 96 } 97 } 99 102 private void createPeriodControls() 103 { 104 String sql = "SELECT p.C_Period_ID, dt.DocBaseType " 105 + "FROM C_Period p" 106 + " FULL JOIN C_DocType dt ON (p.AD_Client_ID=dt.AD_Client_ID) " 107 + "WHERE p.AD_Client_ID=?" 108 + " AND NOT EXISTS" 109 + " (SELECT * FROM C_PeriodControl pc WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dt.DocBaseType)"; 110 PreparedStatement pstmt = null; 111 int counter = 0; 112 try 113 { 114 pstmt = DB.prepareCall(sql); 115 pstmt.setInt(1, getAD_Client_ID()); 116 ResultSet rs = pstmt.executeQuery(); 117 while (rs.next()) 118 { 119 MPeriodControl pc = new MPeriodControl (getCtx(), rs.getInt(1), rs.getString(2)); 120 if (pc.save()) 121 counter++; 122 } 123 rs.close(); 124 pstmt.close(); 125 pstmt = null; 126 } 127 catch (Exception e) 128 { 129 log.error("createPeriodControls", e); 130 } 131 try 132 { 133 if (pstmt != null) 134 pstmt.close(); 135 pstmt = null; 136 } 137 catch (Exception e) 138 { 139 pstmt = null; 140 } 141 addLog (0, null, new BigDecimal(counter), "@C_PeriodControl_ID@ @Created@"); 142 } 144 } | Popular Tags |