1 /*
2 * The Kuali Financial System, a comprehensive financial management system for higher education.
3 *
4 * Copyright 2005-2014 The Kuali Foundation
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package org.kuali.kfs.module.tem.document.validation.impl;
20
21 import org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase;
22 import org.kuali.kfs.module.tem.businessobject.PerDiem;
23 import org.kuali.rice.core.api.util.type.KualiDecimal;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.krad.document.Document;
26
27 /**
28 * Business Prerules applicable to Per Diem documents. These PreRules checks that the Per Diem totals match.
29 */
30 public class PerDiemDocumentPreRules extends MaintenancePreRulesBase {
31
32
33 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PerDiemDocumentPreRules.class);
34
35 protected PerDiem newPerDiem;
36
37 /**
38 * Sets up a convenience object and few other vendor attributes
39 *
40 * @see org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
41 */
42 @Override
43 protected boolean doCustomPreRules(MaintenanceDocument document) {
44 setupConvenienceObjects(document);
45 checkTotals(document);
46 return true;
47 }
48
49 /**
50 * Sets the convenience objects like newPerDiem and oldPerDiem, so you have short and easy handles to the new and old
51 * objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load all
52 * sub-objects from the DB by their primary keys, if available.
53 *
54 * @param document - the maintenanceDocument being evaluated
55 */
56 protected void setupConvenienceObjects(MaintenanceDocument document) {
57 // setup newPerDiem convenience objects, make sure all possible sub-objects are populated
58 newPerDiem = (PerDiem) document.getNewMaintainableObject().getBusinessObject();
59 }
60
61 /**
62 * Checks if the B+L+D+IE total does not match Meal+Incidentals total
63 *
64 * @param document - per diem document
65 */
66 public void checkTotals(Document document) {
67 boolean proceed = true;
68
69 KualiDecimal total = newPerDiem.getBreakfast();
70 total = total.add(newPerDiem.getLunch());
71 total = total.add(newPerDiem.getDinner());
72 total = total.add(newPerDiem.getIncidentals());
73
74 if(!total.equals(newPerDiem.getMealsAndIncidentals()))
75 {
76 proceed = askOrAnalyzeYesNoQuestion("mealsAndIncidentals", "Warning: Breakfast, Lunch, Dinner, and Incidentals total do not match Meals and Incidentals. Would you like to proceed anyway?");
77 if (!proceed) {
78 abortRulesCheck();
79 }
80 }
81 }
82 }