Search in sources :

Example 6 with PaymentApplicationDocument

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

the class PaymentApplicationForm method populate.

@Override
public void populate(HttpServletRequest request) {
    super.populate(request);
    // Set the next non-invoiced line number
    PaymentApplicationDocument paymentApplicationDocument = getPaymentApplicationDocument();
    if (ObjectUtils.isNotNull(paymentApplicationDocument.getNonInvoicedDistributions())) {
        for (NonInvoicedDistribution u : paymentApplicationDocument.getNonInvoicedDistributions()) {
            if (null == getNextNonInvoicedLineNumber()) {
                setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
            } else if (u.getFinancialDocumentLineNumber() > getNextNonInvoicedLineNumber()) {
                setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
            }
        }
    }
    if (null == getNextNonInvoicedLineNumber()) {
        setNextNonInvoicedLineNumber(1);
    }
    // This step doesn't affect anything persisted to the database. It allows proper calculation
    // of amounts for the display.
    String customerNumber = null;
    String docId = getDocument().getDocumentNumber();
    if (ObjectUtils.isNotNull(request.getParameter(KFSConstants.PARAMETER_DOC_ID)) && ObjectUtils.isNull(getDocument().getDocumentNumber())) {
        // The document hasn't yet been set on the form. Let's look it up manually so that we can get the
        // customer number.
        docId = request.getParameter(KFSConstants.PARAMETER_DOC_ID).trim();
        DocumentService documentService = SpringContext.getBean(DocumentService.class);
        Document d;
        try {
            d = documentService.getByDocumentHeaderId(docId);
        } catch (WorkflowException e) {
            throw new RuntimeException("WorkflowException thrown when trying to load docId [" + docId + "]", e);
        }
        PaymentApplicationDocument pDocument = (PaymentApplicationDocument) d;
        AccountsReceivableDocumentHeader arHeader = pDocument.getAccountsReceivableDocumentHeader();
        if (ObjectUtils.isNotNull(arHeader)) {
            customerNumber = arHeader.getCustomerNumber();
        }
    }
    if (ObjectUtils.isNull(getSelectedInvoiceApplication())) {
        if (ObjectUtils.isNull(invoices) || invoices.isEmpty()) {
            if (ObjectUtils.isNotNull(customerNumber)) {
                // get open invoices for the current customer
                CustomerInvoiceDocumentService customerInvoiceDocumentService = SpringContext.getBean(CustomerInvoiceDocumentService.class);
                Collection<CustomerInvoiceDocument> openInvoicesForCustomer = customerInvoiceDocumentService.getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
                setInvoices(new ArrayList<>(openInvoicesForCustomer));
                if (invoices != null && !invoices.isEmpty()) {
                    setSelectedInvoiceDocumentNumber(invoices.get(0).getDocumentNumber());
                }
                setupInvoiceWrappers(docId);
            }
        }
    }
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) CustomerInvoiceDocumentService(org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) NonInvoicedDistribution(org.kuali.kfs.module.ar.businessobject.NonInvoicedDistribution) Document(org.kuali.kfs.krad.document.Document) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CashControlDocument(org.kuali.kfs.module.ar.document.CashControlDocument) WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CustomerInvoiceDocumentService(org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService)

Example 7 with PaymentApplicationDocument

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

the class PaymentApplicationAction method quickApplyToInvoices.

protected List<InvoicePaidApplied> quickApplyToInvoices(PaymentApplicationForm paymentApplicationForm, List<InvoicePaidApplied> appliedToIndividualDetails) {
    PaymentApplicationDocument applicationDocument = (PaymentApplicationDocument) paymentApplicationForm.getDocument();
    List<InvoicePaidApplied> invoicePaidApplieds = new ArrayList<>();
    // go over the selected invoices and apply full amount to each of their details
    for (PaymentApplicationInvoiceApply invoiceApplication : paymentApplicationForm.getInvoiceApplications()) {
        String invoiceDocNumber = invoiceApplication.getDocumentNumber();
        // skip the line if its not set to quick apply
        if (!invoiceApplication.isQuickApply()) {
            // if it was just flipped from True to False
            if (invoiceApplication.isQuickApplyChanged()) {
                for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
                    // zero out all the details
                    detailApplication.setAmountApplied(KualiDecimal.ZERO);
                    detailApplication.setFullApply(false);
                    // remove any existing paidApplieds for this invoice
                    for (int i = appliedToIndividualDetails.size() - 1; i >= 0; i--) {
                        InvoicePaidApplied applied = appliedToIndividualDetails.get(i);
                        if (applied.getFinancialDocumentReferenceInvoiceNumber().equals(invoiceApplication.getDocumentNumber())) {
                            appliedToIndividualDetails.remove(i);
                        }
                    }
                }
            }
            continue;
        }
        // make sure none of the invoices selected have zero open amounts, complain if so
        if (invoiceApplication.getOpenAmount().isZero()) {
            addGlobalError(ArKeyConstants.PaymentApplicationDocumentErrors.CANNOT_QUICK_APPLY_ON_INVOICE_WITH_ZERO_OPEN_AMOUNT);
            return invoicePaidApplieds;
        }
        // remove any existing paidApplieds for this invoice
        for (int i = appliedToIndividualDetails.size() - 1; i >= 0; i--) {
            InvoicePaidApplied applied = appliedToIndividualDetails.get(i);
            if (applied.getFinancialDocumentReferenceInvoiceNumber().equals(invoiceApplication.getDocumentNumber())) {
                appliedToIndividualDetails.remove(i);
            }
        }
        // create and validate the paid applieds for each invoice detail
        String fieldName = "invoiceApplications[" + invoiceDocNumber + "].quickApply";
        for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
            detailApplication.setAmountApplied(detailApplication.getAmountOpen());
            detailApplication.setFullApply(true);
            InvoicePaidApplied paidApplied = generateAndValidateNewPaidApplied(detailApplication, fieldName, applicationDocument);
            if (paidApplied != null) {
                invoicePaidApplieds.add(paidApplied);
            }
        }
        // maintain the selected doc number
        if (invoiceDocNumber.equals(paymentApplicationForm.getEnteredInvoiceDocumentNumber())) {
            paymentApplicationForm.setSelectedInvoiceDocumentNumber(invoiceDocNumber);
        }
    }
    return invoicePaidApplieds;
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) ArrayList(java.util.ArrayList) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 8 with PaymentApplicationDocument

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

the class PaymentApplicationAction method deleteInvoicePaidApplied.

// CU Customization: Added several helper methods for invoice-paid-applied deletion enhancement.
public ActionForward deleteInvoicePaidApplied(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PaymentApplicationForm paymentApplicationForm = (PaymentApplicationForm) form;
    paymentApplicationForm.setManualInvoicePaidAppliedDatabaseDeletionRequired(true);
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    int deleteIndex = getLineToDelete(request);
    adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied(paymentApplicationForm, deleteIndex);
    paymentApplicationDocument.getInvoicePaidApplieds().remove(deleteIndex);
    GlobalVariables.getMessageMap().clearErrorMessages();
    doApplicationOfFunds((PaymentApplicationForm) form);
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) PaymentApplicationForm(org.kuali.kfs.module.ar.document.web.struts.PaymentApplicationForm)

Example 9 with PaymentApplicationDocument

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

the class PaymentApplicationAction method adjust.

public ActionForward adjust(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    // Document could be stale at this point (Submit followed immediately by Adjust); freshen it up
    super.reload(mapping, form, request, response);
    final KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    final PaymentApplicationDocument applicationDocument = (PaymentApplicationDocument) kualiDocumentFormBase.getDocument();
    final PaymentApplicationAdjustmentDocument appAdjustDocument = getPaymentApplicationDocumentService().createPaymentApplicationAdjustment(applicationDocument);
    kualiDocumentFormBase.setDocument(appAdjustDocument);
    return createActionForward((KualiDocumentFormBase) form);
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) PaymentApplicationAdjustmentDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustmentDocument) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 10 with PaymentApplicationDocument

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

the class PaymentApplicationAction method createDocument.

@Override
protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
    super.createDocument(kualiDocumentFormBase);
    PaymentApplicationForm form = (PaymentApplicationForm) kualiDocumentFormBase;
    PaymentApplicationDocument document = form.getPaymentApplicationDocument();
    // create new accounts receivable header and set it to the payment application document
    AccountsReceivableDocumentHeaderService accountsReceivableDocumentHeaderService = SpringContext.getBean(AccountsReceivableDocumentHeaderService.class);
    AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = accountsReceivableDocumentHeaderService.getNewAccountsReceivableDocumentHeaderForCurrentUser();
    accountsReceivableDocumentHeader.setDocumentNumber(document.getDocumentNumber());
    document.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
}
Also used : AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) AccountsReceivableDocumentHeaderService(org.kuali.kfs.module.ar.document.service.AccountsReceivableDocumentHeaderService) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) PaymentApplicationForm(org.kuali.kfs.module.ar.document.web.struts.PaymentApplicationForm)

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