<?php
date_default_timezone_set("Asia/Kolkata");
 error_reporting(0);
ob_start();
session_start();
include ("../../include/db.php");
error_reporting(0);
ob_start();
session_start();
$session_branch=$_SESSION['branch'];
$session_user_type=$_SESSION['user_type'];
$branch_name=$_GET['branch_name'];

  
$cust_name=$_GET['customer_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$current_date=date('Y-m-d');
 $job_card_num=$_GET['jobcard_no'];
$fabric_types=$_GET['fabric_types'];
$value=explode(',',$_GET['fabric_types']);
 
                   for($i=0;$i<count($value);$i++){                  
                    $fabric1.=$value[$i];                 
				    
				   if($i<(count($value)-1)) {
                   $fabric1.="','";
                  
                   }
				   }
if($cust_name!=""){ $customer_name1= "cust_name='$cust_name'"; }else{$customer_name1=''; }
if($from_date!=""){ $from_date1= "DATE_FORMAT( print_date,'%Y-%m-%d' )>='$from_date'"; }else{$from_date1="DATE_FORMAT(print_date,'%Y-%m-%d' )='$current_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(print_date,'%Y-%m-%d' )<='$to_date'";}else{$to_date1="DATE_FORMAT(print_date,'%Y-%m-%d' )='$current_date'";}
if($job_card_num!=""){ $job_card_nums = "job_card_no='$job_card_num'";}else{$job_card_nums='';}
if($fabric_types!=""){ $fabric_type1 = "fabric_type IN ('$fabric1')";}else{$fabric_type1='';}

$all_value10 = $customer_name1."/".$from_date1."/".$to_date1."/".$job_card_nums."/".$fabric_type1;
$all_array10 = explode('/',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
 $get_query103 .= $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($cust_name!=""){ $cust_name1=$cust_name;} else {$cust_name1="ALL" ;} 
if($job_card_num!=""){ $Jobtype1=$job_card_num;} else {$Jobtype1="ALL" ;}
if($fabric_types!=""){ $fabric_types1=$fabric_types;} else {$fabric_types1="ALL" ;}



$blog=array('','Fusing  Production ','','');


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

$output .="\n";
$output .="\n"; 
$output .="From Date".",".$from_date2.","."To Date".",".$to_date2.","."Customer Name".",".$cust_name1.","."JobCard No".",".$Jobtype1.","."\n"; 
$output .="\n"; 

 
 
     $output .='"SNo","Date","Jobcard No","Customer Name","Job Created","Style No","Style Name","Fabric Type","Printed Qty",'."\n";
     // $table_values_new=array(ItemGroupName);
	 $table_values=array(SNo,Date,JobcardNo,CustomerName,JobCreated,StyleNo,StyleName,FabricType,PrintedQty);
   
   $sql="select * from fusing_production_main where $get_query103 p_id!='' order by job_card_no ASC";
    $rs=mysql_query($sql);
	$sno=0;
	$from=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$p_id=$rsdata['p_id'];
   				$job_card_no=$rsdata['job_card_no'];
				$print_date=$rsdata['print_date'];
	   			$cust_name=$rsdata['cust_name'];
	   			$job_created=$rsdata['job_created'];
				$cust_po=$rsdata['cust_po'];
	   			$style_no=$rsdata['style_no'];
	   			$style_name=$rsdata['style_name'];
				$combo=$rsdata['combo'];
	   			$printed_qty=$rsdata['printed_qty'];
				$fabric_type=$rsdata['fabric_type'];
		  
			 
			foreach ($table_values as $val) 
			{
				
				if($val=='SNo'){$output.='"'.$sno.'",';}
				if($val=='Date'){$output.='"'.date("d-m-Y",strtotime($print_date)).'",';}
				if($val=='JobcardNo'){$output.='"'.$job_card_no.'",';}
				if($val=='CustomerName'){$output.='"'.$cust_name.'",';}
				if($val=='JobCreated'){$output.='"'.$job_created.'",';}
				if($val=='StyleNo'){$output.='"'.$style_no.'",';}
				if($val=='StyleName'){$output.='"'.$style_name.'",';}
				if($val=='FabricType'){$output.='"'.$fabric_type.'",';}	
				if($val=='PrintedQty'){$output.='"'.number_format($printed_qty,3).'",';}
				
				
				

if(($val!='SNo')&&($val!='Date')&&($val!='JobcardNo')&&($val!='CustomerName')&&($val!='JobCreated')&&($val!='StyleNo')&&($val!='StyleName')&&($val!='FabricType')&&($val!='PrintedQty')){$output .='"'.$val.'",';}
} 
 $output .="\n";
		
					
				
				 
	$tot_qty+=$printed_qty;
  
 
}
 
$output .="".",".",".",".",".",".",".",".Total.",".$tot_qty.","."\n\n";

$date=date('d-m-Y H:i:s');
$filename =  "Fusing  Production 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>