Search in sources :

Example 16 with PaymentRequestDocument

use of org.kuali.kfs.module.purap.document.PaymentRequestDocument 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 17 with PaymentRequestDocument

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

the class CuElectronicInvoiceHelperServiceImpl method routePREQDocuments.

/**
 * @return
 */
protected boolean routePREQDocuments() {
    Collection<String> documentIdList = null;
    try {
        documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, PaymentRequestDocument.class);
    } catch (WorkflowException e1) {
        LOG.error("Error retrieving preq documents for routing: " + e1.getMessage(), e1);
        throw new RuntimeException(e1.getMessage(), e1);
    } catch (RemoteException re) {
        LOG.error("Error retrieving preq documents for routing: " + re.getMessage(), re);
        throw new RuntimeException(re.getMessage(), re);
    }
    // Collections.reverse(documentIdList);
    LOG.info("PREQs to Route: " + documentIdList);
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
    for (String preqDocumentId : documentIdList) {
        try {
            LOG.info("Retrieving PREQ document # " + preqDocumentId + ".");
            PaymentRequestDocument preqDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(preqDocumentId);
            LOG.info("Routing PREQ document # " + preqDocumentId + ".");
            if (preqDocument.getPaymentRequestElectronicInvoiceIndicator()) {
                documentService.prepareWorkflowDocument(preqDocument);
                LOG.info("PREQ document # " + preqDocumentId + " prepared for workflow.");
                // calling workflow service to bypass business rule checks
                workflowDocumentService.route(preqDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
                LOG.info("PREQ document # " + preqDocumentId + " routed.");
            }
        } catch (WorkflowException e) {
            LOG.error("Error routing document # " + preqDocumentId + " " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return true;
}
Also used : WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) RemoteException(java.rmi.RemoteException) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)

Example 18 with PaymentRequestDocument

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

the class CuPdpExtractServiceImpl method updatePaymentRequest.

@Override
protected void updatePaymentRequest(PaymentRequestDocument paymentRequestDocument, Person puser, Date processRunDate) {
    try {
        PaymentRequestDocument doc = (PaymentRequestDocument) documentService.getByDocumentHeaderId(paymentRequestDocument.getDocumentNumber());
        doc.setExtractedTimestamp(new Timestamp(processRunDate.getTime()));
        SpringContext.getBean(PurapService.class).saveDocumentNoValidation(doc);
        // RICE20 replaced searchableAttributeProcessingService.indexDocument with DocumentAttributeIndexingQueue.indexDocument
        DocumentTypeService documentTypeService = SpringContext.getBean(DocumentTypeService.class);
        DocumentType documentType = documentTypeService.getDocumentTypeByName(doc.getFinancialDocumentTypeCode());
        DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(documentType.getApplicationId());
        queue.indexDocument(doc.getDocumentNumber());
    } catch (WorkflowException e) {
        throw new IllegalArgumentException("Unable to retrieve payment request: " + paymentRequestDocument.getDocumentNumber());
    }
}
Also used : PurapService(org.kuali.kfs.module.purap.document.service.PurapService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentType(org.kuali.rice.kew.api.doctype.DocumentType) DocumentAttributeIndexingQueue(org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) DocumentTypeService(org.kuali.rice.kew.api.doctype.DocumentTypeService) Timestamp(java.sql.Timestamp)

Example 19 with PaymentRequestDocument

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

the class CuPdpExtractServiceImpl method addNotes.

@Override
protected void addNotes(AccountsPayableDocument accountsPayableDocument, PaymentDetail paymentDetail) {
    int count = 1;
    if (accountsPayableDocument instanceof PaymentRequestDocument) {
        PaymentRequestDocument prd = (PaymentRequestDocument) accountsPayableDocument;
        if (prd.getSpecialHandlingInstructionLine1Text() != null) {
            PaymentNoteText pnt = new PaymentNoteText();
            pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
            pnt.setCustomerNoteText(CUPurapConstants.SPECIAL_HANDLING_NOTE_LINE_1_NAME + prd.getSpecialHandlingInstructionLine1Text());
            paymentDetail.addNote(pnt);
        }
        if (prd.getSpecialHandlingInstructionLine2Text() != null) {
            PaymentNoteText pnt = new PaymentNoteText();
            pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
            pnt.setCustomerNoteText(CUPurapConstants.SPECIAL_HANDLING_NOTE_LINE_2_ADDRESS + prd.getSpecialHandlingInstructionLine2Text());
            paymentDetail.addNote(pnt);
        }
        if (prd.getSpecialHandlingInstructionLine3Text() != null) {
            PaymentNoteText pnt = new PaymentNoteText();
            pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
            pnt.setCustomerNoteText(CUPurapConstants.SPECIAL_HANDLING_NOTE_LINE_3_CITY_STATE_ZIP + prd.getSpecialHandlingInstructionLine3Text());
            paymentDetail.addNote(pnt);
        }
    }
    if (accountsPayableDocument.getNoteLine1Text() != null) {
        PaymentNoteText pnt = new PaymentNoteText();
        pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
        pnt.setCustomerNoteText(CUPurapConstants.PURAP_NOTES_IDENTIFIER + accountsPayableDocument.getNoteLine1Text());
        paymentDetail.addNote(pnt);
    }
    if (accountsPayableDocument.getNoteLine2Text() != null) {
        PaymentNoteText pnt = new PaymentNoteText();
        pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
        pnt.setCustomerNoteText(CUPurapConstants.PURAP_NOTES_IDENTIFIER + accountsPayableDocument.getNoteLine2Text());
        paymentDetail.addNote(pnt);
    }
    if (accountsPayableDocument.getNoteLine3Text() != null) {
        PaymentNoteText pnt = new PaymentNoteText();
        pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
        pnt.setCustomerNoteText(CUPurapConstants.PURAP_NOTES_IDENTIFIER + accountsPayableDocument.getNoteLine3Text());
        paymentDetail.addNote(pnt);
    }
    PaymentNoteText pnt = new PaymentNoteText();
    pnt.setCustomerNoteLineNbr(new KualiInteger(count++));
    pnt.setCustomerNoteText("Sales Tax: " + accountsPayableDocument.getTotalRemitTax());
}
Also used : PaymentNoteText(org.kuali.kfs.pdp.businessobject.PaymentNoteText) KualiInteger(org.kuali.rice.core.api.util.type.KualiInteger) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument)

Example 20 with PaymentRequestDocument

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

the class CuPurapAccountingServiceImpl method updateAccountAmounts.

/**
 * @see org.kuali.kfs.module.purap.service.PurapAccountingService#updateAccountAmounts(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)
 */
@Override
public void updateAccountAmounts(PurchasingAccountsPayableDocument document) {
    PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) document;
    String accountDistributionMethod = purApDocument.getAccountDistributionMethod();
    KualiRuleService kualiRuleService = SpringContext.getBean(KualiRuleService.class);
    WorkflowDocument workflowDocument = purApDocument.getDocumentHeader().getWorkflowDocument();
    Set<String> nodeNames = workflowDocument.getCurrentNodeNames();
    // don't update if past the AP review level
    if ((document instanceof PaymentRequestDocument) && purapService.isFullDocumentEntryCompleted(document)) {
        if (nodeNames.contains(PaymentRequestStatuses.NODE_PAYMENT_METHOD_REVIEW)) {
            // CU needs this update because the customization allows Treasury Manager to change unit/extended price and 'calculate'
            for (PurApItem item : document.getItems()) {
                updatePreqItemAccountAmountsOnly(item);
            }
        } else {
            convertMoneyToPercent((PaymentRequestDocument) document);
        }
        return;
    }
    document.fixItemReferences();
    // if distribution method is sequential and document is PREQ or VCM then...
    if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
        if (document instanceof VendorCreditMemoDocument) {
            VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
            cmDocument.updateExtendedPriceOnItems();
            for (PurApItem item : document.getItems()) {
                for (PurApAccountingLine account : item.getSourceAccountingLines()) {
                    account.setAmount(KualiDecimal.ZERO);
                }
            }
        }
        // update the accounts amounts for PREQ and distribution method = sequential
        for (PurApItem item : document.getItems()) {
            updatePreqItemAccountAmounts(item);
        }
        return;
    }
    // if distribution method is proportional and document is PREQ or VCM then...
    if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
        // update the accounts amounts for PREQ and distribution method = sequential
        if (document instanceof VendorCreditMemoDocument) {
            VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
            cmDocument.updateExtendedPriceOnItems();
            for (PurApItem item : document.getItems()) {
                for (PurApAccountingLine account : item.getSourceAccountingLines()) {
                    account.setAmount(KualiDecimal.ZERO);
                }
            }
        }
        for (PurApItem item : document.getItems()) {
            boolean rulePassed = true;
            // check any business rules
            rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
            if (rulePassed) {
                updatePreqProportionalItemAccountAmounts(item);
            }
        }
        return;
    }
    // No recalculate if the account distribution method code is equal to "S" sequential ON REQ or POs..
    if (PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
        for (PurApItem item : document.getItems()) {
            boolean rulePassed = true;
            // check any business rules
            rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
            return;
        }
    }
    // do recalculate only if the account distribution method code is not equal to "S" sequential method.
    if (!PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
        for (PurApItem item : document.getItems()) {
            boolean rulePassed = true;
            // check any business rules
            rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
            if (rulePassed) {
                updateItemAccountAmounts(item);
            }
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurchasingAccountsPayableDocumentBase(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PurchasingAccountsPayableItemPreCalculateEvent(org.kuali.kfs.module.purap.document.validation.event.PurchasingAccountsPayableItemPreCalculateEvent)

Aggregations

PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)36 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)21 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)15 DocumentService (org.kuali.kfs.krad.service.DocumentService)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)6 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)5 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)4 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)4 RemoteException (java.rmi.RemoteException)3 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)3 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)3 PaymentRequestService (org.kuali.kfs.module.purap.document.service.PaymentRequestService)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 ActionForward (org.apache.struts.action.ActionForward)2 ValidationException (org.kuali.kfs.krad.exception.ValidationException)2 MessageMap (org.kuali.kfs.krad.util.MessageMap)2 WorkflowDocumentService (org.kuali.kfs.krad.workflow.service.WorkflowDocumentService)2