<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="ibase.webitm.ejb.fin.adv.*" %>
        <%@ page import="ibase.webitm.ejb.fin.*" %>
    <%@ page import="java.sql.Connection" %>
       <%@ page import="ibase.system.config.ConnDriver" %>
       <%@ page import="java.util.ArrayList" %>
        <%@ page import="java.sql.*" %>
        <%@ page import="java.util.Enumeration" %>
    <%@ page import="java.util.HashMap" %>
    <%@ page import="ibase.webitm.utility.GenericUtility" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
    font-size: small;
}
</style>
</head>

<body>
<%! private String checkNull(String inp)
{
	if(inp == null)
		inp = " ";
	return inp.trim();
}
%>
<%
// out.println("JSP CALLED FOR PREVIEW");
String xtraParams ="", forcedFlag ="";
/* boolean isPreview = true; */
Connection conn = null;
boolean connStatus=false;
String sql ="";
String effdate = "",effectiveDate = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList abc = null;
MiscPayGltracePreview miscpay = new MiscPayGltracePreview();
ArrayList gltracepreview = null;
ReceiptAdvConf rcf = new ReceiptAdvConf();
PurchaseVoucherGltracePreview pvp = new PurchaseVoucherGltracePreview();
MiscDrCrRcpConf misc = new MiscDrCrRcpConf();
ArrayList<ArrayList> gltracePreviewList1 =null;
GenericUtility genericUtility = null;
String tranDate = "",transactionDate = "";
try{
	 String param = null;
	  String paramvalue = null;
	   genericUtility = new GenericUtility();
	 Enumeration enum1 = request.getParameterNames();
	  while( enum1.hasMoreElements() )
	  {
		  param = (String)enum1.nextElement();
		  paramvalue = request.getParameter(param);
	      System.out.println("param ["+param+"] paramvalue ["+paramvalue+"]");    
	  } 
	
   
	String paramList[];
	String tranID = "";
	String objName = "";
	if ( paramvalue.indexOf("~") != -1 )
	{
	  paramList = paramvalue.split("~");
	  tranID  = paramList[0];
	  objName = paramList[1];
	}

	

System.out.println("Tran Id>>>>>>>"+tranID);


System.out.println("oBJ_NAME>>>>>>>"+objName);

if ( conn == null )//changed by Gulzar - 25/11/11
{
	System.out.println("New Connection created");
	ConnDriver connDriver = null;
	connDriver = new ConnDriver();
	conn = connDriver.getConnectDB("DriverITM");
	conn.setAutoCommit(false);
	connDriver = null;
	connStatus = true;
}

sql = "delete from gltrace_preview where ref_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranID);  
int count = pstmt.executeUpdate();
System.out.print("The value of count>>>>"+count);
if(count > 0)
{
	conn.commit();
}
pstmt.close();
pstmt = null;

if("misc_pay".equalsIgnoreCase(objName))
{
miscpay.preview(tranID, xtraParams, forcedFlag);
}
else if("receipt_adv".equalsIgnoreCase(objName))
{
	rcf.confirm( tranID, xtraParams, forcedFlag, conn ,true);
}
else if("voucher".equalsIgnoreCase(objName))
{
	pvp.preview(tranID, xtraParams, forcedFlag);
}
else if("misc_drcr_rcp_cr".equalsIgnoreCase(objName))
{
	misc.confirm( tranID, xtraParams, forcedFlag, conn ,true);
}
else if("misc_drcr_rcp_dr".equalsIgnoreCase(objName))
{
	misc.confirm( tranID, xtraParams, forcedFlag, conn ,true);
}
gltracePreviewList1 = new ArrayList<ArrayList>();
sql =  "SELECT a.ACCT_CODE,a.DESCR,g.REF_ID,g.ACCT_CODE,g.REF_SER,g.EFF_DATE,g.TRAN_ID,g.TRAN_DATE,g.CCTR_CODE,g.DR_AMT,g.CR_AMT,g.POST_STAT,g.POST_DATE,g.SITE_CODE,g.FIN_ENTITY,g.CURR_CODE,g.EXCH_RATE,g.PRD_CODE,g.SUNDRY_CODE,g.SUNDRY_TYPE,g.ACCT_PRD,g.REF_TYPE,g.REMARKS,g.EMP_CODE,g.ANAL_CODE,g.CHG_DATE,g.CHG_USER,g.CHG_TERM,g.ENTRY_BATCH_NO,g.PROJ_CODE,g.PARTY_DOC_REF,g.DEPT_CODE,g.TRF_TALLY,g.ANALYSIS1,g.ANALYSIS2,g.ANALYSIS3 , (g.DR_AMT * g.EXCH_RATE) as DR_AMT__BC,(g.CR_AMT * g.EXCH_RATE) as CR_AMT__BC FROM GLTRACE_PREVIEW g ,ACCOUNTS a WHERE ( g.acct_code = a.acct_code (+)) and  ( ( g.REF_ID = ? ) )  ";

pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranID);  
rs = pstmt.executeQuery();
while(rs.next())
{  
	gltracepreview = new ArrayList();
	System.out.println("Acct code"+rs.getString("ACCT_CODE"));
	tranDate = rs.getString("TRAN_DATE");
	effdate = rs.getString("EFF_DATE");
	System.out.print("Effective Date***"+effdate);
	transactionDate = genericUtility.getValidDateString(tranDate,genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
    effectiveDate  = genericUtility.getValidDateString(effdate,genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
	System.out.print("Effective Date 2***"+effectiveDate);
    gltracepreview.add(checkNull(rs.getString("TRAN_ID")));
	gltracepreview.add(checkNull(transactionDate));
	gltracepreview.add(checkNull(rs.getString("REF_SER")));
	gltracepreview.add(checkNull(rs.getString("REF_ID")));
	gltracepreview.add(checkNull(rs.getString("ACCT_CODE")));
	gltracepreview.add(checkNull(rs.getString("DESCR")));
	gltracepreview.add(checkNull(rs.getString("DR_AMT")));
	gltracepreview.add(checkNull(rs.getString("CR_AMT")));
	gltracepreview.add(checkNull(rs.getString("SITE_CODE")));
	gltracepreview.add(checkNull(rs.getString("FIN_ENTITY")));
	gltracepreview.add(checkNull(rs.getString("SUNDRY_CODE")));
	gltracepreview.add(checkNull(rs.getString("SUNDRY_TYPE")));
	gltracepreview.add(checkNull(rs.getString("REMARKS")));
	gltracepreview.add(checkNull(rs.getString("CCTR_CODE")));
	gltracepreview.add(checkNull(rs.getString("CURR_CODE")));
	gltracepreview.add(checkNull(rs.getString("EXCH_RATE")));
	gltracepreview.add(checkNull(rs.getString("DR_AMT__BC")));
	gltracepreview.add(checkNull(rs.getString("CR_AMT__BC")));
	gltracepreview.add(checkNull(effectiveDate));
	gltracepreview.add(checkNull(rs.getString("EMP_CODE")));
	gltracepreview.add(checkNull(rs.getString("ANAL_CODE")));
	gltracepreview.add(checkNull(rs.getString("REF_TYPE")));
	gltracepreview.add(checkNull(rs.getString("ANALYSIS1")));
	gltracepreview.add(checkNull(rs.getString("ANALYSIS2")));
	gltracepreview.add(checkNull(rs.getString("ANALYSIS3")));
	System.out.println("ArrayList Size>>>>>>>>>"+gltracepreview.size());
	gltracePreviewList1.add(gltracepreview);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
/* if(conn != null ){
	System.out.println("connection"+conn);
	conn.commit();
	conn.close();
	conn = null;
} */
}
catch(Exception e)
{
	e.printStackTrace();
	System.out.println( "@@@@@ Exception occured:: " );
}
finally{
	try{
		if( rs != null )
			rs.close();
		    rs = null;
		if( pstmt != null )
			pstmt.close();
		pstmt = null;
		if( conn != null )
			conn.close();
		conn = null; 
	}catch( Exception ex ){}
	
}
System.out.println("ArrayList preview Size>>>>>>>>>"+gltracePreviewList1.size());
%>


<table border ='0'>
<thead>

<td>Tran Id</td><td>Trand_date</td><td>Ref_Ser</td><td>Ref_Id</td><td>Acct Code</td><td>Descr</td><td>Dr Amt</td><td>Cr Amt</td><td>Site Code</td><td>Fin Entity</td><td>Sundry Code</td><td>Sundry Type</td>
<td>Remarks</td><td>Cctr Code</td><td>Curr Code</td><td>Exchange Rate</td><td>Dr Amt Bc</td><td>Cr Amt Bc</td><td>Eff Date</td>
<td>Emp Code</td><td>Anal Code</td><td>Ref Type</td><td>Analysis 1</td><td> Analysis 2</td><td>Analysis 3</td>
</thead>
<tbody>
<% for(int i=0;i<gltracePreviewList1.size();i++) 
{
	abc = gltracePreviewList1.get(i);

%>

<tr><%for(int j=0;j<abc.size();j++) 
{
%>

<td><%= abc.get(j) %></td>
<% 
}
%>
</tr>
<% 
}
%>
</tbody>
</table>
</body>
</html>