Search in sources :

Example 6 with ContractsAndGrantsBillingAwardAccount

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createInvoicesByAward.

/**
 * Generates and saves a single Contracts & Grants Invoice Document based on the given award
 *
 * @param awd             the award to generate a Contracts & Grants Invoice Document for
 * @param errorMessages   a holder for error messages
 * @param creationProcessType invoice document creation process type
 * @param accountDetails  letter of credit details if we're creating via loc
 * @param locCreationType letter of credit creation type if we're creating via loc
 */
protected void createInvoicesByAward(ContractsAndGrantsBillingAward awd, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    // Check if award accounts has the same control account
    int accountNum = awd.getActiveAwardAccounts().size();
    Collection<Account> controlAccounts = getContractsGrantsInvoiceDocumentService().getContractControlAccounts(awd);
    if (controlAccounts == null || controlAccounts.size() < accountNum) {
        final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.BILL_BY_CONTRACT_VALID_ACCOUNTS, awd.getProposalNumber());
        errorMessages.add(errorMessage);
    } else {
        // check if control accounts of award accounts are the same
        boolean isValid = true;
        if (accountNum != 1) {
            Set<Account> distinctAwardAccounts = new HashSet<>();
            for (ContractsAndGrantsBillingAwardAccount awardAccount : awd.getActiveAwardAccounts()) {
                if (!ObjectUtils.isNull(awardAccount.getAccount().getContractControlAccount())) {
                    distinctAwardAccounts.add(awardAccount.getAccount().getContractControlAccount());
                }
            }
            if (distinctAwardAccounts.size() > 1) {
                final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.DIFFERING_CONTROL_ACCOUNTS, awd.getProposalNumber());
                errorMessages.add(errorMessage);
                isValid = false;
            }
        }
        if (isValid) {
            // To get valid award accounts of amounts > zero$ and pass it to the create invoices method
            if (!getValidAwardAccounts(awd.getActiveAwardAccounts(), awd, creationProcessType).containsAll(awd.getActiveAwardAccounts())) {
                final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NOT_ALL_BILLABLE_ACCOUNTS, awd.getProposalNumber());
                errorMessages.add(errorMessage);
            }
            /**
             * FINP-5295 changes.
             */
            generateAndSaveContractsAndGrantsInvoiceDocument(awd, getValidAwardAccounts(awd.getActiveAwardAccounts(), awd, creationProcessType), errorMessages, creationProcessType, accountDetails, locCreationType);
        }
    }
}
Also used : ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) Account(org.kuali.kfs.coa.businessobject.Account) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage) HashSet(java.util.HashSet)

Example 7 with ContractsAndGrantsBillingAwardAccount

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount 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)

Example 8 with ContractsAndGrantsBillingAwardAccount

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method checkAwardContractControlAccounts.

@Override
public List<String> checkAwardContractControlAccounts(ContractsAndGrantsBillingAward award) {
    List<String> errorString = new ArrayList<>();
    boolean isValid = true;
    int accountNum = award.getActiveAwardAccounts().size();
    // To check if invoicing options exist on the award
    if (ObjectUtils.isNotNull(award.getInvoicingOptionCode())) {
        // To check if the award account is associated with a contract control account.
        for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
            if (ObjectUtils.isNull(awardAccount.getAccount()) || ObjectUtils.isNull(awardAccount.getAccount().getContractControlAccount())) {
                isValid = false;
                break;
            }
        }
        // one / all award accounts, then throw error.
        if (award.getInvoicingOptionCode().equalsIgnoreCase(ArConstants.INV_CONTRACT_CONTROL_ACCOUNT)) {
            if (!isValid) {
                errorString.add(ArKeyConstants.AwardConstants.ERROR_NO_CTRL_ACCT);
                errorString.add(award.getInvoicingOptionDescription());
            }
        } else if (award.getInvoicingOptionCode().equalsIgnoreCase(ArConstants.INV_AWARD)) {
            // accounts, then throw error.
            if (!isValid) {
                errorString.add(ArKeyConstants.AwardConstants.ERROR_NO_CTRL_ACCT);
                errorString.add(award.getInvoicingOptionDescription());
            } else {
                if (accountNum != 1) {
                    Account tmpAcct1;
                    Account tmpAcct2;
                    Object[] awardAccounts = award.getActiveAwardAccounts().toArray();
                    for (int i = 0; i < awardAccounts.length - 1; i++) {
                        tmpAcct1 = ((ContractsAndGrantsBillingAwardAccount) awardAccounts[i]).getAccount().getContractControlAccount();
                        tmpAcct2 = ((ContractsAndGrantsBillingAwardAccount) awardAccounts[i + 1]).getAccount().getContractControlAccount();
                        // account assigned for the award, then throw error.
                        if (ObjectUtils.isNull(tmpAcct1) || !tmpAcct1.equals(tmpAcct2)) {
                            errorString.add(ArKeyConstants.AwardConstants.ERROR_MULTIPLE_CTRL_ACCT);
                            errorString.add(award.getInvoicingOptionDescription());
                        }
                    }
                }
            }
        }
    }
    return errorString;
}
Also used : ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) Account(org.kuali.kfs.coa.businessobject.Account) ArrayList(java.util.ArrayList) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)

Example 9 with ContractsAndGrantsBillingAwardAccount

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method populateInvoiceFromAward.

/*
     * CU Customization (KFSPTS-23675):
     * Added creationProcessType argument and its usage of it.
     */
/**
 * This method takes all the applicable attributes from the associated award object and sets those attributes into
 * their corresponding invoice attributes.
 *
 * @param award           The associated award that the invoice will be linked to.
 * @param awardAccounts
 * @param document
 * @param accountDetails  letter of credit details if we're creating via loc
 * @param locCreationType letter of credit creation type if we're creating via loc
 * @param creationProcessType The creation process type for the related invoice
 */
protected void populateInvoiceFromAward(ContractsAndGrantsBillingAward award, List<ContractsAndGrantsBillingAwardAccount> awardAccounts, ContractsGrantsInvoiceDocument document, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
    if (ObjectUtils.isNotNull(award)) {
        InvoiceGeneralDetail invoiceGeneralDetail = new InvoiceGeneralDetail();
        invoiceGeneralDetail.setDocumentNumber(document.getDocumentNumber());
        invoiceGeneralDetail.setProposalNumber(award.getProposalNumber());
        invoiceGeneralDetail.setAward(award);
        Timestamp ts = new Timestamp(new java.util.Date().getTime());
        java.sql.Date today = new java.sql.Date(ts.getTime());
        AccountingPeriod currPeriod = accountingPeriodService.getByDate(today);
        BillingPeriod billingPeriod = verifyBillingFrequencyService.getStartDateAndEndDateOfPreviousBillingPeriod(award, currPeriod, creationProcessType);
        invoiceGeneralDetail.setBillingPeriod(getDateTimeService().toDateString(billingPeriod.getStartDate()) + " to " + getDateTimeService().toDateString(billingPeriod.getEndDate()));
        invoiceGeneralDetail.setLastBilledDate(billingPeriod.getEndDate());
        populateInvoiceDetailFromAward(invoiceGeneralDetail, award);
        document.setInvoiceGeneralDetail(invoiceGeneralDetail);
        // To set Bill by address identifier because it is a required field - set the value to 1 as it is never
        // being used.
        document.setCustomerBillToAddressIdentifier(1);
        // Set Invoice due date to current date as it is required field and never used.
        document.setInvoiceDueDate(dateTimeService.getCurrentSqlDateMidnight());
        document.getInvoiceAddressDetails().clear();
        ContractsAndGrantsBillingAgency agency = award.getAgency();
        if (ObjectUtils.isNotNull(agency)) {
            final List<InvoiceAddressDetail> invoiceAddressDetails = buildInvoiceAddressDetails(award, document);
            document.getInvoiceAddressDetails().addAll(invoiceAddressDetails);
        }
        if (ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail())) {
            ContractsAndGrantsBillingAwardAccount awardAccount = awardAccounts.get(0);
            final List<Milestone> milestones = getContractsGrantsBillingUtilityService().getActiveMilestonesForProposalNumber(award.getProposalNumber(), awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber());
            if (!CollectionUtils.isEmpty(milestones)) {
                document.getInvoiceMilestones().clear();
                document.getInvoiceMilestones().addAll(buildInvoiceMilestones(milestones));
            }
        } else if (ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail())) {
            ContractsAndGrantsBillingAwardAccount awardAccount = awardAccounts.get(0);
            final List<Bill> bills = getContractsGrantsBillingUtilityService().getActiveBillsForAwardAccount(award.getProposalNumber(), awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber());
            if (!CollectionUtils.isEmpty(bills)) {
                document.getInvoiceBills().clear();
                document.getInvoiceBills().addAll(buildInvoiceBills(bills));
            }
        }
        document.getAccountDetails().clear();
        final List<InvoiceAccountDetail> invoiceAccountDetails = new ArrayList<>();
        List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectsCodes = new ArrayList<>();
        Map<String, KualiDecimal> budgetAmountsByCostCategory = new HashMap<>();
        Integer currentYear = getUniversityDateService().getCurrentFiscalYear();
        final boolean firstFiscalPeriod = isFirstFiscalPeriod();
        final Integer fiscalYear = firstFiscalPeriod && ArConstants.BillingFrequencyValues.isTimeBased(document.getInvoiceGeneralDetail()) ? currentYear - 1 : currentYear;
        final SystemOptions systemOptions = optionsService.getOptions(fiscalYear);
        List<String> balanceTypeCodeList = new ArrayList<>();
        balanceTypeCodeList.add(systemOptions.getBudgetCheckingBalanceTypeCd());
        balanceTypeCodeList.add(systemOptions.getActualFinancialBalanceTypeCd());
        for (ContractsAndGrantsBillingAwardAccount awardAccount : awardAccounts) {
            InvoiceAccountDetail invoiceAccountDetail = buildInvoiceAccountDetailForAwardAccount(awardAccount, document.getDocumentNumber());
            final ContractsGrantsLetterOfCreditReviewDetail locReviewDetail = retrieveMatchingLetterOfCreditReviewDetail(awardAccount, accountDetails);
            List<Balance> glBalances = retrieveBalances(fiscalYear, awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber(), balanceTypeCodeList);
            KualiDecimal awardAccountBudgetAmount = KualiDecimal.ZERO;
            KualiDecimal awardAccountCumulativeAmount = KualiDecimal.ZERO;
            for (Balance balance : glBalances) {
                if (!isBalanceCostShare(balance)) {
                    if (balance.getBalanceTypeCode().equalsIgnoreCase(systemOptions.getBudgetCheckingBalanceTypeCd())) {
                        awardAccountBudgetAmount = addBalanceToAwardAccountBudgetAmount(balance, awardAccountBudgetAmount, firstFiscalPeriod);
                        updateCategoryBudgetAmountsByBalance(balance, budgetAmountsByCostCategory, firstFiscalPeriod);
                    } else if (balance.getBalanceTypeCode().equalsIgnoreCase(systemOptions.getActualFinancialBalanceTypeCd())) {
                        awardAccountCumulativeAmount = addBalanceToAwardAccountCumulativeAmount(document, balance, award, awardAccountCumulativeAmount, firstFiscalPeriod);
                        updateCategoryActualAmountsByBalance(document, balance, award, invoiceDetailAccountObjectsCodes, firstFiscalPeriod);
                    }
                }
                invoiceAccountDetail.setTotalBudget(awardAccountBudgetAmount);
                invoiceAccountDetail.setCumulativeExpenditures(awardAccountCumulativeAmount);
            }
            invoiceAccountDetails.add(invoiceAccountDetail);
            if (!ObjectUtils.isNull(locReviewDetail) && !locReviewDetail.getClaimOnCashBalance().negated().equals(locReviewDetail.getAmountToDraw()) && ArConstants.BillingFrequencyValues.isLetterOfCredit(award)) {
                distributeAmountAmongAllAccountObjectCodes(document, awardAccount, invoiceDetailAccountObjectsCodes, locReviewDetail);
            } else {
                updateInvoiceDetailAccountObjectCodesByBilledAmount(awardAccount, invoiceDetailAccountObjectsCodes);
            }
        }
        document.getAccountDetails().addAll(invoiceAccountDetails);
        if (!ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail()) && !ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail())) {
            document.getInvoiceDetailAccountObjectCodes().addAll(invoiceDetailAccountObjectsCodes);
            List<AwardAccountObjectCodeTotalBilled> awardAccountObjectCodeTotalBilleds = getAwardAccountObjectCodeTotalBilledDao().getAwardAccountObjectCodeTotalBuildByProposalNumberAndAccount(awardAccounts);
            List<ContractsGrantsInvoiceDetail> invoiceDetails = generateValuesForCategories(document.getDocumentNumber(), document.getInvoiceDetailAccountObjectCodes(), budgetAmountsByCostCategory, awardAccountObjectCodeTotalBilleds);
            document.getInvoiceDetails().addAll(invoiceDetails);
        }
        populateContractsGrantsInvoiceDocument(award, document, accountDetails, locCreationType);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) Timestamp(java.sql.Timestamp) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ArrayList(java.util.ArrayList) List(java.util.List) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) InvoiceAddressDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail) ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) BillingPeriod(org.kuali.kfs.module.ar.businessobject.BillingPeriod) InvoiceMilestone(org.kuali.kfs.module.ar.businessobject.InvoiceMilestone) Milestone(org.kuali.kfs.module.ar.businessobject.Milestone) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) ContractsAndGrantsBillingAgency(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAgency) AwardAccountObjectCodeTotalBilled(org.kuali.kfs.module.ar.businessobject.AwardAccountObjectCodeTotalBilled) Date(java.sql.Date) Date(java.sql.Date) ContractsGrantsLetterOfCreditReviewDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Balance(org.kuali.kfs.gl.businessobject.Balance) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 10 with ContractsAndGrantsBillingAwardAccount

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method calculateTotalExpenditureAmount.

protected KualiDecimal calculateTotalExpenditureAmount(ContractsGrantsInvoiceDocument document, List<ContractsGrantsLetterOfCreditReviewDetail> locReviewDetails) {
    Map<String, KualiDecimal> totalBilledByAccountNumberMap = new HashMap<>();
    for (InvoiceDetailAccountObjectCode objectCode : document.getInvoiceDetailAccountObjectCodes()) {
        final String key = objectCode.getChartOfAccountsCode() + "-" + objectCode.getAccountNumber();
        KualiDecimal totalBilled = cleanAmount(totalBilledByAccountNumberMap.get(key));
        totalBilled = totalBilled.add(objectCode.getTotalBilled());
        totalBilledByAccountNumberMap.put(key, totalBilled);
    }
    KualiDecimal totalExpendituredAmount = KualiDecimal.ZERO;
    for (InvoiceAccountDetail invAcctD : document.getAccountDetails()) {
        final String chartOfAccountsCode = invAcctD.getChartOfAccountsCode();
        final String accountNumber = invAcctD.getAccountNumber();
        final String key = chartOfAccountsCode + "-" + accountNumber;
        if (!ObjectUtils.isNull(totalBilledByAccountNumberMap.get(key))) {
            invAcctD.setTotalPreviouslyBilled(totalBilledByAccountNumberMap.get(key));
        } else {
            invAcctD.setTotalPreviouslyBilled(KualiDecimal.ZERO);
        }
        if (invAcctD.getTotalPreviouslyBilled().isZero()) {
            String proposalNumber = document.getInvoiceGeneralDetail().getProposalNumber();
            KualiDecimal previouslyBilledAmount = KualiDecimal.ZERO;
            previouslyBilledAmount = previouslyBilledAmount.add(contractsGrantsInvoiceDocumentService.getPredeterminedBillingBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber));
            previouslyBilledAmount = previouslyBilledAmount.add(contractsGrantsInvoiceDocumentService.getMilestonesBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber));
            invAcctD.setTotalPreviouslyBilled(previouslyBilledAmount);
        }
        KualiDecimal currentExpenditureAmount = invAcctD.getCumulativeExpenditures().subtract(invAcctD.getTotalPreviouslyBilled());
        invAcctD.setInvoiceAmount(currentExpenditureAmount);
        // overwrite account detail expenditure amount if locReview Indicator is true and award is LOC Billing
        if (!ObjectUtils.isNull(document.getInvoiceGeneralDetail())) {
            ContractsAndGrantsBillingAward award = document.getInvoiceGeneralDetail().getAward();
            if (ObjectUtils.isNotNull(award) && ArConstants.BillingFrequencyValues.isLetterOfCredit(award) && !CollectionUtils.isEmpty(locReviewDetails)) {
                for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                    final ContractsGrantsLetterOfCreditReviewDetail locReviewDetail = retrieveMatchingLetterOfCreditReviewDetail(awardAccount, locReviewDetails);
                    if (!ObjectUtils.isNull(locReviewDetail) && StringUtils.equals(awardAccount.getChartOfAccountsCode(), chartOfAccountsCode) && StringUtils.equals(awardAccount.getAccountNumber(), accountNumber)) {
                        currentExpenditureAmount = locReviewDetail.getAmountToDraw();
                        invAcctD.setInvoiceAmount(currentExpenditureAmount);
                    }
                }
            }
        }
        totalExpendituredAmount = totalExpendituredAmount.add(currentExpenditureAmount);
    }
    totalExpendituredAmount = totalExpendituredAmount.add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
    return totalExpendituredAmount;
}
Also used : HashMap(java.util.HashMap) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode) ContractsGrantsLetterOfCreditReviewDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail)

Aggregations

ContractsAndGrantsBillingAwardAccount (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)13 ArrayList (java.util.ArrayList)6 Account (org.kuali.kfs.coa.businessobject.Account)5 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)5 ContractsGrantsInvoiceDocumentErrorMessage (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)5 Date (java.sql.Date)4 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)4 ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)3 ErrorMessage (org.kuali.kfs.krad.util.ErrorMessage)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ContractsGrantsInvoiceDocumentErrorLog (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorLog)2 ContractsGrantsLetterOfCreditReviewDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail)2 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)2 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)2 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)1 Balance (org.kuali.kfs.gl.businessobject.Balance)1