001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.financial.service;
017:
018: import java.util.List;
019:
020: import org.kuali.core.util.GlobalVariables;
021: import org.kuali.core.util.KualiDecimal;
022: import org.kuali.kfs.bo.AccountingLine;
023: import org.kuali.kfs.bo.SourceAccountingLine;
024: import org.kuali.kfs.context.KualiTestBase;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.module.financial.bo.DisbursementVoucherNonResidentAlienTax;
027: import org.kuali.module.financial.bo.DisbursementVoucherPayeeDetail;
028: import org.kuali.module.financial.document.DisbursementVoucherDocument;
029: import org.kuali.test.ConfigureContext;
030:
031: /**
032: * This class tests the DisbursementVoucherTax service.
033: */
034: @ConfigureContext
035: public class DisbursementVoucherTaxServiceTest extends KualiTestBase {
036: private DisbursementVoucherDocument dvDocument;
037:
038: @Override
039: protected void setUp() throws Exception {
040: super .setUp();
041: dvDocument = new DisbursementVoucherDocument();
042: dvDocument
043: .setDvPayeeDetail(new DisbursementVoucherPayeeDetail());
044: dvDocument
045: .setDvNonResidentAlienTax(new DisbursementVoucherNonResidentAlienTax());
046: dvDocument.getDvPayeeDetail().setDisbVchrAlienPaymentCode(true);
047:
048: AccountingLine line = new SourceAccountingLine();
049: line.setChartOfAccountsCode("UA");
050: line.setAccountNumber("1912610");
051: line.setFinancialObjectCode("5000");
052: line.setAmount(new KualiDecimal(100));
053: line.setSequenceNumber(new Integer(1));
054:
055: dvDocument.getSourceAccountingLines().add(line);
056: dvDocument.setNextSourceLineNumber(new Integer(2));
057: }
058:
059: /**
060: * Test validation of nra information before generation of lines
061: *
062: * @throws Exception
063: */
064: public void testValidateNRA() throws Exception {
065: // check tax is not created for attributes that it should not be generated for
066: dvDocument.setDisbVchrCheckTotalAmount(new KualiDecimal(100));
067: dvDocument.getDvNonResidentAlienTax()
068: .setFederalIncomeTaxPercent(new KualiDecimal(0));
069: dvDocument.getDvNonResidentAlienTax().setStateIncomeTaxPercent(
070: new KualiDecimal(0));
071:
072: // should not be generated for non-reportable
073: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("N");
074: SpringContext.getBean(DisbursementVoucherTaxService.class)
075: .processNonResidentAlienTax(dvDocument);
076: List newTaxNumbers = SpringContext
077: .getBean(DisbursementVoucherTaxService.class)
078: .getNRATaxLineNumbers(
079: dvDocument
080: .getDvNonResidentAlienTax()
081: .getFinancialDocumentAccountingLineText());
082: assertTrue(newTaxNumbers.isEmpty());
083: assertTrue(GlobalVariables.getErrorMap().size() == 1);
084: GlobalVariables.getErrorMap().clear();
085:
086: // should not be generated for foreign source
087: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
088: dvDocument.getDvNonResidentAlienTax()
089: .setForeignSourceIncomeCode(true);
090: SpringContext.getBean(DisbursementVoucherTaxService.class)
091: .processNonResidentAlienTax(dvDocument);
092: newTaxNumbers = SpringContext
093: .getBean(DisbursementVoucherTaxService.class)
094: .getNRATaxLineNumbers(
095: dvDocument
096: .getDvNonResidentAlienTax()
097: .getFinancialDocumentAccountingLineText());
098: assertTrue(newTaxNumbers.isEmpty());
099: assertTrue(GlobalVariables.getErrorMap().size() == 1);
100: GlobalVariables.getErrorMap().clear();
101:
102: // should not be generated for treatly exempt
103: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
104: dvDocument.getDvNonResidentAlienTax()
105: .setForeignSourceIncomeCode(false);
106: dvDocument.getDvNonResidentAlienTax()
107: .setIncomeTaxTreatyExemptCode(true);
108: SpringContext.getBean(DisbursementVoucherTaxService.class)
109: .processNonResidentAlienTax(dvDocument);
110: newTaxNumbers = SpringContext
111: .getBean(DisbursementVoucherTaxService.class)
112: .getNRATaxLineNumbers(
113: dvDocument
114: .getDvNonResidentAlienTax()
115: .getFinancialDocumentAccountingLineText());
116: assertTrue(newTaxNumbers.isEmpty());
117: assertTrue(GlobalVariables.getErrorMap().size() == 1);
118: GlobalVariables.getErrorMap().clear();
119:
120: // should not be generated for doc reference is given
121: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
122: dvDocument.getDvNonResidentAlienTax()
123: .setForeignSourceIncomeCode(false);
124: dvDocument.getDvNonResidentAlienTax()
125: .setIncomeTaxTreatyExemptCode(false);
126: dvDocument.getDvNonResidentAlienTax()
127: .setReferenceFinancialDocumentNumber("foo");
128: SpringContext.getBean(DisbursementVoucherTaxService.class)
129: .processNonResidentAlienTax(dvDocument);
130: newTaxNumbers = SpringContext
131: .getBean(DisbursementVoucherTaxService.class)
132: .getNRATaxLineNumbers(
133: dvDocument
134: .getDvNonResidentAlienTax()
135: .getFinancialDocumentAccountingLineText());
136: assertTrue(newTaxNumbers.isEmpty());
137: assertTrue(GlobalVariables.getErrorMap().size() == 1);
138: GlobalVariables.getErrorMap().clear();
139:
140: // should not be generated if check amount is 0
141: dvDocument.setDisbVchrCheckTotalAmount(new KualiDecimal(0));
142: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
143: dvDocument.getDvNonResidentAlienTax()
144: .setForeignSourceIncomeCode(false);
145: dvDocument.getDvNonResidentAlienTax()
146: .setIncomeTaxTreatyExemptCode(false);
147: dvDocument.getDvNonResidentAlienTax()
148: .setReferenceFinancialDocumentNumber("");
149: SpringContext.getBean(DisbursementVoucherTaxService.class)
150: .processNonResidentAlienTax(dvDocument);
151: newTaxNumbers = SpringContext
152: .getBean(DisbursementVoucherTaxService.class)
153: .getNRATaxLineNumbers(
154: dvDocument
155: .getDvNonResidentAlienTax()
156: .getFinancialDocumentAccountingLineText());
157: assertTrue(newTaxNumbers.isEmpty());
158: assertTrue(GlobalVariables.getErrorMap().size() == 1);
159: GlobalVariables.getErrorMap().clear();
160:
161: }
162:
163: /**
164: * Test generation and clearing of nra tax lines.
165: */
166: public void testGenerateNRATaxLines() {
167: KualiDecimal orginalCheckAmount = new KualiDecimal(100);
168: dvDocument.setDisbVchrCheckTotalAmount(new KualiDecimal(100));
169: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
170: dvDocument.getDvNonResidentAlienTax()
171: .setForeignSourceIncomeCode(false);
172: dvDocument.getDvNonResidentAlienTax()
173: .setIncomeTaxTreatyExemptCode(false);
174: dvDocument.getDvNonResidentAlienTax()
175: .setReferenceFinancialDocumentNumber("");
176: dvDocument.getDvNonResidentAlienTax()
177: .setFederalIncomeTaxPercent(new KualiDecimal(14));
178: dvDocument.getDvNonResidentAlienTax().setStateIncomeTaxPercent(
179: new KualiDecimal(3.4));
180: dvDocument.getDvNonResidentAlienTax().setPostalCountryCode(
181: "USA");
182:
183: SpringContext.getBean(DisbursementVoucherTaxService.class)
184: .processNonResidentAlienTax(dvDocument);
185: List newTaxNumbers = SpringContext
186: .getBean(DisbursementVoucherTaxService.class)
187: .getNRATaxLineNumbers(
188: dvDocument
189: .getDvNonResidentAlienTax()
190: .getFinancialDocumentAccountingLineText());
191: assertTrue(newTaxNumbers.size() == 2);
192: assertTrue(newTaxNumbers.get(0).equals(new Integer(2)));
193: assertTrue(newTaxNumbers.get(1).equals(new Integer(3)));
194: assertTrue(dvDocument.getNextSourceLineNumber().equals(
195: new Integer(4)));
196: assertTrue(dvDocument.getSourceAccountingLines().size() == 3);
197:
198: // test clearning
199: SpringContext.getBean(DisbursementVoucherTaxService.class)
200: .clearNRATaxLines(dvDocument);
201: assertEquals(1, dvDocument.getSourceAccountingLines().size());
202: assertEquals("Check total credited correctly",
203: new KualiDecimal(100), dvDocument
204: .getDisbVchrCheckTotalAmount());
205: assertEquals("Source total does not match check total",
206: new KualiDecimal(100), dvDocument.getSourceTotal());
207:
208: SpringContext.getBean(DisbursementVoucherTaxService.class)
209: .processNonResidentAlienTax(dvDocument);
210: newTaxNumbers = SpringContext
211: .getBean(DisbursementVoucherTaxService.class)
212: .getNRATaxLineNumbers(
213: dvDocument
214: .getDvNonResidentAlienTax()
215: .getFinancialDocumentAccountingLineText());
216: assertTrue(newTaxNumbers.size() == 2);
217: assertTrue(newTaxNumbers.get(0).equals(new Integer(4)));
218: assertTrue(newTaxNumbers.get(1).equals(new Integer(5)));
219: assertTrue(dvDocument.getNextSourceLineNumber().equals(
220: new Integer(6)));
221: assertEquals(3, dvDocument.getSourceAccountingLines().size());
222:
223: // validate debit of check total amount and accounting lines
224: assertEquals("Check total not debited correctly",
225: new KualiDecimal(82.6), dvDocument
226: .getDisbVchrCheckTotalAmount());
227: assertEquals("Source total does not match check total",
228: new KualiDecimal(82.6), dvDocument.getSourceTotal());
229: SpringContext.getBean(DisbursementVoucherTaxService.class)
230: .clearNRATaxLines(dvDocument);
231: }
232:
233: /**
234: * Tests correct calculation of gross up amounts
235: */
236: public void testGrossUp() {
237: dvDocument.getDvNonResidentAlienTax().setIncomeClassCode("F");
238: dvDocument.getDvNonResidentAlienTax()
239: .setForeignSourceIncomeCode(false);
240: dvDocument.getDvNonResidentAlienTax()
241: .setIncomeTaxTreatyExemptCode(false);
242: dvDocument.getDvNonResidentAlienTax()
243: .setReferenceFinancialDocumentNumber("");
244: dvDocument.getDvNonResidentAlienTax().setPostalCountryCode(
245: "USA");
246: dvDocument.getDvNonResidentAlienTax().setIncomeTaxGrossUpCode(
247: true);
248:
249: runGrossUpTest(new KualiDecimal(100), new KualiDecimal(14),
250: new KualiDecimal(3.4));
251: runGrossUpTest(new KualiDecimal(50.55), new KualiDecimal(14),
252: new KualiDecimal(3.4));
253: runGrossUpTest(new KualiDecimal(10), new KualiDecimal(14),
254: new KualiDecimal(3.4));
255: runGrossUpTest(new KualiDecimal(12.82), new KualiDecimal(14),
256: new KualiDecimal(3.4));
257: runGrossUpTest(new KualiDecimal(12.83), new KualiDecimal(14),
258: new KualiDecimal(3.4));
259: runGrossUpTest(new KualiDecimal(12.84), new KualiDecimal(14),
260: new KualiDecimal(3.4));
261: runGrossUpTest(new KualiDecimal(8456234.23), new KualiDecimal(
262: 14), new KualiDecimal(3.4));
263: }
264:
265: private void runGrossUpTest(KualiDecimal checkAmount,
266: KualiDecimal federalTax, KualiDecimal stateTax) {
267: dvDocument.setDisbVchrCheckTotalAmount(checkAmount);
268: dvDocument.getSourceAccountingLine(0).setAmount(checkAmount);
269: dvDocument.getDvNonResidentAlienTax()
270: .setFederalIncomeTaxPercent(federalTax);
271: dvDocument.getDvNonResidentAlienTax().setStateIncomeTaxPercent(
272: stateTax);
273:
274: SpringContext.getBean(DisbursementVoucherTaxService.class)
275: .processNonResidentAlienTax(dvDocument);
276: List newTaxNumbers = SpringContext
277: .getBean(DisbursementVoucherTaxService.class)
278: .getNRATaxLineNumbers(
279: dvDocument
280: .getDvNonResidentAlienTax()
281: .getFinancialDocumentAccountingLineText());
282: assertTrue(newTaxNumbers.size() == 3);
283: assertEquals("Check total does not match original amount",
284: checkAmount, dvDocument.getDisbVchrCheckTotalAmount());
285: assertEquals("Source total does not match original amount",
286: checkAmount, dvDocument.getSourceTotal());
287: SpringContext.getBean(DisbursementVoucherTaxService.class)
288: .clearNRATaxLines(dvDocument);
289: }
290: }
|