Search in sources :

Example 6 with ContractsAndGrantsBillingAward

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

the class CuAREmailServiceImpl method getSubject.

@Override
protected String getSubject(ContractsGrantsInvoiceDocument invoice) {
    String grantNumber = invoice.getInvoiceGeneralDetail().getAward().getProposal().getGrantNumber();
    String subject;
    String message;
    if (StringUtils.isBlank(grantNumber)) {
        subject = kualiConfigurationService.getPropertyValueAsString(ArKeyConstants.CGINVOICE_EMAIL_SUBJECT_NO_GRANT_NUMBER);
        message = MessageFormat.format(subject, invoice.getDocumentNumber(), invoice.getInvoiceGeneralDetail().getAward().getProposal().getProposalNumber());
    } else {
        subject = kualiConfigurationService.getPropertyValueAsString(ArKeyConstants.CGINVOICE_EMAIL_SUBJECT);
        ContractsAndGrantsBillingAward award = invoice.getInvoiceGeneralDetail().getAward();
        message = MessageFormat.format(subject, invoice.getDocumentNumber(), award.getProposal().getGrantNumber(), award.getProposal().getProposalNumber(), award.getAwardPrimaryProjectDirector().getProjectDirector().getName());
    }
    return message;
}
Also used : ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)

Example 7 with ContractsAndGrantsBillingAward

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

the class FirstInvoiceForAwardSuspensionCategory method priorSuccessfulInvoicesExist.

protected boolean priorSuccessfulInvoicesExist(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
    Map<String, String> criteria = new HashMap<>();
    String proposalNumber = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber();
    String documentNumber = contractsGrantsInvoiceDocument.getDocumentNumber();
    ContractsAndGrantsBillingAward award = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAward();
    criteria.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.PROPOSAL_NUMBER, proposalNumber);
    criteria.put(KFSPropertyConstants.DOCUMENT_HEADER + KFSConstants.DELIMITER + KFSPropertyConstants.WORKFLOW_DOCUMENT_STATUS_CODE, buildSuccessfulDocumentStatusesCriteria());
    criteria.put(KFSPropertyConstants.DOCUMENT_NUMBER, SearchOperator.NOT.op() + documentNumber);
    Map<String, String> extraCriteria = buildAdditionalCriteriaForInvoicingOption(contractsGrantsInvoiceDocument, award.getInvoicingOptionCode());
    criteria.putAll(extraCriteria);
    Collection<ContractsGrantsInvoiceDocument> priorInvoices = contractsGrantsInvoiceDocumentDao.getMatchingInvoicesByCollection(criteria);
    return CollectionUtils.isNotEmpty(priorInvoices);
}
Also used : HashMap(java.util.HashMap) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)

Example 8 with ContractsAndGrantsBillingAward

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

the class ContractsGrantsInvoiceDocumentServiceImpl method createSourceAccountingLines.

@Override
public void createSourceAccountingLines(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument, List<ContractsAndGrantsBillingAwardAccount> awardAccounts) {
    // To check if the Source accounting lines are existing. If they are do nothing
    if (CollectionUtils.isEmpty(contractsGrantsInvoiceDocument.getSourceAccountingLines())) {
        ContractsAndGrantsBillingAward award = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAward();
        if (ObjectUtils.isNotNull(award)) {
            if (StringUtils.equalsIgnoreCase(award.getInvoicingOptionCode(), ArConstants.INV_ACCOUNT) || StringUtils.equalsIgnoreCase(award.getInvoicingOptionCode(), ArConstants.INV_SCHEDULE)) {
                // If its bill by Account or Schedule, irrespective of it is by contract control account,
                // there would be a single source accounting line with award account specified by the user.
                CustomerInvoiceDetail cide = createSourceAccountingLine(contractsGrantsInvoiceDocument.getDocumentNumber(), awardAccounts.get(0).getChartOfAccountsCode(), awardAccounts.get(0).getAccountNumber(), awardAccounts.get(0).getAccount().getSubFundGroup(), getTotalAmountForInvoice(contractsGrantsInvoiceDocument), 1);
                contractsGrantsInvoiceDocument.getSourceAccountingLines().add(cide);
            } else if (StringUtils.equalsIgnoreCase(award.getInvoicingOptionCode(), ArConstants.INV_CONTRACT_CONTROL_ACCOUNT)) {
                // by control account
                // If its bill by Contract Control Account there would be a single source accounting line.
                CustomerInvoiceDetail cide = createSourceAccountingLinesByContractControlAccount(contractsGrantsInvoiceDocument);
                contractsGrantsInvoiceDocument.getSourceAccountingLines().add(cide);
            } else {
                // by award
                List<CustomerInvoiceDetail> awardAccountingLines = createSourceAccountingLinesByAward(contractsGrantsInvoiceDocument);
                contractsGrantsInvoiceDocument.getSourceAccountingLines().addAll(awardAccountingLines);
            }
        }
    }
}
Also used : ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with ContractsAndGrantsBillingAward

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

the class ContractsGrantsInvoiceDocumentServiceImpl method updateLastBilledDate.

@Override
public void updateLastBilledDate(ContractsGrantsInvoiceDocument document) {
    boolean isFinalBill = document.getInvoiceGeneralDetail().isFinalBillIndicator();
    for (InvoiceAccountDetail id : document.getAccountDetails()) {
        if (isFinalBill) {
            setAwardAccountFinalBilledValueAndLastBilledDate(id, true, document.getInvoiceGeneralDetail().getProposalNumber(), document.isInvoiceReversal(), document.getInvoiceGeneralDetail().getLastBilledDate());
        } else {
            calculateAwardAccountLastBilledDate(id, document.isInvoiceReversal(), document.getInvoiceGeneralDetail().getLastBilledDate(), document.getInvoiceGeneralDetail().getProposalNumber());
        }
    }
    // 2. Set last Billed to Award = least of last billed date of award account.
    String proposalNumber = document.getInvoiceGeneralDetail().getProposalNumber();
    Map<String, Object> map = new HashMap<>();
    map.put(KFSPropertyConstants.PROPOSAL_NUMBER, proposalNumber);
    ContractsAndGrantsBillingAward award = kualiModuleService.getResponsibleModuleService(ContractsAndGrantsBillingAward.class).getExternalizableBusinessObject(ContractsAndGrantsBillingAward.class, map);
    if (CollectionUtils.isNotEmpty(award.getActiveAwardAccounts())) {
        // To set last billed Date to award.
        contractsAndGrantsModuleBillingService.setLastBilledDateToAward(proposalNumber, getLastBilledDate(award));
    }
}
Also used : HashMap(java.util.HashMap) ContractsAndGrantsBillingAward(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)

Example 10 with ContractsAndGrantsBillingAward

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

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