Search in sources :

Example 26 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method createPaymentRequest.

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) SpringContext.getBean(DocumentService.class).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(PurapConstants.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 = SpringContext.getBean(CUPaymentMethodGeneralLedgerPendingEntryService.class).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 = SpringContext.getBean(BankService.class).getDefaultBankByDocType(PaymentRequestDocument.class);
    }
    if (defaultBank != null) {
        preqDoc.setBankCode(defaultBank.getBankCode());
        preqDoc.setBank(defaultBank);
    }
    RequisitionDocument reqDoc = SpringContext.getBean(RequisitionService.class).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 = SpringContext.getBean(AccountsPayableService.class).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
    SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCalculateAccountsPayableEvent(preqDoc));
    SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, true);
    processItemsForDiscount(preqDoc, orderHolder);
    if (orderHolder.isInvoiceRejected()) {
        return null;
    }
    SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, false);
    /**
     * PaymentRequestReview
     */
    // PaymentRequestDocumentRule.processRouteDocumentBusinessRules
    SpringContext.getBean(KualiRuleService.class).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()) {
            SpringContext.getBean(DocumentService.class).routeDocument(preqDoc, null, null);
        } else {
            SpringContext.getBean(DocumentService.class).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) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) VendorDetailExtension(edu.cornell.kfs.vnd.businessobject.VendorDetailExtension) RequisitionService(org.kuali.kfs.module.purap.document.service.RequisitionService) 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) PaymentRequestService(org.kuali.kfs.module.purap.document.service.PaymentRequestService) WorkflowException(org.kuali.rice.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) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService) ValidationException(org.kuali.kfs.krad.exception.ValidationException) IOException(java.io.IOException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) CxmlParseException(org.kuali.kfs.module.purap.exception.CxmlParseException) 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.rice.kim.api.identity.Person) AccountsPayableService(org.kuali.kfs.module.purap.document.service.AccountsPayableService) AutoPopulatingList(org.springframework.util.AutoPopulatingList)

Example 27 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method processElectronicInvoice.

// end KFSUPGRADE_483
// KFSUPGRADE-480/KFSUPGRADE-484
@Transactional
protected boolean processElectronicInvoice(ElectronicInvoiceLoad eInvoiceLoad, File invoiceFile, byte[] xmlAsBytes) {
    // Checks parameter to see if files should be moved to the accept/reject folders after load
    boolean moveFiles = BooleanUtils.toBoolean(parameterService.getParameterValueAsString(ElectronicInvoiceStep.class, PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND));
    ElectronicInvoice eInvoice = null;
    boolean isExtractFailure = false;
    boolean isCompleteFailure = false;
    try {
        eInvoice = loadElectronicInvoice(xmlAsBytes);
    } catch (CxmlParseException e) {
        LOG.info("Error loading file - " + e.getMessage());
        rejectElectronicInvoiceFile(eInvoiceLoad, UNKNOWN_DUNS_IDENTIFIER, invoiceFile, e.getMessage(), PurapConstants.ElectronicInvoice.FILE_FORMAT_INVALID);
        isExtractFailure = true;
        updateSummaryCounts(EXTRACT_FAILURES);
    } catch (IllegalArgumentException iae) {
        LOG.info("Error loading file - " + iae.getMessage());
        // rejectElectronicInvoiceFile(eInvoiceLoad, UNKNOWN_DUNS_IDENTIFIER, invoiceFile, iae.getMessage(), PurapConstants.ElectronicInvoice.FILE_FORMAT_INVALID);
        isExtractFailure = true;
        updateSummaryCounts(EXTRACT_FAILURES);
    }
    if (!isExtractFailure) {
        if (ObjectUtils.isNotNull(eInvoice)) {
            eInvoice.setFileName(invoiceFile.getName());
        }
        isCompleteFailure = checkForCompleteFailure(eInvoiceLoad, eInvoice, invoiceFile);
        if (!isCompleteFailure) {
            setVendorDUNSNumber(eInvoice);
            setVendorDetails(eInvoice);
            // CU also refactored getItemTypeMappings with overlay
            Map<String, ElectronicInvoiceItemMapping> itemTypeMappings = getItemTypeMappings(eInvoice.getVendorHeaderID(), eInvoice.getVendorDetailID());
            Map<String, ItemType> kualiItemTypes = getKualiItemTypes();
            if (LOG.isInfoEnabled()) {
                if (itemTypeMappings != null && itemTypeMappings.size() > 0) {
                    LOG.info("Item mappings found");
                }
            }
            boolean validateHeader = true;
            try {
                // ==== CU Customization: Added patterns to test for special characters and/or whitespace. ====
                Pattern specialCharsPattern = Pattern.compile("[^\\p{Graph}\\p{Space}]");
                Pattern specialCharsOrWhitespacePattern = Pattern.compile("[^\\p{Graph}]");
                for (ElectronicInvoiceOrder order : eInvoice.getInvoiceDetailOrders()) {
                    String poID = order.getOrderReferenceOrderID();
                    PurchaseOrderDocument po = null;
                    if (NumberUtils.isDigits(StringUtils.defaultString(poID)) && !isIntegerTooLarge(poID)) {
                        po = purchaseOrderService.getCurrentPurchaseOrder(new Integer(poID));
                        if (po != null) {
                            order.setInvoicePurchaseOrderID(poID);
                            order.setPurchaseOrderID(po.getPurapDocumentIdentifier());
                            order.setPurchaseOrderCampusCode(po.getDeliveryCampusCode());
                            if (LOG.isInfoEnabled()) {
                                LOG.info("PO matching Document found");
                            }
                        }
                    }
                    // ==== CU Customization: Remove special characters from certain ID and description fields. ====
                    Matcher tempMatcher;
                    if (StringUtils.isNotEmpty(order.getOrderReferenceDocumentRefPayloadID())) {
                        tempMatcher = specialCharsOrWhitespacePattern.matcher(order.getOrderReferenceDocumentRefPayloadID());
                        if (tempMatcher.find()) {
                            LOG.warn("Found document ref payload ID with special or whitespace characters; these will be removed. Order: " + order.getOrderReferenceOrderID());
                            order.setOrderReferenceDocumentRefPayloadID(tempMatcher.replaceAll(KRADConstants.EMPTY_STRING));
                        }
                    }
                    if (StringUtils.isNotEmpty(order.getOrderReferenceOrderID())) {
                        tempMatcher = specialCharsOrWhitespacePattern.matcher(order.getOrderReferenceOrderID());
                        if (tempMatcher.find()) {
                            LOG.warn("Found ref order ID with special or whitespace characters; these will be removed. Order: " + order.getOrderReferenceOrderID());
                            order.setOrderReferenceOrderID(tempMatcher.replaceAll(KRADConstants.EMPTY_STRING));
                        }
                    }
                    for (ElectronicInvoiceItem item : order.getInvoiceItems()) {
                        if (StringUtils.isNotEmpty(item.getReferenceDescription())) {
                            tempMatcher = specialCharsPattern.matcher(item.getReferenceDescription());
                            if (tempMatcher.find()) {
                                LOG.warn("Found item description with special characters; these will be removed. Line number: " + item.getInvoiceLineNumber());
                                item.setReferenceDescription(tempMatcher.replaceAll(KRADConstants.EMPTY_STRING));
                            }
                        }
                    }
                    CuElectronicInvoiceOrderHolder orderHolder = new CuElectronicInvoiceOrderHolder(eInvoice, order, po, itemTypeMappings, kualiItemTypes, validateHeader);
                    matchingService.doMatchingProcess(orderHolder);
                    if (orderHolder.isInvoiceRejected()) {
                        ElectronicInvoiceRejectDocument rejectDocument = createRejectDocument(eInvoice, order, eInvoiceLoad);
                        if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
                            rejectDocument.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
                        }
                        String dunsNumber = StringUtils.isEmpty(eInvoice.getDunsNumber()) ? UNKNOWN_DUNS_IDENTIFIER : eInvoice.getDunsNumber();
                        ElectronicInvoiceLoadSummary loadSummary = getOrCreateLoadSummary(eInvoiceLoad, dunsNumber);
                        loadSummary.addFailedInvoiceOrder(rejectDocument.getTotalAmount(), eInvoice);
                        eInvoiceLoad.insertInvoiceLoadSummary(loadSummary);
                        LOG.info("Saving Load Summary for DUNS '" + dunsNumber + "'");
                        SpringContext.getBean(BusinessObjectService.class).save(loadSummary);
                        updateSummaryCounts(REJECT);
                    } else {
                        PaymentRequestDocument preqDoc = createPaymentRequest(orderHolder);
                        if (orderHolder.isInvoiceRejected()) {
                            /**
                             * This is required. If there is anything in the error map, then it's not possible to route the doc since the rice
                             * is throwing error if errormap is not empty before routing the doc.
                             */
                            GlobalVariables.getMessageMap().clearErrorMessages();
                            ElectronicInvoiceRejectDocument rejectDocument = createRejectDocument(eInvoice, order, eInvoiceLoad);
                            if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
                                rejectDocument.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
                            }
                            ElectronicInvoiceLoadSummary loadSummary = getOrCreateLoadSummary(eInvoiceLoad, eInvoice.getDunsNumber());
                            loadSummary.addFailedInvoiceOrder(rejectDocument.getTotalAmount(), eInvoice);
                            eInvoiceLoad.insertInvoiceLoadSummary(loadSummary);
                            LOG.info("Saving Load Summary for DUNS '" + eInvoice.getDunsNumber() + "'");
                            SpringContext.getBean(BusinessObjectService.class).save(loadSummary);
                            updateSummaryCounts(REJECT);
                        } else {
                            ElectronicInvoiceLoadSummary loadSummary = getOrCreateLoadSummary(eInvoiceLoad, eInvoice.getDunsNumber());
                            loadSummary.addSuccessfulInvoiceOrder(preqDoc.getTotalDollarAmount(), eInvoice);
                            eInvoiceLoad.insertInvoiceLoadSummary(loadSummary);
                            LOG.info("Saving Load Summary for DUNS '" + eInvoice.getDunsNumber() + "'");
                            SpringContext.getBean(BusinessObjectService.class).save(loadSummary);
                            updateSummaryCounts(ACCEPT);
                        }
                    }
                    validateHeader = false;
                }
            } catch (Exception ex) {
                LOG.info("Error parsing file - " + ex.getMessage());
                LOG.info("Exception: " + ex.toString());
                rejectElectronicInvoiceFile(eInvoiceLoad, UNKNOWN_DUNS_IDENTIFIER, invoiceFile, ex.getMessage(), PurapConstants.ElectronicInvoice.FILE_FORMAT_INVALID);
                isExtractFailure = true;
                updateSummaryCounts(EXTRACT_FAILURES);
            }
        }
    }
    // Move files into accept/reject folder as appropriate
    boolean success = true;
    if (moveFiles) {
        if (isExtractFailure) {
            LOG.info(invoiceFile.getName() + " has caused a batch extract failure.");
            success = this.moveFile(invoiceFile, getExtractFailureDirName());
            if (!success) {
                String errorMessage = "File with name '" + invoiceFile.getName() + "' could not be moved";
                throw new PurError(errorMessage);
            }
        } else if (isCompleteFailure || (ObjectUtils.isNotNull(eInvoice) && eInvoice.isFileRejected())) {
            LOG.info(invoiceFile.getName() + " has been rejected.");
            success = this.moveFile(invoiceFile, getRejectDirName());
            if (!success) {
                String errorMessage = "File with name '" + invoiceFile.getName() + "' could not be moved";
                throw new PurError(errorMessage);
            }
        } else {
            LOG.info(invoiceFile.getName() + " has been accepted");
            success = this.moveFile(invoiceFile, getAcceptDirName());
            if (!success) {
                String errorMessage = "File with name '" + invoiceFile.getName() + "' could not be moved";
                throw new PurError(errorMessage);
            }
        }
    } else {
        // Add .processed file to each successfully processed einvoice file if move files is not enabled.
        if (!isExtractFailure) {
            String fullPath = FilenameUtils.getFullPath(invoiceFile.getAbsolutePath());
            String fileName = FilenameUtils.getBaseName(invoiceFile.getAbsolutePath());
            File processedFile = new File(fullPath + File.separator + fileName + ".processed");
            try {
                FileUtils.touch(processedFile);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    if (ObjectUtils.isNull(eInvoice)) {
        return true;
    }
    return eInvoice.isFileRejected();
}
Also used : Matcher(java.util.regex.Matcher) ItemType(org.kuali.kfs.module.purap.businessobject.ItemType) ElectronicInvoiceItem(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) Pattern(java.util.regex.Pattern) ElectronicInvoiceStep(org.kuali.kfs.module.purap.batch.ElectronicInvoiceStep) ElectronicInvoiceOrder(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceOrder) ElectronicInvoiceLoadSummary(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoadSummary) ElectronicInvoiceItemMapping(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceItemMapping) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) IOException(java.io.IOException) ValidationException(org.kuali.kfs.krad.exception.ValidationException) IOException(java.io.IOException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) CxmlParseException(org.kuali.kfs.module.purap.exception.CxmlParseException) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) CxmlParseException(org.kuali.kfs.module.purap.exception.CxmlParseException) ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) CuElectronicInvoiceRejectDocument(edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument) PurError(org.kuali.kfs.module.purap.exception.PurError) File(java.io.File) ElectronicInvoice(org.kuali.kfs.module.purap.businessobject.ElectronicInvoice) NonTransactional(org.kuali.kfs.sys.service.NonTransactional) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method setVendorDetails.

protected void setVendorDetails(ElectronicInvoice eInvoice) {
    // based on code found in this class
    // Marcia mentioned that each einvoice just for one po.
    String poID = eInvoice.getInvoiceDetailOrders().get(0).getOrderReferenceOrderID();
    PurchaseOrderDocument po = null;
    if (StringUtils.isNotEmpty(eInvoice.getDunsNumber())) {
        // KFSUPGRADE-479 : retrieve vendor from po vendor.
        VendorDetail vendorDetail = null;
        if (NumberUtils.isDigits(StringUtils.defaultString(poID)) && !isIntegerTooLarge(poID)) {
            po = purchaseOrderService.getCurrentPurchaseOrder(new Integer(poID));
        }
        if (po != null) {
            vendorDetail = vendorService.getVendorDetail(po.getVendorHeaderGeneratedIdentifier(), po.getVendorDetailAssignedIdentifier());
            if (vendorDetail == null) {
                vendorDetail = vendorService.getVendorByDunsNumber(eInvoice.getDunsNumber());
            }
        } else {
            vendorDetail = vendorService.getVendorByDunsNumber(eInvoice.getDunsNumber());
        }
        if (vendorDetail != null) {
            LOG.info("Vendor match found - " + vendorDetail.getVendorNumber());
            eInvoice.setVendorHeaderID(vendorDetail.getVendorHeaderGeneratedIdentifier());
            eInvoice.setVendorDetailID(vendorDetail.getVendorDetailAssignedIdentifier());
            eInvoice.setVendorName(vendorDetail.getVendorName());
        } else {
            eInvoice.setVendorHeaderID(null);
            eInvoice.setVendorDetailID(null);
            eInvoice.setVendorName(null);
        }
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Example 29 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuB2BPurchaseOrderSciquestServiceImplTest method testGetCxml.

public void testGetCxml() throws Exception {
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_B2B.createPurchaseOrderdDocument(documentService);
    String cxml = b2bPurchaseOrderService.getCxml(po, UserNameFixture.ccs1.getPerson().getPrincipalId(), cuB2BPurchaseOrderSciquestServiceImpl.getB2bPurchaseOrderPassword(), po.getVendorContract().getContractManager(), cuB2BPurchaseOrderSciquestServiceImpl.getContractManagerEmail(po.getVendorContract().getContractManager()), po.getVendorDetail().getVendorDunsNumber());
    assertTrue(!cxml.isEmpty());
}
Also used : PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Example 30 with PurchaseOrderDocument

use of org.kuali.kfs.module.purap.document.PurchaseOrderDocument in project cu-kfs by CU-CommunityApps.

the class CuB2BPurchaseOrderSciquestServiceImplTest method testVerifyCxmlPOData_Valid.

public void testVerifyCxmlPOData_Valid() throws Exception {
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_B2B_CXML_VALIDATION.createPurchaseOrderdDocument(documentService);
    String errors = b2bPurchaseOrderService.verifyCxmlPOData(po, UserNameFixture.ccs1.getPerson().getPrincipalId(), cuB2BPurchaseOrderSciquestServiceImpl.getB2bPurchaseOrderPassword(), po.getVendorContract().getContractManager(), cuB2BPurchaseOrderSciquestServiceImpl.getContractManagerEmail(po.getVendorContract().getContractManager()), po.getVendorDetail().getVendorDunsNumber());
    assertTrue(errors.isEmpty());
}
Also used : PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Aggregations

PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)52 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)17 DocumentService (org.kuali.kfs.krad.service.DocumentService)16 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)14 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)9 ArrayList (java.util.ArrayList)6 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)6 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)5 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)4 MessageMap (org.kuali.kfs.krad.util.MessageMap)4 PurchaseOrderAmendmentDocument (org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument)4 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)4 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 Iterator (java.util.Iterator)3