1    package com.instantbank.collections.ach;
2    
3    import javax.servlet.ServletException;
4    import javax.servlet.http.HttpServletRequest;
5    import java.util.Iterator;
6    import java.util.List;
7    import java.math.BigDecimal;
8    import com.instantbank.collections.collectionsActivities.ejb.ActionResultServices;
9    import com.instantbank.collections.companyInfo.ejb.CompanyServices;
10   import com.instantbank.collections.companyInfo.ejb.CompanyServicesHome;
11   import com.instantbank.collections.util.InstantbankException;
12   import com.instantbank.collections.util.LongWrapper;
13   import com.instantbank.collections.util.ServiceLocator;
14   
15   public class AchManagerBean {
16     private CompanyServices cservices;
17     private ActionResultServices aservices;
18     private HttpServletRequest req = null;
19     //* common variables
20     private String abaStatus = "0";
21     private String abaNumber = null;
22     //* ach clearing house variables
23     private long achcId = 0l;
24     private String postFlag = "1";
25     private String interFaceCode = "E";
26     private String batchDesc = null;
27     private String batchNum = null;
28     private String bankNumber = null;
29     private String destName = null;
30     private String originName = null;
31     private String origin = null;
32     private String lastChangedById = null;
33     private String lastChangedByDate = null;
34     private String currStatus = "A";
35     private long companySystemId = 1l;
36     private int iBatchNumber = 0;
37     //* ach payment variables
38     private BigDecimal achFeeAmount = null,
39       achPaymentAmount = null,
40       achTotalDraftAmount = null;
41     private String acctType = "27";
42     private String achAccountNumber = null;
43     private String achNameOnAccount = null;
44     private String abaBankName = null;
45     private String validateFlag = null;
46   
47   
48     public AchManagerBean() { }
49   
50   
51     public AchManagerBean(HttpServletRequest request) throws InstantbankException {
52       req = request;
53   
54     }
55   
56   
57     public long getAchcId() {
58       return this.achcId;
59     }
60   
61   
62     public String getBankNumber() {
63       return this.bankNumber;
64     }
65   
66   
67     public String getDestName() {
68       return this.destName;
69     }
70   
71   
72     public String getAbaNumber() {
73       return this.abaNumber;
74     }
75   
76   
77     public String getOriginName() {
78       return this.originName;
79     }
80   
81   
82     public String getOrigin() {
83       return this.origin;
84     }
85   
86   
87     public String getLastChangedById() {
88       return this.lastChangedById;
89     }
90   
91   
92     public String getLastChangedByDate() {
93       return this.lastChangedByDate;
94     }
95   
96   
97     public String getBatchNum() {
98       return this.batchNum;
99     }
100  
101  
102    public String getBatchDesc() {
103      return this.batchDesc;
104    }
105  
106  
107    public String getStatus() {
108      return this.currStatus;
109    }
110  
111  
112    public String getAbaStatus() {
113      return this.abaStatus;
114    }
115  
116  
117    public String getPostFlag() {
118      return this.postFlag;
119    }
120  
121  
122    public String getInterFaceCode() {
123      return this.interFaceCode;
124    }
125  
126  
127    public long getSystemId() {
128      return this.companySystemId;
129    }
130  
131  
132    public BigDecimal getAchPaymentAmount() {
133      return this.achPaymentAmount;
134    }
135  
136  
137    public BigDecimal getAchTotalDraftAmount() {
138      return this.achTotalDraftAmount;
139    }
140  
141  
142    public BigDecimal getAchFeeAmount() {
143      return this.achFeeAmount;
144    }
145  
146  
147    public String getAchAccountNumber() {
148      return this.achAccountNumber;
149    }
150  
151  
152    public String getAchNameOnAccount() {
153      return this.achNameOnAccount;
154    }
155  
156  
157    public String getAbaBankName() {
158      return this.abaBankName;
159    }
160  
161  
162    public String getAcctType() {
163      return this.acctType;
164    }
165  
166  
167    public String getValidateFlag() {
168      return this.validateFlag;
169    }
170  
171  
172    // Create a new ach xac
173    public void addAchXac() throws ServletException {
174      AchXac obj = buildAchXac(req);
175      long userId = ((Long)req.getSession().getAttribute("userId")).longValue();
176      AchXacDO dataObject = new AchXacDO(obj, -1, Long.parseLong(req.getParameter("system")),
177        userId, null);
178      try {
179        CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
180        CompanyServices cservices = home.create();
181        cservices.createDataObject(dataObject);
182        initAchClearValues();
183  
184      }
185      catch(Exception e) {
186        throw new ServletException(e);
187      }
188    }
189  
190    // Update an existing ach xac
191    public void updateAchXac() throws ServletException {
192      AchXac obj = buildAchXac(req);
193      long userId = ((Long)req.getSession().getAttribute("userId")).longValue();
194      long id = Long.parseLong((String)req.getParameter("xacId"));
195      if(id == -1) {
196        throw new ServletException("Missing primary key");
197      }
198      AchXacDO dataObject = new AchXacDO(obj, id, Long.parseLong(req.getParameter("system")),
199        userId, null);
200      try {
201        CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
202        CompanyServices cservices = home.create();
203        cservices.updateDataObject(dataObject);
204        initAchClearValues();
205  
206      }
207      catch(Exception e) {
208        throw new ServletException(e);
209      }
210    }
211  
212  
213    public static AchXac buildAchXac(HttpServletRequest request) {
214      return new AchXac(request.getParameter("xacCode"), request.getParameter("xacDesc"),
215        request.getParameter("feeIndicator"), request.getParameter("xacStatus"));
216    }
217  
218  //* the following methods are for the clearing account process
219    public void addClearingHouse(long theCompanyid, long theUserid) throws ServletException {
220      setAchClearValues();
221      /*if (validateAba(this.abaNumber))    12092002 tjm - not required on this screen per Diana & Kathy
222         {*/
223      ClearingHouse ch = new ClearingHouse(this.interFaceCode,
224        this.destName,
225        this.abaNumber,
226        this.originName,
227        this.origin,
228        this.currStatus,
229        this.iBatchNumber,
230        this.batchDesc,
231        this.bankNumber);
232      ClearingHouseDO dataObject = new ClearingHouseDO(ch, -1, theCompanyid, this.companySystemId, theUserid, null);
233      try {
234        CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
235        CompanyServices cservices = home.create();
236        cservices.createDataObject(dataObject);
237        initAchClearValues();
238  
239      }
240      catch(Exception e) {
241        throw new ServletException(e);
242      }
243      //}
244    }
245  
246  
247    public void updateClearingHouse(long theCompanyid, long theUserid)
248       throws ServletException {
249      setAchClearValues();
250      /* if (validateAba(this.abaNumber))    12092002 tjm - not required on this screen per Diana & Kathy
251         {*/
252      ClearingHouse ch = new ClearingHouse(this.interFaceCode,
253        this.destName,
254        this.abaNumber,
255        this.originName,
256        this.origin,
257        this.currStatus,
258        this.iBatchNumber,
259        this.batchDesc,
260        this.bankNumber);
261      ClearingHouseDO dataObject = new ClearingHouseDO(ch, this.achcId, theCompanyid, this.companySystemId, theUserid, null);
262      try {
263        CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
264        CompanyServices cservices = home.create();
265        cservices.updateDataObject(dataObject);
266        initAchClearValues();
267      }
268      catch(Exception e) {
269        throw new ServletException(e);
270      }
271      //}
272    }
273  
274  
275    public void removeClearingHouse()
276       throws InstantbankException {
277      System.out.println("debug - remove an ach");
278  
279      synchronized(this) {
280      }
281    }
282  
283  
284    public void setAchClearValues() {
285      String strAchcid = req.getParameter("achcid");
286      this.achcId = Long.parseLong(strAchcid);
287      this.abaNumber = req.getParameter("immediateDestination");
288      this.interFaceCode = req.getParameter("interfacecode");
289      if(this.interFaceCode.compareTo("E") == 0) {
290        this.batchDesc = null;
291        this.batchNum = null;
292      }
293      else {
294        this.interFaceCode = "I";
295        this.batchDesc = (String)req.getParameter("batchDescription");
296        this.batchNum = (String)req.getParameter("batchNumber");
297      }
298      this.batchNum = (String)req.getParameter("batchNumber");
299      if(this.batchNum.length() > 0) {
300        this.iBatchNumber = Integer.parseInt(this.batchNum);
301      }
302      else {
303        this.iBatchNumber = 0;
304      }
305      this.abaStatus = "0";
306      this.postFlag = req.getParameter("postFlag");
307      this.bankNumber = req.getParameter("bankNumber");
308      this.destName = req.getParameter("immediateDestinationName");
309      this.originName = req.getParameter("immediateOriginName");
310      this.origin = req.getParameter("immediateOrigin");
311      this.lastChangedById = req.getParameter("lastChangedById");
312      this.lastChangedByDate = req.getParameter("lastChangedByDate");
313      this.currStatus = req.getParameter("currStatus");
314      String companySystemStr = req.getParameter("companySystemId");
315      this.companySystemId = Long.parseLong(companySystemStr);
316    }
317  
318  
319    public void initAchClearValues() {
320      this.abaStatus = "0";
321      this.achcId = 0l;
322      this.postFlag = "1";
323      this.interFaceCode = "E";
324      this.abaNumber = null;
325      this.batchDesc = null;
326      this.batchNum = null;
327      this.bankNumber = null;
328      this.destName = null;
329      this.originName = null;
330      this.origin = null;
331      this.lastChangedById = null;
332      this.lastChangedByDate = null;
333      this.currStatus = "A";
334      this.companySystemId = 1l;
335    }
336    //* the following methods are for the Ach Payment process
337  
338    public void achPaymentValidate(String theAbanumber) throws ServletException {
339      this.abaNumber = theAbanumber;
340      setAchPaymentValues();
341      if(theAbanumber.length() < 9) {
342        this.abaStatus = "2";
343      }
344      else {
345        try {
346          List keys = AchDAO.genericQuery(AchAbaDO.getFindByRoutingNumberSQL() + theAbanumber);
347          if(keys.size() > 0) {
348            this.abaStatus = "1";
349            for(Iterator walker = keys.iterator(); walker.hasNext(); ) {
350              LongWrapper lw = (LongWrapper)walker.next();
351              AchAbaDO achAbaDO = new AchAbaDO(lw.getValue());
352              AchDAO.populateByPrimaryKey(achAbaDO);
353              this.abaBankName = achAbaDO.getAchAba().getCustomerName();
354            }
355            return;
356          }
357          else {
358            this.abaStatus = "2";
359            this.abaBankName = " ";
360            return;
361          }
362        }
363        catch(Exception e) {
364          throw new ServletException(e);
365        }
366      }
367    }
368  
369  
370    public void setAchPaymentValues() {
371      String strPayment;
372  
373      this.abaBankName = req.getParameter("abaBankName");
374      this.acctType = req.getParameter("acctType");
375      this.abaStatus = "0";
376      this.validateFlag = req.getParameter("validateFlag");
377      strPayment = (String)req.getParameter("achPaymentAmount");
378      if(strPayment == null || strPayment.length() < 1) {
379        this.achPaymentAmount = new BigDecimal(0);
380      }
381      else {
382        this.achPaymentAmount = new BigDecimal(strPayment);
383      }
384      strPayment = (String)req.getParameter("achFeeAmount");
385      if(strPayment == null || strPayment.length() < 1) {
386        this.achFeeAmount = new BigDecimal(0);
387      }
388      else {
389        this.achFeeAmount = new BigDecimal(strPayment);
390      }
391      strPayment = (String)req.getParameter("achTotalDraftAmount");
392      if(strPayment == null || strPayment.length() < 1) {
393        this.achTotalDraftAmount = new BigDecimal(0);
394      }
395      else {
396        this.achTotalDraftAmount = new BigDecimal(strPayment);
397      }
398      this.achNameOnAccount = req.getParameter("achNameOnAccount");
399      this.achAccountNumber = req.getParameter("achAccountNumber");
400  
401    }
402  
403  
404    public boolean validateAba(String theAbanumber) throws ServletException {
405      try {
406        List keys = AchDAO.genericQuery(AchAbaDO.getFindByRoutingNumberSQL() + theAbanumber);
407        if(keys.size() > 0) {
408          this.abaStatus = "1";
409          return true;
410        }
411        else {
412          this.abaStatus = "2";
413          return false;
414        }
415      }
416      catch(Exception e) {
417        throw new ServletException(e);
418      }
419    }
420  
421  }
422