1    package com.instantbank.collections.collectionsActivities.ejb;
2    
3    import java.io.ByteArrayInputStream;
4    import java.io.PrintWriter;
5    import java.io.StringWriter;
6    import java.sql.Connection;
7    import java.sql.PreparedStatement;
8    import java.sql.ResultSet;
9    import java.sql.SQLException;
10   import java.sql.Statement;
11   import java.text.SimpleDateFormat;
12   import java.util.Date;
13   import java.util.Vector;
14   import javax.ejb.CreateException;
15   import javax.ejb.EJBContext;
16   import javax.ejb.SessionBean;
17   import javax.ejb.SessionContext;
18   import oracle.xml.parser.v2.DOMParser;
19   import oracle.xml.parser.v2.XMLDocument;
20   import oracle.xml.parser.v2.XMLElement;
21   import oracle.xml.parser.v2.XMLNode;
22   import oracle.xml.parser.v2.XMLText;
23   import oracle.xml.parser.v2.XSLException;
24   import org.w3c.dom.Element;
25   import org.w3c.dom.Node;
26   import org.w3c.dom.NodeList;
27   import java.math.BigDecimal;
28   import com.instantbank.collections.ach.AchDAO;
29   import com.instantbank.collections.ach.AchPmt;
30   import com.instantbank.collections.ach.AchPmtDO;
31   import com.instantbank.collections.ach.DataObject;
32   import com.instantbank.collections.commonQueuing.ejb.QueueServices;
33   import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
34   import com.instantbank.collections.companyInfo.ejb.CompanyServices;
35   import com.instantbank.collections.companyInfo.ejb.CompanyServicesHome;
36   import com.instantbank.collections.letters.ejb.LetterServices;
37   import com.instantbank.collections.letters.ejb.LetterServicesHome;
38   import com.instantbank.collections.util.DataAccess;
39   import com.instantbank.collections.util.InstantbankException;
40   import com.instantbank.collections.util.ServiceLocator;
41   import com.instantbank.collections.util.StringFormat;
42   import com.instantbank.collections.util.UniqueIDGenerator;
43   import com.instantbank.collections.util.XMLDataAccess;
44   import com.instantbank.collections.util.XMLUtils;
45   
46   public class ActionResultServicesBean
47       implements SessionBean {
48     private EJBContext context;
49   
50   
51     public void createDataObject(DataObject dataObject)
52        throws InstantbankException {
53       try {
54         AchDAO.create(dataObject);
55       }
56       catch(Exception e) {
57         e.printStackTrace();
58         setRollbackOnly();
59         throw new InstantbankException(e, "221001", "Failed to add DataObject: "
60           + dataObject.toString());
61       }
62     }
63   
64   
65     public void updateDataObject(DataObject dataObject)
66        throws InstantbankException {
67       try {
68         AchDAO.update(dataObject);
69       }
70       catch(Exception e) {
71         e.printStackTrace();
72         setRollbackOnly();
73         throw new InstantbankException(e, "221001", "Failed to update DataObject: "
74           + dataObject.toString());
75       }
76     }
77   
78   
79     public void removeDataObject(DataObject dataObject)
80        throws InstantbankException {
81       try {
82         AchDAO.remove(dataObject);
83       }
84       catch(Exception e) {
85         e.printStackTrace();
86         setRollbackOnly();
87         throw new InstantbankException(e, "221001", "Failed to remove DataObject: "
88           + dataObject.toString());
89       }
90     }
91   
92   
93     public ActionResultServicesBean() { }
94   
95   
96     public void ejbCreate() throws CreateException {
97       // TODO:  Add custom implementation.
98     }
99   
100  
101    public void ejbActivate() { }
102  
103  
104    public void ejbPassivate() { }
105  
106  
107    public void ejbRemove() { }
108  
109  
110    private int calculateGraceDays(String duedata, String graceDays, String prmType, NodeList calendarList)
111       throws XSLException {
112      String calendar = ((XMLNode)calendarList.item(0)).valueOf("days");
113      Long promiseDay = new Long(duedata.substring(3, 5));
114      Long promiseMonth = new Long(duedata.substring(0, 2));
115      Long promiseYear = new Long(duedata.substring(6, 10));
116      Long graceDaysL = new Long(graceDays);
117      int graceDaysI = graceDaysL.intValue();
118      int day;
119      int endOfYear;
120      int prmDay = promiseDay.intValue();
121      int prmYear = promiseYear.intValue();
122      int prmMonth = promiseMonth.intValue();
123      endOfYear = convertToJulian(prmYear, 12, 31) - convertToJulian(prmYear, 1, 1);
124  
125      if(prmType.equalsIgnoreCase("B")) {
126        day = convertToJulian(prmYear, prmMonth, prmDay) - convertToJulian(prmYear, 1, 1);
127        for(int i = 1; i <= graceDaysI; i++) {
128          if(day + 1 > endOfYear) {
129            day = 0;
130            calendar = ((XMLNode)calendarList.item(1)).valueOf("days");
131          }
132          if(!calendar.substring(day, day + 1).equalsIgnoreCase("P")) {
133            graceDaysI = graceDaysI + 1;
134          }
135          day = day + 1;
136        }
137      }
138  
139      return graceDaysI;
140    }
141  
142  
143    /*  This function converts the date into the respective julian date
144    *
145    */
146    private int convertToJulian(int year, int month, int day) {
147  
148      //Julian date constant
149      double IGREG = (14 + 31 * (10 + 12 * 1582));
150      int julianDay;
151      int ysgn = 1;
152      double jy = ysgn * year;
153      double ja;
154      double jm;
155      double jul;
156  
157  // Julian days formula
158      if(jy < 0) {
159        ++jy;
160      }
161      if(month > 2) {
162        jm = month + 1;
163      }
164      else {
165        --jy;
166        jm = month + 13;
167      }
168      jul = (365.25 * jy) + (30.6001 * jm) + day + 1720995;
169      if(day + 31 * (month + 12 * ysgn * year) >= IGREG) {
170        ja = (0.01 * jy);
171        jul += 2 - ja + (0.25 * ja);
172      }
173  
174      julianDay = (int)jul;
175      return julianDay;
176    }
177  
178  
179    public String getAction(Long actionId, Long companyId) throws InstantbankException {
180      String ActionStr;
181      String actionXmlString;
182      XMLDataAccess da = null;
183      XMLDocument doc;
184      Node node;
185      String ResultLinkStr;
186      Element root;
187      String sqlAction;
188      String sqlResultLink;
189  
190      try {
191        da = new XMLDataAccess("");
192        da.connect();
193        doc = new XMLDocument();
194  
195        root = doc.createElement("ActionsResults");
196        node = doc.appendChild(root);
197  
198        sqlAction = "SELECT ";
199        sqlAction += "ACT_ID id,";
200        sqlAction += "ACT_CODE code,";
201        sqlAction += "ACT_SECURITY_LEVEL securityLevel,";
202        sqlAction += "ACT_DESCRIPTION description,";
203        sqlAction += "ACT_ACTIVE_INDICATOR activeIndicator,";
204        sqlAction += "to_char(ACT_LAST_CHANGED_DATE,'mm-dd-yyyy') lastChangedDate,";
205        sqlAction += "USER_USERID lastChangedBy";
206        sqlAction += " FROM ";
207        sqlAction += " actions,";
208        sqlAction += " users";
209        sqlAction += " WHERE ";
210        sqlAction += " (act_id = " + actionId.toString() + ") AND ";
211        sqlAction += " (act_cmp_id = " + companyId.toString() + ") AND ";
212        sqlAction += " (user_id = act_last_changed_by)";
213  
214        doc = da.makeXMLSelect(sqlAction, "ActionList", "Action", node);
215        node = doc.getDocumentElement();
216  
217        sqlResultLink = " SELECT ";
218        sqlResultLink += " arl_res_id resultId ";
219        sqlResultLink += " FROM  ";
220        sqlResultLink += " action_result_links ";
221        sqlResultLink += " WHERE ";
222        sqlResultLink += " arl_act_id = " + actionId.toString() + " AND ";
223        sqlResultLink += " arl_active_indicator = 'Y'";
224  
225        actionXmlString = da.getXml(sqlResultLink, "SelectedResults", "Result", node);
226        return actionXmlString;
227      }
228      catch(Exception e) {
229        this.context.setRollbackOnly();
230        throw new InstantbankException(e, "511001", "Failed to read action from the database");
231      }
232      finally {
233        try {
234          if(da != null) {
235            da.disconnect();
236          }
237        }
238        catch(Exception e) {
239        }
240      }
241    }
242  
243  
244    public String getHistory(Long companyId, Long agrmId, String primarySort, String secondarySort, Long rowNum) throws InstantbankException {
245      XMLDataAccess xda = null;
246      String orderByPrimary;
247      String orderBySecondary;
248      String sql;
249      String xmlString;
250      Long maxRows;
251  
252      try {
253        maxRows = new Long("19");
254        if(primarySort.equals("postingDate")) {
255          orderByPrimary = "acrh_date DESC";
256        }
257        else if(primarySort.equals("operator")) {
258          orderByPrimary = "operator";
259        }
260        else if(primarySort.equals("action")) {
261          orderByPrimary = "action";
262        }
263        else if(primarySort.equals("result")) {
264          orderByPrimary = "result";
265        }
266        else {
267          orderByPrimary = "acrh_date DESC";
268        }
269  
270        if(secondarySort.equals("postingDate")) {
271          orderBySecondary = "acrh_date DESC";
272        }
273        else if(secondarySort.equals("operator")) {
274          orderBySecondary = "operator";
275        }
276        else if(secondarySort.equals("action")) {
277          orderBySecondary = "action";
278        }
279        else if(secondarySort.equals("result")) {
280          orderBySecondary = "result";
281        }
282        else {
283          orderBySecondary = "operator";
284        }
285  
286        xda = new XMLDataAccess("");
287        xda.connect();
288  
289        sql = "SELECT ";
290        sql += "Id, ";
291        sql += "PostingDate, ";
292        sql += "Operator, ";
293        sql += "Action, ";
294        sql += "Result, ";
295        sql += "daysToDisplay, ";
296        sql += "Letter, ";
297        sql += "PromiseDate, ";
298        sql += "currentDate, ";
299        sql += "TimeLoop, ";
300        sql += "DayLoop, ";
301        sql += "Contact, ";
302        sql += "Comments ";
303        sql += "FROM (SELECT ";
304        sql += "Id, ";
305        sql += "PostingDate, ";
306        sql += "Operator, ";
307        sql += "Action, ";
308        sql += "Result, ";
309        sql += "daysToDisplay, ";
310        sql += "Letter, ";
311        sql += "PromiseDate, ";
312        sql += "currentDate, ";
313        sql += "TimeLoop, ";
314        sql += "DayLoop, ";
315        sql += "Contact, ";
316        sql += "Comments, ";
317        sql += "ROWNUM theRow ";
318        sql += "FROM (SELECT ";
319        sql += "acrh_id Id, ";
320        sql += "to_char(acrh_date,'mm-dd-yyyy HH24:MI') PostingDate, ";
321        sql += "user_userid Operator, ";
322        sql += "act_description Action, ";
323        sql += "res_description Result, ";
324        sql += "res_miscval_days_to_display daysToDisplay, ";
325        sql += "let_name Letter, ";
326        sql += "to_char(acrh_next_review_date,'mm-dd-yyyy HH24:MI') PromiseDate, ";
327        sql += "(select to_char(SYSDATE,'mm-dd-yyyy') from dual) currentDate, ";
328        sql += "acrh_time_loop TimeLoop, ";
329        sql += "acrh_day_loop DayLoop, ";
330        sql += "acrh_customer_contact Contact, ";
331        sql += "acrh_comments Comments ";
332        sql += "FROM ";
333        sql += "action_results_history, ";
334        sql += "actions, ";
335        sql += "results, ";
336        sql += "letter_templates, ";
337        sql += "users ";
338        sql += "WHERE ";
339        sql += "(acrh_agrm_id = " + agrmId.toString() + ") AND ";
340        sql += "(act_id = acrh_act_id) AND (res_id = acrh_res_id) AND ";
341        sql += "(let_id (+) = acrh_let_id) AND  (user_id (+) = acrh_user_id) AND (acrh_flag_show <> 'N')";
342        sql += "ORDER BY ";
343        sql += orderByPrimary + ", ";
344        sql += orderBySecondary + ")) ";
345        sql += "WHERE ";
346        sql += " theRow between ";
347        sql += rowNum.toString();
348        sql += "  AND " + new Long(rowNum.longValue() + maxRows.longValue()).toString();
349        xmlString = xda.getXml(sql, "ActionResultHistory", "Activity");
350        return xmlString;
351      }
352      catch(Exception e) {
353        this.context.setRollbackOnly();
354        throw new InstantbankException(e, "511002", "Failed to read Result History from the database");
355      }
356      finally {
357        try {
358          if(xda != null) {
359            xda.disconnect();
360          }
361        }
362        catch(Exception e) {
363        }
364      }
365    }
366  
367  
368    public Long getRowsHistory(Long companyId, Long agrmId) throws InstantbankException {
369      Connection con = null;
370      PreparedStatement ps = null;
371      ResultSet result = null;
372      String xml = "";
373      Long maxRows = null;
374      String sql;
375  
376      try {
377  
378        sql = "SELECT  count(ROWNUM) FROM action_results_history, actions, ";
379        sql += "results, letter_templates, users WHERE  ";
380        sql += "(acrh_agrm_id = ?) AND (act_id = acrh_act_id) AND (res_id = acrh_res_id) AND ";
381        sql += "(let_id (+) = acrh_let_id) AND  (user_id (+) = acrh_user_id)";
382        con = ServiceLocator.instance().getConnection();
383        ps = con.prepareStatement(sql);
384        ps.setLong(1, agrmId.longValue());
385        result = ps.executeQuery();
386  
387        if(result.next()) {
388          maxRows = new Long(result.getLong(1));
389        }
390        else {
391          maxRows = new Long("0");
392        }
393  
394        return maxRows;
395      }
396      catch(Exception e) {
397        throw new InstantbankException(e, "131009", "Failed to get the the number of promises ");
398      }
399      finally {
400        try {
401          if(result != null) {
402            result.close();
403          }
404          if(ps != null) {
405            ps.close();
406          }
407          if(con != null) {
408            con.close();
409          }
410        }
411        catch(SQLException se) {
412          se.printStackTrace();
413        }
414      }
415  
416    }
417  
418  
419  
420    public String getListByUser(Long userId, Long companyId) throws InstantbankException {
421      XMLDataAccess xda = null;
422      String query;
423      String xmlString;
424      try {
425        xda = new XMLDataAccess("");
426        xda.connect();
427        query = "SELECT ";
428        query += "act_id,";
429        query += "act_code,";
430        query += "act_description,";
431        query += "res_id,";
432        query += "res_code,";
433        query += "res_description";
434        query += " FROM ";
435        query += "actions, results,	users,	action_result_links,	";
436        query += "collections_security_profiles, security_profiles  ";
437        query += " WHERE ";
438        query += "act_cmp_id = " + companyId.toString() + " AND ";
439        query += "res_cmp_id = " + companyId.toString() + " AND ";
440        query += "user_sprf_id = sprf_id AND ";
441        query += "sprf_csp_id = csp_id AND ";
442        query += "csp_action_code_level >= act_security_level AND ";
443        query += "csp_result_code_level >= res_security_level AND ";
444        query += "arl_act_id = act_id AND ";
445        query += "arl_res_id = res_id AND ";
446        query += "arl_active_indicator = 'Y' AND ";
447        query += "act_active_indicator = 'Y' AND ";
448        query += "res_active_indicator = 'Y' AND ";
449        query += "user_id = " + userId + " ";
450        query += " ORDER BY act_code";
451  
452        xmlString = xda.getXml(query, "actionResultsList", "actionResult");
453        return xmlString;
454      }
455      catch(Exception e) {
456        this.context.setRollbackOnly();
457        throw new InstantbankException(e, "511003", "Failed to read actions from the database");
458      }
459      finally {
460        try {
461          if(xda != null) {
462            xda.disconnect();
463          }
464        }
465        catch(Exception e) {
466        }
467      }
468    }
469  
470  
471    public String getLists(Long companyId) throws InstantbankException {
472      XMLDataAccess da = null;
473      XMLDocument doc;
474      Node node;
475      Element root;
476      String sqlActions;
477      String sqlResults;
478      String xml;
479  
480      try {
481        da = new XMLDataAccess("");
482        da.connect();
483  
484        doc = new XMLDocument();
485        root = doc.createElement("ActionsResults");
486        node = doc.appendChild(root);
487  
488        sqlActions = "SELECT ";
489        sqlActions += "act_id Id, ";
490        sqlActions += "act_code Code,";
491        sqlActions += "act_description Description ";
492        sqlActions += "FROM ";
493        sqlActions += "actions ";
494        sqlActions += "WHERE ";
495        sqlActions += "act_cmp_id = " + companyId.toString() + " ";
496        sqlActions += "ORDER BY act_code";
497  
498        doc = da.makeXMLSelect(sqlActions, "ActionList", "Action", node);
499        node = doc.getDocumentElement();
500  
501        sqlResults = "SELECT ";
502        sqlResults += "res_id Id,";
503        sqlResults += "res_code Code,";
504        sqlResults += "res_description Description ";
505        sqlResults += "FROM ";
506        sqlResults += "results ";
507        sqlResults += "WHERE ";
508        sqlResults += "res_cmp_id = " + companyId.toString() + " ";
509        sqlResults += "ORDER BY res_code";
510  
511        return da.getXml(sqlResults, "ResultList", "Result", node);
512      }
513      catch(Exception e) {
514        this.context.setRollbackOnly();
515        throw new InstantbankException(e, "511005", "Failed to read Actions/Results from the database");
516      }
517      finally {
518        try {
519          if(da != null) {
520            da.disconnect();
521          }
522        }
523        catch(Exception e) {
524        }
525      }
526    }
527  
528  
529    public String getResult(Long companyId, Long resultId) throws InstantbankException {
530      DataAccess da = null;
531      XMLElement element;
532      NodeList nl;
533      XMLNode node;
534      PrintWriter pw;
535      String query;
536      XMLDocument resultXml = new XMLDocument();
537      XMLNode root;
538      ResultSet rs = null;
539      SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
540      Statement st = null;
541      String strResult = new String("");
542      StringWriter sw = new StringWriter();
543      XMLText text;
544      Long XmlCompanyId;
545  
546      /*The following variable (RES_PRVAL_MIN_PERCENT) should be a Folat,
547      but is treated as String to avoid conversion inconsistencies.*/
548      String RES_PRVAL_MIN_PERCENT = null;
549      String RES_QTVAL_SUPERVISOR_TRANS = null;
550      String RES_QTVAL_COLLECTIONS = null;
551      Long RES_MISCVAL_DAYS_TO_DISPLAY = null;
552      String RES_MISCVAL_REPORT = null;
553      String RES_MISCVAL_ACH = null;  //* CR2002062600 - add ach drafting to collections *//
554      Long RES_SECURITY_LEVEL = null;
555      Long RES_ID = null;
556      Long RES_MISCVAL_MAX_DAY_LOOP = null;
557      String RES_LAST_CHANGED_BY = null;
558      Long RES_PRVAL_MAX_DAYS = null;
559      String RES_QTVAL_RECOVERY = null;
560      String RES_MISCVAL_TIME_LOOP = null;
561      Long RES_CMP_ID = null;
562      String RES_DESCRIPTION = null;
563      Long RES_MISCVAL_DEFAULT_TIME_LOOP = null;
564      Long RES_NVCDV_MAX_DAYS = null;
565      String RES_PRVAL_REQUIRED_IND = null;
566      String RES_QTVAL_REQUIRED_IND = null;
567      String RES_MISCVAL_COMMENTS = null;
568      String RES_NVCDV_REQUIRED_IND = null;
569      String RES_MISCVAL_LETTER = null;
570      /*The following variable (RES_PRVAL_MIN_PERCENT) should be a Folat,
571      but is treated as String to avoid conversion inconsistencies.*/
572      String RES_PRVAL_MIN_AMOUNT = null;
573      String RES_QUEUE_STATS_PROMISE = null;
574      String RES_NVCDV_BASE = null;
575      String RES_MISCVAL_STORE = null;
576      String RES_QTVAL_CUSTOMER_SERVICE = null;
577      java.sql.Date RES_LAST_CHANGED_DATE = null;
578      Long RES_QTVAL_DEFAULT_QUEUE_ID = null;
579      Long RES_MISCVAL_DEFAULT_LETTER_ID = null;
580      String RES_QUEUE_STATS_CUSTOMER_CONT = null;
581      String RES_PRVAL_TYPE = null;
582      String RES_QTVAL_OTHER = null;
583      String RES_QUEUE_STATS_ATTEMPTS_CONT = null;
584      String RES_NVCDV_TYPE = null;
585      String RES_QUEUE_STATS_INDIRECT_CONT = null;
586      String RES_QUEUE_STATS_TRANSFER = null;
587      String RES_QTVAL_CLEAR_TRANS = null;
588      String RES_CODE = null;
589      Long RES_NVCDV_ADVANCE_DAYS = null;
590      Long RES_PRVAL_GRACE_DAYS = null;
591      String RES_ACTIVE_INDICATOR = null;
592  
593      try {
594        da = new DataAccess();
595        da.connect();
596        st = da.getConnection().createStatement();
597        query = "SELECT RES_ID," +
598          " RES_CMP_ID," +
599          " RES_CODE," +
600          " RES_DESCRIPTION," +
601          " RES_SECURITY_LEVEL," +
602          " USER_USERID," +
603          " RES_LAST_CHANGED_DATE," +
604          " RES_PRVAL_REQUIRED_IND," +
605          " RES_PRVAL_GRACE_DAYS," +
606          " RES_PRVAL_MAX_DAYS," +
607          " RES_PRVAL_MIN_AMOUNT," +
608          " RES_PRVAL_MIN_PERCENT," +
609          " RES_PRVAL_TYPE," +
610          " RES_QUEUE_STATS_PROMISE," +
611          " RES_QUEUE_STATS_CUSTOMER_CONT," +
612          " RES_QUEUE_STATS_TRANSFER," +
613          " RES_QUEUE_STATS_ATTEMPTS_CONT," +
614          " RES_QUEUE_STATS_INDIRECT_CONT," +
615          " RES_QTVAL_REQUIRED_IND," +
616          " RES_QTVAL_SUPERVISOR_TRANS," +
617          " RES_QTVAL_CLEAR_TRANS," +
618          " RES_QTVAL_DEFAULT_QUEUE_ID," +
619          " RES_QTVAL_COLLECTIONS," +
620          " RES_QTVAL_RECOVERY," +
621          " RES_QTVAL_CUSTOMER_SERVICE," +
622          " RES_QTVAL_OTHER," +
623          " RES_MISCVAL_COMMENTS," +
624          " RES_MISCVAL_LETTER," +
625          " RES_MISCVAL_DAYS_TO_DISPLAY," +
626          " RES_MISCVAL_DEFAULT_LETTER_ID," +
627          " RES_MISCVAL_TIME_LOOP," +
628          " RES_MISCVAL_STORE," +
629          " RES_MISCVAL_REPORT," +
630          " RES_MISCVAL_ACH," +   //*CR2002062600 - add ach drafting to collections*//
631        " RES_MISCVAL_DEFAULT_TIME_LOOP," +
632          " RES_MISCVAL_MAX_DAY_LOOP," +
633          " RES_NVCDV_REQUIRED_IND," +
634          " RES_NVCDV_ADVANCE_DAYS," +
635          " RES_NVCDV_MAX_DAYS," +
636          " RES_NVCDV_BASE," +
637          " RES_NVCDV_TYPE," +
638          " RES_ACTIVE_INDICATOR FROM results, users WHERE user_id = RES_LAST_CHANGED_BY and res_id = " + resultId.toString();
639  
640        rs = st.executeQuery(query);
641        while(rs.next()) {
642          RES_PRVAL_MIN_PERCENT = rs.getString("RES_PRVAL_MIN_PERCENT");
643          RES_QTVAL_SUPERVISOR_TRANS = rs.getString("RES_QTVAL_SUPERVISOR_TRANS");
644          RES_QTVAL_COLLECTIONS = rs.getString("RES_QTVAL_COLLECTIONS");
645          RES_MISCVAL_DAYS_TO_DISPLAY = new Long(rs.getLong("RES_MISCVAL_DAYS_TO_DISPLAY"));
646          RES_MISCVAL_REPORT = rs.getString("RES_MISCVAL_REPORT");
647          RES_MISCVAL_ACH = rs.getString("RES_MISCVAL_ACH");  //*CR2002062600 - add ach drafting to collections*//
648          RES_SECURITY_LEVEL = new Long(rs.getLong("RES_SECURITY_LEVEL"));
649          RES_ID = new Long(rs.getLong("RES_ID"));
650          RES_MISCVAL_MAX_DAY_LOOP = new Long(rs.getLong("RES_MISCVAL_MAX_DAY_LOOP"));
651          RES_LAST_CHANGED_BY = rs.getString("USER_USERID");
652          RES_PRVAL_MAX_DAYS = new Long(rs.getLong("RES_PRVAL_MAX_DAYS"));
653          RES_QTVAL_RECOVERY = rs.getString("RES_QTVAL_RECOVERY");
654          RES_MISCVAL_TIME_LOOP = rs.getString("RES_MISCVAL_TIME_LOOP");
655          RES_CMP_ID = new Long(rs.getLong("RES_CMP_ID"));
656          RES_DESCRIPTION = rs.getString("RES_DESCRIPTION");
657          RES_MISCVAL_DEFAULT_TIME_LOOP = new Long(rs.getLong("RES_MISCVAL_DEFAULT_TIME_LOOP"));
658          RES_NVCDV_MAX_DAYS = new Long(rs.getLong("RES_NVCDV_MAX_DAYS"));
659          RES_PRVAL_REQUIRED_IND = rs.getString("RES_PRVAL_REQUIRED_IND");
660          RES_QTVAL_REQUIRED_IND = rs.getString("RES_QTVAL_REQUIRED_IND");
661          RES_MISCVAL_COMMENTS = rs.getString("RES_MISCVAL_COMMENTS");
662          RES_NVCDV_REQUIRED_IND = rs.getString("RES_NVCDV_REQUIRED_IND");
663          RES_MISCVAL_LETTER = rs.getString("RES_MISCVAL_LETTER");
664          RES_PRVAL_MIN_AMOUNT = rs.getString("RES_PRVAL_MIN_AMOUNT");
665          RES_QUEUE_STATS_PROMISE = rs.getString("RES_QUEUE_STATS_PROMISE");
666          RES_NVCDV_BASE = rs.getString("RES_NVCDV_BASE");
667          RES_MISCVAL_STORE = rs.getString("RES_MISCVAL_STORE");
668          RES_QTVAL_CUSTOMER_SERVICE = rs.getString("RES_QTVAL_CUSTOMER_SERVICE");
669          RES_LAST_CHANGED_DATE = rs.getDate("RES_LAST_CHANGED_DATE");
670          RES_QTVAL_DEFAULT_QUEUE_ID = new Long(rs.getLong("RES_QTVAL_DEFAULT_QUEUE_ID"));
671          RES_MISCVAL_DEFAULT_LETTER_ID = new Long(rs.getLong("RES_MISCVAL_DEFAULT_LETTER_ID"));
672          RES_QUEUE_STATS_CUSTOMER_CONT = rs.getString("RES_QUEUE_STATS_CUSTOMER_CONT");
673          RES_PRVAL_TYPE = rs.getString("RES_PRVAL_TYPE");
674          RES_QTVAL_OTHER = rs.getString("RES_QTVAL_OTHER");
675          RES_QUEUE_STATS_ATTEMPTS_CONT = rs.getString("RES_QUEUE_STATS_ATTEMPTS_CONT");
676          RES_NVCDV_TYPE = rs.getString("RES_NVCDV_TYPE");
677          RES_QUEUE_STATS_INDIRECT_CONT = rs.getString("RES_QUEUE_STATS_INDIRECT_CONT");
678          RES_QUEUE_STATS_TRANSFER = rs.getString("RES_QUEUE_STATS_TRANSFER");
679          RES_QTVAL_CLEAR_TRANS = rs.getString("RES_QTVAL_CLEAR_TRANS");
680          RES_CODE = rs.getString("RES_CODE");
681          RES_NVCDV_ADVANCE_DAYS = new Long(rs.getLong("RES_NVCDV_ADVANCE_DAYS"));
682          RES_PRVAL_GRACE_DAYS = new Long(rs.getLong("RES_PRVAL_GRACE_DAYS"));
683          RES_ACTIVE_INDICATOR = rs.getString("RES_ACTIVE_INDICATOR");
684        }
685  
686        if(RES_SECURITY_LEVEL.equals(new Long("0"))) {
687          RES_SECURITY_LEVEL = null;
688        }
689        if(RES_ID.equals(new Long("0"))) {
690          RES_ID = null;
691        }
692        if(RES_LAST_CHANGED_BY.equals(new Long("0"))) {
693          RES_LAST_CHANGED_BY = null;
694        }
695        if(RES_CMP_ID.equals(new Long("0"))) {
696          RES_CMP_ID = null;
697        }
698        if(RES_QTVAL_DEFAULT_QUEUE_ID.equals(new Long("0"))) {
699          RES_QTVAL_DEFAULT_QUEUE_ID = null;
700        }
701        if(RES_MISCVAL_DEFAULT_LETTER_ID.equals(new Long("0"))) {
702          RES_MISCVAL_DEFAULT_LETTER_ID = null;
703        }
704  
705        element = new XMLElement("resultXml");
706        node = (XMLNode)element;
707        resultXml.appendChild(node);
708        root = node;
709  
710        if(RES_PRVAL_MIN_PERCENT != null) {
711          element = new XMLElement("res_prval_min_percent");
712          text = new XMLText(RES_PRVAL_MIN_PERCENT);
713          node = (XMLNode)element;
714          node.appendChild((Node)text);
715          root.appendChild(node);
716        }
717  
718        if(RES_QTVAL_SUPERVISOR_TRANS != null) {
719          element = new XMLElement("res_qtval_supervisor_trans");
720          text = new XMLText(RES_QTVAL_SUPERVISOR_TRANS);
721          node = (XMLNode)element;
722          node.appendChild((Node)text);
723          root.appendChild(node);
724        }
725  
726        if(RES_QTVAL_COLLECTIONS != null) {
727          element = new XMLElement("res_qtval_collections");
728          text = new XMLText(RES_QTVAL_COLLECTIONS);
729          node = (XMLNode)element;
730          node.appendChild((Node)text);
731          root.appendChild(node);
732        }
733  
734        if(RES_MISCVAL_DAYS_TO_DISPLAY != null) {
735          element = new XMLElement("res_miscval_days_to_display");
736          text = new XMLText(RES_MISCVAL_DAYS_TO_DISPLAY.toString());
737          node = (XMLNode)element;
738          node.appendChild((Node)text);
739          root.appendChild(node);
740        }
741  
742        if(RES_MISCVAL_REPORT != null) {
743          element = new XMLElement("res_miscval_report");
744          text = new XMLText(RES_MISCVAL_REPORT);
745          node = (XMLNode)element;
746          node.appendChild((Node)text);
747          root.appendChild(node);
748        }
749  //* CR2002062600 - add ach drafting to collections *//
750        if(RES_MISCVAL_ACH != null) {
751          element = new XMLElement("res_miscval_ach");
752          text = new XMLText(RES_MISCVAL_ACH);
753          node = (XMLNode)element;
754          node.appendChild((Node)text);
755          root.appendChild(node);
756        }
757        if(RES_SECURITY_LEVEL != null) {
758          element = new XMLElement("res_security_level");
759          text = new XMLText(RES_SECURITY_LEVEL.toString());
760          node = (XMLNode)element;
761          node.appendChild((Node)text);
762          root.appendChild(node);
763        }
764  
765        if(RES_ID != null) {
766          element = new XMLElement("res_id");
767          text = new XMLText(RES_ID.toString());
768          node = (XMLNode)element;
769          node.appendChild((Node)text);
770          root.appendChild(node);
771        }
772  
773        if(RES_MISCVAL_MAX_DAY_LOOP != null) {
774          element = new XMLElement("res_miscval_max_day_loop");
775          text = new XMLText(RES_MISCVAL_MAX_DAY_LOOP.toString());
776          node = (XMLNode)element;
777          node.appendChild((Node)text);
778          root.appendChild(node);
779        }
780  
781        if(RES_LAST_CHANGED_BY != null) {
782          element = new XMLElement("res_last_changed_by");
783          text = new XMLText(RES_LAST_CHANGED_BY.toString());
784          node = (XMLNode)element;
785          node.appendChild((Node)text);
786          root.appendChild(node);
787        }
788  
789        if(RES_PRVAL_MAX_DAYS != null) {
790          element = new XMLElement("res_prval_max_days");
791          text = new XMLText(RES_PRVAL_MAX_DAYS.toString());
792          node = (XMLNode)element;
793          node.appendChild((Node)text);
794          root.appendChild(node);
795        }
796  
797        if(RES_QTVAL_RECOVERY != null) {
798          element = new XMLElement("res_qtval_recovery");
799          text = new XMLText(RES_QTVAL_RECOVERY);
800          node = (XMLNode)element;
801          node.appendChild((Node)text);
802          root.appendChild(node);
803        }
804  
805        if(RES_QTVAL_OTHER != null) {
806          element = new XMLElement("res_qtval_other");
807          text = new XMLText(RES_QTVAL_OTHER);
808          node = (XMLNode)element;
809          node.appendChild((Node)text);
810          root.appendChild(node);
811        }
812  
813        if(RES_MISCVAL_TIME_LOOP != null) {
814          element = new XMLElement("res_miscval_time_loop");
815          text = new XMLText(RES_MISCVAL_TIME_LOOP);
816          node = (XMLNode)element;
817          node.appendChild((Node)text);
818          root.appendChild(node);
819        }
820  
821        if(RES_CMP_ID != null) {
822          element = new XMLElement("res_cmp_id");
823          text = new XMLText(RES_CMP_ID.toString());
824          node = (XMLNode)element;
825          node.appendChild((Node)text);
826          root.appendChild(node);
827        }
828  
829        if(RES_DESCRIPTION != null) {
830          element = new XMLElement("res_description");
831          text = new XMLText(RES_DESCRIPTION);
832          node = (XMLNode)element;
833          node.appendChild((Node)text);
834          root.appendChild(node);
835        }
836  
837        if(RES_MISCVAL_DEFAULT_TIME_LOOP != null) {
838          element = new XMLElement("res_miscval_default_time_loop");
839          text = new XMLText(RES_MISCVAL_DEFAULT_TIME_LOOP.toString());
840          node = (XMLNode)element;
841          node.appendChild((Node)text);
842          root.appendChild(node);
843        }
844  
845        if(RES_NVCDV_MAX_DAYS != null) {
846          element = new XMLElement("res_nvcdv_max_days");
847          text = new XMLText(RES_NVCDV_MAX_DAYS.toString());
848          node = (XMLNode)element;
849          node.appendChild((Node)text);
850          root.appendChild(node);
851        }
852  
853        if(RES_PRVAL_REQUIRED_IND != null) {
854          element = new XMLElement("res_prval_required_ind");
855          text = new XMLText(RES_PRVAL_REQUIRED_IND);
856          node = (XMLNode)element;
857          node.appendChild((Node)text);
858          root.appendChild(node);
859        }
860  
861        if(RES_QTVAL_REQUIRED_IND != null) {
862          element = new XMLElement("res_qtval_required_ind");
863          text = new XMLText(RES_QTVAL_REQUIRED_IND);
864          node = (XMLNode)element;
865          node.appendChild((Node)text);
866          root.appendChild(node);
867        }
868  
869        if(RES_MISCVAL_COMMENTS != null) {
870          element = new XMLElement("res_miscval_comments");
871          text = new XMLText(RES_MISCVAL_COMMENTS);
872          node = (XMLNode)element;
873          node.appendChild((Node)text);
874          root.appendChild(node);
875        }
876  
877        if(RES_NVCDV_REQUIRED_IND != null) {
878          element = new XMLElement("res_nvcdv_required_ind");
879          text = new XMLText(RES_NVCDV_REQUIRED_IND);
880          node = (XMLNode)element;
881          node.appendChild((Node)text);
882          root.appendChild(node);
883        }
884  
885        if(RES_PRVAL_MIN_AMOUNT != null) {
886          element = new XMLElement("res_prval_min_amount");
887          text = new XMLText(RES_PRVAL_MIN_AMOUNT);
888          node = (XMLNode)element;
889          node.appendChild((Node)text);
890          root.appendChild(node);
891        }
892  
893        if(RES_QUEUE_STATS_PROMISE != null) {
894          element = new XMLElement("res_queue_stats_promise");
895          text = new XMLText(RES_QUEUE_STATS_PROMISE);
896          node = (XMLNode)element;
897          node.appendChild((Node)text);
898          root.appendChild(node);
899        }
900  
901        if(RES_NVCDV_BASE != null) {
902          element = new XMLElement("res_nvcdv_base");
903          text = new XMLText(RES_NVCDV_BASE);
904          node = (XMLNode)element;
905          node.appendChild((Node)text);
906          root.appendChild(node);
907        }
908  
909        if(RES_MISCVAL_STORE != null) {
910          element = new XMLElement("res_miscval_store");
911          text = new XMLText(RES_MISCVAL_STORE);
912          node = (XMLNode)element;
913          node.appendChild((Node)text);
914          root.appendChild(node);
915        }
916  
917        if(RES_QTVAL_CUSTOMER_SERVICE != null) {
918          element = new XMLElement("res_qtval_customer_service");
919          text = new XMLText(RES_QTVAL_CUSTOMER_SERVICE);
920          node = (XMLNode)element;
921          node.appendChild((Node)text);
922          root.appendChild(node);
923        }
924  
925        if(RES_LAST_CHANGED_DATE != null) {
926          element = new XMLElement("res_last_changed_date");
927          text = new XMLText(sdf.format(RES_LAST_CHANGED_DATE));
928          node = (XMLNode)element;
929          node.appendChild((Node)text);
930          root.appendChild(node);
931        }
932  
933        if(RES_MISCVAL_LETTER != null) {
934          element = new XMLElement("res_miscval_letter");
935          text = new XMLText(RES_MISCVAL_LETTER);
936          node = (XMLNode)element;
937          node.appendChild((Node)text);
938          root.appendChild(node);
939        }
940  
941        if(RES_MISCVAL_DEFAULT_LETTER_ID != null) {
942          element = new XMLElement("res_miscval_default_letter_id");
943          text = new XMLText(RES_MISCVAL_DEFAULT_LETTER_ID.toString());
944          node = (XMLNode)element;
945          node.appendChild((Node)text);
946          root.appendChild(node);
947        }
948  
949        if(RES_QUEUE_STATS_CUSTOMER_CONT != null) {
950          element = new XMLElement("res_queue_stats_customer_cont");
951          text = new XMLText(RES_QUEUE_STATS_CUSTOMER_CONT);
952          node = (XMLNode)element;
953          node.appendChild((Node)text);
954          root.appendChild(node);
955        }
956  
957        if(RES_QTVAL_DEFAULT_QUEUE_ID != null) {
958          element = new XMLElement("res_qtval_default_queue_id");
959          text = new XMLText(RES_QTVAL_DEFAULT_QUEUE_ID.toString());
960          node = (XMLNode)element;
961          node.appendChild((Node)text);
962          root.appendChild(node);
963        }
964  
965        if(RES_PRVAL_TYPE != null) {
966          element = new XMLElement("res_prval_type");
967          text = new XMLText(RES_PRVAL_TYPE);
968          node = (XMLNode)element;
969          node.appendChild((Node)text);
970          root.appendChild(node);
971        }
972  
973        if(RES_QUEUE_STATS_ATTEMPTS_CONT != null) {
974          element = new XMLElement("res_queue_stats_attempts_cont");
975          text = new XMLText(RES_QUEUE_STATS_ATTEMPTS_CONT);
976          node = (XMLNode)element;
977          node.appendChild((Node)text);
978          root.appendChild(node);
979        }
980  
981        if(RES_NVCDV_TYPE != null) {
982          element = new XMLElement("res_nvcdv_type");
983          text = new XMLText(RES_NVCDV_TYPE);
984          node = (XMLNode)element;
985          node.appendChild((Node)text);
986          root.appendChild(node);
987        }
988  
989        if(RES_QUEUE_STATS_INDIRECT_CONT != null) {
990          element = new XMLElement("res_queue_stats_indirect_cont");
991          text = new XMLText(RES_QUEUE_STATS_INDIRECT_CONT);
992          node = (XMLNode)element;
993          node.appendChild((Node)text);
994          root.appendChild(node);
995        }
996  
997        if(RES_QUEUE_STATS_TRANSFER != null) {
998          element = new XMLElement("res_queue_stats_transfer");
999          text = new XMLText(RES_QUEUE_STATS_TRANSFER);
1000         node = (XMLNode)element;
1001         node.appendChild((Node)text);
1002         root.appendChild(node);
1003       }
1004 
1005       if(RES_QTVAL_CLEAR_TRANS != null) {
1006         element = new XMLElement("res_qtval_clear_trans");
1007         text = new XMLText(RES_QTVAL_CLEAR_TRANS);
1008         node = (XMLNode)element;
1009         node.appendChild((Node)text);
1010         root.appendChild(node);
1011       }
1012 
1013       if(RES_CODE != null) {
1014         element = new XMLElement("res_code");
1015         text = new XMLText(RES_CODE);
1016         node = (XMLNode)element;
1017         node.appendChild((Node)text);
1018         root.appendChild(node);
1019       }
1020 
1021       if(RES_NVCDV_ADVANCE_DAYS != null) {
1022         element = new XMLElement("res_nvcdv_advance_days");
1023         text = new XMLText(RES_NVCDV_ADVANCE_DAYS.toString());
1024         node = (XMLNode)element;
1025         node.appendChild((Node)text);
1026         root.appendChild(node);
1027       }
1028 
1029       if(RES_PRVAL_GRACE_DAYS != null) {
1030         element = new XMLElement("res_prval_grace_days");
1031         text = new XMLText(RES_PRVAL_GRACE_DAYS.toString());
1032         node = (XMLNode)element;
1033         node.appendChild((Node)text);
1034         root.appendChild(node);
1035       }
1036 
1037       if(RES_ACTIVE_INDICATOR != null) {
1038         element = new XMLElement("res_active_indicator");
1039         text = new XMLText(RES_ACTIVE_INDICATOR);
1040         node = (XMLNode)element;
1041         node.appendChild((Node)text);
1042         root.appendChild(node);
1043       }
1044 
1045       sw = new StringWriter();
1046       pw = new PrintWriter(sw);
1047       resultXml.print(pw);
1048       nl = resultXml.selectNodes("/resultXml/res_cmp_id/text()");
1049       XmlCompanyId = new Long(nl.item(0).getNodeValue());
1050       if(!companyId.equals(XmlCompanyId)) {
1051         throw new Exception("Company Id does not match!!");
1052       }
1053       ;
1054       strResult = sw.toString();
1055       return strResult;
1056     }
1057     catch(Exception e) {
1058       setRollbackOnly();
1059       throw new InstantbankException(e, "511004", "Failed to read Result from the database");
1060     }
1061     finally {
1062       try {
1063         if(rs != null) {
1064           rs.close();
1065         }
1066         if(st != null) {
1067           st.close();
1068         }
1069         if(da != null) {
1070           da.disconnect();
1071         }
1072       }
1073       catch(Exception e) {
1074       }
1075     }
1076   }
1077 
1078 
1079   public String getResultRules(String sessionInfo, Long resultId) throws InstantbankException {
1080     CompanyServicesHome Calhome;
1081     Vector categories = new Vector(4);
1082     Long companyId;
1083     String currentDateString = "";
1084     int currentYear;
1085     DataAccess da = null;
1086     DOMParser docParser = new DOMParser();
1087     String lettersXmlStr = "";
1088     String queuesXmlStr = "";
1089     XMLDocument resultXML;
1090     String resultXmlStr = "";
1091     String resultRulesXmlStr = "<resultRules/>";
1092     ResultSet rs = null;
1093     CompanyServices services;
1094     XMLDocument sessionXml;
1095     Statement st = null;
1096     ByteArrayInputStream stream;
1097     String supervisorQueueXmlStr = "";
1098     Long userId;
1099     String xmlCalendarCY;
1100     String xmlCalendarNY;
1101 
1102     try {
1103       stream = new ByteArrayInputStream(sessionInfo.getBytes());
1104       docParser.setValidationMode(false);
1105       docParser.parse(stream);
1106       sessionXml = docParser.getDocument();
1107 
1108       userId = new Long(sessionXml.valueOf("session/userId"));
1109       companyId = new Long(sessionXml.valueOf("session/companyId"));
1110 
1111       resultXmlStr = getResult(companyId, resultId);
1112       stream = new ByteArrayInputStream(resultXmlStr.getBytes());
1113       docParser.setValidationMode(false);
1114       docParser.parse(stream);
1115       resultXML = docParser.getDocument();
1116       if((resultXML.valueOf("resultXml/res_qtval_required_ind").equals("Q")) || (resultXML.valueOf("resultXml/res_qtval_required_ind").equals("O"))) {
1117         if(resultXML.valueOf("resultXml/res_qtval_collections").equals("Y")) {
1118           categories.insertElementAt("C", 0);
1119         }
1120         if(resultXML.valueOf("resultXml/res_qtval_recovery").equals("Y")) {
1121           categories.insertElementAt("R", 0);
1122         }
1123         if(resultXML.valueOf("resultXml/res_qtval_customer_service").equals("Y")) {
1124           categories.insertElementAt("S", 0);
1125         }
1126         if(resultXML.valueOf("resultXml/res_qtval_other").equals("Y")) {
1127           categories.insertElementAt("T", 0);
1128         }
1129         QueueServicesHome qshome = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, true);
1130         QueueServices queueServices = qshome.create();
1131         queuesXmlStr = queueServices.getQueuesByCategory(categories, companyId);
1132         if(resultXML.valueOf("resultXml/res_qtval_supervisor_trans").equals("Y")) {
1133           supervisorQueueXmlStr = queueServices.getUsersSupervisorQueue(userId);
1134         }
1135       }
1136       if((resultXML.valueOf("resultXml/res_miscval_letter").equals("Q")) || (resultXML.valueOf("resultXml/res_miscval_letter").equals("O")) || (resultXML.valueOf("resultXml/res_miscval_letter").equals("D"))) {
1137         LetterServicesHome lshome = (LetterServicesHome)ServiceLocator.instance().createEJB("LetterServicesHome", LetterServicesHome.class, true);
1138         LetterServices letterServices = lshome.create();
1139         lettersXmlStr = XMLUtils.removeHeader(letterServices.getListByCompany(companyId, userId));
1140       }
1141       Calhome = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
1142       services = Calhome.create();
1143       currentYear = services.getDBYear();
1144       xmlCalendarCY = services.getCalendar(companyId, currentYear, (currentYear + 1));
1145       //xmlCalendarNY =  services.getCalendar(companyId, (currentYear + 1));
1146 
1147       if(!resultXmlStr.equals("")) {
1148         resultXmlStr = XMLUtils.removeHeader(resultXmlStr);
1149       }
1150       if(!queuesXmlStr.equals("")) {
1151         queuesXmlStr = XMLUtils.removeHeader(queuesXmlStr);
1152       }
1153       if(!supervisorQueueXmlStr.equals("")) {
1154         supervisorQueueXmlStr = XMLUtils.removeHeader(supervisorQueueXmlStr);
1155       }
1156       if(!lettersXmlStr.equals("")) {
1157         lettersXmlStr = XMLUtils.removeHeader(lettersXmlStr);
1158       }
1159       if(!xmlCalendarCY.equals("")) {
1160         xmlCalendarCY = XMLUtils.removeHeader(xmlCalendarCY);
1161       }
1162       /*      if (!xmlCalendarNY.equals("")){
1163         xmlCalendarNY = XMLUtils.removeHeader(xmlCalendarNY);
1164         }*/
1165       da = new DataAccess();
1166       da.connect();
1167       st = da.getConnection().createStatement();
1168       rs = st.executeQuery("select TO_CHAR(SYSDATE, 'mm-dd-yyyy') from DUAL");
1169       while(rs.next()) {
1170         currentDateString = rs.getString(1);
1171       }
1172 
1173       resultRulesXmlStr = "<resultRules>" +
1174         resultXmlStr +
1175         queuesXmlStr +
1176         supervisorQueueXmlStr +
1177         lettersXmlStr +
1178         xmlCalendarCY +
1179       //                     xmlCalendarNY +
1180         "<CurrentDate>" + currentDateString + "</CurrentDate>" +
1181         "</resultRules>";
1182       da.disconnect();
1183       return resultRulesXmlStr;
1184     }
1185     catch(Exception e) {
1186       setRollbackOnly();
1187       throw new InstantbankException(e, "511006", "Failed to read Result/Rules from the database");
1188     }
1189     finally {
1190       try {
1191         if(rs != null) {
1192           rs.close();
1193         }
1194         if(st != null) {
1195           st.close();
1196         }
1197         if(da != null) {
1198           da.disconnect();
1199         }
1200       }
1201       catch(Exception e) {
1202       }
1203     }
1204   }
1205 
1206 
1207   public String getResultsList(Long companyId) throws InstantbankException {
1208     String sql;
1209     String resultsList;
1210     XMLDataAccess da = null;
1211     XMLDocument docResults;
1212 
1213     try {
1214       da = new XMLDataAccess("");
1215       da.connect();
1216       sql = "SELECT ";
1217       sql += " res_id Id,";
1218       sql += " res_code Code,";
1219       sql += " res_description Description ";
1220       sql += "FROM ";
1221       sql += "results ";
1222       sql += "WHERE ";
1223       sql += "res_cmp_id = " + companyId.toString();
1224       resultsList = da.getXml(sql, "Results", "Result");
1225       return resultsList;
1226     }
1227     catch(Exception e) {
1228       this.context.setRollbackOnly();
1229       throw new InstantbankException(e, "511007", "Failed to read Result from the database");
1230     }
1231     finally {
1232       try {
1233         if(da != null) {
1234           da.disconnect();
1235         }
1236       }
1237       catch(Exception e) {
1238       }
1239     }
1240   }
1241 
1242 
1243   public String newResult() throws InstantbankException {
1244     String xml;
1245 
1246     try {
1247       xml = "<Result>";
1248       xml += "<Id>0</Id>";
1249       xml += "<Description>N</Description>";
1250       xml += "<SecurityLevel>N</SecurityLevel>";
1251       xml += "<Date>N</Date>";
1252       xml += "<PVRequiredIndicator>P</PVRequiredIndicator>";
1253       xml += "<PVGraceDays>N</PVGraceDays>";
1254       xml += "<PVMaximumDays>N</PVMaximumDays>";
1255       xml += "<PVType>B</PVType>";
1256       xml += "<PVMinimumAmount>N</PVMinimumAmount>";
1257       xml += "<PVMinimumPercent>N</PVMinimumPercent>";
1258       xml += "<QSPromise>N</QSPromise>";
1259       xml += "<QSCustomerContact>N</QSCustomerContact>";
1260       xml += "<QSTransfer>N</QSTransfer>";
1261       xml += "<QSAttemptedContact>N</QSAttemptedContact>";
1262       xml += "<QSIndirectContact>N</QSIndirectContact>";
1263       xml += "<QTRequiredIndicator>O</QTRequiredIndicator>";
1264       xml += "<QTSupervisorTransfer>N</QTSupervisorTransfer>";
1265       xml += "<QTClearTransfer>N</QTClearTransfer>";
1266       xml += "<QTDefaultQueueId>0</QTDefaultQueueId>";
1267       xml += "<QTCollections>N</QTCollections>";
1268       xml += "<QTRecovery>N</QTRecovery>";
1269       xml += "<QTCustomerService>N</QTCustomerService>";
1270       xml += "<QTOther>N</QTOther>";
1271       xml += "<MVComments>O</MVComments>";
1272       xml += "<MVLetters>O</MVLetters>";
1273       xml += "<MVDefaultLetterId>0</MVDefaultLetterId>";
1274       xml += "<MVDaysToDisplay>N</MVDaysToDisplay>";
1275       xml += "<MVTimeLoop>N</MVTimeLoop>";
1276       xml += "<MVStore>N</MVStore>";
1277       xml += "<MVReport>N</MVReport>";
1278       xml += "<MVAch>N</MVAch>";  //* CR2002062600 - add ach drafting to collections*//
1279       xml += "<MVDefaultTimeLoop>N</MVDefaultTimeLoop>";
1280       xml += "<MVMaxDayLoop>N</MVMaxDayLoop>";
1281       xml += "<CDRequiredInd>O</CDRequiredInd>";
1282       xml += "<CDAdvanceDays>N</CDAdvanceDays>";
1283       xml += "<CDMaximumDays>N</CDMaximumDays>";
1284       xml += "<CDBase>T</CDBase>";
1285       xml += "<CDType>B</CDType>";
1286       xml += "</Result>";
1287       return xml;
1288     }
1289     catch(Exception e) {
1290       setRollbackOnly();
1291       throw new InstantbankException(e, "511011", "Failed to read new results from the database");
1292     }
1293     finally {
1294       try {
1295       }
1296       catch(Exception e) {
1297       }
1298     }
1299   }
1300 
1301 
1302   public String recordActivity(String activityXmlString, String sessionInfo, Long workItemId, Long agrmId) throws InstantbankException {
1303     String ACRH_COMMENTS = "";
1304     Long ACRH_DAY_LOOP;
1305     Long ACRH_ID;
1306     Long ACRH_TIME_LOOP;
1307     XMLDocument activityXml;
1308     Long agreementId = null;
1309     String amount = "";
1310     int attemptIndicator = 0;
1311     String calendar = "";
1312     NodeList calendarList;
1313     Long companyId;
1314     int contactIndicator = 0;
1315     java.sql.Date currentSysdate = null;
1316     java.sql.Date currentSysdateTime = null;
1317     Long custCont = new Long(0);
1318     String custContStr;
1319     DataAccess da = null;
1320     String dataQuery = "";
1321     String duedata = "";
1322     String nextdata = "";
1323     int days = 0;
1324     DOMParser docParser = new DOMParser();
1325     Date dueDate = null;
1326     java.sql.Date followupDate = null;
1327     String followupTime = "00:00";
1328     int fromMinutes = 0;
1329     String graceDays;
1330     int graceDaysTotal;
1331     int hours;
1332     String hoursStr;
1333     int indirectIndicator = 0;
1334     Long letterId = null;
1335     int minutes;
1336     String minutesStr;
1337     boolean mustToSavePromise = false;
1338     Date nextReviewDate = null;
1339     long numberOfCurrentPromises = 0;
1340     Long planId;
1341     String prmType = "";
1342     String promiseAmount = "0";
1343     int promiseIndicator = 0;
1344     Long qplanId = null;
1345     ResultSet rs = null;
1346     ResultSet rs2 = null;
1347     SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
1348     SimpleDateFormat sdf2 = new SimpleDateFormat("MM-dd-yyyy HH:mm");
1349     String sql;
1350     XMLDocument sessionXml;
1351     Statement st = null;
1352     Statement st2 = null;
1353     String status = null;
1354     ByteArrayInputStream stream;
1355     int timeOffset = 0;
1356     int total;
1357     Long userId;
1358     String xmlResponse;
1359 //Cr 2002062600  - ach payments - 11/2002 dwar
1360     BigDecimal pmtAmt = null;
1361     BigDecimal feeAmt = null;
1362     String abaNumber = null;
1363     String acctNumber = null;
1364     String pmtStatus = null;
1365     String typeofacct = null;
1366     String nameonacct = null;
1367     try {
1368 
1369       da = new DataAccess();
1370       da.connect();
1371       st = da.getConnection().createStatement();
1372       st2 = da.getConnection().createStatement();
1373       stream = new ByteArrayInputStream(activityXmlString.getBytes());
1374       docParser.setValidationMode(false);
1375       docParser.parse(stream);
1376       activityXml = docParser.getDocument();
1377 
1378       stream = new ByteArrayInputStream(sessionInfo.getBytes());
1379       docParser.setValidationMode(false);
1380       docParser.parse(stream);
1381       sessionXml = docParser.getDocument();
1382 
1383       userId = new Long(sessionXml.valueOf("session/userId"));
1384       companyId = new Long(sessionXml.valueOf("session/companyId"));
1385 
1386       QueueServicesHome qshome = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, true);
1387       QueueServices queueServices = qshome.create();
1388       //*
1389 
1390 
1391       //**
1392 
1393       if(workItemId.longValue() > 0) {
1394         rs = st.executeQuery("SELECT   wrki_object_id, wrki_qplan_id " +
1395           "FROM     work_items " +
1396           "WHERE    wrki_id = " + workItemId.toString());
1397         while(rs.next()) {
1398           agreementId = new Long(rs.getLong(1));
1399           planId = new Long(rs.getLong(2));
1400         }
1401       }
1402       else {
1403         agreementId = agrmId;
1404       }
1405       //**
1406 
1407       //***
1408       if((activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_letter").equals("Q")) && (activityXml.valueOf("activityXml/activity/acrh_let_id").length() == 0)) {
1409         throw new InstantbankException("511015", "There is no letter template selected, but Send Letter is required to save the Activity.");
1410       }
1411       else if((!activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_letter").equals("R")) && (activityXml.valueOf("activityXml/activity/acrh_let_id").length() != 0)) {
1412         LetterServicesHome lshome = (LetterServicesHome)ServiceLocator.instance().createEJB("LetterServicesHome", LetterServicesHome.class, true);
1413         LetterServices letterServices = lshome.create();
1414         letterServices.orderLetter(new Long(activityXml.valueOf("activityXml/activity/acrh_let_id")), agreementId, true);
1415         letterId = new Long(activityXml.valueOf("activityXml/activity/acrh_let_id"));
1416       }
1417       //***
1418 
1419       rs2 = st2.executeQuery("SELECT USER_TIME_OFFSET FROM USERS WHERE USER_ID=" + userId);
1420       if(rs2.next()) {
1421         timeOffset = rs2.getInt(1);
1422       }
1423       if(timeOffset > 0) {
1424         rs = st.executeQuery("select sysdate+(" + timeOffset + "/24) from dual");
1425       }
1426       else {
1427         rs = st.executeQuery("SELECT SYSDATE FROM DUAL");
1428       }
1429 
1430       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_customer_cont").length() != 0) {
1431         custContStr = activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_customer_cont");
1432         if(custContStr.equals("Y")) {
1433           custCont = new Long("1");
1434         }
1435         else {
1436           custCont = new Long("0");
1437         }
1438       }
1439 
1440       if(activityXml.valueOf("activityXml/activity/acrh_next_review_date").length() != 0) {
1441         nextdata = activityXml.valueOf("activityXml/activity/acrh_next_review_date");
1442       }
1443       else {
1444         nextdata = "";
1445       }
1446       if((activityXml.valueOf("activityXml/resultRules/resultXml/res_nvcdv_required_ind").equals("Q")) && (nextdata.equals(""))) {
1447         throw new InstantbankException("511012", "There is no Next Valid Collection Date, but it is required.");
1448       }
1449 
1450       if(activityXml.valueOf("activityXml/activity/acrh_day_loop").length() != 0) {
1451         ACRH_DAY_LOOP = new Long(activityXml.valueOf("activityXml/activity/acrh_day_loop"));
1452       }
1453       else {
1454         ACRH_DAY_LOOP = null;
1455       }
1456 
1457       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_time_loop").equals("Y")) {
1458         if(activityXml.valueOf("activityXml/activity/acrh_time_loop").length() != 0) {
1459           ACRH_TIME_LOOP = new Long(activityXml.valueOf("activityXml/activity/acrh_time_loop"));
1460         }
1461         else {
1462           ACRH_TIME_LOOP = null;
1463         }
1464       }
1465       else {
1466         ACRH_TIME_LOOP = null;
1467       }
1468 
1469       if(!activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_comments").equals("R")) {
1470         if(activityXml.valueOf("activityXml/activity/comments").length() != 0) {
1471           ACRH_COMMENTS = activityXml.valueOf("activityXml/activity/comments");
1472         }
1473         else {
1474           ACRH_COMMENTS = "";
1475         }
1476       }
1477       else {
1478         ACRH_COMMENTS = "";
1479       }
1480 
1481       if(activityXml.valueOf("activityXml/activity/acrh_qplan_id").length() > 0) {
1482         qplanId = new Long(activityXml.valueOf("activityXml/activity/acrh_qplan_id"));
1483       }
1484 
1485       ACRH_ID = new Long(UniqueIDGenerator.instance().getNextId());
1486       //* cr 2002081501 - moved add of the action to last process in this method
1487       //*
1488       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_promise").equals("Y")) {
1489         promiseIndicator = 1;
1490       }
1491 
1492       if(workItemId.longValue() > 0) {
1493         if(activityXml.valueOf("activityXml/promise/prm_amount").length() != 0) {
1494           promiseAmount = activityXml.valueOf("activityXml/promise/prm_amount");
1495         }
1496         if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_customer_cont").equals("Y")) {
1497           contactIndicator = 1;
1498         }
1499         if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_indirect_cont").equals("Y")) {
1500           indirectIndicator = 1;
1501         }
1502         if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_attempts_cont").equals("Y")) {
1503           attemptIndicator = 1;
1504         }
1505         queueServices.recordWork(workItemId, promiseIndicator, promiseAmount, contactIndicator, indirectIndicator, attemptIndicator);
1506       }
1507 
1508       while(rs.next()) {
1509         currentSysdateTime = new java.sql.Date((sdf2.parse(sdf2.format(rs.getDate(1)))).getTime());
1510         currentSysdate = new java.sql.Date((sdf.parse(sdf.format(rs.getDate(1)))).getTime());
1511       }
1512 
1513       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_queue_stats_customer_cont").equals("Y")) {
1514         da.makeUpdate("UPDATE   agreements " +
1515           "SET      agrm_date_last_cust_contact = TO_CHAR(SYSDATE) " +
1516           "WHERE    agrm_id = " + agreementId.toString());
1517       }
1518 
1519       if((activityXml.valueOf("activityXml/activity/acrh_day_loop").length() == 0) || ((new Integer(activityXml.valueOf("activityXml/activity/acrh_day_loop"))).intValue() == 0)) {
1520         long difference = (currentSysdateTime.getTime() - currentSysdate.getTime()) / 60000;
1521         fromMinutes = (new Integer((new Long(difference)).toString())).intValue();
1522         followupDate = currentSysdate;
1523       }
1524       else {
1525         followupDate = new java.sql.Date(currentSysdate.getTime() + ((new Long(activityXml.valueOf("activityXml/activity/acrh_day_loop"))).longValue() * 86400000));
1526       }
1527 
1528       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_time_loop").equals("Y")) {
1529         if(activityXml.valueOf("activityXml/activity/acrh_time_loop").length() != 0) {
1530           minutes = fromMinutes + (new Integer(activityXml.valueOf("activityXml/activity/acrh_time_loop"))).intValue();
1531           hours = minutes / 60;
1532           minutes = minutes % 60;
1533           days = hours / 24;
1534           followupDate = new java.sql.Date(followupDate.getTime() + ((new Integer(days)).longValue() * 86400000));
1535           hours = hours % 24;
1536           hoursStr = (new Integer(hours)).toString();
1537           minutesStr = (new Integer(minutes)).toString();
1538           while(hoursStr.length() < 2) {
1539             hoursStr = "0".concat(hoursStr);
1540           }
1541           while(minutesStr.length() < 2) {
1542             minutesStr = "0".concat(minutesStr);
1543           }
1544           followupTime = hoursStr + ":" + minutesStr;
1545         }
1546         else {
1547           followupTime = "00:00";
1548         }
1549       }
1550       else {
1551         followupTime = "00:00";
1552       }
1553 
1554       if((workItemId.longValue() > 0) && (((activityXml.valueOf("activityXml/activity/acrh_day_loop").length() != 0) && ((new Integer(activityXml.valueOf("activityXml/activity/acrh_day_loop"))).intValue() != 0)) || ((activityXml.valueOf("activityXml/activity/acrh_time_loop").length() != 0) && ((new Integer(activityXml.valueOf("activityXml/activity/acrh_time_loop"))).intValue() != 0)))) {
1555         queueServices.dateTimeLoop(workItemId, followupDate, followupTime);
1556       }
1557       else if(workItemId.longValue() > 0) {
1558         if(contactIndicator == 1) {
1559           queueServices.dateTimeLoop(workItemId, null, null);
1560         }
1561         else {
1562           queueServices.dateTimeLoop(workItemId, currentSysdate, null);
1563         }
1564       }
1565 
1566       if((activityXml.valueOf("activityXml/resultRules/resultXml/res_qtval_required_ind").equals("Q")) && (activityXml.valueOf("activityXml/resultRules/resultXml/res_qtval_clear_trans").equals("Y"))) {
1567         throw new InstantbankException("511014", "An activity cannot be saved for Transfer To Queue and Clear Transfer at the same time.");
1568       }
1569 
1570       if((activityXml.valueOf("activityXml/resultRules/resultXml/res_qtval_required_ind").equals("Q")) && (activityXml.valueOf("activityXml/activity/acrh_qplan_id").length() == 0)) {
1571         throw new InstantbankException("511013", "There is no queue to transfer, but Transfer To Queue is required.");
1572       }
1573       else if((!activityXml.valueOf("activityXml/resultRules/resultXml/res_qtval_required_ind").equals("R")) && (activityXml.valueOf("activityXml/activity/acrh_qplan_id").length() != 0)) {
1574         if(workItemId.longValue() > 0) {
1575           queueServices.transferToQueue(workItemId, new Long(activityXml.valueOf("activityXml/activity/acrh_qplan_id")), promiseIndicator, contactIndicator, indirectIndicator, attemptIndicator);
1576         }
1577         if(workItemId.longValue() == 0) {
1578           queueServices.assignToQueue(new Long(activityXml.valueOf("activityXml/activity/acrh_qplan_id")), "A", agrmId, userId, followupDate, followupTime);
1579         }
1580         qplanId = new Long(activityXml.valueOf("activityXml/activity/acrh_qplan_id"));
1581       }
1582       else if(activityXml.valueOf("activityXml/resultRules/resultXml/res_qtval_clear_trans").equals("Y")) {
1583         if(workItemId.longValue() > 0) {
1584           queueServices.clearTransfer(workItemId);
1585         }
1586       }
1587 
1588       if((activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_comments").equals("Q")) && (activityXml.valueOf("activityXml/activity/comments").length() == 0)) {
1589         throw new InstantbankException("511015", "There is no Comment, but Comments are required to save the Activity.");
1590       }
1591       else if(activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_comments").equals("O")) {
1592         if(activityXml.valueOf("activityXml/activity/comments").length() != 0) {
1593           dataQuery = " INSERT INTO notes (" +
1594             "     note_id," +
1595             "     note_description," +
1596             "     note_last_changed_date," +
1597             "     note_last_changed_by," +
1598             "     note_agrm_id" +
1599             " ) VALUES (" +
1600             (new Long(UniqueIDGenerator.instance().getNextId())).toString() + ", " +
1601             "'" + StringFormat.toSafeOracleString(activityXml.valueOf("activityXml/activity/comments")) + "', " +
1602             " SYSDATE, " +
1603             userId.toString() + ", " +
1604             agreementId.toString() + ")";
1605           da.makeInsert(dataQuery);
1606         }
1607       }
1608 
1609       if(activityXml.valueOf("activityXml/promise/prm_due_date").length() != 0) {
1610         duedata = activityXml.valueOf("activityXml/promise/prm_due_date");
1611       }
1612       else {
1613         duedata = "";
1614       }
1615       if(activityXml.valueOf("activityXml/promise/prm_amount").length() != 0) {
1616         amount = activityXml.valueOf("activityXml/promise/prm_amount");
1617       }
1618       else {
1619         amount = "";
1620       }
1621       if(activityXml.valueOf("activityXml/promise/prm_status").length() != 0) {
1622         status = activityXml.valueOf("activityXml/promise/prm_status");
1623       }
1624 
1625       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_prval_required_ind").equals("Q")) {
1626         mustToSavePromise = true;
1627       }
1628       else if(activityXml.valueOf("activityXml/resultRules/resultXml/res_prval_required_ind").equals("R")) {
1629         mustToSavePromise = false;
1630       }
1631       else if((!duedata.equals("")) && (!amount.equals(""))) {
1632         mustToSavePromise = true;
1633       }
1634       else {
1635         mustToSavePromise = false;
1636       }
1637       //Cr 2002062600  - ach payments - 11/2002 dwar
1638       if(activityXml.valueOf("activityXml/returnXml/achp_status").equals("1")) {
1639         pmtAmt = new BigDecimal(activityXml.valueOf("activityXml/returnXml/achp_payment_amt"));
1640         feeAmt = new BigDecimal(activityXml.valueOf("activityXml/returnXml/achp_fee_amt"));
1641         abaNumber = activityXml.valueOf("activityXml/returnXml/achp_aba_number");
1642         acctNumber = activityXml.valueOf("activityXml/returnXml/achp_acct_number");
1643         nameonacct = activityXml.valueOf("activityXml/returnXml/achp_name_on_acct");
1644         typeofacct = activityXml.valueOf("activityXml/returnXml/achp_check_saving_code");
1645         pmtStatus = "A";
1646 
1647         AchPmt pmt = new AchPmt(pmtAmt, feeAmt, abaNumber, acctNumber, pmtStatus, nameonacct, typeofacct);
1648         AchPmtDO pmtobj = new AchPmtDO(pmt, -1, companyId.longValue(), agreementId.longValue(), userId.longValue(), null);
1649         createDataObject(pmtobj);
1650       }
1651 
1652 //* cr 2002081501 - moved add of the action to here so that it is only added if actions is good
1653       dataQuery = "Insert into ACTION_RESULTS_HISTORY ";
1654       dataQuery += "(ACRH_ID,";
1655       dataQuery += "ACRH_AGRM_ID,";
1656       dataQuery += "ACRH_ACT_ID,";
1657       dataQuery += "ACRH_RES_ID,";
1658       dataQuery += "ACRH_LET_ID,";
1659       dataQuery += "ACRH_USER_ID,";
1660       dataQuery += "ACRH_QPLAN_ID,";
1661       dataQuery += "ACRH_DATE,";
1662       dataQuery += "ACRH_COMMENTS,";
1663       dataQuery += "ACRH_CUSTOMER_CONTACT,";
1664       dataQuery += "ACRH_NEXT_REVIEW_DATE, ";
1665       dataQuery += "ACRH_TIME_LOOP,";
1666       dataQuery += "ACRH_DAY_LOOP, ";
1667       dataQuery += " ACRH_FLAG_SHOW) ";
1668       dataQuery += "values (";
1669       dataQuery += ACRH_ID + ",";
1670       dataQuery += agreementId.toString() + ",";
1671       dataQuery += new Long(activityXml.valueOf("activityXml/activity/acrh_act_id")) + ",";
1672       dataQuery += new Long(activityXml.valueOf("activityXml/activity/acrh_res_id")) + ",";
1673       dataQuery += letterId + ",";
1674       dataQuery += userId + ",";
1675       dataQuery += qplanId + ",";
1676       dataQuery += "SYSDATE+(" + timeOffset + "/24),'";
1677       dataQuery += StringFormat.toSafeOracleString(ACRH_COMMENTS) + "',";
1678       dataQuery += custCont + ",";
1679       dataQuery += ((nextdata.equals("")) ? ("NULL, ") : ("TO_DATE('" + nextdata + "','mm-dd-yyyy'), "));
1680       dataQuery += ACRH_TIME_LOOP + ",";
1681       dataQuery += ACRH_DAY_LOOP + ",";
1682       if(activityXml.valueOf("activityXml/resultRules/resultXml/res_miscval_store").equals("Y")) {
1683         dataQuery += "'Y')";
1684       }
1685       else {
1686         dataQuery += "'N')";
1687       }
1688 
1689       total = da.makeInsert(dataQuery);
1690       if(total != 1) {
1691         throw new InstantbankException("511008-A", "Failed to save in the Action Result History");
1692       }
1693 
1694       if(workItemId.longValue() > 0) {
1695         queueServices.setLastActivityIdToWorkItem(workItemId, ACRH_ID);
1696       }
1697 
1698       if(mustToSavePromise) {
1699         if(activityXml.valueOf("activityXml/resultRules/resultXml/res_prval_grace_days").length() > 0) {
1700           graceDays = activityXml.valueOf("activityXml/resultRules/resultXml/res_prval_grace_days");
1701         }
1702         else {
1703           graceDays = "0";
1704         }
1705         prmType = activityXml.valueOf("activityXml/resultRules/resultXml/res_prval_type");
1706         calendarList = activityXml.selectSingleNode("activityXml/resultRules/Calendars").getChildNodes();
1707 
1708         graceDaysTotal = calculateGraceDays(duedata, graceDays, prmType, calendarList);
1709 
1710         dataQuery = "INSERT INTO PROMISES (";
1711         dataQuery += "PRM_ID, ";
1712         dataQuery += "PRM_DATE, ";
1713         dataQuery += "PRM_DUE_DATE, ";
1714         dataQuery += "PRM_AMOUNT, ";
1715         dataQuery += "PRM_STATUS, ";
1716         dataQuery += "PRM_ACRH_ID ";
1717         dataQuery += ") VALUES (";
1718         dataQuery += new Long(UniqueIDGenerator.instance().getNextId()) + ", ";
1719         dataQuery += "sysdate, ";
1720         dataQuery += "TO_DATE('" + duedata + "','mm-dd-yyyy')+" + graceDaysTotal + ",";
1721         dataQuery += amount + ", ";
1722         dataQuery += "'" + status + "', ";
1723         dataQuery += ACRH_ID + ")";
1724         da.makeInsert(dataQuery);
1725         dataQuery = "SELECT agrm_num_promises_current FROM agreements WHERE agrm_id = " + agreementId.toString();
1726         rs = st.executeQuery(dataQuery);
1727         while(rs.next()) {
1728           numberOfCurrentPromises = rs.getLong("agrm_num_promises_current");
1729         }
1730         numberOfCurrentPromises++;
1731         dataQuery = "UPDATE agreements SET agrm_num_promises_current = " + (new Long(numberOfCurrentPromises)).toString() + " WHERE agrm_id = " + agreementId.toString();
1732         da.makeInsert(dataQuery);
1733       }
1734 
1735       xmlResponse = XMLUtils.setAnswer("OK", "", "Activity Recorded", "");
1736       return (xmlResponse);
1737     }
1738     catch(Exception e) {
1739       e.printStackTrace();
1740       this.context.setRollbackOnly();
1741       throw new InstantbankException(e, "511008", "Failed to add Activity Record from the database");
1742     }
1743     finally {
1744       try {
1745         if(rs != null) {
1746           rs.close();
1747         }
1748         if(st != null) {
1749           st.close();
1750         }
1751         if(da != null) {
1752           da.disconnect();
1753         }
1754       }
1755       catch(Exception e) {
1756       }
1757     }
1758   }
1759 
1760 
1761   public void saveAction(String data, Long companyId, Long userId) throws InstantbankException {
1762     String activeIndicator = "Y";
1763     ByteArrayInputStream stream;
1764     DOMParser docParser = new DOMParser();
1765     long actionId;
1766     Long NumId = new Long("0");
1767     NodeList FirstTag;
1768     NodeList FirstChild;
1769     String Description = new String("");
1770     String Code = new String("");
1771     String securityLevel = new String("");
1772     String Id = new String("");
1773     String xml;
1774     String sqlInsert;
1775     String sqlUpdate;
1776     String sqlDelete;
1777     String strActionId;
1778     XMLDocument xmlDoc;
1779     DataAccess da = null;
1780     try {
1781       xml = XMLUtils.xmlHeader() + data;
1782       xmlDoc = null;
1783       stream = new ByteArrayInputStream(xml.getBytes());
1784       docParser.setValidationMode(false);
1785       docParser.parse(stream);
1786       xmlDoc = docParser.getDocument();
1787 
1788       FirstTag = xmlDoc.getElementsByTagName("ActionList");
1789       FirstTag = FirstTag.item(0).getChildNodes();
1790       FirstChild = FirstTag.item(0).getChildNodes();
1791 
1792       for(int i = 0; i < FirstChild.getLength(); i++) {
1793         Node n;
1794         n = FirstChild.item(i);
1795         if(n.getNodeName().equals("id")) {
1796           NumId = new Long(n.getChildNodes().item(0).getNodeValue());
1797         }
1798         else if(n.getNodeName().equals("description")) {
1799           Description = n.getChildNodes().item(0).getNodeValue();
1800         }
1801         else if(n.getNodeName().equals("code")) {
1802           Code = n.getChildNodes().item(0).getNodeValue();
1803         }
1804         else if(n.getNodeName().equals("securitylevel")) {
1805           securityLevel = n.getChildNodes().item(0).getNodeValue();
1806         }
1807         else if(n.getNodeName().equals("activeindicator")) {
1808           activeIndicator = n.getChildNodes().item(0).getNodeValue();
1809         }
1810       }
1811 
1812       da = new DataAccess();
1813       da.connect();
1814 
1815       if(NumId.equals(new Long("0"))) {
1816         actionId = UniqueIDGenerator.instance().getNextId();
1817         strActionId = new String(new Long(actionId).toString());
1818         sqlInsert = "INSERT INTO actions (act_id, act_code, act_security_level, act_description, act_last_changed_date, act_active_indicator, act_cmp_id, act_last_changed_by) VALUES (" + strActionId + ", '" + StringFormat.toSafeOracleString(Code) + "', " + securityLevel + ", '" + StringFormat.toSafeOracleString(Description) + "', SYSDATE, '" + activeIndicator + "', " + companyId.toString() + ", " + userId.toString() + ")";
1819         da.makeInsert(sqlInsert);
1820       }
1821       else {
1822         actionId = NumId.longValue();
1823         sqlUpdate = "UPDATE actions SET act_code = '" + StringFormat.toSafeOracleString(Code.toString()) + "', act_description = '" + StringFormat.toSafeOracleString(Description.toString()) + "', act_security_level = " + securityLevel.toString() + ", act_last_changed_date = SYSDATE, act_last_changed_by =" + userId.toString() + ", act_active_indicator = '" + activeIndicator + "' WHERE (act_id = " + actionId + ") AND (act_cmp_id = " + companyId.toString() + ")";
1824         da.makeUpdate(sqlUpdate);
1825       }
1826 
1827       sqlDelete = "DELETE FROM action_result_links WHERE arl_act_id = " + actionId;
1828       da.makeDelete(sqlDelete);
1829 
1830       FirstTag = xmlDoc.getElementsByTagName("SelectedResults");
1831       FirstTag = FirstTag.item(0).getChildNodes();
1832 
1833       for(int i = 0; i < FirstTag.getLength(); i++) {
1834         FirstChild = FirstTag.item(i).getChildNodes();
1835         Node n;
1836         n = FirstChild.item(0);
1837         Id = n.getChildNodes().item(0).getNodeValue();
1838         sqlInsert = "INSERT INTO action_result_links (arl_act_id, arl_res_id, arl_date, arl_active_indicator) VALUES(" + actionId + ", " + Id.toString() + ", SYSDATE, 'Y')";
1839         da.makeInsert(sqlInsert);
1840       }
1841     }
1842     catch(Exception e) {
1843       this.context.setRollbackOnly();
1844       throw new InstantbankException(e, "511009", "Failed to save action ");
1845     }
1846     finally {
1847       try {
1848         if(da != null) {
1849           da.disconnect();
1850         }
1851       }
1852       catch(Exception e) {
1853       }
1854     }
1855   }
1856 
1857 
1858   public void saveResult(String data, Long companyId, Long userId) throws InstantbankException {
1859     Long auxLong;
1860     DataAccess da = null;
1861     XMLDocument doc;
1862     DOMParser docParser = new DOMParser();
1863     NodeList nl;
1864     String query = "";
1865     Long resultId;
1866     ResultSet rs = null;
1867     SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
1868     Statement st = null;
1869     ByteArrayInputStream stream;
1870 
1871     /*The following variable (RES_PRVAL_MIN_PERCENT) should be a Folat,
1872     but is treated as String to avoid conversion inconsistencies.*/
1873     String RES_PRVAL_MIN_PERCENT = "''";
1874     String RES_QTVAL_SUPERVISOR_TRANS = null;
1875     String RES_QTVAL_COLLECTIONS = null;
1876     Long RES_MISCVAL_DAYS_TO_DISPLAY = null;
1877     String RES_MISCVAL_REPORT = null;
1878     String RES_MISCVAL_ACH = null;  //*CR2002062600 - add ach drafting to collections*//
1879     Long RES_SECURITY_LEVEL = null;
1880     Long RES_ID = null;
1881     Long RES_MISCVAL_MAX_DAY_LOOP = null;
1882     Long RES_LAST_CHANGED_BY = null;
1883     Long RES_PRVAL_MAX_DAYS = null;
1884     String RES_QTVAL_RECOVERY = null;
1885     String RES_MISCVAL_TIME_LOOP = null;
1886     Long RES_CMP_ID = null;
1887     String RES_DESCRIPTION = null;
1888     Long RES_MISCVAL_DEFAULT_TIME_LOOP = null;
1889     Long RES_NVCDV_MAX_DAYS = null;
1890     String RES_PRVAL_REQUIRED_IND = null;
1891     String RES_QTVAL_REQUIRED_IND = null;
1892     String RES_MISCVAL_COMMENTS = null;
1893     String RES_NVCDV_REQUIRED_IND = null;
1894     String RES_MISCVAL_LETTER = null;
1895     /*The following variable (RES_PRVAL_MIN_PERCENT) should be a Folat,
1896     but is treated as String to avoid conversion inconsistencies.*/
1897     String RES_PRVAL_MIN_AMOUNT = "''";
1898     String RES_QUEUE_STATS_PROMISE = null;
1899     String RES_NVCDV_BASE = null;
1900     String RES_MISCVAL_STORE = null;
1901     String RES_QTVAL_CUSTOMER_SERVICE = null;
1902     java.sql.Date RES_LAST_CHANGED_DATE = null;
1903     Long RES_QTVAL_DEFAULT_QUEUE_ID = null;
1904     Long RES_MISCVAL_DEFAULT_LETTER_ID = null;
1905     String RES_QUEUE_STATS_CUSTOMER_CONT = null;
1906     String RES_PRVAL_TYPE = null;
1907     String RES_QTVAL_OTHER = null;
1908     String RES_QUEUE_STATS_ATTEMPTS_CONT = null;
1909     String RES_NVCDV_TYPE = null;
1910     String RES_QUEUE_STATS_INDIRECT_CONT = null;
1911     String RES_QUEUE_STATS_TRANSFER = null;
1912     String RES_QTVAL_CLEAR_TRANS = null;
1913     String RES_CODE = null;
1914     Long RES_NVCDV_ADVANCE_DAYS = null;
1915     Long RES_PRVAL_GRACE_DAYS = null;
1916     String RES_ACTIVE_INDICATOR = null;
1917 
1918     try {
1919       da = new DataAccess();
1920       da.connect();
1921       st = da.getConnection().createStatement();
1922       doc = null;
1923       stream = new ByteArrayInputStream(data.getBytes());
1924       docParser.setValidationMode(false);
1925       docParser.parse(stream);
1926       doc = docParser.getDocument();
1927       StringWriter sw = new StringWriter();
1928       PrintWriter pw = new PrintWriter(sw);
1929       doc.print(pw);
1930       nl = doc.selectNodes("/Result/Id/text()");
1931       resultId = new Long(nl.item(0).getNodeValue());
1932       if(resultId.equals(new Long("0"))) {
1933         RES_ID = new Long(UniqueIDGenerator.instance().getNextId());
1934       }
1935       else {
1936         RES_ID = resultId;
1937       }
1938 
1939       RES_MISCVAL_COMMENTS = doc.valueOf("Result/MVComments");
1940       if(!(doc.valueOf("Result/MVDefaultLetterId")).equals("")) {
1941         auxLong = new Long(doc.valueOf("Result/MVDefaultLetterId"));
1942       }
1943       else {
1944         auxLong = null;
1945       }
1946       RES_MISCVAL_DEFAULT_LETTER_ID = auxLong;
1947       RES_MISCVAL_LETTER = doc.valueOf("Result/MVLetters");
1948       RES_NVCDV_BASE = doc.valueOf("Result/CDBase");
1949       RES_NVCDV_REQUIRED_IND = doc.valueOf("Result/CDRequiredInd");
1950       RES_NVCDV_TYPE = doc.valueOf("Result/CDType");
1951       RES_PRVAL_REQUIRED_IND = doc.valueOf("Result/PVRequiredIndicator");
1952       RES_PRVAL_TYPE = doc.valueOf("Result/PVType");
1953       RES_QTVAL_CLEAR_TRANS = doc.valueOf("Result/QTClearTransfer");
1954       RES_QTVAL_COLLECTIONS = doc.valueOf("Result/QTCollections");
1955       RES_QTVAL_CUSTOMER_SERVICE = doc.valueOf("Result/QTCustomerService");
1956       if(!(doc.valueOf("Result/QTDefaultQueueId")).equals("")) {
1957         auxLong = new Long(doc.valueOf("Result/QTDefaultQueueId"));
1958       }
1959       else {
1960         auxLong = null;
1961       }
1962       RES_QTVAL_DEFAULT_QUEUE_ID = auxLong;
1963       RES_QTVAL_OTHER = doc.valueOf("Result/QTOther");
1964       RES_QTVAL_RECOVERY = doc.valueOf("Result/QTRecovery");
1965       RES_QTVAL_REQUIRED_IND = doc.valueOf("Result/QTRequiredIndicator");
1966       RES_QTVAL_SUPERVISOR_TRANS = doc.valueOf("Result/QTSupervisorTransfer");
1967       RES_QUEUE_STATS_ATTEMPTS_CONT = doc.valueOf("Result/QSAttemptedContact");
1968       RES_QUEUE_STATS_CUSTOMER_CONT = doc.valueOf("Result/QSCustomerContact");
1969       RES_QUEUE_STATS_INDIRECT_CONT = doc.valueOf("Result/QSIndirectContact");
1970       RES_QUEUE_STATS_PROMISE = doc.valueOf("Result/QSPromise");
1971       RES_QUEUE_STATS_TRANSFER = doc.valueOf("Result/QSTransfer");
1972       if(!(doc.valueOf("Result/PVGraceDays")).equals("")) {
1973         auxLong = new Long(doc.valueOf("Result/PVGraceDays"));
1974       }
1975       else {
1976         auxLong = null;
1977       }
1978       RES_PRVAL_GRACE_DAYS = auxLong;
1979       if(!(doc.valueOf("Result/PVMaximumDays")).equals("")) {
1980         auxLong = new Long(doc.valueOf("Result/PVMaximumDays"));
1981       }
1982       else {
1983         auxLong = null;
1984       }
1985       RES_PRVAL_MAX_DAYS = auxLong;
1986       if(!(doc.valueOf("Result/PVMinimumPercent")).equals("")) {
1987         RES_PRVAL_MIN_PERCENT = doc.valueOf("Result/PVMinimumPercent");
1988       }
1989       if(!(doc.valueOf("Result/PVMinimumAmount")).equals("")) {
1990         RES_PRVAL_MIN_AMOUNT = doc.valueOf("Result/PVMinimumAmount");
1991       }
1992       if(!(doc.valueOf("Result/CDMaximumDays")).equals("")) {
1993         auxLong = new Long(doc.valueOf("Result/CDMaximumDays"));
1994       }
1995       else {
1996         auxLong = null;
1997       }
1998       RES_NVCDV_MAX_DAYS = auxLong;
1999       if(!(doc.valueOf("Result/CDAdvanceDays")).equals("")) {
2000         auxLong = new Long(doc.valueOf("Result/CDAdvanceDays"));
2001       }
2002       else {
2003         auxLong = null;
2004       }
2005       RES_NVCDV_ADVANCE_DAYS = auxLong;
2006       if(!(doc.valueOf("Result/MVDefaultTimeLoop")).equals("")) {
2007         auxLong = new Long(doc.valueOf("Result/MVDefaultTimeLoop"));
2008       }
2009       else {
2010         auxLong = null;
2011       }
2012       RES_MISCVAL_DEFAULT_TIME_LOOP = auxLong;
2013       if(!(doc.valueOf("Result/MVMaxDayLoop")).equals("")) {
2014         auxLong = new Long(doc.valueOf("Result/MVMaxDayLoop"));
2015       }
2016       else {
2017         auxLong = null;
2018       }
2019       RES_MISCVAL_MAX_DAY_LOOP = auxLong;
2020       if(!(doc.valueOf("Result/MVDaysToDisplay")).equals("")) {
2021         auxLong = new Long(doc.valueOf("Result/MVDaysToDisplay"));
2022       }
2023       else {
2024         auxLong = null;
2025       }
2026       RES_MISCVAL_DAYS_TO_DISPLAY = auxLong;
2027       RES_CMP_ID = companyId;
2028       RES_SECURITY_LEVEL = new Long(doc.valueOf("Result/SecurityLevel"));
2029       RES_LAST_CHANGED_BY = userId;
2030       RES_CODE = doc.valueOf("Result/Code");
2031       RES_DESCRIPTION = doc.valueOf("Result/Description");
2032       RES_ACTIVE_INDICATOR = doc.valueOf("Result/ActiveIndicator");
2033       RES_MISCVAL_TIME_LOOP = doc.valueOf("Result/MVTimeLoop");
2034       RES_MISCVAL_STORE = doc.valueOf("Result/MVStore");
2035       RES_MISCVAL_REPORT = doc.valueOf("Result/MVReport");
2036       RES_MISCVAL_ACH = doc.valueOf("Result/MVAch");  //*CR2002062600 - add ach drafting to collections*//
2037       rs = st.executeQuery("SELECT sysdate FROM dual");
2038       while(rs.next()) {
2039         RES_LAST_CHANGED_DATE = rs.getDate(1);
2040       }
2041 
2042       if(resultId.equals(new Long("0"))) {
2043         query = " INSERT INTO results (" +
2044           " RES_ID," +
2045           " RES_CMP_ID," +
2046           " RES_CODE," +
2047           " RES_DESCRIPTION," +
2048           " RES_SECURITY_LEVEL," +
2049           " RES_LAST_CHANGED_BY," +
2050           " RES_LAST_CHANGED_DATE," +
2051           " RES_PRVAL_REQUIRED_IND," +
2052           " RES_PRVAL_GRACE_DAYS," +
2053           " RES_PRVAL_MAX_DAYS," +
2054           " RES_PRVAL_MIN_AMOUNT," +
2055           " RES_PRVAL_MIN_PERCENT," +
2056           " RES_PRVAL_TYPE," +
2057           " RES_QUEUE_STATS_PROMISE," +
2058           " RES_QUEUE_STATS_CUSTOMER_CONT," +
2059           " RES_QUEUE_STATS_TRANSFER," +
2060           " RES_QUEUE_STATS_ATTEMPTS_CONT," +
2061           " RES_QUEUE_STATS_INDIRECT_CONT," +
2062           " RES_QTVAL_REQUIRED_IND," +
2063           " RES_QTVAL_SUPERVISOR_TRANS," +
2064           " RES_QTVAL_CLEAR_TRANS," +
2065           " RES_QTVAL_DEFAULT_QUEUE_ID," +
2066           " RES_QTVAL_COLLECTIONS," +
2067           " RES_QTVAL_RECOVERY," +
2068           " RES_QTVAL_CUSTOMER_SERVICE," +
2069           " RES_QTVAL_OTHER," +
2070           " RES_MISCVAL_COMMENTS," +
2071           " RES_MISCVAL_LETTER," +
2072           " RES_MISCVAL_DAYS_TO_DISPLAY," +
2073           " RES_MISCVAL_DEFAULT_LETTER_ID," +
2074           " RES_MISCVAL_TIME_LOOP," +
2075           " RES_MISCVAL_STORE," +
2076           " RES_MISCVAL_REPORT," +
2077           " RES_MISCVAL_ACH," +   //*CR2002062600 - add ach drafting to collections*//
2078         " RES_MISCVAL_DEFAULT_TIME_LOOP," +
2079           " RES_MISCVAL_MAX_DAY_LOOP," +
2080           " RES_NVCDV_REQUIRED_IND," +
2081           " RES_NVCDV_ADVANCE_DAYS," +
2082           " RES_NVCDV_MAX_DAYS," +
2083           " RES_NVCDV_BASE," +
2084           " RES_NVCDV_TYPE," +
2085           " RES_ACTIVE_INDICATOR" +
2086           ") values (" +
2087           RES_ID + ", " +
2088           RES_CMP_ID + ", " +
2089           "'" + StringFormat.toSafeOracleString(RES_CODE) + "', " +
2090           "'" + StringFormat.toSafeOracleString(RES_DESCRIPTION) + "', " +
2091           RES_SECURITY_LEVEL + ", " +
2092           RES_LAST_CHANGED_BY + ", " +
2093           "TO_DATE('" + sdf.format(RES_LAST_CHANGED_DATE) + "','mm-dd-yyyy'), " +
2094           "'" + RES_PRVAL_REQUIRED_IND + "', " +
2095           RES_PRVAL_GRACE_DAYS + ", " +
2096           RES_PRVAL_MAX_DAYS + ", " +
2097           RES_PRVAL_MIN_AMOUNT + ", " +
2098           RES_PRVAL_MIN_PERCENT + ", " +
2099           "'" + RES_PRVAL_TYPE + "', " +
2100           "'" + RES_QUEUE_STATS_PROMISE + "', " +
2101           "'" + RES_QUEUE_STATS_CUSTOMER_CONT + "', " +
2102           "'" + RES_QUEUE_STATS_TRANSFER + "', " +
2103           "'" + RES_QUEUE_STATS_ATTEMPTS_CONT + "', " +
2104           "'" + RES_QUEUE_STATS_INDIRECT_CONT + "', " +
2105           "'" + RES_QTVAL_REQUIRED_IND + "', " +
2106           "'" + RES_QTVAL_SUPERVISOR_TRANS + "', " +
2107           "'" + RES_QTVAL_CLEAR_TRANS + "', " +
2108           RES_QTVAL_DEFAULT_QUEUE_ID + ", " +
2109           "'" + RES_QTVAL_COLLECTIONS + "', " +
2110           "'" + RES_QTVAL_RECOVERY + "', " +
2111           "'" + RES_QTVAL_CUSTOMER_SERVICE + "', " +
2112           "'" + RES_QTVAL_OTHER + "', " +
2113           "'" + RES_MISCVAL_COMMENTS + "', " +
2114           "'" + RES_MISCVAL_LETTER + "', " +
2115           RES_MISCVAL_DAYS_TO_DISPLAY + ", " +
2116           RES_MISCVAL_DEFAULT_LETTER_ID + ", " +
2117           "'" + RES_MISCVAL_TIME_LOOP + "', " +
2118           "'" + RES_MISCVAL_STORE + "', " +
2119           "'" + RES_MISCVAL_REPORT + "', " +
2120           "'" + RES_MISCVAL_ACH + "', " +   //*CR2002062600 - add ach drafting to collections*//
2121         RES_MISCVAL_DEFAULT_TIME_LOOP + ", " +
2122           RES_MISCVAL_MAX_DAY_LOOP + ", " +
2123           "'" + RES_NVCDV_REQUIRED_IND + "', " +
2124           RES_NVCDV_ADVANCE_DAYS + ", " +
2125           RES_NVCDV_MAX_DAYS + ", " +
2126           "'" + RES_NVCDV_BASE + "', " +
2127           "'" + RES_NVCDV_TYPE + "', " +
2128           "'" + RES_ACTIVE_INDICATOR + "')";
2129       }
2130       else {
2131         query = " UPDATE results SET" +
2132           " RES_CMP_ID = " + RES_CMP_ID + "," +
2133           " RES_CODE = '" + StringFormat.toSafeOracleString(RES_CODE) + "'," +
2134           " RES_DESCRIPTION = '" + StringFormat.toSafeOracleString(RES_DESCRIPTION) + "'," +
2135           " RES_SECURITY_LEVEL = " + RES_SECURITY_LEVEL + "," +
2136           " RES_LAST_CHANGED_BY = " + RES_LAST_CHANGED_BY + "," +
2137           " RES_LAST_CHANGED_DATE = TO_DATE('" + sdf.format(RES_LAST_CHANGED_DATE) + "','mm-dd-yyyy')," +
2138           " RES_PRVAL_REQUIRED_IND = '" + RES_PRVAL_REQUIRED_IND + "'," +
2139           " RES_PRVAL_GRACE_DAYS = " + RES_PRVAL_GRACE_DAYS + "," +
2140           " RES_PRVAL_MAX_DAYS = " + RES_PRVAL_MAX_DAYS + "," +
2141           " RES_PRVAL_MIN_AMOUNT = " + RES_PRVAL_MIN_AMOUNT + "," +
2142           " RES_PRVAL_MIN_PERCENT = " + RES_PRVAL_MIN_PERCENT + "," +
2143           " RES_PRVAL_TYPE = '" + RES_PRVAL_TYPE + "'," +
2144           " RES_QUEUE_STATS_PROMISE = '" + RES_QUEUE_STATS_PROMISE + "'," +
2145           " RES_QUEUE_STATS_CUSTOMER_CONT = '" + RES_QUEUE_STATS_CUSTOMER_CONT + "'," +
2146           " RES_QUEUE_STATS_TRANSFER = '" + RES_QUEUE_STATS_TRANSFER + "'," +
2147           " RES_QUEUE_STATS_ATTEMPTS_CONT = '" + RES_QUEUE_STATS_ATTEMPTS_CONT + "'," +
2148           " RES_QUEUE_STATS_INDIRECT_CONT = '" + RES_QUEUE_STATS_INDIRECT_CONT + "'," +
2149           " RES_QTVAL_REQUIRED_IND = '" + RES_QTVAL_REQUIRED_IND + "'," +
2150           " RES_QTVAL_SUPERVISOR_TRANS = '" + RES_QTVAL_SUPERVISOR_TRANS + "'," +
2151           " RES_QTVAL_CLEAR_TRANS = '" + RES_QTVAL_CLEAR_TRANS + "'," +
2152           " RES_QTVAL_DEFAULT_QUEUE_ID = " + RES_QTVAL_DEFAULT_QUEUE_ID + "," +
2153           " RES_QTVAL_COLLECTIONS = '" + RES_QTVAL_COLLECTIONS + "'," +
2154           " RES_QTVAL_RECOVERY = '" + RES_QTVAL_RECOVERY + "'," +
2155           " RES_QTVAL_CUSTOMER_SERVICE = '" + RES_QTVAL_CUSTOMER_SERVICE + "'," +
2156           " RES_QTVAL_OTHER = '" + RES_QTVAL_OTHER + "'," +
2157           " RES_MISCVAL_COMMENTS = '" + RES_MISCVAL_COMMENTS + "'," +
2158           " RES_MISCVAL_LETTER = '" + RES_MISCVAL_LETTER + "'," +
2159           " RES_MISCVAL_DAYS_TO_DISPLAY = " + RES_MISCVAL_DAYS_TO_DISPLAY + "," +
2160           " RES_MISCVAL_DEFAULT_LETTER_ID = " + RES_MISCVAL_DEFAULT_LETTER_ID + "," +
2161           " RES_MISCVAL_TIME_LOOP = '" + RES_MISCVAL_TIME_LOOP + "'," +
2162           " RES_MISCVAL_STORE = '" + RES_MISCVAL_STORE + "'," +
2163           " RES_MISCVAL_REPORT = '" + RES_MISCVAL_REPORT + "'," +
2164           " RES_MISCVAL_ACH = '" + RES_MISCVAL_ACH + "'," +   //*CR2002062600 - add ach drafting to collections*//
2165         " RES_MISCVAL_DEFAULT_TIME_LOOP = " + RES_MISCVAL_DEFAULT_TIME_LOOP + "," +
2166           " RES_MISCVAL_MAX_DAY_LOOP = " + RES_MISCVAL_MAX_DAY_LOOP + "," +
2167           " RES_NVCDV_REQUIRED_IND = '" + RES_NVCDV_REQUIRED_IND + "'," +
2168           " RES_NVCDV_ADVANCE_DAYS = " + RES_NVCDV_ADVANCE_DAYS + "," +
2169           " RES_NVCDV_MAX_DAYS = " + RES_NVCDV_MAX_DAYS + "," +
2170           " RES_NVCDV_BASE = '" + RES_NVCDV_BASE + "'," +
2171           " RES_NVCDV_TYPE = '" + RES_NVCDV_TYPE + "'," +
2172           " RES_ACTIVE_INDICATOR = '" + RES_ACTIVE_INDICATOR + "'" +
2173           " WHERE RES_ID = " + RES_ID;
2174       }
2175       da.makeInsert(query);
2176 
2177     }
2178     catch(Exception e) {
2179       this.context.setRollbackOnly();
2180       throw new InstantbankException(e, "511010", "Failed to save Result ");
2181     }
2182     finally {
2183       try {
2184         if(rs != null) {
2185           rs.close();
2186         }
2187         if(st != null) {
2188           st.close();
2189         }
2190         if(da != null) {
2191           da.disconnect();
2192         }
2193       }
2194       catch(Exception e) {
2195       }
2196     }
2197   }
2198 
2199 
2200   private void setRollbackOnly() {
2201     try {
2202       this.context.setRollbackOnly();
2203     }
2204     catch(Exception ne) {
2205     }
2206   }
2207 
2208 
2209   public void setSessionContext(SessionContext ctx) {
2210     this.context = ctx;
2211   }
2212 }
2213