<?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='Media' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $particulars=$rsdata11->particulars;

 } 
 return $particulars;
}

 $jobtype=$_GET['jobtype'];
 $supplier_name=$_GET['supplier_name'];
  $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($supplier_name!=""){ $supplier_name41 = "supplier_name='$supplier_name'";}else{$supplier_name41="";}
if($roll_size!=""){ $roll_size41 = "particulars='$roll_size'";}else{$roll_size41="";}
if($jobtype!=""){ $jobtype41 = "job_types='$jobtype'";}else{$jobtype41="";}

$all_value10 = $from_date1."@".$to_date1."@".$supplier_name41."@".$roll_size41."@".$jobtype41;
$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($supplier_name!=""){ $supplier_name1=$supplier_name;} else {$supplier_name1="ALL" ;}
if($roll_size!=""){ $roll_size1=$roll_size;} else {$roll_size1="ALL" ;}
if($jobtype!=""){ $jobtype1=$jobtype;} else {$jobtype1="ALL" ;}


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


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

$output .="\n";
$output .="\n"; 
$output .="From Date".",".$from_date2.","."To Date".",".$to_date2.","."Job Type".",".$jobtype1.","."Supplier Name".",".$supplier_name1.","."Roll Size".",".$roll_size1.","."\n"; 
$output .="\n"; 
 
     $output .='"SNo","Date",Jobcard No","Return No","Invoice No","Purchase No","Supplier Name","Particulars","Qty","Mtr/Qty","Total Mtr",'."\n";
      $table_values_new=array(ItemGroupName);
	  $table_values = array("SNo", "Date", "JobType", "JobType", "ReturnNo", "InvoiceNo", "PurchaseNo", "SupplierName", "Particulars", "Qty", "MtrQty", "TotalMtr");

   
  
  $sql="select *  from return_media_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'];
		 $jobtype=$rsdata['job_types'];
		 $purchase_no=$rsdata['media_pur_no'];
         $invoice_no=$rsdata['invoice_no'];
         $supplier_name=$rsdata['supplier_name'];
          $particulars=$rsdata['particulars'];
         $qty=$rsdata['qty'];
		  $mtr_roll=$rsdata['mtr_roll'];
         $tot_mtr=$rsdata['tot_mtr'];
		 
				
			  $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=='JobType'){$output.='"'.$jobtype.'",';}
				if($val=='ReturnNo'){$output.='"'.$return_no.'",';}
				if($val=='InvoiceNo'){$output.='"'.$purchase_no.'",';}
				if($val=='PurchaseNo'){$output.='"'.$invoice_no.'",';}
				if($val=='SupplierName'){$output.='"'.$supplier_name.'",';}
				if($val=='Particulars'){$output.='"'.$particulars.'",';}
				if($val=='Qty'){$output.='"'.number_format($qty,2).'",';}
				if($val=='MtrQty'){$output.='"'.number_format($mtr_roll,2).'",';}
				if($val=='TotalMtr'){$output.='"'.number_format($tot_mtr,2).'",';}
				
				

if(($val!='SNo')&&($val!='Date')&&($val!='ReturnNo')&&($val!='JobType')&&($val!='InvoiceNo')&&($val!='PurchaseNo')&&($val!='SupplierName')&&($val!='Particulars')&&($val!='Qty')&&($val!='MtrQty')&&($val!='TotalMtr')){$output .='"'.$val.'",';}
} 
 $output .="\n";
		
					
				
				 
	 $s1 += $tot_mtr;
 
}
 
$output .="".",".",".",".",".",".",".",".",".Total.",".$s1."\n\n";
}
$date=date('d-m-Y H:i:s');
$filename =  "Return Media 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>