List of usage examples for com.google.gson JsonObject add
public void add(String property, JsonElement value)
From source file:account.DailySalesStatementDetail.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . j ava 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 mode = Integer.parseInt(request.getParameter("mode")); 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.branch_cd,v.inv_no,v.v_type,a.fname,v.v_date,(p.card_chg+p.bajaj_chg) AS ins,(NET_AMT) AS net_amt,SUM(v1.DISC_RATE) AS adjst,\n" + " (v.BUY_BACK_AMT) AS buy_back,(p.CASH_AMT) AS cash,(p.CARD_AMT) AS card,(p.BANK_AMT) AS bank,(p.BAJAJ_AMT) AS bajaj,(p.DISC_AMT) AS mop " + " ,p.card_no,tid_no FROM VILSHD v LEFT JOIN PAYMENT p ON v.REF_NO=p.REF_NO LEFT JOIN acntmst a ON v.ac_cd=a.ac_cd\n" + " LEFT JOIN vilsdt v1 ON v.REF_NO=v1.REF_NO WHERE is_del =0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "'"; if (mode != 2) { sql += " and v.V_TYPE=" + mode; } if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } sql += " GROUP BY v.REF_NO order by v.v_date,v.v_type,v.inv_no"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("inv_no", viewDataRs.getString("inv_no")); object.addProperty("v_type", viewDataRs.getString("v_type")); object.addProperty("fname", viewDataRs.getString("fname")); object.addProperty("v_date", viewDataRs.getString("v_date")); object.addProperty("ins", viewDataRs.getDouble("ins")); object.addProperty("net_amt", viewDataRs.getDouble("net_amt")); object.addProperty("buy_back", viewDataRs.getDouble("buy_back")); object.addProperty("cash", viewDataRs.getDouble("cash")); object.addProperty("card", viewDataRs.getString("card")); object.addProperty("bank", viewDataRs.getString("bank")); object.addProperty("bajaj", viewDataRs.getString("bajaj")); object.addProperty("adjst", viewDataRs.getString("adjst")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); object.addProperty("MOP", viewDataRs.getString("MOP")); object.addProperty("card_no", viewDataRs.getString("card_no")); object.addProperty("tid_no", viewDataRs.getString("tid_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.DCRegister.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w w w . j a va 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 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 d.ref_no,FNAME,d.INV_NO,d.V_DATE,d1.TAG_NO,s.SR_NAME,d1.RATE,d1.remark from DCHD d left join DCDT d1 on d.REF_NO=d1.REF_NO " + " left join ACNTMST a on d.AC_CD=a.AC_CD left join SERIESMST s on d1.SR_CD=s.SR_CD " + " left join modelmst m on m.model_cd = s.model_cd where d.IS_DEL=0" + " and d.v_date>='" + from_date + "' " + " and d.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 d.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("V_DATE", viewDataRs.getString("V_DATE")); object.addProperty("RATE", viewDataRs.getDouble("RATE")); object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO")); object.addProperty("REF_NO", viewDataRs.getString("REF_NO")); object.addProperty("REMARK", viewDataRs.getString("REMARK")); 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.EOD.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . j a v a 2s . 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 DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int mode = Integer.parseInt(request.getParameter("mode")); 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 sum(v.ins_amt) as ins,sum(net_amt) as net_amt,sum(v.head_disc) as MOP," + "sum(v.BUY_BACK_AMT) as buy_back,(SELECT SUM(disc_rate) FROM vilsdt v1 WHERE v1.REF_NO=v.REF_NO)AS adjst" + ",sum(p.CASH_AMT) as cash," + "sum(p.CARD_AMT) as card,sum(p.BANK_AMT) as bank,sum(p.BAJAJ_AMT) as bajaj" + " from VILSHD v left join PAYMENT p on v.REF_NO=p.REF_NO where is_del =0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "'"; if (mode != 2) { sql += " and v.V_TYPE=" + mode; } 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("ins", viewDataRs.getDouble("ins")); object.addProperty("net_amt", viewDataRs.getDouble("net_amt")); object.addProperty("buy_back", viewDataRs.getDouble("buy_back")); object.addProperty("cash", viewDataRs.getDouble("cash")); object.addProperty("card", viewDataRs.getString("card")); object.addProperty("bank", viewDataRs.getString("bank")); object.addProperty("bajaj", viewDataRs.getString("bajaj")); object.addProperty("adjst", viewDataRs.getString("adjst")); 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.GenralLedger.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .jav a2 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 { 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) { double opb = 0.00; String sql = "(select (select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' and DOC_DATE<'" + from_date + "' and CRDR=0) -" + "(select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' " + "and DOC_DATE<'" + from_date + "' and CRDR=1) as opb from dual) "; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); viewDataRS = pstLocal.executeQuery(); if (viewDataRS.next()) { jResultObj.addProperty("opb", viewDataRS.getDouble("opb")); opb = viewDataRS.getDouble("opb"); } else { jResultObj.addProperty("opb", 0.00); } makeQuery(); double opbRs = 0.00; JsonArray array = new JsonArray(); while (viewDataRS.next()) { JsonObject object = new JsonObject(); object.addProperty("FNAME", viewDataRS.getString("FNAME")); if (viewDataRS.getString("DOC_REF_NO").startsWith("05")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("BILL_NO")); } else if (viewDataRS.getString("DOC_REF_NO").startsWith("02")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); } else if (viewDataRS.getString("INV_NO").equalsIgnoreCase("0")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("DOC_REF_NO")); } else { object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); } object.addProperty("DOC_DATE", viewDataRS.getString("DOC_DATE")); object.addProperty("DOC_CD", viewDataRS.getString("DOC_CD")); object.addProperty("DR", lb.roundOffDoubleValue(viewDataRS.getDouble("DR"))); object.addProperty("CR", lb.roundOffDoubleValue(viewDataRS.getDouble("CR"))); opbRs += viewDataRS.getDouble("DR") - viewDataRS.getDouble("CR"); object.addProperty("BAL", lb.roundOffDoubleValue(opbRs)); object.addProperty("PARTICULAR", viewDataRS.getString("PARTICULAR")); object.addProperty("OPP_AC_CD", viewDataRS.getString("OPP_AC_CD")); object.addProperty("REF_NO", viewDataRS.getString("doc_ref_no")); object.addProperty("OPB", opb); array.add(object); } jResultObj.addProperty("opb", opb); 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.GetCardDetail.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www.j a v 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 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 ww w . 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 { 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 w w w . j a va 2s .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 { 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 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 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 va 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./*w ww . 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 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); }