Search in sources :

Example 1 with ContractsGrantsPaymentHistoryReport

use of org.kuali.kfs.module.ar.businessobject.ContractsGrantsPaymentHistoryReport in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsPaymentHistoryReportLookupableHelperServiceImpl method performLookup.

/*
     * back-port FINP-7396
     */
@Override
public Collection<ContractsGrantsPaymentHistoryReport> performLookup(LookupForm lookupForm, Collection<ResultRow> resultTable, boolean bounded) {
    Map<String, String> lookupFormFields = lookupForm.getFieldsForLookup();
    setBackLocation(lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION));
    setDocFormKey(lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY));
    Collection<ContractsGrantsPaymentHistoryReport> displayList = new ArrayList<>();
    Map<String, String> invoiceAppliedLookupFields = new HashMap<>();
    if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_TYPE)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + KFSPropertyConstants.DOCUMENT_HEADER + "." + KFSPropertyConstants.WORKFLOW_DOCUMENT_TYPE_NAME, lookupFormFields.get(ArPropertyConstants.INVOICE_TYPE));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_NUMBER)) {
        invoiceAppliedLookupFields.put(KFSPropertyConstants.DOCUMENT_NUMBER, lookupFormFields.get(ArPropertyConstants.PAYMENT_NUMBER));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER_NUMBER, lookupFormFields.get(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_AMOUNT)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDetailFields.INVOICE_ITEM_APPLIED_AMOUNT, lookupFormFields.get(ArPropertyConstants.PAYMENT_AMOUNT));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_NUMBER)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDocumentFields.FINANCIAL_DOCUMENT_REF_INVOICE_NUMBER, lookupFormFields.get(ArPropertyConstants.INVOICE_NUMBER));
    }
    Collection<InvoicePaidApplied> invoicePaidApplieds = getLookupService().findCollectionBySearchHelper(InvoicePaidApplied.class, invoiceAppliedLookupFields, true);
    // For each Cash Control doc, get a list of payment app doc numbers
    try {
        for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
            boolean useInvoicePaidApplied = true;
            final Document doc = getDocumentService().getByDocumentHeaderId(invoicePaidApplied.getDocumentNumber());
            if (doc instanceof PaymentApplicationAdjustableDocument) {
                final PaymentApplicationAdjustableDocument paymentApp = (PaymentApplicationAdjustableDocument) doc;
                if (getFinancialSystemDocumentService().getUnsuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                    useInvoicePaidApplied = false;
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR))) {
                    final String appliedIndicator = lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR);
                    if (KRADConstants.YES_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                        useInvoicePaidApplied = false;
                    } else if (KRADConstants.NO_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getPendingDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                        useInvoicePaidApplied = false;
                    }
                }
                final DateTime dateFinalized = paymentApp.getDocumentHeader().getWorkflowDocument().getDateFinalized();
                Date paymentAppFinalDate = null;
                if (dateFinalized != null) {
                    paymentAppFinalDate = dateFinalized.toDate();
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE))) {
                    final Date toPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE));
                    if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, toPaymentDate) && toPaymentDate.before(paymentAppFinalDate)) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE))) {
                    final Date fromPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE));
                    if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, fromPaymentDate) && fromPaymentDate.after(paymentAppFinalDate)) {
                        useInvoicePaidApplied = false;
                    }
                }
                final ContractsGrantsInvoiceDocument cgInvoiceDocument = getBusinessObjectService().findBySinglePrimaryKey(ContractsGrantsInvoiceDocument.class, invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
                OperatorAndValue invoiceAmountOperator = buildOperatorAndValueFromField(lookupFormFields, ArPropertyConstants.INVOICE_AMOUNT);
                if (invoiceAmountOperator != null && !invoiceAmountOperator.applyComparison(cgInvoiceDocument.getTotalDollarAmount())) {
                    useInvoicePaidApplied = false;
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
                    if (!StringUtils.equals(cgInvoiceDocument.getInvoiceGeneralDetail().getAward().getProposalNumber(), lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR))) {
                    final String reversedIndicator = lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR);
                    if (KRADConstants.YES_INDICATOR_VALUE.equals(reversedIndicator) && !cgInvoiceDocument.isInvoiceReversal()) {
                        useInvoicePaidApplied = false;
                    } else if (KRADConstants.NO_INDICATOR_VALUE.equals(reversedIndicator) & cgInvoiceDocument.isInvoiceReversal()) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (useInvoicePaidApplied) {
                    ContractsGrantsPaymentHistoryReport cgPaymentHistoryReport = new ContractsGrantsPaymentHistoryReport();
                    cgPaymentHistoryReport.setPaymentNumber(invoicePaidApplied.getDocumentNumber());
                    cgPaymentHistoryReport.setPaymentDocumentType(paymentApp.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
                    FinancialSystemDocumentHeader documentHeader = (FinancialSystemDocumentHeader) cgInvoiceDocument.getDocumentHeader();
                    cgPaymentHistoryReport.setInvoiceType(documentHeader.getWorkflowDocumentTypeName());
                    cgPaymentHistoryReport.setPaymentAmount(invoicePaidApplied.getInvoiceItemAppliedAmount());
                    cgPaymentHistoryReport.setInvoiceNumber(invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
                    if (dateFinalized != null) {
                        cgPaymentHistoryReport.setPaymentDate(new java.sql.Date(dateFinalized.getMillis()));
                    }
                    cgPaymentHistoryReport.setAppliedIndicator(getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode()));
                    if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail())) {
                        cgPaymentHistoryReport.setAwardNumber(cgInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
                    }
                    cgPaymentHistoryReport.setReversedIndicator(cgInvoiceDocument.isInvoiceReversal());
                    cgPaymentHistoryReport.setCustomerNumber(cgInvoiceDocument.getCustomerNumber());
                    cgPaymentHistoryReport.setCustomerName(cgInvoiceDocument.getCustomer().getCustomerName());
                    cgPaymentHistoryReport.setInvoiceAmount(cgInvoiceDocument.getTotalDollarAmount());
                    displayList.add(cgPaymentHistoryReport);
                }
            }
        }
        buildResultTable(lookupForm, displayList, resultTable);
    } catch (WorkflowException we) {
        throw new RuntimeException("Could not open payment application document related to search", we);
    } catch (ParseException pe) {
        throw new RuntimeException("I tried to validate the date and amount fields related to search, I really " + "did.  But...I guess I didn't try hard enough", pe);
    }
    return displayList;
}
Also used : ContractsGrantsPaymentHistoryReport(org.kuali.kfs.module.ar.businessobject.ContractsGrantsPaymentHistoryReport) HashMap(java.util.HashMap) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) Document(org.kuali.kfs.krad.document.Document) PaymentApplicationAdjustableDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustableDocument) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) DateTime(org.joda.time.DateTime) Date(java.util.Date) PaymentApplicationAdjustableDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustableDocument) InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) ParseException(java.text.ParseException) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)

Aggregations

ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)1 Document (org.kuali.kfs.krad.document.Document)1 ContractsGrantsPaymentHistoryReport (org.kuali.kfs.module.ar.businessobject.ContractsGrantsPaymentHistoryReport)1 InvoicePaidApplied (org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied)1 ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)1 PaymentApplicationAdjustableDocument (org.kuali.kfs.module.ar.document.PaymentApplicationAdjustableDocument)1 FinancialSystemDocumentHeader (org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader)1