Search in sources :

Example 1 with CustomerInvoiceDetail

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

the class ContractsGrantsInvoiceDocumentServiceImpl method createSourceAccountingLine.

protected CustomerInvoiceDetail createSourceAccountingLine(String docNum, String coaCode, String acctNum, SubFundGroup subFundGroup, KualiDecimal totalAmount, Integer seqNum) {
    CustomerInvoiceDetail cid = new CustomerInvoiceDetail();
    cid.setDocumentNumber(docNum);
    cid.setAccountNumber(acctNum);
    cid.setChartOfAccountsCode(coaCode);
    ContractsGrantsInvoiceObjectCode cgbiObjectCode = contractGrantsInvoiceObjectCodeForSubFundGroup(subFundGroup, coaCode);
    if (cgbiObjectCode != null) {
        cid.setFinancialObjectCode(cgbiObjectCode.getIncomeFinancialObjectCode());
        // To get AR Object codes for the GLPEs .... as it is not being called implicitly.
        cid.setAccountsReceivableObjectCode(cgbiObjectCode.getReceivableFinancialObjectCode());
    }
    cid.setSequenceNumber(seqNum);
    cid.setInvoiceItemQuantity(BigDecimal.ONE);
    cid.setInvoiceItemUnitOfMeasureCode(ArConstants.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
    cid.setInvoiceItemUnitPrice(totalAmount);
    cid.setAmount(totalAmount);
    if (totalAmount.isNegative()) {
        cid.setInvoiceItemDiscountLineNumber(seqNum);
    }
    return cid;
}
Also used : ContractsGrantsInvoiceObjectCode(org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceObjectCode) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail)

Example 2 with CustomerInvoiceDetail

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

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

the class CustomerInvoiceDetailServiceImpl method getCustomerInvoiceDetailFromOrganizationAccountingDefault.

@Override
public CustomerInvoiceDetail getCustomerInvoiceDetailFromOrganizationAccountingDefault(Integer universityFiscalYear, String chartOfAccountsCode, String organizationCode) {
    CustomerInvoiceDetail customerInvoiceDetail = new CustomerInvoiceDetail();
    Map<String, Object> criteria = new HashMap<>();
    criteria.put("universityFiscalYear", universityFiscalYear);
    criteria.put("chartOfAccountsCode", chartOfAccountsCode);
    criteria.put("organizationCode", organizationCode);
    OrganizationAccountingDefault organizationAccountingDefault = businessObjectService.findByPrimaryKey(OrganizationAccountingDefault.class, criteria);
    if (ObjectUtils.isNotNull(organizationAccountingDefault)) {
        customerInvoiceDetail.setChartOfAccountsCode(organizationAccountingDefault.getDefaultInvoiceChartOfAccountsCode());
        customerInvoiceDetail.setAccountNumber(organizationAccountingDefault.getDefaultInvoiceAccountNumber());
        customerInvoiceDetail.setSubAccountNumber(organizationAccountingDefault.getDefaultInvoiceSubAccountNumber());
        customerInvoiceDetail.setFinancialObjectCode(organizationAccountingDefault.getDefaultInvoiceFinancialObjectCode());
        customerInvoiceDetail.setFinancialSubObjectCode(organizationAccountingDefault.getDefaultInvoiceFinancialSubObjectCode());
        customerInvoiceDetail.setProjectCode(organizationAccountingDefault.getDefaultInvoiceProjectCode());
        customerInvoiceDetail.setOrganizationReferenceId(organizationAccountingDefault.getDefaultInvoiceOrganizationReferenceIdentifier());
    }
    customerInvoiceDetail.setInvoiceItemTaxAmount(new KualiDecimal(0.00));
    customerInvoiceDetail.setInvoiceItemQuantity(new BigDecimal(1));
    customerInvoiceDetail.setInvoiceItemUnitOfMeasureCode(ArConstants.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
    customerInvoiceDetail.setTaxableIndicator(false);
    return customerInvoiceDetail;
}
Also used : OrganizationAccountingDefault(org.kuali.kfs.module.ar.businessobject.OrganizationAccountingDefault) HashMap(java.util.HashMap) AccountsReceivableCustomerInvoiceDetail(org.kuali.kfs.integration.ar.AccountsReceivableCustomerInvoiceDetail) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) BigDecimal(java.math.BigDecimal)

Example 4 with CustomerInvoiceDetail

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

the class CustomerInvoiceDetailServiceImpl method getCustomerInvoiceDetailFromCustomerInvoiceItemCode.

@Override
public CustomerInvoiceDetail getCustomerInvoiceDetailFromCustomerInvoiceItemCode(String invoiceItemCode, String chartOfAccountsCode, String organizationCode) {
    Map<String, String> criteria = new HashMap<>();
    criteria.put("invoiceItemCode", invoiceItemCode);
    criteria.put("chartOfAccountsCode", chartOfAccountsCode);
    criteria.put("organizationCode", organizationCode);
    CustomerInvoiceItemCode customerInvoiceItemCode = businessObjectService.findByPrimaryKey(CustomerInvoiceItemCode.class, criteria);
    CustomerInvoiceDetail customerInvoiceDetail = null;
    if (ObjectUtils.isNotNull(customerInvoiceItemCode)) {
        customerInvoiceDetail = new CustomerInvoiceDetail();
        customerInvoiceDetail.setChartOfAccountsCode(customerInvoiceItemCode.getDefaultInvoiceChartOfAccountsCode());
        customerInvoiceDetail.setAccountNumber(customerInvoiceItemCode.getDefaultInvoiceAccountNumber());
        customerInvoiceDetail.setSubAccountNumber(customerInvoiceItemCode.getDefaultInvoiceSubAccountNumber());
        customerInvoiceDetail.setFinancialObjectCode(customerInvoiceItemCode.getDefaultInvoiceFinancialObjectCode());
        customerInvoiceDetail.setFinancialSubObjectCode(customerInvoiceItemCode.getDefaultInvoiceFinancialSubObjectCode());
        customerInvoiceDetail.setProjectCode(customerInvoiceItemCode.getDefaultInvoiceProjectCode());
        customerInvoiceDetail.setOrganizationReferenceId(customerInvoiceItemCode.getDefaultInvoiceOrganizationReferenceIdentifier());
        customerInvoiceDetail.setInvoiceItemCode(customerInvoiceItemCode.getInvoiceItemCode());
        customerInvoiceDetail.setInvoiceItemDescription(customerInvoiceItemCode.getInvoiceItemDescription());
        customerInvoiceDetail.setInvoiceItemUnitPrice(customerInvoiceItemCode.getItemDefaultPrice());
        customerInvoiceDetail.setInvoiceItemUnitOfMeasureCode(customerInvoiceItemCode.getDefaultUnitOfMeasureCode());
        customerInvoiceDetail.setInvoiceItemQuantity(customerInvoiceItemCode.getItemDefaultQuantity());
        customerInvoiceDetail.setTaxableIndicator(customerInvoiceItemCode.isTaxableIndicator());
        // TODO set sales tax accordingly
        customerInvoiceDetail.setInvoiceItemTaxAmount(new KualiDecimal(0.00));
        // set amount = unit price * quantity
        customerInvoiceDetail.updateAmountBasedOnQuantityAndUnitPrice();
    }
    return customerInvoiceDetail;
}
Also used : CustomerInvoiceItemCode(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceItemCode) HashMap(java.util.HashMap) AccountsReceivableCustomerInvoiceDetail(org.kuali.kfs.integration.ar.AccountsReceivableCustomerInvoiceDetail) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 5 with CustomerInvoiceDetail

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

the class CustomerInvoiceDetailServiceImpl method getDiscountCustomerInvoiceDetail.

@Override
public CustomerInvoiceDetail getDiscountCustomerInvoiceDetail(CustomerInvoiceDetail customerInvoiceDetail, Integer universityFiscalYear, String chartOfAccountsCode, String organizationCode) {
    CustomerInvoiceDetail discountCustomerInvoiceDetail = (CustomerInvoiceDetail) ObjectUtils.deepCopy(customerInvoiceDetail);
    discountCustomerInvoiceDetail.setInvoiceItemUnitPriceToNegative();
    discountCustomerInvoiceDetail.updateAmountBasedOnQuantityAndUnitPrice();
    discountCustomerInvoiceDetail.setInvoiceItemDescription(ArConstants.DISCOUNT_PREFIX + StringUtils.trimToEmpty(customerInvoiceDetail.getInvoiceItemDescription()));
    Map<String, Object> criteria = new HashMap<>();
    criteria.put("universityFiscalYear", universityFiscalYear);
    criteria.put("processingChartOfAccountCode", chartOfAccountsCode);
    criteria.put("processingOrganizationCode", organizationCode);
    SystemInformation systemInformation = businessObjectService.findByPrimaryKey(SystemInformation.class, criteria);
    if (ObjectUtils.isNotNull(systemInformation)) {
        discountCustomerInvoiceDetail.setFinancialObjectCode(systemInformation.getDiscountObjectCode());
    }
    return discountCustomerInvoiceDetail;
}
Also used : HashMap(java.util.HashMap) SystemInformation(org.kuali.kfs.module.ar.businessobject.SystemInformation) AccountsReceivableCustomerInvoiceDetail(org.kuali.kfs.integration.ar.AccountsReceivableCustomerInvoiceDetail) CustomerInvoiceDetail(org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail)

Aggregations

CustomerInvoiceDetail (org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail)11 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AccountsReceivableCustomerInvoiceDetail (org.kuali.kfs.integration.ar.AccountsReceivableCustomerInvoiceDetail)4 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)3 List (java.util.List)2 InvoiceAccountDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAccountDetail)2 BigDecimal (java.math.BigDecimal)1 SubFundGroup (org.kuali.kfs.coa.businessobject.SubFundGroup)1 ContractsAndGrantsBillingAward (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward)1 ContractsGrantsInvoiceObjectCode (org.kuali.kfs.module.ar.businessobject.ContractsGrantsInvoiceObjectCode)1 CustomerInvoiceItemCode (org.kuali.kfs.module.ar.businessobject.CustomerInvoiceItemCode)1 OrganizationAccountingDefault (org.kuali.kfs.module.ar.businessobject.OrganizationAccountingDefault)1 SystemInformation (org.kuali.kfs.module.ar.businessobject.SystemInformation)1 AttributedRouteDocumentEvent (org.kuali.kfs.sys.document.validation.event.AttributedRouteDocumentEvent)1