Commit 41fa2933 authored by msharma's avatar msharma

SQL logic changed for ATP to retrieve stock


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@101431 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 9c93e8a1
......@@ -4433,6 +4433,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
double reorderLevel=0,planSupply=0,netReqd=0;
HashMap<String, ArrayList<DataBean>> dataMap = new HashMap<String, ArrayList<DataBean>>();
HashMap<String, ArrayList<DataBean>> altItemdataMap = new HashMap<String, ArrayList<DataBean>>();
ArrayList<String> itemSiteList=new ArrayList<String>();
try
{
......@@ -4444,7 +4445,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
itemCode = adpElement.getItemCode();
siteCodeAdp = adpElement.getSiteCode();
itemSiteList.add(siteCodeAdp+"@"+itemCode);
//System.out.println("@@@cpatil_sale_order==["+saleOrder+"]itemCode==["+itemCode+"]siteCodeAdp["+siteCodeAdp+"]");
//System.out.println("ctr1=="+ctr1);
if(ctr1 > 0)
......@@ -4457,6 +4458,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
tempitemCodeList = "'"+siteCodeAdp+itemCode+"'" ;
}
//adpElement=null; //cpatilnull
//itemSiteMap.put(itemCode, siteCodeAdp);
}
//System.out.println("@@@@@@@@ before tempitemCodeList==["+tempitemCodeList+"]");
......@@ -4482,8 +4484,9 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
// //cpatil-25/08/14-System.out.println("commonConstants.DB_NAME "+CommonConstants.DB_NAME);
// 14-02-2007 manoharan
dataMap=getItemMap(tempitemCodeList,siteCodeAdp);
//dataMap=getItemMap(tempitemCodeList,siteCodeAdp);
dataMap=getItemMap(itemSiteList,siteCodeAdp);
itemSiteList.clear();
//System.out.println("adpList.size["+adpList.size()+"]adpList["+adpList+"]");
for( int ctr=0; ctr < adpList.size() ; ctr++ )
......@@ -4640,11 +4643,12 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
for(int i=0;i<altItemlist.size();i++)
{
customAltItem+="'"+(adpElement.getSiteCode()).trim()+((altItemlist.get(i)).split("@"))[0].trim()+"',";
//customAltItem+="'"+(adpElement.getSiteCode()).trim()+((altItemlist.get(i)).split("@"))[0].trim()+"',";
itemSiteList.add(adpElement.getSiteCode()+"@"+((altItemlist.get(i)).split("@"))[0]);
}
System.out.println("customAltItem["+customAltItem+"]");;
customAltItem=customAltItem.substring(1, customAltItem.length()-2);
altItemdataMap=getItemMap(customAltItem, siteCodeAdp);
//System.out.println("customAltItem["+customAltItem+"]");;
//customAltItem=customAltItem.substring(1, customAltItem.length()-2);
altItemdataMap=getItemMap(itemSiteList, siteCodeAdp);
//System.out.println("altItemdataMap["+altItemdataMap+"]");
//System.out.println("altItemdataMap.size()["+altItemdataMap.size()+"]");
if(altItemdataMap.size()>0)
......@@ -4752,6 +4756,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
}
itemSiteList.clear();
}
/////////////////Ended by Manoj dtd 07/04/2016//////////////////
......@@ -11984,7 +11989,228 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
}
private HashMap<String, ArrayList<DataBean>> getItemMap(String itemCodeList,String siteCodeAdp) throws ITMException
private HashMap<String, ArrayList<DataBean>> getItemMap(ArrayList<String> itemSiteList,String siteCodeAdp) throws ITMException
{
String sqlFileName = null;
String adpQuery="",tranId="",tranSer="";
HashMap<String, ArrayList<DataBean>> dataMap = new HashMap<String, ArrayList<DataBean>>();
PreparedStatement pstmt=null;
ResultSet rs=null;
System.out.println("matPlan---"+matPlan+"----mfgPlan----"+mfgPlan);
System.out.println("isDetailReq2------"+isDetailReq);
Timestamp dueDate=null;
String dbName="";
String adpGenQuery="";
String adpGenQuery1="";
String itemCode="",siteCode="";
String itemSiteCode="";
String strQuery="";
try
{
if (matPlan.equalsIgnoreCase("N") && mfgPlan.equalsIgnoreCase("N"))
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplyforecastonly";
}
else if (matPlan.equalsIgnoreCase("Y") && mfgPlan.equalsIgnoreCase("N"))
{
//cpatil-25/08/14-System.out.println("wnName1["+wnName1+"]");
if(wnName1.trim().equals("w_requirement"))
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplymaterialReq";
}
else
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplymaterial";
}
} else
{
//Condition Added By manoj dtd 31/10/2013 to get demand supply at detail level
//cpatil-25/08/14-System.out.println("isDetailReq------"+isDetailReq);
if(isDetailReq)
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplyDetail";
}
else
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupply";
}
}
//cpatil-25/08/14-System.out.println("sqlFileName---"+sqlFileName);
// end 14-02-2007 manoharan
if ((CommonConstants.DB_NAME).equalsIgnoreCase("db2"))
{
// System.out.println("Firing DB2 Sql For Site Code :" +
// siteCode + " Item Code : " + itemCode + " From Date : " +
// dateFrom + " To Date : "+ dateTo + " StandgOrdTypes : "+
// standingOrdTypes +" MadeToOrder " +madeToOrder+
// " MadeToStock : " + madeToStock);
// 14-02-2007 manoharan
// String adpQueryOriginal = readFile(CommonConstants.JBOSSHOME
// + File.separator +"sql" + File.separator +
// "demandsupplyDB2.sql");
String adpQueryOriginal = readFile(sqlFileName + "DB2.sql");
// end 14-02-2007 manoharan
String strDateFrom = dateFrom.toString();
strDateFrom = strDateFrom.replaceAll(" ", "-");
strDateFrom = strDateFrom.replaceAll(":", ".");
String strDateTo = dateTo.toString();
strDateTo = strDateTo.replaceAll(" ", "-");
strDateTo = strDateTo.replaceAll(":", ".");
adpQuery = adpQueryOriginal;
//adpQuery = adpQuery.replaceAll("@itemcode@", itemCodeList);
adpQuery = adpQuery.replaceAll("@fromdate@", dateFromString);
adpQuery = adpQuery.replaceAll("@todate@", dateToString);
adpQuery = adpQuery.replaceAll("@ordtypes@", standingOrdTypes);
adpQuery = adpQuery.replaceAll("@madetoorder@", madeToOrder);
adpQuery = adpQuery.replaceAll("@madetostock@", madeToStock);
adpQuery = adpQuery.replaceAll("@rundate@", runDateString);
dbName="db2";
} else if ((CommonConstants.DB_NAME).equalsIgnoreCase("oracle"))
{
String adpQueryOriginal = readFile(sqlFileName + "Oracle.sql");
// end 14-02-2007 manoharan
adpQuery = adpQueryOriginal;
//adpQuery = adpQuery.replaceAll("@itemcode@", itemCodeList );
adpQuery = adpQuery.replaceAll("@fromdate@", dbDateFrom);
adpQuery = adpQuery.replaceAll("@todate@", dbDateTo);
adpQuery = adpQuery.replaceAll("@ordtypes@", standingOrdTypes);
adpQuery = adpQuery.replaceAll("@madetoorder@", madeToOrder);
adpQuery = adpQuery.replaceAll("@madetostock@", madeToStock);
// 01-10-2007 manoharan
adpQuery = adpQuery.replaceAll("@rundate@", dbRunDate);
dbName="oracle";
// end 01-10-2007 manoharan
// System.out.println("Replaced Values.in SQL.....");
}
adpGenQuery=adpQuery;
adpGenQuery1=adpQuery;
if(!isDetailReq)
{
FileOutputStream fout = null;
BufferedWriter bw = null;
fout = new FileOutputStream("demandsupply.sql");
bw = new BufferedWriter(new OutputStreamWriter(fout));
bw.write(adpQuery);
bw.close();
fout.close();
}
// stmt = conn.createStatement();
// System.out.println("Executing Query After Replacement.....");
// rs = stmt.executeQuery(adpQuery);
if(itemSiteList.size()>0)
{
for(int ctr=0;ctr<itemSiteList.size();ctr++)
{
adpGenQuery=adpQuery;
itemSiteCode=itemSiteList.get(ctr);
adpGenQuery = adpGenQuery.replaceAll("@itemcode@", itemSiteCode.split("@")[1]);
adpGenQuery = adpGenQuery.replaceAll("@sitecode@", itemSiteCode.split("@")[0]);
if(ctr==itemSiteList.size()-1)
{
strQuery=strQuery+adpGenQuery;
}
else
{
strQuery=strQuery+adpGenQuery+" union all ";
}
}
}
strQuery=" select item_code, due_date, 0 demand, sum(supply) supply ,"
+ " sum(stock_qty) stock_qty, sum(oth_supply) oth_supply, sum(pending_po) pending_po ,"
+ "sum(pending_do) pending_do, sum(pending_indent) pending_indent,"
+ " sum(pending_dr) pending_dr,tran_id,tran_ser ,site_code from ( "+strQuery;
strQuery=strQuery+" ) alias group by item_code,due_date ,tran_id,tran_ser,site_code having sum(demand) <> 0 or sum(supply) <> 0 ";
pstmt = conn.prepareStatement(strQuery);
rs = pstmt.executeQuery();
// System.out.println("Query Executed for item : " + itemCode);
String rsItemCode = "", adpItemcode = "",rsSiteCode="";
// HashMap<K, V>
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
Timestamp today = new java.sql.Timestamp(System.currentTimeMillis()) ;
today = java.sql.Timestamp.valueOf(sdf.format(today) + " 00:00:00.000");
while(rs.next())
{
DataBean dataBeanObject = new DataBean();
rsItemCode = rs.getString(1);
rsSiteCode = rs.getString(13);
dueDate=rs.getTimestamp(2);
if(dueDate.compareTo(today)<0)
{
dueDate=today;
}
//rsSiteCode = siteCode;
dataBeanObject.setItemCode(rs.getString(1));
dataBeanObject.setDueDate(dueDate);
dataBeanObject.setDemand(rs.getDouble(3));
dataBeanObject.setSupply(rs.getDouble(4));
dataBeanObject.setStockQty(rs.getDouble(5));
dataBeanObject.setOthSupply(rs.getDouble(6));
dataBeanObject.setPendDOQty(rs.getDouble(8));
dataBeanObject.setPendDRQty(rs.getDouble(10));
dataBeanObject.setPendIndQty(rs.getDouble(9));
dataBeanObject.setPendPOQty(rs.getDouble(7));
if(isDetailReq)
{
tranId=rs.getString("tran_id");
tranSer=rs.getString("tran_ser");
dataBeanObject.setTranId(tranId);
dataBeanObject.setTranSer(tranSer);
}
System.out.println("@@@_for setmap:::itemCode==["+rs.getString(1)+"]siteCode["+rs.getString(13)+"]demand["+rs.getDouble(3)+"]supply["+rs.getDouble(4)+"]stockQty["+rs.getDouble(5)+"]othSupply["+rs.getDouble(6)+"]pendingPO["+rs.getDouble(7)+"]pendingDO["+rs.getDouble(8)+"]pendingIndent["+rs.getDouble(9)+"]pendingDR["+rs.getDouble(10)+"]");
if( dataMap.containsKey(siteCodeAdp+rsItemCode) )
{
ArrayList tempAdpElementList = (ArrayList) dataMap.get(rsSiteCode+rsItemCode);
tempAdpElementList.add(dataBeanObject);
dataMap.put(rsSiteCode+rsItemCode,tempAdpElementList);
//adpElementMap.put(siteCodeAdp+rsItemCode,adpElementList);
}
else
{
ArrayList tempAdpElementList = new ArrayList();
tempAdpElementList.add(dataBeanObject);
dataMap.put(rsSiteCode+rsItemCode,tempAdpElementList);
//adpElementMap.put(siteCodeAdp+rsItemCode, adpElementList);
}
dataBeanObject = null;
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}catch(Exception e)
{
e.printStackTrace();
}
return dataMap;
}
private HashMap<String, ArrayList<DataBean>> getItemMap1(String itemCodeList,String siteCodeAdp) throws ITMException
{
String sqlFileName = null;
String adpQuery="",tranId="",tranSer="";
......
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