<?php
date_default_timezone_set("Asia/Kolkata");
 error_reporting(0);
ob_start();
session_start();
 
	include("../../include/db.php");

	function get_item_id_media_print($item_name4)
{
$sql_query11="select * from consumable_creation where id='$item_name4' and item='Ink' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $particulars=$rsdata11->particulars;

 } 
 return $particulars;
}

 

  $roll_size=$_GET['roll_size'];
 $item_id4=$_GET['item_name'];
 $type_1=$_GET['type_1'];
 $item_name4=get_item_id_media_print($item_id4);

 $from_date=$_GET['from_date'];
 $to_date=$_GET['to_date'];
 $cur_date=date("Y-m-d");
if($from_date!=""){ $from_date1= "DATE_FORMAT(entrydates,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(entrydates,'%Y-%m-%d')='$cur_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(entrydates,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(entrydates,'%Y-%m-%d')='$cur_date'";}
if($roll_size!=""){ $roll_size41 = "particulars='$roll_size'";}else{$roll_size41="";}

$all_value10 = $from_date1."@".$to_date1."@".$roll_size41;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query105 .= $value10." AND ";
}
}	  

if($from_date!=""){ $from_date2= $from_date; }else{$from_date2=$cur_date; }
if($to_date!=""){ $to_date2 = $to_date;}else{$to_date2=$cur_date;}
if($roll_size!=""){ $roll_size1=$roll_size;} else {$roll_size1="ALL" ;}


$blog=array('','Return Ink Report','','');


foreach($blog as $icon)
{
$output		.= '"'.$icon.'",';
}

$output .="\n";
$output .="\n"; 
$output .="From Date".",".$from_date2.","."To Date".",".$to_date2.","."Item Name".",".$roll_size1.","."\n"; 
$output .="\n"; 
 
     $output .='"SNo","Date","Return No","Invoice No","Purchase No","Supplier Name","Particulars","Qty",'."\n";
      $table_values_new=array(ItemGroupName);
	 $table_values=array(SNo,Date,ReturnNo,InvoiceNo,PurchaseNo,SupplierName,Particulars,Qty);
   
  
  $sql="select *  from return_ink_pur_sublist where $get_query105 id!='' order by return_no ASC ";


    $rs=mysql_query($sql);
	 $rscount=mysql_num_rows($rs);
	if($rscount!='')
	{
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
		{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                $entry_date=$rsdata['entrydates'];
		 $return_no=$rsdata['return_no'];
		 $purchase_no=$rsdata['ink_pur_no'];
         $invoice_no=$rsdata['invoice_no'];
         $supplier_name=$rsdata['supplier_name'];
          $particulars=$rsdata['particulars'];
         $qty=$rsdata['qty'];
		  
		 
				
			  $i=$i+1;	
			 
			foreach ($table_values as $val) 
			{
				
				if($val=='SNo'){$output.='"'.$i.'",';}
				if($val=='Date'){$output.='"'.date("d-m-Y",strtotime($entry_date)).'",';}
				if($val=='ReturnNo'){$output.='"'.$return_no.'",';}
				if($val=='InvoiceNo'){$output.='"'.$invoice_no.'",';}
				if($val=='PurchaseNo'){$output.='"'.$purchase_no.'",';}
				if($val=='SupplierName'){$output.='"'.$supplier_name.'",';}
				if($val=='Particulars'){$output.='"'.$particulars.'",';}
				if($val=='Qty'){$output.='"'.number_format($qty,2).'",';}
				
				
				

if(($val!='SNo')&&($val!='Date')&&($val!='ReturnNo')&&($val!='InvoiceNo')&&($val!='PurchaseNo')&&($val!='SupplierName')&&($val!='Particulars')&&($val!='Qty')){$output .='"'.$val.'",';}
} 
 $output .="\n";
		
					
				
				 
	 $s1 += $qty;
 
}
 
$output .="".",".",".",".",".",".",".Total.",".$s1."\n\n";
}
$date=date('d-m-Y H:i:s');
$filename =  "Return Ink Report". $date.".csv";
header('Content-type: application/xls');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;



exit;
	


?>
<style>
br{
	
	mso-data-placement:same-cell;
	}
</style>