/**
   * Adds handling for credit card receipt amount updates.
   *
   * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
   *     org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;

    if (ccrForm.hasDocumentId()) {
      CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();

      ccrDoc.setTotalCreditCardAmount(
          ccrDoc.calculateCreditCardReceiptTotal()); // recalc b/c changes to the amounts could
      // have happened

      // set bank
      ccrDoc.setBank(
          SpringContext.getBean(BankService.class)
              .getByPrimaryId(ccrDoc.getCreditCardReceiptBankCode()));
    }

    // proceed as usual
    return super.execute(mapping, form, request, response);
  }
  /**
   * Deletes the selected creditCardReceipt (line) from the document
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward deleteCreditCardReceipt(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
    CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();

    int deleteIndex = getLineToDelete(request);
    // delete creditCardReceipt
    ccrDoc.removeCreditCardReceipt(deleteIndex);

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }
  /**
   * Adds a CreditCardDetail instance created from the current "new creditCardReceipt" line to the
   * document
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward addCreditCardReceipt(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
    CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();

    CreditCardDetail newCreditCardReceipt = ccrForm.getNewCreditCardReceipt();
    ccrDoc.prepareNewCreditCardReceipt(newCreditCardReceipt);

    // creditCardReceipt business rules
    boolean rulePassed = validateNewCreditCardReceipt(newCreditCardReceipt);
    if (rulePassed) {
      // add creditCardReceipt
      ccrDoc.addCreditCardReceipt(newCreditCardReceipt);

      // clear the used creditCardReceipt
      ccrForm.setNewCreditCardReceipt(new CreditCardDetail());
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }