Search in sources :

Example 1 with CustomerInvoiceDocumentService

use of org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService 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)

Aggregations

WorkflowDocument (org.kuali.kfs.kew.api.WorkflowDocument)1 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)1 Document (org.kuali.kfs.krad.document.Document)1 DocumentService (org.kuali.kfs.krad.service.DocumentService)1 AccountsReceivableDocumentHeader (org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader)1 NonInvoicedDistribution (org.kuali.kfs.module.ar.businessobject.NonInvoicedDistribution)1 CashControlDocument (org.kuali.kfs.module.ar.document.CashControlDocument)1 CustomerInvoiceDocument (org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)1 PaymentApplicationDocument (org.kuali.kfs.module.ar.document.PaymentApplicationDocument)1 CustomerInvoiceDocumentService (org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService)1