<?php
session_start();
include '../../db_connect.php';

function date_formatc($temp_date)
{
list($year, $month, $day) = explode('-', $temp_date);
return "$day/$month/$year";
}

$today_date=date("d/m/Y");
$from_date = $today_date;
$to_date = $today_date;

$cmp_key=$_POST['cmp_key'];


if(trim($_POST['from_date']))
$from_date =$_POST['from_date'];

if(trim($_POST['to_date']))
$to_date =$_POST['to_date'];

$sql="";
if($_POST['sortby']=='BUYER'){
	
	$qrypart="and buyercode like '". $_POST['searchtype']."%'";
	}
/*else if($_POST['sortby']=='SHIPVIA'){
	$qrypart="and shipvia like '". $_POST['searchtype']."%'";
	}*/
else if($_POST['sortby']=='orderid'){
	$qrypart="and orderid like '". $_POST['searchtype']."%'";
	}
	else
	{
	//$qrypart="where  orderdate between STR_TO_DATE('$from_date','%d/%m/%Y') and STR_TO_DATE('$to_date','%d/%m/%Y')";	
	$qrypart="";
		}
$sql = "select * from  drcrnotereg  where drcrtype = 'debitnote'  $qrypart order by orderid desc";

if(isset($_POST['next_rec']))
$sql=$sql." limit $_POST[next_rec],200";

	if($result = mysqli_query($con,$sql))
	{
	$no_of_rec=mysqli_num_rows($result);
	if($no_of_rec==0)
	echo "";
	else{
	$show_rec=$no_of_rec;
	if($no_of_rec>200)
	{
	$result = mysqli_query($con,$sql." limit 0,200");
	$show_rec=$_POST[next_rec]+mysqli_num_rows($result);
	}
	echo "<table id='demotable' border='1' bordercolor='#053400'  width='100%' cellspacing='0' ><thead><tr>
	<th ><textarea name='orderid[]'>ORDER ID</textarea></th>
	<th ><textarea name='orderdate[]'>ORDER DATE</textarea></th>
	<th ><textarea name='buyercode[]'>BUYER</textarea></th>
	<th><textarea name='agentcode[]'>AGENT</textarea></th>
	<th ><textarea name='dlvdate[]'>DLVDATE</textarea></th>
	<th ><textarea name='shipto[]'>SHIP TO</textarea></th>
	<th><textarea name='shipvia[]'>SHIP VIA</textarea></th>
	<th><textarea name='status[]'>STATUS</textarea></th>
	</tr></thead><tbody>";
	while($row = mysqli_fetch_array($result))
	{
	
	
  	echo "<tr><td  ><a href='debitentry.php?orderid=$row[orderid]' onClick='positionedPopup(this.href,1200,650);return false'><textarea name ='orderid[]' >$row[orderid]</textarea></a></td>
<td><textarea name ='orderdate[]'>".date_formatc($row[orderdate])."</textarea></td>
<td><textarea name ='buyercode[]' class ='buyercode'>$row[buyercode]</textarea></td>

<td><textarea name ='agentcode[]' class ='agentcode' >$row[agentcode]</textarea></td>
<td><textarea name ='dlvdate[]' class ='dlvdate'>".date_formatc($row[dlvdate])."</textarea></td>
<td><textarea name ='shipto[]'>$row[shipto]</textarea></td>
<td><textarea name ='shipvia[]' class ='shipvia'  >$row[shipvia]</textarea></td>
<td><textarea name ='status[]' class='status' >$row[status]</textarea></td>
</tr>";
}
$temp_var=0;
if(isset($_POST['next_rec']))
$temp_var=$_POST['next_rec'];

if(isset($_POST[tot_rec]))
$no_of_rec=$_POST[tot_rec];

echo "</tbody></table>###<div style='float:left;font-weight: bold;color: #000;width:30%;padding:5px'>Showing records ".($_POST[next_rec]+1)."-".($show_rec+$temp_var)." of  <span id='tot_rec'>".($no_of_rec)."</span></div>";

if($no_of_rec>200||isset($_POST['next_rec']))
{
echo "<div style='text-align: right;font-weight: bold;color: #000;padding:5px;width:30%;float: left;'>";
for($i=0;($no_of_rec/200)>0;$i++,$no_of_rec-=200)
echo "<span class='links'><a style='color:#000' class='linkspages' href='#' id=".($i*200).">".($i+1)."</a></span>";
echo "</div>";
}
	}
	}
	else 
	echo mysqli_error($con);


mysqli_close($con);
?>


