Search in sources :

Example 1 with ContractsAndGrantsBillingAward

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createInvoices.

/**
 * This method iterates through awards and create cgInvoice documents
 *
 * @param awards          used to create cgInvoice documents
 * @param creationProcessType  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
 * @return List of error messages (if any)
 */
protected List<ErrorMessage> createInvoices(Collection<ContractsAndGrantsBillingAward> awards, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    List<ErrorMessage> errorMessages = new ArrayList<>();
    if (ObjectUtils.isNotNull(awards) && awards.size() > 0) {
        for (ContractsAndGrantsBillingAward awd : awards) {
            String invOpt = awd.getInvoicingOptionCode();
            final ContractsAndGrantsOrganization awardOrganization = awd.getPrimaryAwardOrganization();
            if (ObjectUtils.isNull(awardOrganization)) {
                final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_ORGANIZATION_ON_AWARD, awd.getProposalNumber());
                errorMessages.add(errorMessage);
            } else {
                switch(invOpt) {
                    case ArConstants.INV_ACCOUNT:
                    case ArConstants.INV_SCHEDULE:
                        createInvoicesByAccounts(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
                        break;
                    case ArConstants.INV_CONTRACT_CONTROL_ACCOUNT:
                        createInvoicesByContractControlAccounts(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
                        break;
                    case ArConstants.INV_AWARD:
                        createInvoicesByAward(awd, errorMessages, creationProcessType, accountDetails, locCreationType);
                        break;
                    default:
                        break;
                }
            }
        }
    } else {
        final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_AWARD);
        errorMessages.add(errorMessage);
    }
    return errorMessages;
}
Also used : ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) ArrayList(java.util.ArrayList) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage) ContractsAndGrantsOrganization(org.kuali.kfs.integration.cg.ContractsAndGrantsOrganization)

Example 2 with ContractsAndGrantsBillingAward

use of org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward 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 3 with ContractsAndGrantsBillingAward

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

the class ContractsGrantsInvoiceDocumentServiceImpl method buildInvoiceGeneralDetailFieldsMap.

private Map<String, Object> buildInvoiceGeneralDetailFieldsMap(ContractsGrantsInvoiceDocument document) {
    Map<String, Object> invoiceGeneralDetailFieldsMap = new HashMap<>();
    InvoiceGeneralDetail invoiceGeneralDetail = document.getInvoiceGeneralDetail();
    if (ObjectUtils.isNotNull(invoiceGeneralDetail)) {
        invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.ADVANCE_FLAG, ArConstants.BillingFrequencyValues.isPredeterminedBilling(invoiceGeneralDetail));
        invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.REIMBURSEMENT_FLAG, !ArConstants.BillingFrequencyValues.isPredeterminedBilling(invoiceGeneralDetail));
        invoiceGeneralDetailFieldsMap.put(KFSPropertyConstants.PROPOSAL_NUMBER, invoiceGeneralDetail.getProposalNumber());
        final String prefix = ArPropertyConstants.INVOICE_GENERAL_DETAIL + ".";
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.AWARD_DATE_RANGE, invoiceGeneralDetail.getAwardDateRange());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.BILLING_FREQUENCY_CODE, invoiceGeneralDetail.getBillingFrequencyCode());
        invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.FINAL_BILL, invoiceGeneralDetail.isFinalBillIndicator());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.BILLING_PERIOD, invoiceGeneralDetail.getBillingPeriod());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.INSTRUMENT_TYPE_CODE, invoiceGeneralDetail.getInstrumentTypeCode());
        invoiceGeneralDetailFieldsMap.put(prefix + ArConstants.AWARD_TOTAL, invoiceGeneralDetail.getAwardTotal());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.AMOUNT_REMAINING_TO_BILL, invoiceGeneralDetail.getAmountRemainingToBill());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.COST_SHARE_AMOUNT, invoiceGeneralDetail.getCostShareAmount());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.LAST_BILLED_DATE, invoiceGeneralDetail.getLastBilledDate());
        invoiceGeneralDetailFieldsMap.put(prefix + ArPropertyConstants.TOTAL_PREVIOUSLY_BILLED, invoiceGeneralDetail.getTotalPreviouslyBilled());
        invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.TOTAL_AMOUNT_DUE, getTotalAmountForInvoice(document));
        invoiceGeneralDetailFieldsMap.put(ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER + "." + ArPropertyConstants.FULL_ADDRESS, contractsGrantsBillingUtilityService.buildFullAddress(invoiceGeneralDetail.getCustomerAddress()));
        ContractsAndGrantsBillingAward award = invoiceGeneralDetail.getAward();
        if (ObjectUtils.isNotNull(award)) {
            invoiceGeneralDetailFieldsMap.putAll(buildAwardFieldsMap(award));
        }
    }
    return invoiceGeneralDetailFieldsMap;
}
Also used : HashMap(java.util.HashMap) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)

Example 4 with ContractsAndGrantsBillingAward

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

the class ContractsGrantsInvoiceDocumentServiceImpl method determineContractControlAccountNumber.

// access relaxed for Cornell
protected String determineContractControlAccountNumber(ContractsGrantsInvoiceDocument document) {
    final InvoiceGeneralDetail invoiceGeneralDetail = document.getInvoiceGeneralDetail();
    if (ObjectUtils.isNotNull(invoiceGeneralDetail)) {
        final ContractsAndGrantsBillingAward award = invoiceGeneralDetail.getAward();
        if (ObjectUtils.isNotNull(award)) {
            final List<Account> contractControlAccounts = getContractControlAccounts(award);
            if (CollectionUtils.isNotEmpty(contractControlAccounts)) {
                return contractControlAccounts.get(0).getAccountNumber();
            }
        }
    }
    final List<InvoiceAccountDetail> accountDetails = document.getAccountDetails();
    if (CollectionUtils.isNotEmpty(accountDetails)) {
        return accountDetails.get(0).getAccountNumber();
    }
    return null;
}
Also used : ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) Account(org.kuali.kfs.coa.businessobject.Account) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)

Example 5 with ContractsAndGrantsBillingAward

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

Aggregations

ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)11 HashMap (java.util.HashMap)4 ContractsAndGrantsBillingAwardAccount (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)4 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)3 ContractsGrantsInvoiceDocumentErrorMessage (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)3 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)3 Date (java.sql.Date)2 ArrayList (java.util.ArrayList)2 ContractsGrantsInvoiceDocumentErrorLog (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorLog)2 InvoiceGeneralDetail (org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)2 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 List (java.util.List)1 Account (org.kuali.kfs.coa.businessobject.Account)1 ContractsAndGrantsOrganization (org.kuali.kfs.integration.cg.ContractsAndGrantsOrganization)1 ErrorMessage (org.kuali.kfs.krad.util.ErrorMessage)1 ContractsGrantsLetterOfCreditReviewDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail)1 CustomerInvoiceDetail (org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail)1