public ModelAndView newBill(HttpServletRequest request, HttpServletResponse response)throws Exception
{
float qtySold,total,price;
int productId;
long billId;
Product product = new Product();
try{
qtySold=Float.parseFloat(request.getParameter("qtySold"));
price=Float.parseFloat(request.getParameter("price"));
productId=Integer.parseInt(request.getParameter("productId"));
}catch(NullPointerException e){
qtySold=0;
price=0;
productId=0;
System.out.println("Null pointer eexception");
}
total=qtySold*price;
List<Product> productList= productDAO.selectById(productId);
for(int i=0;i<productList.size();i++)
{
product = productList.get(i);
}
float temp= product.getQtyAvail();
if(qtySold == 0)
return new ModelAndView("redirect:listBill.htm?noQty=true");
if(temp<qtySold || temp == 0)
{
return new ModelAndView("redirect:listBill.htm?noStock="+(temp-qtySold));
}
else
{
product.setQtyAvail(temp-qtySold);
productDAO.updateProduct(product);
StockAlertSettings stockAlertLimit;
String stockAlertString="";
try{
stockAlertLimit = stockAlertSettingsDAO.getSettings();
}catch (NullPointerException e) {
StockAlertSettings settings= new StockAlertSettings();
settings.setVariable("min_qty");
settings.setValue("10");
stockAlertLimit = stockAlertSettingsDAO.getSettings();
}
if(product.getQtyAvail()< Float.parseFloat(stockAlertLimit.getValue()))
stockAlertString="stockAlert="+temp;
billId= Long.parseLong(request.getSession().getAttribute("billId").toString());
Bill bill = new Bill();
bill= billDAO.selectBill(billId);
Sales sales= new Sales(product, qtySold, total,bill ,1); //Sales(Product productId, float qtySold, float total, long billId , int isActive)