/**
   * Searching lab outsourced
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @SuppressWarnings("all")
  public ActionForward searchForLabOutsource(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    new TransactionContext((UserDetails) request.getSession(false).getAttribute("userDetails"));
    AshaLogger.logInfo(logger, this.getClass().getName(), "search", "Executing");
    String startDate1 = "0000-00-00";
    String endDate1 = "0000-00-00";
    AmountDueDao dueDao = new AmountDueDao();

    String startDate = request.getParameter("from_date");
    String endDate = request.getParameter("to_date");
    startDate = dueDao.formatDate(startDate);
    endDate = dueDao.formatDate(endDate);

    request.setAttribute("hidden_startDate", startDate);
    request.setAttribute("hidden_endDate", endDate);

    String status = "";
    status = dueDao.getLabOutsourcedDetails(startDate, endDate, request);
    status = "searchLabOutsource";
    ActionForward actionForward = mapping.findForward(status);
    return actionForward;
  }
  /**
   * Getting lab outsource details
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward getLabOutsourced(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    new TransactionContext((UserDetails) request.getSession(false).getAttribute("userDetails"));
    AshaLogger.logInfo(logger, this.getClass().getName(), "getLabOutsourced", "Executing");
    String startDate1 = "0000-00-00";
    String endDate1 = "0000-00-00";
    AmountDueDao dueDao = new AmountDueDao();

    Date date = new Date();
    Format formatter = new SimpleDateFormat("dd-MMM-yyyy");
    String startDate = formatter.format(date);
    String endDate = formatter.format(date);

    request.setAttribute("startDate", startDate.toUpperCase());
    request.setAttribute("endDate", endDate.toUpperCase());

    startDate = dueDao.formatDate(startDate);
    endDate = dueDao.formatDate(endDate);

    request.setAttribute("hidden_startDate", startDate);
    request.setAttribute("hidden_endDate", endDate);

    String status = "";
    status = dueDao.getLabOutsourcedDetails(startDate, endDate, request);
    ActionForward actionForward = mapping.findForward(status);
    return actionForward;
  }
  /**
   * Getting Balance(Amount due) details
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward getAmountDue(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    // new

    AshaLogger.logInfo(logger, this.getClass().getName(), "getAmountDue", "Executing");
    AmountDueDao amountDueDao = new AmountDueDao();
    String details = amountDueDao.getAmountDue();
    // logger.info("details is " + details);
    AmountDuePojos duePojo = null;
    ArrayList<AmountDuePojos> param_ob = new ArrayList<AmountDuePojos>();

    try {
      if (null != details && details.length() != 0) {

        StringTokenizer st = new StringTokenizer(details, "|");

        int count = 1;
        String p_ob = null;
        while (st.hasMoreTokens()) {
          duePojo = new AmountDuePojos();

          p_ob = st.nextToken();

          // StringTokenizer st_ob = new
          // StringTokenizer(p_ob.substring(1, p_ob.length() - 1),
          // "~");
          StringTokenizer st_ob = new StringTokenizer(p_ob, "~");

          int count_token = st_ob.countTokens();

          // logger.info("count_token is "+count_token);
          if (count_token == 7) {
            duePojo.setPid(st_ob.nextToken());
            duePojo.setName(st_ob.nextToken());
            duePojo.setMobile(st_ob.nextToken());
            duePojo.setAmount(st_ob.nextToken());
            duePojo.setAdvance(st_ob.nextToken());
            duePojo.setBalance(st_ob.nextToken());
            duePojo.setSponsor(st_ob.nextToken());
            // logger.info("Sponsor is "+duePojo.getSponsor());
            // logger.info("error is "+6);
            param_ob.add(duePojo);
          }
        }
      }

      request.setAttribute("amountDue", param_ob);
    } catch (Exception e) {

      AshaLogger.logException(logger, this.getClass().getName(), "getAmountDue", "Exception", e);
    }

    ActionForward actionForward = mapping.findForward("amountDue");
    return actionForward;
  }
  /**
   * Getting details on clicking service
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @SuppressWarnings("all")
  public ActionForward getDetails(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    new TransactionContext((UserDetails) request.getSession(false).getAttribute("userDetails"));
    AshaLogger.logInfo(logger, this.getClass().getName(), "getDetails", "Executing");
    String status = "";
    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");
    String name = request.getParameter("name");
    // logger.info("name is get detais is "+name);
    String sgcode = request.getParameter("sgcode");
    AmountDueDao amountDao = new AmountDueDao();
    if (name.equalsIgnoreCase("advances")) {
      status = amountDao.getAdvanceDetailsForExcel(name, startDate, endDate, sgcode, request);
      request.setAttribute("advance", "advance");
    } else if (name.equalsIgnoreCase("discount(-)")) {
      status = amountDao.getDiscountDetailsForExcel(name, startDate, endDate, sgcode, request);
      request.setAttribute("discount", "discount");
    } else if (name.equalsIgnoreCase("Refund(-)")) {
      status = amountDao.getRefundDetailsForExcel(name, startDate, endDate, sgcode, request);
      request.setAttribute("refund", "refund");
    } else if (name.equalsIgnoreCase("Pharmacy")) {
      status = amountDao.getPharmacyDetailsForExcel(name, startDate, endDate, sgcode, request);
      request.setAttribute("pharmacy", "pharmacy");
    } else if (name.equalsIgnoreCase("Unrealized")) {
      status = amountDao.getUnrealizedDetailsForExcel(name, startDate, endDate, sgcode, request);
      request.setAttribute("unrealized", "unrealized");
    } else {
      status = amountDao.getDetailsForExcel(name, startDate, endDate, sgcode, request);
    }

    request.setAttribute("hidden_startDate", startDate);
    request.setAttribute("hidden_endDate", endDate);

    ActionForward actionForward = mapping.findForward(status);
    return actionForward;
  }