1 32 33 package com.knowgate.hipergate; 34 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 38 import com.knowgate.debug.DebugFile; 39 import com.knowgate.jdc.JDCConnection; 40 import com.knowgate.dataobjs.DB; 41 import com.knowgate.dataobjs.DBBind; 42 import com.knowgate.dataobjs.DBPersist; 43 44 49 50 public class BankAccount extends DBPersist { 51 public BankAccount() { 52 super(DB.k_bank_accounts, "BankAccount"); 53 } 54 55 61 public boolean delete (JDCConnection oConn) 62 throws SQLException { 63 Statement oStmt; 64 boolean bRetVal; 65 66 if (DebugFile.trace) { 67 DebugFile.writeln("Begin BankAccount.delete([Connection])"); 68 DebugFile.incIdent(); 69 } 70 71 if (DBBind.exists(oConn, DB.k_x_company_bank, "U")) { 72 oStmt = oConn.createStatement(); 73 74 if (DebugFile.trace) 75 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_company_bank + " WHERE " + DB.nu_bank_acc + "='" + getStringNull(DB.nu_bank_acc, "") + "' AND " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea, "") + "')"); 76 77 oStmt.executeUpdate("DELETE FROM " + DB.k_x_company_bank + " WHERE " + DB.nu_bank_acc + "='" + getStringNull(DB.nu_bank_acc, "") + "' AND " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea, "") + "'"); 78 oStmt.close(); 79 } 80 81 if (DBBind.exists(oConn, DB.k_x_contact_bank, "U")) { 82 oStmt = oConn.createStatement(); 83 84 if (DebugFile.trace) 85 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_contact_bank + " WHERE " + DB.nu_bank_acc + "='" + getStringNull(DB.nu_bank_acc, "") + "' AND " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea, "") + "')"); 86 87 oStmt.executeUpdate("DELETE FROM " + DB.k_x_contact_bank + " WHERE " + DB.nu_bank_acc + "='" + getStringNull(DB.nu_bank_acc, "") + "' AND " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea, "") + "'"); 88 oStmt.close(); 89 } 90 91 bRetVal = super.delete(oConn); 92 93 if (DebugFile.trace) { 94 DebugFile.decIdent(); 95 DebugFile.writeln("End BankAccount.delete() : " + String.valueOf(bRetVal)); 96 } 97 98 return bRetVal; 99 } 101 public String getString(String sKey) throws NullPointerException { 102 return AllVals.get(sKey).toString().trim(); 103 } 104 105 public String getStringNull(String sKey, String sDefault) { 106 Object oVal; 107 if (AllVals.containsKey(sKey)) { 108 oVal = AllVals.get(sKey); 109 if (null==oVal) 110 return sDefault; 111 else 112 return oVal.toString().trim(); 113 } 114 else 115 return sDefault; 116 } 117 118 124 public String format20() 125 throws NullPointerException , StringIndexOutOfBoundsException { 126 if (isNull(DB.nu_bank_acc)) 127 throw new NullPointerException ("BankAccount.format20() Bank account may not be null"); 128 else if (getString(DB.nu_bank_acc).length()!=20) 129 throw new StringIndexOutOfBoundsException ("BankAccount.format20 can only be called on 20 digits bank accounts"); 130 else { 131 String a = getString(DB.nu_bank_acc); 132 return a.substring(0,4)+" "+a.substring(4,8)+" "+a.substring(8,10)+" "+a.substring(10); 133 } 134 } 136 143 public String getBankAccountDC() 144 throws IllegalArgumentException ,NullPointerException { 145 if (isNull(DB.nu_bank_acc)) 146 throw new NullPointerException ("BankAccount.getBankAccountDC() Bank account may not be null"); 147 String sBankAcc = getString(DB.nu_bank_acc); 148 if (sBankAcc.length()!=20) 149 throw new IllegalArgumentException ("BankAccount.getBankAccountDC() Bank account must be of 20 characters"); 150 return BankAccount.getBankAccountDC(sBankAcc.substring(0,4),sBankAcc.substring(4,8), sBankAcc.substring(10)); 151 } 153 161 public static int getBankAccountCtrl(String sAccountNumber) 162 throws IllegalArgumentException ,NullPointerException { 163 int ccc; 164 int suma = 0; 165 int contpesos = 10; 166 int[] mintpesos = new int[]{0, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1}; 167 168 if (sAccountNumber.length()!=10) 169 throw new IllegalArgumentException ("BankAccount.getBankAccountCtrl() Bank account number must be 10 digits"); 170 171 for (int d=0; d<10; d++) { 172 suma += (mintpesos[contpesos] * Integer.parseInt(sAccountNumber.substring(d,1))); 173 contpesos-=1; 174 } 176 ccc = 11 - (suma % 11); 177 if (ccc==10) ccc=1; 178 if (ccc==11) ccc=0; 179 180 return ccc; 181 } 183 191 public static String getBankAccountDC(String sEntity, String sOffice, String sAccountNumber) 192 throws IllegalArgumentException ,NullPointerException { 193 if (sEntity.length()!=4) 194 throw new IllegalArgumentException ("BankAccount.getBankAccountDC() Bank Entity code must be 4 digits"); 195 if (sOffice.length()!=4) 196 throw new IllegalArgumentException ("BankAccount.getBankAccountDC() Bank office code must be 4 digits"); 197 return String.valueOf(getBankAccountCtrl("00" + sEntity + sOffice)) + String.valueOf(getBankAccountCtrl(sAccountNumber)); 198 } 200 203 public static final short ClassId = 8; 204 205 } 206 | Popular Tags |