public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws ParseException, ProductDaoException, SupplierDaoException { String[] prsNumbers = request.getParameterValues("prsNumber"); String[] itemCodes = request.getParameterValues("itemCode"); String[] supplierCodes = request.getParameterValues("supplierCode"); String[] selecteds = request.getParameterValues("selected"); String[] prices = request.getParameterValues("price"); String[] tops = request.getParameterValues("top"); String[] topDescs = request.getParameterValues("topDesc"); String[] tods = request.getParameterValues("tod"); String[] wps = request.getParameterValues("wp"); LoginUser lu = (LoginUser) request.getSession().getAttribute("user"); /* get prs assign to supplier */ AssignCanvassingDao assignCanvassingDao = DaoFactory.createAssignCanvassingDao(); for (int i = 0; i < itemCodes.length; i++) { AssignCanvassing ac = assignCanvassingDao.findForPriceSaving(prsNumbers[i], itemCodes[i], supplierCodes[0]); ac.setIsSelected(selecteds[i].equals("on") ? "Y" : "N"); ac.setUnitPrice(new BigDecimal(prices[i])); ac.setTop(tops[i]); ac.setTopDesc(topDescs[i]); ac.setTod(tods[i]); ac.setWp(wps[i].isEmpty() ? null : new SimpleDateFormat("dd/MM/yyyy").parse(wps[i])); ac.setUpdatedBy(lu.getUserId()); ac.setUpdatedDate(new Date()); assignCanvassingDao.update(ac); } return findByPrimaryKey(request, response); }
public ModelAndView getSupplier(HttpServletRequest request, HttpServletResponse response) throws IOException, ProductDaoException, SupplierDaoException { String supplierCode = request.getParameter("key"); LoginUser lu = (LoginUser) request.getSession().getAttribute("user"); /* get assigned supplier */ ProductDao productDao = DaoFactory.createProductDao(); SupplierDao supplierDao = DaoFactory.createSupplierDao(); PrsDetailDao prsDetailDao = DaoFactory.createPrsDetailDao(); AssignCanvassingDao assignCanvassingDao = DaoFactory.createAssignCanvassingDao(); List<AssignCanvassing> acs = assignCanvassingDao.findForPriceAssign(supplierCode, lu.getUserId()); Map<String, Object> json = new HashMap<String, Object>(); List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>(); for (AssignCanvassing x : acs) { Product p = productDao.findWhereProductCodeEquals(x.getProductCode()).get(0); Supplier s = supplierDao.findWhereSupplierCodeEquals(x.getSupplierCode()).get(0); PrsDetail pd = prsDetailDao.findByPrsProduct(x.getPrsNumber(), x.getProductCode()); Map<String, Object> row = new HashMap<String, Object>(); row.put("0", x.getId()); row.put("1", x.getPrsNumber()); row.put("2", new SimpleDateFormat("dd/MM/yyyy").format(x.getCreateDate())); row.put("3", x.getProductCode()); row.put("4", p.getProductName()); row.put("5", pd.getQty()); row.put("6", x.getSupplierCode()); row.put("7", s.getSupplierName()); rows.add(row); } json.put("rows", rows); return new ModelAndView("jsonView", json); }
public void ajaxSearch(HttpServletRequest request, HttpServletResponse response) throws IOException, ProductDaoException, SupplierDaoException { Boolean b = Boolean.FALSE; PrintWriter pw = response.getWriter(); LoginUser lu = (LoginUser) request.getSession().getAttribute("user"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); ProductDao productDao = DaoFactory.createProductDao(); SupplierDao supplierDao = DaoFactory.createSupplierDao(); AssignCanvassingDao assignCanvassingDao = DaoFactory.createAssignCanvassingDao(); pw.print( "{\"maxpage\": " + assignCanvassingDao.ajaxMaxPagePA( request.getParameter("where"), new BigDecimal(request.getParameter("show")), lu.getUserId()) + ",\"data\": ["); List<AssignCanvassing> acs = assignCanvassingDao.ajaxSearchPA( request.getParameter("where"), request.getParameter("order"), Integer.parseInt(request.getParameter("page"), 10), Integer.parseInt(request.getParameter("show")), lu.getUserId()); for (AssignCanvassing x : acs) { Product p = productDao.findWhereProductCodeEquals(x.getProductCode()).get(0); Supplier s = supplierDao.findWhereSupplierCodeEquals(x.getSupplierCode()).get(0); if (b) pw.print(","); pw.print("{\"1\": \"" + x.getId() + "\", "); pw.print("\"2\": \"" + x.getPrsNumber() + "\", "); pw.print("\"3\": \"" + x.getSupplierCode() + "\", "); pw.print("\"4\": \"" + s.getSupplierName() + "\", "); pw.print( "\"5\": \"" + (x.getUpdatedDate() == null ? "" : sdf.format(x.getUpdatedDate())) + "\", "); pw.print("\"6\": \"" + x.getProductCode() + "\", "); pw.print("\"7\": \"" + p.getProductName() + "\"}"); b = Boolean.TRUE; } pw.print("]}"); }
public void ajaxDocument(HttpServletRequest request, HttpServletResponse response) throws ProductDaoException, SupplierDaoException, IOException { String prsNumber = request.getParameter("key1"); String itemCode = request.getParameter("key2"); String supplierCode = request.getParameter("key3"); /* get assigned supplier */ ProductDao productDao = DaoFactory.createProductDao(); SupplierDao supplierDao = DaoFactory.createSupplierDao(); AssignCanvassingDao assignCanvassingDao = DaoFactory.createAssignCanvassingDao(); List<AssignCanvassing> acs = assignCanvassingDao.findByPrsNumberItemCodeSupplierCode(prsNumber, itemCode, supplierCode); String out = "["; for (AssignCanvassing x : acs) { if (!out.equals("[")) { out += ","; } Product p = productDao.findWhereProductCodeEquals(x.getProductCode()).get(0); Supplier s = supplierDao.findWhereSupplierCodeEquals(x.getSupplierCode()).get(0); out += "{\"prsNo\": \"" + x.getPrsNumber() + "\", " + "\"assignDate\": \"" + new SimpleDateFormat("dd/MM/yyyy").format(x.getCreateDate()) + "\", " + "\"itemCode\": \"" + x.getProductCode() + "\", " + "\"itemName\": \"" + p.getProductName() + "\", " + "\"supplierCode\": \"" + x.getSupplierCode() + "\", " + "\"supplierName\": \"" + s.getSupplierName() + "\", " + "\"unitPrice\": \"" + x.getUnitPrice() + "\", " + "\"top\": \"" + x.getTop() + "\", " + "\"topDesc\": \"" + x.getTopDesc() + "\", " + "\"tod\": \"" + x.getTod() + "\", " + "\"warranty\": \"" + x.getWp() + "\"}"; } out += "]"; response.getWriter().print(out); }