Search in sources :

Example 1 with PaymentApplicationDocument

use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument 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 2 with PaymentApplicationDocument

use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method doApplicationOfFunds.

protected void doApplicationOfFunds(PaymentApplicationForm paymentApplicationForm) throws WorkflowException {
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    List<InvoicePaidApplied> invoicePaidApplieds = new ArrayList<>();
    // apply invoice detail entries
    invoicePaidApplieds.addAll(applyToIndividualCustomerInvoiceDetails(paymentApplicationForm));
    // quick-apply invoices
    invoicePaidApplieds.addAll(quickApplyToInvoices(paymentApplicationForm, invoicePaidApplieds));
    // re-number the paidApplieds internal sequence numbers
    int paidAppliedItemNumber = 1;
    for (InvoicePaidApplied i : invoicePaidApplieds) {
        i.setPaidAppliedItemNumber(paidAppliedItemNumber++);
    }
    // apply non-Invoiced
    NonInvoiced nonInvoiced = applyNonInvoiced(paymentApplicationForm);
    // apply non-applied holdings
    NonAppliedHolding nonAppliedHolding = applyUnapplied(paymentApplicationForm);
    // sum up the paid applieds
    KualiDecimal sumOfInvoicePaidApplieds = KualiDecimal.ZERO;
    for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
        KualiDecimal amount = invoicePaidApplied.getInvoiceItemAppliedAmount();
        if (null == amount) {
            amount = KualiDecimal.ZERO;
        }
        sumOfInvoicePaidApplieds = sumOfInvoicePaidApplieds.add(amount);
    }
    // sum up all applieds
    KualiDecimal appliedAmount = KualiDecimal.ZERO;
    appliedAmount = appliedAmount.add(sumOfInvoicePaidApplieds);
    if (null != nonInvoiced && null != nonInvoiced.getFinancialDocumentLineAmount()) {
        appliedAmount = appliedAmount.add(nonInvoiced.getFinancialDocumentLineAmount());
    }
    appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonAppliedDistributions());
    appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonInvoicedDistributions());
    appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonInvoiceds());
    if (null != paymentApplicationDocument.getNonAppliedHoldingAmount()) {
        appliedAmount = appliedAmount.add(paymentApplicationDocument.getNonAppliedHoldingAmount());
    }
    // check that we haven't applied more than our control total
    KualiDecimal controlTotalAmount = paymentApplicationForm.getTotalFromControl();
    // if the person over-applies, we dont stop them, we just complain
    if (appliedAmount.isGreaterThan(controlTotalAmount)) {
        addGlobalError(ArKeyConstants.PaymentApplicationDocumentErrors.CANNOT_APPLY_MORE_THAN_CASH_CONTROL_TOTAL_AMOUNT);
    }
    // swap out the old paidApplieds with the newly generated
    paymentApplicationDocument.getInvoicePaidApplieds().clear();
    paymentApplicationDocument.getInvoicePaidApplieds().addAll(invoicePaidApplieds);
    // NonInvoiced list management
    if (null != nonInvoiced) {
        paymentApplicationDocument.getNonInvoiceds().add(nonInvoiced);
        // re-number the non-invoiced
        int nonInvoicedItemNumber = 1;
        for (NonInvoiced n : paymentApplicationDocument.getNonInvoiceds()) {
            n.setFinancialDocumentLineNumber(nonInvoicedItemNumber++);
            n.refreshReferenceObject("chartOfAccounts");
            n.refreshReferenceObject("account");
            n.refreshReferenceObject("subAccount");
            n.refreshReferenceObject("financialObject");
            n.refreshReferenceObject("financialSubObject");
            n.refreshReferenceObject("project");
        }
        // make an empty new one
        paymentApplicationForm.setNonInvoicedAddLine(new NonInvoiced());
    }
    // reset the allocations, so it gets re-calculated
    paymentApplicationForm.setNonAppliedControlAllocations(null);
    // Update the doc total if it is not a CashControl generated PayApp
    if (!paymentApplicationDocument.hasCashControlDetail()) {
        paymentApplicationDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(appliedAmount);
    }
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) ArrayList(java.util.ArrayList) 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) NonInvoiced(org.kuali.kfs.module.ar.businessobject.NonInvoiced)

Example 3 with PaymentApplicationDocument

use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method applyToIndividualCustomerInvoiceDetails.

protected List<InvoicePaidApplied> applyToIndividualCustomerInvoiceDetails(PaymentApplicationForm paymentApplicationForm) {
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    // Handle amounts applied at the invoice detail level
    int simpleInvoiceDetailApplicationCounter = 0;
    // calculate paid applieds for all invoices
    List<InvoicePaidApplied> invoicePaidApplieds = this.filterTempInvoicePaidApplieds(paymentApplicationForm);
    for (PaymentApplicationInvoiceApply invoiceApplication : paymentApplicationForm.getInvoiceApplications()) {
        for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
            // selectedInvoiceDetailApplications[${ctr}].amountApplied
            String fieldName = "selectedInvoiceDetailApplications[" + simpleInvoiceDetailApplicationCounter + "].amountApplied";
            // needs to be incremented even if we skip this line
            simpleInvoiceDetailApplicationCounter++;
            // handle the user clicking full apply
            if (detailApplication.isFullApply()) {
                detailApplication.setAmountApplied(detailApplication.getAmountOpen());
            } else {
                // handle the user manually entering an amount
                if (detailApplication.isFullApplyChanged()) {
                    // means it went from true to false
                    detailApplication.setAmountApplied(KualiDecimal.ZERO);
                }
            }
            // Don't add lines where the amount to apply is zero. Wouldn't make any sense to do that.
            if (KualiDecimal.ZERO.equals(detailApplication.getAmountApplied())) {
                continue;
            }
            if (containsIdentical(detailApplication.getInvoiceDetail(), detailApplication.getAmountApplied(), invoicePaidApplieds)) {
                continue;
            }
            // generate and validate the paidApplied, and always add it to the list, even if
            // it fails validation. Validation failures will stop routing.
            LOG.debug("Generating paid applied for detail application " + detailApplication.getInvoiceDocumentNumber());
            InvoicePaidApplied invoicePaidApplied = generateAndValidateNewPaidApplied(detailApplication, fieldName, paymentApplicationDocument);
            GlobalVariables.getMessageMap().addToErrorPath(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB);
            GlobalVariables.getMessageMap().removeFromErrorPath(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB);
            invoicePaidApplieds.add(invoicePaidApplied);
        }
    }
    return invoicePaidApplieds;
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 4 with PaymentApplicationDocument

use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied.

protected void adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied(PaymentApplicationForm paymentApplicationForm, int deletedAppliedFundsIndex) {
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    InvoicePaidApplied appliedFundBeingDeleted = paymentApplicationDocument.getInvoicePaidApplieds().get(deletedAppliedFundsIndex);
    String summaryOfAppliedFundsDocumentNumberBeingDeleted = appliedFundBeingDeleted.getFinancialDocumentReferenceInvoiceNumber();
    KualiDecimal summaryOfAppliedFundsAmountBeingDeleted = appliedFundBeingDeleted.getInvoiceItemAppliedAmount();
    if (StringUtils.isNotBlank(summaryOfAppliedFundsDocumentNumberBeingDeleted)) {
        for (PaymentApplicationInvoiceApply invoiceListItem : paymentApplicationForm.getInvoiceApplications()) {
            for (PaymentApplicationInvoiceDetailApply invoiceListItemDetail : invoiceListItem.getDetailApplications()) {
                deleteCleanupOfApplyToInvoiceDetailData(invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted, summaryOfAppliedFundsAmountBeingDeleted);
                deleteCleanupOfQuickApplyToInvoiceData(invoiceListItem, invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted);
            }
        }
    }
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 5 with PaymentApplicationDocument

use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.

the class PaymentApplicationAction method manuallyAddressInvoicePaidAppliedDeletions.

protected void manuallyAddressInvoicePaidAppliedDeletions(PaymentApplicationForm paymentApplicationForm) {
    if (paymentApplicationForm.isManualInvoicePaidAppliedDatabaseDeletionRequired()) {
        PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
        getInvoicePaidAppliedDao().deleteAllInvoicePaidApplieds(paymentApplicationDocument.getDocumentNumber());
        paymentApplicationForm.setManualInvoicePaidAppliedDatabaseDeletionRequired(false);
    }
}
Also used : PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Aggregations

PaymentApplicationDocument (org.kuali.kfs.module.ar.document.PaymentApplicationDocument)16 InvoicePaidApplied (org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied)6 ArrayList (java.util.ArrayList)4 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)3 AccountsReceivableDocumentHeader (org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader)3 NonAppliedHolding (org.kuali.kfs.module.ar.businessobject.NonAppliedHolding)3 NonInvoiced (org.kuali.kfs.module.ar.businessobject.NonInvoiced)3 PaymentApplicationForm (org.kuali.kfs.module.ar.document.web.struts.PaymentApplicationForm)3 HashMap (java.util.HashMap)2 WorkflowDocument (org.kuali.kfs.kew.api.WorkflowDocument)2 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)2 Document (org.kuali.kfs.krad.document.Document)2 CashControlDocument (org.kuali.kfs.module.ar.document.CashControlDocument)2 CustomerInvoiceDocument (org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)2 PaymentApplicationAdjustmentDocument (org.kuali.kfs.module.ar.document.PaymentApplicationAdjustmentDocument)2 LinkedList (java.util.LinkedList)1 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)1 DocumentService (org.kuali.kfs.krad.service.DocumentService)1 CashControlDetail (org.kuali.kfs.module.ar.businessobject.CashControlDetail)1 Customer (org.kuali.kfs.module.ar.businessobject.Customer)1