Example usage for com.google.gson JsonArray JsonArray

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

Introduction

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

Prototype

public JsonArray() 

Source Link

Document

Creates an empty JsonArray.

Usage

From source file:account.GetCardDetail.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w ww . jav a  2s. 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 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 Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select v.ref_no,v_date,inv_no,a.FNAME,v.NET_AMT,p.CARD_AMT,p.tid_no,p.card_no from vilshd v,payment p,acntmst a, phbkmst p1\n"
                    + " where v.AC_CD=a.AC_CD and v.REF_NO=p.REF_NO and a.AC_CD = p1.AC_CD and v.IS_DEL=0 and v.v_date>='"
                    + from_date + "' " + " and v.v_date <='" + to_date + "' and card_amt <>0";
            if (branch_cd != 0) {
                sql += " and v.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("ref_no", viewDataRs.getString("ref_no"));
                object.addProperty("v_date", viewDataRs.getString("v_date"));
                object.addProperty("inv_no", viewDataRs.getString("inv_no"));
                object.addProperty("fname", viewDataRs.getString("fname"));
                object.addProperty("net_amt", viewDataRs.getString("net_amt"));
                object.addProperty("card_amt", viewDataRs.getString("card_amt"));
                object.addProperty("tid_no", viewDataRs.getString("tid_no"));
                object.addProperty("card_no", viewDataRs.getString("card_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.GetDenomation.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  w w  .ja  v  a2s. 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("v_date");
    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 Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "select * from denomation where v_date='" + from_date + "'";
            if (branch_cd != 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("note_cd", viewDataRs.getInt("note_cd"));
                object.addProperty("qty", viewDataRs.getInt("qty"));
                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.GetGeneralLedgerSummary.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  www .  j a  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 {
    DBHelper helper = DBHelper.GetDBHelper();
    dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    ac_cd = request.getParameter("ac_cd");
    from_date = request.getParameter("from_date");
    to_date = request.getParameter("to_date");
    try {
        if (dataConnection != null) {
            makeQuery();
            JsonArray array = new JsonArray();
            while (crsMain.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("MONTH", crsMain.getString("MONTH"));
                object.addProperty("DR", crsMain.getDouble("DR"));
                object.addProperty("CR", crsMain.getDouble("CR"));
                object.addProperty("AMT", crsMain.getDouble("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());
    } finally {
        lb.closeConnection(dataConnection);
    }
    response.getWriter().print(jResultObj);
}

From source file:account.GetGroupSummary.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w  w w  .j  a v  a  2s  .  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 grp_cd = request.getParameter("grp_cd");
    final double amt = Double.parseDouble(request.getParameter("amt"));
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final int mode = Integer.parseInt(request.getParameter("mode"));
    Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {

            String sql = null;
            PreparedStatement pstLocal = null;
            sql = "select concat(fname , ' ' ,mname , ' ' , lname) as fname,opb,";
            for (int i = 1; i <= 12; i++) {
                sql += "DR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += " as dr, ";
            for (int i = 1; i <= 12; i++) {
                sql += "CR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += " as cr ,(";
            for (int i = 1; i <= 12; i++) {
                sql += "DR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += "-";
            for (int i = 1; i <= 12; i++) {
                sql += "CR_" + i + "-";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += ") as bal,acntmst.ac_cd from oldb2_1,acntmst,GROUPMST "
                    + "where ACNTMST.GRP_CD=GROUPMST.grp_cd and ((";
            for (int i = 1; i <= 12; i++) {
                sql += "DR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += "-";
            for (int i = 1; i <= 12; i++) {
                sql += "CR_" + i + "-";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += ") > 1 or (";
            for (int i = 1; i <= 12; i++) {
                sql += "DR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += "-";
            for (int i = 1; i <= 12; i++) {
                sql += "CR_" + i + "-";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += ") < -1 )";
            if (!grp_cd.equalsIgnoreCase("")) {
                sql += "and (ACNTMST.grp_cd='" + grp_cd + "' "
                        + "or acntmst.grp_cd in( select grp_cd from groupmst where head_grp='" + grp_cd
                        + "')) ";
            }
            sql += " and acntmst.ac_cd=oldb2_1.ac_cd and (";
            for (int i = 1; i <= 12; i++) {
                sql += "DR_" + i + "+";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += "-";
            for (int i = 1; i <= 12; i++) {
                sql += "CR_" + i + "-";
            }
            sql = sql.substring(0, sql.length() - 1);
            if (mode == 0) {
                sql += ") <> 0";
            } else if (mode == 1) {
                sql += " ) <" + (amt * -1);
            } else if (mode == 2) {
                sql += " ) >" + amt;
            }
            sql += " order by fname";
            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("opb", viewDataRs.getDouble("opb"));
                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.GetInsuranceRegister.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  w 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 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 {
            String sql = "select v1.branch_cd,v.ref_no,v1.inv_no,a.FNAME,(a1.ADD1||' '||a1.ADD2||' '||a1.ADD3) as ADD1,p.MOBILE1,s.SR_NAME,v1.V_DATE as ins_date,v.TAG_NO,v1.INS_AMT,v.RATE,v1.V_DATE from vilsdt v "
                    + " left join SERIESMST s on v.SR_CD=s.SR_CD left join VILSHD v1 on v.REF_NO=v1.REF_NO left join acntmst a on v1.AC_CD=a.AC_CD "
                    + " left join adbkmst a1 on a.AC_CD=a1.AC_CD left join phbkmst p on a.AC_CD=p.AC_CD "
                    + " where v1.V_DATE>='" + from_date + "'" + " and v1.V_DATE<='" + to_date
                    + "' and v1.is_del=0 " + " and (v.IMEI_NO<>'' or v.SERAIL_NO<>'') and INS_CD<>''";
            if (branch_cd != 0) {
                sql += " and v1.branch_cd=" + branch_cd;
            }
            sql += " order by v1.V_DATE";
            PreparedStatement 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("ADD1", viewDataRs.getString("ADD1"));
                object.addProperty("MOBILE1", viewDataRs.getString("MOBILE1"));
                object.addProperty("SR_NAME", viewDataRs.getString("SR_NAME"));
                object.addProperty("INS_DATE", viewDataRs.getString("ins_date"));
                object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO"));
                object.addProperty("INV_NO", viewDataRs.getString("INV_NO"));
                object.addProperty("INS_AMT", viewDataRs.getDouble("INS_AMT"));
                object.addProperty("RATE", viewDataRs.getDouble("RATE"));
                object.addProperty("REF_NO", viewDataRs.getString("REF_NO"));
                object.addProperty("branch_cd", viewDataRs.getString("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.GetModelwiseMonthWiseSalesStatement.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from ww  w.  j  a  v  a 2 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 code = request.getParameter("code");
    final String mode = request.getParameter("mode");
    final String type_cd = request.getParameter("type_cd");
    final String sub_type_cd = request.getParameter("sub_type_cd");
    final String GD_CD = request.getParameter("GD_CD");
    final String before_date = request.getParameter("before_date");
    final String after_date = request.getParameter("after_date");
    final String equal_date = request.getParameter("equal_date");
    final String date_mode = request.getParameter("date_mode");
    final String before_rate = request.getParameter("before_rate");
    final String after_rate = request.getParameter("after_rate");
    final String rate_mode = request.getParameter("rate_mode");
    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 {
            String sql = "SELECT t.branch_cd,SR_NAME,SUM(CASE WHEN DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 <=15  "
                    + " THEN 1 ELSE 0 END) AS day_15, "
                    + " SUM(CASE WHEN DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 <=45 and "
                    + " DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 >15 "
                    + " THEN 1 ELSE 0 END )AS day_45, "
                    + " SUM(CASE WHEN DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 <=90 and "
                    + " DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 >45 "
                    + " THEN 1 ELSE 0 END )AS day_90, "
                    + " SUM(CASE WHEN DATEDIFF( CASE WHEN l.v_date IS NOT NULL THEN l.v_date WHEN t.PUR_DATE IS NOT NULL THEN t.PUR_DATE ELSE '2016-04-01' END ,v.V_DATE)*-1 >90 "
                    + " THEN 1 ELSE 0 END ) AS day_100  "
                    + " 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 brandmst b ON m.brand_cd=b.brand_cd  "
                    + " LEFT JOIN lbrphd l ON l.ref_no=t.PUR_REF_NO LEFT JOIN vilshd v ON v.REF_NO=t.SALE_REF_NO"
                    + " LEFT JOIN acntmst a ON l.ac_cd=a.ac_cd WHERE t.is_del = 1  " + " ";
            if (mode.equalsIgnoreCase("brand")) {
                if (!code.equalsIgnoreCase("")) {
                    sql += " and b.BRAND_CD='" + code + "'";
                }
            }
            if (mode.equalsIgnoreCase("series")) {
                if (!code.equalsIgnoreCase("")) {
                    sql += " and s.sr_cd='" + code + "'";
                }
            }
            if (mode.equalsIgnoreCase("model")) {
                if (!code.equalsIgnoreCase("")) {
                    sql += " and m.model_cd='" + code + "'";
                }
            }

            if (date_mode.equalsIgnoreCase("2")) {
                sql += " and v_date <'" + before_date + "'";
            }

            if (date_mode.equalsIgnoreCase("3")) {
                sql += " and v_date >'" + after_date + "'";
            }

            if (date_mode.equalsIgnoreCase("4")) {
                sql += " and v_date ='" + equal_date + "'";
            }

            if (rate_mode.equalsIgnoreCase("2")) {
                sql += " and PUR_RATE <" + before_rate + "";
            }

            if (rate_mode.equalsIgnoreCase("3")) {
                sql += " and PUR_RATE >=" + after_rate + "";
            }

            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd='" + type_cd + "'";
            }

            if (!sub_type_cd.equalsIgnoreCase("")) {
                sql += " and m.sub_type_cd='" + sub_type_cd + "'";
            }
            if (!GD_CD.equalsIgnoreCase("2")) {
                sql += " and godown =" + GD_CD;
            }
            if (!branch_cd.equalsIgnoreCase("")) {
                sql += " and t.branch_cd='" + branch_cd + "' ";
            }
            sql += " GROUP BY t.branch_cd,sr_name";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("SR_NAME", rsLocal.getString("SR_NAME"));
                object.addProperty("day_15", rsLocal.getString("day_15"));
                object.addProperty("day_45", rsLocal.getString("day_45"));
                object.addProperty("day_90", rsLocal.getString("day_90"));
                object.addProperty("day_100", rsLocal.getString("day_100"));
                object.addProperty("branch_cd", rsLocal.getString("branch_cd"));
                array.add(object);
            }
            lb.closeResultSet(rsLocal);
            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.IMEWisePS.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww  w . j a  v a  2s  . 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 model_cd = request.getParameter("model_cd");
    final String brand_cd = request.getParameter("brand_cd");
    final String ac_cd = request.getParameter("ac_cd");
    final String type_cd = request.getParameter("type_cd");
    final String bill_no = request.getParameter("bill_no");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {
            String sql = "select a.FNAME,l.V_DATE,TAG_NO,SR_NAME,PUR_RATE,SALE_RATE,b.BRAND_NAME 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 brandmst b on m.brand_cd=b.brand_cd "
                    + " left join LBRPHD l on l.REF_NO=t.PUR_REF_NO left join ACNTMST a on l.AC_CD=a.AC_CD where t.TAG_NO <> ''";
            if (bill_no.equalsIgnoreCase("")) {
                sql += " and l.v_date>='" + from_date + "' and " + " l.v_date<='" + to_date + "'";
            } else {
                sql += " and l.inv_no=" + bill_no;
            }
            if (!model_cd.equalsIgnoreCase("")) {
                sql += " and m.model_cd ='" + model_cd + "'";
            }
            if (!brand_cd.equalsIgnoreCase("")) {
                sql += " and m.brand_cd ='" + brand_cd + "'";
            }

            if (!ac_cd.equalsIgnoreCase("")) {
                sql += " and l.ac_cd ='" + ac_cd + "'";
            }
            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd ='" + type_cd + "'";
            }
            sql += " order by l.v_date";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("FNAME", rsLocal.getString("FNAME"));
                object.addProperty("V_DATE", rsLocal.getString("V_DATE"));
                object.addProperty("TAG_NO", rsLocal.getString("TAG_NO"));
                object.addProperty("SR_NAME", rsLocal.getString("SR_NAME"));
                object.addProperty("BRAND_NAME", rsLocal.getString("BRAND_NAME"));
                object.addProperty("PUR_RATE", rsLocal.getDouble("PUR_RATE"));
                object.addProperty("SALE_RATE", rsLocal.getDouble("SALE_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.IMEWisePSSales.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w ww  . j  ava  2 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 model_cd = request.getParameter("model_cd");
    final String brand_cd = request.getParameter("brand_cd");
    final String ac_cd = request.getParameter("ac_cd");
    final String type_cd = request.getParameter("type_cd");
    final String bill_no = request.getParameter("bill_no");
    final boolean include = Boolean.parseBoolean(request.getParameter("include"));
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {
            String sql = "select a.FNAME,l.V_DATE,TAG_NO,SR_NAME,PUR_RATE,SALE_RATE,b.BRAND_NAME 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 brandmst b on m.brand_cd=b.brand_cd "
                    + " left join VILSHD l on l.REF_NO=t.SALE_REF_NO left join ACNTMST a on l.AC_CD=a.AC_CD where t.TAG_NO <> ''";
            if (bill_no.equalsIgnoreCase("")) {
                sql += " and l.v_date>='" + from_date + "' and " + " l.v_date<='" + to_date + "'";
            } else {
                sql += " and l.inv_no=" + bill_no;
            }
            if (!model_cd.equalsIgnoreCase("")) {
                sql += " and m.model_cd ='" + model_cd + "'";
            }
            if (!brand_cd.equalsIgnoreCase("")) {
                sql += " and m.brand_cd ='" + brand_cd + "'";
            }

            if (!ac_cd.equalsIgnoreCase("")) {
                if (include) {
                    sql += " and l.ac_cd ='" + ac_cd + "'";
                } else {
                    sql += " and l.ac_cd <>'" + ac_cd + "'";
                }
            }
            if (!type_cd.equalsIgnoreCase("")) {
                sql += " and m.type_cd ='" + type_cd + "'";
            }
            sql += " order by l.v_date";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("FNAME", rsLocal.getString("FNAME"));
                object.addProperty("V_DATE", rsLocal.getString("V_DATE"));
                object.addProperty("TAG_NO", rsLocal.getString("TAG_NO"));
                object.addProperty("SR_NAME", rsLocal.getString("SR_NAME"));
                object.addProperty("BRAND_NAME", rsLocal.getString("BRAND_NAME"));
                object.addProperty("PUR_RATE", rsLocal.getDouble("PUR_RATE"));
                object.addProperty("SALE_RATE", rsLocal.getDouble("SALE_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.ListBills.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w w w  .ja  v  a 2 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 ac_cd = request.getParameter("ac_cd");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Library lb = Library.getInstance();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final boolean sales = Boolean.parseBoolean((request.getParameter("sales")));

    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT * FROM oldb2_4 WHERE ac_cd='" + ac_cd + "' and unpaid_amt <> 0";
            if (sales) {
                sql += " AND tot_amt>0";
            } else {
                sql += " AND tot_amt<0";
            }

            sql += " order by DOC_DATE";
            pstLocal = dataConnection.prepareStatement(sql);
            ResultSet viewDataRs = pstLocal.executeQuery();

            JsonArray array = new JsonArray();
            while (viewDataRs.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("DOC_REF_NO", viewDataRs.getString("DOC_REF_NO"));
                object.addProperty("DOC_CD", viewDataRs.getString("DOC_CD"));
                object.addProperty("INV_NO", viewDataRs.getString("INV_NO"));
                object.addProperty("DOC_DATE", viewDataRs.getString("DOC_DATE"));
                object.addProperty("TOT_AMT", viewDataRs.getString("TOT_AMT"));
                object.addProperty("UNPAID_AMT", viewDataRs.getString("UNPAID_AMT"));
                object.addProperty("SR_NO", viewDataRs.getString("SR_NO"));
                if (lb.isDeleted(dataConnection, viewDataRs.getString("DOC_REF_NO"))) {
                    array.add(object);
                }
            }

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("balance", lb.getBalance(dataConnection, ac_cd));
            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.ListBillsAdjsted.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww  w. j  a  va2 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 Library lb = Library.getInstance();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();

    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "SELECT doc_ref_no,dr_doc_cd,dr_inv_no,cr_doc_cd,cr_inv_no,amt,DR_DOC_REF_NO,CR_DOC_REF_NO FROM billadjst WHERE "
                    + " DR_DOC_REF_NO IN (SELECT doc_ref_no FROM oldb2_2 WHERE ac_cd='" + ac_cd + "') OR "
                    + " CR_DOC_REF_NO IN (SELECT doc_ref_no FROM oldb2_2 WHERE 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("DOC_REF_NO", viewDataRs.getString("DOC_REF_NO"));
                object.addProperty("DR_DOC_CD", viewDataRs.getString("DR_DOC_CD"));
                object.addProperty("CR_DOC_CD", viewDataRs.getString("CR_DOC_CD"));
                object.addProperty("DR_INV_NO", viewDataRs.getString("DR_INV_NO"));
                object.addProperty("CR_INV_NO", viewDataRs.getString("CR_INV_NO"));
                object.addProperty("TOT_AMT", viewDataRs.getString("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);
}