/**
   * Performs refresh of objects after a lookup.
   *
   * @see
   *     org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
   *     org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  public ActionForward refresh(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;

    AccountsPayableDocumentBase document = (AccountsPayableDocumentBase) baseForm.getDocument();

    if (StringUtils.equals(
        baseForm.getRefreshCaller(), VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
      if (StringUtils.isNotBlank(
          request.getParameter(
              KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
        Integer vendorAddressGeneratedId = document.getVendorAddressGeneratedIdentifier();
        VendorAddress refreshVendorAddress = new VendorAddress();
        refreshVendorAddress.setVendorAddressGeneratedIdentifier(vendorAddressGeneratedId);
        refreshVendorAddress =
            (VendorAddress)
                SpringContext.getBean(BusinessObjectService.class).retrieve(refreshVendorAddress);
        document.templateVendorAddress(refreshVendorAddress);
      }
    }

    return super.refresh(mapping, form, request, response);
  }
  /**
   * @see
   *     org.kuali.kfs.sys.batch.service.PaymentSourceToExtractService#createPaymentGroup(org.kuali.kfs.sys.document.PaymentSource,
   *     java.sql.Date)
   */
  @Override
  public PaymentGroup createPaymentGroup(TEMReimbursementDocument document, Date processRunDate) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("createPaymentGroupForReimbursable() started");
    }

    final boolean disburseCorporateCardPayments =
        getParameterService()
            .getParameterValueAsBoolean(
                TemParameterConstants.TEM_DOCUMENT.class,
                TemConstants.TravelParameters.CORPORATE_CARD_PAYMENT_IND);
    if (!disburseCorporateCardPayments) {
      return null; // can't disburse payments? then don't create payment groups
    }

    PaymentGroup pg = new PaymentGroup();
    final CreditCardAgency creditCardAgency = getCorporateCreditCardAgency(document);
    if (creditCardAgency == null) {
      LOG.error(
          "Skipping corporate card payment for "
              + document.getDocumentNumber()
              + " because no credit card agency could be found.");
      return null;
    }
    final VendorDetail vendor = getCorporateCardVendor(creditCardAgency);
    if (vendor == null) {
      LOG.error(
          "Skipping corporate card payment for "
              + document.getDocumentNumber()
              + " because no vendor could be found.");
      return null;
    }
    final VendorAddress vendorAddress =
        getVendorService()
            .getVendorDefaultAddress(
                vendor.getVendorAddresses(),
                vendor
                    .getVendorHeader()
                    .getVendorType()
                    .getAddressType()
                    .getVendorAddressTypeCode(),
                "");

    pg.setCombineGroups(Boolean.TRUE);
    pg.setCampusAddress(Boolean.FALSE);

    pg.setCity(vendorAddress.getVendorCityName());
    pg.setCountry(vendorAddress.getVendorCountryCode());
    pg.setLine1Address(vendorAddress.getVendorLine1Address());
    pg.setLine2Address(vendorAddress.getVendorLine2Address());
    pg.setPayeeName(vendor.getVendorName());
    pg.setState(vendorAddress.getVendorStateCode());
    pg.setZipCd(vendorAddress.getVendorZipCode());
    pg.setPaymentDate(getNextDate(processRunDate));
    pg.setProcessImmediate(false);
    pg.setPymtAttachment(false);
    pg.setPymtSpecialHandling(false);
    pg.setNraPayment(false);
    pg.setBankCode(creditCardAgency.getBankCode());
    pg.setPaymentStatusCode(PdpConstants.PaymentStatusCodes.OPEN);
    if (StringUtils.equals(
        document.getTraveler().getTravelerTypeCode(), TemConstants.EMP_TRAVELER_TYP_CD)) {
      pg.setEmployeeIndicator(true);
    }
    pg.setPayeeId(vendor.getVendorNumber());
    pg.setPayeeIdTypeCd(PdpConstants.PayeeIdTypeCodes.VENDOR_ID);
    pg.setTaxablePayment(Boolean.FALSE);
    pg.setPayeeOwnerCd(vendor.getVendorHeader().getVendorOwnershipCode());

    // now add the payment detail
    final PaymentDetail paymentDetail = buildPaymentDetail(document, processRunDate);
    pg.addPaymentDetails(paymentDetail);
    paymentDetail.setPaymentGroup(pg);

    return pg;
  }