/**
   * Builds the PaymentDetail for the given reimbursable travel & entertainment document
   *
   * @param document the reimbursable travel & entertainment document to create a payment for
   * @param processRunDate the date when the extraction is occurring
   * @return a PaymentDetail to add to the PaymentGroup
   */
  protected PaymentDetail buildPaymentDetail(
      TEMReimbursementDocument document, Date processRunDate) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("buildPaymentDetail() started");
    }

    PaymentDetail pd = new PaymentDetail();
    if (StringUtils.isNotEmpty(document.getDocumentHeader().getOrganizationDocumentNumber())) {
      pd.setOrganizationDocNbr(document.getDocumentHeader().getOrganizationDocumentNumber());
    }
    pd.setCustPaymentDocNbr(document.getDocumentNumber());
    pd.setInvoiceDate(new java.sql.Date(processRunDate.getTime()));
    pd.setOrigInvoiceAmount(getPaymentAmount(document));
    pd.setInvTotDiscountAmount(KualiDecimal.ZERO);
    pd.setInvTotOtherCreditAmount(KualiDecimal.ZERO);
    pd.setInvTotOtherDebitAmount(KualiDecimal.ZERO);
    pd.setInvTotShipAmount(KualiDecimal.ZERO);
    pd.setNetPaymentAmount(getPaymentAmount(document));
    pd.setPrimaryCancelledPayment(Boolean.FALSE);
    pd.setFinancialDocumentTypeCode(getAchCheckDocumentType(document));
    pd.setFinancialSystemOriginCode(KFSConstants.ORIGIN_CODE_KUALI);
    pd.setPurchaseOrderNbr(document.getTravelDocumentIdentifier());
    pd.setOrganizationDocNbr(document.getTravelDocumentIdentifier());

    int line = 0;
    PaymentNoteText pnt = new PaymentNoteText();
    pnt.setCustomerNoteLineNbr(new KualiInteger(line++));
    final String travelerId =
        (!ObjectUtils.isNull(document.getTemProfile())
            ? (!ObjectUtils.isNull(document.getTemProfile().getPrincipal())
                ? document.getTemProfile().getPrincipal().getPrincipalName()
                : document.getTemProfile().getCustomerNumber())
            : document.getDocumentNumber()); // they got this far without a payee id?  that really
    // probably shouldn't happen
    pnt.setCustomerNoteText(
        "Info: " + travelerId + " " + document.getTemProfile().getPhoneNumber());
    pd.addNote(pnt);

    final String text = document.getDocumentHeader().getDocumentDescription();
    if (!StringUtils.isBlank(text)) {
      pnt = getPaymentSourceHelperService().buildNoteForCheckStubText(text, line);
      if (LOG.isDebugEnabled()) {
        LOG.debug("Creating check stub text note: " + pnt.getCustomerNoteText());
      }
      pd.addNote(pnt);
    }
    // Handle accounts, but only corporate card accounting lines
    List<TemSourceAccountingLine> corporateCardLines = new ArrayList<TemSourceAccountingLine>();
    for (TemSourceAccountingLine accountingLine :
        (List<TemSourceAccountingLine>) document.getSourceAccountingLines()) {
      if (StringUtils.equals(TemConstants.TRAVEL_TYPE_CORP, accountingLine.getCardType())) {
        corporateCardLines.add(accountingLine);
      }
    }
    final List<PaymentAccountDetail> paymentAccounts =
        buildPaymentAccountDetails(corporateCardLines);
    for (PaymentAccountDetail pad : paymentAccounts) {
      pd.addAccountDetail(pad);
    }

    return pd;
  }