Search in sources :

Example 1 with ContractsAndGrantsBillingAwardAccount

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

the class CuContractsGrantsInvoiceCreateDocumentServiceImpl method getValidAwardAccounts.

/*
     * CUMod: KFSPTS-13256
     * Added evaluation of account sub-fund not being an expenditure to existing base code evaluation
     * of billing frequency and invoice document status when determining valid award accounts.
     * Expenditure sub-funds associated to accounts to exclude are defined in CG system parameter
     * CG_INVOICING_EXCLUDE_EXPENSES_SUB_FUNDS.
     */
@Override
protected List<ContractsAndGrantsBillingAwardAccount> getValidAwardAccounts(List<ContractsAndGrantsBillingAwardAccount> awardAccounts, ContractsAndGrantsBillingAward award, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
    LOG.info("getValidAwardAccounts: CU Customization invoked with creationProcessTypeCode = " + ArConstants.ContractsAndGrantsInvoiceDocumentCreationProcessType.getName(creationProcessType.getCode()));
    if (!ArConstants.BillingFrequencyValues.isMilestone(award) && !ArConstants.BillingFrequencyValues.isPredeterminedBilling(award)) {
        List<ContractsAndGrantsBillingAwardAccount> validAwardAccounts = new ArrayList<>();
        Set<Account> invalidAccounts = harvestAccountsFromContractsGrantsInvoices(getInProgressInvoicesForAward(award));
        for (ContractsAndGrantsBillingAwardAccount awardAccount : awardAccounts) {
            if (!invalidAccounts.contains(awardAccount.getAccount())) {
                boolean checkGracePeriod = ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL != creationProcessType;
                // CUMod KFSPTS-13256, KFSPTS-23675
                if (verifyBillingFrequencyService.validateBillingFrequency(award, awardAccount, checkGracePeriod, creationProcessType) && isNotExpenditureAccount(awardAccount)) {
                    LOG.info("getValidAwardAccounts: Evaluation of account sub-fund not being an expenditure was performed.");
                    validAwardAccounts.add(awardAccount);
                }
            }
        }
        return validAwardAccounts;
    } else {
        return awardAccounts;
    }
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) ArrayList(java.util.ArrayList) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)

Example 2 with ContractsAndGrantsBillingAwardAccount

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

the class CuContractsGrantsInvoiceCreateDocumentServiceImpl method storeValidationErrors.

/**
 * Fixes NullPointerException that can occur when getting the award total amount.
 * award.getAwardTotalAmount().bigDecimalValue() causes the NullPointerException if the total amount returned null.
 */
@Override
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);
            KualiDecimal awardTotalAmount = award.getAwardTotalAmount() == null ? KualiDecimal.ZERO : award.getAwardTotalAmount();
            contractsGrantsInvoiceDocumentErrorLog.setAwardTotalAmount(awardTotalAmount.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 3 with ContractsAndGrantsBillingAwardAccount

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

the class AwardExtensionRule method checkBillingFrequency.

/**
 * Checks for null on the nullable Billing Frequency Code field. Fixes NullPointerException.
 */
@Override
protected boolean checkBillingFrequency() {
    boolean success = true;
    String newBillingFrequencyCode = newAwardCopy.getBillingFrequencyCode();
    String oldBillingFrequencyCode = oldAwardCopy.getBillingFrequencyCode();
    if (!StringUtils.equals(newBillingFrequencyCode, oldBillingFrequencyCode)) {
        final String proposalNumber = newAwardCopy.getProposalNumber();
        for (ContractsAndGrantsBillingAwardAccount awardAccount : newAwardCopy.getActiveAwardAccounts()) {
            if (StringUtils.equals(oldBillingFrequencyCode, CGConstants.MILESTONE_BILLING_SCHEDULE_CODE) && SpringContext.getBean(AccountsReceivableModuleBillingService.class).hasActiveUnbilledMilestones(proposalNumber, awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber())) {
                success = false;
                putFieldError(CGPropertyConstants.AwardFields.BILLING_FREQUENCY_CODE, CGKeyConstants.AwardConstants.ERROR_CG_ACTIVE_MILESTONES_EXIST, getBillingFrequencyDescription(newAwardCopy));
                break;
            } else if (StringUtils.equals(oldBillingFrequencyCode, CGConstants.PREDETERMINED_BILLING_SCHEDULE_CODE) && SpringContext.getBean(AccountsReceivableModuleBillingService.class).hasActiveUnbilledBills(proposalNumber, awardAccount.getChartOfAccountsCode(), awardAccount.getAccountNumber())) {
                success = false;
                putFieldError(CGPropertyConstants.AwardFields.BILLING_FREQUENCY_CODE, CGKeyConstants.AwardConstants.ERROR_CG_ACTIVE_BILLS_EXIST, getBillingFrequencyDescription(newAwardCopy));
                break;
            }
        }
    }
    return success;
}
Also used : ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) AccountsReceivableModuleBillingService(org.kuali.kfs.integration.ar.AccountsReceivableModuleBillingService)

Example 4 with ContractsAndGrantsBillingAwardAccount

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

the class ContractsGrantsInvoiceDocumentServiceImpl method getLastBilledDate.

@Override
public java.sql.Date getLastBilledDate(ContractsAndGrantsBillingAward award) {
    java.sql.Date awdLastBilledDate = null;
    if (ObjectUtils.isNotNull(award)) {
        if (CollectionUtils.isNotEmpty(award.getActiveAwardAccounts())) {
            ContractsAndGrantsBillingAwardAccount firstActiveAwardAccount = award.getActiveAwardAccounts().get(0);
            awdLastBilledDate = firstActiveAwardAccount.getCurrentLastBilledDate();
            for (int i = 0; i < award.getActiveAwardAccounts().size(); i++) {
                if (ObjectUtils.isNull(awdLastBilledDate) || ObjectUtils.isNull(award.getActiveAwardAccounts().get(i).getCurrentLastBilledDate())) {
                    // The dates would be null if the user is correcting the first invoice created for the award.
                    // Then the award last billed date should also be null.
                    awdLastBilledDate = null;
                } else if (ObjectUtils.isNotNull(awdLastBilledDate) && ObjectUtils.isNotNull(award.getActiveAwardAccounts().get(i).getCurrentLastBilledDate())) {
                    if (awdLastBilledDate.after(award.getActiveAwardAccounts().get(i).getCurrentLastBilledDate())) {
                        awdLastBilledDate = award.getActiveAwardAccounts().get(i).getCurrentLastBilledDate();
                    }
                }
            }
        }
    }
    return awdLastBilledDate;
}
Also used : ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)

Example 5 with ContractsAndGrantsBillingAwardAccount

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

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