Current File : //home/obabain/ms_obaba_in/ViewProformaInvoices.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ include file="Connection.jsp" %>
    <%!
public int nullIntconv(String str)
{   
    int conv=0;
    if(str==null)
    {
        str="0";
    }
    else if((str.trim()).equals("null"))
    {
        str="0";
    }
    else if(str.equals(""))
    {
        str="0";
    }
    try{
        conv=Integer.parseInt(str);
    }
    catch(Exception e)
    {
    }
    return conv;
}
%>
     <%
    
	Statement st=con.createStatement();
     ResultSet rsRowCnt = null;
     
     int iShowRows=20;  // Number of records show on per page
     int iTotalSearchRecords=10;  // Number of pages index shown
      
     int iTotalRows=nullIntconv(request.getParameter("iTotalRows"));
     int iTotalPages=nullIntconv(request.getParameter("iTotalPages"));
     int iPageNo=nullIntconv(request.getParameter("iPageNo"));
     int cPageNo=nullIntconv(request.getParameter("cPageNo"));
     String filt=request.getParameter("filter");
     if(iPageNo==0)
     {
         iPageNo=0;
     }
     else{
         iPageNo=Math.abs((iPageNo-1)*iShowRows);
     }
     int iStartResultNo=0;
     int iEndResultNo=0;
     
     
	%>
<!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">
<title>Sales invoice</title>
<script src='https://code.jquery.com/jquery-3.3.1.js'></script>   
 <script src='https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'></script> 
 <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js" charset="utf-8"></script> 

 

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">

<script>
<script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>

<style>
.dropbtn {
  background-color: #009191;
  color: white;
  padding: 5px;
  font-size: 13px;
  border: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 120px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {background-color: #ddd;}

.dropdown:hover .dropdown-content {display: block;}

.dropdown:hover .dropbtn {background-color: #009191;}

</style>

</head>
<body>
<%@include file="master.jsp" %>
<form>


<div class="content">
<div class="row">
<div class="col-md-9"  style="background-color:#eae9e9;width:80%;">
<div class="panel panel-default" >
       <div class="panel-heading main-color-bg">
        <h3 class="panel-title">Proforma Invoices</h3>
              </div>
             </div>
             <!-- <div class="col-md-4" >
                         <input type="text" id="search" placeholder="Type to search">
                      </div> -->
             

<div class="headerbar-item pull-right"  style="margin-top:10px;"><a style="background:#009191" class="btn btn-info" onclick="goBack()">Back</a>
<a class="btn btn-info" style="background:#009191"  href="ProformaInvoiceMain.jsp">New</a>
</div>
<div>
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="iShowRows" value="<%=iShowRows%>">
<table id="example" class="table table-striped table-bordered "width="100%">
<thead>
<tr>
<!-- <th>Status</th> -->
<th>Date</th>                                                                                                                   
<th> Proforma Invoice No.</th>
<th>Client</th>
<th>Total</th>
<th>Balance</th>
<th>options</th>

</tr>
</thead>
<tbody>
<%
ResultSet rs=null;
if(filt==null)
{
	rsRowCnt=st.executeQuery("select count(*)as cnt from ip_proforma_invoice");
    if(rsRowCnt.next())
    {
       iTotalRows=rsRowCnt.getInt("cnt");
    }
 rs=st.executeQuery("select tb.*,(select client_name from ip_clients  where client_id=tb.supplier_id)suppl,(select description from ip_status where id=tb.salesinv_status)stat,(tb.total-IFNULL(tb.received_amt,0)) bal  from ip_proforma_invoice tb order by sinvoice_id desc limit "+iPageNo+","+iShowRows+"");
}
else
{
	rsRowCnt=st.executeQuery("select count(*)as cnt from ip_proforma_invoice where  supplier_id in(select client_id from ip_clients where client_name like '%"+filt+"%' and branch_id="+loginid+") and branch_id="+loginid+"");
	if(rsRowCnt.next())
    {
       iTotalRows=rsRowCnt.getInt("cnt");
    }
	 rs=st.executeQuery("select tb.*,(select client_name from ip_clients  where client_id=tb.supplier_id)suppl,(select description from ip_status where id=tb.salesinv_status)stat,(tb.total-IFNULL(tb.received_amt,0)) bal from ip_proforma_invoice tb where supplier_id in(select client_id from ip_clients where client_name like '%"+filt+"%' )  order by sinvoice_id desc limit "+iPageNo+","+iShowRows+"");
	}
	
	
while(rs.next())
{
%>
<tr>


<%-- <td><%=rs.getString("stat") %></td> --%>
<td><%=rs.getString("invoice_date_created")%></td>
<%-- <td><a href="wasteViewSIbyNO.jsp?Id=<%=rs.getString("sinvoice_id")%>">
<%=rs.getString("sales_invoice_no")%></a></td> --%>

<td><a href="ViewPRbyNO.jsp?Id=<%=rs.getString("sinvoice_id")%>">
<%=rs.getString("sales_invoice_no")%></a></td> 
<td><%=rs.getString("suppl") %></td>
<td><%=rs.getString("total")%></td>
<td><%=rs.getString("bal")%></td>



<td>
<div class="dropdown">
  <button class="dropbtn">Options</button>
  <div class="dropdown-content">
  <a href="prpdf.jsp?Id=<%=rs.getString("sinvoice_id")%>&inv=<%=rs.getString("type")%>&type=Original Copy For Customer"><span class="fontstyle">Download PDF(Original)</span></a>
<a href="prpdf.jsp?Id=<%=rs.getString("sinvoice_id")%>&inv=<%=rs.getString("type")%>&type=Duplicate Copy For Transporter"><span class="fontstyle">Download PDF(Duplicate)</span></a>
<a href="prpdf.jsp?Id=<%=rs.getString("sinvoice_id")%>&inv=<%=rs.getString("type")%>&type=Triplicate Copy For Supplier"><span class="fontstyle">Download PDF(Triplicate)</span></a>
<a href="prpdf.jsp?Id=<%=rs.getString("sinvoice_id")%>&inv=<%=rs.getString("type")%>&type=Extra copy"><span class="fontstyle">Download PDF(Extra)</span></a>
<%-- <a href="Editsalesinvoice.jsp?Id=<%=rs.getString("sinvoice_id")%>"><span class="fontstyle">Edit</span></a> --%>
<a href="deleteprInvoice.jsp?Id=<%=rs.getString("sinvoice_id")%>" onclick = "if (! confirm('Continue?')) { return false; }">
<span class="fontstyle">Delete</span>
</a>
  </div>
</div>

</td>


<%} %>
</tr>
<%
  //// calculate next record start record  and end record 
        try{
            if(iTotalRows<(iPageNo+iShowRows))
            {
                iEndResultNo=iTotalRows;
            }
            else
            {
                iEndResultNo=(iPageNo+iShowRows);
            }
            
            iStartResultNo=(iPageNo+1);
            iTotalPages=((int)(Math.ceil((double)iTotalRows/iShowRows)));
         
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
 
%><tr>
<td colspan="5" align="center">
<div>
<%
        //// index of pages 
         
        int i=0;
        int cPage=0;
         if(filt==null)
         {
        
        if(iTotalRows!=0)
        {
        cPage=((int)(Math.ceil((double)iEndResultNo/(iTotalSearchRecords*iShowRows))));
         
        int prePageNo=(cPage*iTotalSearchRecords)-((iTotalSearchRecords-1)+iTotalSearchRecords);
        if((cPage*iTotalSearchRecords)-(iTotalSearchRecords)>0)
        {
         %>
          <a href="ViewInvoices.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
         <%
        }
         
        for(i=((cPage*iTotalSearchRecords)-(iTotalSearchRecords-1));i<=(cPage*iTotalSearchRecords);i++)
        {
          if(i==((iPageNo/iShowRows)+1))
          {
          %>
           <a href="ViewInvoices.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
          <%
          }
          else if(i<=iTotalPages)
          {
          %>
           <a href="ViewInvoices.jsp?iPageNo=<%=i%>"><%=i%></a>
          <% 
          }
        }
        if(iTotalPages>iTotalSearchRecords && i<iTotalPages)
        {
         %>
         <a href="ViewInvoices.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a> 
         <%
        }
        }
         }
         else{
        	 
             if(iTotalRows!=0)
             {
             cPage=((int)(Math.ceil((double)iEndResultNo/(iTotalSearchRecords*iShowRows))));
              
             int prePageNo=(cPage*iTotalSearchRecords)-((iTotalSearchRecords-1)+iTotalSearchRecords);
             if((cPage*iTotalSearchRecords)-(iTotalSearchRecords)>0)
             {
              %>
               <a href="ViewInvoices.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>&filter=<%=filt%>"> << Previous</a>
              <%
             }
              
             for(i=((cPage*iTotalSearchRecords)-(iTotalSearchRecords-1));i<=(cPage*iTotalSearchRecords);i++)
             {
               if(i==((iPageNo/iShowRows)+1))
               {
               %>
                <a href="ViewInvoices.jsp?iPageNo=<%=i%>&filter=<%=filt%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
               <%
               }
               else if(i<=iTotalPages)
               {
               %>
                <a href="ViewInvoices.jsp?iPageNo=<%=i%>&filter=<%=filt%>"><%=i%></a>
               <% 
               }
             }
             if(iTotalPages>iTotalSearchRecords && i<iTotalPages)
             {
              %>
              <a href="ViewInvoices.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>&filter=<%=filt%>"> >> Next</a> 
              <%
             }
             }
         }
      %>
      <span style="margin-left:50px;"><b>Rows <%=iStartResultNo%> - <%=iEndResultNo%>   Total Result  <%=iTotalRows%> </b></span>

</tbody>

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