use of edu.cornell.kfs.gl.businessobject.ReversionUnitOfWorkCategoryAmount 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.businessobject.ReversionUnitOfWorkCategoryAmount in project cu-kfs by CU-CommunityApps.
the class ReversionProcessBase method generateMany.
public void generateMany(List<OriginEntryFull> originEntriesToWrite) throws FatalErrorException {
int originEntriesCreated = 0;
for (Iterator<ReversionCategory> iter = categoryList.iterator(); iter.hasNext(); ) {
ReversionCategory cat = iter.next();
ReversionCategoryInfo detail = cfReversionProcessInfo.getReversionDetail(cat.getReversionCategoryCode());
ReversionUnitOfWorkCategoryAmount amount = unitOfWork.amounts.get(cat.getReversionCategoryCode());
if (!amount.getCarryForward().isZero()) {
KualiDecimal commonAmount = amount.getCarryForward();
String commonObject = detail.getReversionObjectCode();
OriginEntryFull entry = getEntry();
entry.setUniversityFiscalYear((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR) + 1);
entry.setChartOfAccountsCode(unitOfWork.chartOfAccountsCode);
entry.setAccountNumber(unitOfWork.accountNumber);
entry.setSubAccountNumber(unitOfWork.subAccountNumber);
entry.setFinancialObjectCode((String) jobParameters.get(KFSConstants.BEG_BUD_CASH_OBJECT_CD));
entry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
entry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_CURRENT_BUDGET);
getPersistenceService().retrieveReferenceObject(entry, KFSPropertyConstants.FINANCIAL_OBJECT);
if (ObjectUtils.isNull(entry.getFinancialObject())) {
throw new FatalErrorException("Object Code for Entry not found: " + entry);
}
ObjectCode objectCode = entry.getFinancialObject();
entry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
entry.setUniversityFiscalPeriodCode(KFSConstants.MONTH1);
entry.setDocumentNumber(DEFAULT_DOCUMENT_NUMBER_PREFIX + unitOfWork.accountNumber);
entry.setTransactionLedgerEntryDescription(FUND_CARRIED_MESSAGE + (Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR));
entry.setTransactionLedgerEntryAmount(commonAmount);
// 3259 MOVE TRN-LDGR-ENTR-AMT TO WS-AMT-W-PERIOD
// 3260 WS-AMT-N.
// 3261 MOVE WS-AMT-X TO TRN-AMT-RED-X.
originEntriesToWrite.add(entry);
entry = getEntry();
entry.setUniversityFiscalYear((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR) + 1);
entry.setChartOfAccountsCode(unitOfWork.chartOfAccountsCode);
entry.setAccountNumber(unitOfWork.accountNumber);
entry.setSubAccountNumber(unitOfWork.subAccountNumber);
entry.setFinancialObjectCode(commonObject);
entry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
entry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_CURRENT_BUDGET);
getPersistenceService().retrieveReferenceObject(entry, KFSPropertyConstants.FINANCIAL_OBJECT);
if (ObjectUtils.isNull(entry.getFinancialObject())) {
throw new FatalErrorException("Object Code for Entry not found: " + entry);
}
objectCode = entry.getFinancialObject();
entry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
entry.setUniversityFiscalPeriodCode(KFSConstants.MONTH1);
entry.setDocumentNumber(DEFAULT_DOCUMENT_NUMBER_PREFIX + unitOfWork.accountNumber);
entry.setTransactionLedgerEntryDescription(FUND_CARRIED_MESSAGE + (Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR));
entry.setTransactionLedgerEntryAmount(commonAmount);
// 3343 MOVE TRN-LDGR-ENTR-AMT TO WS-AMT-W-PERIOD
// 3344 WS-AMT-N.
// 3345 MOVE WS-AMT-X TO TRN-AMT-RED-X.
originEntriesToWrite.add(entry);
}
}
}
use of edu.cornell.kfs.gl.businessobject.ReversionUnitOfWorkCategoryAmount 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);
}
use of edu.cornell.kfs.gl.businessobject.ReversionUnitOfWorkCategoryAmount in project cu-kfs by CU-CommunityApps.
the class ReversionUnitOfWorkServiceImpl method loadCategories.
public ReversionUnitOfWork loadCategories(ReversionUnitOfWork orgRevUnitOfWork) {
Collection categoryAmounts = businessObjectService.findMatching(ReversionUnitOfWorkCategoryAmount.class, orgRevUnitOfWork.toStringMapper());
Map<String, ReversionUnitOfWorkCategoryAmount> categories = orgRevUnitOfWork.getCategoryAmounts();
Iterator iter = categoryAmounts.iterator();
while (iter.hasNext()) {
ReversionUnitOfWorkCategoryAmount catAmount = (ReversionUnitOfWorkCategoryAmount) iter.next();
categories.put(catAmount.getCategoryCode(), catAmount);
}
return orgRevUnitOfWork;
}
use of edu.cornell.kfs.gl.businessobject.ReversionUnitOfWorkCategoryAmount in project cu-kfs by CU-CommunityApps.
the class ReversionUnitOfWorkServiceImpl method save.
public <T extends ReversionUnitOfWork> void save(T orgRevUnitOfWork) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving org reversion summary for " + orgRevUnitOfWork.toString() + "; its category keys are: " + orgRevUnitOfWork.getCategoryAmounts().keySet());
}
getBusinessObjectService().save(orgRevUnitOfWork);
for (String category : orgRevUnitOfWork.getCategoryAmounts().keySet()) {
final ReversionUnitOfWorkCategoryAmount categoryAmount = orgRevUnitOfWork.getCategoryAmounts().get(category);
if (LOG.isDebugEnabled()) {
LOG.debug("Saving category amount for " + categoryAmount.toString());
}
getBusinessObjectService().save(categoryAmount);
}
}
Aggregations