<?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'];


if($_GET['mode']=="ptview"){
	
	$sql="";
if($_POST['fromtype']=='order'){
	
	$qrypart="SELECT job_id, prodname as `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, sordervar.`mrp` FROM sordervar inner join prodreg on prodreg.code = sordervar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	}
else if($_POST['fromtype']=='Packinglist'){
	$qrypart="SELECT job_id, prodname as `code`, gencode as `gencode`, cat as `desc`,subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, spacklistvar.`mrp` FROM spacklistvar inner join prodreg on prodreg.code = spacklistvar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	}
else if($_POST['fromtype']=='Invoice'){
	$qrypart="SELECT job_id, prodname as `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, sinvoicevar.`mrp` FROM sinvoicevar inner join prodreg on prodreg.code = sinvoicevar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	}
else if($_POST['fromtype']=='Productreg'){
	$qrypart="SELECT job_id, `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, prodvar.size as `size`, prodvar.qnty as `qnty`, `cat`, `color`, prodvar.`mrp` FROM prodreg inner join prodvar on code = prodname WHERE prodname like '". $_POST['valueid']."%'";
	
	}
	else
	{
	//$qrypart="where  issdate between STR_TO_DATE('$from_date','%d/%m/%Y') and STR_TO_DATE('$to_date','%d/%m/%Y')";
	$qrypart="";	
	}
		
	//echo $qrypart;	
$sql = "$qrypart";

	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='2500' cellspacing='0' ><thead><tr>
	<th ><textarea name='coname[]'>Co_Name</textarea></th>
	<th ><textarea name='ordno[]'>Order_No</textarea></th>
	<th ><textarea name='pono[]'>PO_No</textarea></th>
	<th ><textarea name='invno[]'>Invoice_No</textarea></th>
	<th ><textarea name='sodate[]'>SO_Date</textarea></th>
	<th ><textarea name='invdate[]'>Invoice_Date</textarea></th>
	<th ><textarea name='barcode[]'>Barcode</textarea></th>
	<th ><textarea name='skucode[]'>SKU_code</textarea></th>
	<th ><textarea name='cat[]'>Category</textarea></th>
	<th ><textarea name='product[]'>Product</textarea></th>
	<th ><textarea name='style[]'>Style</textarea></th>
	<th ><textarea name='type[]'>Type</textarea></th>
	<th ><textarea name='typeabrv[]'>Type_Abrv</textarea></th>
	<th ><textarea name='shade[]'>Shade</textarea></th>
	<th ><textarea name='unit[]'>Unit</textarea></th>
	<th ><textarea name='brand[]'>Brand</textarea></th>
	<th ><textarea name='lot[]'>Lot</textarea></th>
	<th ><textarea name='size[]'>Size</textarea></th>
	<th ><textarea name='qty[]'>Quantity</textarea></th>
	<th ><textarea name='mrp[]'>MRP</textarea></th>
	<th ><textarea name='wsp[]'>WSP</textarea></th>
	<th ><textarea name='consigname[]'>Consignee_Name</textarea></th>
	<th ><textarea name='consigcity[]'>Consignee_City</textarea></th>
	<th ><textarea name='transname[]'>Transporter_Name</textarea></th>
	<th ><textarea name='mrpdiff[]'>MRP_DIFF</textarea></th>
	<th ><textarea name='wspdiff[]'>WSP_DIFF</textarea></th>
	<th ><textarea name='season[]'>SEASON</textarea></th>
	<th ><textarea name='quality[]'>QUALITY</textarea></th>
	</tr></thead><tbody>";
	while($row = mysqli_fetch_array($result))
	{
	$highlight='';
	
	$statusArray = $_SESSION[SESS_STATUSARR];
  	echo "<tr><td ><textarea name='coname[]'>".$_SESSION['SESS_CMP']."</textarea></td>
	<td ><textarea name='ordno[]'>$row[job_id]</textarea></td>
	<td ><textarea name='pono[]'></textarea></td>
	<td ><textarea name='invno[]'></textarea></td>
	<td ><textarea name='sodate[]'></textarea></td>
	<td ><textarea name='invdate[]'></textarea></td>
	<td ><textarea name='barcode[]'></textarea></td>
	<td ><textarea name='skucode[]'>$row[sku]</textarea></td>
	<td ><textarea name='cat[]'>$row[cat]</textarea></td>
	<td ><textarea name='product[]'>$row[code]</textarea></td>
	<td ><textarea name='style[]'>$row[gencode]</textarea></td>
	<td ><textarea name='type[]'>$row[subcat]</textarea></td>
	<td ><textarea name='typeabrv[]'>$row[subcat]</textarea></td>
	<td ><textarea name='shade[]'>$row[color]</textarea></td>
	<td ><textarea name='unit[]'></textarea></td>
	<td ><textarea name='brand[]'></textarea></td>
	<td ><textarea name='lot[]'></textarea></td>
	<td ><textarea name='size[]'>$row[size]</textarea></td>
	<td ><input name='qty[]' value='$row[qnty]' style='border: none;text-align: center;    padding: 8px 0px;width:70%' /></td>
	<td ><textarea name='mrp[]'>$row[mrp]</textarea></td>
	<td ><textarea name='wsp[]'></textarea></td>
	<td ><textarea name='consigname[]'></textarea></td>
	<td ><textarea name='consigcity[]'></textarea></td>
	<td ><textarea name='transname[]'></textarea></td>
	<td ><textarea name='mrpdiff[]'></textarea></td>
	<td ><textarea name='wspdiff[]'></textarea></td>
	<td ><textarea name='season[]'></textarea></td>
	<td ><textarea name='quality[]'></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='links1'><a style='color:#000' class='linkspages1' href='#' id=".($i*200).">".($i+1)."</a></span>";
	  echo "</div>";
	  }
	}
  }
  else 
  echo mysqli_error($con);
	
	}


	else{
	$sql="";
	if($_POST['fromtype']=='order')
	{
	$qrypart="SELECT prodname as `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, sordervar.`mrp` FROM sordervar inner join prodreg on prodreg.code = sordervar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	}
	else if($_POST['fromtype']=='Packinglist')
	{
	$qrypart="SELECT prodname as `code`, gencode as `gencode`, cat as `desc`,subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, spacklistvar.`mrp` FROM spacklistvar inner join prodreg on prodreg.code = spacklistvar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	}
  else if($_POST['fromtype']=='Invoice')
  	{
	  $qrypart="SELECT prodname as `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, size as `size`, qnty as `qnty`, `cat`, `color`, sinvoicevar.`mrp` FROM sinvoicevar inner join prodreg on prodreg.code = sinvoicevar.prodname WHERE job_id like '". $_POST['valueid']."%'";
	 }
  else if($_POST['fromtype']=='Productreg')
  	{
	//   $qrypart="SELECT `code`, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,size) sku, prodvar.size as `size`, prodvar.qnty as `qnty`, `cat`, `color`, prodvar.`mrp` FROM prodreg inner join prodvar on code = prodname WHERE prodname like '". $_POST['valueid']."%'";
	$qrypart="SELECT id, code, gencode as `gencode`, cat as `desc`, subcat as `subcat`, CONCAT(code,color) sku,  stock, '1' as qnty, cat, color, round(grtotal+grtotal*40/100) as mrp FROM prodreg  WHERE code like '". $_POST['valueid']."%'";
	  }
	else
	{
	//$qrypart="where  issdate between STR_TO_DATE('$from_date','%d/%m/%Y') and STR_TO_DATE('$to_date','%d/%m/%Y')";
	$qrypart="";	
		}
		
	//echo $qrypart;	
	$sql = "$qrypart";

	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='cat[]'>Product Code</textarea></th>
	<th ><textarea name='qty[]'>Quantity</textarea></th>
	<th ><textarea name='styleno[]'>Style No</textarea></th>
	<th ><textarea name='productcode[]'>Style Code</textarea></th>
	<th ><textarea name='color[]'>Color</textarea></th>
	<th ><textarea name='fit[]'>Fit</textarea></th>
	<th ><textarea name='sku[]'>BarCode/Sku</textarea></th>
	<th ><textarea name='Size[]'>Size</textarea></th>
	<th ><textarea name='MRP[]'>MRP</textarea></th>
	</tr></thead><tbody>";
	while($row = mysqli_fetch_array($result))
	{
	$highlight='';
	
	$statusArray = $_SESSION[SESS_STATUSARR];
  	echo "<tr><td><textarea name ='cat[]' >$row[cat]</textarea></td>
	<td><input name='qty[]' value='$row[qnty]' style='border: none;text-align: center;    padding: 8px 0px;width:70%' /></td>
	<td><textarea name ='styleno[]'>$row[gencode]</textarea></td>
	<td><textarea name ='productcode[]' >$row[code]</textarea></td>
	<td><textarea name ='color[]'>$row[color]</textarea></td>
	<td><textarea name ='fit[]'>$row[subcat]</textarea></td>
	<td><textarea name ='barcodevalue[]' class='barcodevalue'>$row[sku]</textarea></td>
	<td><textarea name ='Size[]' class ='Size'>$row[size]</textarea></td>
	<td><textarea name ='MRP[]' class ='MRP' >$row[mrp]</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);
?>


