Commit 35694017 authored by cpatil's avatar cpatil

added and modify for supreme to minimize execution time


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@96870 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e84c1491
package ibase.webitm.ejb.mfg;
import java.sql.Timestamp;
public class DataBean
{
String itemCode="";
Timestamp dueDate = null;
double demand = 0, supply = 0,stockQty = 0,othSupply = 0,pendDOQty = 0, pendDRQty = 0, pendIndQty = 0 , pendPOQty = 0;
String tranId = "", tranSer="";
public String getItemCode()
{
return itemCode;
}
public void setItemCode(String itemCode)
{
this.itemCode = itemCode;
}
public Timestamp getDueDate() {
return dueDate;
}
public void setDueDate(Timestamp dueDate)
{
this.dueDate = dueDate;
}
public double getDemand()
{
return demand;
}
public void setDemand(double demand)
{
this.demand = demand;
}
public double getSupply()
{
return supply;
}
public void setSupply(double supply)
{
this.supply = supply;
}
public double getStockQty()
{
return stockQty;
}
public void setStockQty(double stockQty)
{
this.stockQty = stockQty;
}
public double getOthSupply()
{
return othSupply;
}
public void setOthSupply(double othSupply)
{
this.othSupply = othSupply;
}
public double getPendDOQty()
{
return pendDOQty;
}
public void setPendDOQty(double pendDOQty)
{
this.pendDOQty = pendDOQty;
}
public double getPendDRQty() {
return pendDRQty;
}
public void setPendDRQty(double pendDRQty)
{
this.pendDRQty = pendDRQty;
}
public double getPendIndQty()
{
return pendIndQty;
}
public void setPendIndQty(double pendIndQty)
{
this.pendIndQty = pendIndQty;
}
public double getPendPOQty()
{
return pendPOQty;
}
public void setPendPOQty(double pendPOQty)
{
this.pendPOQty = pendPOQty;
}
public String getTranId()
{
return tranId;
}
public void setTranId(String tranId)
{
this.tranId = tranId;
}
public String getTranSer()
{
return tranSer;
}
public void setTranSer(String tranSer)
{
this.tranSer = tranSer;
}
}
......@@ -175,6 +175,8 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
String orderType=""; // added by cpatil on 02/07/14
long startTime = 0;
String itemCodeOnlyList=""; //added cpatil on 20/11/14
//String IPD_INDEPENDENT = "",IPD_INDENT = "",IPD_MPS_ORDER = "",IPD_DIST = ""; //cpatil on 15/01/14
/*
* public void ejbCreate() throws RemoteException, CreateException { try {
......@@ -302,7 +304,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
itemCodeList = genericUtility.getColumnValue("item_code_list", dom); // added by cpatil
siteItemList = genericUtility.getColumnValue("site_item_list", dom); //added by chandrashekar
siteList = genericUtility.getColumnValue("site_list", dom); //added by chandrashekar
itemCodeOnlyList = genericUtility.getColumnValue("item_code_only_list", dom); // added by cpatil
//cpatil-25/08/14-System.out.println("siteList@@@@@@"+siteList);
String isBomReplaceStr = genericUtility.getColumnValue("isBomReplace", dom); // added by cpatil on 17/05/14
......@@ -1407,14 +1409,20 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
if ((CommonConstants.DB_NAME).equalsIgnoreCase("db2")) /// added for db2 on 17/02/14
{
//subQuery=" AND C.ITEM_CODE IN ( SELECT ITEM_CODE__ORD FROM SORDDET WHERE CONCAT (SALE_ORDER,ITEM_CODE) IN("+itemCodeList+") ) ";
subQuery=" AND C.ITEM_CODE IN ( SELECT ITEM_CODE__ORD FROM SORDDET WHERE CONCAT (SALE_ORDER,ITEM_CODE) IN("+itemCodeList+") " +
" UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE CONCAT (TRAN_ID,ITEM_CODE) IN("+itemCodeList+") ) ";
//subQuery=" AND C.ITEM_CODE IN ( SELECT ITEM_CODE__ORD FROM SORDDET WHERE CONCAT (SALE_ORDER,ITEM_CODE) IN("+itemCodeList+") " +
// " UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE CONCAT (TRAN_ID,ITEM_CODE) IN("+itemCodeList+") ) ";
subQuery=" and ( C.ITEM_CODE IN ("+itemCodeOnlyList+ ") OR C.ITEM_CODE IN( SELECT ITEM_CODE FROM MPS_ORDER WHERE CONCAT (TRAN_ID,ITEM_CODE) IN("+itemCodeList+") ) ) ";
// subQuery=" and C.ITEM_CODE IN ( select "+itemCodeOnlyList+" from dual " +
//" UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE CONCAT (TRAN_ID,ITEM_CODE) IN("+itemCodeList+") ) ";
}
else
{
// subQuery=" AND C.ITEM_CODE IN(SELECT ITEM_CODE__ORD FROM SORDER WHERE SALE_ORDER IN("+sorderList+") ";
subQuery=" AND C.ITEM_CODE IN(SELECT ITEM_CODE__ORD FROM SORDDET WHERE SALE_ORDER||ITEM_CODE IN("+itemCodeList+")" +
" UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE TRAN_ID||ITEM_CODE IN("+itemCodeList+") )";
//subQuery=" AND C.ITEM_CODE IN(SELECT ITEM_CODE__ORD FROM SORDDET WHERE SALE_ORDER||ITEM_CODE IN("+itemCodeList+")" +
// " UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE TRAN_ID||ITEM_CODE IN("+itemCodeList+") )";
// subQuery=" and C.ITEM_CODE IN ("+itemCodeOnlyList+ ") OR C.ITEM_CODE IN( SELECT ITEM_CODE FROM MPS_ORDER WHERE CONCAT (TRAN_ID,ITEM_CODE) IN("+itemCodeList+") ) ";
subQuery=" and ( C.ITEM_CODE IN ( select "+itemCodeOnlyList+" from dual " +
" UNION SELECT ITEM_CODE FROM MPS_ORDER WHERE ( TRAN_ID||ITEM_CODE) IN ("+itemCodeList+") ) ) ";
}
}else if(isRequirement)
{
......@@ -1463,7 +1471,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
}
//cpatil-25/08/14-System.out.println("@@@@@ sql :["+sql+"]");
System.out.println("@@@@@ sql :["+sql+"]");
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCodeFrom);
pstmt.setString(2, itemCodeTo);
......@@ -3175,6 +3183,13 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
tempList = null;
}
//cpatil-25/08/14-System.out.println("12/06/14 populateADPList madeToOrder [" + madeToOrder + "] adpeList.size() [" + adpeList.size() + "]");
if(isDetailReq)
{
System.out.println("@@@@cpatil adpList["+adpeList.size()+"]");
populateDemandSupply(adpeList);
}
else
{
for (int ctr = 0; ctr < adpeList.size(); ctr++)
{
......@@ -3206,13 +3221,14 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
//System.out.println("Detail level Demand Supply set in ADPElement---"+adpElement.getDetMap());
}
} //end if
} catch (Exception e)
{
throw (e);
}
}
private ADPElement populateDemandSupply(ADPElement adpElement) throws Exception
{
double demand = 0;
......@@ -3594,6 +3610,774 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
// end return commented & changed by sabyasachi 25-03-2011
}
private void populateDemandSupply(ArrayList adpList) throws Exception
{
double demand = 0;
double supply = 0;
java.sql.Timestamp dueDate = null;
String itemCode = null;
String siteCode = null;
// 12/04/10 manoharan MF90BHU001
double stockQty = 0;
double othSupply = 0;
// end 12/04/10 manoharan MF90BHU001
// Variables declared by gulzar on 4/18/2012
double pendPOQty = 0;
double pendDOQty = 0;
double pendIndQty = 0;
double pendDRQty = 0;
// End changes by gulzar on 4/18/2012
// Variable Declared by Sachin on 24/6/2013
double availStk = 0;
double quarntineStk = 0;
// End Variable Declared by Sachin on 24/6/2013
Statement stmt = null;
ResultSet rs = null;
errString = "";
String adpQuery = null;
PreparedStatement pstmt = null;
String saleOrder = null;
String lineNo = null;
//Added By Manoj dtd 31/10/2013
String tranId="";
String tranSer="";
double prevdemand=0;
double prevsupply=0;
double prevstockQty=0;
double prevothSupply=0;
double prevpendPOQty=0;
double prevpendDOQty=0;
double prevpendIndQty=0;
double prevpendDRQty=0;
double qtStk=0;//added by Chandrashekar 0n 11-08-14
String siteCodeAdp="",tempitemCodeList="";
try
{
System.out.println("@@@@cpatil adpList["+adpList.size()+"]");
for ( int ctr1 = 0; ctr1 < adpList.size(); ctr1++ ) //Loop for each node of current detail
{
ADPElement adpElement = (ADPElement) adpeList.get(ctr1);
itemCode = adpElement.getItemCode();
siteCodeAdp = adpElement.getSiteCode();
System.out.println("@@@cpatil_sale_order==["+saleOrder+"]itemCode==["+itemCode+"]siteCodeAdp["+siteCodeAdp+"]");
System.out.println("ctr1=="+ctr1);
if(ctr1 > 0)
{
tempitemCodeList = tempitemCodeList + ",'"+siteCodeAdp+itemCode+"'" ;
}
else
{
//tempitemCodeList = "'"+siteCode+itemCode+"'" ;
tempitemCodeList = "'"+siteCodeAdp+itemCode+"'" ;
}
}
System.out.println("@@@@@@@@ before tempitemCodeList==["+tempitemCodeList+"]");
tempitemCodeList = tempitemCodeList.substring(1, tempitemCodeList.length()-1);
System.out.println("@@@@@@@@ after tempitemCodeList==["+tempitemCodeList+"]");
//itemCode = adpElement.getItemCode();
//siteCode = adpElement.getSiteCode();
// 01/04/11 manoharan if made to order is selected and item is of
// made to order
// don't process here
//cpatil-25/08/14-System.out.println("siteCode----"+siteCode+"itemCode----"+itemCode);
//cpatil-25/08/14-System.out.println("madeToOrder---"+madeToOrder+"----adpElement.getMfgType()----"+adpElement.getMfgType());
/* Commented by Manoj dtd 30/12/2013 calling same method for all items
if ("0".equals(madeToOrder) && "O".equals(adpElement.getMfgType()))
{
return adpElement;
}*/
// end 01/04/11 manoharan
// //cpatil-25/08/14-System.out.println("commonConstants.DB_NAME "+CommonConstants.DB_NAME);
// 14-02-2007 manoharan
String sqlFileName = null;
System.out.println("matPlan---"+matPlan+"----mfgPlan----"+mfgPlan);
System.out.println("isDetailReq2------"+isDetailReq);
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(":", ".");
/*
* // 01-10-2007 manoharan String strRunDate =
* runDate.toString(); strRunDate =
* strRunDate.replaceAll(" ","-"); strRunDate =
* strRunDate.replaceAll(":","."); // end 01-10-2007 manoharan
*/
adpQuery = adpQueryOriginal;
// System.out.println("Afetr Reading File adpQuery..");
//adpQuery = adpQuery.replaceAll("@sitecode@", siteCode);
adpQuery = adpQuery.replaceAll("@itemcode@", tempitemCodeList);
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);
// 01-10-2007 manoharan
adpQuery = adpQuery.replaceAll("@rundate@", runDateString);
// end 01-10-2007 manoharan
} else if ((CommonConstants.DB_NAME).equalsIgnoreCase("oracle"))
{
// 14-02-2007 manoharan
// String adpQueryOriginal = readFile(CommonConstants.JBOSSHOME
// + File.separator +"sql" + File.separator +
// "demandsupplyOracle.sql");
String adpQueryOriginal = readFile(sqlFileName + "Oracle.sql");
// end 14-02-2007 manoharan
adpQuery = adpQueryOriginal;
// System.out.println("Replacing Values.in SQL.....");
//adpQuery = adpQuery.replaceAll("@sitecode@", siteCode);
adpQuery = adpQuery.replaceAll("@itemcode@", tempitemCodeList );
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);
// end 01-10-2007 manoharan
// System.out.println("Replaced Values.in SQL.....");
}
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);
pstmt = conn.prepareStatement(adpQuery);
rs = pstmt.executeQuery();
// System.out.println("Query Executed for item : " + itemCode);
String rsItemCode = "", adpItemcode = "",rsSiteCode="";
HashMap<String, ArrayList<DataBean>> dataMap = new HashMap<String, ArrayList<DataBean>>();
// HashMap<K, V>
while(rs.next())
{
DataBean dataBeanObject = new DataBean();
rsItemCode = rs.getString(1);
rsSiteCode = rs.getString(13);
//rsSiteCode = siteCode;
dataBeanObject.setItemCode(rs.getString(1));
dataBeanObject.setDueDate(rs.getTimestamp(2));
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");
}
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);
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("adpList.size["+adpList.size()+"]adpList["+adpList+"]");
for( int ctr=0; ctr < adpList.size() ; ctr++ )
{
ADPElement adpElement = (ADPElement) adpeList.get(ctr);
ArrayList adpElementListValueAll = new ArrayList();
itemCode = adpElement.getItemCode();
siteCodeAdp = adpElement.getSiteCode();
System.out.println("dataMap["+dataMap+"]");
if( dataMap != null && dataMap.containsKey(siteCodeAdp+itemCode))
{
adpElementListValueAll = dataMap.get(siteCodeAdp+itemCode);
}
System.out.println("@@@@@ value get from map.....");
System.out.println("adpElementListValueAll.size["+adpElementListValueAll.size()+"]");
for( int ctrList =0; ctrList < adpElementListValueAll.size(); ctrList++)
{
ArrayList adpElementListValue = new ArrayList();
DataBean dataBeanTemp = (DataBean) adpElementListValueAll.get(ctrList);
System.out.println("@@@cpatiladpElementListValue["+adpElementListValue+"]");
//dueDate = (Timestamp)adpElementListValue.get(1);
dueDate = (Timestamp) dataBeanTemp.getDueDate();
if("0".equals(madeToOrder) && "O".equals(adpElement.getMfgType()))
{
demand=0;
}
else
{
//demand = (Double) adpElementListValue.get(2);
demand = (Double) dataBeanTemp.getDemand();
}
//adpElement.setDemand(dueDate, demand, " ", " ");
adpElement.setDemand(dueDate, demand, " ", " ");
//adpElement.setSupply(dueDate, supply);
adpElement.setSupply(dueDate, (Double) dataBeanTemp.getSupply());
//adpElement.setStockQty(dueDate, stockQty);
adpElement.setStockQty(dueDate, (Double) dataBeanTemp.getStockQty());
//adpElement.setOthSupply(dueDate, othSupply);
adpElement.setOthSupply(dueDate, (Double) dataBeanTemp.getOthSupply());
//adpElement.setPendingPO(dueDate, pendPOQty);
adpElement.setPendingPO(dueDate, (Double) dataBeanTemp.getPendPOQty());
//adpElement.setPendingDO(dueDate, pendDOQty);
adpElement.setPendingDO(dueDate, (Double) dataBeanTemp.getPendPOQty());
//adpElement.setPendingIndent(dueDate, pendIndQty);
adpElement.setPendingIndent(dueDate, (Double) dataBeanTemp.getPendIndQty());
//adpElement.setPendingDR(dueDate, pendDRQty);
adpElement.setPendingDR(dueDate, (Double) dataBeanTemp.getPendDRQty());
if(isDetailReq)
{
ADPElement detADPElement=new ADPElement();
detADPElement.setDemand(dueDate, demand, " ", " ");
detADPElement.setSupply(dueDate, supply);
detADPElement.setStockQty(dueDate, dataBeanTemp.getStockQty());
detADPElement.setOthSupply(dueDate, dataBeanTemp.getOthSupply());
detADPElement.setPendingPO(dueDate, dataBeanTemp.getPendPOQty());
detADPElement.setPendingDO(dueDate, dataBeanTemp.getPendDOQty());
detADPElement.setPendingIndent(dueDate, dataBeanTemp.getPendIndQty());
detADPElement.setPendingDR(dueDate, dataBeanTemp.getPendDRQty());
//cpatil-25/08/14-System.out.println("Setting SaleOrder in Detail record---"+adpElement.getSaleOrder());
//cpatil-25/08/14-System.out.println("Setting Line No in Detail record---"+adpElement.getLineNo());
detADPElement.setSaleOrder(adpElement.getSaleOrder());
detADPElement.setLineNo(adpElement.getLineNo());
//cpatil-25/08/14-System.out.println("detADPElement.getPendingPO()----"+detADPElement.getPendingPO());
HashMap<String, ADPElement> detMap=new HashMap<String, ADPElement>();
System.out.println("tranId#tranSer----"+tranId+"#"+tranSer);
detMap.put(tranId+"#"+tranSer, detADPElement);
ArrayList<HashMap<String, ADPElement>> alist=adpElement.getDetList();
//cpatil-25/08/14-System.out.println("alist.size()-1---"+alist.size());
if(detMap.size()>0)
{
alist.add( detMap);
}
//adpElement.setDetMap(detMap);
adpElement.setDetList(alist);
detMap=null;
detADPElement=null;
alist=null;
}
}
System.out.println(adpElement.getSupply());
if (demand != 0 || supply != 0)
{
if (adpElement.getSuppSour().equals("M"))
System.out.println("Site Code : " + siteCode + " Item Code : " + itemCode + " Due Date : " + dueDate + " Demand : " + demand + " supply : " + supply);
}
System.out.println("@@@@@ in ctr["+ctr+"]adpElement["+adpElement+"]");
adpeList.set(ctr, adpElement);
}
System.out.println("@@@@@ adpeList.size()["+adpeList.size()+"]");
} catch (SQLException se)
{
System.out.println("SQLException :RunMRPPrcEJB : populateDemandSupply(ADPElement).." + se.getMessage());
System.out.println(adpQuery);
se.printStackTrace();
errString = se.getMessage();
throw new ITMException(se);
} catch (Exception e)
{
System.out.println("Exception :RunMRPPrcEJB : populateDemandSupply(ADPElement):...." + e.getMessage() + ":");
this.errString = genericUtility.createErrorString(e);
e.printStackTrace();
errString = e.getMessage();
throw new ITMException(e);
} finally
{
if (pstmt != null)
{
pstmt = null;
}
if (rs != null)
{
rs = null;
}
this.fw1.flush();// Added by jiten 10/11/06
}
}
private void populateDemandSupply1(ArrayList adpList) throws Exception //added by cpatil on 20/11/14
{
double demand = 0;
double supply = 0;
java.sql.Timestamp dueDate = null;
String itemCode = null;
String siteCode = null;
double stockQty = 0;
double othSupply = 0;
double pendPOQty = 0;
double pendDOQty = 0;
double pendIndQty = 0;
double pendDRQty = 0;
double availStk = 0;
double quarntineStk = 0;
Statement stmt = null;
ResultSet rs = null;
errString = "";
String adpQuery = null;
PreparedStatement pstmt = null;
String saleOrder = null;
String lineNo = null;
String tranId="";
String tranSer="";
double prevdemand=0;
double prevsupply=0;
double prevstockQty=0;
double prevothSupply=0;
double prevpendPOQty=0;
double prevpendDOQty=0;
double prevpendIndQty=0;
double prevpendDRQty=0;
double qtStk=0;
String tempitemCodeList="",siteCodeAdp="";
try
{
System.out.println("@@@@cpatil adpList["+adpList.size()+"]");
for ( int ctr1 = 0; ctr1 < adpList.size(); ctr1++ ) //Loop for each node of current detail
{
ADPElement adpElement = (ADPElement) adpeList.get(ctr1);
itemCode = adpElement.getItemCode();
siteCodeAdp = adpElement.getSiteCode();
System.out.println("@@@cpatil_sale_order==["+saleOrder+"]itemCode==["+itemCode+"]siteCodeAdp["+siteCodeAdp+"]");
System.out.println("ctr1=="+ctr1);
if(ctr1 > 0)
{
tempitemCodeList = tempitemCodeList + ",'"+siteCodeAdp+itemCode+"'" ;
}
else
{
//tempitemCodeList = "'"+siteCode+itemCode+"'" ;
tempitemCodeList = "'"+siteCodeAdp+itemCode+"'" ;
}
}
System.out.println("@@@@@@@@ before tempitemCodeList==["+tempitemCodeList+"]");
tempitemCodeList = tempitemCodeList.substring(1, tempitemCodeList.length()-1);
System.out.println("@@@@@@@@ after tempitemCodeList==["+tempitemCodeList+"]");
String sqlFileName = null;
System.out.println("matPlan---"+matPlan+"----mfgPlan----"+mfgPlan);
System.out.println("isDetailReq2------"+isDetailReq);
if (matPlan.equalsIgnoreCase("N") && mfgPlan.equalsIgnoreCase("N"))
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplyforecastonly";
}
else if (matPlan.equalsIgnoreCase("Y") && mfgPlan.equalsIgnoreCase("N"))
{
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
{
sqlFileName = CommonConstants.JBOSSHOME + File.separator + "sql" + File.separator + "demandsupplyDetail";
}
//cpatil-25/08/14-System.out.println("sqlFileName---"+sqlFileName);
if ((CommonConstants.DB_NAME).equalsIgnoreCase("db2"))
{
String adpQueryOriginal = readFile(sqlFileName + "DB2.sql");
String strDateFrom = dateFrom.toString();
strDateFrom = strDateFrom.replaceAll(" ", "-");
strDateFrom = strDateFrom.replaceAll(":", ".");
String strDateTo = dateTo.toString();
strDateTo = strDateTo.replaceAll(" ", "-");
strDateTo = strDateTo.replaceAll(":", ".");
adpQuery = adpQueryOriginal;
// System.out.println("Afetr Reading File adpQuery..");
//adpQuery = adpQuery.replaceAll("@sitecode@", siteCode);
adpQuery = adpQuery.replaceAll("@itemcode@", tempitemCodeList);
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);
// 01-10-2007 manoharan
adpQuery = adpQuery.replaceAll("@rundate@", runDateString);
// end 01-10-2007 manoharan
} else if ((CommonConstants.DB_NAME).equalsIgnoreCase("oracle"))
{
String adpQueryOriginal = readFile(sqlFileName + "Oracle.sql");
// end 14-02-2007 manoharan
adpQuery = adpQueryOriginal;
// System.out.println("Replacing Values.in SQL.....");
//adpQuery = adpQuery.replaceAll("@sitecode@", siteCode);
adpQuery = adpQuery.replaceAll("@itemcode@", tempitemCodeList);
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);
// end 01-10-2007 manoharan
// System.out.println("Replaced Values.in SQL.....");
}
FileOutputStream fout = null;
BufferedWriter bw = null;
fout = new FileOutputStream("demandsupply.sql");
bw = new BufferedWriter(new OutputStreamWriter(fout));
bw.write(adpQuery);
bw.close();
fout.close();
System.out.println("@@@@@@@@ cpatil adpQuery["+adpQuery+"]");
// stmt = conn.createStatement();
// System.out.println("Executing Query After Replacement.....");
// rs = stmt.executeQuery(adpQuery);
pstmt = conn.prepareStatement(adpQuery);
rs = pstmt.executeQuery();
HashMap adpElementMap = new HashMap();
// System.out.println("Query Executed for item : " + itemCode);
String rsItemCode = "", adpItemcode = "",rsSiteCode="";
int updctr=0;
boolean updFlag=false;
while (rs.next())
{
ArrayList adpElementList = new ArrayList();
rsItemCode = rs.getString(1);// Added by JIten 02/11/06 as per
adpElementList.add(rs.getString(1));
dueDate = rs.getTimestamp(2);
if (dueDate.compareTo(dateFrom) < 0)
{
dueDate = dateFrom;
}
adpElementList.add(dueDate);
//demand = rs.getDouble(3);
adpElementList.add(rs.getDouble(3));
//supply = rs.getDouble(4);
adpElementList.add(rs.getDouble(4));
//stockQty = rs.getDouble(5);
adpElementList.add(rs.getDouble(5));
//othSupply = rs.getDouble(6);
adpElementList.add(rs.getDouble(6));
//pendPOQty = rs.getDouble(7);
adpElementList.add(rs.getDouble(7));
//pendDOQty = rs.getDouble(8);
adpElementList.add(rs.getDouble(8));
//pendIndQty = rs.getDouble(9);
adpElementList.add(rs.getDouble(9));
//pendDRQty = rs.getDouble(10);
adpElementList.add(rs.getDouble(10));
if(isDetailReq)
{
//tranId=rs.getString("tran_id");
adpElementList.add(rs.getString("tran_id"));
//tranSer=rs.getString("tran_ser");
adpElementList.add(rs.getString("tran_ser"));
}
if( adpElementMap.containsKey(siteCodeAdp+rsItemCode) )
{
ArrayList tempAdpElementList = (ArrayList) adpElementMap.get(siteCodeAdp+rsItemCode);
//tempAdpElementList.add(adpElementList);
//adpElementMap.put(siteCodeAdp+rsItemCode,tempAdpElementList);
adpElementMap.put(siteCodeAdp+rsItemCode,adpElementList);
}
else
{
ArrayList tempAdpElementList = new ArrayList();
//tempAdpElementList.add(adpElementList);
//adpElementMap.put(siteCodeAdp+rsItemCode, tempAdpElementList);
adpElementMap.put(siteCodeAdp+rsItemCode, adpElementList);
}
}
System.out.println("@@@cpatiladpElementMap["+adpElementMap+"]");
System.out.println("@@@cpatiladpList.size()["+adpList.size()+"]");
for( int ctr=0; ctr < adpList.size() ; ctr++ )
{
ADPElement adpElement = (ADPElement) adpeList.get(ctr);
ArrayList adpElementListValueAll = new ArrayList();
itemCode = adpElement.getItemCode();
siteCodeAdp = adpElement.getSiteCode();
ArrayList adpElementListValue = new ArrayList();
adpElementListValue = (ArrayList) adpElementMap.get(siteCodeAdp+rsItemCode);
//adpElementListValueAll = (ArrayList) adpElementMap.get(siteCodeAdp+rsItemCode);
//System.out.println("@@@cpatilitemCode["+itemCode+"]siteCodeAdp["+siteCodeAdp+"]adpElementListValue["+adpElementListValue+"]");
//ADPElement adpElement = new ADPElement();
System.out.println("@@@cpatil adpElementListValueAll.size()["+ adpElementListValueAll.size()+"]");
//for( int ctrList=0; ctrList < adpElementListValueAll.size(); ctrList++ )
{
// ArrayList adpElementListValue = new ArrayList();
// adpElementListValue = (ArrayList) adpElementListValueAll.get(ctr);
System.out.println("@@@cpatiladpElementListValue["+adpElementListValue+"]");
dueDate = (Timestamp)adpElementListValue.get(1);
if("0".equals(madeToOrder) && "O".equals(adpElement.getMfgType()))
{
demand=0;
}
else
{
demand = (Double) adpElementListValue.get(2);
}
//adpElement.setDemand(dueDate, demand, " ", " ");
adpElement.setDemand(dueDate, demand, " ", " ");
//adpElement.setSupply(dueDate, supply);
adpElement.setSupply(dueDate, (Double) adpElementListValue.get(3));
//adpElement.setStockQty(dueDate, stockQty);
adpElement.setStockQty(dueDate, (Double) adpElementListValue.get(4));
//adpElement.setOthSupply(dueDate, othSupply);
adpElement.setOthSupply(dueDate, (Double) adpElementListValue.get(5));
//adpElement.setPendingPO(dueDate, pendPOQty);
adpElement.setPendingPO(dueDate, (Double) adpElementListValue.get(6));
//adpElement.setPendingDO(dueDate, pendDOQty);
adpElement.setPendingDO(dueDate, (Double) adpElementListValue.get(7));
//adpElement.setPendingIndent(dueDate, pendIndQty);
adpElement.setPendingIndent(dueDate, (Double) adpElementListValue.get(8));
//adpElement.setPendingDR(dueDate, pendDRQty);
adpElement.setPendingDR(dueDate, (Double) adpElementListValue.get(9));
//delete
//if (rsItemCode != null && rsItemCode.trim().equalsIgnoreCase(itemCode.trim()))
//{
System.out.println("dueDate---demand---supply"+dueDate+"---"+demand+"---"+supply);
if(isDetailReq)
{
ADPElement detADPElement=new ADPElement();
detADPElement.setDemand(dueDate, demand, " ", " ");
//detADPElement.setSupply(dueDate, supply);
detADPElement.setSupply(dueDate, (Double) adpElementListValue.get(3));
//detADPElement.setStockQty(dueDate, stockQty);
detADPElement.setStockQty(dueDate, (Double) adpElementListValue.get(4));
//detADPElement.setOthSupply(dueDate, othSupply);
detADPElement.setOthSupply(dueDate, (Double) adpElementListValue.get(5));
//detADPElement.setPendingPO(dueDate, pendPOQty);
detADPElement.setPendingPO(dueDate, (Double) adpElementListValue.get(6));
//detADPElement.setPendingDO(dueDate, pendDOQty);
detADPElement.setPendingDO(dueDate, (Double) adpElementListValue.get(7));
//detADPElement.setPendingIndent(dueDate, pendIndQty);
detADPElement.setPendingIndent(dueDate, (Double) adpElementListValue.get(8));
//detADPElement.setPendingDR(dueDate, pendDRQty);
detADPElement.setPendingDR(dueDate, (Double) adpElementListValue.get(9));
detADPElement.setSaleOrder(adpElement.getSaleOrder());
detADPElement.setLineNo(adpElement.getLineNo());
HashMap<String, ADPElement> detMap=new HashMap<String, ADPElement>();
tranId = ( String ) adpElementListValue.get(10) ;
tranSer = ( String ) adpElementListValue.get(11) ;
System.out.println("tranId#tranSer----"+tranId+"#"+tranSer);
detMap.put(tranId+"#"+tranSer, detADPElement);
ArrayList<HashMap<String, ADPElement>> alist=adpElement.getDetList();
//cpatil-25/08/14-System.out.println("alist.size()-1---"+alist.size());
if(detMap.size()>0)
{
alist.add( detMap);
}
adpElement.setDetList(alist);
detMap=null;
detADPElement=null;
alist=null;
}
//System.out.println("@@@@@ out updctr["+updctr+"]updFlag["+updFlag+"]");
//if( updFlag == true)
/*
else
{
//cpatil-25/08/14-System.out.println("Site Code :: " + siteCode + " rsItemCode :: " + rsItemCode + " Item Code :: " + itemCode);
int ctr = indexOfADPElement(siteCode, rsItemCode, " ", " ");
// System.out.println("AdpList : "+adpeList.size()+"Index ctr :: "+ctr);//Added
// by Jiten 09/11/06 Sun
if (ctr > 0)
{// if condition added by jiten as per Manoharan Sir
// 10/11/06
ADPElement tempADPElement = (ADPElement) adpeList.get(ctr);
tempADPElement.setDemand(dueDate, demand, " ", " ");
tempADPElement.setSupply(dueDate, supply);
adpeList.set(ctr, tempADPElement);
} else if (ctr == -1)
{// Else if condition added by jiten 10/11/06 as per Tarun
// Bhai to write for skipped item
this.fw1.write(siteCode + " " + itemCode + " " + rsItemCode + "\r\n");
}
}
// End addding
*/
System.out.println(adpElement.getSupply());
if (demand != 0 || supply != 0)
{
if (adpElement.getSuppSour().equals("M"))
// System.out.println("adpQuery ::"+adpQuery);
System.out.println("Site Code : " + siteCode + " Item Code : " + itemCode + " Due Date : " + dueDate + " Demand : " + demand + " supply : " + supply);
}
}
//System.out.println("@@@@@ out updctr["+updctr+"]updFlag["+updFlag+"]");
//if( updFlag == true)
{
System.out.println("@@@@@ in ctr["+ctr+"]adpElement["+adpElement+"]");
adpeList.set(ctr, adpElement);
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
} catch (SQLException se)
{
System.out.println("SQLException :RunMRPPrcEJB : populateDemandSupply(ADPElement).." + se.getMessage());
System.out.println(adpQuery);
se.printStackTrace();
errString = se.getMessage();
throw new ITMException(se);
} catch (Exception e)
{
System.out.println("Exception :RunMRPPrcEJB : populateDemandSupply(ADPElement):...." + e.getMessage() + ":");
this.errString = genericUtility.createErrorString(e);
e.printStackTrace();
errString = e.getMessage();
throw new ITMException(e);
} finally
{
if (pstmt != null)
{
pstmt = null;
}
if (rs != null)
{
rs = null;
}
this.fw1.flush();// Added by jiten 10/11/06
}
}
// //////////////////////////////////////////////////////////////////////////
private void populateMTODemandSupply(String siteCode, String itemCode, ADPElement adpElement) throws Exception
......@@ -3770,7 +4554,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
}
}
//End Added by chandrashekar on 09-07-2014
*/ //adpElement.setSaleOrder(saleOrder);
*/ //adpElement.setSaleOrder(saleOrder);
//adpElement.setLineNo(lineNo);
// cpatil end
......@@ -8412,7 +9196,7 @@ public class RunMRPPrc extends ProcessEJB implements RunMRPPrcLocal, RunMRPPrcRe
System.out.println("Printing valueXmlString----2---" + valueXmlString);
System.out.println("Printing context-------" + context);
// context=2;
//if (context != null && context.trim().length() > 0 && (context.equals("2") ||context.equals("3"))) //Commented by Manoj dtd 06/06/2014 to check on boolean value
//if (context != null && context.trim().length() > 0 && (context.equals("2") ||context.equals("3"))) //Commented by Manoj dtd 06/06/2014 to check on boolean value
//cpatil-25/08/14-System.out.println("isWizard-------"+isWizard);
if(isWizard)
......
......@@ -288,6 +288,7 @@ public class RunMRPWiz extends ValidatorEJB implements RunMRPWizLocal, RunMRPWiz
String orderType="";
java.sql.Date orderDueDate=null;
String itemCodeOnlyList=""; // added 20/11/14 by cpatil
try
{
......@@ -523,10 +524,17 @@ public class RunMRPWiz extends ValidatorEJB implements RunMRPWizLocal, RunMRPWiz
System.out.println("sale_order=="+saleOrder+"itemCode=="+itemCode);
System.out.println("ctr1=="+ctr1);
if(ctr1 > 0)
{
itemCodeList = itemCodeList + ",'"+saleOrder+itemCode+"'" ;
itemCodeOnlyList = itemCodeOnlyList + ",'"+itemCode+"'" ;
}
else
{
itemCodeList = "'"+saleOrder+itemCode+"'" ;
itemCodeOnlyList = "'"+itemCode+"'" ;
}
System.out.println("itemCodeList=="+itemCodeList);
System.out.println("itemCodeOnlyList=="+itemCodeOnlyList);
orderType= checkNull(genericUtility.getColumnValueFromNode( "order_type", detail2List.item(ctr1) ));
System.out.println("inside for orderType["+orderType+"]");
......@@ -558,6 +566,7 @@ public class RunMRPWiz extends ValidatorEJB implements RunMRPWizLocal, RunMRPWiz
argData.append("<date_from>").append(genericUtility.getColumnValue("date_from",dom1)).append("</date_from>\r\n");
argData.append("<date_to>").append(genericUtility.getColumnValue("date_to",dom1)).append("</date_to>\r\n");
argData.append("<item_code_list>").append(itemCodeList).append("</item_code_list>\r\n");
argData.append("<item_code_only_list>").append(itemCodeOnlyList).append("</item_code_only_list>\r\n");
argData.append("<site_code__from>").append(siteCodeFr).append("</site_code__from>\r\n");
argData.append("<site_code__to>").append(siteCodeTo).append("</site_code__to\r\n>");
argData.append("<item_code__from>").append("00").append("</item_code__from>\r\n");
......
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