public PurchaseOrderDocument initiateReopenPurchaseOrder(
      PurchaseOrderDocument po, String annotation) {
    try {
      LogicContainer logicToRun =
          new LogicContainer() {
            public Object runLogic(Object[] objects) throws Exception {
              PurchaseOrderDocument po = (PurchaseOrderDocument) objects[0];

              Note cancelNote = new Note();
              cancelNote.setNoteTypeCode(po.getNoteType().getCode());
              cancelNote.setAuthorUniversalIdentifier(
                  GlobalVariables.getUserSession().getPerson().getPrincipalId());
              cancelNote.setNoteText(
                  SpringContext.getBean(ConfigurationService.class)
                      .getPropertyValueAsString(PurapKeyConstants.AP_REOPENS_PURCHASE_ORDER_NOTE));
              cancelNote.setNotePostedTimestampToCurrent();
              po.addNote(cancelNote);
              SpringContext.getBean(PurapService.class).saveDocumentNoValidation(po);

              return SpringContext.getBean(PurchaseOrderService.class)
                  .createAndRoutePotentialChangeDocument(
                      po.getDocumentNumber(),
                      PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT,
                      (String) objects[1],
                      null,
                      PurchaseOrderStatuses.APPDOC_PENDING_REOPEN);
            }
          };
      return (PurchaseOrderDocument)
          SpringContext.getBean(PurapService.class)
              .performLogicWithFakedUserSession(
                  KFSConstants.SYSTEM_USER, logicToRun, new Object[] {po, annotation});
    } catch (WorkflowException e) {
      String errorMsg = "Workflow Exception caught: " + e.getLocalizedMessage();
      LOG.error(errorMsg, e);
      throw new RuntimeException(errorMsg, e);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  protected void spawnPoAmendmentForUnorderedItems(
      ReceivingDocument receivingDocument, PurchaseOrderDocument po) {

    // if receiving line document
    if (receivingDocument instanceof LineItemReceivingDocument) {
      LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) receivingDocument;

      // if a new item has been added spawn a purchase order amendment
      if (hasNewUnorderedItem((LineItemReceivingDocument) receivingDocument)) {
        String newSessionUserId = KFSConstants.SYSTEM_USER;
        try {

          LogicContainer logicToRun =
              new LogicContainer() {
                @Override
                public Object runLogic(Object[] objects) throws Exception {
                  LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) objects[0];
                  String poDocNumber = (String) objects[1];

                  // create a PO amendment
                  PurchaseOrderAmendmentDocument amendmentPo =
                      (PurchaseOrderAmendmentDocument)
                          purchaseOrderService.createAndSavePotentialChangeDocument(
                              poDocNumber,
                              PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT,
                              PurchaseOrderStatuses.APPDOC_AMENDMENT);

                  // KFSPTS-1769, KFSUPGRADE-339
                  ((CuPurchaseOrderAmendmentDocument) amendmentPo).setSpawnPoa(true);
                  // add new lines to amendement
                  addUnorderedItemsToAmendment(amendmentPo, rlDoc);

                  // route amendment
                  documentService.routeDocument(amendmentPo, null, null);

                  // add note to amendment po document
                  String note =
                      "Purchase Order Amendment "
                          + amendmentPo.getPurapDocumentIdentifier()
                          + " (document id "
                          + amendmentPo.getDocumentNumber()
                          + ") created for new unordered line items due to Receiving (document id "
                          + rlDoc.getDocumentNumber()
                          + ")";

                  Note noteObj = documentService.createNoteFromDocument(amendmentPo, note);
                  amendmentPo.addNote(noteObj);
                  noteService.save(noteObj);

                  return null;
                }
              };

          purapService.performLogicWithFakedUserSession(
              newSessionUserId, logicToRun, new Object[] {rlDoc, po.getDocumentNumber()});
        } catch (WorkflowException e) {
          String errorMsg = "Workflow Exception caught: " + e.getLocalizedMessage();
          throw new RuntimeException(errorMsg, e);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }
  }