Search in sources :

Example 16 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method processCustomInsertAccountingLine.

/**
 * @see org.kuali.kfs.module.purap.document.web.struts.PurchasingAccountsPayableActionBase#processCustomInsertAccountingLine(PurchasingAccountsPayableFormBase, HttpServletRequest)
 */
@Override
public boolean processCustomInsertAccountingLine(PurchasingAccountsPayableFormBase purapForm, HttpServletRequest request) {
    boolean success = false;
    PurchasingFormBase purchasingForm = (PurchasingFormBase) purapForm;
    // index of item selected
    int itemIndex = getSelectedLine(request);
    PurApItem item = null;
    boolean institutionNeedsDistributeAccountValidation = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.VALIDATE_ACCOUNT_DISTRIBUTION_IND);
    if (itemIndex == -2 && !institutionNeedsDistributeAccountValidation) {
        PurApAccountingLine line = purchasingForm.getAccountDistributionnewSourceLine();
        purchasingForm.addAccountDistributionsourceAccountingLine(line);
        success = true;
    }
    return success;
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants)

Example 17 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method addFavoriteAccount.

/*
     * KFSPTS-985 : add favorite account.
     * This is a copy from requisitionaction.  to be shared by both req & po
     */
public ActionForward addFavoriteAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase poForm = (PurchasingFormBase) form;
    PurchasingDocumentBase document = (PurchasingDocumentBase) poForm.getDocument();
    int itemIdx = getSelectedLine(request);
    final int DISTRIBUTION_INDEX = -2;
    PurchasingFavoriteAccountLineBuilderBase<? extends PurApAccountingLine> favoriteAccountBuilder;
    // Initialize the correct builder based on whether the Favorite Account is for an item in the list or for account distribution.
    if (itemIdx >= 0) {
        PurchasingItemBase item = (PurchasingItemBase) document.getItem(itemIdx);
        favoriteAccountBuilder = new PurchasingFavoriteAccountLineBuilderForLineItem<PurApAccountingLine>(item, itemIdx, poForm.setupNewPurchasingAccountingLine());
    } else if (itemIdx == DISTRIBUTION_INDEX) {
        favoriteAccountBuilder = new PurchasingFavoriteAccountLineBuilderForDistribution<PurApAccountingLine>(document, poForm.getAccountDistributionsourceAccountingLines(), poForm.setupNewAccountDistributionAccountingLine());
    } else {
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }
    // Add a new Favorite-Account-derived accounting line to the list, with errors inserted into the message map as appropriate.
    favoriteAccountBuilder.addNewFavoriteAccountLineToListIfPossible();
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchasingFavoriteAccountLineBuilderForDistribution(edu.cornell.kfs.module.purap.util.PurchasingFavoriteAccountLineBuilderForDistribution) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchasingItemBase(org.kuali.kfs.module.purap.businessobject.PurchasingItemBase) PurchasingDocumentBase(org.kuali.kfs.module.purap.document.PurchasingDocumentBase)

Example 18 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class FavoriteAccountLineBuilderTest method assertAccountingLineHasCorrectConfiguration.

/*
     * Convenience method for validating that the generated accounting line has the correct data and is of the correct type.
     */
private void assertAccountingLineHasCorrectConfiguration(FavoriteAccount expectedAccount, Class<? extends GeneralLedgerPendingEntrySourceDetail> expectedLineClass, GeneralLedgerPendingEntrySourceDetail acctLine) throws Exception {
    if (!expectedLineClass.isAssignableFrom(acctLine.getClass())) {
        fail("Expected line type is " + expectedLineClass.getName() + " but the generated line is of type " + acctLine.getClass().getName() + " which is not an instance of the expected one");
    }
    assertEquals("Generated line has wrong chart code", expectedAccount.getChartOfAccountsCode(), acctLine.getChartOfAccountsCode());
    assertEquals("Generated line has wrong account number", expectedAccount.getAccountNumber(), acctLine.getAccountNumber());
    assertEquals("Generated line has wrong sub-account number", expectedAccount.getSubAccountNumber(), acctLine.getSubAccountNumber());
    assertEquals("Generated line has wrong object code", expectedAccount.getFinancialObjectCode(), acctLine.getFinancialObjectCode());
    assertEquals("Generated line has wrong sub-object code", expectedAccount.getFinancialSubObjectCode(), acctLine.getFinancialSubObjectCode());
    assertEquals("Generated line has wrong project code", expectedAccount.getProjectCode(), acctLine.getProjectCode());
    assertEquals("Generated line has wrong org ref ID", expectedAccount.getOrganizationReferenceId(), acctLine.getOrganizationReferenceId());
    // Validate pre-initialized percentage. The retrieval means will vary depending on line type and whether we need hacks to avoid Spring calls.
    if (acctLine instanceof RequisitionAccount) {
        assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, getRequisitionAccountLinePercent(((RequisitionAccount) acctLine)).compareTo(new BigDecimal(100)));
    } else if (acctLine instanceof PurApAccountingLine) {
        assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((PurApAccountingLine) acctLine).getAccountLinePercent().compareTo(new BigDecimal(100)));
    } else if (acctLine instanceof IWantAccount) {
        assertEquals("Generated line has wrong amount-or-percent indicator", CUPurapConstants.PERCENT, ((IWantAccount) acctLine).getUseAmountOrPercent());
        assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((IWantAccount) acctLine).getAmountOrPercent().compareTo(new KualiDecimal(100)));
    }
}
Also used : RequisitionAccount(org.kuali.kfs.module.purap.businessobject.RequisitionAccount) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) BigDecimal(java.math.BigDecimal)

Example 19 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.

the class FavoriteAccountLineBuilderTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
    userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
    reqsAccounts = new ArrayList<PurApAccountingLine>();
    poAccounts = new ArrayList<PurApAccountingLine>();
    reqsItem = new RequisitionItem();
    poItem = new PurchaseOrderItem();
    reqsDoc = getMockedDocument(CuRequisitionDocument.class);
    poDoc = getMockedDocument(PurchaseOrderDocument.class);
    iwntDoc = getMockedDocument(IWantDocument.class);
    iwntDoc.setAccounts(new ArrayList<IWantAccount>());
    // Favorite Account with only some fields populated.
    testFavoriteAccount = new FavoriteAccount();
    testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
    testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
    testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
    testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
    testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
    // Favorite Account with all fields populated (except reference objects or object ID or version number).
    testAltFavoriteAccount = new FavoriteAccount();
    testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
    testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
    testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
    testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
    testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
    testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
    testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
    testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
    GlobalVariables.setMessageMap(new MessageMap());
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) UserProcurementProfileValidationServiceImpl(edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) BeforeClass(org.junit.BeforeClass)

Example 20 with PurApAccountingLine

use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine 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)

Aggregations

PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)27 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)17 ArrayList (java.util.ArrayList)9 List (java.util.List)7 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)7 BigDecimal (java.math.BigDecimal)6 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)4 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)3 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)3 PurchasingAccountsPayableDocument (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)3 KfsParameterConstants (org.kuali.kfs.sys.service.impl.KfsParameterConstants)3 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)3 Account (org.kuali.kfs.coa.businessobject.Account)2 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)2 PurchasingItemBase (org.kuali.kfs.module.purap.businessobject.PurchasingItemBase)2 RequisitionAccount (org.kuali.kfs.module.purap.businessobject.RequisitionAccount)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 PurchasingAccountsPayableDocumentBase (org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase)2