<%@ page contentType="text/html"%>
<%@ page
	import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*"%>
<%@page import="ibase.dashboard.sfa.ejb.*"%>
<!--<%@page import="ibase.webitm.reports.utility.ResourceConstants"%>
-->
<%@page import="ibase.utility.CommonConstants"%>
<%@ page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page import="org.w3c.dom.Node"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="ibase.webitm.utility.GenericUtility"%>

<%!GenericUtility genericUtility = GenericUtility.getInstance();
	String xmlString = "";
	String objName = "";
	Document dom = null;
	NodeList dtlList = null;
	Node parentNode = null;
	NodeList childNodeList = null;
	Node currDetail = null;
	String childNodeName = "";
	String  drNotVisited = "", unDrtVisited = "", drVisited = "";
	String visitedDr = "", notVisitedDr = "", unPlndDrVisited = "";
	ArrayList<String> unDrVisitedList=null;
	ArrayList<String> drVisitedList =null;
	ArrayList<String> drNotVisitedList =null;
	int unDrVisitedListSize=0;
	int drVisitedListSize=0;
	int drNotVisitedListSize=0;
	String rptTitle="";
	
	
	%>
<%
	response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
	response.setHeader("Cache-Control", "no-store, no-cache,must-revalidate");
	response.addHeader("Cache-Control", "post-check=0, pre-check=0");
	response.setHeader("Pragma", "no-cache");
	int ctr = 0;
	CommonConstants.setAPPLICATION_CONTEXT(config.getServletContext().getRealPath("/"));
%>

<%@page import="java.util.ArrayList"%>
<html>
<head>
<style type="text/css">
.reportName {
	FONT-FAMILY: Arial;
	FONT-SIZE: 12pt;
	font-weight: bold;
}

.reportTitle {
	FONT-FAMILY: Arial;
	FONT-SIZE: 10pt;
}



.reportDetail{
	FONT-FAMILY: Arial;
	FONT-SIZE: 10pt;
	width: 550px;
}

.rowColor {
	background-color: grey;
	text-align: left;
	font-weight: bold;
}
.tblHeader 
{
border:1px solid
font-weight: bold;
}
</style>
</head>
<body>

<%
	try
	{
		rptTitle   = request.getParameter("rtitle");
		if (rptTitle == null || rptTitle.trim().length() == 0)
		{
			rptTitle =" " ;
		} else
		{
			if(rptTitle.equalsIgnoreCase("Y") && rptTitle.trim().length()!= 0)
			{
				rptTitle =" Planned v/s Actual Doctors Visit ";
		      }
			else{
				rptTitle =" " ;
			}
		}
		
		
		ibase.utility.UserInfoBean userInfo = (ibase.utility.UserInfoBean) session.getAttribute("USER_INFO");
		String user = userInfo.getLoginCode();
		System.out.println("user ::" + user);
		//String outputFilename = objName + user + System.currentTimeMillis();
		Context context = new InitialContext();
		PlannedVSActualActionTypesRemote plannedVSActualAction = (PlannedVSActualActionTypesRemote) context.lookup("ibase/PlannedVSActualActionTypes/remote");
		//DashboardPortal dashboardPortal=(DashboardPortal)context.lookup("ibase.dashboard.sfa.ejb.DashboardPortal.class.getName()");
		if (user != null && user.trim().length() != 0)
		{
			xmlString = plannedVSActualAction.getData(user);
			System.out.println("Return xmlString====" + xmlString);
			System.out.println("xmlString  length is ==>" + xmlString.length());
		}
%>
<%
	if (xmlString != null && xmlString.trim().length() > 0)
		{
%>
<table class="reportName">
	<tr>
		<td><%=rptTitle %></td>
	</tr>
</table>
<table>
	<tr class="reportTitle">
		<td><b>Sales Person:</b></td>
		<td><%=plannedVSActualAction.getSalesPerson()%></td>
	</tr>
</table>

<table class="reportDetail" RULES="cols"  FRAME=BOX >
	<tr class="tblHeader">
		<th> Planned Doctors Not Visited</th>
		<th> Planned Doctors Visited</th>
		<th> Unplanned Doctors Visited</th>
	</tr>
	<%
		      unDrVisitedList = new ArrayList<String>();
			  drVisitedList = new ArrayList<String>();
			  drNotVisitedList = new ArrayList<String>();

				dom = genericUtility.parseString(xmlString);
				if (dom != null)
				{
					dtlList = dom.getElementsByTagName("un_dr_visitd");
					System.out.println("Detail Node Length==" + dtlList.getLength());

					for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
					{
						parentNode = dtlList.item(cntr);
						unDrtVisited = parentNode.getTextContent();
						unDrVisitedList.add(unDrtVisited);
					}

					dtlList = dom.getElementsByTagName("dr_visitd");
					for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
					{
						parentNode = dtlList.item(cntr);
						drVisited = parentNode.getTextContent();
						drVisitedList.add(drVisited);
					}
					dtlList = dom.getElementsByTagName("dr_not_visited");
					for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
					{
						parentNode = dtlList.item(cntr);
						drNotVisited = parentNode.getTextContent();
						drNotVisitedList.add(drNotVisited);
					}
				}

				 unDrVisitedListSize = unDrVisitedList.size();
				 drVisitedListSize = drVisitedList.size();
				 drNotVisitedListSize = drNotVisitedList.size();
				
				System.out.print("unDrVisitedListSize ="+unDrVisitedListSize +"drVisitedListSize ="+drVisitedListSize + "drNotVisitedListSize :"+drNotVisitedListSize);
				int maxLength = Math.max(unDrVisitedListSize, Math.max(drVisitedListSize, drNotVisitedListSize));
				System.out.print("Max Length is ="+maxLength);
				for (int i = 0; i < maxLength; i++)
				{
					if (i<drVisitedListSize)
					{
						visitedDr = drVisitedList.get(i);
						
						System.out.print("Visited Dr  ="+visitedDr);
					} else
					{
						visitedDr = " ";
					}
					if(i < drNotVisitedListSize)
					{
					  notVisitedDr = drNotVisitedList.get(i);
					}else{
						
						notVisitedDr="";
					}
					if(i< unDrVisitedListSize)
					{
					unPlndDrVisited = unDrVisitedList.get(i);

					System.out.print("unPlndDrVisited  Dr  are ="+unPlndDrVisited);
					}else
					{
						unPlndDrVisited=" ";
					}
			%>
	<tr>
		<td><%=notVisitedDr%></td>
		<td><%=visitedDr%></td>
		<td><%= unPlndDrVisited%></td>
	</tr>
	<%
		}
	%>

</table>
<%
	}

	} catch (Exception ex)
	{
		System.out.println("Exception in JSP :PlannedVSActualActionTypes:" + ex.getMessage()); 
	}
%>
</body>
</html>