コード例 #1
0
  protected ActionForward askQuestionsAndPerformReopenPurchaseOrder(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    LOG.debug("askQuestionsAndPerformDocumentAction started.");
    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    AccountsPayableDocumentBase apDoc =
        (AccountsPayableDocumentBase) kualiDocumentFormBase.getDocument();
    Object question = request.getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
    String questionType = PODocumentsStrings.REOPEN_PO_QUESTION;
    String confirmType = PODocumentsStrings.CONFIRM_REOPEN_QUESTION;
    String messageType = PurapKeyConstants.PURCHASE_ORDER_MESSAGE_REOPEN_DOCUMENT;
    String operation = "Reopen ";

    try {
      ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class);

      // Start in logic for confirming the proposed operation.
      if (ObjectUtils.isNull(question)) {
        String key =
            kualiConfiguration.getPropertyValueAsString(
                PurapKeyConstants.PURCHASE_ORDER_QUESTION_DOCUMENT);
        String message = StringUtils.replace(key, "{0}", operation);
        return this.performQuestionWithoutInput(
            mapping,
            form,
            request,
            response,
            questionType,
            message,
            KFSConstants.CONFIRMATION_QUESTION,
            questionType,
            "");
      } else {
        Object buttonClicked = request.getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
        if (question.equals(questionType) && buttonClicked.equals(ConfirmationQuestion.NO)) {
          // If 'No' is the button clicked, just reload the doc
          return mapping.findForward(KFSConstants.MAPPING_BASIC);
        } else if (question.equals(confirmType)
            && buttonClicked.equals(SingleConfirmationQuestion.OK)) {
          // This is the case when the user clicks on "OK" in the end; redirect to the preq doc
          return mapping.findForward(KFSConstants.MAPPING_BASIC);
        }
      }

      PurchaseOrderDocument po = apDoc.getPurchaseOrderDocument();
      if (!po.isPendingActionIndicator()
          && PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(
              po.getApplicationDocumentStatus())) {
        /*
         * Below if-else code block calls PurchaseOrderService methods that will throw ValidationException objects if errors
         * occur during any process in the attempt to perform its actions. Assume, if these return successfully, that the
         * PurchaseOrderDocument object returned from each is the newly created document and that all actions in the method
         * were run correctly. NOTE: IF BELOW IF-ELSE IS EDITED THE NEW METHODS CALLED MUST THROW ValidationException OBJECT
         * IF AN ERROR IS ADDED TO THE GlobalVariables
         */
        po = initiateReopenPurchaseOrder(po, kualiDocumentFormBase.getAnnotation());

        if (!GlobalVariables.getMessageMap().hasNoErrors()) {
          throw new ValidationException("errors occurred during new PO creation");
        }

        if (StringUtils.isNotEmpty(messageType)) {
          KNSGlobalVariables.getMessageList().add(messageType);
        }
        return this.performQuestionWithoutInput(
            mapping,
            form,
            request,
            response,
            confirmType,
            kualiConfiguration.getPropertyValueAsString(messageType),
            PODocumentsStrings.SINGLE_CONFIRMATION_QUESTION,
            questionType,
            "");
      } else {
        return this.performQuestionWithoutInput(
            mapping,
            form,
            request,
            response,
            confirmType,
            "Unable to reopen the PO at this time due to the incorrect PO status or a pending PO change document.",
            PODocumentsStrings.SINGLE_CONFIRMATION_QUESTION,
            questionType,
            "");
      }

    } catch (ValidationException ve) {
      throw ve;
    }
  }
コード例 #2
0
  /**
   * Handles continue request. This request comes from the initial screen which gives indicates
   * whether the type is payment request, purchase order, or vendor. Based on that, the credit memo
   * is initially populated and the remaining tabs shown.
   *
   * @param mapping An ActionMapping
   * @param form An ActionForm
   * @param request The HttpServletRequest
   * @param response The HttpServletResponse
   * @throws Exception
   * @return An ActionForward
   */
  public ActionForward continueCreditMemo(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    VendorCreditMemoForm cmForm = (VendorCreditMemoForm) form;
    VendorCreditMemoDocument creditMemoDocument = (VendorCreditMemoDocument) cmForm.getDocument();

    String defaultDistributionMethod =
        SpringContext.getBean(ParameterService.class)
            .getParameterValueAsString(
                PurapConstants.PURAP_NAMESPACE,
                "Document",
                PurapParameterConstants.DISTRIBUTION_METHOD_FOR_ACCOUNTING_LINES);

    String preqId = request.getParameter("document.paymentRequestIdentifier");
    if (!StringUtils.isEmpty(preqId)) {
      // get the po document and get the account distribution method code....
      String distributionCode = getDistributionMethodFromPReq(preqId);
      if (ObjectUtils.isNotNull(distributionCode)) {
        defaultDistributionMethod = distributionCode;
      }
    } else {
      String poId = request.getParameter("document.purchaseOrderIdentifier");
      if (!StringUtils.isEmpty(poId)) {
        // get the po document and get the account distribution method code....
        String distributionCode = getDistributionMethodFromPO(poId);
        if (ObjectUtils.isNotNull(distributionCode)) {
          defaultDistributionMethod = distributionCode;
        }
      }
    }

    // set the account distribution method code on the document.
    creditMemoDocument.setAccountDistributionMethod(defaultDistributionMethod);

    boolean rulePassed =
        SpringContext.getBean(KualiRuleService.class)
            .applyRules(new AttributedContinuePurapEvent(creditMemoDocument));
    if (!rulePassed) {
      return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }

    if (creditMemoDocument.isSourceDocumentPaymentRequest()) {
      PaymentRequestDocument preq =
          SpringContext.getBean(PaymentRequestService.class)
              .getPaymentRequestById(creditMemoDocument.getPaymentRequestIdentifier());
      if (ObjectUtils.isNotNull(preq)) {
        // TODO figure out a more straightforward way to do this.  ailish put this in so the link id
        // would be set and the perm check would work
        creditMemoDocument.setAccountsPayablePurchasingDocumentLinkIdentifier(
            preq.getAccountsPayablePurchasingDocumentLinkIdentifier());

        if (!SpringContext.getBean(DocumentHelperService.class)
            .getDocumentAuthorizer(creditMemoDocument)
            .isAuthorizedByTemplate(
                creditMemoDocument,
                KRADConstants.KNS_NAMESPACE,
                KimConstants.PermissionTemplateNames.OPEN_DOCUMENT,
                GlobalVariables.getUserSession().getPrincipalId())) {
          throw buildAuthorizationException("initiate document", creditMemoDocument);
        }
      }
    } else if (creditMemoDocument.isSourceDocumentPurchaseOrder()) {
      PurchaseOrderDocument po =
          SpringContext.getBean(PurchaseOrderService.class)
              .getCurrentPurchaseOrder(creditMemoDocument.getPurchaseOrderIdentifier());
      if (ObjectUtils.isNotNull(po)) {
        // TODO figure out a more straightforward way to do this.  ailish put this in so the link id
        // would be set and the perm check would work
        creditMemoDocument.setAccountsPayablePurchasingDocumentLinkIdentifier(
            po.getAccountsPayablePurchasingDocumentLinkIdentifier());

        if (!SpringContext.getBean(DocumentHelperService.class)
            .getDocumentAuthorizer(creditMemoDocument)
            .isAuthorizedByTemplate(
                creditMemoDocument,
                KRADConstants.KNS_NAMESPACE,
                KimConstants.PermissionTemplateNames.OPEN_DOCUMENT,
                GlobalVariables.getUserSession().getPrincipalId())) {
          throw buildAuthorizationException("initiate document", creditMemoDocument);
        }
      }
    } else {
      // do nothing for credit memos against a vendor; no link to PO means no need to hide doc based
      // on sensitive data
    }

    // preform duplicate check which will forward to a question prompt if one is found
    ActionForward forward =
        performDuplicateCreditMemoCheck(mapping, form, request, response, creditMemoDocument);
    if (forward != null) {
      return forward;
    }

    // perform validation of init tab
    SpringContext.getBean(CreditMemoService.class).populateAndSaveCreditMemo(creditMemoDocument);

    // sort below the line (doesn't really need to be done on CM, but will help if we ever bring btl
    // from other docs)
    SpringContext.getBean(PurapService.class).sortBelowTheLine(creditMemoDocument);

    // update the counts on the form
    cmForm.updateItemCounts();

    // if source is (PREQ or PO) and the PO status is CLOSED, automatically reopen the PO
    PurchaseOrderDocument po = creditMemoDocument.getPurchaseOrderDocument();
    if ((creditMemoDocument.isSourceDocumentPaymentRequest()
            || creditMemoDocument.isSourceDocumentPurchaseOrder())
        && PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(
            po.getApplicationDocumentStatus())) {
      initiateReopenPurchaseOrder(po, cmForm.getAnnotation());
    }

    // update the accounts amounts to zero.  The recalculate will calculate the totals...
    List<PurApItem> items = creditMemoDocument.getItems();

    for (PurApItem item : items) {
      for (PurApAccountingLine accountLine : item.getSourceAccountingLines()) {
        accountLine.setAmount(KualiDecimal.ZERO);
      }
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }