Commit b8b54d9e authored by vvengurlekar's avatar vvengurlekar

ShortageInventory.java, ShortageInventoryLocal.java,...

ShortageInventory.java, ShortageInventoryLocal.java, ShortageInventoryRemote.java, ShortageInventoryServlet.java added for shortage inventory dashboard


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@175452 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 5598983b
package ibase.dashboard.scm.ejb;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.io.File;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
@Stateless
public class ShortageInventory extends ValidatorEJB implements ShortageInventoryLocal, ShortageInventoryRemote
{
@SuppressWarnings({ "unchecked"})
public JSONObject getShortageInventory(String dataSourceName , String loginSiteCode , String finYear) throws RemoteException, ITMException
{
JSONObject shortageInvJSON = new JSONObject();
JSONObject rowData = null;
JSONObject countData = null;
String sql = "", sql1 = "", fromDate = "", toDate = "";
String tran_image = "" , itemCode = "";
String itemDescr = "",orderCount = "", quantity = "";
double pendingQty = 0.0, pendingValue = 0.0, availableQty = 0.0, avgSalesPerDay = 0.0, availQtyForNearBy = 0.0;
double daysInventoryAvail = 0.0, shortageInventory =0.0;
Connection con = null;
ConnDriver connDriver = new ConnDriver();
ResultSet rs = null, rs1 = null;
PreparedStatement pstmt = null, pstmt1 = null;
int count=0;
Calendar cal = null;
SimpleDateFormat sdf = null;
try
{
System.out.println("Try block of InventoryShortage.getShortageInventory()");
con = connDriver.getConnectDB(dataSourceName);
connDriver=null;
/*if(finYear == null || "".equalsIgnoreCase(finYear))
{
sql = "Select Acct_Prd,Code,Descr From Period Where To_Date(Sysdate) Between Fr_Date and To_Date";
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
acctPeriod = checkNull(rs.getString("Acct_Prd"));
System.out.println("Period code ======== " + acctPeriod );
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
acctPeriod = finYear;
System.out.println("Financial year ======= " + acctPeriod);
}*/
System.out.println("LOGIN SITE CODE ======= " + loginSiteCode);
cal = Calendar.getInstance();
sdf = new SimpleDateFormat("dd-MMM-yy");
int currentDayMonth = cal.DAY_OF_MONTH;
int lastDayMonth = cal.getActualMaximum(Calendar.DATE);
cal = Calendar.getInstance();
//cal.add(cal.MONTH,-1);
//cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DATE));
System.out.println("get currentDayMonth==="+currentDayMonth+" LastDayMonth========"+lastDayMonth);
System.out.println("Date of today: "+fromDate+" Last day of month: "+toDate);
sql = "select item_code,ROUND(nvl(SUM(quantity) / SUM(DAY),0),0) as avg_sales " +
"from ( select i.item_code as item_code,1 as day," +
//" to_date(h.conf_date) as conf_date, " +
"round(sum(i.quantity__stduom),0) as quantity " +
"from invoice_trace i, invoice h where i.invoice_id = h.invoice_id " +
"AND TO_DATE(H.CONF_DATE) BETWEEN TO_DATE(SYSDATE) - 90 " +
"AND TO_DATE(SYSDATE) AND H.SITE_CODE ='"+loginSiteCode+"' " +
"GROUP BY I.ITEM_CODE) " +
"GROUP BY ITEM_CODE ORDER BY ITEM_CODE";
pstmt = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = pstmt.executeQuery();
int rowCount = 0;
rs.last();
rowCount = rs.getRow();
System.out.println("rowCount ==== " + rowCount);
rs.beforeFirst();
while(rs.next())
{
itemCode = checkNull(rs.getString("item_code"));
avgSalesPerDay = Math.round(checkDouble(rs.getString("avg_sales")));
//For calculating available inventory
sql1 = "SELECT FN_GET_ITMSTK ('"+itemCode+"', '"+loginSiteCode+"') as available_qty from dual";
pstmt1 = con.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
availableQty = Math.round(checkDouble(rs1.getString("available_qty")));
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
//For calculating available inventoryNumber of Pending orders,Total Pending order quantity,total Pending order value
sql1 = "SELECT SORDITEM.ITEM_CODE, ITEM.DESCR AS ITEM_DESCR," +
"COUNT(DISTINCT SORDITEM.SALE_ORDER) ORDER_COUNT, " +
"sum(sorditem.quantity) quantity, sum(sorditem.quantity - sorditem.qty_desp)" +
" as pending_qty, sum ((sorditem.quantity - sorditem.qty_desp) * " +
"sorditem.rate ) as pending_value FROM sorder, sorditem, item, sorddet " +
"WHERE ( sorder.sale_order = sorditem.sale_order ) " +
"and ( sorditem.sale_order = sorddet.sale_order ) " +
"and ( sorditem.line_no = sorddet.line_no ) " +
"and ( sorditem.item_code = item.item_code ) and ( sorder.confirmed = 'Y' ) " +
"and ( sorditem.status = 'P' ) AND ( sorditem.site_code='"+loginSiteCode+"') " +
"and ( sorditem.item_code='"+itemCode+" ') " +
"group by sorditem.item_code,item.descr";
pstmt1 = con.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
itemDescr = checkNull(rs1.getString("ITEM_DESCR"));
orderCount = checkNull(rs1.getString("ORDER_COUNT"));
quantity = checkNull(rs1.getString("quantity"));
pendingQty = Math.round(checkDouble(rs1.getString("pending_qty")));
pendingValue = Math.round(checkDouble(rs1.getString("pending_value")));
String object = "images"+ File.separator + "users";
String userImagePath = "/ibase/CustomMenuImageServlet?fldValue="+itemDescr+"&object="+object+"&objName="+object+"&ALT_FLD_VALUE="+itemDescr;
tran_image = "<img class='cardProdImg2' src='"+userImagePath+"' style='margin-top:-15px'/>";
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
//For calculating Number of days inventory available
daysInventoryAvail = Math.round(availableQty/avgSalesPerDay);
//For calculating Near by site stock
String siteCodeFrom = "";
sql1 = "SELECT SITE_CODE__FROM, DISTANCE FROM DIST_INTERSITE_OPTIONS " +
"WHERE SITE_CODE='"+loginSiteCode+"' ORDER BY SITE_CODE ASC,DISTANCE ASC";
pstmt1 = con.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
siteCodeFrom = checkNull(rs1.getString("SITE_CODE__FROM"));
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
sql1 = "SELECT FN_GET_ITMSTK ('"+itemCode+"', '"+siteCodeFrom+"') as available_qty_nearby from dual";
pstmt1 = con.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
availQtyForNearBy = Math.round(checkDouble(rs1.getString("available_qty_nearby")));
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
//For calculating Shortage of inventory
int balanceDays = lastDayMonth-currentDayMonth;
shortageInventory = Math.round((balanceDays*avgSalesPerDay) - availableQty);
System.out.println("shortageInventory: "+shortageInventory);
rowData = new JSONObject();
rowData.put("image", tran_image);
rowData.put("descr", itemDescr+" ("+itemCode+") ");
rowData.put("avgSalesPerDay", avgSalesPerDay);
if(shortageInventory > 0)
{
rowData.put("availableQty", availableQty+"(+"+shortageInventory+")");
}
else
{
rowData.put("availableQty", availableQty);
}
rowData.put("orderCount", orderCount);
rowData.put("pendingQty", pendingQty);
rowData.put("pendingValue", pendingValue);
rowData.put("daysInventoryAvail", daysInventoryAvail);
rowData.put("availQtyForNearBy", availQtyForNearBy);
rowData.put("Items", pendingValue);
shortageInvJSON.put(count, rowData);
count++;
}
}
catch (Exception e)
{
System.out.println("Catch Block of InventoryShortage.getShortageInventory()"+e);
}
finally
{
try
{
if (con != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
con.close();
con = null;
}
con = null;
} catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception in :InventoryShortage:" + e.getMessage());
throw new ITMException(e);
}
}
return shortageInvJSON;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
} else
{
input = input.trim();
}
return input;
}
private Double checkDouble(String input)
{
if (input == null || input.length()==0)
{
return 0.0;
} else
{
return Double.parseDouble(input);
}
}
}
package ibase.dashboard.scm.ejb;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
@Local
public interface ShortageInventoryLocal extends ValidatorLocal
{
public JSONObject getShortageInventory(String dataSourceName , String siteCode , String finYear) throws RemoteException, ITMException;
}
package ibase.dashboard.scm.ejb;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
@Remote
public interface ShortageInventoryRemote extends ValidatorRemote
{
public JSONObject getShortageInventory(String dataSourceName , String siteCode , String finYear) throws RemoteException, ITMException;
}
package ibase.dashboard.scm.servlet;
import ibase.dashboard.scm.ejb.ShortageInventoryRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.json.simple.JSONObject;
public class ShortageInventoryServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
ShortageInventoryRemote shortageInventoryRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String loginSiteCode = "";
String finYear = "";
try
{
System.out.println("Try block of ShortageInventoryServlet.doPost()");
response.setContentType("application/xml");
HttpSession session = request.getSession(true);
ibase.utility.UserInfoBean userInfo = (ibase.utility.UserInfoBean) session.getAttribute("USER_INFO");
loginSiteCode = userInfo.getSiteCode();
dataSourceName = request.getParameter("dataSourceName");
finYear = request.getParameter("finYear");
context = new InitialContext(appConnectParm.getProperty());
shortageInventoryRemote = (ShortageInventoryRemote) context.lookup("ibase/ShortageInventory/remote");
JSONObject jsonObjData = (JSONObject) shortageInventoryRemote.getShortageInventory(dataSourceName,loginSiteCode,finYear);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println("Final data set for ShortageInventoryServlet build the Graph is === " + jsonObjData);
} catch (Exception e)
{
System.out.println("Catch block of ShortageInventoryServlet.doPost()");
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment