001: /*
002: * Copyright 2005-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.rules;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.kuali.core.document.MaintenanceDocument;
020: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
021: import org.kuali.core.service.KualiConfigurationService;
022: import org.kuali.core.util.GlobalVariables;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.kfs.KFSKeyConstants;
025: import org.kuali.kfs.KFSPropertyConstants;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.financial.bo.Payee;
028: import org.kuali.module.financial.service.DisbursementVoucherTaxService;
029:
030: /**
031: * Business rules for the Payee maintenance document.
032: */
033: public class PayeeDocumentRule extends MaintenanceDocumentRuleBase
034: implements DisbursementVoucherRuleConstants {
035:
036: /**
037: * This method performs custom route business rule checks on the document being routed. The rules include
038: * checking the tax id number and the presense of all required fields for the associated Payee instance.
039: *
040: * @param document The document being routed.
041: * @return True if all the business rules pass, false otherwise.
042: *
043: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules
044: */
045: @Override
046: public boolean processCustomRouteDocumentBusinessRules(
047: MaintenanceDocument maintenanceDocument) {
048: Payee payee = (Payee) maintenanceDocument
049: .getNewMaintainableObject().getBusinessObject();
050:
051: checkTaxIDNumber(payee);
052: checkRequiredFields(payee);
053:
054: // Payment reason not passed in payee maintenance document, no checks for required tax id number
055: //
056: // 1-1 if ($$curr_state = $$screate | $$curr_state = $$snew)
057: // 2-2 if ($new_payee$)
058: // 3-2 $$error_message = "A new payee ID number has already been created."
059: // 4-2 call fp_final_errmsg
060: // 5-2 return $$failure
061: // 6-2 else
062: // 7-2 run "fp_h0072"
063: // 8-3 if ($status = $$success)
064: // 9-3 dv_payee_id_nbr.fp_dv_pend_payee_t = $1
065: // 10-4 if(dv_payee_cntry_nm.fp_dv_pend_payee_t = "")
066: // 11-4 dv_payee_cntry_nm.fp_dv_pend_payee_t = "USA"
067: // 12-4 endif
068: // 13-3 dv_payee_entry_dt.fp_dv_pend_payee_t = $$today
069: // 14-3 dv_taxctrl_mdfy_dt.fp_dv_pend_payee_t = $$today
070: // 15-3 $new_payee$ = $$true
071: // 16-3 endif
072: // 17-2 endif
073: //
074: //
075: //
076: // ;Only people in DV_TAXGRP can update controls and tax code
077: // sql "select fs_work_grp_id from fs_work_grp_usr_t where person_unvl_id %\
078: // = '%%$$universal_id' and fs_work_grp_id = 'DV_TAXGRP'","DEF"
079: // if ($status = 0)
080: // field_syntax dv_payee_txctrl_cd.fp_dv_pend_payee_t, "NED,NPR"
081: // field_video dv_payee_txctrl_cd.fp_dv_pend_payee_t, "COL=27"
082: // field_syntax dv_payee_tax_cd.fp_dv_pend_payee_t, "NED,NPR"
083: // field_video dv_payee_tax_cd.fp_dv_pend_payee_t, "COL=27"
084:
085: return GlobalVariables.getErrorMap().isEmpty();
086: }
087:
088: /**
089: * Checks that the given tax id number is not being used for another payee, vendor, or employee. This method
090: * posts errors to the error map, but does not otherwise indicate any problems occurred.
091: *
092: * @param payee The payee whose tax id number will be validated.
093: */
094: private void checkTaxIDNumber(Payee payee) {
095: DisbursementVoucherTaxService taxIDService = SpringContext
096: .getBean(DisbursementVoucherTaxService.class);
097: KualiConfigurationService kualiConfigurationService = SpringContext
098: .getBean(KualiConfigurationService.class);
099:
100: String taxIDNumber = payee.getTaxIdNumber();
101: String taxIDType = payee.getTaxpayerTypeCode();
102: Integer foundType = null;
103:
104: if (StringUtils.isNotBlank(taxIDNumber)
105: && StringUtils.isNotBlank(taxIDType)) {
106: String institutionFeinNumber = kualiConfigurationService
107: .getPropertyString(KFSKeyConstants.INSTITUTION_TAX_FEIN_NUMBER);
108: if (taxIDNumber.equals(institutionFeinNumber)
109: && TAX_TYPE_FEIN.equals(taxIDType)) {
110: putFieldError(KFSPropertyConstants.TAX_ID_NUMBER,
111: KFSKeyConstants.ERROR_FOUND_TAX_ID_INSTITUTION);
112: } else {
113: // vendor
114: String vendorId = taxIDService.getVendorId(taxIDNumber,
115: taxIDType);
116: if (vendorId != null) {
117: putFieldError(KFSPropertyConstants.TAX_ID_NUMBER,
118: KFSKeyConstants.ERROR_FOUND_TAX_ID_VENDOR,
119: vendorId);
120: } else {
121: // payee
122: String payeeId = taxIDService.getPayeeId(
123: taxIDNumber, taxIDType);
124: if (payeeId != null
125: && !payee.getPayeeIdNumber()
126: .equals(payeeId)) {
127: putFieldError(
128: KFSPropertyConstants.TAX_ID_NUMBER,
129: KFSKeyConstants.ERROR_FOUND_TAX_ID_PAYEE,
130: payeeId);
131: } else {
132: // pending payee
133: String pendingPayeeId = taxIDService
134: .getPendingPayeeId(taxIDNumber,
135: taxIDType);
136: if (pendingPayeeId != null
137: && !payee.getPayeeIdNumber().equals(
138: pendingPayeeId)) {
139: putFieldError(
140: KFSPropertyConstants.TAX_ID_NUMBER,
141: KFSKeyConstants.ERROR_FOUND_TAX_ID_PEND_PAYEE,
142: pendingPayeeId);
143: } else {
144: // employee
145: String universalId = taxIDService
146: .getUniversalId(taxIDNumber,
147: taxIDType);
148: if (universalId != null) {
149: if (!payee.isPayeeEmployeeCode()) {
150: putFieldError(
151: KFSPropertyConstants.TAX_ID_NUMBER,
152: KFSKeyConstants.ERROR_FOUND_TAX_ID_EMPL);
153: }
154: }
155: /* employee flag can only be selected if it really is an employee */
156: else if (payee.isPayeeEmployeeCode()) {
157: putFieldError(
158: KFSPropertyConstants.PAYEE_EMPLOYEE_CODE,
159: KFSKeyConstants.ERROR_EMPL_FLAG);
160: }
161: }
162: }
163: }
164: }
165: }
166: }
167:
168: /**
169: * Checks conditional required fields. The required fields being checked for are:
170: * <ul>
171: * <li>tax type code (only required if a tax id number is present)</li>
172: * <li>employee flag (only required if SSN is present)</li>
173: * <li>city, state and zip fields populated (only required if country is US)</li>
174: * <li>alien flag (only required if payee is an individual, not a company or other entity)</li>
175: * </ul>
176: *
177: * @param payee
178: */
179: private void checkRequiredFields(Payee payee) {
180:
181: /* check tax type code given if tax id number was given */
182: if (StringUtils.isNotBlank(payee.getTaxIdNumber())) {
183: if (StringUtils.isBlank(payee.getTaxpayerTypeCode())) {
184: putFieldError(KFSPropertyConstants.TAXPAYER_TYPE_CODE,
185: KFSKeyConstants.ERROR_TAX_TYPE_REQUIRED);
186: }
187: }
188:
189: /* employee flag can be checked only if ssn */
190: if (payee.isPayeeEmployeeCode()
191: && !TAX_TYPE_SSN.equals(payee.getTaxpayerTypeCode())) {
192: putFieldError(KFSPropertyConstants.PAYEE_EMPLOYEE_CODE,
193: KFSKeyConstants.ERROR_EMPL_FLAG_NOT_SSN);
194: }
195:
196: /* city, state & zip must be given for the US */
197: if (KFSConstants.COUNTRY_CODE_UNITED_STATES.equals(payee
198: .getPayeeCountryCode())) {
199: if (StringUtils.isBlank(payee.getPayeeCityName())) {
200: putFieldErrorWithShortLabel(
201: KFSPropertyConstants.PAYEE_CITY_NAME,
202: KFSKeyConstants.ERROR_REQUIRED_FOR_US);
203: }
204: if (StringUtils.isBlank(payee.getPayeeStateCode())) {
205: putFieldErrorWithShortLabel(
206: KFSPropertyConstants.PAYEE_STATE_CODE,
207: KFSKeyConstants.ERROR_REQUIRED_FOR_US);
208: }
209: if (StringUtils.isBlank(payee.getPayeeZipCode())) {
210: putFieldErrorWithShortLabel(
211: KFSPropertyConstants.PAYEE_ZIP_CODE,
212: KFSKeyConstants.ERROR_REQUIRED_FOR_US);
213: }
214: }
215:
216: /* alien indicator can only be checked for individuals */
217: if (payee.isAlienPaymentCode()
218: && !DisbursementVoucherDocumentRule.OWNERSHIP_TYPE_INDIVIDUAL
219: .equals(payee.getPayeeOwnershipTypCd())) {
220: putFieldError(KFSPropertyConstants.ALIEN_PAYMENT_CODE,
221: KFSKeyConstants.ERROR_DV_ALIEN_NOT_INDIVIDUAL);
222: }
223: }
224: }
|