Search in sources :

Example 41 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal 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 42 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method containsIdentical.

protected boolean containsIdentical(CustomerInvoiceDetail customerInvoiceDetail, KualiDecimal amountApplied, List<InvoicePaidApplied> invoicePaidApplieds) {
    boolean identicalFlag = false;
    String custRefInvoiceDocNumber = customerInvoiceDetail.getDocumentNumber();
    Integer custInvoiceSequenceNumber = customerInvoiceDetail.getInvoiceItemNumber();
    for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
        String refInvoiceDocNumber = invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber();
        Integer invoiceSequenceNumber = invoicePaidApplied.getInvoiceItemNumber();
        KualiDecimal appliedAmount = invoicePaidApplied.getInvoiceItemAppliedAmount();
        if (custRefInvoiceDocNumber.equals(refInvoiceDocNumber) && custInvoiceSequenceNumber.equals(invoiceSequenceNumber) && amountApplied.equals(appliedAmount)) {
            identicalFlag = true;
            break;
        }
    }
    return identicalFlag;
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 43 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method applyUnapplied.

protected NonAppliedHolding applyUnapplied(PaymentApplicationForm payAppForm) throws WorkflowException {
    PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
    KualiDecimal amount = payAppForm.getNonAppliedHoldingAmount();
    // validate the customer number in the unapplied
    if (StringUtils.isNotBlank(payAppForm.getNonAppliedHoldingCustomerNumber())) {
        Map<String, String> pkMap = new HashMap<>();
        pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
        int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
        if (found == 0) {
            addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.UNAPPLIED_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.UNAPPLIED_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
            return null;
        }
        // force customer number to upper
        payAppForm.setNonAppliedHoldingCustomerNumber(payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
    }
    // validate the amount in the unapplied
    if (payAppForm.getNonAppliedHoldingAmount() != null && payAppForm.getNonAppliedHoldingAmount().isNegative()) {
        addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.UNAPPLIED_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.UNAPPLIED_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors.UNAPPLIED_AMOUNT_CANNOT_BE_NEGATIVE);
        return null;
    }
    // if we dont have enough information to make an UnApplied, then do nothing
    if (StringUtils.isBlank(payAppForm.getNonAppliedHoldingCustomerNumber()) || amount == null || amount.isZero()) {
        payAppDoc.setNonAppliedHolding(null);
        return null;
    }
    // if we already have a NonAppliedHolding on the doc, we want to get that to avoid an OLE, otherwise, we'll
    // create a new one
    NonAppliedHolding nonAppliedHolding = payAppDoc.getNonAppliedHolding();
    if (ObjectUtils.isNull(nonAppliedHolding)) {
        nonAppliedHolding = new NonAppliedHolding();
        nonAppliedHolding.setCustomerNumber(payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
        nonAppliedHolding.setReferenceFinancialDocumentNumber(payAppDoc.getDocumentNumber());
        payAppDoc.setNonAppliedHolding(nonAppliedHolding);
    }
    nonAppliedHolding.setFinancialDocumentLineAmount(amount);
    boolean isValid = PaymentApplicationDocumentRuleUtil.validateNonAppliedHolding(payAppDoc, payAppForm.getTotalFromControl());
    // check the validation results and return null if there were any errors
    if (!isValid) {
        return null;
    }
    return nonAppliedHolding;
}
Also used : HashMap(java.util.HashMap) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) NonAppliedHolding(org.kuali.kfs.module.ar.businessobject.NonAppliedHolding)

Example 44 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method writeErrorEntryByAward.

protected void writeErrorEntryByAward(ContractsAndGrantsBillingAward award, List<String> validationCategory, PrintStream printStream) throws IOException {
    // %15s %18s %20s %19s %15s %18s %23s %18s
    if (ObjectUtils.isNotNull(award)) {
        KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
        String awardBeginningDate;
        String awardEndingDate;
        String awardTotalAmount;
        String proposalNumber = award.getProposalNumber();
        Date beginningDate = award.getAwardBeginningDate();
        Date endingDate = award.getAwardEndingDate();
        KualiDecimal totalAmount = award.getAwardTotalAmount();
        if (ObjectUtils.isNotNull(beginningDate)) {
            awardBeginningDate = beginningDate.toString();
        } else {
            awardBeginningDate = "null award beginning date";
        }
        if (ObjectUtils.isNotNull(endingDate)) {
            awardEndingDate = endingDate.toString();
        } else {
            awardEndingDate = "null award ending date";
        }
        if (ObjectUtils.isNotNull(totalAmount) && ObjectUtils.isNotNull(totalAmount.bigDecimalValue())) {
            awardTotalAmount = totalAmount.toString();
        } else {
            awardTotalAmount = "null award total amount";
        }
        if (CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
            writeToReport(proposalNumber, "", awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
        } else {
            final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
            // calculate cumulativeExpenses
            for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
            }
            boolean firstLineFlag = true;
            for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
                if (firstLineFlag) {
                    writeToReport(proposalNumber, awardAccount.getAccountNumber(), awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
                    firstLineFlag = false;
                } else {
                    writeToReport("", awardAccount.getAccountNumber(), "", "", "", "", printStream);
                }
            }
        }
    }
    // To print all the errors from the validation category.
    for (String vCat : validationCategory) {
        printStream.printf("%s", "     " + vCat);
        printStream.print("\r\n");
    }
    printStream.print(REPORT_LINE_DIVIDER);
    printStream.print("\r\n");
}
Also used : 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 45 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method takeAPennyLeaveAPennyCGBStyle.

/**
 * If the total of current expenditures within the list of InvoiceDetailAccountObjectCode business objects does
 * not meet the amount to target, steal or give a penny from one of those business objects so that it does
 *
 * @param invoiceDetailAccountObjectCodes a List of InvoiceDetailAccountObjectCode business objects
 * @param amountToTarget                  the amount which the sum of those objects should equal
 */
protected void takeAPennyLeaveAPennyCGBStyle(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, KualiDecimal amountToTarget) {
    if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodes)) {
        final KualiDecimal currentExpenditureTotal = sumInvoiceDetailAccountObjectCodes(invoiceDetailAccountObjectCodes).getCurrentExpenditures();
        if (!currentExpenditureTotal.equals(amountToTarget)) {
            final KualiDecimal difference = currentExpenditureTotal.subtract(amountToTarget);
            InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = findFirstPositiveCurrentExpenditureInvoiceDetailAccountObjectCode(invoiceDetailAccountObjectCodes);
            if (invoiceDetailAccountObjectCode != null) {
                invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().subtract(difference));
            }
        }
    }
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) InvoiceDetailAccountObjectCode(org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8