Search in sources :

Example 1 with ExpiredOrClosedAccountEntry

use of org.kuali.kfs.module.purap.util.ExpiredOrClosedAccountEntry in project cu-kfs by CU-CommunityApps.

the class CuCreditMemoServiceImpl method populateDocumentAfterInit.

/**
 * @see org.kuali.kfs.module.purap.document.service.CreditMemoCreateService#populateDocumentAfterInit(org.kuali.kfs.module.purap.document.CreditMemoDocument)
 */
@Override
public void populateDocumentAfterInit(VendorCreditMemoDocument cmDocument) {
    // make a call to search for expired/closed accounts
    HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = accountsPayableService.getExpiredOrClosedAccountList(cmDocument);
    if (cmDocument.isSourceDocumentPaymentRequest()) {
        populateDocumentFromPreq(cmDocument, expiredOrClosedAccountList);
    } else if (cmDocument.isSourceDocumentPurchaseOrder()) {
        populateDocumentFromPO(cmDocument, expiredOrClosedAccountList);
    } else {
        populateDocumentFromVendor(cmDocument);
    }
    // KFSPTS-1891
    VendorDetail vendorDetail = vendorService.getVendorDetail(cmDocument.getVendorHeaderGeneratedIdentifier(), cmDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNotNull(vendorDetail) && ObjectUtils.isNotNull(vendorDetail.getExtension())) {
        if (vendorDetail.getExtension() instanceof VendorDetailExtension && StringUtils.isNotBlank(((VendorDetailExtension) vendorDetail.getExtension()).getDefaultB2BPaymentMethodCode())) {
            ((CuVendorCreditMemoDocument) cmDocument).setPaymentMethodCode(((VendorDetailExtension) vendorDetail.getExtension()).getDefaultB2BPaymentMethodCode());
        }
    }
    populateDocumentDescription(cmDocument);
    // write a note for expired/closed accounts if any exist and add a message stating there were expired/closed accounts at the
    // top of the document
    accountsPayableService.generateExpiredOrClosedAccountNote(cmDocument, expiredOrClosedAccountList);
    // set indicator so a message is displayed for accounts that were replaced due to expired/closed status
    if (ObjectUtils.isNotNull(expiredOrClosedAccountList) && !expiredOrClosedAccountList.isEmpty()) {
        cmDocument.setContinuationAccountIndicator(true);
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension) ExpiredOrClosedAccountEntry(org.kuali.kfs.module.purap.util.ExpiredOrClosedAccountEntry)

Example 2 with ExpiredOrClosedAccountEntry

use of org.kuali.kfs.module.purap.util.ExpiredOrClosedAccountEntry in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method createPaymentRequest.

@Override
protected PaymentRequestDocument createPaymentRequest(ElectronicInvoiceOrderHolder orderHolder) {
    LOG.info("Creating Payment Request document");
    KNSGlobalVariables.getMessageList().clear();
    validateInvoiceOrderValidForPREQCreation(orderHolder);
    if (LOG.isInfoEnabled()) {
        if (orderHolder.isInvoiceRejected()) {
            LOG.info("Not possible to convert einvoice details into payment request");
        } else {
            LOG.info("Payment request document creation validation succeeded");
        }
    }
    if (orderHolder.isInvoiceRejected()) {
        return null;
    }
    PaymentRequestDocument preqDoc = null;
    try {
        preqDoc = (PaymentRequestDocument) documentService.getNewDocument("PREQ");
    } catch (WorkflowException e) {
        String extraDescription = "Error=" + e.getMessage();
        ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_WORKLOW_EXCEPTION, extraDescription, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason);
        LOG.error("Error creating Payment request document - " + e.getMessage());
        return null;
    }
    PurchaseOrderDocument poDoc = orderHolder.getPurchaseOrderDocument();
    if (poDoc == null) {
        throw new RuntimeException("Purchase Order document (POId=" + poDoc.getPurapDocumentIdentifier() + ") does not exist in the system");
    }
    preqDoc.getDocumentHeader().setDocumentDescription(generatePREQDocumentDescription(poDoc));
    try {
        preqDoc.updateAndSaveAppDocStatus(PaymentRequestStatuses.APPDOC_IN_PROCESS);
    } catch (WorkflowException we) {
        throw new RuntimeException("Unable to save route status data for document: " + preqDoc.getDocumentNumber(), we);
    }
    preqDoc.setInvoiceDate(orderHolder.getInvoiceDate());
    preqDoc.setInvoiceNumber(orderHolder.getInvoiceNumber());
    preqDoc.setVendorInvoiceAmount(new KualiDecimal(orderHolder.getInvoiceNetAmount()));
    preqDoc.setAccountsPayableProcessorIdentifier("E-Invoice");
    preqDoc.setVendorCustomerNumber(orderHolder.getCustomerNumber());
    preqDoc.setPaymentRequestElectronicInvoiceIndicator(true);
    if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
        preqDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
    }
    // Copied from PaymentRequestServiceImpl.populatePaymentRequest()
    // set bank code to default bank code in the system parameter
    // KFSPTS-1891
    boolean hasPaymentMethodCode = false;
    if (preqDoc instanceof PaymentRequestDocument) {
        String vendorPaymentMethodCode = ((VendorDetailExtension) poDoc.getVendorDetail().getExtension()).getDefaultB2BPaymentMethodCode();
        if (StringUtils.isNotEmpty(vendorPaymentMethodCode)) {
            ((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(vendorPaymentMethodCode);
            hasPaymentMethodCode = true;
        } else {
            ((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(DEFAULT_EINVOICE_PAYMENT_METHOD_CODE);
        }
    }
    Bank defaultBank = null;
    if (hasPaymentMethodCode) {
        defaultBank = cUPaymentMethodGeneralLedgerPendingEntryService.getBankForPaymentMethod(((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode());
    } else {
        // default to baseline behavior - extended documents not in use
        // Copied from PaymentRequestServiceImpl.populatePaymentRequest()
        // set bank code to default bank code in the system parameter
        defaultBank = bankService.getDefaultBankByDocType(preqDoc.getClass());
    }
    if (defaultBank != null) {
        preqDoc.setBankCode(defaultBank.getBankCode());
        preqDoc.setBank(defaultBank);
    }
    RequisitionDocument reqDoc = getRequisitionService().getRequisitionById(poDoc.getRequisitionIdentifier());
    String reqDocInitiator = reqDoc.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
    try {
        Person user = KimApiServiceLocator.getPersonService().getPerson(reqDocInitiator);
        setProcessingCampus(preqDoc, user.getCampusCode());
    } catch (Exception e) {
        String extraDescription = "Error setting processing campus code - " + e.getMessage();
        ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason);
        return null;
    }
    HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = getAccountsPayableService().expiredOrClosedAccountsList(poDoc);
    if (expiredOrClosedAccountList == null) {
        expiredOrClosedAccountList = new HashMap();
    }
    if (LOG.isInfoEnabled()) {
        LOG.info(expiredOrClosedAccountList.size() + " accounts has been found as Expired or Closed");
    }
    preqDoc.populatePaymentRequestFromPurchaseOrder(orderHolder.getPurchaseOrderDocument(), expiredOrClosedAccountList);
    // need to populate here for ext price.  it become per item
    // KFSPTS-1719.  convert 1st matching inv item that is qty, but po is non-qty
    checkQtyInvItemForNoQtyOrder(preqDoc, orderHolder);
    populateItemDetails(preqDoc, orderHolder);
    // KFSUPGRADE-485, KFSPTS-1719
    if (CollectionUtils.isNotEmpty(((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems())) {
        for (ElectronicInvoiceItemHolder invItem : ((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems()) {
            PurchaseOrderItem item = (PurchaseOrderItem) ObjectUtils.deepCopy((Serializable) orderHolder.getPurchaseOrderDocument().getItems().get(invItem.getInvoiceItemLineNumber() - 1));
            item.setItemLineNumber(invItem.getInvoiceItemLineNumber());
            item.setItemDescription(((CuElectronicInvoiceItemHolder) invItem).getReferenceDescription());
            // this will be populated to reqitem.poitemunitprice
            item.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
            PaymentRequestItem paymentRequestItem = new PaymentRequestItem(item, preqDoc, expiredOrClosedAccountList);
            ((CuPaymentRequestItemExtension) paymentRequestItem.getExtension()).setInvLineNumber(Integer.parseInt(((CuElectronicInvoiceItemHolder) invItem).getInvLineNumber()));
            // need following in case inv item is qty item
            paymentRequestItem.setItemQuantity(new KualiDecimal(invItem.getInvoiceItemQuantity()));
            paymentRequestItem.setItemUnitOfMeasureCode(invItem.getInvoiceItemUnitOfMeasureCode());
            paymentRequestItem.setPurchaseOrderItemUnitPrice(invItem.getInvoiceItemUnitPrice());
            // if non qty don't need this unit price set, then this need to have a check
            if (invItem.getInvoiceItemQuantity() != null && (new KualiDecimal(invItem.getInvoiceItemQuantity())).isPositive()) {
                paymentRequestItem.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
            }
            paymentRequestItem.setItemCatalogNumber(invItem.getCatalogNumberStripped());
            preqDoc.getItems().add(paymentRequestItem);
            ((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem((CuElectronicInvoiceItemHolder) invItem);
            populateItemDetailsForNonMatching(preqDoc, orderHolder);
            ((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem(null);
        }
    }
    /**
     * Validate totals,paydate
     */
    // PaymentRequestDocumentRule.processCalculateAccountsPayableBusinessRules
    kualiRuleService.applyRules(new AttributedCalculateAccountsPayableEvent(preqDoc));
    paymentRequestService.calculatePaymentRequest(preqDoc, true);
    processItemsForDiscount(preqDoc, orderHolder);
    if (orderHolder.isInvoiceRejected()) {
        return null;
    }
    paymentRequestService.calculatePaymentRequest(preqDoc, false);
    /**
     * PaymentRequestReview
     */
    // PaymentRequestDocumentRule.processRouteDocumentBusinessRules
    kualiRuleService.applyRules(new AttributedPaymentRequestForEInvoiceEvent(preqDoc));
    if (GlobalVariables.getMessageMap().hasErrors()) {
        if (LOG.isInfoEnabled()) {
            LOG.info("***************Error in rules processing - " + GlobalVariables.getMessageMap());
        }
        Map<String, AutoPopulatingList<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
        String errors = errorMessages.toString();
        ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, errors, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason);
        return null;
    }
    if (KNSGlobalVariables.getMessageList().size() > 0) {
        if (LOG.isInfoEnabled()) {
            LOG.info("Payment request contains " + KNSGlobalVariables.getMessageList().size() + " warning message(s)");
            for (int i = 0; i < KNSGlobalVariables.getMessageList().size(); i++) {
                LOG.info("Warning " + i + "  - " + KNSGlobalVariables.getMessageList().get(i));
            }
        }
    }
    addShipToNotes(preqDoc, orderHolder);
    try {
        // KFSUPGRADE-490: Do save-only operations for just non-EIRT-generated PREQs.
        if (orderHolder.isRejectDocumentHolder()) {
            documentService.routeDocument(preqDoc, null, null);
        } else {
            documentService.saveDocument(preqDoc, DocumentSystemSaveEvent.class);
        }
    } catch (WorkflowException e) {
        e.printStackTrace();
        ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_FAILURE, e.getMessage(), orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason);
        return null;
    } catch (ValidationException e) {
        String extraDescription = GlobalVariables.getMessageMap().toString();
        ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
        orderHolder.addInvoiceOrderRejectReason(rejectReason);
        return null;
    }
    return preqDoc;
}
Also used : Serializable(java.io.Serializable) Bank(org.kuali.kfs.sys.businessobject.Bank) ValidationException(org.kuali.kfs.krad.exception.ValidationException) ElectronicInvoiceItemHolder(org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceItemHolder) HashMap(java.util.HashMap) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension) ExpiredOrClosedAccountEntry(org.kuali.kfs.module.purap.util.ExpiredOrClosedAccountEntry) CuPaymentRequestItemExtension(edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension) AttributedCalculateAccountsPayableEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedCalculateAccountsPayableEvent) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) ElectronicInvoiceRejectReason(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason) ValidationException(org.kuali.kfs.krad.exception.ValidationException) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) CxmlParseException(org.kuali.kfs.module.purap.exception.CxmlParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) AttributedPaymentRequestForEInvoiceEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedPaymentRequestForEInvoiceEvent) Person(org.kuali.kfs.kim.api.identity.Person) AutoPopulatingList(org.springframework.util.AutoPopulatingList)

Aggregations

VendorDetailExtension (edu.cornell.kfs.vnd.businessobject.VendorDetailExtension)2 ExpiredOrClosedAccountEntry (org.kuali.kfs.module.purap.util.ExpiredOrClosedAccountEntry)2 CuPaymentRequestItemExtension (edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension)1 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 CuVendorCreditMemoDocument (edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)1 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)1 Person (org.kuali.kfs.kim.api.identity.Person)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 ElectronicInvoiceRejectReason (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason)1 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)1 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)1 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)1