1 package com.instantbank.collections.creditInfo.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 javax.ejb.CreateException;
12 import javax.ejb.EJBContext;
13 import javax.ejb.EJBException;
14 import javax.ejb.SessionBean;
15 import javax.ejb.SessionContext;
16 import javax.naming.NamingException;
17 import org.w3c.dom.Node;
18 import org.w3c.dom.NodeList;
19 import oracle.xml.parser.v2.DOMParser;
20 import oracle.xml.parser.v2.XMLDocument;
21 import oracle.xml.parser.v2.XMLNode;
22 import oracle.xml.parser.v2.XSLException;
23 import com.instantbank.collections.customerInfo.ejb.CustomerInfoServices;
24 import com.instantbank.collections.customerInfo.ejb.CustomerInfoServicesHome;
25 import com.instantbank.collections.util.DataAccess;
26 import com.instantbank.collections.util.InstantbankException;
27 import com.instantbank.collections.util.ServiceLocator;
28 import com.instantbank.collections.util.StringFormat;
29 import com.instantbank.collections.util.UniqueIDGenerator;
30 import com.instantbank.collections.util.XMLDataAccess;
31 import com.instantbank.collections.util.XMLUtils;
32
33 public class AccountInfoServicesBean
34 implements SessionBean {
35 private EJBContext context;
36
37
38 public AccountInfoServicesBean() { }
39
40
41 public void ejbCreate() throws CreateException {
42
43 }
44
45
46 public void ejbActivate() { }
47
48
49 public void ejbPassivate() { }
50
51
52 public void ejbRemove() { }
53
54
55 public void setSessionContext(SessionContext ctx) {
56 this.context = ctx;
57 }
58
59
60 private boolean compareCollateral(XMLDocument originalDoc, XMLDocument newDoc, String valueToCompareOri, String valueToCompareDes) throws XSLException {
61 String originalValue;
62 String newValue;
63
64 originalValue = originalDoc.valueOf("/CollateralsList/" + valueToCompareOri);
65 newValue = newDoc.valueOf("/Maintenance/" + valueToCompareDes);
66 if(originalValue.equals(newValue)) {
67 return true;
68 }
69 else {
70 return false;
71 }
72 }
73
74
75 private boolean compareCustomerInfo(XMLDocument newData, XMLNode oldNode, String parameter) throws Exception {
76 String param = "AccountDemographics/CustomerRole/Customer/";
77 param += parameter;
78 if(parameter.equals(new String("DriverLicense"))) {
79 parameter = "driverslicense";
80 }
81
82 if(!newData.valueOf(param).equals(new String("NULL"))) {
83 return ((newData.valueOf(param).equals(oldNode.valueOf(parameter.toLowerCase()))) ? true : false);
84 }
85 else {
86 return true;
87 }
88 }
89
90
91 private boolean compareCorporationInfo(XMLDocument newData, XMLNode oldNode, String parameter) throws Exception {
92 String param = "AccountDemographics/CustomerRole/Corporation/";
93 param += parameter;
94 if(!newData.valueOf(param).equals(new String("NULL"))) {
95 return ((newData.valueOf(param).equals(oldNode.valueOf(parameter.toLowerCase()))) ? true : false);
96 }
97 else {
98 return true;
99 }
100 }
101
102
103 private void compareDemographicsXml(Long companyId, Long agrmId, Long userId, String data, String oldXml) throws Exception {
104
105
106 XMLDocument dataDoc;
107 DOMParser docParser = new DOMParser();
108 boolean flagAl = false;
109 boolean flagEm = false;
110 boolean flagPr = false;
111 boolean flagOth = false;
112 boolean flagPl = false;
113 NodeList newAddressList;
114 XMLNode newInfo;
115 NodeList newOccupationList;
116 NodeList newPhoneList;
117 NodeList oldAddressList;
118 XMLNode oldCustomerInfo;
119 XMLNode oldInfo;
120 NodeList oldList;
121 NodeList oldOccupationList;
122 NodeList oldPhoneList;
123 XMLDocument oldXmlDoc;
124 ByteArrayInputStream stream;
125 long lNameKey = 0L;
126
127 dataDoc = null;
128 stream = new ByteArrayInputStream(data.getBytes());
129 docParser.setValidationMode(false);
130 docParser.parse(stream);
131 dataDoc = docParser.getDocument();
132 oldXmlDoc = null;
133 stream = new ByteArrayInputStream(oldXml.getBytes());
134 docParser.setValidationMode(false);
135 docParser.parse(stream);
136 oldXmlDoc = docParser.getDocument();
137
138 oldInfo = (XMLNode)oldXmlDoc.getDocumentElement();
139 oldList = oldInfo.getChildNodes();
140
141 oldCustomerInfo = null;
142 if(dataDoc.valueOf("AccountDemographics/CustomerRole/Role").equals("PR")) {
143 flagPr = true;
144 for(int i = 0; i < oldList.getLength(); i++) {
145 oldInfo = (XMLNode)oldList.item(i);
146 if(oldInfo.valueOf("./role").equals("PR")) {
147 oldCustomerInfo = (XMLNode)oldInfo.selectSingleNode("./Customer/Info");
148 }
149 }
150 }
151 else if(dataDoc.valueOf("AccountDemographics/CustomerRole/Role").equals("AL")) {
152 for(int i = 0; i < oldList.getLength(); i++) {
153 oldInfo = (XMLNode)oldList.item(i);
154 if((oldInfo.valueOf("./role").equals("AL")) && (dataDoc.valueOf("AccountDemographics/CustomerRole/Customer/Id").equals(oldInfo.valueOf("./customerid")))) {
155 oldCustomerInfo = (XMLNode)oldInfo.selectSingleNode("./Customer/Info");
156 flagAl = true;
157 }
158 }
159 }
160 else if(dataDoc.valueOf("AccountDemographics/CustomerRole/Type").equals("PR") || dataDoc.valueOf("AccountDemographics/CustomerRole/Type").equals("AL")) {
161 for(int i = 0; i < oldList.getLength(); i++) {
162 oldInfo = (XMLNode)oldList.item(i);
163 if((oldInfo.valueOf("./role").equals(dataDoc.valueOf("AccountDemographics/CustomerRole/Role"))) && (dataDoc.valueOf("AccountDemographics/CustomerRole/Customer/Id").equals(oldInfo.valueOf("./customerid")))) {
164 oldCustomerInfo = (XMLNode)oldInfo.selectSingleNode("./Customer/Info");
165 flagOth = true;
166 }
167 }
168 }
169
170 if((flagAl) || (flagPr) || (flagOth)) {
171
172
173
174 String param = "AccountDemographics/CustomerRole/Customer/";
175
176
177 if(dataDoc.valueOf(param + "NameKey").length() > 0) {
178 lNameKey = Long.parseLong(dataDoc.valueOf(param + "NameKey"));
179 }
180
181
182 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "FirstName")) {
183 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "FirstName", oldCustomerInfo.valueOf("firstname"), dataDoc.valueOf(param + "FirstName"), lNameKey);
184 }
185 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "MiddleName")) {
186 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "MiddleName", oldCustomerInfo.valueOf("middlename"), dataDoc.valueOf(param + "MiddleName"), lNameKey);
187 }
188 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "LastName")) {
189 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "LastName", oldCustomerInfo.valueOf("lastname"), dataDoc.valueOf(param + "LastName"), lNameKey);
190 }
191 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "Generation")) {
192 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Generation", oldCustomerInfo.valueOf("generation"), dataDoc.valueOf(param + "Generation"), lNameKey);
193 }
194 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "StatusId")) {
195 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "StatusId", getCustomerStatus(companyId, oldCustomerInfo.valueOf("statusid")), getCustomerStatus(companyId, dataDoc.valueOf(param + "StatusId")), 0);
196 }
197 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "BirthDate")) {
198 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "BirthDate", oldCustomerInfo.valueOf("birthdate"), dataDoc.valueOf(param + "BirthDate"), lNameKey);
199 }
200 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "Email")) {
201 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Email", oldCustomerInfo.valueOf("email"), dataDoc.valueOf(param + "Email"), lNameKey);
202 }
203 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "SSN")) {
204 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "SSN", oldCustomerInfo.valueOf("ssn"), dataDoc.valueOf(param + "SSN"), lNameKey);
205 }
206 if(!compareCustomerInfo(dataDoc, oldCustomerInfo, "DriverLicense")) {
207 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "DriverLicense", oldCustomerInfo.valueOf("driverslicense"), dataDoc.valueOf(param + "DriverLicense"), lNameKey);
208 }
209
210 oldInfo = null;
211 oldInfo = oldCustomerInfo;
212 oldPhoneList = oldInfo.getChildNodes();
213 for(int i = 0; i < oldPhoneList.getLength(); i++) {
214 if(((XMLNode)oldPhoneList.item(i)).getNodeName().equals("PhoneList")) {
215 oldPhoneList = oldPhoneList.item(i).getChildNodes();
216 }
217 }
218
219
220
221 newInfo = (XMLNode)dataDoc.getDocumentElement();
222 newPhoneList = newInfo.getChildNodes();
223 newPhoneList = ((NodeList)((NodeList)newPhoneList.item(0).getChildNodes()).item(2).getChildNodes()).item(9).getChildNodes();
224 for(int j = 0; j < newPhoneList.getLength(); j++) {
225 for(int i = 0; i < oldPhoneList.getLength(); i++) {
226 if((((XMLNode)newPhoneList.item(j)).valueOf("./Type").equals(((XMLNode)oldPhoneList.item(i)).valueOf("./phonetype"))) && (((XMLNode)newPhoneList.item(j)).valueOf("./Id").equals(((XMLNode)oldPhoneList.item(i)).valueOf("./phoneid")))) {
227 flagPl = true;
228 if(!((XMLNode)newPhoneList.item(j)).valueOf("./Number").equals(((XMLNode)oldPhoneList.item(i)).valueOf("./phonenumber"))) {
229 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "PhoneNumber - " + ((XMLNode)oldPhoneList.item(i)).valueOf("./phonetype"), ((XMLNode)oldPhoneList.item(i)).valueOf("./phonenumber"), ((XMLNode)newPhoneList.item(j)).valueOf("./Number"), lNameKey);
230 }
231 if(!((XMLNode)newPhoneList.item(j)).valueOf("./Extension").equals(((XMLNode)oldPhoneList.item(i)).valueOf("./phoneextension"))) {
232 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "PhoneExtension", ((XMLNode)oldPhoneList.item(i)).valueOf("./phoneextension"), ((XMLNode)newPhoneList.item(j)).valueOf("./Extension"), lNameKey);
233 }
234 }
235 }
236 if(flagPl == false) {
237 String newPhoneNumber = ((XMLNode)newPhoneList.item(j)).valueOf("./Number");
238 String newPhoneExt = ((XMLNode)newPhoneList.item(j)).valueOf("./Extension");
239 if(newPhoneNumber.length() > 0) {
240 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "PhoneNumber - " + ((XMLNode)newPhoneList.item(j)).valueOf("./Type"), " ", ((XMLNode)newPhoneList.item(j)).valueOf("./Number"), lNameKey);
241 }
242 if(newPhoneExt.length() > 0) {
243 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "PhoneExtension", " ", ((XMLNode)newPhoneList.item(j)).valueOf("./Extension"), lNameKey);
244 }
245 }
246 }
247
248
249
250 oldInfo = null;
251 newInfo = null;
252 oldInfo = oldCustomerInfo;
253 oldAddressList = oldInfo.getChildNodes();
254 for(int i = 0; i < oldAddressList.getLength(); i++) {
255 if(((XMLNode)oldAddressList.item(i)).getNodeName().equals("Address")) {
256 oldAddressList = oldAddressList.item(i).getChildNodes();
257 }
258 }
259
260 newInfo = (XMLNode)dataDoc.getDocumentElement();
261 newAddressList = newInfo.getChildNodes();
262 newAddressList = ((NodeList)((NodeList)newAddressList.item(0).getChildNodes()).item(2).getChildNodes()).item(10).getChildNodes();
263
264 if(!((XMLNode)newAddressList.item(0)).valueOf("./Line1").equals(((XMLNode)oldAddressList.item(0)).valueOf("./address1"))) {
265 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "AddressLine1", ((XMLNode)oldAddressList.item(0)).valueOf("./address1"), ((XMLNode)newAddressList.item(0)).valueOf("./Line1"), lNameKey);
266 }
267 if(!((XMLNode)newAddressList.item(0)).valueOf("./Line2").equals(((XMLNode)oldAddressList.item(0)).valueOf("./address2"))) {
268 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "AddressLine2", ((XMLNode)oldAddressList.item(0)).valueOf("./address2"), ((XMLNode)newAddressList.item(0)).valueOf("./Line2"), lNameKey);
269 }
270 if(!((XMLNode)newAddressList.item(0)).valueOf("./City").equals(((XMLNode)oldAddressList.item(0)).valueOf("./city"))) {
271 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "City", ((XMLNode)oldAddressList.item(0)).valueOf("./city"), ((XMLNode)newAddressList.item(0)).valueOf("./City"), lNameKey);
272 }
273 if(!((XMLNode)newAddressList.item(0)).valueOf("./StateCode").equals(((XMLNode)oldAddressList.item(0)).valueOf("./statecode"))) {
274 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "StateCode", ((XMLNode)oldAddressList.item(0)).valueOf("./statecode"), ((XMLNode)newAddressList.item(0)).valueOf("./StateCode"), lNameKey);
275 }
276 if(!((XMLNode)newAddressList.item(0)).valueOf("./ZipCode").equals(((XMLNode)oldAddressList.item(0)).valueOf("./zipcode"))) {
277 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "ZipCode", ((XMLNode)oldAddressList.item(0)).valueOf("./zipcode"), ((XMLNode)newAddressList.item(0)).valueOf("./ZipCode"), lNameKey);
278 }
279 if(!((XMLNode)newAddressList.item(0)).valueOf("./CountryId").equals(((XMLNode)oldAddressList.item(0)).valueOf("./countryid"))) {
280 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Country", ((XMLNode)oldAddressList.item(0)).valueOf("./countryid"), ((XMLNode)newAddressList.item(0)).valueOf("./CountryId"), lNameKey);
281 }
282 if(!((XMLNode)newAddressList.item(0)).valueOf("./AccommodationStatusId").equals(((XMLNode)oldAddressList.item(0)).valueOf("./accommodationstatusid"))) {
283 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Resident Type", ((XMLNode)oldAddressList.item(0)).valueOf("./accommodationstatusid"), ((XMLNode)newAddressList.item(0)).valueOf("./AccommodationStatusId"), 0);
284 }
285
286 if(!((XMLNode)newAddressList.item(0)).valueOf("./TimeInResidence").equals("NULL")) {
287 if(!((XMLNode)newAddressList.item(0)).valueOf("./TimeInResidence").equals(((XMLNode)oldAddressList.item(0)).valueOf("./timeinresidence"))) {
288 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "TimeInResidence", ((XMLNode)oldAddressList.item(0)).valueOf("./timeinresidence"), ((XMLNode)newAddressList.item(0)).valueOf("./TimeInResidence"), 0);
289 }
290 }
291
292 if(flagAl) {
293 if(!((XMLNode)newAddressList.item(0)).valueOf("./StartDate").equals(((XMLNode)oldAddressList.item(0)).valueOf("./startdate"))) {
294 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "StartDate", ((XMLNode)oldAddressList.item(0)).valueOf("./startdate"), ((XMLNode)newAddressList.item(0)).valueOf("./StartDate"), 0);
295 }
296 if(!((XMLNode)newAddressList.item(0)).valueOf("./EndDate").equals(((XMLNode)oldAddressList.item(0)).valueOf("./enddate"))) {
297 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "EndDate", ((XMLNode)oldAddressList.item(0)).valueOf("./enddate"), ((XMLNode)newAddressList.item(0)).valueOf("./EndDate"), 0);
298 }
299 }
300
301 if(!((XMLNode)newAddressList.item(0)).valueOf("./HomePhone").equals(((XMLNode)oldAddressList.item(0)).valueOf("./homephone"))) {
302 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "HomePhone", ((XMLNode)oldAddressList.item(0)).valueOf("./homephone"), ((XMLNode)newAddressList.item(0)).valueOf("./HomePhone"), lNameKey);
303 }
304
305
306
307 oldInfo = null;
308 newInfo = null;
309 oldInfo = oldCustomerInfo;
310 oldOccupationList = oldInfo.getChildNodes();
311 for(int i = 0; i < oldOccupationList.getLength(); i++) {
312 if(((XMLNode)oldOccupationList.item(i)).getNodeName().equals("Occupation")) {
313 oldOccupationList = oldOccupationList.item(i).getChildNodes();
314 }
315 }
316 newInfo = (XMLNode)dataDoc.getDocumentElement();
317 newOccupationList = newInfo.getChildNodes();
318 newOccupationList = ((NodeList)((NodeList)newOccupationList.item(0).getChildNodes()).item(2).getChildNodes()).item(11).getChildNodes();
319 if(oldOccupationList.getLength() > 0) {
320
321 if(!((XMLNode)newOccupationList.item(0)).valueOf("./Description").equals(((XMLNode)oldOccupationList.item(0)).valueOf("./description"))) {
322 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Occupation", ((XMLNode)oldOccupationList.item(0)).valueOf("./description"), ((XMLNode)newOccupationList.item(0)).valueOf("./Description"), 0);
323 }
324 if(!((XMLNode)newOccupationList.item(0)).valueOf("./Employer").equals(((XMLNode)oldOccupationList.item(0)).valueOf("./employer"))) {
325 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Employer", ((XMLNode)oldOccupationList.item(0)).valueOf("./employer"), ((XMLNode)newOccupationList.item(0)).valueOf("./Employer"), 0);
326 }
327 if(!((XMLNode)newOccupationList.item(0)).valueOf("./TimeJob").equals("NULL")) {
328 if(!((XMLNode)newOccupationList.item(0)).valueOf("./TimeJob").equals(((XMLNode)oldOccupationList.item(0)).valueOf("./timejob"))) {
329 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "TimeJob", ((XMLNode)oldOccupationList.item(0)).valueOf("./timejob"), ((XMLNode)newOccupationList.item(0)).valueOf("./TimeJob"), 0);
330 }
331 }
332 if(!((XMLNode)oldOccupationList.item(0)).valueOf("./income").equals("")) {
333 String sNewIncome = ((XMLNode)newOccupationList.item(0)).valueOf("./Income");
334 String sOldIncome = ((XMLNode)oldOccupationList.item(0)).valueOf("./income");
335 if(sNewIncome.length() <= 0) {
336 sNewIncome = "0";
337 }
338
339 if(sOldIncome.length() <= 0) {
340 sOldIncome = "0";
341 }
342
343 Double dblIncome = new Double(sNewIncome);
344 Double dblOldIncome = new Double(sOldIncome);
345 if(!dblIncome.equals(dblOldIncome)) {
346 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Income", ((XMLNode)oldOccupationList.item(0)).valueOf("./income"), ((XMLNode)newOccupationList.item(0)).valueOf("./Income"), 0);
347 }
348 }
349 }
350 else if(newOccupationList.getLength() > 0) {
351 String sNewOccupation = ((XMLNode)newOccupationList.item(0)).valueOf("./Description");
352 String sNewEmployer = ((XMLNode)newOccupationList.item(0)).valueOf("./Employer");
353 String sNewIncome = ((XMLNode)newOccupationList.item(0)).valueOf("./Income");
354 String sNewTimeJob = ((XMLNode)newOccupationList.item(0)).valueOf("./TimeJob");
355 if(sNewOccupation.length() > 0) {
356 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Occupation", " ", ((XMLNode)newOccupationList.item(0)).valueOf("./Description"), 0);
357 }
358 if(sNewEmployer.length() > 0) {
359 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Employer", " ", ((XMLNode)newOccupationList.item(0)).valueOf("./Employer"), 0);
360 }
361 if((!(sNewTimeJob.equals("NULL"))) && (!(sNewTimeJob.equals("")))) {
362 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "TimeJob", " ", ((XMLNode)newOccupationList.item(0)).valueOf("./TimeJob"), 0);
363 }
364 if((!(sNewIncome.equals("0.00"))) && (!(sNewIncome.equals("")))) {
365
366 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Income", " ", ((XMLNode)newOccupationList.item(0)).valueOf("./Income"), 0);
367 }
368 }
369 }
370 else {
371 if(dataDoc.valueOf("AccountDemographics/CustomerRole/Role").equals("EM")) {
372
373 for(int i = 0; i < oldList.getLength(); i++) {
374 oldInfo = (XMLNode)oldList.item(i);
375 if(oldInfo.valueOf("./role").equals("EM")) {
376 oldCustomerInfo = (XMLNode)oldInfo.selectSingleNode("./Corporation/Info");
377 flagEm = true;
378 }
379 }
380 }
381
382 if(flagEm) {
383
384
385 String param = "AccountDemographics/CustomerRole/Corporation/";
386
387 if(!compareCorporationInfo(dataDoc, oldCustomerInfo, "Name")) {
388 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Name", oldCustomerInfo.valueOf("name"), dataDoc.valueOf(param + "Name"), 0);
389 }
390 if(!compareCorporationInfo(dataDoc, oldCustomerInfo, "Email")) {
391 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Email", oldCustomerInfo.valueOf("email"), dataDoc.valueOf(param + "Email"), 0);
392 }
393
394 oldInfo = null;
395 newInfo = null;
396 oldInfo = oldCustomerInfo;
397 oldAddressList = oldInfo.getChildNodes();
398
399 for(int i = 0; i < oldAddressList.getLength(); i++) {
400 if(((XMLNode)oldAddressList.item(i)).getNodeName().equals("Address")) {
401 oldAddressList = oldAddressList.item(i).getChildNodes();
402 }
403 }
404
405 newInfo = (XMLNode)dataDoc.getDocumentElement();
406 newAddressList = newInfo.getChildNodes();
407 newAddressList = (NodeList)((NodeList)newAddressList.item(0).getChildNodes()).item(2).getChildNodes();
408
409 if(!((XMLNode)newAddressList.item(4)).valueOf("./Line1").equals(((XMLNode)oldAddressList.item(0)).valueOf("./address1"))) {
410 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Address Line1", ((XMLNode)oldAddressList.item(0)).valueOf("./address1"), ((XMLNode)newAddressList.item(4)).valueOf("./Line1"), 0);
411 }
412 if(!((XMLNode)newAddressList.item(4)).valueOf("./Line2").equals(((XMLNode)oldAddressList.item(0)).valueOf("./address2"))) {
413 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Address Line2", ((XMLNode)oldAddressList.item(0)).valueOf("./address2"), ((XMLNode)newAddressList.item(4)).valueOf("./Line2"), 0);
414 }
415 if(!((XMLNode)newAddressList.item(4)).valueOf("./City").equals(((XMLNode)oldAddressList.item(0)).valueOf("./city"))) {
416 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "City", ((XMLNode)oldAddressList.item(0)).valueOf("./city"), ((XMLNode)newAddressList.item(4)).valueOf("./City"), 0);
417 }
418 if(!((XMLNode)newAddressList.item(4)).valueOf("./StateCode").equals(((XMLNode)oldAddressList.item(0)).valueOf("./statecode"))) {
419 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "StateCode", ((XMLNode)oldAddressList.item(0)).valueOf("./statecode"), ((XMLNode)newAddressList.item(4)).valueOf("./StateCode"), 0);
420 }
421 if(!((XMLNode)newAddressList.item(4)).valueOf("./ZipCode").equals(((XMLNode)oldAddressList.item(0)).valueOf("./zipcode"))) {
422 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "ZipCode", ((XMLNode)oldAddressList.item(0)).valueOf("./zipcode"), ((XMLNode)newAddressList.item(4)).valueOf("./ZipCode"), 0);
423 }
424 if(!((XMLNode)newAddressList.item(4)).valueOf("./CountryId").equals(((XMLNode)oldAddressList.item(0)).valueOf("./countryid"))) {
425 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "CountryId", ((XMLNode)oldAddressList.item(0)).valueOf("./countryid"), ((XMLNode)newAddressList.item(4)).valueOf("./CountryId"), 0);
426 }
427 if(!((XMLNode)newAddressList.item(4)).valueOf("./Phone").equals(((XMLNode)oldAddressList.item(0)).valueOf("./phone"))) {
428 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Phone", ((XMLNode)oldAddressList.item(0)).valueOf("./phone"), ((XMLNode)newAddressList.item(4)).valueOf("./Phone"), 0);
429 }
430 }
431 }
432 }
433
434
435 private boolean compareMiscelaneous(XMLDocument originalDoc, XMLDocument newDoc, String valueToCompareOri, String valueToCompareDes) throws XSLException {
436 String originalValue;
437 String newValue;
438 originalValue = originalDoc.valueOf("/AgreementDetailsList/" + valueToCompareOri);
439 newValue = newDoc.valueOf("/Maintenance/" + valueToCompareDes);
440 if(originalValue.equals(newValue)) {
441 return true;
442 }
443 else {
444 return false;
445 }
446 }
447
448
449 private void createAgreementMaintenance(long agrmId, long userId, String filedName, String oldData, String newData, long nameKey) throws Exception {
450 Connection con = null;
451 PreparedStatement ps = null;
452 ResultSet result = null;
453 try {
454 con = ServiceLocator.instance().getConnection();
455 ps = con.prepareStatement(
456 "insert into agreements_maintenance(" +
457 "amnt_id, " +
458 "amnt_agrm_id, " +
459 "amnt_user_id, " +
460 "amnt_date, " +
461 "amnt_field_name, " +
462 "amnt_old_data, " +
463
464 "amnt_new_data, " +
465 "amnt_name_key " +
466
467
468 ") values (" +
469
470 " ?,?,?,sysdate,?,?,?,? " +
471
472 ")"
473 );
474 ps.setLong(1, UniqueIDGenerator.instance().getNextId());
475 ps.setLong(2, agrmId);
476 ps.setLong(3, userId);
477 ps.setString(4, filedName);
478 ps.setString(5, oldData);
479 ps.setString(6, newData);
480
481 ps.setLong(7, nameKey);
482
483 int n = ps.executeUpdate();
484 if(n != 1) {
485 throw new InstantbankException("321001", "Failed to create Agreements Maintenance to the database");
486 }
487 }
488 catch(Exception e) {
489 setRollbackOnly();
490 throw new InstantbankException(e, "321001", "Failed to create Agreements Maintenance to the database");
491 }
492 finally {
493 try {
494 if(ps != null) {
495 ps.close();
496 }
497 if(con != null) {
498 con.close();
499 }
500 }
501 catch(SQLException se) {
502 }
503 }
504 }
505
506
507 public Long getAgreementId(Long companyId, Long agreementCode) throws InstantbankException {
508 Long agreementId = new Long(0);
509 DataAccess da = null;
510 String query = "";
511 ResultSet rs = null;
512 Statement st = null;
513
514 try {
515
516 da = new DataAccess();
517 da.connect();
518 st = da.getConnection().createStatement();
519
520 query = "SELECT agrm_id FROM agreements WHERE agrm_code=" + agreementCode + " and agrm_cmp_id=" + companyId;
521 rs = st.executeQuery(query);
522
523 while(rs.next()) {
524 agreementId = new Long(rs.getLong(1));
525 }
526
527 return agreementId;
528 }
529 catch(Exception e) {
530 setRollbackOnly();
531 throw new InstantbankException(e, "311012", "Failed to retrieve the account Id");
532 }
533 finally {
534 try {
535 if(rs != null) {
536 rs.close();
537 }
538 if(st != null) {
539 st.close();
540 }
541 if(da != null) {
542 da.disconnect();
543 }
544 }
545 catch(Exception e) {
546 }
547 }
548 }
549
550
551 public String getAgreementDetails(Long companyId, Long agrmId, boolean financial, boolean promises, boolean delinquency, boolean miscellaneous) throws InstantbankException {
552 String currentQueues;
553 String fromTables = " agreements";
554 String join = "";
555 String query;
556 String selectedFields = "";
557 XMLDataAccess xda = null;
558
559 try {
560 xda = new XMLDataAccess("");
561 xda.connect();
562 selectedFields += " agrm_code accountNumber,";
563 if(financial) {
564 selectedFields += " to_char(agrm_past_due_date,'mm-dd-yyyy') finNoPastDue,";
565 selectedFields += " agrm_amount_past_due finAmountPastDue,";
566 selectedFields += " agrm_partial finPartial,";
567 selectedFields += " AGRM_CURR_DEL_DAYS delinquency,";
568 selectedFields += " agrm_regular_pay_amount finRegularPayment,";
569 selectedFields += " to_char(agrm_maturity_date,'mm-dd-yyyy') finMaturityDate,";
570 selectedFields += " agrm_late_charges finLateCharges,";
571 selectedFields += " agrm_balance finBalance,";
572 selectedFields += " agrm_financed finFinanced,";
573 selectedFields += " agrm_payoff finPayoff,";
574 selectedFields += " (NVL(agrm_unpaid_fee1,0) + NVL(agrm_unpaid_fee2,0)) fee,";
575
576 selectedFields += " AGRM_ID, NVL(AGRM_REGULAR_PAY_AMOUNT,0) prinDue,";
577
578 selectedFields += " to_char(agrm_payoff_date,'mm-dd-yyyy') finPayoffDate,";
579 selectedFields += " agrm_IntBal intbal,";
580 }
581 if(promises) {
582 selectedFields += " agrm_num_promises_kept promisesKept,";
583 selectedFields += " agrm_num_promises_broken promisesBroken,";
584 selectedFields += " agrm_num_promises_current promisesCurrent,";
585 }
586 if(delinquency) {
587 selectedFields += " agrm_pastdue_15 del15,";
588 selectedFields += " agrm_pastdue_30 del30,";
589 selectedFields += " agrm_pastdue_60 del60,";
590 selectedFields += " agrm_pastdue_90 del90,";
591 }
592 if(miscellaneous) {
593 currentQueues = "select count(distinct wrki_qplan_id) from work_items where wrki_object_id=" + agrmId;
594 selectedFields += " to_char(trn_processing_date,'mm-dd-yyyy') miscLastTrProcessDate,";
595 selectedFields += " to_char(trn_effective_date,'mm-dd-yyyy') miscLastTrEffectiveDate,";
596 selectedFields += " trn_principal_amount miscLastTrPrincipal,";
597 selectedFields += " trn_interest_amount miscLastTrInterest,";
598 selectedFields += " trt_description miscLastTrDescription,";
599
600 selectedFields += " TRN_FEES_AMOUNT miscLastTrFees,";
601 selectedFields += " agrm_number_nsf miscNoNSF,";
602 selectedFields += " agrm_months_extended miscMonthsExtended,";
603 selectedFields += " (" + currentQueues + ") miscCurrentQueues,";
604 selectedFields += " agrm_old_code oldAccount,";
605 selectedFields += " agrm_permanent_review_time permanentreviewtime,";
606 selectedFields += " agrm_alert miscAlert,";
607
608 fromTables += ", transactions, transaction_types ";
609 join = " AND (trn_id (+) = agrm_last_trn_id AND trt_id (+) = trn_trt_id)";
610 }
611
612 selectedFields = selectedFields.substring(0, selectedFields.length() - 1);
613
614 query = "SELECT ";
615 query += selectedFields + " ";
616 query += "FROM ";
617 query += fromTables + " ";
618 query += " WHERE ";
619 query += "(agrm_id = " + agrmId.toString() + ") AND ";
620 query += "(agrm_cmp_id = " + companyId.toString() + ") " + join;
621 String ret = xda.getXml(query, "AgreementDetailsList", "AgreementDetails");
622 ;
623 return ret;
624 }
625 catch(Exception e) {
626 setRollbackOnly();
627 throw new InstantbankException(e, "321002", "Failed to get agreement details");
628 }
629 finally {
630 try {
631 if(xda != null) {
632 xda.disconnect();
633 }
634 }
635 catch(Exception e) {
636 }
637 }
638 }
639
640
641 public String getAgreementDetailsCont(Long companyId, Long agrmId) throws InstantbankException {
642 String query;
643 String selectedFields = "";
644 XMLDataAccess xda = null;
645 try {
646 xda = new XMLDataAccess("");
647 xda.connect();
648 selectedFields += " agrm_recovery_code recoveryCode,";
649 selectedFields += " agrm_coll_officer collOfficer,";
650 selectedFields += " agrm_status status,";
651 selectedFields += " agrm_contract_state contractState,";
652 selectedFields += " agrm_payments_made paymentsMade,";
653 selectedFields += " agrm_term term,";
654 selectedFields += " agrm_loan_class class,";
655 selectedFields += " agrm_pool_num poolNumber,";
656 selectedFields += " agrm_loan_type loanType ,";
657 selectedFields += " agrm_gl_code glCode,";
658 selectedFields += " agrm_payment_due_day dueDay,";
659 selectedFields += " agrm_classified_code classifiedCode,";
660 selectedFields += " agrm_due_principal prinDue,";
661 selectedFields += " agrm_unpaid_fee1 unpaidFee1,";
662 selectedFields += " agrm_unpaid_fee2 unpaidFee2,";
663 selectedFields += " agrm_credit_score_orig originalCrBur,";
664 selectedFields += " agrm_curr_credit_score currentCrBur,";
665 selectedFields += " agrm_behave_score behaveioral,";
666 selectedFields += " agrm_tickler_a_cd ticklerCode1,";
667 selectedFields += " to_char(agrm_tickler_a_date,'mm-dd-yyyy') ticklerDate1,";
668 selectedFields += " agrm_tickler_b_cd ticklerCode2,";
669 selectedFields += " to_char(agrm_tickler_b_date,'mm-dd-yyyy') ticklerDate2,";
670 selectedFields += " to_char(agrm_fpay_date,'mm-dd-yyyy') firstPayment,";
671 selectedFields += " to_char(agrm_date_last_cust_contact,'mm-dd-yyyy') lastCustCont,";
672 selectedFields += " to_char(agrm_date_last_extension,'mm-dd-yyyy')lastExtension,";
673 selectedFields += " agrm_financed financed,";
674 selectedFields += " to_char(agrm_maturity_date,'mm-dd-yyyy') matDate,";
675
676 selectedFields += " agrm_payments_past_due paymentspastdue,";
677 selectedFields += " to_char(agrm_date_termination,'mm-dd-yyyy') termination";
678
679 query = "SELECT ";
680 query += selectedFields + " ";
681 query += "FROM ";
682 query += "agreements ";
683 query += " WHERE ";
684 query += "agrm_id = " + agrmId.toString() + " AND ";
685 query += "agrm_cmp_id = " + companyId.toString();
686 return xda.getXml(query, "AgreementDetailsContList", "AgreementDetailsCont");
687 }
688 catch(Exception e) {
689 setRollbackOnly();
690 throw new InstantbankException(e, "321002", "Failed to get agreement details");
691 }
692 finally {
693 try {
694 if(xda != null) {
695 xda.disconnect();
696 }
697 }
698 catch(Exception e) {
699 }
700 }
701 }
702
703
704 public String getCollateralInfo(Long companyId, Long agrmId) throws InstantbankException {
705 String sql;
706 XMLDataAccess xda = null;
707
708 try {
709 xda = new XMLDataAccess("database.properties");
710 xda.connect();
711 sql = "SELECT ";
712 sql += "vehi_id vehiId, ";
713 sql += "vehi_year year, ";
714 sql += "vehi_make make, ";
715 sql += "vehi_model model, ";
716 sql += "vehi_vin vin, ";
717 sql += "vehi_new_used newOrUsed, ";
718 sql += "coll_id collId, ";
719 sql += "coll_orig_price originalPrice, ";
720 sql += "coll_curr_price currentPrice, ";
721 sql += "to_char(agrm_booked_date,'mm-dd-yyyy') dateBooked, ";
722 sql += "agrm_annual_perc_rate apr, ";
723 sql += "coll_type type ";
724 sql += "FROM ";
725 sql += "collaterals, ";
726 sql += "vehicles, ";
727 sql += "agreements";
728 sql += " WHERE ";
729 sql += "(agrm_id = " + agrmId.toString() + ") and ";
730 sql += "(agrm_cmp_id = " + companyId.toString() + ") and ";
731 sql += "(coll_agrm_id = agrm_id) and ";
732 sql += "(coll_role = 'FI') and ";
733 sql += "(vehi_id = coll_vehi_id)";
734
735 return xda.getXml(sql, "CollateralsList", "Collateral");
736 }
737 catch(Exception e) {
738 setRollbackOnly();
739 throw new InstantbankException(e, "311003", "Failed to get collateral info");
740 }
741 finally {
742 try {
743 xda.disconnect();
744 }
745 catch(Exception e) {
746 }
747 }
748 }
749
750
751 public String getCustomers(Long companyId, Long agrmId) throws InstantbankException {
752 Long addressId;
753 String code;
754 Long corpId;
755 Long custId;
756 CustomerInfoServices customerInfoServices;
757 CustomerInfoServicesHome customerInfoServicesHome;
758 XMLDocument doc;
759 XMLNode node;
760 NodeList nodeList;
761 Node newNode;
762 PrintWriter pw;
763 String sql;
764 XMLNode root;
765 StringWriter sw;
766 XMLDataAccess xda = null;
767 String xmlCorp;
768 String xmlCust;
769 XMLDocument xmlDoc;
770
771 try {
772 sw = new StringWriter();
773 pw = new PrintWriter(sw);
774 xda = new XMLDataAccess("database.properties");
775 customerInfoServicesHome = (CustomerInfoServicesHome)ServiceLocator.instance().createEJB("CustomerInfoServicesHome", CustomerInfoServicesHome.class, false);
776 customerInfoServices = customerInfoServicesHome.create();
777
778 xda.connect();
779 sql = "SELECT ";
780 sql += "acl_csr_code Role, ";
781 sql += "csr_screen_type screenType, ";
782 sql += "acl_cust_id CustomerId, ";
783 sql += "acl_corp_id CorporationId, ";
784 sql += "acl_add_id AddressId ";
785 sql += "FROM ";
786 sql += "agreements, ";
787 sql += "agreements_cust_links, ";
788 sql += "customer_roles ";
789 sql += "WHERE ";
790 sql += "(agrm_id = " + agrmId.toString() + ") and ";
791 sql += "(agrm_cmp_id = " + companyId.toString() + ") and ";
792 sql += "(acl_agrm_id = agrm_id) and ";
793 sql += "(acl_csr_code = csr_code)";
794
795 xmlDoc = xda.makeXMLSelect(sql, "Demographics", "CustomerRole");
796
797 root = (XMLNode)xmlDoc.getDocumentElement();
798 nodeList = root.getChildren();
799 for(int i = 0; i < nodeList.getLength(); i++) {
800 node = (XMLNode)nodeList.item(i);
801 code = node.valueOf("./screentype");
802
803 if(!node.valueOf("./addressid").equals("")) {
804 addressId = new Long(node.valueOf("./addressid"));
805 }
806 else {
807 addressId = null;
808 }
809 if(code.equals("EM")) {
810 corpId = new Long(node.valueOf("./corporationid"));
811 xmlCorp = customerInfoServices.getCorporation(companyId, corpId, addressId);
812 doc = XMLUtils.getXMLDocument(xmlCorp);
813 newNode = doc.getDocumentElement();
814 newNode = newNode.cloneNode(true);
815 node.appendChild(newNode);
816 }
817 else {
818 custId = new Long(node.valueOf("./customerid"));
819 xmlCust = customerInfoServices.getCustomer(companyId, custId, addressId);
820
821 doc = XMLUtils.getXMLDocument(xmlCust);
822 newNode = doc.getDocumentElement();
823 newNode = newNode.cloneNode(true);
824 node.appendChild(newNode);
825 }
826 }
827 xmlDoc.print(pw);
828 return sw.toString();
829 }
830 catch(Exception e) {
831 setRollbackOnly();
832 throw new InstantbankException(e, "311004", "Failed to retrieve customers");
833 }
834 finally {
835 try {
836 if(xda != null) {
837 xda.disconnect();
838 }
839 }
840 catch(Exception e) {
841 }
842 }
843 }
844
845
846 private String getCustomerStatus(Long companyId, String cstId) throws InstantbankException {
847 Connection con = null;
848 String dateFilter = "";
849 PreparedStatement ps = null;
850 ResultSet result = null;
851 String status = "";
852 String sql = null;
853
854 try {
855
856 sql = "select cst_description from customer_statuses where cst_id = " + cstId + " and cst_cmp_id = " + companyId;
857
858 con = ServiceLocator.instance().getConnection();
859 ps = con.prepareStatement(sql);
860 result = ps.executeQuery();
861
862 if(result.next()) {
863 status = result.getString(1);
864 }
865
866 return status;
867 }
868 catch(Exception e) {
869 throw new InstantbankException(e, "131009", "Failed to get the the number of Transactions ");
870 }
871 finally {
872 try {
873 if(result != null) {
874 result.close();
875 }
876 if(ps != null) {
877 ps.close();
878 }
879 if(con != null) {
880 con.close();
881 }
882 }
883 catch(SQLException se) {
884 se.printStackTrace();
885 }
886 }
887
888 }
889
890
891 public String getMaintenanceHistory(Long companyId, Long agrmId, String primarySort,
892 String secondarySort, String fromDate, String toDate, Long rowNum) throws InstantbankException {
893
894 XMLDataAccess da = null;
895 String dateFilter = "";
896 String orderByPrimary;
897 String orderBySecondary;
898 String sql;
899 Long maxRows;
900
901 if((!fromDate.equals("--")) && (!toDate.equals("--")) && (!fromDate.equals("")) && (!toDate.equals(""))) {
902 dateFilter = " AND amnt_date BETWEEN " +
903 " TO_DATE('" + fromDate + "','mm-dd-yyyy') AND " +
904 " TO_DATE('" + toDate + "','mm-dd-yyyy') ";
905 }
906
907 if(primarySort.equals("postingDate")) {
908 orderByPrimary = "amnt_date desc";
909 }
910 else if(primarySort.equals("operator")) {
911 orderByPrimary = "operator";
912 }
913 else if(primarySort.equals("field")) {
914 orderByPrimary = "fieldname";
915 }
916 else {
917 orderByPrimary = "amnt_date desc";
918 }
919
920 if(secondarySort.equals("postingDate")) {
921 orderBySecondary = "amnt_date desc";
922 }
923 else if(secondarySort.equals("operator")) {
924 orderBySecondary = "operator";
925 }
926 else if(secondarySort.equals("field")) {
927 orderBySecondary = "fieldname";
928 }
929 else {
930 orderBySecondary = "user_userid";
931 }
932
933 try {
934 da = new XMLDataAccess("");
935 da.connect();
936 maxRows = new Long("19");
937
938 sql = "select postingdate, operator, fieldname, newdata, olddata ";
939 sql += "FROM(select postingdate, operator, fieldname, newdata, olddata, ";
940 sql += "ROWNUM theRow";
941 sql += " FROM(SELECT to_char(amnt_date, 'mm-dd-yyyy hh24:mi') postingdate, ";
942 sql += "user_userid operator, amnt_field_name fieldname, amnt_new_data newdata, ";
943 sql += "amnt_old_data olddata FROM agreements_maintenance, users ";
944 sql += "WHERE amnt_agrm_id = " + agrmId + " and ";
945 sql += "amnt_user_id = user_id " + dateFilter + "ORDER BY ";
946 sql += orderByPrimary + ", ";
947 sql += orderBySecondary;
948 sql += ")) Where theRow between " + rowNum.toString() + " and " + new Long(rowNum.longValue() + maxRows.longValue()).toString();
949 return da.getXml(sql, "MaintenanceHistory", "Event");
950 }
951 catch(Exception e) {
952 setRollbackOnly();
953 throw new InstantbankException(e, "311005", "Failed to retrieve maintenance history");
954 }
955 finally {
956 try {
957 if(da != null) {
958 da.disconnect();
959 }
960 }
961 catch(Exception e) {
962 }
963 }
964 }
965
966
967 public Long getRowsMaintenanceHistory(Long companyId, Long agrmId, String fromDate, String toDate) throws InstantbankException {
968 Connection con = null;
969 String dateFilter = "";
970 PreparedStatement ps = null;
971 ResultSet result = null;
972 String xml = "";
973 Long maxRows = null;
974 String sql = null;
975
976 try {
977 if((!fromDate.equals("--")) && (!toDate.equals("--")) && (!fromDate.equals("")) && (!toDate.equals(""))) {
978 dateFilter = " AND amnt_date BETWEEN " +
979 " TO_DATE('" + fromDate + "','mm-dd-yyyy') AND " +
980 " TO_DATE('" + toDate + "','mm-dd-yyyy') ";
981 }
982
983 sql = "SELECT count(ROWNUM) ";
984 sql += "FROM agreements_maintenance, users ";
985 sql += "WHERE amnt_agrm_id = ? and ";
986 sql += " amnt_user_id = user_id " + dateFilter;
987
988 con = ServiceLocator.instance().getConnection();
989 ps = con.prepareStatement(sql);
990 ps.setLong(1, agrmId.longValue());
991 result = ps.executeQuery();
992
993 if(result.next()) {
994 maxRows = new Long(result.getLong(1));
995 }
996 else {
997 maxRows = new Long("0");
998 }
999
1000 return maxRows;
1001 }
1002 catch(Exception e) {
1003 throw new InstantbankException(e, "131009", "Failed to get the the number of promises ");
1004 }
1005 finally {
1006 try {
1007 if(result != null) {
1008 result.close();
1009 }
1010 if(ps != null) {
1011 ps.close();
1012 }
1013 if(con != null) {
1014 con.close();
1015 }
1016 }
1017 catch(SQLException se) {
1018 se.printStackTrace();
1019 }
1020 }
1021
1022 }
1023
1024
1025 public String getPrimaryCustomer(Long companyId, Long agrmId) throws InstantbankException {
1026 String addressXml = "";
1027 String primaryXmlString = "";
1028 String query;
1029 XMLDataAccess xda = null;
1030
1031 try {
1032 xda = new XMLDataAccess("");
1033 xda.connect();
1034 query = "SELECT ";
1035 query += "cust_first_name firstName,";
1036 query += "cust_middle_name middleName,";
1037 query += "cust_last_name lastName,";
1038 query += "cust_generation_code generationCode,";
1039 query += "cust_email email,";
1040 query += "cust_ssn ssn,";
1041 query += "cust_drivers_license driverslicence,";
1042 query += "to_char(cust_birthdate,'mm-dd-yyyy') birthDate,";
1043 query += "(SELECT coc_employer FROM customer_occupations WHERE coc_cust_id = cust_id AND coc_status = 'PR') employer,";
1044 query += "(SELECT ";
1045 query += "phn_number ";
1046 query += " FROM ";
1047 query += "customer_phones, ";
1048 query += "phone_numbers ";
1049 query += " WHERE ";
1050 query += "cph_cust_id = cust_id AND ";
1051 query += "phn_id = cph_phn_id AND ";
1052 query += "phn_pht_code ='HO' AND ";
1053 query += "ROWNUM=1 ";
1054 query += ") homePhone,";
1055 query += "(SELECT ";
1056 query += "phn_number ";
1057 query += "FROM ";
1058 query += "customer_phones, ";
1059 query += "phone_numbers ";
1060 query += "WHERE ";
1061 query += "cph_cust_id = cust_id AND ";
1062 query += "phn_id = cph_phn_id AND ";
1063 query += "phn_pht_code = 'BU' AND ";
1064 query += "ROWNUM=1 ";
1065 query += ") businessPhone,";
1066 query += "(SELECT ";
1067 query += "phn_extension ";
1068 query += "FROM ";
1069 query += "customer_phones, ";
1070 query += "phone_numbers ";
1071 query += "WHERE ";
1072 query += "cph_cust_id = cust_id AND ";
1073 query += "phn_id = cph_phn_id AND ";
1074 query += "phn_pht_code = 'BU' AND ";
1075 query += "ROWNUM=1 ";
1076 query += ") businessExtension,";
1077 query += "(SELECT ";
1078 query += "phn_number ";
1079 query += "FROM ";
1080 query += "customer_phones, ";
1081 query += "phone_numbers ";
1082 query += "WHERE ";
1083 query += "cph_cust_id = cust_id AND ";
1084 query += "phn_id = cph_phn_id AND ";
1085 query += "phn_pht_code = 'MB' AND ";
1086 query += "ROWNUM=1 ";
1087 query += ") mobilePhone,";
1088 query += "(SELECT ";
1089 query += "phn_number ";
1090 query += "FROM ";
1091 query += "customer_phones, ";
1092 query += "phone_numbers ";
1093 query += "WHERE ";
1094 query += "cph_cust_id = cust_id AND ";
1095 query += "phn_id = cph_phn_id AND ";
1096 query += "phn_pht_code = 'PG' AND ";
1097 query += "ROWNUM=1 ";
1098 query += ") pagerPhone,";
1099 query += "(SELECT ";
1100 query += "phn_extension ";
1101 query += "FROM ";
1102 query += "customer_phones, ";
1103 query += "phone_numbers ";
1104 query += "WHERE ";
1105 query += "cph_cust_id = cust_id AND ";
1106 query += "phn_id = cph_phn_id AND ";
1107 query += "phn_pht_code = 'PG' AND ";
1108 query += "ROWNUM=1 ";
1109 query += ") pagerCode ";
1110 query += "FROM ";
1111 query += "agreements_cust_links, ";
1112 query += "customers ";
1113 query += "WHERE ";
1114 query += "(acl_agrm_id = " + agrmId.toString() + " AND acl_csr_code = 'PR') AND ";
1115 query += "(cust_id = acl_cust_id) AND (cust_cmp_id = " + companyId.toString() + ")";
1116 primaryXmlString = xda.getXml(query, "PrimariesList", "Primary");
1117
1118 query = "SELECT ";
1119 query += "add_line1 line1,";
1120 query += "add_line2 line2,";
1121 query += "add_city city,";
1122 query += "(SELECT stt_code FROM states WHERE stt_id = add_stt_id) state,";
1123 query += "add_zip_code zipCode,";
1124 query += "add_adt_code type,";
1125 query += "(SELECT phn_number FROM phone_numbers WHERE phn_add_id = add_id AND rownum = 1) homePhone ";
1126 query += "FROM ";
1127 query += "addresses, ";
1128 query += "customer_addresses, ";
1129 query += "agreements_cust_links ";
1130 query += "WHERE ";
1131 query += "(acl_agrm_id = " + agrmId.toString() + " AND acl_csr_code = 'PR') AND ";
1132 query += "(cad_cust_id = acl_cust_id) AND (add_adt_code = 'AL') AND ";
1133 query += "(SYSDATE between add_start_date AND add_end_date) AND ";
1134 query += "(cad_add_id = add_id)";
1135 try {
1136
1137 addressXml = StringFormat.cleanXml(xda.getXml(query, "AddressesList", "Address", null, true));
1138 }
1139 catch(Exception e) {
1140 query = "SELECT ";
1141 query += "add_line1 line1,";
1142 query += "add_line2 line2,";
1143 query += "add_city city,";
1144 query += "(SELECT stt_code FROM states WHERE stt_id = add_stt_id) state,";
1145 query += "add_zip_code zipCode,";
1146 query += "add_adt_code type,";
1147 query += "(SELECT phn_number FROM phone_numbers WHERE phn_add_id = add_id and phn_pht_code = 'HO' and ROWNUM = 1) homePhone ";
1148 query += "FROM ";
1149 query += "addresses, ";
1150 query += "customer_addresses, ";
1151 query += "agreements_cust_links ";
1152 query += "WHERE ";
1153 query += "(acl_agrm_id = " + agrmId.toString() + " AND acl_csr_code = 'PR') AND ";
1154 query += "(cad_cust_id = acl_cust_id) AND (add_adt_code = 'PR') AND ";
1155 query += "(cad_add_id = add_id)";
1156 addressXml = StringFormat.cleanXml(xda.getXml(query, "AddressesList", "Address"));
1157 }
1158 primaryXmlString = primaryXmlString.substring(0, primaryXmlString.indexOf("</Primary>")) + addressXml + primaryXmlString.substring(primaryXmlString.indexOf("</Primary>"), primaryXmlString.length());
1159 return primaryXmlString;
1160 }
1161 catch(Exception e) {
1162 setRollbackOnly();
1163 throw new InstantbankException(e, "311006", "Failed to retrieve primary customer");
1164 }
1165 finally {
1166 try {
1167 if(xda != null) {
1168 xda.disconnect();
1169 }
1170 }
1171 catch(Exception e) {
1172 }
1173 }
1174 }
1175
1176
1177 public String getStatusValues(Long companyId, Long agrmId) throws InstantbankException {
1178 String query;
1179 String statusXmlString = "";
1180 XMLDataAccess xda = null;
1181
1182 try {
1183 xda = new XMLDataAccess("database.properties");
1184 xda.connect();
1185
1186 query = "SELECT ";
1187 query += "stc_id categoryId,";
1188 query += "stc_number categoryNumber,";
1189 query += "stc_name categoryName,";
1190 query += "user_userid changedBy,";
1191 query += "to_char(AGRMS_STV_LAST_CHANGED_DATE,'mm-dd-yyyy HH24:MI') changedDate,";
1192 query += "AGRMS_STV_LAST_CHANGED_BY changedbyid,";
1193 query += "(SELECT ";
1194 query += "agrms_stv_id ";
1195 query += "FROM ";
1196 query += "agreements_status ";
1197 query += "WHERE ";
1198 query += "agrms_agrm_id =" + agrmId.toString() + " and ";
1199 query += "agrms_stc_id = stc_id";
1200 query += ")";
1201 query += "valueId,";
1202 query += "(SELECT ";
1203 query += "stv_name ";
1204 query += "FROM ";
1205 query += "status_values ";
1206 query += "WHERE ";
1207 query += "stv_id = ";
1208 query += "(SELECT ";
1209 query += "agrms_stv_id ";
1210 query += "FROM ";
1211 query += "agreements_status ";
1212 query += "WHERE ";
1213 query += "agrms_agrm_id =" + agrmId.toString() + " AND ";
1214 query += "agrms_stc_id = stc_id";
1215 query += ")";
1216 query += ") valueName ";
1217 query += "FROM ";
1218 query += "status_categories,";
1219 query += "agreements_status, users ";
1220 query += "WHERE ";
1221 query += "(stc_cmp_id = " + companyId.toString() + ") AND ";
1222 query += "(agrms_stc_id = stc_id) AND ";
1223 query += "(AGRMS_STV_LAST_CHANGED_BY = user_id) AND ";
1224 query += "(agrms_agrm_id = " + agrmId.toString() + ")";
1225 return xda.getXml(query, "StatusValuesList", "StatusValue");
1226 }
1227 catch(Exception e) {
1228 setRollbackOnly();
1229 throw new InstantbankException(e, "311007", "Failed to retrieve status values");
1230 }
1231 finally {
1232 try {
1233 if(xda != null) {
1234 xda.disconnect();
1235 }
1236 }
1237 catch(Exception e) {
1238 }
1239 }
1240 }
1241
1242
1243 public String getTransactionHistory(Long companyId, Long agrmId, String primarySort,
1244 String secondarySort, String fromDate, String toDate, Long rowNum) throws InstantbankException {
1245
1246 long AgrmId;
1247 String dateFilter = "";
1248 String orderByPrimary;
1249 String orderBySecondary;
1250 String sql;
1251 XMLDataAccess xda = null;
1252 Long maxRows;
1253
1254 if((!fromDate.equals("--")) && (!toDate.equals("--")) && (!fromDate.equals("")) && (!toDate.equals(""))) {
1255 dateFilter = " AND TRN_PROCESSING_DATE BETWEEN " +
1256 " TO_DATE('" + fromDate + "','mm-dd-yyyy') AND " +
1257 " TO_DATE('" + toDate + "','mm-dd-yyyy') ";
1258 }
1259
1260 if(primarySort.equals("ProcessingDate")) {
1261 orderByPrimary = "TRN_PROCESSING_DATE DESC";
1262 }
1263 else if(primarySort.equals("EffectiveDate")) {
1264 orderByPrimary = "TRN_EFFECTIVE_DATE DESC";
1265 }
1266 else if(primarySort.equals("Type")) {
1267 orderByPrimary = "Type";
1268 }
1269 else {
1270 orderByPrimary = "TRN_PROCESSING_DATE DESC";
1271 }
1272
1273 if(secondarySort.equals("ProcessingDate")) {
1274 orderBySecondary = "TRN_PROCESSING_DATE DESC";
1275 }
1276 else if(secondarySort.equals("EffectiveDate")) {
1277 orderBySecondary = "TRN_EFFECTIVE_DATE DESC";
1278 }
1279 else if(secondarySort.equals("Type")) {
1280 orderBySecondary = "Type";
1281 }
1282 else {
1283 orderBySecondary = "Type";
1284 }
1285
1286 try {
1287 xda = new XMLDataAccess("");
1288 xda.connect();
1289 AgrmId = agrmId.longValue();
1290 maxRows = new Long("19");
1291
1292 sql = "select Id, ProcessingDate, EffectiveDate, Type, Reversed, PrincipalAmount, InterestAmount, FeesAmount, ";
1293 sql += "EndingBalance, Source, TraceNumber, OnlineOperator, Description ";
1294 sql += "FROM(select Id, ProcessingDate, EffectiveDate, Type, Reversed, PrincipalAmount, InterestAmount, FeesAmount, ";
1295 sql += "EndingBalance, Source, TraceNumber, OnlineOperator, Description, ROWNUM theRow ";
1296 sql += "FROM(SELECT TRN_ID Id, to_char(TRN_PROCESSING_DATE,'mm-dd-yyyy') ProcessingDate, to_char(TRN_EFFECTIVE_DATE ,'mm-dd-yyyy') EffectiveDate, ";
1297 sql += "TRT_CODE Type, TRN_REVERSED Reversed, TRN_PRINCIPAL_AMOUNT PrincipalAmount, TRN_INTEREST_AMOUNT InterestAmount, ";
1298 sql += "TRN_FEES_AMOUNT FeesAmount, TRN_ENDING_BALANCE EndingBalance, TRN_SOURCE Source, TRN_TRACE_SEQUENCE_NUMBER TraceNumber, ";
1299 sql += "TRN_ONLINE_OPERATOR OnlineOperator, TRT_DESCRIPTION Description ";
1300 sql += "FROM TRANSACTIONS, TRANSACTION_TYPES WHERE (TRN_AGRM_ID = " + AgrmId + ") AND ";
1301 sql += "(TRN_TRT_ID=TRT_ID) " + dateFilter;
1302 sql += " ORDER BY ";
1303 sql += orderByPrimary + ", ";
1304 sql += orderBySecondary + ")) ";
1305 sql += "where theRow between " + rowNum.toString() + " and " + new Long(rowNum.longValue() + maxRows.longValue()).toString();
1306
1307 return xda.getXml(sql, "TransactionHistory", "Transaction");
1308 }
1309 catch(Exception e) {
1310 setRollbackOnly();
1311 throw new InstantbankException(e, "311013", "Failed to retrieve transaction history");
1312 }
1313 finally {
1314 try {
1315 if(xda != null) {
1316 xda.disconnect();
1317 }
1318 }
1319 catch(Exception e) {
1320 }
1321 }
1322 }
1323
1324
1325 public Long getRowsTransactionHistory(Long companyId, Long agrmId, String fromDate, String toDate) throws InstantbankException {
1326 Connection con = null;
1327 String dateFilter = "";
1328 PreparedStatement ps = null;
1329 ResultSet result = null;
1330 String xml = "";
1331 Long maxRows = null;
1332 String sql = null;
1333
1334 try {
1335
1336 if((!fromDate.equals("--")) && (!toDate.equals("--")) && (!fromDate.equals("")) && (!toDate.equals(""))) {
1337 dateFilter = " AND TRN_PROCESSING_DATE BETWEEN " +
1338 " TO_DATE('" + fromDate + "','mm-dd-yyyy') AND " +
1339 " TO_DATE('" + toDate + "','mm-dd-yyyy') ";
1340 }
1341
1342 sql = "SELECT count (ROWNUM) ";
1343 sql += "FROM TRANSACTIONS, ";
1344 sql += "TRANSACTION_TYPES ";
1345 sql += "WHERE (TRN_AGRM_ID = ?) AND ";
1346 sql += "(TRN_TRT_ID=TRT_ID) " + dateFilter;
1347
1348 con = ServiceLocator.instance().getConnection();
1349 ps = con.prepareStatement(sql);
1350 ps.setLong(1, agrmId.longValue());
1351 result = ps.executeQuery();
1352
1353 if(result.next()) {
1354 maxRows = new Long(result.getLong(1));
1355 }
1356 else {
1357 maxRows = new Long("0");
1358 }
1359
1360 return maxRows;
1361 }
1362 catch(Exception e) {
1363 throw new InstantbankException(e, "131009", "Failed to get the the number of Transactions ");
1364 }
1365 finally {
1366 try {
1367 if(result != null) {
1368 result.close();
1369 }
1370 if(ps != null) {
1371 ps.close();
1372 }
1373 if(con != null) {
1374 con.close();
1375 }
1376 }
1377 catch(SQLException se) {
1378 se.printStackTrace();
1379 }
1380 }
1381
1382 }
1383
1384
1385 private void modifyAgreements(XMLDocument doc, long agrmId, long userId, boolean workItemsFlag) throws Exception {
1386 Connection con = null;
1387 PreparedStatement ps = null;
1388 ResultSet result = null;
1389 String sql;
1390 String permanentReviewTime = doc.valueOf("/Maintenance/Miscelaneous/PermanentReviewTime");
1391 try {
1392 con = ServiceLocator.instance().getConnection();
1393 sql = "update agreements ";
1394 sql += "set agrm_alert = ?, ";
1395 sql += "agrm_old_code = '" + doc.valueOf("/Maintenance/Miscelaneous/OldAccount") + "', ";
1396 if(permanentReviewTime.length() > 0) {
1397 sql += "AGRM_PERMANENT_REVIEW_TIME = '" + permanentReviewTime + "', ";
1398 }
1399 else {
1400 sql += "AGRM_PERMANENT_REVIEW_TIME = null, ";
1401 }
1402 sql += "agrm_last_changed_by = ?, ";
1403 sql += "agrm_last_changed_date = sysdate ";
1404 sql += "where agrm_id = ?";
1405 ps = con.prepareStatement(sql);
1406 ps.setString(1, doc.valueOf("/Maintenance/Miscelaneous/alert"));
1407 ps.setLong(2, userId);
1408 ps.setLong(3, agrmId);
1409
1410 int n = ps.executeUpdate();
1411 if(n != 1) {
1412 throw new CreateException("Failed to create Agreements Maintenance to the database");
1413 }
1414 else {
1415 if(workItemsFlag) {
1416 updatePermanentReviewTime(agrmId, permanentReviewTime, userId);
1417 }
1418 }
1419 }
1420 catch(NamingException ne) {
1421 throw new EJBException(ne);
1422 }
1423 catch(SQLException se) {
1424 setRollbackOnly();
1425 throw new EJBException(se);
1426 }
1427 finally {
1428 try {
1429 if(ps != null) {
1430 ps.close();
1431 }
1432 if(con != null) {
1433 con.close();
1434 }
1435 }
1436 catch(SQLException se) {
1437 se.printStackTrace();
1438 }
1439 }
1440 }
1441
1442
1443 private void modifyCollateral(XMLDocument doc, long collId) throws Exception {
1444 Connection con = null;
1445 String current;
1446 String original;
1447 PreparedStatement ps = null;
1448 ResultSet result = null;
1449
1450 try {
1451 con = ServiceLocator.instance().getConnection();
1452 ps = con.prepareStatement(
1453 "update collaterals " +
1454 "set coll_orig_price = ?, " +
1455 "coll_curr_price = ? " +
1456 "where coll_id = ?"
1457 );
1458 original = doc.valueOf("/Maintenance/Collateral/originalprice");
1459 current = doc.valueOf("/Maintenance/Collateral/currentprice");
1460 if(original == null || original.equals("")) {
1461 ps.setNull(1, java.sql.Types.FLOAT);
1462 }
1463 else {
1464 ps.setFloat(1, Float.parseFloat(original));
1465 }
1466 if(current == null || current.equals("")) {
1467 ps.setNull(2, java.sql.Types.FLOAT);
1468 }
1469 else {
1470 ps.setFloat(2, Float.parseFloat(current));
1471 }
1472 ps.setLong(3, collId);
1473
1474 int n = ps.executeUpdate();
1475 if(n != 1) {
1476 throw new CreateException("Failed to create Agreements Maintenance to the database");
1477 }
1478 }
1479 catch(NamingException ne) {
1480 throw new EJBException(ne);
1481 }
1482 catch(SQLException se) {
1483 setRollbackOnly();
1484 throw new EJBException(se);
1485 }
1486 finally {
1487 try {
1488 if(ps != null) {
1489 ps.close();
1490 }
1491 if(con != null) {
1492 con.close();
1493 }
1494 }
1495 catch(SQLException se) {
1496 se.printStackTrace();
1497 }
1498 }
1499 }
1500
1501
1502 private void modifyVehicle(XMLDocument doc, long vehiId) throws Exception {
1503 Connection con = null;
1504 PreparedStatement ps = null;
1505 ResultSet result = null;
1506 try {
1507 con = ServiceLocator.instance().getConnection();
1508 ps = con.prepareStatement(
1509 "update vehicles " +
1510 "set vehi_make = ?, " +
1511 "vehi_model = ?, " +
1512 "vehi_new_used = ?, " +
1513 "vehi_vin = ?, " +
1514 "vehi_year = ? " +
1515 "where vehi_id = ?"
1516 );
1517 ps.setString(1, doc.valueOf("/Maintenance/Collateral/make"));
1518 ps.setString(2, doc.valueOf("/Maintenance/Collateral/model"));
1519 ps.setString(3, doc.valueOf("/Maintenance/Collateral/neworused"));
1520 ps.setString(4, doc.valueOf("/Maintenance/Collateral/vin"));
1521 if(!doc.valueOf("/Maintenance/Collateral/year").equals(new String(""))) {
1522 ps.setLong(5, Long.parseLong(doc.valueOf("/Maintenance/Collateral/year")));
1523 }
1524 else {
1525 ps.setNull(5, java.sql.Types.NUMERIC);
1526 }
1527 ps.setLong(6, vehiId);
1528
1529 int n = ps.executeUpdate();
1530 if(n != 1) {
1531 throw new CreateException("Failed to create Agreements Maintenance to the database");
1532 }
1533 }
1534 catch(NamingException ne) {
1535 throw new EJBException(ne);
1536 }
1537 catch(SQLException se) {
1538 setRollbackOnly();
1539 throw new EJBException(se);
1540 }
1541 finally {
1542 try {
1543 if(ps != null) {
1544 ps.close();
1545 }
1546 if(con != null) {
1547 con.close();
1548 }
1549 }
1550 catch(SQLException se) {
1551 se.printStackTrace();
1552 }
1553 }
1554 }
1555
1556
1557 public void saveCustomer(String data, Long agrmId, Long companyId, Long userId) throws InstantbankException {
1558 Long aclSequence = new Long(1);
1559 Long addressId = null;
1560 Long custId = null;
1561 CustomerInfoServices customerInfoServices;
1562 CustomerInfoServicesHome customerInfoServicesHome;
1563 XMLNode customerNode;
1564 XMLNode customerRoleNode;
1565 NodeList customerRolesList;
1566 DataAccess dataAccess = null;
1567 String dataNode;
1568 boolean insertFlag = false;
1569 PrintWriter pw;
1570 String query;
1571 String role = null;
1572 XMLNode root;
1573 XMLNode root2;
1574 ResultSet rs = null;
1575 XMLDocument saveXml;
1576 Statement st = null;
1577 XMLDocument statusXml;
1578 String statusXmlStr;
1579 StringWriter sw = new StringWriter();
1580 String type = null;
1581 String oldXml;
1582
1583 try {
1584
1585
1586 oldXml = getCustomers(companyId, agrmId);
1587 compareDemographicsXml(companyId, agrmId, userId, data, oldXml);
1588
1589
1590 customerInfoServicesHome = (CustomerInfoServicesHome)ServiceLocator.instance().createEJB("CustomerInfoServicesHome", CustomerInfoServicesHome.class, false);
1591 customerInfoServices = customerInfoServicesHome.create();
1592 dataAccess = new DataAccess();
1593 dataAccess.connect();
1594 st = dataAccess.getConnection().createStatement();
1595 saveXml = XMLUtils.getXMLDocument(data);
1596 root = (XMLNode)saveXml.getDocumentElement();
1597 customerRolesList = root.getChildNodes();
1598
1599 for(int i = 0; i < customerRolesList.getLength(); i++) {
1600 customerRoleNode = (XMLNode)customerRolesList.item(i);
1601 role = customerRoleNode.valueOf("./Role");
1602 type = customerRoleNode.valueOf("./Type");
1603 if((type.equals("PR")) || (type.equals("AL"))) {
1604
1605 if(!customerRoleNode.valueOf("./Customer/Id").equals("")) {
1606 custId = new Long(customerRoleNode.valueOf("./Customer/Id"));
1607 }
1608 else {
1609 custId = null;
1610 }
1611 if(!customerRoleNode.valueOf("./Customer/AddressList/Address/Id").equals("")) {
1612 addressId = new Long(customerRoleNode.valueOf("./Customer/AddressList/Address/Id"));
1613 }
1614 else {
1615 addressId = null;
1616 }
1617 if(custId == null) {
1618
1619
1620 rs = st.executeQuery("SELECT MAX(acl_sequence)+1 FROM agreements_cust_links WHERE acl_agrm_id = " + agrmId.toString());
1621
1622 if(rs.next()) {
1623 aclSequence = new Long(rs.getLong(1));
1624 }
1625 insertFlag = true;
1626 }
1627 else {
1628 insertFlag = false;
1629 }
1630
1631
1632 customerNode = (XMLNode)customerRoleNode.selectSingleNode("./Customer");
1633 pw = new PrintWriter(sw);
1634 customerNode.print(pw);
1635 dataNode = XMLUtils.xmlHeader() + sw.toString();
1636
1637 statusXmlStr = customerInfoServices.saveCustomer(dataNode, companyId);
1638
1639
1640 statusXml = XMLUtils.getXMLDocument(statusXmlStr);
1641 root2 = (XMLNode)statusXml.getDocumentElement();
1642 custId = new Long(root2.valueOf("./custId"));
1643
1644 if(!root2.valueOf("./addressId").equals("")) {
1645 addressId = new Long(root2.valueOf("./addressId"));
1646 }
1647 else {
1648 addressId = null;
1649 }
1650
1651 if(insertFlag) {
1652 query = "INSERT INTO agreements_cust_links (";
1653 query += "acl_agrm_id,";
1654 query += "acl_sequence,";
1655 query += "acl_csr_code,";
1656 query += "acl_cust_id,";
1657 query += "acl_add_id ";
1658 query += ") VALUES (";
1659 query += agrmId.toString() + ",";
1660 query += aclSequence.toString() + ",";
1661 query += "'" + role.toString() + "',";
1662 query += custId.toString() + ",";
1663 if(addressId != null) {
1664 query += addressId.toString();
1665 }
1666 else {
1667 query += "null";
1668 }
1669 query += ")";
1670
1671 dataAccess.makeInsert(query);
1672 }
1673 else {
1674 query = "UPDATE agreements_cust_links SET ";
1675 query += "acl_csr_code='" + role.toString() + "',";
1676 if(addressId != null) {
1677 query += "acl_add_id=" + addressId.toString() + " ";
1678 }
1679 else {
1680 query += "acl_add_id= null ";
1681 }
1682
1683 query += "WHERE ";
1684 query += "acl_agrm_id=" + agrmId.toString() + " AND ";
1685 query += "ACL_CUST_ID=" + custId.toString();
1686
1687 dataAccess.makeUpdate(query);
1688 }
1689 }
1690 else {
1691
1692 if(!customerRoleNode.valueOf("./Corporation/Id").equals("")) {
1693 custId = new Long(customerRoleNode.valueOf("./Corporation/Id"));
1694 }
1695 else {
1696 custId = null;
1697 }
1698 if(!customerRoleNode.valueOf("./Corporation/Address/Id").equals("")) {
1699 addressId = new Long(customerRoleNode.valueOf("./Corporation/Address/Id"));
1700 }
1701 else {
1702 addressId = null;
1703 }
1704 if(custId == null) {
1705 rs = st.executeQuery("SELECT MAX(acl_sequence)+1 FROM agreements_cust_links WHERE acl_agrm_id = " + agrmId.toString());
1706 while(rs.next()) {
1707 aclSequence = new Long(rs.getLong(1));
1708 }
1709 insertFlag = true;
1710 }
1711 else {
1712 insertFlag = false;
1713 }
1714 customerNode = (XMLNode)customerRoleNode.selectSingleNode("./Corporation");
1715
1716 pw = new PrintWriter(sw);
1717 customerNode.print(pw);
1718 dataNode = XMLUtils.xmlHeader() + sw.toString();
1719 statusXmlStr = customerInfoServices.saveCorporation(dataNode, companyId);
1720 statusXml = XMLUtils.getXMLDocument(statusXmlStr);
1721 root2 = (XMLNode)statusXml.getDocumentElement();
1722 custId = new Long(root2.valueOf("./corpId"));
1723 if(!root2.valueOf("./addressId").equals("")) {
1724 addressId = new Long(root2.valueOf("./addressId"));
1725 }
1726 else {
1727 addressId = null;
1728 }
1729 if(insertFlag) {
1730 query = "INSERT INTO agreements_cust_links (";
1731 query += "acl_agrm_id,";
1732 query += "acl_sequence,";
1733 query += "acl_csr_code,";
1734 query += "acl_corp_id,";
1735 query += "acl_add_id ";
1736 query += ") VALUES (";
1737 query += agrmId.toString() + ",";
1738 query += aclSequence.toString() + ",";
1739 query += "'" + role.toString() + "',";
1740 query += custId.toString() + ",";
1741 if(addressId != null) {
1742 query += addressId.toString();
1743 }
1744 else {
1745 query += "null";
1746 }
1747 query += ")";
1748 dataAccess.makeInsert(query);
1749 }
1750 else {
1751 query = "UPDATE agreements_cust_links SET ";
1752 query += "acl_csr_code='" + role.toString() + "',";
1753 if(addressId != null) {
1754 query += "acl_add_id=" + addressId.toString() + " ";
1755 }
1756 else {
1757 query += "acl_add_id= null ";
1758 }
1759 query += "WHERE ";
1760 query += "acl_agrm_id=" + agrmId.toString() + " AND ";
1761 query += "acl_corp_id=" + custId.toString();
1762 dataAccess.makeUpdate(query);
1763 }
1764 }
1765 }
1766 }
1767 catch(Exception e) {
1768 setRollbackOnly();
1769 throw new InstantbankException(e, "311008", "Failed to save customer");
1770 }
1771 finally {
1772 try {
1773 if(rs != null) {
1774 rs.close();
1775 }
1776 if(st != null) {
1777 st.close();
1778 }
1779 if(dataAccess != null) {
1780 dataAccess.disconnect();
1781 }
1782 }
1783 catch(Exception e) {
1784 }
1785 }
1786 }
1787
1788
1789 public void saveMaintenanceData(String data, Long companyId, Long userId) throws InstantbankException {
1790 Long agrmId;
1791 String attributeNameDes;
1792 String attributeNameOri;
1793 boolean collateralFlag = false;
1794 XMLDocument doc;
1795 DOMParser docParser = new DOMParser();
1796 boolean workItemsFlag = false;
1797 String originalCollateral;
1798 String originalMiscelaneous;
1799 ByteArrayInputStream stream;
1800 boolean vehicleFlag = false;
1801 XMLDocument xmlCollateral;
1802 XMLDocument xmlMiscelaneous;
1803
1804 try {
1805 doc = null;
1806 stream = new ByteArrayInputStream(data.getBytes());
1807 docParser.setValidationMode(false);
1808 docParser.parse(stream);
1809 doc = docParser.getDocument();
1810 agrmId = new Long(doc.valueOf("/Maintenance/agrmid"));
1811 originalCollateral = getCollateralInfo(companyId, agrmId);
1812 stream = new ByteArrayInputStream(originalCollateral.getBytes());
1813 docParser.setValidationMode(false);
1814 docParser.parse(stream);
1815 xmlCollateral = docParser.getDocument();
1816 attributeNameOri = "Collateral/year";
1817 attributeNameDes = "Collateral/year";
1818 if(!compareCollateral(xmlCollateral, doc, attributeNameOri, attributeNameDes)) {
1819 vehicleFlag = true;
1820 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1821 }
1822 attributeNameOri = "Collateral/make";
1823 attributeNameDes = "Collateral/make";
1824 if(!compareCollateral(xmlCollateral, doc, attributeNameOri, attributeNameDes)) {
1825 vehicleFlag = true;
1826 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1827 }
1828 attributeNameOri = "Collateral/model";
1829 attributeNameDes = "Collateral/model";
1830 if(!compareCollateral(xmlCollateral, doc, attributeNameOri, attributeNameDes)) {
1831 vehicleFlag = true;
1832 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1833 }
1834 attributeNameOri = "Collateral/vin";
1835 attributeNameDes = "Collateral/vin";
1836 if(!compareCollateral(xmlCollateral, doc, attributeNameOri, attributeNameDes)) {
1837 vehicleFlag = true;
1838 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1839 }
1840 attributeNameOri = "Collateral/neworused";
1841 attributeNameDes = "Collateral/neworused";
1842 if(!compareCollateral(xmlCollateral, doc, attributeNameOri, attributeNameDes)) {
1843 vehicleFlag = true;
1844 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1845 }
1846
1847 attributeNameOri = "Collateral/originalprice";
1848 attributeNameDes = "Collateral/originalprice";
1849 Double orOriPrice = new Double(xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri));
1850 Double orDesPrice = new Double(doc.valueOf("/Maintenance/" + attributeNameDes));
1851
1852 if(!orOriPrice.equals(orDesPrice)) {
1853 collateralFlag = true;
1854 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1855 }
1856
1860 attributeNameOri = "Collateral/currentprice";
1861 attributeNameDes = "Collateral/currentprice";
1862 Double orOriPrice2 = new Double(xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri));
1863 Double orDesPrice2 = new Double(doc.valueOf("/Maintenance/" + attributeNameDes));
1864
1865 if(!orOriPrice2.equals(orDesPrice2)) {
1866 collateralFlag = true;
1867 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlCollateral.valueOf("/CollateralsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1868 }
1869
1873 if(vehicleFlag) {
1874 modifyVehicle(doc, Long.parseLong(xmlCollateral.valueOf("/CollateralsList/Collateral/vehiid")));
1875 }
1876 if(collateralFlag) {
1877 modifyCollateral(doc, Long.parseLong(xmlCollateral.valueOf("/CollateralsList/Collateral/collid")));
1878 }
1879
1880 originalMiscelaneous = getAgreementDetails(companyId, agrmId, false, false, false, true);
1881 stream = new ByteArrayInputStream(originalMiscelaneous.getBytes());
1882 docParser.setValidationMode(false);
1883 docParser.parse(stream);
1884 xmlMiscelaneous = docParser.getDocument();
1885 attributeNameOri = "AgreementDetails/miscalert";
1886 attributeNameDes = "Miscelaneous/alert";
1887 if(!compareMiscelaneous(xmlMiscelaneous, doc, attributeNameOri, attributeNameDes)) {
1888 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlMiscelaneous.valueOf("/AgreementDetailsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1889 }
1890
1891
1892 attributeNameOri = "AgreementDetails/oldaccount";
1893 attributeNameDes = "Miscelaneous/OldAccount";
1894 if(!compareMiscelaneous(xmlMiscelaneous, doc, attributeNameOri, attributeNameDes)) {
1895 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), attributeNameOri, xmlMiscelaneous.valueOf("/AgreementDetailsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1896 }
1897 attributeNameOri = "AgreementDetails/permanentreviewtime";
1898 attributeNameDes = "Miscelaneous/PermanentReviewTime";
1899 if(!compareMiscelaneous(xmlMiscelaneous, doc, attributeNameOri, attributeNameDes)) {
1900 createAgreementMaintenance(agrmId.longValue(), userId.longValue(), "Permanent Review Time", xmlMiscelaneous.valueOf("/AgreementDetailsList/" + attributeNameOri), doc.valueOf("/Maintenance/" + attributeNameDes), 0);
1901 workItemsFlag = true;
1902 }
1903 modifyAgreements(doc, agrmId.longValue(), userId.longValue(), workItemsFlag);
1904 }
1905 catch(Exception e) {
1906 setRollbackOnly();
1907 throw new InstantbankException(e, "311009", "Failed to save maintenance data");
1908 }
1909 }
1910
1911
1912
1913 public Long saveStatusValues(String data, Long companyId, Long userId, String oldStatusValues) throws InstantbankException {
1914 String agrmId = "0";
1915 long lagrmId;
1916 XMLNode agrmIdNode;
1917 String categoryId;
1918 XMLNode status;
1919 boolean flagChg = false;
1920 DataAccess dataAccess = null;
1921 DOMParser docParser;
1922 String query;
1923 ByteArrayInputStream stream;
1924 String valueId;
1925 XMLDocument xmlDoc;
1926 xmlDoc = null;
1927 DOMParser oldParser;
1928 ByteArrayInputStream oldstream;
1929 XMLNode oldstatus;
1930 NodeList oldList;
1931 XMLDocument oldXmlDoc;
1932 String oldcategoryId;
1933 String oldvalueId;
1934 String oldstatusName;
1935 String oldvalueName;
1936
1937 try {
1938
1939 dataAccess = new DataAccess();
1940 dataAccess.connect();
1941 stream = new ByteArrayInputStream(data.getBytes());
1942 docParser = new DOMParser();
1943 docParser.setValidationMode(false);
1944 docParser.parse(stream);
1945 xmlDoc = docParser.getDocument();
1946 oldXmlDoc = null;
1947 oldstatus = null;
1948 oldstream = new ByteArrayInputStream(oldStatusValues.getBytes());
1949 oldParser = new DOMParser();
1950 oldParser.setValidationMode(false);
1951 oldParser.parse(oldstream);
1952 oldXmlDoc = oldParser.getDocument();
1953
1954 if(xmlDoc.getDocumentElement().hasChildNodes()) {
1955 agrmIdNode = (XMLNode)xmlDoc.selectNodes("/AccountStatus").item(0);
1956 agrmId = agrmIdNode.valueOf("./AgrmId");
1957 lagrmId = Long.parseLong(agrmId);
1958 StringWriter sw = new StringWriter();
1959 PrintWriter pw = new PrintWriter(sw);
1960 agrmIdNode.print(pw);
1961 query = " DELETE FROM AGREEMENTS_STATUS WHERE";
1962 query += " AGRMS_AGRM_ID = \'" + agrmId + "\'";
1963 dataAccess.makeDelete(query);
1964 int statusNumber = xmlDoc.selectNodes("/AccountStatus/StatusList/Status").getLength();
1965 int oldstatusNumber = oldXmlDoc.selectNodes("StatusValuesList/StatusValue").getLength();
1966 Long changedById = null;
1967 String changedDate = null;
1968 for(int i = 0; i < statusNumber; i++) {
1969 changedById = null;
1970 changedDate = null;
1971 status = (XMLNode)xmlDoc.selectNodes("/AccountStatus/StatusList/Status").item(i);
1972 categoryId = status.valueOf("./CategoryId");
1973 valueId = status.valueOf("./ValueId");
1974 flagChg = false;
1975 if(!categoryId.equals("") & !valueId.equals("")) {
1976 for(int j = 0; j < oldstatusNumber; j++) {
1977 oldstatus = (XMLNode)oldXmlDoc.selectNodes("StatusValuesList/StatusValue").item(j);
1978 oldstatusName = oldstatus.valueOf("./categoryname");
1979 oldvalueName = oldstatus.valueOf("./valuename");
1980 oldcategoryId = oldstatus.valueOf("./categoryid");
1981 oldvalueId = oldstatus.valueOf("./valueid");
1982 if(categoryId.equals(oldcategoryId)) {
1983 flagChg = true;
1984 String changedByIdStr = status.valueOf("./changedbyid");
1985 if(changedByIdStr != null && changedByIdStr.length() > 0) {
1986 changedById = new Long(changedByIdStr);
1987 }
1988 changedDate = status.valueOf("./changeddate");
1989 System.out.println("changedby/changeddate=" + changedById + '/' + changedDate);
1990 if(!(valueId.equals(oldvalueId))) {
1991 createAgreementMaintenance(lagrmId, userId.longValue(), "Status - Changed", oldvalueName, oldstatusName + " - " + status.valueOf("./ValueName"), 0);
1992 }
1993 j = oldstatusNumber + 1;
1994 }
1995 }
1996 if(flagChg == false) {
1997 createAgreementMaintenance(lagrmId, userId.longValue(), "Status - New", " ", status.valueOf("./CatergoryName") + status.valueOf("./ValueName"), 0);
1998 }
1999
2000
2001 if(changedById == null) {
2002 changedById = userId;
2003 }
2004 if(changedDate == null || changedDate.length() == 0) {
2005 changedDate = "to_char(sysdate,'mm-dd-yyyy HH24:MI')";
2006 }
2007 else {
2008 changedDate = "'" + changedDate + "'";
2009 }
2010
2011 query = " INSERT INTO AGREEMENTS_STATUS (" +
2012 " AGRMS_AGRM_ID," +
2013 " AGRMS_STC_ID," +
2014 " AGRMS_STV_ID, " +
2015 " AGRMS_STV_LAST_CHANGED_BY," +
2016 " AGRMS_STV_LAST_CHANGED_DATE" +
2017 " ) VALUES (" +
2018 "'" + agrmId + "', " +
2019 "'" + categoryId + "', " +
2020 "'" + valueId + "', " + changedById + ", TO_DATE("
2021 + changedDate + ",'mm-dd-yyyy HH24:MI'))";
2022 dataAccess.makeInsert(query);
2023 }
2024 }
2025 }
2026 return new Long(agrmId);
2027 }
2028 catch(Exception e) {
2029 setRollbackOnly();
2030 throw new InstantbankException(e, "311010", "Failed to save status values");
2031 }
2032 finally {
2033 try {
2034 if(dataAccess != null) {
2035 dataAccess.disconnect();
2036 }
2037 }
2038 catch(Exception e) {
2039 }
2040 }
2041 }
2042
2043
2044 public String searchAccount(Long companyId, String criteria, Long rownum, Integer maxrows) throws InstantbankException {
2045 XMLDocument criteriaXml;
2046 DOMParser docParser = new DOMParser();
2047 boolean flagNulls = true;
2048 boolean flagAddress = true;
2049 String fromTables = "";
2050 String fromTablesAddress = "";
2051 String fromTablesNulls = "";
2052 String joinClause = "";
2053 String joinClauseAddress = "";
2054 String joinClauseNulls = "";
2055 boolean joinFlag = false;
2056 String orderByClause = "";
2057 ByteArrayInputStream stream;
2058 String whereClause = "";
2059 String whereClauseAddress = "";
2060 String whereClauseNulls = "";
2061 XMLDataAccess xda = null;
2062 String xmlDataQuery = "";
2063
2064 try {
2065 xda = new XMLDataAccess("");
2066 xda.connect();
2067
2068 stream = new ByteArrayInputStream(criteria.getBytes());
2069 docParser.setValidationMode(false);
2070 docParser.parse(stream);
2071 criteriaXml = docParser.getDocument();
2072
2073 fromTables = " AGREEMENTS," +
2074 " AGREEMENTS_CUST_LINKS," +
2075 " CUSTOMERS," +
2076 " COLLATERALS," +
2077 " CUSTOMER_ROLES," +
2078 " VEHICLES";
2079 whereClause = " (AGRM_CMP_ID = " + companyId.toString() + ")";
2080 joinClause = " (ACL_AGRM_ID = AGRM_ID)" +
2081 " AND (CUST_ID = ACL_CUST_ID)" +
2082 " AND (COLL_AGRM_ID = AGRM_ID" +
2083 " AND COLL_ROLE = 'FI'" +
2084 " AND COLL_VEHI_ID = VEHI_ID)" +
2085 " AND (ACL_CSR_CODE = CSR_CODE)";
2086
2087 if(!criteriaXml.valueOf("searchCriteria/AccountNo").equals("")) {
2088 whereClause += " AND (AGRM_CODE LIKE '" + criteriaXml.valueOf("searchCriteria/AccountNo") + "%')";
2089
2090 if(criteriaXml.valueOf("searchCriteria/CustomerRole").equals("")) {
2091 whereClause += " AND (ACL_CSR_CODE = 'PR')";
2092 joinFlag = true;
2093 }
2094 }
2095
2096 if(!criteriaXml.valueOf("searchCriteria/PaymentAmount").equals("")) {
2097 whereClause += " AND (AGRM_REGULAR_PAY_AMOUNT = " + criteriaXml.valueOf("searchCriteria/PaymentAmount") + ")";
2098
2099 if(criteriaXml.valueOf("searchCriteria/CustomerRole").equals("")) {
2100 whereClause += " AND (ACL_CSR_CODE = 'PR')";
2101 joinFlag = true;
2102 }
2103 }
2104
2105 if(!criteriaXml.valueOf("searchCriteria/OldAccountNo").equals("")) {
2106 whereClause += " AND (UPPER(AGRM_OLD_CODE) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/OldAccountNo")) + "')||'%')";
2107
2108 if(criteriaXml.valueOf("searchCriteria/CustomerRole").equals("")) {
2109 whereClause += " AND (ACL_CSR_CODE = 'PR')";
2110 joinFlag = true;
2111 }
2112 }
2113
2114 if(!criteriaXml.valueOf("searchCriteria/FirstName").equals("")) {
2115 whereClause += " AND (UPPER(CUST_FIRST_NAME) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/FirstName")) + "')||'%')";
2116 }
2117 if(!criteriaXml.valueOf("searchCriteria/LastName").equals("")) {
2118 whereClause += " AND (UPPER(CUST_LAST_NAME) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/LastName")) + "')||'%')";
2119 }
2120 if(!criteriaXml.valueOf("searchCriteria/SSN").equals("")) {
2121 whereClause += " AND (CUST_SSN LIKE '" + criteriaXml.valueOf("searchCriteria/SSN") + "%')";
2122 }
2123 if(!criteriaXml.valueOf("searchCriteria/Email").equals("")) {
2124 whereClause += " AND (UPPER(CUST_EMAIL) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/Email")) + "')||'%')";
2125 }
2126 if(!criteriaXml.valueOf("searchCriteria/DriversLicense").equals("")) {
2127 whereClause += " AND (CUST_DRIVERS_LICENSE LIKE '" + criteriaXml.valueOf("searchCriteria/DriversLicense") + "%')";
2128 }
2129 if(!criteriaXml.valueOf("searchCriteria/VIN").equals("")) {
2130 whereClause += " AND (VEHI_VIN LIKE '" + criteriaXml.valueOf("searchCriteria/VIN") + "%')";
2131
2132 if(criteriaXml.valueOf("searchCriteria/CustomerRole").equals("")) {
2133 whereClause += " AND (ACL_CSR_CODE = 'PR')";
2134 joinFlag = true;
2135 }
2136 }
2137
2138 if(!criteriaXml.valueOf("searchCriteria/CustomerRole").equals("") && !joinFlag == true) {
2139 whereClause += " AND (ACL_CSR_CODE = '" + criteriaXml.valueOf("searchCriteria/CustomerRole") + "')";
2140 }
2141
2142 if(!criteriaXml.valueOf("searchCriteria/HomePhone").equals("")) {
2143 whereClause += " AND (UPPER(NHOME.PHN_NUMBER) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/HomePhone")) + "')||'%')";
2144 fromTables += ", CUSTOMER_PHONES CHOME, PHONE_NUMBERS NHOME";
2145 joinClause += " AND (CHOME.CPH_CUST_ID = CUST_ID AND NHOME.PHN_ID = CHOME.CPH_PHN_ID AND NHOME.PHN_PHT_CODE = 'HO')";
2146 }
2147
2148 if(!criteriaXml.valueOf("searchCriteria/BusinessPhone").equals("")) {
2149 whereClause += " AND (UPPER(NBUS.PHN_NUMBER) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/BusinessPhone")) + "')||'%')";
2150 fromTables += ", CUSTOMER_PHONES CBUS, PHONE_NUMBERS NBUS";
2151 joinClause += " AND (CBUS.CPH_CUST_ID = CUST_ID AND NBUS.PHN_ID = CBUS.CPH_PHN_ID AND NBUS.PHN_PHT_CODE = 'BU')";
2152 }
2153
2154 whereClauseNulls = whereClause;
2155 if(!criteriaXml.valueOf("searchCriteria/Street").equals("")) {
2156 whereClause += " AND (UPPER(ADD_LINE1) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/Street")) + "')||'%')";
2157 flagNulls = false;
2158 }
2159
2160 if(!criteriaXml.valueOf("searchCriteria/City").equals("")) {
2161 whereClause += " AND (UPPER(ADD_CITY) LIKE UPPER('" + StringFormat.toSafeOracleString(criteriaXml.valueOf("searchCriteria/City")) + "')||'%')";
2162 flagNulls = false;
2163 }
2164
2165 if(!criteriaXml.valueOf("searchCriteria/ZipCode").equals("")) {
2166 whereClause += " AND (ADD_ZIP_CODE LIKE '" + criteriaXml.valueOf("searchCriteria/ZipCode") + "%')";
2167 flagNulls = false;
2168 }
2169
2170 whereClauseAddress = whereClause;
2171 if(!criteriaXml.valueOf("searchCriteria/StateCode").equals("")) {
2172 whereClause += " AND (STT_ID = " + criteriaXml.valueOf("searchCriteria/StateCode") + ")";
2173 flagNulls = false;
2174 flagAddress = false;
2175 }
2176
2177 if((!criteriaXml.valueOf("searchCriteria/FirstName").equals("")) || (!criteriaXml.valueOf("searchCriteria/LastName").equals(""))) {
2178 orderByClause = " ORDER BY CUST_LAST_NAME ";
2179 }
2180 else {
2181 orderByClause = " ORDER BY AGRM_CODE ";
2182 }
2183
2184 joinClauseNulls = joinClause;
2185 fromTablesNulls = fromTables;
2186
2187 fromTables += ", ADDRESSES";
2188 fromTablesAddress = fromTables;
2189 fromTables += ", STATES ";
2190 joinClause += " AND (ACL_ADD_ID = ADD_ID)";
2191 joinClauseAddress = joinClause;
2192 joinClause += " AND (STT_ID = ADD_STT_ID)";
2193
2194 joinClauseAddress += " AND (ADD_STT_ID IS NULL)";
2195 joinClauseNulls += " AND (ACL_ADD_ID IS NULL)";
2196
2197 xmlDataQuery = " SELECT * FROM (" +
2198 " SELECT Id, AccountNumber, Name, Ssn, City, State, Vin, CustomerRole, ROWNUM theRow FROM (" +
2199 " SELECT DISTINCT AGRM_ID Id," +
2200 " AGRM_CODE AccountNumber," +
2201 " CUST_FIRST_NAME || ' ' || CUST_LAST_NAME Name," +
2202 " CUST_SSN Ssn," +
2203 " ADD_CITY City," +
2204 " STT_CODE State," +
2205 " VEHI_VIN Vin," +
2206 " CSR_DESCRIPTION CustomerRole, " +
2207 " CUST_LAST_NAME CustomerLastName " +
2208 " FROM " + fromTables +
2209 " WHERE " + whereClause + " AND (" + joinClause + ")" +
2210 orderByClause + " ) ";
2211
2212 if(flagAddress) {
2213 xmlDataQuery += "UNION ALL SELECT Id, AccountNumber, Name, Ssn, City, State, Vin, CustomerRole, ROWNUM theRow FROM (" +
2214 " SELECT DISTINCT AGRM_ID Id," +
2215 " AGRM_CODE AccountNumber," +
2216 " CUST_FIRST_NAME || ' ' || CUST_LAST_NAME Name," +
2217 " CUST_SSN Ssn," +
2218 " ADD_CITY City," +
2219 " NULL State," +
2220 " VEHI_VIN Vin," +
2221 " CSR_DESCRIPTION CustomerRole, " +
2222 " CUST_LAST_NAME CustomerLastName " +
2223 " FROM " + fromTablesAddress +
2224 " WHERE " + whereClauseAddress + " AND (" + joinClauseAddress + ")" +
2225 orderByClause + " ) ";
2226 }
2227
2228 if(flagNulls) {
2229 xmlDataQuery += "UNION ALL SELECT Id, AccountNumber, Name, Ssn, City, State, Vin, CustomerRole, ROWNUM theRow FROM (" +
2230 " SELECT DISTINCT AGRM_ID Id," +
2231 " AGRM_CODE AccountNumber," +
2232 " CUST_FIRST_NAME || ' ' || CUST_LAST_NAME Name," +
2233 " CUST_SSN Ssn," +
2234 " NULL City," +
2235 " NULL State," +
2236 " VEHI_VIN Vin," +
2237 " CSR_DESCRIPTION CustomerRole, " +
2238 " CUST_LAST_NAME CustomerLastName " +
2239 " FROM " + fromTablesNulls +
2240 " WHERE " + whereClauseNulls + " AND (" + joinClauseNulls + ")" +
2241 orderByClause + ")";
2242 }
2243
2244 xmlDataQuery += ") WHERE theRow between " + rownum.toString() + " AND " + new Long(rownum.longValue() + maxrows.longValue() - 1).toString();
2245 xmlDataQuery += " ORDER BY AccountNumber";
2246
2247 return xda.getXml(xmlDataQuery, "Accounts", "Account");
2248 }
2249 catch(Exception e) {
2250 setRollbackOnly();
2251 throw new InstantbankException(e, "311011", "Failed to retrieve accounts searched");
2252 }
2253 finally {
2254 try {
2255 if(xda != null) {
2256 xda.disconnect();
2257 }
2258 }
2259 catch(Exception e) {
2260 }
2261 }
2262 }
2263
2264
2265 private void setRollbackOnly() {
2266 try {
2267 this.context.setRollbackOnly();
2268 }
2269 catch(Exception ne) {
2270 }
2271 }
2272
2273
2274 private void updatePermanentReviewTime(long agrmId, String permanentReviewTime, long userId) throws Exception {
2275 DataAccess da = null;
2276 String followupTime = "00:00";
2277 int n;
2278 Long prtHour;
2279 long prtHourPlusTimeOffset = 0;
2280 String prtHourS;
2281 String prtMinutes;
2282 String prtMeridian;
2283 ResultSet rs = null;
2284 String sql;
2285 Statement st = null;
2286 int timeoffset = 0;
2287
2288 try {
2289 da = new DataAccess();
2290 da.connect();
2291
2292 st = da.getConnection().createStatement();
2293 sql = "Select USER_TIME_OFFSET ";
2294 sql += "From Users ";
2295 sql += "Where USER_ID = " + userId;
2296 rs = st.executeQuery(sql);
2297 if(rs.next()) {
2298 timeoffset = rs.getInt(1);
2299 }
2300
2301 if(permanentReviewTime.length() > 0) {
2302 prtHour = new Long(permanentReviewTime.substring(0, 2));
2303 prtHourS = permanentReviewTime.substring(0, 2);
2304 prtMinutes = permanentReviewTime.substring(3, 5);
2305 prtMeridian = permanentReviewTime.substring(5, 7);
2306 if(prtMeridian.equalsIgnoreCase("PM") && prtHour.longValue() < 12) {
2307 prtHour = new Long(prtHour.longValue() + 12);
2308 prtHourS = prtHour.toString();
2309 }
2310 else
2311 if(prtMeridian.equalsIgnoreCase("AM") && prtHour.longValue() == 12) {
2312 prtHourS = "00";
2313 }
2314 followupTime = prtHourS + ":" + prtMinutes;
2315 }
2316 else {
2317 followupTime = "00:00";
2318 }
2319
2320 sql = "UPDATE WORK_ITEMS ";
2321 sql += "SET WRKI_FOLLOWUP_TIME = tO_CHAR(TO_DATE('" + followupTime + "','HH24:MI')+" + timeoffset + "/24,'HH24:MI')";
2322 sql += "WHERE WRKI_OBJECT_ID = " + agrmId;
2323 n = st.executeUpdate(sql);
2324 }
2325 catch(Exception e) {
2326 setRollbackOnly();
2327 throw new InstantbankException(e, "311014", "Failed to update Permanent Review Time");
2328 }
2329 finally {
2330 try {
2331 if(st != null) {
2332 st.close();
2333 }
2334 if(da != null) {
2335 da.disconnect();
2336 }
2337 }
2338 catch(Exception e) {
2339 }
2340 }
2341 }
2342
2343 }
2344
2345