Search in sources :

Example 6 with InvoiceAccountDetail

use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail 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 7 with InvoiceAccountDetail

use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method createSourceAccountingLinesByAward.

/**
 * Generates the source accounting lines for a Contracts & Grants Invoice from the award accounts associated with
 * an award (in the form of the pre-generated invoice account details)
 *
 * @param contractsGrantsInvoiceDocument the Contracts & Grants Invoice to create invoice details for
 * @return a List of generated accounting lines
 */
protected List<CustomerInvoiceDetail> createSourceAccountingLinesByAward(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
    List<CustomerInvoiceDetail> awardAccountingLines = new ArrayList<>();
    if (!CollectionUtils.isEmpty(contractsGrantsInvoiceDocument.getAccountDetails())) {
        final Map<String, KualiDecimal> accountExpenditureAmounts = getCategoryExpenditureAmountsForInvoiceAccountDetail(contractsGrantsInvoiceDocument);
        final Map<String, KualiDecimal> accountTotalBilledAmounts = getCategoryTotalBilledAmountsForInvoiceAccountDetail(contractsGrantsInvoiceDocument);
        for (InvoiceAccountDetail invAcctD : contractsGrantsInvoiceDocument.getAccountDetails()) {
            final String proposalNumber = invAcctD.getProposalNumber();
            final String chartOfAccountsCode = invAcctD.getChartOfAccountsCode();
            final String accountNumber = invAcctD.getAccountNumber();
            if (invAcctD.getAccount() == null) {
                invAcctD.refreshReferenceObject(KFSPropertyConstants.ACCOUNT);
            }
            final SubFundGroup subFundGroup = invAcctD.getAccount().getSubFundGroup();
            final Integer sequenceNumber = contractsGrantsInvoiceDocument.getAccountDetails().indexOf(invAcctD) + 1;
            final String accountKey = StringUtils.join(new String[] { chartOfAccountsCode, accountNumber }, "-");
            KualiDecimal totalAmount = accountExpenditureAmounts.getOrDefault(accountKey, KualiDecimal.ZERO);
            if (invAcctD.getTotalPreviouslyBilled().isZero()) {
                KualiDecimal previouslyBilledAmount = getPredeterminedBillingBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber);
                previouslyBilledAmount = previouslyBilledAmount.add(getMilestonesBilledToDateAmount(proposalNumber, chartOfAccountsCode, accountNumber));
                KualiDecimal totalBilledAmount = accountTotalBilledAmounts.getOrDefault(accountKey, KualiDecimal.ZERO);
                previouslyBilledAmount = previouslyBilledAmount.subtract(totalBilledAmount);
                if (previouslyBilledAmount.isGreaterThan(KualiDecimal.ZERO)) {
                    totalAmount = totalAmount.subtract(previouslyBilledAmount);
                }
            }
            CustomerInvoiceDetail cide = createSourceAccountingLine(contractsGrantsInvoiceDocument.getDocumentNumber(), chartOfAccountsCode, accountNumber, subFundGroup, totalAmount, sequenceNumber);
            awardAccountingLines.add(cide);
        }
    }
    return awardAccountingLines;
}
Also used : SubFundGroup(org.kuali.kfs.coa.businessobject.SubFundGroup) ArrayList(java.util.ArrayList) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)

Example 8 with InvoiceAccountDetail

use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method generateAndSaveContractsAndGrantsInvoiceDocument.

/**
 * FINP-5295 This method was modified for the backport.
 *
 * Generates and then saves a Contracts & Grants Invoice Document
 *
 * @param awd                the award for the document
 * @param validAwardAccounts the award accounts which should appear on the document
 * @param errorMessages      a List of error messages, to be appended to if there are errors in document generation
 * @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 generateAndSaveContractsAndGrantsInvoiceDocument(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> validAwardAccounts, List<ErrorMessage> errorMessages, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType) {
    ChartOrgHolder chartOrgHolder = financialSystemUserService.getPrimaryOrganization(awd.getAwardPrimaryFundManager().getFundManager().getPrincipalId(), KFSConstants.OptionalModuleNamespaces.ACCOUNTS_RECEIVABLE);
    /*
         * CU Customization (KFSPTS-23675):
         * Include creationProcessType in the method call.
         */
    ContractsGrantsInvoiceDocument cgInvoiceDocument = createCGInvoiceDocumentByAwardInfo(awd, validAwardAccounts, chartOrgHolder.getChartOfAccountsCode(), chartOrgHolder.getOrganizationCode(), errorMessages, accountDetails, locCreationType, creationProcessType);
    if (ObjectUtils.isNotNull(cgInvoiceDocument)) {
        if (cgInvoiceDocument.getTotalInvoiceAmount().isPositive() || getContractsGrantsInvoiceDocumentService().getInvoiceMilestoneTotal(cgInvoiceDocument).isPositive() || getContractsGrantsInvoiceDocumentService().getBillAmountTotal(cgInvoiceDocument).isPositive() || (ArConstants.BillingFrequencyValues.isTimeBased(awd) && ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL.equals(creationProcessType))) {
            try {
                documentService.saveDocument(cgInvoiceDocument, DocumentSystemSaveEvent.class);
            } catch (WorkflowException ex) {
                LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
                throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
            }
        } else {
            ErrorMessage errorMessage;
            List<InvoiceAccountDetail> invoiceAccounts = cgInvoiceDocument.getAccountDetails();
            if (!invoiceAccounts.isEmpty()) {
                errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, invoiceAccounts.get(0).getAccountNumber(), awd.getProposalNumber());
            } else {
                errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NON_BILLABLE, null, awd.getProposalNumber());
            }
            errorMessages.add(errorMessage);
        }
    }
}
Also used : ChartOrgHolder(org.kuali.kfs.sys.businessobject.ChartOrgHolder) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) ContractsGrantsInvoiceDocumentErrorMessage(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDocumentErrorMessage)

Example 9 with InvoiceAccountDetail

use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method correctContractsGrantsInvoiceDocument.

@Override
public void correctContractsGrantsInvoiceDocument(ContractsGrantsInvoiceDocument document) {
    // correct Direct Cost Invoice Details.
    for (ContractsGrantsInvoiceDetail id : document.getDirectCostInvoiceDetails()) {
        correctInvoiceDetail(id);
    }
    // correct Indirect Cost Invoice Details.
    for (ContractsGrantsInvoiceDetail id : document.getIndirectCostInvoiceDetails()) {
        correctInvoiceDetail(id);
    }
    // update correction to the InvoiceAccountDetail objects
    for (InvoiceAccountDetail id : document.getAccountDetails()) {
        correctInvoiceAccountDetail(id);
    }
    // correct invoiceDetailAccountObjectCode.
    for (InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode : document.getInvoiceDetailAccountObjectCodes()) {
        invoiceDetailAccountObjectCode.correctInvoiceDetailAccountObjectCodeExpenditureAmount();
    }
    // correct Bills
    KualiDecimal totalBillingAmount = KualiDecimal.ZERO;
    for (InvoiceBill bill : document.getInvoiceBills()) {
        bill.setEstimatedAmount(bill.getEstimatedAmount().negated());
        totalBillingAmount = totalBillingAmount.add(bill.getEstimatedAmount());
    }
    // correct Milestones
    KualiDecimal totalMilestonesAmount = KualiDecimal.ZERO;
    for (InvoiceMilestone milestone : document.getInvoiceMilestones()) {
        milestone.setMilestoneAmount(milestone.getMilestoneAmount().negated());
        totalMilestonesAmount = totalMilestonesAmount.add(milestone.getMilestoneAmount());
    }
    document.getInvoiceGeneralDetail().setTotalPreviouslyBilled(getAwardBilledToDateAmountExcludingDocument(document.getInvoiceGeneralDetail().getProposalNumber(), document.getDocumentNumber()));
    if (ArConstants.BillingFrequencyValues.isMilestone(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceMilestones())) {
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalMilestonesAmount));
    } else if (ArConstants.BillingFrequencyValues.isPredeterminedBilling(document.getInvoiceGeneralDetail()) && CollectionUtils.isNotEmpty(document.getInvoiceBills())) {
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(document.getInvoiceGeneralDetail().getTotalAmountBilledToDate().add(totalBillingAmount));
    } else {
        KualiDecimal newTotalBilled = document.getTotalCostInvoiceDetail().getInvoiceAmount().add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
        newTotalBilled = newTotalBilled.add(getOtherTotalBilledForAwardPeriod(document));
        document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(newTotalBilled);
        calculatePreviouslyBilledAmounts(document);
    }
    for (InvoiceAddressDetail invoiceAddressDetail : document.getInvoiceAddressDetails()) {
        invoiceAddressDetail.setInitialTransmissionDate(null);
        invoiceAddressDetail.setTransmittedByPrincipalId("");
        invoiceAddressDetail.setTransmissionDate(null);
        invoiceAddressDetail.setTransmissionStatusCode("");
        invoiceAddressDetail.setTransmissionCount(0);
    }
}
Also used : ContractsGrantsInvoiceDetail(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail) InvoiceBill(org.kuali.kfs.module.ar.businessobject.InvoiceBill) AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail) InvoiceMilestone(org.kuali.kfs.module.ar.businessobject.InvoiceMilestone) InvoiceAddressDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Example 10 with InvoiceAccountDetail

use of org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method updateInvoiceSourceAccountingLines.

protected void updateInvoiceSourceAccountingLines(List<InvoiceAccountDetail> invoiceAccountDetails, List sourceAccountingLines) {
    if (sourceAccountingLines.size() > 1) {
        // Invoice By Award
        for (CustomerInvoiceDetail cide : (List<CustomerInvoiceDetail>) sourceAccountingLines) {
            for (InvoiceAccountDetail invoiceAccountDetail : invoiceAccountDetails) {
                if (cide.getAccountNumber().equals(invoiceAccountDetail.getAccountNumber())) {
                    cide.setInvoiceItemUnitPrice(invoiceAccountDetail.getInvoiceAmount());
                    cide.setAmount(invoiceAccountDetail.getInvoiceAmount());
                }
            }
        }
    } else if (sourceAccountingLines.size() == 1) {
        // This would be a case where the invoice is generated by Contract Control Account or Invoice By Account.
        KualiDecimal totalExpenditureAmount = KualiDecimal.ZERO;
        if (invoiceAccountDetails.size() == 1) {
            // Invoice By Account
            // update source accounting lines
            CustomerInvoiceDetail cide = (CustomerInvoiceDetail) sourceAccountingLines.get(0);
            cide.setInvoiceItemUnitPrice(invoiceAccountDetails.get(0).getInvoiceAmount());
            cide.setAmount(invoiceAccountDetails.get(0).getInvoiceAmount());
        } else {
            // Invoice By Contract Control Account
            for (InvoiceAccountDetail invoiceAccountDetail : invoiceAccountDetails) {
                totalExpenditureAmount = totalExpenditureAmount.add(invoiceAccountDetail.getInvoiceAmount());
            }
            // update source accounting lines
            CustomerInvoiceDetail cide = (CustomerInvoiceDetail) sourceAccountingLines.get(0);
            cide.setInvoiceItemUnitPrice(totalExpenditureAmount);
            cide.setAmount(totalExpenditureAmount);
        }
    }
}
Also used : CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) AbstractKualiDecimal(org.kuali.kfs.core.api.util.type.AbstractKualiDecimal) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ArrayList(java.util.ArrayList) List(java.util.List) InvoiceAccountDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)

Aggregations

InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)18 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)9 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)7 HashMap (java.util.HashMap)5 Account (org.kuali.kfs.coa.businessobject.Account)5 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)5 ContractsAndGrantsBillingAwardAccount (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAwardAccount)4 ArrayList (java.util.ArrayList)3 SubFundGroup (org.kuali.kfs.coa.businessobject.SubFundGroup)3 ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)3 AwardAccountExtendedAttribute (edu.cornell.kfs.module.cg.businessobject.AwardAccountExtendedAttribute)2 List (java.util.List)2 ContractsGrantsInvoiceDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceDetail)2 ContractsGrantsLetterOfCreditReviewDetail (org.kuali.kfs.module.ar.businessobject.ContractsGrantsLetterOfCreditReviewDetail)2 CustomerInvoiceDetail (org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail)2 InvoiceAddressDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail)2 InvoiceGeneralDetail (org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)2 InvoiceMilestone (org.kuali.kfs.module.ar.businessobject.InvoiceMilestone)2 ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)2 BigDecimal (java.math.BigDecimal)1