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.DB; 21 22 28 public class ImportBankStatement extends SvrProcess 29 { 30 31 private int m_AD_Client_ID = 0; 32 33 private int m_AD_Org_ID = 0; 34 35 private int m_C_BankAccount_ID = 0; 36 37 private boolean m_deleteOldImported = false; 38 39 42 protected void prepare() 43 { 44 ProcessInfoParameter[] para = getParameter(); 45 for (int i = 0; i < para.length; i++) 46 { 47 String name = para[i].getParameterName(); 48 if (para[i].getParameter() == null) 49 ; 50 else if (name.equals("AD_Client_ID")) 51 m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue(); 52 else if (name.equals("AD_Org_ID")) 53 m_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue(); 54 else if (name.equals("C_BankAccount_ID")) 55 m_C_BankAccount_ID = ((BigDecimal)para[i].getParameter()).intValue(); 56 else if (name.equals("DeleteOldImported")) 57 m_deleteOldImported = "Y".equals(para[i].getParameter()); 58 else 59 log.error("prepare - Unknown Parameter: " + name); 60 } 61 } 63 64 69 protected String doIt() throws java.lang.Exception 70 { 71 StringBuffer sql = null; 72 int no = 0; 73 String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; 74 75 77 if (m_deleteOldImported) 79 { 80 sql = new StringBuffer ("DELETE I_BankStatement " 81 + "WHERE I_IsImported='Y'").append (clientCheck); 82 no = DB.executeUpdate (sql.toString ()); 83 log.debug ("doIt - Delete Old Impored =" + no); 84 } 85 86 sql = new StringBuffer ("UPDATE I_BankStatement " 88 + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append (")," 89 + " AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append ("),"); 90 sql.append(" IsActive = COALESCE (IsActive, 'Y')," 91 + " Created = COALESCE (Created, SysDate)," 92 + " CreatedBy = COALESCE (CreatedBy, 0)," 93 + " Updated = COALESCE (Updated, SysDate)," 94 + " UpdatedBy = COALESCE (UpdatedBy, 0)," 95 + " I_ErrorMsg = NULL," 96 + " I_IsImported = 'N' " 97 + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); 98 no = DB.executeUpdate (sql.toString ()); 99 log.info ("doIt - Reset=" + no); 100 101 sql = new StringBuffer ("UPDATE I_BankStatement o " 102 + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" 103 + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" 104 + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" 105 + " AND I_IsImported<>'Y'").append (clientCheck); 106 no = DB.executeUpdate (sql.toString ()); 107 if (no != 0) 108 log.warn ("doIt - Invalid Org=" + no); 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 throw new IllegalStateException ("Not implemented yet"); 124 } 126 } | Popular Tags |