Search in sources :

Example 1 with KualiRuleService

use of org.kuali.kfs.krad.service.KualiRuleService in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method addNewItem.

private boolean addNewItem(IWantDocumentForm iWantDocumentForm, IWantDocument iWantDoc, IWantItem item) {
    KualiRuleService ruleService = SpringContext.getBean(KualiRuleService.class);
    boolean rulePassed = true;
    // call business rules
    rulePassed &= ruleService.applyRules(new AddIWantItemEvent(StringUtils.EMPTY, iWantDoc, item));
    if (rulePassed) {
        item = iWantDocumentForm.getAndResetNewIWantItemLine();
        iWantDoc.addItem(item);
    }
    return rulePassed;
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) AddIWantItemEvent(edu.cornell.kfs.module.purap.document.validation.event.AddIWantItemEvent)

Example 2 with KualiRuleService

use of org.kuali.kfs.krad.service.KualiRuleService 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);
            }
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurchasingAccountsPayableDocumentBase(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PurchasingAccountsPayableItemPreCalculateEvent(org.kuali.kfs.module.purap.document.validation.event.PurchasingAccountsPayableItemPreCalculateEvent)

Example 3 with KualiRuleService

use of org.kuali.kfs.krad.service.KualiRuleService in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method continueToRouting.

/**
 * Takes the user to next page
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward continueToRouting(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = iWantForm.getIWantDocument();
    // call business rules
    KualiRuleService ruleService = SpringContext.getBean(KualiRuleService.class);
    boolean rulePassed = true;
    rulePassed &= ruleService.applyRules(new RouteDocumentEvent("", iWantDocument));
    if (rulePassed) {
        iWantForm.setStep(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
        iWantDocument.setStep(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) RouteDocumentEvent(org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)

Example 4 with KualiRuleService

use of org.kuali.kfs.krad.service.KualiRuleService in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method continueToVendor.

/**
 * Takes the user to next page
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward continueToVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = iWantForm.getIWantDocument();
    boolean added = true;
    // add new item and new accounting line if not empty
    IWantItem item = iWantForm.getNewIWantItemLine();
    if (StringUtils.isNotBlank(item.getItemDescription()) || item.getItemUnitPrice() != null || item.getItemQuantity() != null) {
        added &= addNewItem(iWantForm, iWantDocument, item);
    }
    added &= addNewFavoriteAccountIfNecessary(added, iWantDocument);
    if (added) {
        IWantAccount account = iWantForm.getNewSourceLine();
        if (StringUtils.isNotBlank(account.getAccountNumber()) || StringUtils.isNotBlank(account.getSubAccountNumber()) || StringUtils.isNotBlank(account.getFinancialObjectCode()) || StringUtils.isNotBlank(account.getFinancialSubObjectCode()) || StringUtils.isNotBlank(account.getProjectCode()) || StringUtils.isNotBlank(account.getOrganizationReferenceId())) {
            added &= addNewAccount(iWantForm, iWantDocument, account);
        }
    }
    // If addition of IWNT item or account failed, then skip the rest of the validation.
    if (!added) {
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    KualiRuleService ruleService = SpringContext.getBean(KualiRuleService.class);
    boolean rulePassed = true;
    // call business rules
    rulePassed &= ruleService.applyRules(new RouteDocumentEvent("", iWantDocument));
    if (rulePassed) {
        iWantForm.setStep(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
        iWantDocument.setStep(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) RouteDocumentEvent(org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent) IWantItem(edu.cornell.kfs.module.purap.businessobject.IWantItem) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)

Example 5 with KualiRuleService

use of org.kuali.kfs.krad.service.KualiRuleService in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method addNewAccount.

private boolean addNewAccount(IWantDocumentForm iWantDocumentForm, IWantDocument iWantDoc, IWantAccount account) {
    KualiRuleService ruleService = SpringContext.getBean(KualiRuleService.class);
    boolean acctRulesPassed = true;
    acctRulesPassed &= ruleService.applyRules(new KualiAddLineEvent(iWantDoc, "accounts", account));
    if (acctRulesPassed) {
        account = iWantDocumentForm.getAndResetNewIWantAccountLine();
        iWantDoc.addAccount(account);
    }
    return acctRulesPassed;
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) KualiAddLineEvent(org.kuali.kfs.kns.rule.event.KualiAddLineEvent)

Aggregations

KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)6 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)3 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)3 RouteDocumentEvent (org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent)3 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)1 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)1 AddIWantItemEvent (edu.cornell.kfs.module.purap.document.validation.event.AddIWantItemEvent)1 KualiAddLineEvent (org.kuali.kfs.kns.rule.event.KualiAddLineEvent)1 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)1 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)1 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)1 PurchasingAccountsPayableDocumentBase (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase)1 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)1 PurchasingAccountsPayableItemPreCalculateEvent (org.kuali.kfs.module.purap.document.validation.event.PurchasingAccountsPayableItemPreCalculateEvent)1 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)1