Search in sources :

Example 11 with ContractsAndGrantsBillingAwardAccount

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createInvoicesByContractControlAccounts.

/**
 * Generates and saves Contracts & Grants Invoice Documents based on the given award's contract control accounts
 *
 * @param awd             the award with contract control accounts to build Contracts & Grants Invoice Documents from
 * @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 createInvoicesByContractControlAccounts(ContractsAndGrantsBillingAward awd, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    List<ContractsAndGrantsBillingAwardAccount> tmpAcctList = new ArrayList<>();
    List<Account> controlAccounts = getContractsGrantsInvoiceDocumentService().getContractControlAccounts(awd);
    List<Account> controlAccountsTemp = getContractsGrantsInvoiceDocumentService().getContractControlAccounts(awd);
    // to check if the number of contract control accounts is same as the number of accounts
    if (controlAccounts == null || (controlAccounts.size() != awd.getActiveAwardAccounts().size())) {
        final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_CONTROL_ACCOUNT, awd.getProposalNumber());
        errorMessages.add(errorMessage);
    } else {
        Set<Account> controlAccountSet = new HashSet<>();
        for (int i = 0; i < controlAccountsTemp.size(); i++) {
            if (ObjectUtils.isNotNull(controlAccountsTemp.get(i))) {
                for (int j = i + 1; j < controlAccounts.size(); j++) {
                    if (controlAccountsTemp.get(i).equals(controlAccounts.get(j))) {
                        controlAccounts.set(j, null);
                    }
                }
            } else {
                break;
            }
        }
        for (Account ctrlAcct : controlAccounts) {
            if (ObjectUtils.isNotNull(ctrlAcct)) {
                controlAccountSet.add(ctrlAcct);
            }
        }
        if (controlAccountSet.size() != 0) {
            for (Account controlAccount : controlAccountSet) {
                Account tmpCtrlAcct;
                tmpAcctList.clear();
                for (ContractsAndGrantsBillingAwardAccount awardAccount : awd.getActiveAwardAccounts()) {
                    if (!awardAccount.isFinalBilledIndicator()) {
                        tmpCtrlAcct = awardAccount.getAccount().getContractControlAccount();
                        if (tmpCtrlAcct.getChartOfAccountsCode().equals(controlAccount.getChartOfAccountsCode()) && tmpCtrlAcct.getAccountNumber().equals(controlAccount.getAccountNumber())) {
                            tmpAcctList.add(awardAccount);
                        }
                    }
                }
                // To get valid award accounts of amounts > zero$ and pass it to the create invoices method
                if (!getValidAwardAccounts(tmpAcctList, awd, creationProcessType).containsAll(tmpAcctList)) {
                    final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.CONTROL_ACCOUNT_NON_BILLABLE, controlAccount.getAccountNumber(), awd.getProposalNumber());
                    errorMessages.add(errorMessage);
                }
                /**
                 * FINP-5295 changes.
                 */
                generateAndSaveContractsAndGrantsInvoiceDocument(awd, getValidAwardAccounts(tmpAcctList, awd, creationProcessType), errorMessages, creationProcessType, accountDetails, locCreationType);
            }
        } else {
            final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.BILL_BY_CONTRACT_LACKS_CONTROL_ACCOUNT, awd.getProposalNumber());
            errorMessages.add(errorMessage);
        }
    }
}
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) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage) HashSet(java.util.HashSet)

Example 12 with ContractsAndGrantsBillingAwardAccount

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method getValidAwardAccounts.

/**
 * @param awardAccounts
 * @param creationProcessType invoice document creation process type
 * @return the valid award accounts based on evaluation of billing frequency and invoice document status
 */
protected List<ContractsAndGrantsBillingAwardAccount> getValidAwardAccounts(List<ContractsAndGrantsBillingAwardAccount> awardAccounts, ContractsAndGrantsBillingAward award, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
    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;
                /*
                     * CU Customization (KFSPTS-23675):
                     * Include creationProcessType in the method call.
                     */
                if (verifyBillingFrequencyService.validateBillingFrequency(award, awardAccount, checkGracePeriod, creationProcessType)) {
                    validAwardAccounts.add(awardAccount);
                }
            }
        }
        return validAwardAccounts;
    } else {
        return awardAccounts;
    }
}
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 13 with ContractsAndGrantsBillingAwardAccount

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

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createInvoicesByAccounts.

/**
 * Generates and saves Contracts & Grants Invoice Documents based on the award accounts of the passed in award
 *
 * @param award           the award to build Contracts & Grants Invoice Documents from the award accounts on
 * @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 createInvoicesByAccounts(ContractsAndGrantsBillingAward award, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    List<ContractsAndGrantsBillingAwardAccount> tmpAcctList = new ArrayList<>();
    for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
        if (!awardAccount.isFinalBilledIndicator()) {
            tmpAcctList.clear();
            tmpAcctList.add(awardAccount);
            final List<ContractsAndGrantsBillingAwardAccount> validAwardAccounts = getValidAwardAccounts(tmpAcctList, award, creationProcessType);
            if (validAwardAccounts.containsAll(tmpAcctList) && contractsGrantsBillingAwardVerificationService.isAwardAccountValidToInvoiceBasedOnSchedule(awardAccount)) {
                /**
                 * FINP-5295 changes.
                 */
                generateAndSaveContractsAndGrantsInvoiceDocument(award, validAwardAccounts, errorMessages, creationProcessType, accountDetails, locCreationType);
            } else {
                final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, awardAccount.getAccountNumber(), award.getProposalNumber());
                errorMessages.add(errorMessage);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ContractsAndGrantsBillingAwardAccount(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)

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