use of edu.cornell.kfs.gl.batch.service.ReversionCategoryLogic in project cu-kfs by CU-CommunityApps.
the class AccountReversionServiceImpl method getCategories.
/**
* @see org.kuali.kfs.coa.service.OrganizationReversionService#getCategories()
*/
public Map<String, ReversionCategoryLogic> getCategories() {
LOG.debug("getCategories() started");
Map<String, ReversionCategoryLogic> categories = new HashMap<String, ReversionCategoryLogic>();
Collection cats = accountReversionDao.getCategories();
for (Iterator iter = cats.iterator(); iter.hasNext(); ) {
ReversionCategory rc = (ReversionCategory) iter.next();
String categoryCode = rc.getReversionCategoryCode();
Map<String, ReversionCategoryLogic> beanMap = SpringContext.getBeansOfType(ReversionCategoryLogic.class);
if (beanMap.containsKey("gl" + categoryCode + "AccountReversionCategory")) {
LOG.info("Found Account Reversion Category Logic for gl" + categoryCode + "AccountReversionCategory");
categories.put(categoryCode, beanMap.get("gl" + categoryCode + "AccountReversionCategory"));
} else {
LOG.info("No Account Reversion Category Logic for gl" + categoryCode + "AccountReversionCategory; using generic");
GenericReversionCategory cat = SpringContext.getBean(GenericReversionCategory.class);
cat.setCategoryCode(categoryCode);
cat.setCategoryName(rc.getReversionCategoryName());
categories.put(categoryCode, (ReversionCategoryLogic) cat);
}
}
return categories;
}
use of edu.cornell.kfs.gl.batch.service.ReversionCategoryLogic in project cu-kfs by CU-CommunityApps.
the class ReversionProcessBase method calculateTotals.
public void calculateTotals() throws FatalErrorException {
/*
* How this works: At the start, in the clearCalculationTotals(), both the unit of work's totalAvailable and totalReversion
* are set to the available amounts from each of the category amounts. Then, as the logic is applied, the totalCarryForward
* is added to and the totalReversion is subtracted from. Let's look at a simple example: Let's say you've got an amount for
* C01, which has $2000 available, no encumbrances, that's all you've got. This means that at the end of
* clearCalculationTotals(), there's $2000 in totalAvailable, $2000 in totalReversion, and $0 in totalCarryForward. Now, C01,
* let's say, is for code A. So, look below at the if that catches Code A. You'll note that it adds the available amount to
* totalCarryForward, it's own carryForward, the negated available to totalReversion, and that, done, it sets available to
* $0. With our example, that means that $2000 is in totalCarryForward (and in the amount's carryForward), the
* totalReversion has been knocked down to $0, and the available is $0. So, carry forward origin entries get created, and
* reversions do not. This is also why you don't see a block about calculating R2 totals below...the process has a natural
* inclination towards creating R2 (ie, ignore encumbrances and revert all available) entries.
*/
// clear out the unit of work totals we're going to calculate values in, in preperation for applying rules
clearCalculationTotals();
// For each category, apply the rules
for (ReversionCategory category : categoryList) {
String categoryCode = category.getReversionCategoryCode();
ReversionCategoryLogic logic = categories.get(categoryCode);
ReversionUnitOfWorkCategoryAmount amount = unitOfWork.amounts.get(categoryCode);
ReversionCategoryInfo detail = cfReversionProcessInfo.getReversionDetail(categoryCode);
if (detail == null) {
throw new FatalErrorException(" Reversion " + cfReversionProcessInfo.getUniversityFiscalYear() + "-" + cfReversionProcessInfo.getChartOfAccountsCode() + "-" + cfReversionProcessInfo.getSourceAttribute() + " does not have a detail for category " + categoryCode);
}
String ruleCode = detail.getReversionCode();
// if (LOG.isDebugEnabled()) {
LOG.info("Unit of Work: " + unitOfWork.getChartOfAccountsCode() + unitOfWork.getAccountNumber() + unitOfWork.getSubAccountNumber() + ", category " + category.getReversionCategoryName() + ": budget = " + amount.getBudget() + "; actual = " + amount.getActual() + "; encumbrance = " + amount.getEncumbrance() + "; available = " + amount.getAvailable() + "; apply rule code " + ruleCode);
// xe
if (KFSConstants.RULE_CODE_R1.equals(ruleCode) || KFSConstants.RULE_CODE_N1.equals(ruleCode) || KFSConstants.RULE_CODE_C1.equals(ruleCode)) {
if (amount.getAvailable().compareTo(KualiDecimal.ZERO) > 0) {
// do we have budget left?
if (amount.getAvailable().compareTo(amount.getEncumbrance()) > 0) {
// is it more than enough to cover our
// encumbrances?
unitOfWork.addTotalCarryForward(amount.getEncumbrance());
amount.addCarryForward(amount.getEncumbrance());
unitOfWork.addTotalReversion(amount.getEncumbrance().negated());
amount.addAvailable(amount.getEncumbrance().negated());
} else {
// there's not enough available left to cover the encumbrances; cover what we can
unitOfWork.addTotalCarryForward(amount.getAvailable());
amount.addCarryForward(amount.getAvailable());
unitOfWork.addTotalReversion(amount.getAvailable().negated());
amount.setAvailable(KualiDecimal.ZERO);
}
}
}
// Check this in the debugger to see if this is the right amt to get..
if (CUKFSConstants.RULE_CODE_CA.equals(ruleCode)) {
// just gonna break this right here...amount.
// unitOfWork.addTotalCash(amount.getAvailable());
// amount.addActual(amount.getAvailable());
// unitOfWork.addTotalReversion(amount.getAvailable().negated());
// amount.setAvailable(KualiDecimal.ZERO);
}
// xa
if (KFSConstants.RULE_CODE_A.equals(ruleCode)) {
unitOfWork.addTotalCarryForward(amount.getAvailable());
amount.addCarryForward(amount.getAvailable());
unitOfWork.addTotalReversion(amount.getAvailable().negated());
amount.setAvailable(KualiDecimal.ZERO);
}
// xp
if (KFSConstants.RULE_CODE_C1.equals(ruleCode) || KFSConstants.RULE_CODE_C2.equals(ruleCode)) {
if (amount.getAvailable().compareTo(KualiDecimal.ZERO) > 0) {
unitOfWork.addTotalCarryForward(amount.getAvailable());
amount.addCarryForward(amount.getAvailable());
unitOfWork.addTotalReversion(amount.getAvailable().negated());
amount.setAvailable(KualiDecimal.ZERO);
}
}
// xn
if (KFSConstants.RULE_CODE_N1.equals(ruleCode) || KFSConstants.RULE_CODE_N2.equals(ruleCode)) {
if (amount.getAvailable().compareTo(KualiDecimal.ZERO) < 0) {
unitOfWork.addTotalCarryForward(amount.getAvailable());
amount.addCarryForward(amount.getAvailable());
unitOfWork.addTotalReversion(amount.getAvailable().negated());
amount.setAvailable(KualiDecimal.ZERO);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Totals Now: " + unitOfWork.getChartOfAccountsCode() + unitOfWork.getAccountNumber() + unitOfWork.getSubAccountNumber() + ", total cash now " + unitOfWork.getTotalCash() + ": total available = " + unitOfWork.getTotalAvailable() + "; total reversion = " + unitOfWork.getTotalReversion() + "; total carry forward = " + unitOfWork.getTotalCarryForward());
}
}
}
use of edu.cornell.kfs.gl.batch.service.ReversionCategoryLogic in project cu-kfs by CU-CommunityApps.
the class AccountReversionServiceImplTest method testGetCategories.
public void testGetCategories() {
ReversionCategory goodReversionCategory = ReversionCategoryFixture.A1_CATEGORY.createReversionCategory();
Map<String, ReversionCategoryLogic> results = accountReversionService.getCategories();
assertTrue("categories should not be empty", results.size() > 0);
assertTrue(results.containsKey(goodReversionCategory.getReversionCategoryCode()));
assertEquals(goodReversionCategory.getReversionCategoryName(), results.get(goodReversionCategory.getReversionCategoryCode()).getName());
}
use of edu.cornell.kfs.gl.batch.service.ReversionCategoryLogic in project cu-kfs by CU-CommunityApps.
the class ReversionProcessBase method clearCalculationTotals.
protected void clearCalculationTotals() {
// Initialize all the amounts before applying the proper rule
KualiDecimal totalAvailable = KualiDecimal.ZERO;
for (ReversionCategory category : categoryList) {
ReversionCategoryLogic logic = categories.get(category.getReversionCategoryCode());
ReversionUnitOfWorkCategoryAmount amount = unitOfWork.amounts.get(category.getReversionCategoryCode());
if (logic.isExpense()) {
amount.setAvailable(amount.getBudget().subtract(amount.getActual()));
} else {
amount.setAvailable(amount.getActual().subtract(amount.getBudget()));
}
totalAvailable = totalAvailable.add(amount.getAvailable());
amount.setCarryForward(KualiDecimal.ZERO);
}
unitOfWork.setTotalAvailable(totalAvailable);
unitOfWork.setTotalReversion(totalAvailable);
unitOfWork.setTotalCarryForward(KualiDecimal.ZERO);
}
Aggregations