<?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;
}

 $job_card_no=$_GET['job_card_no'];
 $buyer_name=$_GET['buyer_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(media_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(media_date,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date'";}
if($job_card_no!=""){ $job_card_no41 = "jobcard_no='$job_card_no'";}else{$job_card_no41="";}
if($buyer_name!=""){ $buyer_name41 = "in_cust_name='$buyer_name'";}else{$buyer_name41="";}
if($roll_size!=""){ $roll_size41 = "roll_name='$roll_size'";}else{$roll_size41="";}

$all_value10 = $from_date1."@".$to_date1."@".$job_card_no41."@".$buyer_name41."@".$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($job_card_no!=""){ $job_card_no1=$job_card_no;} else {$job_card_no1="ALL" ;} 
if($buyer_name!=""){ $buyer_name1=$buyer_name;} else {$buyer_name1="ALL" ;}
if($roll_size!=""){ $roll_size1=$roll_size;} else {$roll_size1="ALL" ;}


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


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

$output .="\n";
$output .="\n"; 
$output .="From Date".",".$from_date2.","."To Date".",".$to_date2.","."Jobcard No".",".$job_card_no1.","."Buyer Name".",".$buyer_name1.","."Roll Size".",".$roll_size1."\n"; 
$output .="\n"; 

 

 
     $output .='"SNo","Date","Jobcard No","Buyer Name","Particulars","Width","Height","Order Qty","Plan Qty","Roll Size","Req By","Steps Used","Steps","Total Repeats","Gap","Gap Mtr","Total Req",'."\n";
      $table_values_new=array(ItemGroupName);
	 $table_values=array(SNo,Date,JobcardNo,BuyerName,Particulars,Width,Height,OrderQty,PlanQty,RollSize,ReqBy,StepsUsed,Steps,TotalRepeats,Gap,GapMtr,TotalReq);
   
   //echo "select *  from media_sub_list where $get_query105 id!='' order by jobcard_no ASC ";
   $sql="select *  from media_sub_list where $get_query105 id!='' order by jobcard_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;
                 $media_date=$rsdata['media_date'];
				  $media_particular=$rsdata['media_particular'];
				$customer_name=$rsdata['in_cust_name'];
				 $jobcard_no=$rsdata['jobcard_no'];
				 $width=$rsdata['width'];
				 $roll_name=$rsdata['roll_name'];
				 $roll_size=$rsdata['roll_size'];
				  $total_qty=$rsdata['plan_qty'];
		 $order_qty=$rsdata['order_qty'];
				 $height=$rsdata['height'];
				  $tot_req_by=$rsdata['tot_req_by'];
				   $total_qty=$rsdata['plan_qty'];
				 $operator_name=$rsdata['operator_name'];
				 $steps=$rsdata['steps'];
				$steps_used=$rsdata['steps_used'];
				$gap_mtr = $rsdata['gap_mtr'];
				$gap=$rsdata['gap'];
				$total_steps=$rsdata['total_steps'];
				$req_by=$rsdata['req_by'];
				
			  $i=$i+1;	
			 
			foreach ($table_values as $val) 
			{
				
				if($val=='SNo'){$output.='"'.$i.'",';}
				if($val=='Date'){$output.='"'.date("d-m-Y",strtotime($media_date)).'",';}
				if($val=='JobcardNo'){$output.='"'.$jobcard_no.'",';}
				if($val=='BuyerName'){$output.='"'.$customer_name.'",';}
				if($val=='Particulars'){$output.='"'.$media_particular.'",';}
				if($val=='Width'){$output.='"'.$width.'",';}
				if($val=='Height'){$output.='"'.$height.'",';}
				if($val=='OrderQty'){$output.='"'.number_format($order_qty,2).'",';}
				if($val=='PlanQty'){$output.='"'.number_format($total_qty,2).'",';}
				if($val=='RollSize'){$output.='"'.$roll_name.'",';}
				if($val=='ReqBy'){$output.='"'.$req_by.'",';}
				if($val=='StepsUsed'){$output.='"'.$steps_used.'",';}
				if($val=='Steps'){$output.='"'.$steps.'",';}
				if($val=='TotalRepeats'){$output.='"'.$total_steps.'",';}
				if($val=='Gap'){$output.='"'.$gap.'",';}
				if($val=='GapMtr'){$output.='"'.$gap_mtr.'",';}
				if($val=='TotalReq'){$output.='"'.number_format($tot_req_by,2).'",';}
				
				

if(($val!='SNo')&&($val!='Date')&&($val!='OB')&&($val!='JobcardNo')&&($val!='BuyerName')&&($val!='Particulars')&&($val!='Width')&&($val!='Height')&&($val!='OrderQty')&&($val!='PlanQty')&&($val!='RollSize')&&($val!='ReqBy')&&($val!='StepsUsed')&&($val!='Steps')&&($val!='TotalRepeats')&&($val!='Gap')&&($val!='GapMtr')&&($val!='TotalReq')){$output .='"'.$val.'",';}
} 
 $output .="\n";
		
					
				
				 
	 $s1 += $tot_req_by;
	  $s2 += $order_qty;
	   $s3 += $total_qty;
 
}
 
$output .="".Total.",".",".",".",".",".",".",".$s2.",".$s3.",".",".",".",".",".",".",".",".$s1."\n\n";
}
$date=date('d-m-Y H:i:s');
$filename =  "Media Usage 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>