View Javadoc
1   /*
2    * Copyright 2013 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.document;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
20  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
21  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
22  import org.kuali.ole.fp.document.service.DisbursementVoucherPaymentReasonService;
23  import org.kuali.ole.module.purap.PurapConstants;
24  import org.kuali.ole.select.businessobject.OleDisbursementVoucherAccountingLine;
25  import org.kuali.ole.select.businessobject.OleDisbursementVoucherPayeeDetail;
26  import org.kuali.ole.select.businessobject.OlePaymentMethod;
27  import org.kuali.ole.sys.OLEConstants;
28  import org.kuali.ole.sys.OLEConstants.AdHocPaymentIndicator;
29  import org.kuali.ole.sys.businessobject.Bank;
30  import org.kuali.ole.sys.businessobject.ChartOrgHolder;
31  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
32  import org.kuali.ole.sys.context.SpringContext;
33  import org.kuali.ole.sys.document.AmountTotaling;
34  import org.kuali.ole.sys.service.BankService;
35  import org.kuali.ole.vnd.VendorConstants;
36  import org.kuali.ole.vnd.businessobject.VendorAddress;
37  import org.kuali.ole.vnd.businessobject.VendorAlias;
38  import org.kuali.ole.vnd.businessobject.VendorDetail;
39  import org.kuali.rice.kim.api.identity.Person;
40  import org.kuali.rice.krad.service.BusinessObjectService;
41  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
42  import org.kuali.rice.krad.service.LookupService;
43  import org.kuali.rice.krad.util.GlobalVariables;
44  import org.kuali.rice.krad.util.ObjectUtils;
45  
46  import java.sql.Date;
47  import java.text.MessageFormat;
48  import java.util.Calendar;
49  import java.util.HashMap;
50  import java.util.List;
51  import java.util.Map;
52  
53  
54  public class OleDisbursementVoucherDocument extends DisbursementVoucherDocument {
55  
56      private String vendorAliasName;
57      private String invoiceNumber;
58  
59      public String getVendorAliasName() {
60          return vendorAliasName;
61      }
62  
63      public void setVendorAliasName(String vendorAliasName) {
64          this.vendorAliasName = vendorAliasName;
65      }
66  
67      public String getInvoiceNumber() {
68          return invoiceNumber;
69      }
70  
71      public void setInvoiceNumber(String invoiceNumber) {
72          this.invoiceNumber = invoiceNumber;
73      }
74  
75      protected static final String HAS_CLEARING_ACCOUNT_TYPE_SPLIT = "HasClearingAccountType";
76  
77      protected OleDisbursementVoucherPayeeDetail dvPayeeDetail;
78  
79      /**
80       * Default no-arg constructor.
81       */
82      public OleDisbursementVoucherDocument() {
83          super();
84          dvPayeeDetail = new OleDisbursementVoucherPayeeDetail();
85      }
86  
87      /**
88       * @return Returns the dvPayeeDetail.
89       */
90      @Override
91      public OleDisbursementVoucherPayeeDetail getDvPayeeDetail() {
92          return dvPayeeDetail;
93      }
94  
95      /**
96       * @param dvPayeeDetail The dvPayeeDetail to set.
97       */
98      @Override
99      public void setDvPayeeDetail(DisbursementVoucherPayeeDetail dvPayeeDetail) {
100         OleDisbursementVoucherPayeeDetail dvDetail = (OleDisbursementVoucherPayeeDetail) dvPayeeDetail;
101         this.dvPayeeDetail = dvDetail;
102     }
103 
104     /**
105      * @see org.kuali.rice.kns.document.Document#prepareForSave()
106      */
107     @Override
108     public void prepareForSave() {
109         if (this instanceof AmountTotaling) {
110             getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(
111                     ((AmountTotaling) this).getTotalDollarAmount());
112         }
113 
114         if (dvWireTransfer != null) {
115             dvWireTransfer.setDocumentNumber(this.documentNumber);
116         }
117 
118         if (dvNonResidentAlienTax != null) {
119             dvNonResidentAlienTax.setDocumentNumber(this.documentNumber);
120         }
121 
122         dvPayeeDetail.setDocumentNumber(this.documentNumber);
123 
124         if (dvNonEmployeeTravel != null) {
125             dvNonEmployeeTravel.setDocumentNumber(this.documentNumber);
126             dvNonEmployeeTravel.setTotalTravelAmount(dvNonEmployeeTravel.getTotalTravelAmount());
127         }
128 
129         if (dvPreConferenceDetail != null) {
130             dvPreConferenceDetail.setDocumentNumber(this.documentNumber);
131             dvPreConferenceDetail.setDisbVchrConferenceTotalAmt(dvPreConferenceDetail.getDisbVchrConferenceTotalAmt());
132         }
133 
134         if (shouldClearSpecialHandling()) {
135             clearSpecialHandling();
136         }
137         if (dvPayeeDetail.getVendorAliasName() != null && dvPayeeDetail.getVendorAliasName().length() > 0) {
138             checkVendorUsingVendorAliasName();
139         }
140         if(this.getPaymentMethodId() != null)  {
141             OlePaymentMethod olePaymentMethod = new OlePaymentMethod();
142                  olePaymentMethod = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(
143                         OlePaymentMethod.class, this.getPaymentMethodId());
144            if(olePaymentMethod != null)  {
145                if(olePaymentMethod.getPaymentMethod().equalsIgnoreCase("CHECK")) {
146                    this.setDisbVchrPaymentMethodCode(DisbursementVoucherConstants.PAYMENT_METHOD_CHECK);
147                }
148                else if(olePaymentMethod.getPaymentMethod().equalsIgnoreCase("Wire Transfer")) {
149                    this.setDisbVchrPaymentMethodCode(DisbursementVoucherConstants.PAYMENT_METHOD_WIRE);
150                }
151                else if(olePaymentMethod.getPaymentMethod().equalsIgnoreCase("Foreign Draft")) {
152                    this.setDisbVchrPaymentMethodCode(DisbursementVoucherConstants.PAYMENT_METHOD_DRAFT);
153                }
154 
155            }
156         }
157     }
158 
159     private void checkVendorUsingVendorAliasName() {
160         Map vendorAliasMap = new HashMap();
161         vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, dvPayeeDetail.getVendorAliasName());
162         org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
163         List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
164         if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {
165             if (this.getDvPayeeDetail().getDisbVchrPayeeIdNumber() == null) {
166                 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
167             } else {
168                 String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
169                 String vendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
170                 String AliasPayeeId = vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier;
171                 if (this.getDvPayeeDetail().getDisbVchrPayeeIdNumber().equalsIgnoreCase(AliasPayeeId)) {
172                     this.getDvPayeeDetail().setDisbVchrPaymentReasonCode(DisbursementVoucherConstants.DV_PAYEE_TYPE_EMPLOYEE);
173                     LOG.debug("###########vendors are allowed to save###########");
174                 } else {
175                     GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
176                 }
177             }
178         } else {
179             GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
180         }
181     }
182 
183     /**
184      * Clears all set special handling fields
185      */
186     @Override
187     protected void clearSpecialHandling() {
188         OleDisbursementVoucherPayeeDetail payeeDetail = getDvPayeeDetail();
189 
190         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingPersonName())) {
191             payeeDetail.setDisbVchrSpecialHandlingPersonName(null);
192         }
193         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingLine1Addr())) {
194             payeeDetail.setDisbVchrSpecialHandlingLine1Addr(null);
195         }
196         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingLine2Addr())) {
197             payeeDetail.setDisbVchrSpecialHandlingLine2Addr(null);
198         }
199         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingCityName())) {
200             payeeDetail.setDisbVchrSpecialHandlingCityName(null);
201         }
202         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingStateCode())) {
203             payeeDetail.setDisbVchrSpecialHandlingStateCode(null);
204         }
205         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingZipCode())) {
206             payeeDetail.setDisbVchrSpecialHandlingZipCode(null);
207         }
208         if (!StringUtils.isBlank(payeeDetail.getDisbVchrSpecialHandlingCountryCode())) {
209             payeeDetail.setDisbVchrSpecialHandlingCountryCode(null);
210         }
211     }
212 
213     /**
214      * Clears information that might have been entered for sub tables, but because of changes to the document is longer needed and
215      * should not be persisted.
216      */
217     @Override
218     protected void cleanDocumentData() {
219         // TODO: warren: this method ain't called!!! maybe this should be called by prepare for save above
220         if (!DisbursementVoucherConstants.PAYMENT_METHOD_WIRE.equals(this.getDisbVchrPaymentMethodCode()) && !DisbursementVoucherConstants.PAYMENT_METHOD_DRAFT.equals(this.getDisbVchrPaymentMethodCode())) {
221             getBusinessObjectService().delete(dvWireTransfer);
222             dvWireTransfer = null;
223         }
224 
225         if (!dvPayeeDetail.isDisbVchrAlienPaymentCode()) {
226             getBusinessObjectService().delete(dvNonResidentAlienTax);
227             dvNonResidentAlienTax = null;
228         }
229 
230         DisbursementVoucherPaymentReasonService paymentReasonService = SpringContext.getBean(DisbursementVoucherPaymentReasonService.class);
231         String paymentReasonCode = this.getDvPayeeDetail().getDisbVchrPaymentReasonCode();
232         //Commented for the jira issue OLE-3415
233         /*if (!paymentReasonService.isNonEmployeeTravelPaymentReason(paymentReasonCode)) {
234             getBusinessObjectService().delete(dvNonEmployeeTravel);
235             dvNonEmployeeTravel = null;
236         }
237 
238         if (!paymentReasonService.isPrepaidTravelPaymentReason(paymentReasonCode)) {
239             getBusinessObjectService().delete(dvPreConferenceDetail);
240             dvPreConferenceDetail = null;
241         }*/
242     }
243 
244     /**
245      * build document title based on the properties of current document
246      *
247      * @param the default document title
248      * @return the combine information of the given title and additional payment indicators
249      */
250     @Override
251     protected String buildDocumentTitle(String title) {
252         OleDisbursementVoucherPayeeDetail payee = getDvPayeeDetail();
253         if (payee == null) {
254             return title;
255         }
256 
257         Object[] indicators = new String[2];
258         indicators[0] = payee.isEmployee() ? AdHocPaymentIndicator.EMPLOYEE_PAYEE : AdHocPaymentIndicator.OTHER;
259         indicators[1] = payee.isDisbVchrAlienPaymentCode() ? AdHocPaymentIndicator.ALIEN_PAYEE : AdHocPaymentIndicator.OTHER;
260 
261         DisbursementVoucherPaymentReasonService paymentReasonService = SpringContext.getBean(DisbursementVoucherPaymentReasonService.class);
262         //Commented for the jira OLE-3415
263         /*boolean isTaxReviewRequired = paymentReasonService.isTaxReviewRequired(payee.getDisbVchrPaymentReasonCode());
264         indicators[2] = isTaxReviewRequired ? AdHocPaymentIndicator.PAYMENT_REASON_REQUIRING_TAX_REVIEW : AdHocPaymentIndicator.OTHER;*/
265 
266         for (Object indicator : indicators) {
267             if (!AdHocPaymentIndicator.OTHER.equals(indicator)) {
268                 String titlePattern = title + " [{0}:{1}]";
269                 return MessageFormat.format(titlePattern, indicators);
270             }
271         }
272 
273         return title;
274     }
275 
276     /**
277      * Convenience method to set dv payee detail fields based on a given vendor.
278      *
279      * @param vendor
280      */
281     @Override
282     public void templateVendor(VendorDetail vendor, VendorAddress vendorAddress) {
283         if (vendor == null) {
284             return;
285         }
286         if (this.getDocumentHeader().getDocumentTemplateNumber() == null) {
287             this.setPaymentMethodId(vendor.getPaymentMethodId());
288         }
289         this.getDvPayeeDetail().setDisbursementVoucherPayeeTypeCode(DisbursementVoucherConstants.DV_PAYEE_TYPE_VENDOR);
290         this.getDvPayeeDetail().setDisbVchrPayeeIdNumber(vendor.getVendorNumber());
291         this.getDvPayeeDetail().setDisbVchrPayeePersonName(vendor.getVendorName());
292 
293         this.getDvPayeeDetail().setDisbVchrAlienPaymentCode(vendor.getVendorHeader().getVendorForeignIndicator());
294 
295         if (ObjectUtils.isNull(vendorAddress) || ObjectUtils.isNull(vendorAddress.getVendorAddressGeneratedIdentifier())) {
296             for (VendorAddress addr : vendor.getVendorAddresses()) {
297                 if (addr.isVendorDefaultAddressIndicator()) {
298                     vendorAddress = addr;
299                     break;
300                 }
301             }
302         }
303 
304         if (ObjectUtils.isNotNull(vendorAddress) && ObjectUtils.isNotNull(vendorAddress.getVendorAddressGeneratedIdentifier())) {
305             this.getDvPayeeDetail().setDisbVchrVendorAddressIdNumber(vendorAddress.getVendorAddressGeneratedIdentifier().toString());
306             this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(vendorAddress.getVendorLine1Address());
307             this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(vendorAddress.getVendorLine2Address());
308             this.getDvPayeeDetail().setDisbVchrPayeeCityName(vendorAddress.getVendorCityName());
309             this.getDvPayeeDetail().setDisbVchrPayeeStateCode(vendorAddress.getVendorStateCode());
310             this.getDvPayeeDetail().setDisbVchrPayeeZipCode(vendorAddress.getVendorZipCode());
311             this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(vendorAddress.getVendorCountryCode());
312         } else {
313             this.getDvPayeeDetail().setDisbVchrVendorAddressIdNumber("");
314             this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr("");
315             this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr("");
316             this.getDvPayeeDetail().setDisbVchrPayeeCityName("");
317             this.getDvPayeeDetail().setDisbVchrPayeeStateCode("");
318             this.getDvPayeeDetail().setDisbVchrPayeeZipCode("");
319             this.getDvPayeeDetail().setDisbVchrPayeeCountryCode("");
320         }
321 
322 //        this.getDvPayeeDetail().setDisbVchrAlienPaymentCode(vendor.getVendorHeader().getVendorForeignIndicator());
323         this.getDvPayeeDetail().setDvPayeeSubjectPaymentCode(VendorConstants.VendorTypes.SUBJECT_PAYMENT.equals(vendor.getVendorHeader().getVendorTypeCode()));
324         this.getDvPayeeDetail().setDisbVchrEmployeePaidOutsidePayrollCode(getVendorService().isVendorInstitutionEmployee(vendor.getVendorHeaderGeneratedIdentifier()));
325 
326         this.getDvPayeeDetail().setHasMultipleVendorAddresses(1 < vendor.getVendorAddresses().size());
327 
328         boolean w9AndW8Checked = false;
329         if ((ObjectUtils.isNotNull(vendor.getVendorHeader().getVendorW9ReceivedIndicator()) && vendor.getVendorHeader().getVendorW9ReceivedIndicator() == true) ||
330                 (ObjectUtils.isNotNull(vendor.getVendorHeader().getVendorW8BenReceivedIndicator()) && vendor.getVendorHeader().getVendorW8BenReceivedIndicator() == true)) {
331 
332             w9AndW8Checked = true;
333         }
334 
335         //    this.disbVchrPayeeW9CompleteCode = vendor.getVendorHeader().getVendorW8BenReceivedIndicator()  == null ? false : vendor.getVendorHeader().getVendorW8BenReceivedIndicator();
336         this.disbVchrPayeeW9CompleteCode = w9AndW8Checked;
337 
338         Date vendorFederalWithholdingTaxBeginDate = vendor.getVendorHeader().getVendorFederalWithholdingTaxBeginningDate();
339         Date vendorFederalWithholdingTaxEndDate = vendor.getVendorHeader().getVendorFederalWithholdingTaxEndDate();
340         java.util.Date today = getDateTimeService().getCurrentDate();
341         if ((vendorFederalWithholdingTaxBeginDate != null && vendorFederalWithholdingTaxBeginDate.before(today)) && (vendorFederalWithholdingTaxEndDate == null || vendorFederalWithholdingTaxEndDate.after(today))) {
342             this.disbVchrPayeeTaxControlCode = DisbursementVoucherConstants.TAX_CONTROL_CODE_BEGIN_WITHHOLDING;
343         }
344 
345         // if vendor is foreign, default alien payment code to true
346         if (getVendorService().isVendorForeign(vendor.getVendorHeaderGeneratedIdentifier())) {
347             getDvPayeeDetail().setDisbVchrAlienPaymentCode(true);
348         }
349     }
350 
351     /**
352      * This method is overridden to populate some local variables that are not persisted to the database. These values need to be
353      * computed and saved to the DV Payee Detail BO so they can be serialized to XML for routing. Some of the routing rules rely on
354      * these variables.
355      *
356      * @see org.kuali.rice.kns.document.DocumentBase#populateDocumentForRouting()
357      */
358     @Override
359     public void populateDocumentForRouting() {
360         OleDisbursementVoucherPayeeDetail payeeDetail = getDvPayeeDetail();
361 
362         if (payeeDetail.isVendor()) {
363             payeeDetail.setDisbVchrPayeeEmployeeCode(getVendorService().isVendorInstitutionEmployee(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger()));
364             payeeDetail.setDvPayeeSubjectPaymentCode(getVendorService().isSubjectPaymentVendor(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger()));
365         } else if (payeeDetail.isEmployee()) {
366             //Commented for the jira issue OLE-3415
367             // Determine if employee is a research subject
368             /*ParameterEvaluator researchPaymentReasonCodeEvaluator = getParameterService().getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.RESEARCH_PAYMENT_REASONS_PARM_NM, payeeDetail.getDisbVchrPaymentReasonCode());
369             if (researchPaymentReasonCodeEvaluator.evaluationSucceeds()) {
370                 if (getParameterService().parameterExists(DisbursementVoucherDocument.class, DisbursementVoucherConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT_PARM_NM)) {
371                     String researchPayLimit = getParameterService().getParameterValue(DisbursementVoucherDocument.class, DisbursementVoucherConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT_PARM_NM);
372                     if (StringUtils.isNotBlank(researchPayLimit)) {
373                         KualiDecimal payLimit = new KualiDecimal(researchPayLimit);
374 
375                         if (getDisbVchrCheckTotalAmount().isLessThan(payLimit)) {
376                             payeeDetail.setDvPayeeSubjectPaymentCode(true);
377                         }
378                     }
379                 }
380             }*/
381         }
382         if (this.getPaymentMethodId() != null) {
383             OlePaymentMethod olePaymentMethod = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(OlePaymentMethod.class, this.getPaymentMethodId());
384             this.setPaymentMethod(olePaymentMethod);
385         }
386         super.populateDocumentForRouting(); // Call last, serializes to XML
387     }
388 
389     /**
390      * generic, shared logic used to initiate a dv document
391      */
392     @Override
393     public void initiateDocument() {
394         Person currentUser = GlobalVariables.getUserSession().getPerson();
395         setDisbVchrContactPersonName(currentUser.getName());
396         setDisbVchrContactPhoneNumber(currentUser.getPhoneNumber());
397         setDisbVchrContactEmailId(currentUser.getEmailAddress());
398         ChartOrgHolder chartOrg = SpringContext.getBean(org.kuali.ole.sys.service.FinancialSystemUserService.class).getPrimaryOrganization(currentUser, OLEConstants.ParameterNamespaces.FINANCIAL);
399 
400         // Does a valid campus code exist for this person?  If so, simply grab
401         // the campus code via the business object service.
402         if (chartOrg != null && chartOrg.getOrganization() != null) {
403             setCampusCode(chartOrg.getOrganization().getOrganizationPhysicalCampusCode());
404         }
405         // A valid campus code was not found; therefore, use the default affiliated
406         // campus code.
407         else {
408             String affiliatedCampusCode = currentUser.getCampusCode();
409             setCampusCode(affiliatedCampusCode);
410         }
411 
412         // due date
413         Calendar calendar = getDateTimeService().getCurrentCalendar();
414         calendar.add(Calendar.DAY_OF_MONTH, 1);
415         setDisbursementVoucherDueDate(new Date(calendar.getTimeInMillis()));
416 
417         // default doc location
418         if (StringUtils.isBlank(getDisbursementVoucherDocumentationLocationCode())) {
419             setDisbursementVoucherDocumentationLocationCode(getParameterService().getParameterValueAsString(
420                     DisbursementVoucherDocument.class, DisbursementVoucherConstants.DEFAULT_DOC_LOCATION_PARM_NM));
421         }
422 
423         // default bank code
424         Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
425         if (defaultBank != null) {
426             this.disbVchrBankCode = defaultBank.getBankCode();
427             this.bank = defaultBank;
428         }
429         OlePaymentMethod olePaymentMethod = new OlePaymentMethod();
430         if (this.getPaymentMethodId() != null) {
431             olePaymentMethod = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(
432                     OlePaymentMethod.class, this.getPaymentMethodId());
433         }
434 
435         this.setPaymentMethod(olePaymentMethod);
436     }
437 
438     /**
439      * This implementation sets the sequence number appropriately for the passed in source accounting line using the value that has
440      * been stored in the nextSourceLineNumber variable, adds the accounting line to the list that is aggregated by this object, and
441      * then handles incrementing the nextSourceLineNumber variable for you.
442      *
443      * @see org.kuali.ole.sys.document.AccountingDocument#addSourceAccountingLine(org.kuali.ole.sys.businessobject.SourceAccountingLine)
444      */
445     @Override
446     public void addSourceAccountingLine(SourceAccountingLine line) {
447         OleDisbursementVoucherAccountingLine oleDisbursementVoucherAccountingLine = (OleDisbursementVoucherAccountingLine) line;
448         oleDisbursementVoucherAccountingLine.setSequenceNumber(this.getNextSourceLineNumber());
449         this.sourceAccountingLines.add(oleDisbursementVoucherAccountingLine);
450         this.nextSourceLineNumber = new Integer(this.getNextSourceLineNumber().intValue() + 1);
451     }
452 
453     /**
454      * This implementation is coupled tightly with some underlying issues that the Struts PojoProcessor plugin has with how objects
455      * get instantiated within lists. The first three lines are required otherwise when the PojoProcessor tries to automatically
456      * inject values into the list, it will get an index out of bounds error if the instance at an index is being called and prior
457      * instances at indices before that one are not being instantiated. So changing the code below will cause adding lines to break
458      * if you add more than one item to the list.
459      *
460      * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLine(int)
461      */
462     @Override
463     public OleDisbursementVoucherAccountingLine getSourceAccountingLine(int index) {
464         while (getSourceAccountingLines().size() <= index) {
465             try {
466                 getSourceAccountingLines().add((OleDisbursementVoucherAccountingLine) getSourceAccountingLineClass().newInstance());
467             } catch (InstantiationException e) {
468                 throw new RuntimeException("Unable to get class");
469             } catch (IllegalAccessException e) {
470                 throw new RuntimeException("Unable to get class");
471             }
472         }
473         return getSourceAccountingLines().get(index);
474     }
475 
476     /**
477      * Returns the default Source accounting line class.Dollar
478      *
479      * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLineClass()
480      */
481     @Override
482     public Class getSourceAccountingLineClass() {
483         if (sourceAccountingLineClass == null) {
484             sourceAccountingLineClass = (getDataDictionaryEntry().getAccountingLineGroups() != null && getDataDictionaryEntry().getAccountingLineGroups().containsKey("source") && getDataDictionaryEntry().getAccountingLineGroups().get("source").getAccountingLineClass() != null) ? getDataDictionaryEntry().getAccountingLineGroups().get("source").getAccountingLineClass() : OleDisbursementVoucherAccountingLine.class;
485         }
486         return sourceAccountingLineClass;
487     }
488 
489     /**
490      * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLines()
491      */
492     @Override
493     public List<OleDisbursementVoucherAccountingLine> getSourceAccountingLines() {
494         return this.sourceAccountingLines;
495     }
496 
497     /**
498      * @see org.kuali.ole.sys.document.AccountingDocument#setSourceAccountingLines(java.util.List)
499      */
500     @Override
501     public void setSourceAccountingLines(List sourceLines) {
502         this.sourceAccountingLines = sourceLines;
503     }
504 
505     /**
506      * Provides answers to the following splits: PayeeIsPurchaseOrderVendor
507      * RequiresTaxReview
508      * RequiresTravelReview
509      * HasClearingAccountType
510      * HasPaymentMethod
511      *
512      * @see org.kuali.ole.sys.document.FinancialSystemTransactionalDocumentBase#answerSplitNodeQuestion(String)
513      */
514     @Override
515     public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
516         if (nodeName.equals(OleDisbursementVoucherDocument.HAS_CLEARING_ACCOUNT_TYPE_SPLIT)) {
517             return hasClearingAccountType();
518         }
519         if (nodeName.equals(DisbursementVoucherDocument.PAYEE_IS_PURCHASE_ORDER_VENDOR_SPLIT)) {
520             return isPayeePurchaseOrderVendor();
521         }
522         if (nodeName.equals(DisbursementVoucherDocument.DOCUMENT_REQUIRES_TAX_REVIEW_SPLIT)) {
523             return isTaxReviewRequired();
524         }
525         if (nodeName.equals(DisbursementVoucherDocument.DOCUMENT_REQUIRES_TRAVEL_REVIEW_SPLIT)) {
526             return true;
527         }
528         if (nodeName.equals(DOCUMENT_REQUIRES_SEPARATION_OF_DUTIES)) {
529             return isSeparationOfDutiesReviewRequired();
530         }
531         throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
532     }
533 
534     private boolean hasClearingAccountType() {
535         boolean hasAccountType = false;
536         List<OleDisbursementVoucherAccountingLine> sourceAccounts = this.getSourceAccountingLines();
537         for (OleDisbursementVoucherAccountingLine sourceAccount : sourceAccounts) {
538             if (sourceAccount.getAccount().getSubFundGroupCode().equalsIgnoreCase(OLEConstants.CLEARING_ACCOUNT_CODE)) {
539                 hasAccountType = true;
540             }
541         }/*
542         if(hasAccountType) {
543             List roleIds = new ArrayList<String>();
544             String nameSpaceCode = OLEConstants.OleRequisition.REQUISITION_NAMESPACE;
545             String roleId = getRoleService().getRoleIdByName(nameSpaceCode,OLEConstants.OLE_PREPAYMENT);
546             roleIds.add(roleId);
547             hasAccountType = !getRoleService().principalHasRole(this.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId(), roleIds, null);
548         }*/
549         return hasAccountType;
550     }
551 
552     private LookupService getLookupService() {
553         return KRADServiceLocatorWeb.getLookupService();
554     }
555 
556 }