Example usage for com.google.gson JsonObject JsonObject

List of usage examples for com.google.gson JsonObject JsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonObject JsonObject.

Prototype

JsonObject

Source Link

Usage

From source file:account.BranchWisePendingCollecionReport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w w w .  j av a2  s .  c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final int branch_cd = Integer.parseInt(request.getParameter("branch_cd"));
    final int v_type = Integer.parseInt(request.getParameter("v_type"));
    final String ref_cd = (request.getParameter("ref_cd"));
    final Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT p.mobile1,v.REMARK,v.INV_NO,o.DOC_REF_NO,o.DOC_DATE,o.AC_CD,o.UNPAID_AMT,o.DUE_DATE,v.BRANCH_CD,a.FNAME,v.buy_back_model,v.buy_back_amt,r.ref_name FROM "
                    + "oldb2_4 o LEFT JOIN vilshd v ON v.REF_NO=o.DOC_REF_NO LEFT JOIN acntmst a ON a.AC_CD=v.AC_CD "
                    + " left join refmst r on v.ref_cd=r.ref_cd left join phbkmst p on a.ac_cd=p.ac_cd"
                    + " WHERE doc_ref_no LIKE '02%' AND o.UNPAID_AMT >0 and v.is_del=0 ";
            if (branch_cd != 0) {
                sql += " and v.branch_cd=" + branch_cd;
            }
            if (v_type != -1) {
                sql += " and v.v_type=" + v_type;
            }
            if (!ref_cd.equalsIgnoreCase("0")) {
                sql += " and v.REF_CD='" + ref_cd + "'";
            }
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("DOC_DATE", viewDataRs.getString("DOC_DATE"));
                object.addProperty("INV_NO", viewDataRs.getString("INV_NO"));
                object.addProperty("DOC_REF_NO", viewDataRs.getString("DOC_REF_NO"));
                object.addProperty("AC_CD", viewDataRs.getString("AC_CD"));
                object.addProperty("DOC_CD", "");
                object.addProperty("UNPAID_AMT", viewDataRs.getDouble("UNPAID_AMT"));
                object.addProperty("DUE_DATE", viewDataRs.getString("DUE_DATE"));
                object.addProperty("branch_cd", viewDataRs.getString("branch_cd"));
                object.addProperty("FNAME", viewDataRs.getString("FNAME"));
                object.addProperty("BUY_BACK_MODEL", viewDataRs.getString("BUY_BACK_MODEL"));
                object.addProperty("BUY_BACK_AMT", viewDataRs.getString("BUY_BACK_AMT"));
                object.addProperty("REMARK", viewDataRs.getString("REMARK"));
                object.addProperty("MOBILE1",
                        (viewDataRs.getString("MOBILE1") == null) ? "" : viewDataRs.getString("MOBILE1"));
                object.addProperty("REF_NAME",
                        (viewDataRs.getString("REF_NAME") == null) ? "" : viewDataRs.getString("REF_NAME"));
                array.add(object);
            }
            lb.closeResultSet(viewDataRs);
            lb.closeStatement(pstLocal);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.BuyBackRegister.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w w  w.j ava2  s  .  co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String ac_cd = request.getParameter("ac_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final String sr_cd = request.getParameter("sr_cd");
    final String type_cd = request.getParameter("type_cd");
    final String brand_cd = request.getParameter("brnad_cd");
    final String model_cd = request.getParameter("model_cd");
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select v.branch_cd,v.inv_no,v.ref_no,a.fname,v.BUY_BACK_MODEL,v.v_date,'' as TYPE_NAME,BUY_BACK_MODEL as IMEI_NO,BUY_BACK_IMEI_NO,(1) as pcs,BUY_BACK_AMT as tot_sales from VILSHD v  "
                    + " left join acntmst a on v.ac_cd=a.ac_cd where v.IS_DEL=0 " + " and v.v_date>='"
                    + from_date + "' " + " and v.v_date<='" + to_date + "'   and v.BUY_BACK_AMT <> 0";
            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd='" + type_cd + "' ";
            }
            if (!sr_cd.equalsIgnoreCase("")) {
                sql += " and s.SR_CD='" + sr_cd + "'";
            } else if (!brand_cd.equalsIgnoreCase("")) {
                sql += " and s.brand_cd='" + brand_cd + "'";
            } else if (!model_cd.equalsIgnoreCase("")) {
                sql += " and s.model_cd='" + model_cd + "'";
            }
            if (!ac_cd.equalsIgnoreCase("")) {
                sql += " and v.ac_cd='" + ac_cd + "'";
            }

            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("fname", viewDataRs.getString("fname"));
                object.addProperty("sr_name", viewDataRs.getString("BUY_BACK_MODEL"));
                object.addProperty("v_date", viewDataRs.getString("v_date"));
                object.addProperty("type_name", viewDataRs.getString("type_name"));
                object.addProperty("pcs", viewDataRs.getInt("pcs"));
                object.addProperty("tot_sales", viewDataRs.getDouble("tot_sales"));
                object.addProperty("IMEI_NO", viewDataRs.getString("IMEI_NO"));
                object.addProperty("BUY_BACK_IMEI_NO", viewDataRs.getString("BUY_BACK_IMEI_NO"));
                object.addProperty("REF_NO", viewDataRs.getString("REF_NO"));
                object.addProperty("INV_NO", viewDataRs.getString("INV_NO"));
                object.addProperty("branch_cd", viewDataRs.getString("branch_cd"));
                array.add(object);
            }

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.CardWiseSalesDetailStatement.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  ww.java2 s .  c o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String ac_cd = request.getParameter("ac_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select v.ins_amt,v.ref_no,case when v.V_TYPE=0 then 'Retail Invoice' else 'Tax Invoice' end as v_type,v.INV_NO,v.V_DATE,v.PMT_MODE,"
                    + " case when a.FNAME is null then '' else fname end as fname,s.SR_ALIAS,s.SR_NAME,v1.IMEI_NO,"
                    + " v1.SERAIL_NO,v1.QTY,v1.RATE,v1.AMT,v.DET_TOT,v1.TAX_AMT,v1.ADD_TAX_AMT,v.NET_AMT,p.CASH_AMT,p.BANK_AMT,p.CARD_AMT,p.bajaj_amt,t.TAX_NAME"
                    + " ,v.BUY_BACK_MODEL,v.BUY_BACK_AMT from VILSHD v left join VILSDT v1 on v.REF_NO =v1.REF_NO left join acntmst a on v.AC_CD=a.AC_CD "
                    + " left join SERIESMST s on s.SR_CD=v1.SR_CD left join PAYMENT p on v.REF_NO=p.REF_NO   left join TAXMST t on v1.TAX_CD=t.TAX_CD "
                    + " where is_del=0 and card_no<>''";
            if (!ac_cd.equalsIgnoreCase("")) {
                sql += " and v.ac_cd='" + ac_cd + "' ";
            }
            sql += " order by v.V_DATE,v.INV_NO";
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("ref_no", viewDataRs.getString("REF_NO"));
                object.addProperty("v_type", viewDataRs.getString("V_TYPE"));
                object.addProperty("inv_no", viewDataRs.getString("inv_no"));
                object.addProperty("fname", viewDataRs.getString("FNAME"));
                object.addProperty("SR_ALIAS", viewDataRs.getString("SR_ALIAS"));
                object.addProperty("SR_NAME", viewDataRs.getString("SR_NAME"));
                object.addProperty("IMEI_NO", viewDataRs.getString("IMEI_NO"));
                object.addProperty("SERAIL_NO", viewDataRs.getString("SERAIL_NO"));
                object.addProperty("v_date", viewDataRs.getString("V_DATE"));
                object.addProperty("QTY", viewDataRs.getInt("QTY"));
                object.addProperty("RATE", viewDataRs.getDouble("RATE"));
                object.addProperty("AMT", viewDataRs.getDouble("AMT"));
                object.addProperty("det_tot", viewDataRs.getDouble("DET_TOT"));
                object.addProperty("tax_amt", viewDataRs.getDouble("TAX_AMT"));
                object.addProperty("add_tax_amt", viewDataRs.getDouble("ADD_TAX_AMT"));
                object.addProperty("CASH_AMT", viewDataRs.getDouble("CASH_AMT"));
                object.addProperty("BANK_AMT", viewDataRs.getDouble("BANK_AMT"));
                object.addProperty("CARD_AMT", viewDataRs.getDouble("CARD_AMT"));
                object.addProperty("net_amt", viewDataRs.getDouble("NET_AMT"));
                object.addProperty("tax_name", viewDataRs.getString("tax_name"));
                object.addProperty("buy_back_model", viewDataRs.getString("buy_back_model"));
                object.addProperty("ins_amt", viewDataRs.getDouble("ins_amt"));
                object.addProperty("buy_back_amt", viewDataRs.getDouble("buy_back_amt"));
                object.addProperty("bajaj_amt", viewDataRs.getDouble("bajaj_amt"));
                array.add(object);
            }
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.CardWiseSalesStatement.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w  ww.j  av a2 s . com
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final boolean card_no = Boolean.parseBoolean(request.getParameter("card").toString());
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select a.AC_CD,a.FNAME,a.CARD_NO,p.MOBILE1,sum(v.DET_TOT+v.TAX_AMT+v.ADD_TAX_AMT) as NET_AMT from VILSHD v "
                    + " left join ACNTMST a on v.AC_CD=a.AC_CD left join phbkmst p on p.AC_CD=a.AC_CD "
                    + " where v.IS_DEL=0  ";

            if (!card_no) {
                sql += " and CARD_NO <>''";
            }
            sql += "  group by a.FNAME,a.card_no,a.ac_cd,p.mobile1 order by a.CARD_NO";
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("AC_CD", viewDataRs.getString("AC_CD"));
                object.addProperty("FNAME", viewDataRs.getString("FNAME"));
                object.addProperty("CARD_NO", viewDataRs.getString("CARD_NO"));
                object.addProperty("MOBILE1", viewDataRs.getString("MOBILE1"));
                object.addProperty("NET_AMT", viewDataRs.getDouble("NET_AMT"));
                array.add(object);
            }

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.CashSnapshot.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww  w.ja  v a 2 s  . c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String grp_cd = request.getParameter("grp_cd");
    String from_date = "";
    String to_date = "";
    from_date = request.getParameter("from_date");
    to_date = request.getParameter("to_date");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            String sql = null;
            PreparedStatement pstLocal = null;
            sql = "SELECT o.ac_cd,fname,doc_date,SUM(CASE WHEN crdr=0 THEN val ELSE 0 END) AS dr,SUM(CASE WHEN crdr=1 THEN val ELSE 0 END) AS cr,"
                    + " (SUM(CASE WHEN crdr=0 THEN val ELSE 0 END) -SUM(CASE WHEN crdr=1 THEN val ELSE 0 END)) AS bal"
                    + " FROM oldb2_2 o left join acntmst a on a.ac_cd=o.ac_cd WHERE o.ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd ='"
                    + grp_cd + "')" + " AND  doc_date>='" + from_date + "' and doc_date<='" + to_date
                    + "' GROUP BY o.ac_cd,fname,doc_date";
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("fname", viewDataRs.getString("fname"));
                object.addProperty("doc_date", viewDataRs.getString("doc_date"));
                object.addProperty("dr", viewDataRs.getDouble("dr"));
                object.addProperty("cr", viewDataRs.getDouble("cr"));
                object.addProperty("bal", viewDataRs.getDouble("bal"));
                object.addProperty("ac_cd", viewDataRs.getString("ac_cd"));
                array.add(object);
            }
            lb.closeResultSet(viewDataRs);
            lb.closeStatement(pstLocal);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.CreditNoteRegister.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w w  .j av  a  2 s.  c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String ac_cd = request.getParameter("ac_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final String sr_cd = request.getParameter("sr_cd");
    final String type_cd = request.getParameter("type_cd");
    final String brand_cd = request.getParameter("brnad_cd");
    final String model_cd = request.getParameter("model_cd");
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select a.FNAME,s.SR_NAME,t.BASIC_PUR_RATE,t.PUR_RATE,t.TAG_NO,p.REMARK,l.V_DATE as PUR_DATE,v.V_DATE as SALE_DATE,p.RATE "
                    + " from PRIZE_DROP p left join TAG t on p.PUR_TAG_NO=t.REF_NO left join SERIESMST s on t.SR_CD=s.SR_CD "
                    + " left join LBRPHD l on t.PUR_REF_NO=l.REF_NO left join modelmst m on s.model_cd=m.model_cd "
                    + " left join  acntmst a on l.AC_CD=a.AC_CD left join VILSHD v on t.SALE_REF_NO=v.REF_NO where  "
                    + " p.v_date>='" + from_date + "' " + " and p.v_date<='" + to_date + "' ";
            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd='" + type_cd + "' ";
            }
            if (!sr_cd.equalsIgnoreCase("")) {
                sql += " and s.SR_CD='" + sr_cd + "'";
            } else if (!brand_cd.equalsIgnoreCase("")) {
                sql += " and s.brand_cd='" + brand_cd + "'";
            } else if (!model_cd.equalsIgnoreCase("")) {
                sql += " and s.model_cd='" + model_cd + "'";
            }
            if (!ac_cd.equalsIgnoreCase("")) {
                sql += " and v.ac_cd='" + ac_cd + "'";
            }

            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("fname", viewDataRs.getString("fname"));
                object.addProperty("sr_name", viewDataRs.getString("sr_name"));
                object.addProperty("BASIC_PUR_RATE", viewDataRs.getDouble("BASIC_PUR_RATE"));
                object.addProperty("PUR_RATE", viewDataRs.getDouble("PUR_RATE"));
                object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO"));
                object.addProperty("REMARK", viewDataRs.getString("REMARK"));
                object.addProperty("PUR_DATE", viewDataRs.getString("PUR_DATE"));
                object.addProperty("SALE_DATE", viewDataRs.getString("SALE_DATE"));
                object.addProperty("RATE", viewDataRs.getString("RATE"));
                array.add(object);
            }

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.CreditNoteReport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  ww.j  av  a 2 s.c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String ac_cd = request.getParameter("ac_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final String model_cd = (request.getParameter("model_cd"));
    final String memory_cd = (request.getParameter("memory_cd"));
    final String type_cd = (request.getParameter("type_cd"));
    final boolean sales = Boolean.parseBoolean((request.getParameter("sales")));
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select t.ac_name as fname,s.sr_name,t.pur_date as v_date,t1.TYPE_NAME,(t.tag_no) as pcs,(t.PUR_RATE) as tot_sales,t.ref_no as pur_tag_no"
                    + ",sales.V_DATE as sales_date,disc_per,extra_support,backend,activation,prize_drop from tag t "
                    + "  "
                    + " left join SERIESMST s on t.SR_CD=s.SR_CD left join MODELMST m on s.MODEL_CD=m.MODEL_CD left join TYPEMST t1 on m.TYPE_CD=t1.TYPE_CD "
                    + " left join VILSHD sales on t.SALE_REF_NO=sales.REF_NO where t.PUR_DATE>='" + from_date
                    + "' " + " and t.PUR_DATE<='" + to_date + "' ";
            if (sales) {

            } else {
                sql += " and (sales.V_DATE>'" + to_date + "' or t.SALE_REF_NO='')";
            }
            if (!model_cd.equalsIgnoreCase("")) {
                sql += " and m.model_cd='" + model_cd + "'";
            }
            if (!memory_cd.equalsIgnoreCase("")) {
                sql += " and s.MEMORY_CD='" + memory_cd + "'";
            }
            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd='" + type_cd + "'";
            }

            if (!ac_cd.equalsIgnoreCase("")) {
                sql += " and sales.ac_cd='" + ac_cd + "'";
            }
            sql += " and t.is_del <> -1 order by t.PUR_DATE";
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("fname", viewDataRs.getString("fname"));
                object.addProperty("sr_name", viewDataRs.getString("sr_name"));
                object.addProperty("v_date", viewDataRs.getString("v_date"));
                object.addProperty("type_name", viewDataRs.getString("type_name"));
                object.addProperty("pcs", viewDataRs.getString("pcs"));
                object.addProperty("tot_sales", viewDataRs.getDouble("tot_sales"));
                object.addProperty("PUR_TAG_NO", viewDataRs.getString("PUR_TAG_NO"));
                object.addProperty("sales_date", viewDataRs.getString("sales_date"));
                object.addProperty("disc_per", viewDataRs.getString("disc_per"));
                object.addProperty("extra_support", viewDataRs.getString("extra_support"));
                object.addProperty("backend", viewDataRs.getString("backend"));
                object.addProperty("activation", viewDataRs.getString("activation"));
                object.addProperty("prize_drop", viewDataRs.getString("prize_drop"));
                array.add(object);
            }

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.DailyBankStatementDetail.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  ww . j  a  va2s  .com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String branch_cd = request.getParameter("branch_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT doc_date,branch_cd,doc_ref_no,(CASE WHEN CRDR=0 THEN val ELSE val*-1 END) AS bal FROM oldb2_2 \n"
                    + " WHERE ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd IN (SELECT grp_cd FROM groupmst WHERE group_name='BANK')) "
                    + " AND doc_cd <>'SL' " + " and doc_date>='" + from_date + "' " + " and doc_date<='"
                    + to_date + "' and branch_cd <>0";
            if (!branch_cd.equalsIgnoreCase("0")) {
                sql += " and branch_cd=" + branch_cd;
            }

            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("v_date", viewDataRs.getString("doc_date"));
                object.addProperty("bal", viewDataRs.getDouble("bal"));
                object.addProperty("branch_cd", viewDataRs.getString("branch_cd"));
                object.addProperty("doc_ref_no", viewDataRs.getString("doc_ref_no"));
                array.add(object);
            }
            lb.closeResultSet(viewDataRs);
            lb.closeStatement(pstLocal);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.DailyBankSummary.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w  w. j  a va2s  .  c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final int branch_cd = Integer.parseInt(request.getParameter("branch_cd"));
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT branch_cd,doc_date,SUM(CASE WHEN CRDR=0 THEN val ELSE val*-1 END) AS bal FROM oldb2_2 \n"
                    + " WHERE ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd IN (SELECT grp_cd FROM groupmst WHERE group_name='BANK')) "
                    + " AND doc_cd <>'SL' " + " and doc_date>='" + from_date + "' " + " and doc_date<='"
                    + to_date + "' and branch_cd =" + branch_cd + " group by doc_date,branch_cd";

            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("v_date", viewDataRs.getString("doc_date"));
                object.addProperty("bal", viewDataRs.getDouble("bal"));
                object.addProperty("branch_cd", viewDataRs.getDouble("branch_cd"));
                array.add(object);
            }
            lb.closeResultSet(viewDataRs);
            lb.closeStatement(pstLocal);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.DailyCashStatementDetail.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w  w  . j ava2s .c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String branch_cd = request.getParameter("branch_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT doc_date,branch_cd,doc_ref_no,(CASE WHEN CRDR=0 THEN val ELSE val*-1 END) AS bal FROM oldb2_2 \n"
                    + " WHERE ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd IN (SELECT grp_cd FROM groupmst WHERE group_name='CASH')) "
                    + " AND doc_cd <>'SL' " + " and doc_date>='" + from_date + "' " + " and doc_date<='"
                    + to_date + "' and branch_cd <>0";
            if (!branch_cd.equalsIgnoreCase("0")) {
                sql += " and branch_cd=" + branch_cd;
            }

            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("v_date", viewDataRs.getString("doc_date"));
                object.addProperty("bal", viewDataRs.getDouble("bal"));
                object.addProperty("branch_cd", viewDataRs.getString("branch_cd"));
                object.addProperty("doc_ref_no", viewDataRs.getString("doc_ref_no"));
                array.add(object);
            }
            lb.closeResultSet(viewDataRs);
            lb.closeStatement(pstLocal);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}