Search in sources :

Example 1 with CostCategory

use of org.kuali.kfs.module.ar.businessobject.CostCategory in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method assignCurrentExpenditureToNonExistingAccountObjectCode.

protected void assignCurrentExpenditureToNonExistingAccountObjectCode(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument, ContractsGrantsInvoiceDetail invoiceDetail) {
    String categoryCode = invoiceDetail.getCategoryCode();
    if (StringUtils.isBlank(categoryCode)) {
        throw new IllegalArgumentException("Category Code can not be null during recalculation of account object code for Contracts & Grants Invoice Document.");
    }
    // get the category that matches this category code.
    final CostCategory category = businessObjectService.findBySinglePrimaryKey(CostCategory.class, categoryCode);
    // got the category now.
    if (!ObjectUtils.isNull(category)) {
        final KualiDecimal oneCent = new KualiDecimal(0.01);
        int size = contractsGrantsInvoiceDocument.getAccountDetails().size();
        KualiDecimal amount = new KualiDecimal(invoiceDetail.getInvoiceAmount().bigDecimalValue().divide(new BigDecimal(size), 2, RoundingMode.HALF_UP));
        KualiDecimal remainder = invoiceDetail.getInvoiceAmount().subtract(amount.multiply(new KualiDecimal(size)));
        for (InvoiceAccountDetail invoiceAccountDetail : contractsGrantsInvoiceDocument.getAccountDetails()) {
            InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = new InvoiceDetailAccountObjectCode();
            invoiceDetailAccountObjectCode.setDocumentNumber(contractsGrantsInvoiceDocument.getDocumentNumber());
            invoiceDetailAccountObjectCode.setProposalNumber(contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
            invoiceDetailAccountObjectCode.setCategoryCode(categoryCode);
            invoiceDetailAccountObjectCode.setAccountNumber(invoiceAccountDetail.getAccountNumber());
            invoiceDetailAccountObjectCode.setChartOfAccountsCode(invoiceAccountDetail.getChartOfAccountsCode());
            // it's 0.00 that's why we are in this section to begin with.
            invoiceDetailAccountObjectCode.setCumulativeExpenditures(KualiDecimal.ZERO);
            // this is also 0.00 because it has never been billed before
            invoiceDetailAccountObjectCode.setTotalBilled(KualiDecimal.ZERO);
            final ObjectCodeCurrent objectCode = getCostCategoryService().findObjectCodeForChartAndCategory(invoiceAccountDetail.getChartOfAccountsCode(), categoryCode);
            if (!ObjectUtils.isNull(objectCode)) {
                invoiceDetailAccountObjectCode.setFinancialObjectCode(objectCode.getFinancialObjectCode());
            }
            // tack on or remove one penny until the remainder is 0 - take a penny, leave a penny!
            if (remainder.isGreaterThan(KualiDecimal.ZERO)) {
                amount = amount.add(oneCent);
                remainder = remainder.subtract(oneCent);
            } else if (remainder.isLessThan(KualiDecimal.ZERO)) {
                amount = amount.subtract(oneCent);
                remainder = remainder.add(oneCent);
            }
            invoiceDetailAccountObjectCode.setCurrentExpenditures(amount);
            List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes = contractsGrantsInvoiceDocument.getInvoiceDetailAccountObjectCodes();
            if (invoiceDetailAccountObjectCodes.contains(invoiceDetailAccountObjectCode)) {
                // update existing code
                InvoiceDetailAccountObjectCode original = invoiceDetailAccountObjectCodes.get(invoiceDetailAccountObjectCodes.indexOf(invoiceDetailAccountObjectCode));
                original.setCurrentExpenditures(amount);
                original.setCategoryCode(categoryCode);
            } else {
                // add this single account object code item to the list in the Map
                contractsGrantsInvoiceDocument.getInvoiceDetailAccountObjectCodes().add(invoiceDetailAccountObjectCode);
            }
        }
    } else {
        LOG.error("Category Code cannot be found from the category list during recalculation of account object " + "code for Contracts & Grants Invoice Document.");
    }
}
Also used : AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) ObjectCodeCurrent(org.kuali.kfs.coa.businessobject.ObjectCodeCurrent) CostCategory(org.kuali.kfs.module.ar.businessobject.CostCategory) BigDecimal(java.math.BigDecimal) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 2 with CostCategory

use of org.kuali.kfs.module.ar.businessobject.CostCategory in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method mapAwardAccountObjectCodeTotalBilledsByCategoryCode.

/**
 * Converts a List of AwardAccountObjectCodeTotalBilled into a Map, keyed by the Cost Category which most closely
 * matches them
 *
 * @param awardAccountObjectCodeTotalBilleds the List of AwardAccountObjectCodeTotalBilled business objects to Map
 * @return the Mapped AwardAccountObjectCodeTotalBilled records
 */
protected Map<String, List<AwardAccountObjectCodeTotalBilled>> mapAwardAccountObjectCodeTotalBilledsByCategoryCode(List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds) {
    Integer fiscalYear = getUniversityDateService().getCurrentFiscalYear();
    Map<String, List<AwardAccountObjectCodeTotalBilled>> billedsMap = new HashMap<>();
    for (AwardAccountObjectCodeTotalBilled billed : awardAccountObjectCodeTotalBilleds) {
        final CostCategory category = getCostCategoryService().getCostCategoryForObjectCode(fiscalYear, billed.getChartOfAccountsCode(), billed.getFinancialObjectCode());
        if (!ObjectUtils.isNull(category)) {
            List<AwardAccountObjectCodeTotalBilled> billedForCategory = billedsMap.get(category.getCategoryCode());
            if (billedForCategory == null) {
                billedForCategory = new ArrayList<>();
            }
            billedForCategory.add(billed);
            billedsMap.put(category.getCategoryCode(), billedForCategory);
        } else {
            LOG.warn("Could not find cost category for AwardAccountObjectCodeTotalBilled, fiscal year = " + fiscalYear + " " + billed.getChartOfAccountsCode() + " " + billed.getFinancialObjectCode());
        }
    }
    return billedsMap;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) AwardAccountObjectCodeTotalBilled(org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled) CostCategory(org.kuali.kfs.module.ar.businessobject.CostCategory)

Example 3 with CostCategory

use of org.kuali.kfs.module.ar.businessobject.CostCategory in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method updateCategoryActualAmountsByBalance.

/**
 * Updates the appropriate amounts for the InvoiceDetailAccountObjectCode matching the given balance
 *
 * @param document                        the CINV document we're generating
 * @param balance                         the balance to update amounts by
 * @param award                           the award on the CINV document we're generating
 * @param invoiceDetailAccountObjectCodes the List of invoiceDetailObjectCodes to update one of
 * @param firstFiscalPeriod               whether we're generating the CINV document in the fiscal fiscal period
 *                                        or not
 */
protected void updateCategoryActualAmountsByBalance(ContractsGrantsInvoiceDocument document, Balance balance, ContractsAndGrantsBillingAward award, List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, boolean firstFiscalPeriod) {
    final CostCategory category = getCostCategoryService().getCostCategoryForObjectCode(balance.getUniversityFiscalYear(), balance.getChartOfAccountsCode(), balance.getObjectCode());
    if (!ObjectUtils.isNull(category)) {
        final InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = getInvoiceDetailAccountObjectCodeByBalanceAndCategory(invoiceDetailAccountObjectCodes, balance, document.getDocumentNumber(), document.getInvoiceGeneralDetail().getProposalNumber(), category);
        if (ArConstants.BillingFrequencyValues.isTimeBased(document.getInvoiceGeneralDetail())) {
            if (firstFiscalPeriod) {
                invoiceDetailAccountObjectCode.setCumulativeExpenditures(cleanAmount(invoiceDetailAccountObjectCode.getCumulativeExpenditures()).add(cleanAmount(balance.getContractsGrantsBeginningBalanceAmount())).add(cleanAmount(balance.getAccountLineAnnualBalanceAmount())));
                if (!includePeriod13InPeriod01Calculations()) {
                    invoiceDetailAccountObjectCode.setCumulativeExpenditures(cleanAmount(invoiceDetailAccountObjectCode.getCumulativeExpenditures()).subtract(cleanAmount(balance.getMonth13Amount())));
                }
            } else {
                invoiceDetailAccountObjectCode.setCumulativeExpenditures(cleanAmount(invoiceDetailAccountObjectCode.getCumulativeExpenditures()).add(calculateBalanceAmountWithoutLastBilledPeriod(document.getInvoiceGeneralDetail().getLastBilledDate(), balance)));
            }
        } else {
            // For other billing frequencies
            cleanAmount(balance.getContractsGrantsBeginningBalanceAmount()).add(cleanAmount(balance.getAccountLineAnnualBalanceAmount()));
            invoiceDetailAccountObjectCode.setCumulativeExpenditures(cleanAmount(invoiceDetailAccountObjectCode.getCumulativeExpenditures()).add(cleanAmount(balance.getContractsGrantsBeginningBalanceAmount()).add(cleanAmount(balance.getAccountLineAnnualBalanceAmount()))));
        }
    }
}
Also used : CostCategory(org.kuali.kfs.module.ar.businessobject.CostCategory) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 4 with CostCategory

use of org.kuali.kfs.module.ar.businessobject.CostCategory in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method generateValuesForCategories.

/**
 * 1. This method is responsible to populate categories column for the ContractsGrantsInvoice Document. 2. The
 * categories are retrieved from the Maintenance document as a collection and then a logic with conditions to
 * handle ranges of Object Codes. 3. Once the object codes are retrieved and categories are set the
 * performAccountingCalculations method of InvoiceDetail BO will do all the accounting calculations.
 *
 * @param documentNumber                     the number of the document we want to add invoice details to
 * @param invoiceDetailAccountObjectCodes    the List of InvoiceDetailAccountObjectCodes containing amounts to
 *                                           sum into our invoice details
 * @param budgetAmountsByCostCategory        the budget amounts, sorted by cost category
 * @param awardAccountObjectCodeTotalBilleds the business objects containing what has been billed from the
 *                                           document's award accounts already
 */
public List<ContractsGrantsInvoiceDetail> generateValuesForCategories(String documentNumber, List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, Map<String, KualiDecimal> budgetAmountsByCostCategory, List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds) {
    Collection<CostCategory> costCategories = retrieveAllBillingCategories();
    List<ContractsGrantsInvoiceDetail> invoiceDetails = new ArrayList<>();
    Map<String, List<InvoiceDetailAccountObjectCode>> invoiceDetailAccountObjectCodesMap = mapInvoiceDetailAccountObjectCodesByCategoryCode(invoiceDetailAccountObjectCodes);
    Map<String, List<AwardAccountObjectCodeTotalBilled>> billedsMap = mapAwardAccountObjectCodeTotalBilledsByCategoryCode(awardAccountObjectCodeTotalBilleds);
    for (CostCategory category : costCategories) {
        ContractsGrantsInvoiceDetail invDetail = new ContractsGrantsInvoiceDetail();
        invDetail.setDocumentNumber(documentNumber);
        invDetail.setCategoryCode(category.getCategoryCode());
        invDetail.setCostCategory(category);
        invDetail.setIndirectCostIndicator(category.isIndirectCostIndicator());
        // calculate total billed first
        invDetail.setCumulativeExpenditures(KualiDecimal.ZERO);
        invDetail.setInvoiceAmount(KualiDecimal.ZERO);
        invDetail.setTotalPreviouslyBilled(KualiDecimal.ZERO);
        List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodesForCategory = invoiceDetailAccountObjectCodesMap.get(category.getCategoryCode());
        if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodesForCategory)) {
            for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodesForCategory) {
                invDetail.setCumulativeExpenditures(invDetail.getCumulativeExpenditures().add(invoiceDetailAccountObjectCode.getCumulativeExpenditures()));
                invDetail.setInvoiceAmount(invDetail.getInvoiceAmount().add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
            }
        }
        List<AwardAccountObjectCodeTotalBilled> billedForCategory = billedsMap.get(category.getCategoryCode());
        if (!CollectionUtils.isEmpty(billedForCategory)) {
            for (AwardAccountObjectCodeTotalBilled accountObjectCodeTotalBilled : billedForCategory) {
                // this adds up all the total billed based on object code into categories; sum for this category.
                invDetail.setTotalPreviouslyBilled(invDetail.getTotalPreviouslyBilled().add(accountObjectCodeTotalBilled.getTotalBilled()));
            }
        }
        // calculate the rest using billed to date
        if (!ObjectUtils.isNull(budgetAmountsByCostCategory.get(category.getCategoryCode()))) {
            invDetail.setTotalBudget(budgetAmountsByCostCategory.get(category.getCategoryCode()));
        } else {
            invDetail.setTotalBudget(KualiDecimal.ZERO);
        }
        invoiceDetails.add(invDetail);
    }
    return invoiceDetails;
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) ArrayList(java.util.ArrayList) AwardAccountObjectCodeTotalBilled(org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled) CostCategory(org.kuali.kfs.module.ar.businessobject.CostCategory) ArrayList(java.util.ArrayList) List(java.util.List) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 5 with CostCategory

use of org.kuali.kfs.module.ar.businessobject.CostCategory in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method updateCategoryBudgetAmountsByBalance.

/**
 * Updates the cost category budget amount (in the given Map, budgetAmountsByCostCategory) by the total amount of
 * the balance
 *
 * @param balance                     the balance to update the budget amounts by
 * @param budgetAmountsByCostCategory the Map of budget amounts sorted by cost category
 * @param firstFiscalPeriod           whether this CINV is being generated in the first fiscal period or not
 * @return the updated award account budget amount
 */
protected void updateCategoryBudgetAmountsByBalance(Balance balance, Map<String, KualiDecimal> budgetAmountsByCostCategory, boolean firstFiscalPeriod) {
    CostCategory category = getCostCategoryService().getCostCategoryForObjectCode(balance.getUniversityFiscalYear(), balance.getChartOfAccountsCode(), balance.getObjectCode());
    if (!ObjectUtils.isNull(category)) {
        final KualiDecimal balanceAmount = getBudgetBalanceAmount(balance, firstFiscalPeriod);
        KualiDecimal categoryBudgetAmount = budgetAmountsByCostCategory.get(category.getCategoryCode());
        if (categoryBudgetAmount == null) {
            categoryBudgetAmount = KualiDecimal.ZERO;
        }
        categoryBudgetAmount = categoryBudgetAmount.add(balanceAmount);
        budgetAmountsByCostCategory.put(category.getCategoryCode(), categoryBudgetAmount);
    } else {
        LOG.warn("Could not find cost category for balance: " + balance.getUniversityFiscalYear() + " " + balance.getChartOfAccountsCode() + " " + balance.getAccountNumber() + " " + balance.getSubAccountNumber() + " " + balance.getObjectCode() + " " + balance.getSubObjectCode() + " " + balance.getBalanceTypeCode());
    }
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CostCategory(org.kuali.kfs.module.ar.businessobject.CostCategory)

Aggregations

CostCategory (org.kuali.kfs.module.ar.businessobject.CostCategory)5 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)2 AwardAccountObjectCodeTotalBilled (org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ObjectCodeCurrent (org.kuali.kfs.coa.businessobject.ObjectCodeCurrent)1 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)1 ContractsGrantsInvoiceDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail)1 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)1