Current File : /home/obabain/khb_obaba_in/ledgerById.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;
     %>
     <%
     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 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");
     }
     %>
<!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">

   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"  rel="stylesheet">
    <link href="css/select2.min.css" rel="stylesheet">
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.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>
<title>Insert title here</title>
</head>
<body>
<%@include file="master.jsp" %>
<form action="ledgerByIdDA.jsp">

<div class="content">
 <div class="row">
    <div class="col-md-9" >
       <div class="panel panel-default" >
       <div class="panel-heading main-color-bg">
        <h3 class="panel-title">Ledger Vouchers</h3>
    </div>
    
<div class="panel-body">
<input type="hidden" value="<%=id %>" name="Id">
<div class="headerbar-item pull-right" style="margin-top:10px;"><a class="btn btn-info" style="background:#204b58"   onclick="goBack()">Back</a>
<a class="btn btn-info" href="ledgerByIdpdfFrame.jsp?Id=<%=id %>&from=<%=from %>&to=<%=to %>" style="background:#204b58" >Print</a>
<a  class="btn btn-info"  style="background:#204b58"  data-toggle="modal" data-target="#myModalledg">Period</a>
</div>
<div class="row">
<!-- <div class="form-group col-xs-2">From date<input type="text" class="form-control" id="datetimepicker"></div><div  class="form-group col-xs-2"> To date<input type="text" id="datetimepicker2" class="form-control"></div> -->
<div class="form-group col-xs-4"><span style=" font-size:large; margin-left:20px;"><b><%=ledgername %></b></span></div>
</div>
<table class="table">
<thead>
<tr>
<th style="width:150px;">Date</th>
<th style="width:150px;">Vch.No.</th>
<th style="width:150px;">Particular</th>
<th style="width:140px;">Vch.Type</th>
<th style="width:170px; text-align:right;">Debit</th>
<th style="width:170px; text-align:right; padding-right:30px;">Credit</th>
</tr>
</thead>

<tbody>
<tr>
<td colspan="6">
 <div class="scrollit">
 <table class="viewtable table-borderless viewtable-hover">
 

<%
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 style="width:150px;"><%=rs.getString("voucher_date") %></td>
<td style="width:150px;"><a href="editVouchLedgerwise.jsp?Id=<%=rs.getString("voucher_id") %>&type=<%=rs.getString("voucher_type") %>"><%=rs.getString("voucher_no") %></a></td>
<td style="width:150px;"><%=rs.getString("parti") %></td>
<td style="width:150px;"><%=rs.getString("vtype") %></td>
<td style="width:150px;" align="right"><%=rs.getString("debit") %></td>
<td style="width:150px;" align="right"><%=rs.getString("credit") %></td>
</tr>
<%}%>
</table>
</div>
</td>
</tr>
</tbody>
<tfoot>
<%
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>
 <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:30px;"><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:30px;"><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:30px;"><b><%=sum %></b>  </td>
        </tr>
        
    </tfoot>
</table>
</div>
<div class="modal fade" id="myModalledg" role="dialog" >
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
        
        
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          
        </div>
        <div class="modal-body">
         <div class="panel-body">
  <div>
  <div class="row">
       	 <div class="col-xs-6">
       	 From
         <input type="date" class="form-control" name="fromdate">
        </div>
       <div class="col-xs-6">
       To
         <input type="date" class="form-control" name="todate">
        </div>
        </div>
                      
                      </div>

 
</div>
        </div>
        <div class="modal-footer">
         <input type="submit" value="Search" class="btn btn-primary">   
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
</div>
</div>

</form>
<%@include file="footer.jsp" %>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></script>
    <script src="js/select2.min.js"></script>
    <script src="js/jquery.datetimepicker.full.js"></script>
   
    <script>
    $('select').select2();
    </script>
     <script>
     jQuery('#datetimepicker').datetimepicker({
    	 timepicker:false,
    	 todayBtn: "linked"
    	 //mask:true, // '9999/19/39 29:59' - digit is the maximum possible for a cell
    	});
     
     jQuery('#datetimepicker2').datetimepicker({
    	 timepicker:false,
    	 todayBtn: "linked"
    	 //mask:true, // '9999/19/39 29:59' - digit is the maximum possible for a cell
    	});
    </script>
</body>
<script type="text/javascript">
function goBack() {
    window.history.back(); 
};  

</script>

</html>