Search in sources :

Example 6 with ContractsGrantsInvoiceDetail

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

the class ContractsGrantsInvoiceDocumentServiceImpl method buildTotalCostInvoiceDetailFieldsMap.

private Map<String, Object> buildTotalCostInvoiceDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
    Map<String, Object> totalCostInvoiceDetailFieldsMap = new HashMap<>();
    ContractsGrantsInvoiceDetail totalCostInvoiceDetail = document.getTotalCostInvoiceDetail();
    if (ObjectUtils.isNotNull(totalCostInvoiceDetail)) {
        final String prefix = ArPropertyConstants.TOTAL_INVOICE_DETAIL + ".";
        totalCostInvoiceDetailFieldsMap.putAll(buildInvoiceDetailFieldMap(prefix, totalCostInvoiceDetail));
    }
    return totalCostInvoiceDetailFieldsMap;
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) HashMap(java.util.HashMap)

Example 7 with ContractsGrantsInvoiceDetail

use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail 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 8 with ContractsGrantsInvoiceDetail

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

the class CuContractsGrantsInvoiceDocumentServiceImpl method prorateBill.

@Override
public void prorateBill(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
    LOG.debug("prorateBill, entering");
    // Amount to be billed on
    KualiDecimal totalCost = new KualiDecimal(0);
    // manually changed the value
    for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
        totalCost = totalCost.add(invD.getInvoiceAmount());
    }
    // Total Billed so far
    KualiDecimal billedTotalCost = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getTotalPreviouslyBilled();
    // CU Customization, use award budget total, and not the award total
    // KualiDecimal accountAwardTotal = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAwardTotal();
    Award award = (Award) contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAward();
    AwardExtendedAttribute awardExtension = (AwardExtendedAttribute) award.getExtension();
    KualiDecimal accountAwardTotal = awardExtension.getBudgetTotalAmount();
    if (accountAwardTotal.subtract(billedTotalCost).isGreaterEqual(new KualiDecimal(0))) {
        KualiDecimal amountEligibleForBilling = accountAwardTotal.subtract(billedTotalCost);
        if (totalCost.isGreaterThan(amountEligibleForBilling)) {
            // use BigDecimal because percentage should not have only a
            // scale of 2, we need more for accuracy
            BigDecimal percentage = amountEligibleForBilling.bigDecimalValue().divide(totalCost.bigDecimalValue(), 10, RoundingMode.HALF_DOWN);
            // use to check if rounding has left a few cents off
            KualiDecimal amountToBill = new KualiDecimal(0);
            ContractsGrantsInvoiceDetail largestCostCategory = null;
            BigDecimal largestAmount = BigDecimal.ZERO;
            for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
                BigDecimal newValue = invD.getInvoiceAmount().bigDecimalValue().multiply(percentage);
                KualiDecimal newKualiDecimalValue = new KualiDecimal(newValue.setScale(2, RoundingMode.DOWN));
                invD.setInvoiceAmount(newKualiDecimalValue);
                amountToBill = amountToBill.add(newKualiDecimalValue);
                if (newValue.compareTo(largestAmount) > 0) {
                    largestAmount = newKualiDecimalValue.bigDecimalValue();
                    largestCostCategory = invD;
                }
            }
            if (!amountToBill.equals(amountEligibleForBilling)) {
                KualiDecimal remaining = amountEligibleForBilling.subtract(amountToBill);
                if (ObjectUtils.isNull(largestCostCategory) && CollectionUtils.isNotEmpty(contractsGrantsInvoiceDocument.getInvoiceDetails())) {
                    largestCostCategory = contractsGrantsInvoiceDocument.getInvoiceDetails().get(0);
                }
                if (ObjectUtils.isNotNull(largestCostCategory)) {
                    largestCostCategory.setInvoiceAmount(largestCostCategory.getInvoiceAmount().add(remaining));
                }
            }
            recalculateTotalAmountBilledToDate(contractsGrantsInvoiceDocument);
        }
    }
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) Award(org.kuali.kfs.module.cg.businessobject.Award) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) AwardExtendedAttribute(edu.cornell.kfs.module.cg.businessobject.AwardExtendedAttribute) BigDecimal(java.math.BigDecimal)

Example 9 with ContractsGrantsInvoiceDetail

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

the class CuContractsGrantsInvoiceDocumentServiceImpl method getInstitutionTemplateParameters.

protected Map<String, String> getInstitutionTemplateParameters(ContractsGrantsInvoiceDocument document) {
    Map<String, Object> localParameterMap = new HashMap<String, Object>();
    if (document.getInvoiceGeneralDetail().isFinalBillIndicator()) {
        localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.FINAL_BILL, CUKFSConstants.CAPITAL_X);
        localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.PARTIAL_BILL, StringUtils.EMPTY);
    } else {
        localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.FINAL_BILL, StringUtils.EMPTY);
        localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.PARTIAL_BILL, CUKFSConstants.CAPITAL_X);
    }
    ContractsGrantsInvoiceDetail totalCostInvoiceDetail = document.getTotalCostInvoiceDetail();
    if (ObjectUtils.isNotNull(totalCostInvoiceDetail)) {
        localParameterMap.put(CuArPropertyConstants.ContractsAndGrantsBillingAwardFields.TOTAL_PROGRAM_OUTLAYS_TO_DATE, totalCostInvoiceDetail.getTotalAmountBilledToDate().add(document.getInvoiceGeneralDetail().getCostShareAmount()));
    }
    setAwardExtendedAttributeValuesInParameterMap(document, localParameterMap);
    setPurchaseOrderNumberFieldInParameterMap(document, localParameterMap);
    if (!localParameterMap.isEmpty()) {
        LOG.debug("getInstitutionTemplateParameters, there were local parameters, these will be in the returned map.");
    }
    return localParameterMap.keySet().stream().collect(Collectors.toMap(key -> key, key -> stringifyValue(localParameterMap.get(key)), (a, b) -> b));
}
Also used : Customer(org.kuali.kfs.module.ar.businessobject.Customer) CuContractsGrantsInvoiceDocumentService(edu.cornell.kfs.module.ar.document.service.CuContractsGrantsInvoiceDocumentService) SubFundGroup(org.kuali.kfs.coa.businessobject.SubFundGroup) HashMap(java.util.HashMap) Award(org.kuali.kfs.module.cg.businessobject.Award) StringUtils(org.apache.commons.lang3.StringUtils) ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) CollectionUtils(org.apache.commons.collections4.CollectionUtils) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode) CUKFSConstants(edu.cornell.kfs.sys.CUKFSConstants) BigDecimal(java.math.BigDecimal) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) ArKeyConstants(org.kuali.kfs.module.ar.ArKeyConstants) Calendar(java.util.Calendar) Map(java.util.Map) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) CustomerExtendedAttribute(edu.cornell.kfs.module.ar.businessobject.CustomerExtendedAttribute) AwardAccountExtendedAttribute(edu.cornell.kfs.module.cg.businessobject.AwardAccountExtendedAttribute) ContractsGrantsInvoiceDocumentServiceImpl(org.kuali.kfs.module.ar.document.service.impl.ContractsGrantsInvoiceDocumentServiceImpl) Account(org.kuali.kfs.coa.businessobject.Account) RoundingMode(java.math.RoundingMode) CGIntegrationConstants(org.kuali.kfs.integration.cg.CGIntegrationConstants) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) CuArPropertyConstants(edu.cornell.kfs.module.ar.CuArPropertyConstants) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CuArParameterKeyConstants(edu.cornell.kfs.module.ar.CuArParameterKeyConstants) KFSPropertyConstants(org.kuali.kfs.sys.KFSPropertyConstants) Collectors(java.util.stream.Collectors) ObjectUtils(org.kuali.kfs.krad.util.ObjectUtils) Date(java.sql.Date) List(java.util.List) AwardExtendedAttribute(edu.cornell.kfs.module.cg.businessobject.AwardExtendedAttribute) Logger(org.apache.logging.log4j.Logger) OrganizationAccountingDefault(org.kuali.kfs.module.ar.businessobject.OrganizationAccountingDefault) SystemInformation(org.kuali.kfs.module.ar.businessobject.SystemInformation) ArPropertyConstants(org.kuali.kfs.module.ar.ArPropertyConstants) Optional(java.util.Optional) ArConstants(org.kuali.kfs.module.ar.ArConstants) LogManager(org.apache.logging.log4j.LogManager) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) HashMap(java.util.HashMap)

Example 10 with ContractsGrantsInvoiceDetail

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

the class ContractsGrantsInvoiceDocumentServiceImpl method correctContractsGrantsInvoiceDocument.

@Override
public void correctContractsGrantsInvoiceDocument(ContractsGrantsInvoiceDocument document) {
    // correct Direct Cost Invoice Details.
    for (ContractsGrantsInvoiceDetail id : document.getDirectCostInvoiceDetails()) {
        correctInvoiceDetail(id);
    }
    // correct Indirect Cost Invoice Details.
    for (ContractsGrantsInvoiceDetail id : document.getIndirectCostInvoiceDetails()) {
        correctInvoiceDetail(id);
    }
    // update correction to the InvoiceAccountDetail objects
    for (InvoiceAccountDetail id : document.getAccountDetails()) {
        correctInvoiceAccountDetail(id);
    }
    // correct invoiceDetailAccountObjectCode.
    for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : document.getInvoiceDetailAccountObjectCodes()) {
        invoiceDetailAccountObjectCode.correctInvoiceDetailAccountObjectCodeExpenditureAmount();
    }
    // correct Bills
    KualiDecimal totalBillingAmount = KualiDecimal.ZERO;
    for (InvoiceBill bill : document.getInvoiceBills()) {
        bill.setEstimatedAmount(bill.getEstimatedAmount().negated());
        totalBillingAmount = totalBillingAmount.add(bill.getEstimatedAmount());
    }
    // correct Milestones
    KualiDecimal totalMilestonesAmount = KualiDecimal.ZERO;
    for (InvoiceMilestone milestone : document.getInvoiceMilestones()) {
        milestone.setMilestoneAmount(milestone.getMilestoneAmount().negated());
        totalMilestonesAmount = totalMilestonesAmount.add(milestone.getMilestoneAmount());
    }
    document.getInvoiceGeneralDetail().setTotalPreviouslyBilled(getAwardBilledToDateAmountExcludingDocument(document.getInvoiceGeneralDetail().getProposalNumber(), document.getDocumentNumber()));
    if (ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceMilestones())) {
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalMilestonesAmount));
    } else if (ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceBills())) {
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalBillingAmount));
    } else {
        KualiDecimal newTotalBilled = document.getTotalCostInvoiceDetail().getInvoiceAmount().add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
        newTotalBilled = newTotalBilled.add(getOtherTotalBilledForAwardPeriod(document));
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(newTotalBilled);
        calculatePreviouslyBilledAmounts(document);
    }
    for (InvoiceAddressDetail invoiceAddressDetail : document.getInvoiceAddressDetails()) {
        invoiceAddressDetail.setInitialTransmissionDate(null);
        invoiceAddressDetail.setTransmittedByPrincipalId("");
        invoiceAddressDetail.setTransmissionDate(null);
        invoiceAddressDetail.setTransmissionStatusCode("");
        invoiceAddressDetail.setTransmissionCount(0);
    }
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) InvoiceBill(org.kuali.kfs.module.ar.businessobject.InvoiceBill) 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) InvoiceMilestone(org.kuali.kfs.module.ar.businessobject.InvoiceMilestone) InvoiceAddressDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Aggregations

ContractsGrantsInvoiceDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail)13 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)8 HashMap (java.util.HashMap)7 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)5 List (java.util.List)4 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)4 AwardExtendedAttribute (edu.cornell.kfs.module.cg.businessobject.AwardExtendedAttribute)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)3 Award (org.kuali.kfs.module.cg.businessobject.Award)3 Date (java.sql.Date)2 ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)2 InvoiceAddressDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail)2 InvoiceGeneralDetail (org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)2 InvoiceMilestone (org.kuali.kfs.module.ar.businessobject.InvoiceMilestone)2 ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)2 CuArParameterKeyConstants (edu.cornell.kfs.module.ar.CuArParameterKeyConstants)1 CuArPropertyConstants (edu.cornell.kfs.module.ar.CuArPropertyConstants)1 CustomerExtendedAttribute (edu.cornell.kfs.module.ar.businessobject.CustomerExtendedAttribute)1