1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
85
86
87
88
89
90
91
92
93
94
95
96
97
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
129
130
131
132
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
137
138
139
140 form.setDocument(this);
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 }
165 }