Commit 8d0c97ca authored by sshinde's avatar sshinde

Add new new functionallity on dated 28062013


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93300 ce508802-f39f-4f6c-b175-0d175dae99d5
parent c50bd4a1
...@@ -13,29 +13,29 @@ import ibase.webitm.ejb.*; ...@@ -13,29 +13,29 @@ import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility; import ibase.webitm.utility.GenericUtility;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.ejb.Stateless; import javax.ejb.Stateless;
@Stateless @Stateless
public class RequirementIC extends ValidatorEJB implements RequirementICLocal, RequirementICRemote // SessionBean
public class RequirementIC extends ValidatorEJB implements RequirementICLocal,RequirementICRemote //SessionBean
{ {
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
SimpleDateFormat simpleDateFormat = null; SimpleDateFormat simpleDateFormat = null;
public String wfValData() throws RemoteException,ITMException public String wfValData() throws RemoteException, ITMException
{ {
System.out.println("wfValData()..."); System.out.println("wfValData()...");
return ""; return "";
} }
// Item Change // Item Change
public String itemChanged() throws RemoteException,ITMException public String itemChanged() throws RemoteException, ITMException
{ {
System.out.println("itemChanged Called..."); System.out.println("itemChanged Called...");
return ""; return "";
} }
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{ {
Document dom = null; Document dom = null;
...@@ -45,42 +45,43 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -45,42 +45,43 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
try try
{ {
System.out.println("xmlString.........::"+xmlString); System.out.println("xmlString.........::" + xmlString);
System.out.println("xmlString1.........::"+xmlString1); System.out.println("xmlString1.........::" + xmlString1);
System.out.println("xmlString2.........::"+xmlString2); System.out.println("xmlString2.........::" + xmlString2);
if (xmlString != null && xmlString.trim().length()!=0) if (xmlString != null && xmlString.trim().length() != 0)
{ {
dom = genericUtility.parseString(xmlString); dom = genericUtility.parseString(xmlString);
} }
if (xmlString1 != null && xmlString1.trim().length()!=0) if (xmlString1 != null && xmlString1.trim().length() != 0)
{ {
dom1 = genericUtility.parseString(xmlString1); dom1 = genericUtility.parseString(xmlString1);
} }
if (xmlString2 != null && xmlString2.trim().length()!=0) if (xmlString2 != null && xmlString2.trim().length() != 0)
{ {
dom2 = genericUtility.parseString(xmlString2); dom2 = genericUtility.parseString(xmlString2);
} }
errString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams); errString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
} } catch (Exception e)
catch (Exception e)
{ {
System.out.println ("Exception :ProcessControlEJB :itemChanged(String,String):" + e.getMessage() + ":"); System.out.println("Exception :ProcessControlEJB :itemChanged(String,String):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e); errString = genericUtility.createErrorString(e);
throw new ITMException(e); throw new ITMException(e);
} }
System.out.println ("returning from ProcessControlEJB itemChanged"); System.out.println("returning from ProcessControlEJB itemChanged");
return errString; return errString;
} }
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{ {
String loginSiteCode = ""; String loginSiteCode = "";
String sql = ""; String sql = "";
String columnValue = ""; String columnValue = "";
String userId = ""; String userId = "";
String errString=""; String errString = "";
Connection conn = null; Connection conn = null;
Statement stmt = null; Statement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int lineNo = 0;
StringBuffer valueXmlString = new StringBuffer(); StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0; int currentFormNo = 0;
...@@ -129,6 +130,9 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -129,6 +130,9 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
double quantity = 0d; double quantity = 0d;
double yieldPerc = 0d; double yieldPerc = 0d;
String winName = ""; // Added by sachin on 26/6/13
double batchReq = 0d;
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
try try
{ {
...@@ -138,380 +142,398 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -138,380 +142,398 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
connDriver = null; connDriver = null;
simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat()); simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode"); userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"); loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat()); SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
columnValue = genericUtility.getColumnValue(currentColumn,dom); columnValue = genericUtility.getColumnValue(currentColumn, dom);
if(objContext != null && objContext.trim().length()>0) if (objContext != null && objContext.trim().length() > 0)
{ {
currentFormNo = Integer.parseInt(objContext); currentFormNo = Integer.parseInt(objContext);
} }
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>"); valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></Header>"); valueXmlString.append(editFlag).append("</editFlag></Header>");
switch (currentFormNo) switch (currentFormNo)
{ {
case 1: case 1:
valueXmlString.append("<Detail1>"); valueXmlString.append("<Detail1>");
if(currentColumn.trim().equals("itm_default")) if (currentColumn.trim().equals("itm_default"))
{
valueXmlString.append("<site_code__fr>").append(loginSiteCode).append("</site_code__fr>");
valueXmlString.append("<site_code__to>").append(loginSiteCode).append("</site_code__to>");
}
valueXmlString.append("</Detail1>");
break;
case 2:
if (currentColumn.trim().equals("itm_default"))
{
int detCnt = 0;
siteCodeFr = genericUtility.getColumnValue("site_code__fr", dom1);
siteCodeTo = genericUtility.getColumnValue("site_code__to", dom1);
/*
* "SELECT A.TRAN_ID, A.SITE_CODE, A.ITEM_CODE, B.DESCR, A.QUANTITY, A.DUE_DATE, A.UNIT, A.YIELD_PERC "
* + "FROM MPS_ORDER A, ITEM B "+
* "WHERE ( A.ITEM_CODE = B.ITEM_CODE (+)) " +
* "AND A.SITE_CODE >= ? AND A.SITE_CODE <= ? "+
* "AND A.STATUS IN ('P','T','M')";
*/
/* Change By Sachin on 26/6/2013 */
selectSql = "SELECT A.SITE_CODE, A.ITEM_CODE, B.DESCR, A.UNIT, C.BATCH_QTY, SUM(A.QUANTITY) AS QUANTITY " + "FROM MPS_ORDER A, ITEM B ,BOM C " + "WHERE ( A.ITEM_CODE = B.ITEM_CODE (+)) " + "AND A.SITE_CODE >= ? AND A.SITE_CODE <=? " + "AND A.STATUS IN ('P','T','M') " + "AND A.BOM_CODE=C.BOM_CODE " + "GROUP BY A.SITE_CODE, A.ITEM_CODE, B.DESCR, A.UNIT, C.BATCH_QTY";
pstmt = conn.prepareStatement(selectSql);
pstmt.setString(1, siteCodeFr);
pstmt.setString(2, siteCodeTo);
rs = pstmt.executeQuery();
while (rs.next())
{ {
valueXmlString.append("<site_code__fr>").append(loginSiteCode).append("</site_code__fr>"); detCnt++;
valueXmlString.append("<site_code__to>").append(loginSiteCode).append("</site_code__to>"); lineNo++;
quantity = rs.getDouble("QUANTITY");
batchQty = rs.getDouble("BATCH_QTY");
batchReq = (quantity / batchQty);
System.out.println(" aFTER CALUCLATION Quantity is =" + quantity + " batch quantity is =" + batchQty + "batch Requirement is =" + batchReq);
/*
* dueDate = rs.getDate("DUE_DATE"); if (dueDate !=
* null) { dueDate1 = sdf.format(dueDate); } else {
* dueDate1 = ""; }
*/
valueXmlString.append("<Detail2 domID='" + lineNo + "' objContext = '" + currentFormNo + "' selected=\"Y\">\r\n");
valueXmlString.append("<attribute selected=\"Y\" updateFlag=\"E\" status=\"O\" pkNames=\"\"/>\r\n");
valueXmlString.append("<site_code>").append("<![CDATA[" + rs.getString("SITE_CODE") + "]]>").append("</site_code>\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[" + rs.getString("ITEM_CODE") + "]]>").append("</item_code>\r\n");
valueXmlString.append("<item_descr protect = '1'>").append("<![CDATA[" + rs.getString("DESCR") + "]]>").append("</item_descr>\r\n");
valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + rs.getString("UNIT") + "]]>").append("</unit>\r\n");
valueXmlString.append("<no_of_batch protect = '1'>").append("<![CDATA[" + batchReq + "]]>").append("</no_of_batch>\r\n");
valueXmlString.append("<quantity>").append("<![CDATA[" + rs.getDouble("QUANTITY") + "]]>").append("</quantity>\r\n");
valueXmlString.append("</Detail2>");
} }
valueXmlString.append("</Detail1>"); rs.close();
break; rs = null;
case 2: pstmt.close();
if(currentColumn.trim().equals("itm_default")) pstmt = null;
if (detCnt == 0)
{ {
int detCnt = 0; // valueXmlString.append("<Detail2>\r\n");
siteCodeFr = genericUtility.getColumnValue("site_code__fr",dom1); valueXmlString.append("<Detail2 domID='" + lineNo + "' objContext = '" + currentFormNo + "' selected=\"Y\">\r\n");
siteCodeTo = genericUtility.getColumnValue("site_code__to",dom1); valueXmlString.append("<attribute selected=\"Y\" updateFlag=\"E\" status=\"O\" pkNames=\"\"/>\r\n");
selectSql = "SELECT A.TRAN_ID, A.SITE_CODE, A.ITEM_CODE, B.DESCR, A.QUANTITY, A.DUE_DATE, A.UNIT, A.YIELD_PERC " + valueXmlString.append("<site_code>").append("").append("</site_code>\r\n");
"FROM MPS_ORDER A, ITEM B "+ valueXmlString.append("<item_code>").append("").append("</item_code>\r\n");
"WHERE ( A.ITEM_CODE = B.ITEM_CODE (+)) " + valueXmlString.append("<item_descr protect = '1'>").append("").append("</item_descr>\r\n");
"AND A.SITE_CODE >= ? AND A.SITE_CODE <= ? "+ valueXmlString.append("<quantity>").append("0").append("</quantity>\r\n");
"AND A.STATUS IN ('P','T','M')"; valueXmlString.append("<no_of_batch protect = '1'>").append("0").append("</no_of_batch>\r\n");
valueXmlString.append("<unit protect = '1'>").append("").append("</unit>\r\n");
pstmt = conn.prepareStatement(selectSql); valueXmlString.append("</Detail2>");
pstmt.setString(1, siteCodeFr);
pstmt.setString(2, siteCodeTo);
rs = pstmt.executeQuery();
while ( rs.next() )
{
detCnt++;
dueDate = rs.getDate("DUE_DATE");
if(dueDate != null)
{
dueDate1 = sdf.format(dueDate);
}
else
{
dueDate1 = "";
}
valueXmlString.append("<Detail2>\r\n");
valueXmlString.append("<site_code>").append("<![CDATA["+rs.getString("SITE_CODE")+"]]>").append("</site_code>\r\n");
valueXmlString.append("<item_code>").append("<![CDATA["+rs.getString("ITEM_CODE")+"]]>").append("</item_code>\r\n");
valueXmlString.append("<item_descr protect = '1'>").append("<![CDATA["+rs.getString("DESCR")+"]]>").append("</item_descr>\r\n");
valueXmlString.append("<quantity>").append("<![CDATA["+rs.getDouble("QUANTITY")+"]]>").append("</quantity>\r\n");
valueXmlString.append("<due_date protect = '1'>").append("<![CDATA["+dueDate1+"]]>").append("</due_date>\r\n");
valueXmlString.append("<unit protect = '1'>").append("<![CDATA["+rs.getString("UNIT")+"]]>").append("</unit>\r\n");
valueXmlString.append("<yield_perc protect = '1'>").append("<![CDATA["+rs.getString("YIELD_PERC")+"]]>").append("</yield_perc>\r\n");
valueXmlString.append("<tran_id protect = '1'>").append("<![CDATA["+rs.getString("TRAN_ID")+"]]>").append("</tran_id>\r\n");
valueXmlString.append("</Detail2>");
}
rs.close(); rs = null;
pstmt.close(); pstmt = null;
if ( detCnt == 0 )
{
valueXmlString.append("<Detail2>\r\n");
valueXmlString.append("<site_code>").append("").append("</site_code>\r\n");
valueXmlString.append("<item_code>").append("").append("</item_code>\r\n");
valueXmlString.append("<item_descr protect = '1'>").append("").append("</item_descr>\r\n");
valueXmlString.append("<quantity>").append("0").append("</quantity>\r\n");
valueXmlString.append("<due_date protect = '1'>").append("").append("</due_date>\r\n");
valueXmlString.append("<unit protect = '1'>").append("").append("</unit>\r\n");
valueXmlString.append("<yield_perc protect = '1'>").append("").append("</yield_perc>\r\n");
valueXmlString.append("<tran_id protect = '1'>").append("").append("</tran_id>\r\n");
valueXmlString.append("</Detail2>");
}
} }
break;
//added by akhilesh
case 3:
if(currentColumn.trim().equals("itm_default"))
{
TreeSet itemTreeSet = new TreeSet(); /* End Change By Sachin on 26/6/2013 */
TreeSet siteTreeSet = new TreeSet(); }
ArrayList tranIdList = new ArrayList(); break;
HashMap mpsDataMap = new HashMap(); // added by akhilesh
case 3:
if (currentColumn.trim().equals("itm_default"))
{
TreeSet itemTreeSet = new TreeSet();
TreeSet siteTreeSet = new TreeSet();
ArrayList tranIdList = new ArrayList();
int newDataCnt = 0; HashMap mpsDataMap = new HashMap();
int noOfSite = 0;
String tranIdDom = "";
String qtyStr = "";
siteCodeFr = genericUtility.getColumnValue("site_code__fr",dom1); int newDataCnt = 0;
siteCodeTo = genericUtility.getColumnValue("site_code__to",dom1); int noOfSite = 0;
String tranIdDom = "";
String qtyStr = "";
insertSql = "INSERT INTO MPS_ORDER(TRAN_ID, ORDER_TYPE, ITEM_CODE, SITE_CODE, QUANTITY, ORD_DATE, DUE_DATE, STATUS, STATUS_DATE, YIELD_PERC, UNIT ) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; siteCodeFr = genericUtility.getColumnValue("site_code__fr", dom1);
siteCodeTo = genericUtility.getColumnValue("site_code__to", dom1);
pstmtIns = conn.prepareStatement(insertSql); insertSql = "INSERT INTO MPS_ORDER(TRAN_ID, ORDER_TYPE, ITEM_CODE, SITE_CODE, QUANTITY, ORD_DATE, DUE_DATE, STATUS, STATUS_DATE, YIELD_PERC, UNIT ) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
selectSql = "SELECT BATCH_QTY FROM BOM WHERE BOM_CODE = (SELECT BOM_CODE FROM SITEITEM WHERE SITE_CODE = ? AND ITEM_CODE = ? )"; pstmtIns = conn.prepareStatement(insertSql);
pstmtSel = conn.prepareStatement(selectSql);
selectSql = "SELECT UNIT,YIELD_PERC FROM ITEM WHERE ITEM_CODE = ? "; selectSql = "SELECT BATCH_QTY FROM BOM WHERE BOM_CODE = (SELECT BOM_CODE FROM SITEITEM WHERE SITE_CODE = ? AND ITEM_CODE = ? )";
pstmtSel1 = conn.prepareStatement(selectSql); pstmtSel = conn.prepareStatement(selectSql);
parentNodeList = dom2.getElementsByTagName("Detail2"); selectSql = "SELECT UNIT,YIELD_PERC FROM ITEM WHERE ITEM_CODE = ? ";
parentNodeListLength = parentNodeList.getLength(); pstmtSel1 = conn.prepareStatement(selectSql);
for(int p = 0; p < parentNodeListLength; p++) parentNodeList = dom2.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
for (int p = 0; p < parentNodeListLength; p++)
{
tranIdDom = "";
itemCode = "";
siteCode = "";
qtyStr = "";
quantity = 0d;
parentNode = parentNodeList.item(p);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (int c = 0; c < childNodeListLength; c++)
{ {
tranIdDom = ""; itemCode = ""; siteCode = ""; qtyStr = ""; quantity = 0d; childNode = childNodeList.item(c);
parentNode = parentNodeList.item(p); childNodeName = childNode.getNodeName();
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); System.out.println("childNodeName :: " + childNodeName);
for(int c = 0; c < childNodeListLength; c++) if (childNodeName.equals("tran_id"))
{ {
childNode = childNodeList.item(c); if (childNode.getFirstChild() != null)
childNodeName = childNode.getNodeName();
System.out.println("childNodeName :: " + childNodeName);
if (childNodeName.equals("tran_id"))
{ {
if (childNode.getFirstChild() != null) tranIdDom = checkNull(childNode.getFirstChild().getNodeValue());
{
tranIdDom = checkNull(childNode.getFirstChild().getNodeValue());
}
} }
else if (childNodeName.equals("item_code")) } else if (childNodeName.equals("item_code"))
{
if (childNode.getFirstChild() != null)
{ {
if (childNode.getFirstChild() != null) itemCode = checkNull(childNode.getFirstChild().getNodeValue());
{
itemCode = checkNull(childNode.getFirstChild().getNodeValue());
}
} }
else if (childNodeName.equals("site_code")) } else if (childNodeName.equals("site_code"))
{
if (childNode.getFirstChild() != null)
{ {
if (childNode.getFirstChild() != null) siteCode = checkNull(childNode.getFirstChild().getNodeValue());
{
siteCode = checkNull(childNode.getFirstChild().getNodeValue());
}
} }
else if (childNodeName.equals("quantity")) } else if (childNodeName.equals("quantity"))
{
if (childNode.getFirstChild() != null)
{ {
if (childNode.getFirstChild() != null) qtyStr = childNode.getFirstChild().getNodeValue();
if (qtyStr != null && qtyStr.trim().length() > 0)
{ {
qtyStr = childNode.getFirstChild().getNodeValue(); try
if ( qtyStr != null && qtyStr.trim().length() > 0 ) {
quantity = Double.parseDouble(qtyStr);
} catch (NumberFormatException n)
{ {
try quantity = 0;
{
quantity = Double.parseDouble(qtyStr);
}
catch (NumberFormatException n)
{
quantity = 0;
}
} }
} }
} }
}//End of Inner for loop
if ( itemCode != null && itemCode.trim().length() > 0 )
{
itemTreeSet.add(itemCode);
}
if ( siteCode != null && siteCode.trim().length() > 0 )
{
siteTreeSet.add(siteCode);
}
if ( tranIdDom == null || tranIdDom.trim().length() == 0 )
{
newDataCnt++;
ArrayList newDataList = new ArrayList();
newDataList.add(siteCode);
newDataList.add(itemCode);
newDataList.add(quantity);
mpsDataMap.put(""+newDataCnt,newDataList);
pstmtSel1.setString(1, itemCode);
rs = pstmtSel1.executeQuery();
if ( rs.next() )
{
unit = rs.getString("UNIT");
yieldPerc = rs.getDouble("YIELD_PERC");
}
pstmtSel1.clearParameters();
rs.close(); rs = null;
pstmtSel.setString(1, siteCode);
pstmtSel.setString(2, itemCode);
rs = pstmtSel.executeQuery();
if ( rs.next() )
{
batchQty = rs.getDouble("BATCH_QTY");
}
pstmtSel.clearParameters();
rs.close(); rs = null;
//quantity = batchQty * noOfBatch;
tranIdSuffix++;
String newTranId = "";
newTranId = tranId;
newTranId = newTranId + tranIdSuffix;
tranIdList.add(newTranId);
pstmtIns.setString(1,newTranId);
pstmtIns.setString(2,orderType);
pstmtIns.setString(3,itemCode);
pstmtIns.setString(4,siteCode);
pstmtIns.setDouble(5,quantity);
pstmtIns.setTimestamp(6,sysDate);
pstmtIns.setTimestamp(7,sysDate);
pstmtIns.setString(8,status);
pstmtIns.setTimestamp(9,sysDate);
pstmtIns.setDouble(10,yieldPerc);
pstmtIns.setString(11,unit);
pstmtIns.addBatch();
pstmtIns.clearParameters();
} }
} }// End of Inner for loop
noOfItem = itemTreeSet.size(); if (itemCode != null && itemCode.trim().length() > 0)
if ( noOfItem > 0 )
{
itemCodeFr = (String)itemTreeSet.first();
itemCodeTo = (String)itemTreeSet.last();
}
noOfSite = siteTreeSet.size();
if ( noOfSite > 0 )
{ {
siteCodeFr = (String)siteTreeSet.first(); itemTreeSet.add(itemCode);
siteCodeTo = (String)siteTreeSet.last();
} }
if (siteCode != null && siteCode.trim().length() > 0)
int insCnt[] = null;
insCnt = pstmtIns.executeBatch();
if ( insCnt.length > 0 )
{ {
System.out.println("Record inserted into mps_order successfully for tran id =["+insCnt.length +"]"); siteTreeSet.add(siteCode);
conn.commit();
} }
if (tranIdDom == null || tranIdDom.trim().length() == 0)
Calendar cal = Calendar.getInstance();
Date d = new Date();
String runDate = simpleDateFormat.format(d);
cal.setTime(d);
cal.set(Calendar.DATE,1);
d = cal.getTime();
String fromDate = simpleDateFormat.format(d);
cal.setTime(d);
cal.add(Calendar.MONTH,3);
cal.set(Calendar.DATE,0);
d = cal.getTime();
String toDate = simpleDateFormat.format(d);
System.out.println("From Date :" + fromDate + " To Date :" + toDate);
StringBuffer argData = new StringBuffer();
argData = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
argData.append(editFlag).append("</editFlag></Header>");
argData.append("<Detail\r\n>");
argData.append("<date_from>").append(fromDate).append("</date_from>\r\n");
argData.append("<date_to>").append(toDate).append("</date_to>\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(itemCodeFr).append("</item_code__from>\r\n");
argData.append("<item_code__to>").append(itemCodeTo).append("</item_code__to>\r\n");
argData.append("<item_ser__from>").append("0").append("</item_ser__from>\r\n");
argData.append("<item_ser__to>").append("ZZ").append("</item_ser__to>\r\n");
argData.append("<process_cycle>").append("3").append("</process_cycle>\r\n");
argData.append("<run_date>").append(runDate).append("</run_date>\r\n"); // 01-10-2007 manoharan
argData.append("<dis_plan>").append("N").append("</dis_plan>\r\n");
argData.append("<mfg_plan>").append("N").append("</mfg_plan>\r\n");
argData.append("<mat_plan>").append("Y").append("</mat_plan>\r\n");
argData.append("<made_to_stock>").append("0").append("</made_to_stock>\r\n");
argData.append("<made_to_order>").append("0").append("</made_to_order>\r\n");
argData.append("<balance_intersite>").append("N").append("</balance_intersite>\r\n");
argData.append("<gen_ind>").append("N").append("</gen_ind>\r\n");
argData.append("<wizard>").append("3").append("</wizard>\r\n");
argData.append("</Detail>");
argData.append("</Root>");
argDom = genericUtility.parseString(argData.toString());
String mrpGetData = "";
RunMRPPrc runMRPObj = new RunMRPPrc();
mrpGetData = runMRPObj.getData(argDom, dom2, "", xtraParams);
System.out.println("mrpGetData =["+mrpGetData+"]");
String tranIdStr = "'";
if ( tranIdList != null && tranIdList.size() > 0 )
{ {
for (int i = 0; i < tranIdList.size(); i++) newDataCnt++;
ArrayList newDataList = new ArrayList();
newDataList.add(siteCode);
newDataList.add(itemCode);
newDataList.add(quantity);
mpsDataMap.put("" + newDataCnt, newDataList);
pstmtSel1.setString(1, itemCode);
rs = pstmtSel1.executeQuery();
if (rs.next())
{ {
tranIdStr = tranIdStr + tranIdList.get(i) + "','"; unit = rs.getString("UNIT");
yieldPerc = rs.getDouble("YIELD_PERC");
} }
pstmtSel1.clearParameters();
rs.close();
rs = null;
pstmtSel.setString(1, siteCode);
pstmtSel.setString(2, itemCode);
rs = pstmtSel.executeQuery();
if (rs.next())
{
batchQty = rs.getDouble("BATCH_QTY");
}
pstmtSel.clearParameters();
rs.close();
rs = null;
// quantity = batchQty * noOfBatch;
tranIdSuffix++;
String newTranId = "";
newTranId = tranId;
newTranId = newTranId + tranIdSuffix;
tranIdList.add(newTranId);
pstmtIns.setString(1, newTranId);
pstmtIns.setString(2, orderType);
pstmtIns.setString(3, itemCode);
pstmtIns.setString(4, siteCode);
pstmtIns.setDouble(5, quantity);
pstmtIns.setTimestamp(6, sysDate);
pstmtIns.setTimestamp(7, sysDate);
pstmtIns.setString(8, status);
pstmtIns.setTimestamp(9, sysDate);
pstmtIns.setDouble(10, yieldPerc);
pstmtIns.setString(11, unit);
pstmtIns.addBatch();
pstmtIns.clearParameters();
} }
if ( tranIdStr.length() >= 2 ) }
{ noOfItem = itemTreeSet.size();
tranIdStr = tranIdStr.substring(0, tranIdStr.length()-2); if (noOfItem > 0)
} {
else itemCodeFr = (String) itemTreeSet.first();
itemCodeTo = (String) itemTreeSet.last();
}
noOfSite = siteTreeSet.size();
if (noOfSite > 0)
{
siteCodeFr = (String) siteTreeSet.first();
siteCodeTo = (String) siteTreeSet.last();
}
int insCnt[] = null;
insCnt = pstmtIns.executeBatch();
if (insCnt.length > 0)
{
System.out.println("Record inserted into mps_order successfully for tran id =[" + insCnt.length + "]");
conn.commit();
}
Calendar cal = Calendar.getInstance();
Date d = new Date();
String runDate = simpleDateFormat.format(d);
cal.setTime(d);
cal.set(Calendar.DATE, 1);
d = cal.getTime();
String fromDate = simpleDateFormat.format(d);
cal.setTime(d);
cal.add(Calendar.MONTH, 3);
cal.set(Calendar.DATE, 0);
d = cal.getTime();
String toDate = simpleDateFormat.format(d);
System.out.println("From Date :" + fromDate + " To Date :" + toDate);
StringBuffer argData = new StringBuffer();
argData = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
argData.append(editFlag).append("</editFlag></Header>");
argData.append("<Detail\r\n>");
argData.append("<date_from>").append(fromDate).append("</date_from>\r\n");
argData.append("<date_to>").append(toDate).append("</date_to>\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(itemCodeFr).append("</item_code__from>\r\n");
argData.append("<item_code__to>").append(itemCodeTo).append("</item_code__to>\r\n");
argData.append("<item_ser__from>").append("0").append("</item_ser__from>\r\n");
argData.append("<item_ser__to>").append("ZZ").append("</item_ser__to>\r\n");
argData.append("<process_cycle>").append("3").append("</process_cycle>\r\n");
argData.append("<run_date>").append(runDate).append("</run_date>\r\n"); // 01-10-2007
// manoharan
argData.append("<dis_plan>").append("N").append("</dis_plan>\r\n");
argData.append("<mfg_plan>").append("N").append("</mfg_plan>\r\n");
argData.append("<mat_plan>").append("Y").append("</mat_plan>\r\n");
argData.append("<made_to_stock>").append("0").append("</made_to_stock>\r\n");
argData.append("<made_to_order>").append("0").append("</made_to_order>\r\n");
argData.append("<balance_intersite>").append("N").append("</balance_intersite>\r\n");
argData.append("<gen_ind>").append("N").append("</gen_ind>\r\n");
argData.append("<wizard>").append("3").append("</wizard>\r\n");
argData.append("</Detail>");
argData.append("</Root>");
argDom = genericUtility.parseString(argData.toString());
String mrpGetData = "";
RunMRPPrc runMRPObj = new RunMRPPrc();
/* Added by sachin */
parentNode = parentNodeList.item(0);
winName = this.getWinName(parentNode);
mrpGetData = runMRPObj.getData(argDom, dom2, winName, xtraParams);
/* End Added by sachin */
System.out.println("mrpGetData =[" + mrpGetData + "]");
String tranIdStr = "'";
if (tranIdList != null && tranIdList.size() > 0)
{
for (int i = 0; i < tranIdList.size(); i++)
{ {
tranIdStr = ""; tranIdStr = tranIdStr + tranIdList.get(i) + "','";
} }
}
if (tranIdStr.length() >= 2)
{
tranIdStr = tranIdStr.substring(0, tranIdStr.length() - 2);
} else
{
tranIdStr = "";
}
if ( tranIdStr != null && tranIdStr.trim().length() > 0 ) if (tranIdStr != null && tranIdStr.trim().length() > 0)
{
deleteSql = "DELETE FROM MPS_ORDER WHERE TRAN_ID IN(" + tranIdStr + ")";
pstmt = conn.prepareStatement(deleteSql);
delCnt = pstmt.executeUpdate();
if (delCnt > 0)
{ {
deleteSql = "DELETE FROM MPS_ORDER WHERE TRAN_ID IN("+tranIdStr+")"; System.out.println("Record deleted from mps_order successfully for tran id =[" + tranIdStr + "]");
pstmt = conn.prepareStatement(deleteSql);
delCnt = pstmt.executeUpdate();
if ( delCnt > 0 )
{
System.out.println("Record deleted from mps_order successfully for tran id =["+tranIdStr+"]");
}
pstmt.close();
pstmt = null;
} }
pstmt.close();
pstmt = null;
}
return mrpGetData;
}
break;
// ended by akhilesh
return mrpGetData;
}
break;
//ended by akhilesh
} }
valueXmlString.append("</Root>"); valueXmlString.append("</Root>");
} } catch (Exception e)
catch(Exception e)
{ {
isError = true; isError = true;
System.out.println("Exception :[RequirementIC][itemChanged::case 1:] :==>\n"+e.getMessage()); System.out.println("Exception :[RequirementIC][itemChanged::case 1:] :==>\n" + e.getMessage());
e.printStackTrace(); e.printStackTrace();
return genericUtility.createErrorString(e); return genericUtility.createErrorString(e);
//throw new ITMException(e); // throw new ITMException(e);
} } finally
finally
{ {
try try
{ {
if ( conn != null ) if (conn != null)
{ {
if ( !isError ) if (!isError)
{ {
conn.commit(); conn.commit();
} } else
else
{ {
conn.rollback(); conn.rollback();
} }
if ( rs != null ) if (rs != null)
{ {
rs.close(); rs.close();
rs = null; rs = null;
} }
if ( pstmtIns != null ) if (pstmtIns != null)
{ {
pstmtIns.close(); pstmtIns.close();
pstmtIns = null; pstmtIns = null;
} }
if ( pstmtSel != null ) if (pstmtSel != null)
{ {
pstmtSel.close(); pstmtSel.close();
pstmtSel = null; pstmtSel = null;
} }
if ( pstmtSel1 != null ) if (pstmtSel1 != null)
{ {
pstmtSel1.close(); pstmtSel1.close();
pstmtSel1 = null; pstmtSel1 = null;
...@@ -519,8 +541,7 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -519,8 +541,7 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
conn.close(); conn.close();
conn = null; conn = null;
} }
} } catch (Exception e)
catch (Exception e)
{ {
} }
} }
...@@ -528,28 +549,27 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -528,28 +549,27 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
} }
// Validation // Validation
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{ {
Document dom = null; Document dom = null;
Document dom1 = null; Document dom1 = null;
Document dom2 = null; Document dom2 = null;
String errString = ""; String errString = "";
System.out.println("wfValData(String)>>>"); System.out.println("wfValData(String)>>>");
try try
{ {
dom = parseString(xmlString); dom = parseString(xmlString);
System.out.println("RequirementIC : wfValData(String xmlString) : ==>\n" + xmlString ); System.out.println("RequirementIC : wfValData(String xmlString) : ==>\n" + xmlString);
System.out.println("RequirementIC : wfValData(String xmlString1) : ==>\n" + xmlString1 ); System.out.println("RequirementIC : wfValData(String xmlString1) : ==>\n" + xmlString1);
dom1 = parseString(xmlString1); dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 ) if (xmlString2.trim().length() > 0)
{ {
dom2 = parseString("<Root>" + xmlString2+ "</Root>"); dom2 = parseString("<Root>" + xmlString2 + "</Root>");
} }
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams); errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
} } catch (Exception e)
catch(Exception e)
{ {
System.out.println("Exception : RequirementIC : wfValData(String xmlString) : ==>\n"+e.getMessage()); System.out.println("Exception : RequirementIC : wfValData(String xmlString) : ==>\n" + e.getMessage());
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e); throw new ITMException(e);
} }
...@@ -563,8 +583,8 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -563,8 +583,8 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
Node parentNode = null; Node parentNode = null;
Node childNode = null; Node childNode = null;
String childNodeName = ""; String childNodeName = "";
String errString = ""; String errString = "";
int ctr,currentFormNo=0; int ctr, currentFormNo = 0;
int childNodeListLength; int childNodeListLength;
int count = 0; int count = 0;
...@@ -580,173 +600,184 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R ...@@ -580,173 +600,184 @@ public class RequirementIC extends ValidatorEJB implements RequirementICLocal,R
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
{ {
simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat()); simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = getConnection(); conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams,"userId"); userId = getValueFromXTRA_PARAMS(xtraParams, "userId");
if(objContext != null && objContext.trim().length()>0) if (objContext != null && objContext.trim().length() > 0)
{ {
currentFormNo = Integer.parseInt(objContext); currentFormNo = Integer.parseInt(objContext);
} }
switch(currentFormNo) switch (currentFormNo)
{ {
case 1: case 1:
{
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (ctr = 0; ctr < childNodeListLength; ctr++)
{ {
parentNodeList = dom.getElementsByTagName("Detail1"); childNode = childNodeList.item(ctr);
parentNode = parentNodeList.item(0); childNodeName = childNode.getNodeName();
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); int cnt;
for(ctr = 0; ctr < childNodeListLength; ctr++) System.out.println("childNodeName 0. : " + childNodeName);
if (childNodeName.equals("site_code__fr") || childNodeName.equals("site_code__to"))
{ {
childNode = childNodeList.item(ctr); siteCodeFr = genericUtility.getColumnValue("site_code__fr", dom);
childNodeName = childNode.getNodeName(); siteCodeTo = genericUtility.getColumnValue("site_code__to", dom);
if (siteCodeFr == null || siteCodeFr.trim().length() == 0)
int cnt;
System.out.println("childNodeName 0. : " + childNodeName);
if ( childNodeName.equals("site_code__fr") || childNodeName.equals("site_code__to") )
{ {
siteCodeFr = genericUtility.getColumnValue("site_code__fr",dom); errCode = "VMSITE11";
siteCodeTo = genericUtility.getColumnValue("site_code__to",dom); errString = getErrorString("site_code__fr", errCode, userId);
if ( siteCodeFr == null || siteCodeFr.trim().length() == 0 ) break;
{ }
errCode = "VMSITE11"; if (siteCodeTo == null || siteCodeTo.trim().length() == 0)
errString = getErrorString("site_code__fr",errCode,userId); {
break; errCode = "VMSITE12";
} errString = getErrorString("site_code__fr", errCode, userId);
if ( siteCodeTo == null || siteCodeTo.trim().length() == 0 ) break;
{
errCode = "VMSITE12";
errString = getErrorString("site_code__fr",errCode,userId);
break;
}
} }
} }
}//End of Case 1 }
}// End of Case 1
break; break;
case 2: case 2:
{
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (ctr = 0; ctr < childNodeListLength; ctr++)
{ {
parentNodeList = dom.getElementsByTagName("Detail2"); childNode = childNodeList.item(ctr);
parentNode = parentNodeList.item(0); childNodeName = childNode.getNodeName();
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); int cnt;
for(ctr = 0; ctr < childNodeListLength; ctr++) System.out.println("childNodeName 0. : " + childNodeName);
if (childNodeName.equals("site_code"))
{ {
childNode = childNodeList.item(ctr); siteCode = genericUtility.getColumnValue("site_code", dom);
childNodeName = childNode.getNodeName(); if (siteCode == null || siteCode.trim().length() == 0)
int cnt;
System.out.println("childNodeName 0. : " + childNodeName);
if ( childNodeName.equals("site_code") )
{ {
siteCode = genericUtility.getColumnValue("site_code",dom); errCode = "VMSITECD";
if ( siteCode == null || siteCode.trim().length() == 0 ) errString = getErrorString("site_code", errCode, userId);
{ break;
errCode = "VMSITECD"; }
errString = getErrorString("site_code",errCode,userId);
break;
}
sql = "SELECT COUNT(*) COUNT FROM SITE WHERE SITE_CODE = ? ";
pstmt = conn.prepareStatement(sql); sql = "SELECT COUNT(*) COUNT FROM SITE WHERE SITE_CODE = ? ";
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery(); pstmt = conn.prepareStatement(sql);
if ( rs.next() ) pstmt.setString(1, siteCode);
{ rs = pstmt.executeQuery();
count = rs.getInt("COUNT"); if (rs.next())
} {
rs.close(); rs = null; count = rs.getInt("COUNT");
if ( count == 0 )
{
errCode = "VMSITE";
errString = getErrorString(childNodeName,errCode,userId);
break;
}
} }
else if ( childNodeName.equals("item_code") ) rs.close();
rs = null;
if (count == 0)
{ {
itemCode = genericUtility.getColumnValue("item_code",dom); errCode = "VMSITE";
if ( itemCode == null || itemCode.trim().length() == 0 ) errString = getErrorString(childNodeName, errCode, userId);
{ break;
errCode = "VMITEMCD"; }
errString = getErrorString("item_code",errCode,userId); } else if (childNodeName.equals("item_code"))
break; {
} itemCode = genericUtility.getColumnValue("item_code", dom);
if (itemCode == null || itemCode.trim().length() == 0)
sql = "SELECT COUNT(*) COUNT FROM ITEM WHERE ITEM_CODE = ? "; {
errCode = "VMITEMCD";
errString = getErrorString("item_code", errCode, userId);
break;
}
pstmt = conn.prepareStatement(sql); sql = "SELECT COUNT(*) COUNT FROM ITEM WHERE ITEM_CODE = ? ";
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery(); pstmt = conn.prepareStatement(sql);
if ( rs.next() ) pstmt.setString(1, itemCode);
{ rs = pstmt.executeQuery();
count = rs.getInt("COUNT"); if (rs.next())
} {
rs.close(); rs = null; count = rs.getInt("COUNT");
if ( count == 0 ) }
{ rs.close();
errCode = "VMITEM1"; rs = null;
errString = getErrorString(childNodeName,errCode,userId); if (count == 0)
break; {
} errCode = "VMITEM1";
errString = getErrorString(childNodeName, errCode, userId);
break;
} }
else if ( childNodeName.equals("quantity") ) } else if (childNodeName.equals("quantity"))
{
quantity = genericUtility.getColumnValue("quantity", dom);
if (quantity == null || quantity.trim().length() == 0 || quantity.equals("0"))
{ {
quantity = genericUtility.getColumnValue("quantity",dom); errCode = "VMWEQTY";
if ( quantity == null || quantity.trim().length() == 0 || quantity.equals("0") ) errString = getErrorString("quantity", errCode, userId);
{ break;
errCode = "VMWEQTY";
errString = getErrorString("quantity",errCode,userId);
break;
}
} }
} }
}//End of Case 1 }
}// End of Case 1
break; break;
}//End of Switch block }// End of Switch block
} } catch (Exception e)
catch(Exception e)
{ {
System.out.println("Exception ::"+e); System.out.println("Exception ::" + e);
e.printStackTrace(); e.printStackTrace();
errString = e.getMessage(); errString = e.getMessage();
throw new ITMException(e); throw new ITMException(e);
} } finally
finally
{ {
try try
{ {
//System.out.println("Closing Connection....."); // System.out.println("Closing Connection.....");
if ( rs != null ) if (rs != null)
{ {
rs.close(); rs.close();
rs = null; rs = null;
} }
if ( pstmt != null ) if (pstmt != null)
{ {
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
conn.close(); conn.close();
conn = null; conn = null;
}catch(Exception se){} } catch (Exception se)
{
}
} }
return errString; return errString;
} }
private String checkNull(String value) private String checkNull(String value)
{ {
if ( value == null ) if (value == null)
{ {
value = ""; value = "";
} }
return value; return value;
} }
/* Added by sachin on 26/6/13 */
private String getWinName(Node node) throws Exception
{
String objName = "";
NamedNodeMap attrMap = node.getAttributes();
objName = attrMap.getNamedItem("objName").getNodeValue();
System.out.println(" Object Name is==>" + objName);
return "w_" + objName;
}
/* End Added by sachin on 26/6/13 */
} }
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