Search in sources :

Example 6 with InvoiceDetailAccountObjectCode

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

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

Example 8 with InvoiceDetailAccountObjectCode

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

the class ContractsGrantsInvoiceDocumentServiceImpl method addToAccountObjectCodeBilledTotal.

@Override
public void addToAccountObjectCodeBilledTotal(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes) {
    for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
        Map<String, Object> totalBilledKeys = new HashMap<>();
        totalBilledKeys.put(KFSPropertyConstants.PROPOSAL_NUMBER, invoiceDetailAccountObjectCode.getProposalNumber());
        totalBilledKeys.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, invoiceDetailAccountObjectCode.getChartOfAccountsCode());
        totalBilledKeys.put(KFSPropertyConstants.ACCOUNT_NUMBER, invoiceDetailAccountObjectCode.getAccountNumber());
        totalBilledKeys.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, invoiceDetailAccountObjectCode.getFinancialObjectCode());
        List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilledList = (List<AwardAccountObjectCodeTotalBilled>) businessObjectService.findMatching(AwardAccountObjectCodeTotalBilled.class, totalBilledKeys);
        AwardAccountObjectCodeTotalBilled awardAccountObjectCodeTotalBilled = new AwardAccountObjectCodeTotalBilled();
        if (awardAccountObjectCodeTotalBilledList != null && !awardAccountObjectCodeTotalBilledList.isEmpty()) {
            awardAccountObjectCodeTotalBilled = awardAccountObjectCodeTotalBilledList.get(0);
            awardAccountObjectCodeTotalBilled.setTotalBilled(awardAccountObjectCodeTotalBilled.getTotalBilled().add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
        } else {
            awardAccountObjectCodeTotalBilled.setProposalNumber(invoiceDetailAccountObjectCode.getProposalNumber());
            awardAccountObjectCodeTotalBilled.setChartOfAccountsCode(invoiceDetailAccountObjectCode.getChartOfAccountsCode());
            awardAccountObjectCodeTotalBilled.setAccountNumber(invoiceDetailAccountObjectCode.getAccountNumber());
            awardAccountObjectCodeTotalBilled.setFinancialObjectCode(invoiceDetailAccountObjectCode.getFinancialObjectCode());
            awardAccountObjectCodeTotalBilled.setTotalBilled(invoiceDetailAccountObjectCode.getCurrentExpenditures());
        }
        getBusinessObjectService().save(awardAccountObjectCodeTotalBilled);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) AwardAccountObjectCodeTotalBilled(org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 9 with InvoiceDetailAccountObjectCode

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

the class ContractsGrantsInvoiceDocumentServiceImpl method recalculateObjectCodeByCategory.

/**
 * This method recalculates the invoiceDetailAccountObjectCode in one category that sits behind the scenes of the
 * invoice document.
 *
 * @param contractsGrantsInvoiceDocument
 * @param invoiceDetail
 * @param total                           is the sum of the current expenditures from all the object codes in
 *                                        that category
 * @param invoiceDetailAccountObjectCodes
 */
protected void recalculateObjectCodeByCategory(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument, ContractsGrantsInvoiceDetail invoiceDetail, KualiDecimal total, List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes) {
    KualiDecimal currentExpenditure = invoiceDetail.getInvoiceAmount();
    KualiDecimal newTotalAmount = KualiDecimal.ZERO;
    // the category
    if (total.compareTo(KualiDecimal.ZERO) == 0) {
        if (invoiceDetailAccountObjectCodes != null) {
            int numberOfObjectCodes = invoiceDetailAccountObjectCodes.size();
            if (numberOfObjectCodes != 0) {
                KualiDecimal newAmount = new KualiDecimal(currentExpenditure.bigDecimalValue().divide(new BigDecimal(numberOfObjectCodes), 10, RoundingMode.HALF_DOWN));
                for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
                    invoiceDetailAccountObjectCode.setCurrentExpenditures(newAmount);
                    newTotalAmount = newTotalAmount.add(newAmount);
                }
            }
        } else {
            // if the list is null, then there are no account/object code in the gl_balance_t. So assign the
            // amount to the first object code in the category
            assignCurrentExpenditureToNonExistingAccountObjectCode(contractsGrantsInvoiceDocument, invoiceDetail);
        }
    } else {
        for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : invoiceDetailAccountObjectCodes) {
            // this may rarely happen
            // if the initial total is 0, that means none of the object codes in this category is set to bill.
            // If this amount is changed, then just divide evenly among all object codes.
            KualiDecimal newAmount = new KualiDecimal(invoiceDetailAccountObjectCode.getCurrentExpenditures().bigDecimalValue().divide(total.bigDecimalValue(), 10, RoundingMode.HALF_DOWN).multiply(currentExpenditure.bigDecimalValue()));
            invoiceDetailAccountObjectCode.setCurrentExpenditures(newAmount);
            newTotalAmount = newTotalAmount.add(newAmount);
        }
        int remainderFromRounding = currentExpenditure.subtract(newTotalAmount).multiply(new KualiDecimal(100)).intValue();
        // add remainder from rounding
        KualiDecimal addAmount = new KualiDecimal(0.01);
        if (remainderFromRounding < 0) {
            addAmount = new KualiDecimal(-0.01);
            remainderFromRounding = Math.abs(remainderFromRounding);
        }
        int objectCodeIndex = 0;
        for (int i = 0; i < remainderFromRounding; i++) {
            InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = invoiceDetailAccountObjectCodes.get(objectCodeIndex);
            invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().add(addAmount));
            objectCodeIndex++;
            if (objectCodeIndex >= invoiceDetailAccountObjectCodes.size()) {
                objectCodeIndex = 0;
            }
        }
    }
}
Also used : AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) BigDecimal(java.math.BigDecimal) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 10 with InvoiceDetailAccountObjectCode

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

the class ContractsGrantsInvoiceDocumentServiceImpl method getCategoryExpenditureAmountsForInvoiceAccountDetail.

/**
 * Totals the current expenditure amounts of any invoice detail account object codes on the document which have set
 * categories by account numbers
 *
 * @param contractsGrantsInvoiceDocument the document holding invoice detail account object codes
 * @return a Map where the key is the concatenation of chartOfAccountsCode-accountNumber and the value is the
 * expenditure amount on that account
 */
protected Map<String, KualiDecimal> getCategoryExpenditureAmountsForInvoiceAccountDetail(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
    Map<String, KualiDecimal> expenditureAmounts = new HashMap<>();
    for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : contractsGrantsInvoiceDocument.getInvoiceDetailAccountObjectCodes()) {
        final String accountKey = StringUtils.join(new String[] { invoiceDetailAccountObjectCode.getChartOfAccountsCode(), invoiceDetailAccountObjectCode.getAccountNumber() }, "-");
        if (StringUtils.isNotBlank(invoiceDetailAccountObjectCode.getCategoryCode())) {
            KualiDecimal total = expenditureAmounts.get(accountKey);
            if (ObjectUtils.isNull(total)) {
                total = KualiDecimal.ZERO;
            }
            expenditureAmounts.put(accountKey, total.add(invoiceDetailAccountObjectCode.getCurrentExpenditures()));
        }
    }
    return expenditureAmounts;
}
Also used : HashMap(java.util.HashMap) AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Aggregations

InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)16 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)10 HashMap (java.util.HashMap)8 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)5 ContractsGrantsInvoiceDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail)4 AwardAccountObjectCodeTotalBilled (org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled)3 CostCategory (org.kuali.kfs.module.ar.businessobject.CostCategory)3 BigDecimal (java.math.BigDecimal)2 ContractsAndGrantsBillingAwardAccount (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)2 ContractsGrantsLetterOfCreditReviewDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail)2 InvoiceAddressDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail)2 InvoiceMilestone (org.kuali.kfs.module.ar.businessobject.InvoiceMilestone)2 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)1 ObjectCodeCurrent (org.kuali.kfs.coa.businessobject.ObjectCodeCurrent)1