Current File : /home/obabain/autoclutchess_obaba_in/ledgerByIdPDF.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
     <%@include file="Connection.jsp" %>
     <%!
     String typ=null;
     String ref_id=null;
     String under=null;
     double i=0;
     double j=0;
     double s=0;
     double su=0;
     String sum=null;
     String sum2=null;
     String i1=null;
     String j1=null;
     String ledgername=null;
     String opbal=null;
     String cr=null;
     String dr=null;
     String addr=null;
     String comp=null;
  	String add1=null;
  	String add2=null;
  	String city=null;
  	String zip=null;
  	String phone=null;
  	String email=null;
  	String web=null;
  	String gst=null;
  	String bankname=null;
  	String acno=null;
  	String ifsc=null;
  	String branch=null;
  	String logo=null;
  	String state=null;
  	String curryear=null;
  	String currdate=null;
     %>
     <%
     String loginid=(String)session.getAttribute("logid");
     Statement st=con.createStatement();
     ResultSet rs=null;
     String id=request.getParameter("Id");
     String from=request.getParameter("from");
     String to=request.getParameter("to");
     
     rs=st.executeQuery("select tb.*,(CONCAT(UCASE(MID(ledger_name,1,1)),LCASE(MID(ledger_name,2)))) as ledgname,(case when type=2 then (select supplier_address_1 from ip_suppliers where supplier_id=tb.ref_id) else (case when type=3 then (select client_address_1 from ip_clients where client_id=tb.ref_id) else '' end)end)addr from account_ledger tb where l_id="+id+"");
     while(rs.next())
     {
    	typ=rs.getString("type");
    	ledgername=rs.getString("ledgname");
    	ref_id=rs.getString("ref_id");
    	under=rs.getString("under");
    	opbal=rs.getString("opening_bal");
    	addr=rs.getString("addr");
     }
     rs=st.executeQuery("select tb.*,upper(tb.user_company)company from ip_users tb where login_id="+loginid+"");
     while(rs.next())
     {
    		comp=rs.getString("company");
    	   	 add1=rs.getString("user_address_1");
    		 add2=rs.getString("user_address_2");
    		 city=rs.getString("user_city");
    		 zip=rs.getString("user_zip");
    		 state=rs.getString("user_state");
    		 
    		 phone=rs.getString("user_phone");
    		 email=rs.getString("user_email");
    		 web=rs.getString("user_web");
    		 gst=rs.getString("user_vat_id");
    		  bankname=rs.getString("bank_name");
    			 acno=rs.getString("account_no");
    			 ifsc=rs.getString("ifsc");
    			 branch=rs.getString("bank_branch");
    	 
     }
      rs=st.executeQuery("select *  from ip_logo where login_id="+loginid+"");
	    while(rs.next())
	    {
	    	logo=rs.getString("name");
	    }
	   
     
     %>
<!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=ISO-8859-1">
<link rel="shortcut icon" type="image/x-icon" href="img/ico.ico" />
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/estilos.css" rel="stylesheet">
    
    <link href="css/Mystyle.css" rel="stylesheet">
    <script src="http://cdn.ckeditor.com/4.6.1/standard/ckeditor.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/jscolor.js"></script>
<style>
/* tbody div{
    overflow:scroll;
    height:350px;
} */
.borderless table {
    border-top-style: none;
    border-left-style: none;
    border-right-style: none;
    border-bottom-style: none;
}
.viewtable>thead>tr>th
{
width:10%;
}

</style>
<style type="text/css">
footer {
  font-size: 9px;
  width:210mm;
  text-align: left;
  /* border-top:1px solid black;  */
}

@page {
  size: A4;
  margin: 9mm 17mm 17mm 17mm;
}

@media print {
  footer {
    position: fixed;
    bottom: 0;
    /* border-top:1px solid black;  */
    width:210mm;
    text-align:left;
    
  }
   body {
    width: 210mm;
    height: 297mm;
    
    
  }
  </style>
<title>Insert title here</title>
</head>
<body>

<form>

<div class="content">
 <div class="row">
    <div class="col-md-9" >
       <div class="panel panel-default" >
      
    
<div class="panel-body">
<table class="viewtable">
<thead>
<tr>
<th>
<div class="row">
<div class="col-xs-3" style="text-align:center; margin-top:50px;"><img src="<%=logo %>"></div>
<div class="col-xs-8">
<div style="width:80%;" align="center"><span style=" font-size:large;"><b><%=comp %></b></span></div>
<div style="width:80%;" align="center"><span style=" font-size:large;"><%=add1 %></span>
<br>
<span style=" font-size:large;"><%=add2 %></span><br>
<span style=" font-size:large;"><u><%=city %>-<%=zip %></u></span><br>
<span style=" font-size:large;"></span><br>
</div>

<div style="width:80%;" align="center"><span style=" font-size:large;"><b><%=ledgername %></b></span>
<br><span style=" font-size:large;">Ledger Account</span>
</div>
<div style="width:80%;" align="center"><span style=" font-size:large;"><%=addr %></span>
<br>
<%-- <span style=" font-size:large;"><b><%=add2 %></b></span><br>
<span style=" font-size:large;"><b><%=city %>-<%=zip %></b></span><br>
<span style=" font-size:large;"><b></b></span><br> --%>
</div>
<input type="hidden" id="demo" value="<%=from %>">
<input type="hidden" id="demo2" value="<%=to %>">
<div style="width:80%;" align="center"><span><p id="period"></p></span></div> 
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr><td>
<table class="viewtable table-borderless">
<thead>
<tr>
<th>Date</th>
<th>Vch.No.</th>
<th>Particular</th>
<th>Vch.Type</th>
<th style=" text-align:right; padding-right:0px;">Debit</th>
<th style=" text-align:right; padding-right:5px;">Credit</th>
</tr>
</thead>

<tbody>

<%
if(typ.equals("2"))
{
	rs=st.executeQuery("select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,(case when cash_cheque='cash' then 'Payment' else 'Cheque Payment' end) as vtype,credit_amt as debit,0 as credit from account_voucher_main where particular="+id+" and voucher_type='payment' and voucher_date between '"+from+"' and '"+to+"'"
			+" union" 
			+" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,'Receipt' as vtype,0,credit_amt from account_voucher_main where particular="+id+" and voucher_type='receipt' and voucher_date between '"+from+"' and '"+to+"'"
			+" union" 
			+" select 'Purchase' as parti, pinvoice_id,'purchase' as voucher_type, purchase_invoice_no,invoice_date_created,'Purchase' as vtype,0,total from ip_puchase_invoice where supplier_id="+ref_id+" and invoice_date_created between '"+from+"' and '"+to+"'"

	+" union "
	+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.particular)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O' and voucher_date between '"+from+"' and '"+to+"'"
	+"  union"
	
	+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',0 as debit,(select credit  from journalentry where type=2 and ref_no=tb.ref_no)credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=2  ) and type <>2 and created_date between '"+from+"' and '"+to+"'"
	+" union "
	+" select (select ledger_name from account_ledger where l_id=debit_note.purchase_ledger)parti,voucher_id,'debitnote' as voucher_type,voucher_no,voucher_date,'DebitNote' as vtype ,0 as debit,total as credit from debit_note where supplier="+ref_id+" and voucher_date between '"+from+"' and '"+to+"'"
			+" union "
			+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',(select debit from journalentry where type=1 and ref_no=tb.ref_no)debit,0 as credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=1  ) and type <>1 and created_date between '"+from+"' and '"+to+"' order by voucher_date desc");

}
else if(typ.equals("3"))
{
	rs=st.executeQuery("select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,(case when cash_cheque='cash' then 'Payment' else 'Cheque Payment' end) as vtype,credit_amt as debit,0 as credit from account_voucher_main where particular="+id+" and voucher_type='payment' and voucher_date between '"+from+"' and '"+to+"'"
			+" union" 
			+" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,'Receipt' as vtype,0,credit_amt from account_voucher_main where particular="+id+" and voucher_type='receipt' and voucher_date between '"+from+"' and '"+to+"'"
			+" union" 
			+" select 'Sales' as parti, sinvoice_id,'sales' as voucher_type, sales_invoice_no,invoice_date_created,'Sales' as vtype,total,0 from ip_sales_invoice where supplier_id="+ref_id+" and invoice_date_created between '"+from+"' and '"+to+"'"

	+" union "
	+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.particular)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O' and voucher_date between '"+from+"' and '"+to+"'"
+"  union"

+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',0 as debit,(select credit from journalentry where type=2 and ref_no=tb.ref_no)credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=2  ) and type <>2 and created_date between '"+from+"' and '"+to+"'"
		+" union "	
		+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',(select debit from journalentry where type=1 and ref_no=tb.ref_no)debit,0 as credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=1  ) and type <>1 and created_date between '"+from+"' and '"+to+"'"
	+" union "
	+" select (select ledger_name from account_ledger where l_id=credit_note.purchase_ledger)parti,voucher_id,'creditnote' as voucher_type,voucher_no,voucher_date,'CreditNote' as vtype ,total as debit,0 as credit from credit_note where supplier="+ref_id+" and voucher_date between '"+from+"' and '"+to+"' order by voucher_date desc");

}
else if(typ.equals("0") && under.equals("26"))
{
	rs=st.executeQuery(" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,'Receipt' as vtype,0 as debit,credit_amt as credit from account_voucher_main where particular="+id+" and voucher_type='receipt' and voucher_date between '"+from+"' and '"+to+"'"
			+" union"
	+" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,(case when cash_cheque='cash' then 'Payment' else 'Cheque Payment' end) as vtype,credit_amt as debit,0 as credit from account_voucher_main where particular="+id+" and voucher_type='payment' and voucher_date between '"+from+"' and '"+to+"'"		
	+" union "
	+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.particular)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O' and voucher_date between '"+from+"' and '"+to+"'"
+"  union"

+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',0 as debit,(select credit from journalentry where type=2 and ref_no=tb.ref_no)credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=2  ) and type <>2 and created_date between '"+from+"' and '"+to+"'"
		+" union "
		+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.particular)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O' and voucher_date between '"+from+"' and '"+to+"'"

		+" union "	
		+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no,'journal',tb.journal_no,created_date,'Journal',(select debit from journalentry where type=1 and ref_no=tb.ref_no)debit,0 as credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=1  ) and type <>1 and created_date between '"+from+"' and '"+to+"'"
	+" union "
	+" select (select ledger_name from account_ledger where l_id=credit_note.purchase_ledger)parti,voucher_id,'creditnote' as voucher_type,voucher_no,voucher_date,'CreditNote' as vtype ,total as debit,0 as credit from credit_note where supplier="+ref_id+" and voucher_date between '"+from+"' and '"+to+"' order by voucher_date desc");

}

else if(under.equals("15") || under.equals("16") || under.equals("17"))
{
	rs=st.executeQuery("select (select ledger_name from account_ledger where l_id=account_voucher_main.particular)parti, voucher_id,voucher_type, voucher_no,voucher_date,(case when cash_cheque='cash' then 'Payment' else 'Cheque Payment' end) as vtype,0 as debit,credit_amt as credit from account_voucher_main where account="+id+" and voucher_type='payment' and voucher_date between '"+from+"' and '"+to+"'"
			+" union" 
			+" select (select ledger_name from account_ledger where l_id=account_voucher_main.particular)parti, voucher_id,voucher_type, voucher_no,voucher_date,'Receipt' as vtype,credit_amt,0 from account_voucher_main where account="+id+" and voucher_type='receipt' and voucher_date between '"+from+"' and '"+to+"'"
			+" union"
			+" select (select ledger_name from account_ledger where l_id=contra_voucher.particular)parti,v_id,voucher_type,voucher_no,voucher_date,'Contra' as vtype,amount,0 from contra_voucher where account="+id+" and voucher_date between '"+from+"' and '"+to+"'"
			+" union "
	+" select (select ledger_name from account_ledger where l_id=contra_voucher.account)parti,v_id,voucher_type,voucher_no,voucher_date,'Contra' as vtype,0,amount from contra_voucher where particular="+id+" and voucher_date between '"+from+"' and '"+to+"' order by voucher_date desc");
	/* +" union" 
			
	+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.bill_no)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O'");
	 */
}
else /* if(typ.equals("1")) */
{
	rs=st.executeQuery("select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no as voucher_id,'journal' as voucher_type ,tb.journal_no as voucher_no,created_date as voucher_date ,'Journal' as vtype,0 as debit,(select credit from journalentry where type=2 and ref_no=tb.ref_no)credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=2  ) and type <>2 and created_date between '"+from+"' and '"+to+"'"
			+" union "	
			+" select (select ledger_name from account_ledger where l_id=tb.particulars)parti,tb.ref_no as voucher_id,'journal' as voucher_type ,tb.journal_no as voucher_no,created_date as voucher_date,'Journal' as vtype,(select debit from journalentry where type=1 and ref_no=tb.ref_no)debit,0 as credit from journalentry tb where ref_no in (select ref_no from journalentry where particulars="+id+" and type=1  ) and type <>1 and created_date between '"+from+"' and '"+to+"'"
					+" union "
					+" select (select ledger_name from account_ledger where l_id=account_voucher_sub.particular)parti ,voucher_id,voucher_type,(select voucher_no from account_voucher_main where voucher_id=account_voucher_sub.voucher_id) as voucher_no,voucher_date,(case when voucher_type='payment' then 'Payment' else 'Receipt' end) as voucher_type,(case when voucher_type='payment' then debit_amt else 0 end)as debit,(case when voucher_type='receipt' then debit_amt else 0 end)as credit  from account_voucher_sub where bill_no="+id+" and type='O' and voucher_date between '"+from+"' and '"+to+"'"

					+" union"
		+" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,(case when cash_cheque='cash' then 'Payment' else 'Cheque Payment' end) as vtype,credit_amt as debit,0 as credit from account_voucher_main where particular="+id+" and voucher_type='payment' and voucher_date between '"+from+"' and '"+to+"'"
				+" union" 
				+" select (select ledger_name from account_ledger where l_id=account_voucher_main.account)parti, voucher_id,voucher_type, voucher_no,voucher_date,'Receipt' as vtype,0,credit_amt from account_voucher_main where particular="+id+" and voucher_type='receipt' and voucher_date between '"+from+"' and '"+to+"'"
				+" union "
						+" select (select supplier_name from ip_suppliers where supplier_id=debit_note.supplier)parti,voucher_id,'debitnote' as voucher_type,voucher_no,voucher_date,'DebitNote' as vtype ,total as debit,0 as credit from debit_note where purchase_ledger="+id+" and voucher_date between '"+from+"' and '"+to+"'"
						+" union "
				+" select (select client_name from ip_clients where client_id=credit_note.supplier)parti,voucher_id,'creditnote' as voucher_type,voucher_no,voucher_date,'CreditNote' as vtype ,0 as debit,total as credit from credit_note where purchase_ledger="+id+" and voucher_date between '"+from+"' and '"+to+"' order by voucher_date desc");
}
i=0;
j=0;
while(rs.next())
{
	
	
	i=i+Double.parseDouble(rs.getString("credit"));
	j=j+Double.parseDouble(rs.getString("debit"));
	i1=String.format("%.2f", i);
	j1=String.format("%.2f", j);
	
%>

<tr>
<td ><%=rs.getString("voucher_date") %></td>
<td ><%=rs.getString("voucher_no") %></td>
<td ><%=rs.getString("parti") %></td>
<td ><%=rs.getString("vtype") %></td>
<td  align="right"><%=rs.getString("debit") %></td>
<td  align="right"><%=rs.getString("credit") %></td>
</tr>
<%}%>




<%
rs=st.executeQuery("select * from account_ledger where l_id="+id+"");
while(rs.next())
{
	String opbaltype=rs.getString("dr_cr");
	if(opbaltype.equals("C"))
	{
		cr=opbal;
		dr="0.00";
	}
	else
	{
		dr=opbal;
		cr="0.00";
	}
}
%>
<tr  style="border-top:1px solid black;">
 <td colspan="4" align="right" >Opening Balance: </td>
            <td align="right" style="padding-right:0px;"> <span ><b><%=dr %></b></span></td>
            <td  align="right" style="padding-right:5px;"><span ><b><%=cr %></b></span></td>
            

</tr>
        <tr>
        <td colspan="4" align="right" >Current Balance: </td>
            <td align="right" style="padding-right:0px;"> <span ><b><%=j1 %></b></span></td>
            <td  align="right" style="padding-right:5px;"><span ><b><%=i1 %></b></span></td>
            
        </tr>
        <%
            
            if(i>j)
            {
             s=Double.parseDouble(cr)+i-(j+Double.parseDouble(dr));
              
             sum = String.format("%.2f", s);
             sum2="";
             
            }
            else
            {
            	su=Double.parseDouble(dr)+j-(i+Double.parseDouble(cr));
            	sum2 = String.format("%.2f", su);
            	sum=""; 
            }
            	
            %>
        <tr>
        <td   colspan="4" align="right" >Closing Balance: </td>
          <td align="right" style="padding-right:0px;"><b><%=sum2 %></b>  </td>
           <td align="right" style="padding-right:5px;"><b><%=sum %></b>  </td>
        </tr>
        
   </tbody> 
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</form>

</body>
<script type="text/javascript">
function goBack() {
    window.history.back(); 
};

   

</script>
<script>
$(document).ready(function(){
	
	var d = new Date($("#demo").val());
	var curr_date = d.getDate();
	var curr_month = d.getMonth() + 1; //Months are zero based
	var curr_year = d.getFullYear();
	//alert(curr_date + "-" + curr_month + "-" + curr_year);
	
	var e = new Date($("#demo2").val());
	var curr_date2 = e.getDate();
	var curr_month2 = e.getMonth() + 1; //Months are zero based
	var curr_year2 = e.getFullYear();
	//alert(curr_date2 + "-" + curr_month2 + "-" + curr_year2);
	
	//alert(curr_date + "-" + curr_month + "-" + curr_year + " to " +curr_date2 + "-" + curr_month2 + "-" + curr_year2 )
	document.getElementById("period").innerHTML =(curr_date + "-" + curr_month + "-" + curr_year + " to " +curr_date2 + "-" + curr_month2 + "-" + curr_year2 );

});
</script>
</html>