Search in sources :

Example 91 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied.

protected void adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied(PaymentApplicationForm paymentApplicationForm, int deletedAppliedFundsIndex) {
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    InvoicePaidApplied appliedFundBeingDeleted = paymentApplicationDocument.getInvoicePaidApplieds().get(deletedAppliedFundsIndex);
    String summaryOfAppliedFundsDocumentNumberBeingDeleted = appliedFundBeingDeleted.getFinancialDocumentReferenceInvoiceNumber();
    KualiDecimal summaryOfAppliedFundsAmountBeingDeleted = appliedFundBeingDeleted.getInvoiceItemAppliedAmount();
    if (StringUtils.isNotBlank(summaryOfAppliedFundsDocumentNumberBeingDeleted)) {
        for (PaymentApplicationInvoiceApply invoiceListItem : paymentApplicationForm.getInvoiceApplications()) {
            for (PaymentApplicationInvoiceDetailApply invoiceListItemDetail : invoiceListItem.getDetailApplications()) {
                deleteCleanupOfApplyToInvoiceDetailData(invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted, summaryOfAppliedFundsAmountBeingDeleted);
                deleteCleanupOfQuickApplyToInvoiceData(invoiceListItem, invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted);
            }
        }
    }
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 92 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method writeErrorEntryByAward.

protected void writeErrorEntryByAward(ContractsAndGrantsBillingAward award, List<String> validationCategory, PrintStream printStream) throws IOException {
    // %15s %18s %20s %19s %15s %18s %23s %18s
    if (ObjectUtils.isNotNull(award)) {
        KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
        String awardBeginningDate;
        String awardEndingDate;
        String awardTotalAmount;
        String proposalNumber = award.getProposalNumber();
        Date beginningDate = award.getAwardBeginningDate();
        Date endingDate = award.getAwardEndingDate();
        KualiDecimal totalAmount = award.getAwardTotalAmount();
        if (ObjectUtils.isNotNull(beginningDate)) {
            awardBeginningDate = beginningDate.toString();
        } else {
            awardBeginningDate = "null award beginning date";
        }
        if (ObjectUtils.isNotNull(endingDate)) {
            awardEndingDate = endingDate.toString();
        } else {
            awardEndingDate = "null award ending date";
        }
        if (ObjectUtils.isNotNull(totalAmount) && ObjectUtils.isNotNull(totalAmount.bigDecimalValue())) {
            awardTotalAmount = totalAmount.toString();
        } else {
            awardTotalAmount = "null award total amount";
        }
        if (CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
            writeToReport(proposalNumber, "", awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
        } else {
            final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
            // calculate cumulativeExpenses
            for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
            }
            boolean firstLineFlag = true;
            for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                if (firstLineFlag) {
                    writeToReport(proposalNumber, awardAccount.getAccountNumber(), awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
                    firstLineFlag = false;
                } else {
                    writeToReport("", awardAccount.getAccountNumber(), "", "", "", "", printStream);
                }
            }
        }
    }
    // To print all the errors from the validation category.
    for (String vCat : validationCategory) {
        printStream.printf("%s", "     " + vCat);
        printStream.print("\r\n");
    }
    printStream.print(REPORT_LINE_DIVIDER);
    printStream.print("\r\n");
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) Date(java.sql.Date)

Example 93 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method takeAPennyLeaveAPennyCGBStyle.

/**
 * If the total of current expenditures within the list of InvoiceDetailAccountObjectCode business objects does
 * not meet the amount to target, steal or give a penny from one of those business objects so that it does
 *
 * @param invoiceDetailAccountObjectCodes a List of InvoiceDetailAccountObjectCode business objects
 * @param amountToTarget                  the amount which the sum of those objects should equal
 */
protected void takeAPennyLeaveAPennyCGBStyle(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, KualiDecimal amountToTarget) {
    if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodes)) {
        final KualiDecimal currentExpenditureTotal = sumInvoiceDetailAccountObjectCodes(invoiceDetailAccountObjectCodes).getCurrentExpenditures();
        if (!currentExpenditureTotal.equals(amountToTarget)) {
            final KualiDecimal difference = currentExpenditureTotal.subtract(amountToTarget);
            InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = findFirstPositiveCurrentExpenditureInvoiceDetailAccountObjectCode(invoiceDetailAccountObjectCodes);
            if (invoiceDetailAccountObjectCode != null) {
                invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().subtract(difference));
            }
        }
    }
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 94 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method calculateBalanceAmountWithoutLastBilledPeriod.

/**
 * This method would make sure the amounts of the current period are not included. So it calculates the cumulative
 * and subtracts the current period values. This would be done for Billing Frequencies - Monthly, Quarterly,
 * Semi-Annual and Annual.
 *
 * @param glBalance
 * @return balanceAmount
 */
protected KualiDecimal calculateBalanceAmountWithoutLastBilledPeriod(java.sql.Date lastBilledDate, Balance glBalance) {
    Timestamp ts = new Timestamp(new java.util.Date().getTime());
    java.sql.Date today = new java.sql.Date(ts.getTime());
    AccountingPeriod currPeriod = accountingPeriodService.getByDate(today);
    String currentPeriodCode = currPeriod.getUniversityFiscalPeriodCode();
    KualiDecimal currentBalanceAmount = KualiDecimal.ZERO;
    switch(currentPeriodCode) {
        case KFSConstants.MONTH13:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth12Amount()));
        // notice - no break!!!! we want to fall through to pick up all the prior months amounts
        case KFSConstants.MONTH12:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth11Amount()));
        // fall through
        case KFSConstants.MONTH11:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth10Amount()));
        // fall through
        case KFSConstants.MONTH10:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth9Amount()));
        // fall through
        case KFSConstants.MONTH9:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth8Amount()));
        // fall through
        case KFSConstants.MONTH8:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth7Amount()));
        // fall through
        case KFSConstants.MONTH7:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth6Amount()));
        // fall through
        case KFSConstants.MONTH6:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth5Amount()));
        // fall through
        case KFSConstants.MONTH5:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth4Amount()));
        // fall through
        case KFSConstants.MONTH4:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth3Amount()));
        // fall through
        case KFSConstants.MONTH3:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth2Amount()));
        // fall through
        case KFSConstants.MONTH2:
            currentBalanceAmount = currentBalanceAmount.add(cleanAmount(glBalance.getMonth1Amount()));
            break;
        default:
            break;
    }
    return glBalance.getContractsGrantsBeginningBalanceAmount().add(currentBalanceAmount);
}
Also used : AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Date(java.sql.Date)

Example 95 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method storeValidationErrors.

protected void storeValidationErrors(Map<ContractsAndGrantsBillingAward, List<String>> invalidGroup, Collection<ContractsGrantsInvoiceDocumentErrorLog> contractsGrantsInvoiceDocumentErrorLogs, String creationProcessTypeCode) {
    for (ContractsAndGrantsBillingAward award : invalidGroup.keySet()) {
        KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
        ContractsGrantsInvoiceDocumentErrorLog contractsGrantsInvoiceDocumentErrorLog = new ContractsGrantsInvoiceDocumentErrorLog();
        if (ObjectUtils.isNotNull(award)) {
            Date beginningDate = award.getAwardBeginningDate();
            Date endingDate = award.getAwardEndingDate();
            final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
            contractsGrantsInvoiceDocumentErrorLog.setProposalNumber(award.getProposalNumber());
            contractsGrantsInvoiceDocumentErrorLog.setAwardBeginningDate(beginningDate);
            contractsGrantsInvoiceDocumentErrorLog.setAwardEndingDate(endingDate);
            contractsGrantsInvoiceDocumentErrorLog.setAwardTotalAmount(award.getAwardTotalAmount().bigDecimalValue());
            if (ObjectUtils.isNotNull(award.getAwardPrimaryFundManager())) {
                contractsGrantsInvoiceDocumentErrorLog.setPrimaryFundManagerPrincipalId(award.getAwardPrimaryFundManager().getPrincipalId());
            }
            if (!CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
                boolean firstLineFlag = true;
                for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                    cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
                    if (firstLineFlag) {
                        firstLineFlag = false;
                        contractsGrantsInvoiceDocumentErrorLog.setAccounts(awardAccount.getAccountNumber());
                    } else {
                        contractsGrantsInvoiceDocumentErrorLog.setAccounts(contractsGrantsInvoiceDocumentErrorLog.getAccounts() + ";" + awardAccount.getAccountNumber());
                    }
                }
            }
            contractsGrantsInvoiceDocumentErrorLog.setCumulativeExpensesAmount(cumulativeExpenses.bigDecimalValue());
        }
        for (String vCat : invalidGroup.get(award)) {
            ContractsGrantsInvoiceDocumentErrorMessage contractsGrantsInvoiceDocumentErrorCategory = new ContractsGrantsInvoiceDocumentErrorMessage();
            contractsGrantsInvoiceDocumentErrorCategory.setErrorMessageText(vCat);
            contractsGrantsInvoiceDocumentErrorLog.getErrorMessages().add(contractsGrantsInvoiceDocumentErrorCategory);
        }
        int errorAccountsMax = dataDictionaryService.getAttributeMaxLength(ContractsGrantsInvoiceDocumentErrorLog.class, ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS);
        contractsGrantsInvoiceDocumentErrorLog.setAccounts(StringUtils.left(contractsGrantsInvoiceDocumentErrorLog.getAccounts(), errorAccountsMax));
        contractsGrantsInvoiceDocumentErrorLog.setErrorDate(dateTimeService.getCurrentTimestamp());
        contractsGrantsInvoiceDocumentErrorLog.setCreationProcessTypeCode(creationProcessTypeCode);
        businessObjectService.save(contractsGrantsInvoiceDocumentErrorLog);
        contractsGrantsInvoiceDocumentErrorLogs.add(contractsGrantsInvoiceDocumentErrorLog);
    }
}
Also used : ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) ContractsGrantsInvoiceDocumentErrorLog(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorLog) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) Date(java.sql.Date)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8