1 27 28 29 package com.sun.ebank.web; 30 31 import com.sun.ebank.util.*; 32 import com.sun.ebank.ejb.account.AccountController; 33 import com.sun.ebank.ejb.tx.TxController; 34 import com.sun.ebank.ejb.exception.*; 35 import java.util.*; 36 import java.rmi.RemoteException ; 37 import java.math.BigDecimal ; 38 39 40 public class AccountHistoryBean { 41 private BigDecimal credits; 42 private BigDecimal debits; 43 private BigDecimal beginningBalance; 44 private BigDecimal endingBalance; 45 private String accountId; 46 private int date; 47 private int activityView; 48 private int sortOption; 49 private int sinceMonth; 50 private int sinceDay; 51 private int beginMonth; 52 private int beginDay; 53 private int endMonth; 54 private int endDay; 55 private int year; 56 private ArrayList selectedTransactions; 57 private AccountDetails selectedAccount; 58 private BeanManager beanManager; 59 private CustomerBean customerBean; 60 61 public AccountHistoryBean() { 62 credits = null; 63 debits = null; 64 beginningBalance = null; 65 endingBalance = null; 66 selectedAccount = null; 67 beanManager = null; 68 customerBean = null; 69 selectedTransactions = null; 70 date = 0; 71 activityView = 0; 72 sortOption = 0; 73 sinceMonth = 1; 74 sinceDay = 1; 75 beginMonth = 1; 76 beginDay = 1; 77 endMonth = 1; 78 endDay = 1; 79 year = 2003; 80 } 81 82 public void doTx() { 83 BigDecimal amount = new BigDecimal ("0.00"); 84 TxDetails td = null; 85 Date startDate = null; 86 Date endDate = null; 87 88 try { 89 switch (date) { 90 case 0: 91 startDate = 92 com.sun.ebank.util.DateHelper.getDate(year, sinceMonth, 93 sinceDay); 94 endDate = new Date(); 95 96 break; 97 98 case 1: 99 startDate = 100 com.sun.ebank.util.DateHelper.getDate(year, beginMonth, 101 beginDay); 102 endDate = 103 com.sun.ebank.util.DateHelper.getDate(year, endMonth, endDay); 104 105 break; 106 } 107 108 ArrayList transactions = 109 beanManager.getTxController() 110 .getTxsOfAccount(startDate, endDate, accountId); 111 112 switch (sortOption) { 113 case 0: 114 Collections.sort(transactions, 115 new Comparator() { 116 public int compare(Object o1, Object o2) { 117 return (((TxDetails) o1).getTimeStamp().compareTo(((TxDetails) o2).getTimeStamp())); 118 } 119 }); 120 121 122 break; 123 124 case 1: 125 Collections.sort(transactions, 126 new Comparator() { 127 public int compare(Object o1, Object o2) { 128 return (((TxDetails) o2).getTimeStamp().compareTo(((TxDetails) o1).getTimeStamp())); 129 } 130 }); 131 132 133 break; 134 135 case 2: 136 Collections.sort(transactions, 137 new Comparator() { 138 public int compare(Object o1, Object o2) { 139 return (((TxDetails) o1).getDescription().compareTo(((TxDetails) o2).getDescription())); 140 } 141 }); 142 143 144 break; 145 146 case 3: 147 Collections.sort(transactions, 148 new Comparator() { 149 public int compare(Object o1, Object o2) { 150 return (((TxDetails) o1).getAmount().compareTo(((TxDetails) o2).getAmount())); 151 } 152 }); 153 154 155 break; 156 } 157 158 credits = new BigDecimal ("0.00"); 159 debits = new BigDecimal ("0.00"); 160 customerBean.setAccount(accountId); 161 selectedAccount = customerBean.getAccountDetails(); 162 beginningBalance = selectedAccount.getBalance(); 163 endingBalance = selectedAccount.getBalance(); 164 165 boolean isCreditAcct = false; 166 167 if (selectedAccount.getType() 168 .equals("Credit")) { 169 isCreditAcct = true; 170 } 171 172 Iterator i = transactions.iterator(); 173 174 if (i.hasNext()) { 175 td = (TxDetails) i.next(); 176 beginningBalance = td.getBalance() 177 .subtract(td.getAmount()); 178 } 179 180 i = transactions.iterator(); 181 182 if (i.hasNext()) { 183 Debug.print("adding to credits and debits."); 184 185 while (i.hasNext()) { 186 td = (TxDetails) i.next(); 187 amount = td.getAmount(); 188 189 if (isCreditAcct) { 190 if (amount.floatValue() < 0) { 191 credits = credits.add(amount); 192 } else { 193 debits = debits.subtract(amount); 194 } 195 } else { 196 if (amount.floatValue() > 0) { 197 Debug.print("Adding " + amount + "to credits."); 198 credits = credits.add(amount); 199 } else { 200 Debug.print("Subtracting " + amount + 201 "from debits."); 202 debits = debits.subtract(amount); 203 } 204 } 205 } 206 } 207 208 if (td != null) { 209 endingBalance = td.getBalance(); 210 } 211 212 selectedTransactions = new ArrayList(); 213 i = transactions.iterator(); 214 215 if (i.hasNext()) { 216 switch (activityView) { 217 case 0: 218 219 while (i.hasNext()) { 220 td = (TxDetails) i.next(); 221 selectedTransactions.add(td); 222 } 223 224 break; 225 226 case 1: 227 228 while (i.hasNext()) { 229 td = (TxDetails) i.next(); 230 231 if (isCreditAcct) { 232 if (td.getAmount() 233 .floatValue() < 0) { 234 selectedTransactions.add(td); 235 } 236 } else { 237 if (td.getAmount() 238 .floatValue() > 0) { 239 selectedTransactions.add(td); 240 } 241 } 242 } 243 244 break; 245 246 case 2: 247 248 while (i.hasNext()) { 249 td = (TxDetails) i.next(); 250 251 if (isCreditAcct) { 252 if (td.getAmount() 253 .floatValue() > 0) { 254 selectedTransactions.add(td); 255 } 256 } else { 257 if (td.getAmount() 258 .floatValue() < 0) { 259 selectedTransactions.add(td); 260 } 261 } 262 } 263 264 break; 265 } 266 } else { 267 Debug.print("No matching transactions."); 268 } 269 } catch (InvalidParameterException e) { 270 } catch (RemoteException e) { 271 Debug.print("Couldn't access enterprise bean: " + e.getMessage()); 272 } 273 } 274 275 public BigDecimal getCredits() { 276 return credits; 277 } 278 279 public BigDecimal getDebits() { 280 return debits; 281 } 282 283 public BigDecimal getBeginningBalance() { 284 return beginningBalance; 285 } 286 287 public BigDecimal getEndingBalance() { 288 return endingBalance; 289 } 290 291 public Collection getTransactions() { 292 return selectedTransactions; 293 } 294 295 public AccountDetails getSelectedAccount() { 296 return selectedAccount; 297 } 298 299 public void setBeanManager(BeanManager beanManager) { 300 this.beanManager = beanManager; 301 } 302 303 public void setCustomerBean(CustomerBean customerBean) { 304 this.customerBean = customerBean; 305 } 306 307 public void setAccountId(String accountId) { 308 this.accountId = accountId; 309 } 310 311 public void setDate(int date) { 312 this.date = date; 313 } 314 315 public void setYear(int year) { 316 this.year = year; 317 } 318 319 public void setBeginMonth(int beginMonth) { 320 this.beginMonth = beginMonth; 321 } 322 323 public void setBeginDay(int beginDay) { 324 this.beginDay = beginDay; 325 } 326 327 public void setEndMonth(int endMonth) { 328 this.endMonth = endMonth; 329 } 330 331 public void setEndDay(int endDay) { 332 this.endDay = endDay; 333 } 334 335 public void setSinceMonth(int sinceMonth) { 336 this.sinceMonth = sinceMonth; 337 } 338 339 public void setSinceDay(int sinceDay) { 340 this.sinceDay = sinceDay; 341 } 342 343 public void setActivityView(int activityView) { 344 this.activityView = activityView; 345 } 346 347 public void setSortOption(int sortOption) { 348 this.sortOption = sortOption; 349 } 350 } 351 | Popular Tags |