View Javadoc
1   /*
2    * Copyright 2012 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.kuali.ole.fp.document.DistributionOfIncomeAndExpenseDocument;
19  import org.kuali.ole.fp.document.DistributionOfIncomeExpenseDocument;
20  import org.kuali.ole.fp.form.OLEDistributionOfIncomeAndExpenseForm;
21  import org.kuali.ole.module.purap.document.service.PurapService;
22  import org.kuali.ole.select.businessobject.OleDistributionOfIncomeAndExpenseAccountingLineBase;
23  import org.kuali.ole.select.businessobject.OleDistributionOfSourceIncomeAndExpenseAccountingLineBase;
24  import org.kuali.ole.select.businessobject.OleDistributionOfTargetIncomeAndExpenseAccountingLineBase;
25  import org.kuali.ole.select.businessobject.OleInvoiceItem;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
28  import org.kuali.ole.sys.businessobject.TargetAccountingLine;
29  import org.kuali.ole.sys.context.SpringContext;
30  import org.kuali.ole.sys.service.UniversityDateService;
31  import org.kuali.rice.kew.api.exception.WorkflowException;
32  import org.kuali.rice.kim.api.identity.Person;
33  import org.kuali.rice.kim.api.identity.PersonService;
34  import org.kuali.rice.krad.service.DocumentHeaderService;
35  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
36  import org.kuali.rice.krad.util.GlobalVariables;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  public class OleDistributionOfIncomeAndExpenseDocument extends DistributionOfIncomeExpenseDocument {
42  
43  
44      private List<OleDistributionOfSourceIncomeAndExpenseAccountingLineBase> oleDistributionOfSourceIncomeAndExpenseAccountingLineBase = new ArrayList<>();
45  
46      private List<OleDistributionOfTargetIncomeAndExpenseAccountingLineBase> oleDistributionOfTargetIncomeAndExpenseAccountingLineBase = new ArrayList<>();
47  
48      public List<OleDistributionOfSourceIncomeAndExpenseAccountingLineBase> getOleDistributionOfSourceIncomeAndExpenseAccountingLineBase() {
49          return oleDistributionOfSourceIncomeAndExpenseAccountingLineBase;
50      }
51  
52      public void setOleDistributionOfSourceIncomeAndExpenseAccountingLineBase(List<OleDistributionOfSourceIncomeAndExpenseAccountingLineBase> oleDistributionOfSourceIncomeAndExpenseAccountingLineBase) {
53          this.oleDistributionOfSourceIncomeAndExpenseAccountingLineBase = oleDistributionOfSourceIncomeAndExpenseAccountingLineBase;
54      }
55  
56      public List<OleDistributionOfTargetIncomeAndExpenseAccountingLineBase> getOleDistributionOfTargetIncomeAndExpenseAccountingLineBase() {
57          return oleDistributionOfTargetIncomeAndExpenseAccountingLineBase;
58      }
59  
60      public void setOleDistributionOfTargetIncomeAndExpenseAccountingLineBase(List<OleDistributionOfTargetIncomeAndExpenseAccountingLineBase> oleDistributionOfTargetIncomeAndExpenseAccountingLineBase) {
61          this.oleDistributionOfTargetIncomeAndExpenseAccountingLineBase = oleDistributionOfTargetIncomeAndExpenseAccountingLineBase;
62      }
63  
64      private String availableBalance;
65  
66      private String chartOfAccountsCode;
67  
68      public String getAvailableBalance() {
69          return availableBalance;
70      }
71  
72      public void setAvailableBalance(String availableBalance) {
73          this.availableBalance = availableBalance;
74      }
75  
76      public String getChartOfAccountsCode() {
77          return chartOfAccountsCode;
78      }
79  
80      public void setChartOfAccountsCode(String chartOfAccountsCode) {
81          this.chartOfAccountsCode = chartOfAccountsCode;
82      }
83  
84     /* private boolean balanceInquiry;
85  
86      public boolean isBalanceInquiry() {
87          return balanceInquiry;
88      }
89  
90      public void setBalanceInquiry(boolean balanceInquiry) {
91          this.balanceInquiry = balanceInquiry;
92      }*/
93  
94      /**
95       * Provides answers to the following splits: HasVendorDepositAccount
96       *
97       * @see org.kuali.ole.sys.document.FinancialSystemTransactionalDocumentBase#answerSplitNodeQuestion(java.lang.String)
98       */
99      @Override
100     public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
101         if (nodeName.equals(OLEConstants.HAS_VENDOR_DEPOSIT_ACCOUNT)) {
102             return hasVendorDepositAccount();
103         }
104         throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
105     }
106 
107     private boolean hasVendorDepositAccount() {
108         List<SourceAccountingLine> sourceAccounts = this.getSourceAccountingLines();
109         List<TargetAccountingLine> targetAccounts = this.getTargetAccountingLines();
110         for (SourceAccountingLine sourceAccount : sourceAccounts) {
111             if (sourceAccount.getAccount().getSubFundGroupCode().equalsIgnoreCase(OLEConstants.CLEARING_ACCOUNT_CODE)) {
112                 return true;
113             }
114         }
115         for (TargetAccountingLine targetAccount : targetAccounts) {
116             if (targetAccount.getAccount().getSubFundGroupCode().equalsIgnoreCase(OLEConstants.CLEARING_ACCOUNT_CODE)) {
117                 return true;
118             }
119         }
120         return false;
121     }
122 
123     public void initiateDocument(OLEDistributionOfIncomeAndExpenseForm form) throws WorkflowException {
124         if (this.getDocumentHeader().getDocumentNumber() == null) {
125             this.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(getDocumentNumber()));
126         }
127 
128        // Document doc = olekradTransactionalForm.getDocument();
129         //  Document doc = getDocumentService().getNewDocument(form.getDocTypeName());
130 
131 
132         //  form.setDocTypeName(doc.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
133         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
134         this.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(this.getDocumentNumber(), principalPerson));
135         form.setDocTypeName(this.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
136        /* List sourceAccountLineList = new ArrayList();
137         sourceAccountLineList.add(new SourceAccountingLine());
138         this.setSourceAccountingLines(new ArrayList(new SourceAccountingLine);*/
139 
140         form.setDocument(this);
141        // super.initiateDocument();
142         /*OleInvoiceItem item;
143         this.setUseTaxIndicator(false);
144         String[] collapseSections = getOleInvoiceService().getDefaultCollapseSections();
145         this.setOverviewFlag(getOleInvoiceService().canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
146         this.setVendorInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.VENDOR_INFO_SECTION, collapseSections));
147         this.setInvoiceInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.INVOICE_INFO_SECTION, collapseSections));
148         this.setProcessTitlesFlag(getOleInvoiceService().canCollapse(OLEConstants.PROCESS_TITLES_SECTION, collapseSections));
149         this.setCurrentItemsFlag(getOleInvoiceService().canCollapse(OLEConstants.CURRENT_ITEM_SECTION, collapseSections));
150         this.setAdditionalChargesFlag(getOleInvoiceService().canCollapse(OLEConstants.ADDITIONAL_CHARGES_SECTION, collapseSections));
151         this.setAccountSummaryFlag(getOleInvoiceService().canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION, collapseSections));
152         this.setAdHocRecipientsFlag(getOleInvoiceService().canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION, collapseSections));
153         this.setRouteLogFlag(getOleInvoiceService().canCollapse(OLEConstants.ROUTE_LOG_SECTION, collapseSections));
154         this.setNotesAndAttachmentFlag(getOleInvoiceService().canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
155 
156         if (this.getItems() == null || this.getItems().size() == 0) {
157             this.items = new ArrayList<>();
158             SpringContext.getBean(PurapService.class).addBelowLineItems(this);
159             List<OleInvoiceItem> oleInvItems = this.getItems();
160             for (OleInvoiceItem oleInvoiceItem : oleInvItems) {
161                 oleInvoiceItem.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate().getUniversityFiscalYear());
162             }
163         }*/
164     }
165 }