use of org.kuali.kfs.module.purap.document.validation.event.PurchasingAccountsPayableItemPreCalculateEvent in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImpl method updateAccountAmounts.
/**
* @see org.kuali.kfs.module.purap.service.PurapAccountingService#updateAccountAmounts(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)
*/
@Override
public void updateAccountAmounts(PurchasingAccountsPayableDocument document) {
PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) document;
String accountDistributionMethod = purApDocument.getAccountDistributionMethod();
KualiRuleService kualiRuleService = SpringContext.getBean(KualiRuleService.class);
WorkflowDocument workflowDocument = purApDocument.getDocumentHeader().getWorkflowDocument();
Set<String> nodeNames = workflowDocument.getCurrentNodeNames();
// don't update if past the AP review level
if ((document instanceof PaymentRequestDocument) && purapService.isFullDocumentEntryCompleted(document)) {
if (nodeNames.contains(PaymentRequestStatuses.NODE_PAYMENT_METHOD_REVIEW)) {
// CU needs this update because the customization allows Treasury Manager to change unit/extended price and 'calculate'
for (PurApItem item : document.getItems()) {
updatePreqItemAccountAmountsOnly(item);
}
} else {
convertMoneyToPercent((PaymentRequestDocument) document);
}
return;
}
document.fixItemReferences();
// if distribution method is sequential and document is PREQ or VCM then...
if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
if (document instanceof VendorCreditMemoDocument) {
VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
cmDocument.updateExtendedPriceOnItems();
for (PurApItem item : document.getItems()) {
for (PurApAccountingLine account : item.getSourceAccountingLines()) {
account.setAmount(KualiDecimal.ZERO);
}
}
}
// update the accounts amounts for PREQ and distribution method = sequential
for (PurApItem item : document.getItems()) {
updatePreqItemAccountAmounts(item);
}
return;
}
// if distribution method is proportional and document is PREQ or VCM then...
if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
// update the accounts amounts for PREQ and distribution method = sequential
if (document instanceof VendorCreditMemoDocument) {
VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
cmDocument.updateExtendedPriceOnItems();
for (PurApItem item : document.getItems()) {
for (PurApAccountingLine account : item.getSourceAccountingLines()) {
account.setAmount(KualiDecimal.ZERO);
}
}
}
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
if (rulePassed) {
updatePreqProportionalItemAccountAmounts(item);
}
}
return;
}
// No recalculate if the account distribution method code is equal to "S" sequential ON REQ or POs..
if (PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
return;
}
}
// do recalculate only if the account distribution method code is not equal to "S" sequential method.
if (!PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
if (rulePassed) {
updateItemAccountAmounts(item);
}
}
}
}
Aggregations