Search in sources :

Example 11 with PaymentApplicationDocument

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

the class PaymentApplicationAction method applyNonInvoiced.

protected NonInvoiced applyNonInvoiced(PaymentApplicationForm payAppForm) throws WorkflowException {
    PaymentApplicationDocument applicationDocument = (PaymentApplicationDocument) payAppForm.getDocument();
    NonInvoiced nonInvoiced = payAppForm.getNonInvoicedAddLine();
    // amount entered is blank or zero.
    if (ObjectUtils.isNull(payAppForm.getNonInvoicedAddLine()) || nonInvoiced.getFinancialDocumentLineAmount() == null || nonInvoiced.getFinancialDocumentLineAmount().isZero()) {
        return null;
    }
    // If we got past the above conditional, wire it up for adding
    nonInvoiced.setFinancialDocumentPostingYear(applicationDocument.getPostingYear());
    nonInvoiced.setDocumentNumber(applicationDocument.getDocumentNumber());
    nonInvoiced.setFinancialDocumentLineNumber(payAppForm.getNextNonInvoicedLineNumber());
    if (StringUtils.isNotBlank(nonInvoiced.getChartOfAccountsCode())) {
        nonInvoiced.setChartOfAccountsCode(nonInvoiced.getChartOfAccountsCode().toUpperCase(Locale.US));
    }
    // run the validations
    boolean isValid = PaymentApplicationDocumentRuleUtil.validateNonInvoiced(nonInvoiced, applicationDocument, payAppForm.getTotalFromControl());
    // check the validation results and return null if there were any errors
    if (!isValid) {
        return null;
    }
    return nonInvoiced;
}
Also used : PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) NonInvoiced(org.kuali.kfs.module.ar.businessobject.NonInvoiced)

Example 12 with PaymentApplicationDocument

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

the class PaymentApplicationAction method deleteNonArLine.

public ActionForward deleteNonArLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PaymentApplicationForm paymentApplicationForm = (PaymentApplicationForm) form;
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    int deleteIndex = getLineToDelete(request);
    paymentApplicationDocument.getNonInvoiceds().remove(deleteIndex);
    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");
    }
    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) NonInvoiced(org.kuali.kfs.module.ar.businessobject.NonInvoiced)

Example 13 with PaymentApplicationDocument

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

the class PaymentApplicationAction method filterTempInvoicePaidApplieds.

protected List<InvoicePaidApplied> filterTempInvoicePaidApplieds(PaymentApplicationForm paymentApplicationForm) {
    PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
    List<InvoicePaidApplied> invoicePaidApplieds = paymentApplicationDocument.getInvoicePaidApplieds();
    return new ArrayList<>(invoicePaidApplieds);
}
Also used : InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) ArrayList(java.util.ArrayList) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument)

Example 14 with PaymentApplicationDocument

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

the class PaymentApplicationAction method loadInvoices.

/**
 * This method loads the invoices for currently selected customer
 *
 * @param payAppForm
 * @param selectedInvoiceNumber
 */
protected void loadInvoices(PaymentApplicationForm payAppForm, String selectedInvoiceNumber) {
    PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
    AccountsReceivableDocumentHeader arDocHeader = payAppDoc.getAccountsReceivableDocumentHeader();
    String currentInvoiceNumber = selectedInvoiceNumber;
    // entered against the db, and complain to the user if either is not right.
    if (StringUtils.isNotBlank(payAppForm.getSelectedCustomerNumber())) {
        Map<String, String> pkMap = new HashMap<>();
        pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getSelectedCustomerNumber());
        int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
        if (found == 0) {
            addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
        }
    }
    boolean validInvoice = this.isValidInvoice(payAppForm);
    if (!validInvoice) {
        addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_NUMBER, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_NOT_FINAL);
    }
    // form with an empty customer number wherever possible.
    if (StringUtils.isBlank(payAppForm.getSelectedCustomerNumber())) {
        if (StringUtils.isBlank(arDocHeader.getCustomerNumber())) {
            if (payAppDoc.hasCashControlDetail()) {
                payAppForm.setSelectedCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
                arDocHeader.setCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
            }
        } else {
            payAppForm.setSelectedCustomerNumber(arDocHeader.getCustomerNumber());
        }
    } else {
        arDocHeader.setCustomerNumber(payAppForm.getSelectedCustomerNumber());
    }
    String customerNumber = payAppForm.getSelectedCustomerNumber();
    // Invoice number entered, but no customer number entered
    if (StringUtils.isBlank(customerNumber) && StringUtils.isNotBlank(currentInvoiceNumber) && validInvoice) {
        Customer customer = getCustomerInvoiceDocumentService().getCustomerByInvoiceDocumentNumber(currentInvoiceNumber);
        customerNumber = customer.getCustomerNumber();
        payAppDoc.getAccountsReceivableDocumentHeader().setCustomerNumber(customerNumber);
    }
    // load up the control docs and non-applied holdings for non-cash-control payapps
    if (StringUtils.isNotBlank(customerNumber)) {
        if (!payAppDoc.hasCashControlDocument()) {
            List<PaymentApplicationDocument> nonAppliedControlDocs = new ArrayList<>();
            List<NonAppliedHolding> nonAppliedControlHoldings = new ArrayList<>();
            // documents and nonapplied holdings that this doc paid against.
            if (payAppDoc.isFinal()) {
                nonAppliedControlDocs.addAll(payAppDoc.getPaymentApplicationDocumentsUsedAsControlDocuments());
                nonAppliedControlHoldings.addAll(payAppDoc.getNonAppliedHoldingsUsedAsControls());
            } else {
                // otherwise, we pull all available non-zero non-applied holdings for
                // this customer, and make the associated docs and non-applied holdings available
                // retrieve the set of available non-applied holdings for this customer
                nonAppliedControlHoldings.addAll(getNonAppliedHoldingService().getNonAppliedHoldingsForCustomer(customerNumber));
                // get the parent list of payapp documents that they come from
                List<String> controlDocNumbers = new ArrayList<>();
                for (NonAppliedHolding nonAppliedHolding : nonAppliedControlHoldings) {
                    if (nonAppliedHolding.getAvailableUnappliedAmount().isPositive() && !controlDocNumbers.contains(nonAppliedHolding.getReferenceFinancialDocumentNumber())) {
                        controlDocNumbers.add(nonAppliedHolding.getReferenceFinancialDocumentNumber());
                    }
                }
                // only try to retrieve docs if we have any to retrieve
                if (!controlDocNumbers.isEmpty()) {
                    try {
                        List<Document> docs = getDocumentService().getDocumentsByListOfDocumentHeaderIds(PaymentApplicationDocument.class, controlDocNumbers);
                        for (Document doc : docs) {
                            nonAppliedControlDocs.add((PaymentApplicationDocument) doc);
                        }
                    } catch (WorkflowException e) {
                        throw new RuntimeException("A runtimeException was thrown when trying to retrieve a list " + "of documents.", e);
                    }
                }
            }
            // set the form vars from what we've loaded up here
            payAppForm.setNonAppliedControlDocs(nonAppliedControlDocs);
            payAppForm.setNonAppliedControlHoldings(nonAppliedControlHoldings);
            payAppDoc.setNonAppliedHoldingsForCustomer(new ArrayList<>(nonAppliedControlHoldings));
            payAppForm.setNonAppliedControlAllocations(null);
        }
    }
    // reload invoices for the selected customer number
    if (StringUtils.isNotBlank(customerNumber)) {
        Collection<CustomerInvoiceDocument> openInvoicesForCustomer;
        // at this point, we want to show the invoices it paid against, NOT the set of open invoices
        if (payAppDoc.isFinal()) {
            openInvoicesForCustomer = payAppDoc.getInvoicesPaidAgainst();
        } else {
            openInvoicesForCustomer = getCustomerInvoiceDocumentService().getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
        }
        payAppForm.setInvoices(new ArrayList<>(openInvoicesForCustomer));
        payAppForm.setupInvoiceWrappers(payAppDoc.getDocumentNumber());
    }
    // if no invoice number entered than get the first invoice
    if (StringUtils.isNotBlank(customerNumber) && StringUtils.isBlank(currentInvoiceNumber)) {
        if (payAppForm.getInvoices() == null || payAppForm.getInvoices().isEmpty()) {
            currentInvoiceNumber = null;
        } else {
            currentInvoiceNumber = payAppForm.getInvoices().get(0).getDocumentNumber();
        }
    }
    // load information for the current selected invoice
    if (StringUtils.isNotBlank(currentInvoiceNumber)) {
        payAppForm.setSelectedInvoiceDocumentNumber(currentInvoiceNumber);
        payAppForm.setEnteredInvoiceDocumentNumber(currentInvoiceNumber);
    }
    // Make sure the invoice applies state are up to date
    for (PaymentApplicationInvoiceApply invoiceApplication : payAppForm.getInvoiceApplications()) {
        updateInvoiceApplication(payAppDoc, invoiceApplication);
    }
    // clear any NonInvoiced add line information from the form vars
    payAppForm.setNonInvoicedAddLine(null);
    // load any NonAppliedHolding information into the form vars
    if (payAppDoc.getNonAppliedHolding() != null) {
        payAppForm.setNonAppliedHoldingCustomerNumber(payAppDoc.getNonAppliedHolding().getCustomerNumber());
        payAppForm.setNonAppliedHoldingAmount(payAppDoc.getNonAppliedHolding().getFinancialDocumentLineAmount());
    } else {
        // clear any NonAppliedHolding information from the form vars if it's empty
        payAppForm.setNonAppliedHoldingCustomerNumber(null);
        payAppForm.setNonAppliedHoldingAmount(null);
    }
    // Presort this list to not reload in the jsp - https://jira.kuali.org/browse/KFSCNTRB-1377
    payAppForm.setInvoiceApplications(sortInvoiceApplications(payAppForm.getInvoiceApplications()));
}
Also used : HashMap(java.util.HashMap) Customer(org.kuali.kfs.module.ar.businessobject.Customer) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) NonAppliedHolding(org.kuali.kfs.module.ar.businessobject.NonAppliedHolding) PaymentApplicationAdjustmentDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustmentDocument) Document(org.kuali.kfs.krad.document.Document) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) AccountsReceivableDocumentHeader(org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) CustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)

Example 15 with PaymentApplicationDocument

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

the class PaymentApplicationForm method isFinalOrProcessed.

private boolean isFinalOrProcessed() {
    final Collection<WorkflowDocument> workflowDocuments = new LinkedList<>();
    final PaymentApplicationDocument appDocument = getPaymentApplicationDocument();
    // Include this APP
    final WorkflowDocument appWorkflowDocument = extractWorkFlowDocument(appDocument);
    workflowDocuments.add(appWorkflowDocument);
    if (appDocument.hasCashControlDetail()) {
        final CashControlDocument cashControlDocument = appDocument.getCashControlDocument();
        // Include this APP's CashControl
        final WorkflowDocument ccWorkflowDocument = extractWorkFlowDocument(cashControlDocument);
        workflowDocuments.add(ccWorkflowDocument);
        // Include any other APPs associated with the CashControl
        final List<CashControlDetail> cashControlDetails = cashControlDocument.getCashControlDetails();
        for (final CashControlDetail cashControlDetail : cashControlDetails) {
            final PaymentApplicationDocument otherAppDocument = cashControlDetail.getReferenceFinancialDocument();
            if (otherAppDocument.getDocumentNumber().equals(appDocument.getDocumentNumber())) {
                // Do not add this Document again; it was added above
                continue;
            }
            final WorkflowDocument otherAppWorkflowDocument = extractWorkFlowDocument(otherAppDocument);
            workflowDocuments.add(otherAppWorkflowDocument);
        }
    }
    return workflowDocuments.stream().allMatch(wfDocument -> wfDocument.isFinal() || wfDocument.isProcessed());
}
Also used : CashControlDocument(org.kuali.kfs.module.ar.document.CashControlDocument) WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument) CashControlDetail(org.kuali.kfs.module.ar.businessobject.CashControlDetail) PaymentApplicationDocument(org.kuali.kfs.module.ar.document.PaymentApplicationDocument) LinkedList(java.util.LinkedList)

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