Search in sources :

Example 1 with IWantAccount

use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.

the class IWantDocument method copyItemsAndAccounts.

/**
 * Create copies of the items and accounts lists upon document copy.
 */
private void copyItemsAndAccounts() {
    List<IWantItem> newItems = new ArrayList<IWantItem>();
    List<IWantAccount> newAccounts = new ArrayList<IWantAccount>();
    if (items != null && !items.isEmpty()) {
        for (IWantItem item : items) {
            newItems.add(IWantItem.createCopy(item));
        }
    }
    if (accounts != null && !accounts.isEmpty()) {
        for (IWantAccount account : accounts) {
            newAccounts.add(IWantAccount.createCopy(account));
        }
    }
    this.items = newItems;
    this.accounts = newAccounts;
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) ArrayList(java.util.ArrayList) IWantItem(edu.cornell.kfs.module.purap.businessobject.IWantItem)

Example 2 with IWantAccount

use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.

the class IWantDocumentAction method route.

/**
 * @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#route(org.apache.struts.action.ActionMapping,
 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
 * javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward route(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    IWantDocumentForm iWantDocForm = (IWantDocumentForm) form;
    IWantDocument iWantDocument = iWantDocForm.getIWantDocument();
    IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
    boolean added = true;
    // add new item and new accounting line if not empty
    IWantItem item = iWantDocForm.getNewIWantItemLine();
    if (StringUtils.isNotBlank(item.getItemDescription()) || item.getItemUnitPrice() != null || item.getItemQuantity() != null) {
        added &= addNewItem(iWantDocForm, iWantDocument, item);
    }
    added &= addNewFavoriteAccountIfNecessary(added, iWantDocument);
    if (added) {
        IWantAccount account = iWantDocForm.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(iWantDocForm, iWantDocument, account);
        }
    }
    // Do not route if there were failures adding new items or accounts.
    if (!added) {
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    iWantDocument.setExplanation(iWantDocument.getDocumentHeader().getExplanation());
    String step = iWantDocForm.getStep();
    String principalId = iWantDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
    boolean setDefaultCollegeDept = iWantDocument.isUseCollegeAndDepartmentAsDefault();
    if (setDefaultCollegeDept) {
        // set these values in user Options table
        String college = iWantDocument.getCollegeLevelOrganization();
        String department = iWantDocument.getDepartmentLevelOrganization();
        saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_COLLEGE, college);
        saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DEPARTMENT, department);
    }
    if (iWantDocument.isSetDeliverToInfoAsDefault()) {
        if (StringUtils.isNotBlank(iWantDocument.getDeliverToNetID())) {
            saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_NET_ID, iWantDocument.getDeliverToNetID());
        }
        if (StringUtils.isNotBlank(iWantDocument.getDeliverToName())) {
            saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_NAME, iWantDocument.getDeliverToName());
        }
        if (StringUtils.isNotBlank(iWantDocument.getDeliverToEmailAddress())) {
            saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_EMAIL_ADDRESS, iWantDocument.getDeliverToEmailAddress());
        }
        if (StringUtils.isNotBlank(iWantDocument.getDeliverToPhoneNumber())) {
            saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_PHONE_NUMBER, iWantDocument.getDeliverToPhoneNumber());
        }
        if (StringUtils.isNotBlank(iWantDocument.getDeliverToAddress())) {
            saveUserOption(principalId, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_ADDRESS, iWantDocument.getDeliverToAddress());
        }
    }
    iWantDocumentService.setIWantDocumentDescription(iWantDocument);
    // insert adhoc route person first and the route
    if (StringUtils.isNotBlank(iWantDocForm.getNewAdHocRoutePerson().getId())) {
        iWantDocument.setCurrentRouteToNetId(iWantDocForm.getNewAdHocRoutePerson().getId());
        insertAdHocRoutePerson(mapping, iWantDocForm, request, response);
    }
    ActionForward actionForward = super.route(mapping, form, request, response);
    if (CUPurapConstants.IWantDocumentSteps.ROUTING_STEP.equalsIgnoreCase(step)) {
        iWantDocForm.setStep(CUPurapConstants.IWantDocumentSteps.REGULAR);
        iWantDocument.setStep(CUPurapConstants.IWantDocumentSteps.REGULAR);
        return mapping.findForward("finish");
    }
    return actionForward;
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) IWantItem(edu.cornell.kfs.module.purap.businessobject.IWantItem) ActionForward(org.apache.struts.action.ActionForward) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) PurApFavoriteAccountLineBuilderForIWantDocument(edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument) IWantDocumentService(edu.cornell.kfs.module.purap.document.service.IWantDocumentService)

Example 3 with IWantAccount

use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.

the class IWantDocumentForm method getAndResetNewIWantAccountLine.

/**
 * This method ...
 *
 * @return
 */
public IWantAccount getAndResetNewIWantAccountLine() {
    IWantAccount aIWantAccount = (IWantAccount) getNewSourceLine();
    newSourceLine = new IWantAccount();
    return aIWantAccount;
}
Also used : IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount)

Example 4 with IWantAccount

use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.

the class CuUserFavoriteAccountServiceImplTest method validateAccount.

private void validateAccount(String accountType, Class accountClass) {
    final FavoriteAccount favoriteAccount = FavoriteAccountFixture.FAVORITE_ACCOUNT_1.createFavoriteAccount();
    final GeneralLedgerPendingEntrySourceDetail acct = userFavoriteAccountService.getPopulatedNewAccount(favoriteAccount, accountClass);
    Assert.assertNotNull("Account should be populated", acct);
    Assert.assertTrue("Account should be " + accountType + " Account", accountClass.isInstance(acct));
    Assert.assertEquals("Account Number should be populated", favoriteAccount.getAccountNumber(), acct.getAccountNumber());
    Assert.assertEquals("Object Code should be populated", favoriteAccount.getFinancialObjectCode(), acct.getFinancialObjectCode());
    if (acct instanceof IWantAccount) {
        final KualiDecimal accountLinePercent = ((IWantAccount) acct).getAmountOrPercent();
        Assert.assertEquals("Incorrect percentage (comparison against 100% should have been zero)", 0, accountLinePercent.compareTo(new KualiDecimal(100)));
        Assert.assertEquals("Amount-or-Percent indicator should be Percent", CUPurapConstants.PERCENT, ((IWantAccount) acct).getUseAmountOrPercent());
    } else {
        final BigDecimal accountLinePercent = ((PurApAccountingLineBase) acct).getAccountLinePercent();
        Assert.assertEquals("Incorrect percentage (comparison against 100% should have been zero)", 0, accountLinePercent.compareTo(new BigDecimal(100)));
    }
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) GeneralLedgerPendingEntrySourceDetail(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) PurApAccountingLineBase(org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase) BigDecimal(java.math.BigDecimal)

Example 5 with IWantAccount

use of edu.cornell.kfs.module.purap.businessobject.IWantAccount in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method populateIWantDocAccounts.

/**
 * Populates the I Want document accounts
 *
 * @param batchIWantDocument
 * @param iWantDocument
 * @return true if no errors encountered, false otherwise
 */
protected boolean populateIWantDocAccounts(BatchIWantDocument batchIWantDocument, IWantDocument iWantDocument) {
    LOG.info("Populate I Want doc accounts");
    boolean noErrors = true;
    // accounts
    List<IWantAccount> iWantAccounts = batchIWantDocument.getAccounts();
    if (CollectionUtils.isNotEmpty(iWantAccounts)) {
        for (IWantAccount account : iWantAccounts) {
            IWantAccount addAccount = new IWantAccount();
            addAccount.setAccountNumber(account.getAccountNumber());
            addAccount.setSubAccountNumber(account.getSubAccountNumber());
            addAccount.setChartOfAccountsCode(account.getChartOfAccountsCode());
            addAccount.setFinancialObjectCode(account.getFinancialObjectCode());
            addAccount.setFinancialSubObjectCode(account.getFinancialSubObjectCode());
            addAccount.setOrganizationReferenceId(account.getOrganizationReferenceId());
            addAccount.setProjectCode(account.getProjectCode());
            addAccount.setAmountOrPercent(account.getAmountOrPercent());
            if ("P".equalsIgnoreCase(account.getUseAmountOrPercent())) {
                addAccount.setUseAmountOrPercent(CUPurapConstants.PERCENT);
            }
            if ("A".equalsIgnoreCase(account.getUseAmountOrPercent())) {
                addAccount.setUseAmountOrPercent(CUPurapConstants.AMOUNT);
            }
            boolean rulePassed = ruleService.applyRules(new KualiAddLineEvent(iWantDocument, "accounts", addAccount));
            if (rulePassed) {
                iWantDocument.addAccount(addAccount);
            } else {
                logErrorMessages();
            }
            noErrors &= rulePassed;
        }
    }
    return noErrors;
}
Also used : KualiAddLineEvent(org.kuali.kfs.kns.rule.event.KualiAddLineEvent) IWantAccount(edu.cornell.kfs.module.purap.businessobject.IWantAccount)

Aggregations

IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)13 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)5 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 IWantItem (edu.cornell.kfs.module.purap.businessobject.IWantItem)4 BigDecimal (java.math.BigDecimal)3 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)3 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)2 FavoriteAccount (edu.cornell.kfs.sys.businessobject.FavoriteAccount)2 ActionForward (org.apache.struts.action.ActionForward)2 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 UserProcurementProfileValidationServiceImpl (edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 KualiAddLineEvent (org.kuali.kfs.kns.rule.event.KualiAddLineEvent)1 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)1 RouteDocumentEvent (org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent)1 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 PurApAccountingLineBase (org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase)1