Commit 40f1c0d3 authored by vdhoble's avatar vdhoble

For recalculation of due date due to delay - D15CSUN014


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98202 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 21647c80
/*********
* Created By : Vishakha
* Date : 06/07/2015
* Request ID : D15CSUN014
* For Recalculation of Due date due to delay.
*/
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
import java.sql.Timestamp;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class POrderMilestone extends ValidatorEJB {
E12GenericUtility genericUtility = new E12GenericUtility();
UtilMethods utilmethod = new UtilMethods();
public String recalcDueDate(String tranId,String xmlDataAll,Connection conn) throws RemoteException,ITMException
{
System.out.println("@@@@@@@ Recalculating Due Date ****** for tran_id **"+tranId);
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String sql = "";
int delayDays=0,cnt = 1,count1 = 0;
Timestamp parsedReschDate = null;
int lineNo = 0;
String complDate="";
String dueDateOrgStr = "",taskCode = "";
Document dom = null;
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs=null;
int ctr=0;
int currentFormNo=0;
int childNodeListLength;
String childNodeName = null;
Timestamp dueDateHeader = null,reschDate = null;
ConnDriver connDriver = new ConnDriver();
Timestamp complDateNew = null,dueDateOrg = null;
String retString = "SUCCESS";
System.out.println("xmlString DOM-->>["+xmlDataAll+"]");
try
{
dom = parseString(xmlDataAll);// read xmldataAll
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("Child name --->> "+childNodeName);
if(childNodeName.equalsIgnoreCase("compl_date"))
{
complDate = checkNull(genericUtility.getColumnValue("compl_date",dom));
System.out.println("complDate--->["+complDate+"]");
}
if(childNodeName.equalsIgnoreCase("task_code"))
{
taskCode = checkNull(genericUtility.getColumnValue("task_code",dom));
System.out.println("taskCode--->["+taskCode+"]");
}
if(childNodeName.equalsIgnoreCase("due_date"))
{
dueDateOrgStr = checkNull(genericUtility.getColumnValue("due_date",dom));
System.out.println("dueDateOrgStr--->["+dueDateOrgStr+"]");
}
}
if(complDate.length() > 0)//completion date is not null
{
complDateNew = Timestamp.valueOf(genericUtility.getValidDateString(complDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("completionDate ====parsed into sql format:::::"+complDateNew);
}
if(dueDateOrgStr.length() > 0)
{
dueDateOrg = Timestamp.valueOf(genericUtility.getValidDateString(dueDateOrgStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("Due Date Original ====parsed into sql format:::==="+dueDateOrg);
}
if(dueDateOrg.before(complDateNew))//if completion date is greater than due date original
{
System.out.println("days-----"+delayDays);
delayDays = (int)utilmethod.DaysAfter(dueDateOrg, complDateNew); //(int)countDaysBetween(dueDateOrg,complDateNew);
System.out.println("delayed days-----"+delayDays);
//added the delayed days to the date to get the next date
parsedReschDate = utilmethod.RelativeDate(dueDateOrg, delayDays);//addDays(dueDateOrg, delayDays);
System.out.println("completionDate ====parsed into sql format:::::"+parsedReschDate);
//added code for finding the max line no of detail
sql = "select max(line_no) as lineNoTot from pur_milstn_resch where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery();
if ( rs.next() )
{
lineNo = rs.getInt("lineNoTot");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
/**selecting pending tasks from header table **inserting records after rescheduling due dates in detail table***/
String sqlResch = "Insert into pur_milstn_resch (TRAN_ID,LINE_NO,DELAY_DAYS,TASK_CODE__DELAY,DUE_DATE_ORG,DUE_DATE_RESCH) values (?,?,?,?,?,?)";
sql = "select task_code,due_date from pur_milstn where purc_order in(select purc_order from pur_milstn where tran_id = ?) and task_status = 'P'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery();
while ( rs.next() )
{
lineNo = lineNo ++;
taskCode = rs.getString("task_code");
dueDateHeader = rs.getTimestamp("due_date");
System.out.println("Inserting into detail table for Task Codes in Header Tables which are pending");
System.out.println("delayed days-----"+delayDays);
//added the delayed days to the date to get the next date
reschDate = utilmethod.RelativeDate(dueDateHeader, delayDays);//addDays(dueDateHeader, delayDays);
System.out.println("getdays==into detail=============="+reschDate);
pstmt1 = conn.prepareStatement(sqlResch);
pstmt1.setString(1,tranId);
pstmt1.setInt(2,lineNo);
pstmt1.setInt(3,delayDays);
pstmt1.setString(4,taskCode);
pstmt1.setTimestamp(5,dueDateHeader);
pstmt1.setTimestamp(6,reschDate);
pstmt1.addBatch();
pstmt1.clearParameters();
}
pstmt1.executeBatch();//added out of the loop for batch update
pstmt1.clearBatch();
pstmt1.close();
pstmt1=null;
rs.close();
rs=null;
pstmt.close();
pstmt=null;
/*****Updating the due date for the ongoing task in header table***/
sql = "update pur_milstn set due_date = ? where tran_id = ?";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setTimestamp(1,parsedReschDate);
pstmt1.setString(2,tranId);
count1 = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
System.out.println("NO. OF RECORDS updated==== "+count1);
}
} //end try
catch (SQLException se) {
retString = se.toString();
System.out.println("SQLException ::"+se);
se.printStackTrace();
throw new ITMException(se);
}
catch(Exception e)
{
retString = e.toString();
System.out.println("Exception ::"+e);
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if(conn!=null)
{
conn.close();
conn = null;
}
if(connDriver!=null){
connDriver = null;
}
if(rs !=null)
{
rs.close();
rs=null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
return retString ;
}
public String checkNull(String input)
{
if (input == null)
{
input="";
}
return input.trim();
}
}
/* public long countDaysBetween(Timestamp complDateNew, Timestamp dueDateOrg)
{
//reset all hours mins and secs to zero on start date
Calendar startCal = GregorianCalendar.getInstance();
startCal.setTime(complDateNew);
startCal.set(Calendar.HOUR_OF_DAY, 0);
startCal.set(Calendar.MINUTE, 0);
startCal.set(Calendar.SECOND, 0);
long startTime = startCal.getTimeInMillis();
//reset all hours mins and secs to zero on end date
Calendar endCal = GregorianCalendar.getInstance();
endCal.setTime(dueDateOrg);
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
long endTime = endCal.getTimeInMillis();
return (endTime - startTime)/(1000 * 60 * 60 * 24) ;
}
*/
/*public Timestamp addDays(Timestamp date, int days) {
Timestamp parsedDate = null;
Calendar c = Calendar.getInstance();
c.setTime((date));
c.add(Calendar.DATE, days);
parsedDate = new Timestamp( c.getTimeInMillis());
return parsedDate;
}*/
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