<?PHP 
include("header.php");
//session_start();
//error_reporting(0);
include "checksession.php";
include "include/db-connect.php";
//....Tamil font......
//mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
//.................
?>
  <div id="content">
  <div class="breadcrumb">
      </div>
              <div class="box">
    <div class="heading">
      <h1><img src="view/image/home.png" alt="" />Supplier Details</h1>
    </div>
    <div class="content">
      <div class="overview" style="width:80%; margin-left:170px;">
        <div class="dashboard-heading">   Supplier Details
         </div>
        <div class="dashboard-content">
<?php
if($_REQUEST['add'] == 'success') {echo $result= '<h4 class="alert_success">Category Added Success </h4>';}
if($_REQUEST['edit'] == 'sucess') {echo $result= '<h4 class="alert_success">Category Edited Success </h4>';}
if($_REQUEST['deactive'] == 'success') {echo $result= '<h4 class="alert_success">Deactivated Successfully </h4>';}
if($_REQUEST['delete'] == 'sucess') {echo $result= '<h4 class="alert_success">Category Deleted Success </h4>';}
?>		

  <table class="list" cellspacing="0" > 
			<thead> 
                 <tr>
                    <td class="left">Purchase Date</td>
                    <td class="left">PID</td>
                    <td class="left">Product Name</td>
                    <td class="left">Quantity</td> 
                    <td class="left">Cost</td>
                    <td class="left">Total Cost</td> 
                    <td class="left">Tax</td>
                    <td class="left">Total Tax</td>
                    <td class="left">Price</td>
                    <td class="left">Total Price</td>
                    <td class="left">Payment Options</td>
                    <td class="left">Supplier Name</td>
                    <td class="left">Bill No</td>
                   <td widtd="4%">Options</td>
              </tr>
              </thead>
			<tbody> 
			<?php 
			$dis1=("select count(*) as num  from ".$purch."");		
		$total_pages = mysql_fetch_array(mysql_query($dis1));
    $total_pages = $total_pages[num];
$targetpage =""; //your file name (the name of this file)
$limit = 30; //how many items to show per page
$page = $_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0;

if ($page == 0) $page = 1; 
$prev = $page - 1; 
$next = $page + 1; 
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1; //last page minus 1
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev \"> Previous &nbsp;</a>";
else
$pagination.= "<span class=\"disabled\"> Previous &nbsp;</span>";

//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter &nbsp;</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter &nbsp;</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1 \">$lpm1 &nbsp;</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage \">$lastpage &nbsp;</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1 \">1 &nbsp;</a>";
$pagination.= "<a href=\"$targetpage?page=2 \">2 &nbsp;</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter &nbsp;</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1 \">$lpm1 &nbsp;</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage \">$lastpage &nbsp;</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1 \">1 &nbsp;</a>";
$pagination.= "<a href=\"$targetpage?page=2 \">2 &nbsp;</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter &nbsp;</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter \">$counter &nbsp;</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next \">Next  &nbsp;</a>";
else
$pagination.= "<span class=\"disabled\">Next  &nbsp;</span>";
$pagination.= "</div>\n";
}

		$qur="select * from ".$purch." order by id desc limit $start, $limit"; 
		$result = mysql_query($qur)or die('Have an error in viewing data'.mysql_error());
		while ($row_section = mysql_fetch_array($result)) 
			{
    				$id= $row_section['id'];
                   $id=base64_encode($id);
                   $product_id= $row_section['product_id'];
				   
				   $product_name= $row_section['product_name'];
					$real_cost= $row_section['real_cost'];
				 	$quantity= $row_section['quantity'];	             
				  	$tot_amount= $row_section['tot_amount'];
					$supplier_name= $row_section['supplier_name'];
					$bill_num= $row_section['bill_num'];
					$payment_option= $row_section['payment_option'];
				  	$purchase_date= $row_section['purchase_date'];
				    $pur_tax= $row_section['pur_tax'];
					$tot_tax= $row_section['tot_tax'];
					$per_pro_amnt= $row_section['per_pro_amnt'];
					$tot_pro_amnt= $row_section['tot_pro_amnt'];
					$havetopay= $row_section['havetopay'];
			  ?>	    
				 
			    <tr> 
                <td class="left"><?php echo $purchase_date; ?> </td>
                <td class="left"><?php echo $product_id; ?> </td>
                <td class="left"><?php echo $product_name; ?> </td>
                <td class="left"><?php echo $quantity; ?> </td>
                <td class="left"><?php echo $real_cost; ?> </td>
                <td class="left"><?php echo $tot_amount; ?> </td>
                <td class="left">Rs.<?php echo $pur_tax; ?> </td>
                <td class="left">Rs.<?php echo $tot_tax; ?> </td>
                <td class="left">Rs.<?php echo $per_pro_amnt; ?> </td>
                <td class="left">Rs.<?php echo $tot_pro_amnt; ?> </td>
                <!--<td><?php echo $havetopay; ?> </td>-->
                <td class="left"><?php echo $payment_option; ?> </td>
                <td class="left"><?php echo $supplier_name; ?> </td>
                <td class="left"><?php echo $bill_num; ?> </td>
   				<td class="left"><!--<a href="edit_pur.php?id=<?php echo $id; ?>"><img src="../images/edit.jpg" height="30" width="30" title="Edit"></a> -->
                <a href="delete_pur.php?pid=<?php echo $product_id; ?>&&date=<?php echo $purchase_date; ?>&&id=<?php echo $id; ?>&&amt=<?php echo $tot_pro_amnt; ?>&&qnty=<?php echo $quantity; ?>&&payopt=<?php echo $payment_option; ?>" onclick="return confirm('You Confirm Delete This Purchase Details.');">
                <img src="images/delete.jpg" height="15" width="15" title="Delete">
                </a>
                </td>     
				</tr> 	 
<?php } ?> 
			</tbody> 
            
			</table>
          
   
        </div>
        <div align="right"><?php echo $pagination; ?> 	</div>	
      </div>
      
      
    </div>
  </div>
</div>
</div>
<?  include("footer.php"); ?>