<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function media_report_print(url)
{
onmouseover650= window.open(url,'onmouseover650','height=580,width=1200,scrollbars=yes,center=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
function media_usage_report_overall_excel(from_date,to_date,buyer_name,roll_size,type_1,jobtype)
{
// 	alert(jobtype);
// 	exit(0);
window.location.href="report/media_usage_analyze_report/usage_excel.php?from_date="+from_date+"&to_date="+to_date+"&buyer_name="+buyer_name+"&roll_size="+roll_size+"&type_1="+type_1+"&jobtype="+jobtype;
}
</script>
<?php error_reporting(0);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
function get_item_id_media($roll_size)
{
$sql_query11="select * from consumable_creation where particulars='$roll_size' and item='Media' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $id=$rsdata11->id;

 } 
 return $id;
}

if($_GET['type_1']!=''){ $type_1=$_GET['type_1'];}else { $type_1="Date Wise";}
 //$job_card_no=$_GET['job_card_no'];
 $buyer_name=$_GET['buyer_name'];
  $roll_size=$_GET['roll_size'];
  $jobtype=$_GET['jobtype'];
  $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($jobtype!=""){ $job_type41 = "job_types='$jobtype'";}else{$job_type41="";}
if($roll_size!=""){ $roll_size41 = "roll_name='$roll_size'";}else{$roll_size41="";}

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

<style type="text/css">

.style1 {font-size: 16px}

</style>
<table width="100%">
<tr>
<td width="1%" height="38">&nbsp;</td>
<td width="7%" class="style15">&nbsp;</td> 
<td width="13%" align="center">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="6%" class="style15">&nbsp;</td>
<td width="14%" align="center"  class="style15">&nbsp;</td>
<td width="2%">&nbsp;</td>
<td width="11%" class="style15">&nbsp;</td>
<td width="24%" align="center" >&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="2%"></td>
<td width="7%" align="center">
            <a onclick="javascript:media_usage_report_overall_excel('<?php echo $_GET['from_date']; ?>','<?php echo $_GET['to_date']; ?>','<?php echo $buyer_name; ?>','<?php echo $roll_size; ?>','<?php echo $type_1; ?>','<?php echo $jobtype; ?>')" style="float:right"><img  align="right" src="img/excel-icon.png" width="30" height="30" border="0" title="click to export"></a>
        </td> 
<td width="7%" align="center"><a href="javascript:media_report_print('report/media_usage_analyze_report/media_usages_report_print.php?from_date=<?php echo $_GET['from_date']; ?>&to_date=<?php echo $_GET['to_date']; ?>&buyer_name=<?php echo $buyer_name; ?>&roll_size=<?php echo $roll_size; ?>&jobtype=<?php echo $jobtype; ?>&type_1=<?php echo $type_1; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="30" title="Print" value="Print"/></a></td>
  </tr>
</table>
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table border="0" width="100%"  align="center" cellpadding="0" cellspacing="0"  >
<thead>
 <tr>
 
 <th height="23" colspan="2"  valign="middle"><?php echo $type_1; ?></th>


</tr> 
<tr>   
   
 <th height="23" colspan="2" valign="middle">

<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0"  >
<tr>
    <th   align="center" >S.No</th>
    <th   align="center" >Date</th>
	<th   align="center" >Job Types </th> 
	<th   align="center" >Buyer Name </th> 
	<th  align="center" >Jobcard No</th> 
	 <!--<th   align="center" >Order Qty</th>-->
    <th   align="center" >Quantity</th>
	 <th   align="center" >Roll Size</th>
    <th   align="center" >Meter</th> 
    <th   align="center" >Sqr Meter</th> 
    <!--<th   align="center" >Sqr Meter</th>Total Req-->
 </tr>
 
 </td>
 
 <td colspan="2">
 
   <?php
$i=0;
if(($from_date!="") && ($type_1=="Buyer Wise")){
        $sql="select * from media_sub_list where $get_query105 id!='' order by in_cust_name ASC ";
    }elseif((($from_date!="") && $type_1=="Job Type Wise")){
        $sql="select * from media_sub_list where $get_query105 id!='' order by job_types ASC ";
    }elseif((($from_date!="") && $type_1=="Size Wise")){
        $sql="select * from media_sub_list where $get_query105 id!='' order by roll_name ASC ";
    }elseif(($from_date!="") && ($type_1=="Date Wise")){
        $sql="select * from media_sub_list where $get_query105 id!='' order by media_date ASC ";
        //echo "select * from media_sub_list where $get_query105 id!='' order by media_date ASC ";
    }else{
        $sql="select * from media_sub_list where DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date' and id!='' order by media_date ASC";  
}
//echo $sql;
    $rs=mysql_query($sql);
     $rscount=mysql_num_rows($rs);
  if($rscount!='')
  {
  $s_no=0;
      while($rsdata=mysql_fetch_array($rs))
        {
         $media_date=$rsdata['media_date'];
	//	 $media_particular=$rsdata['media_particular'];
		 $job_types=$rsdata['job_types'];
		 $customer_name=$rsdata['in_cust_name'];
         $jobcard_no=$rsdata['jobcard_no'];
    //    $width=$rsdata['width'];
    //  $height=$rsdata['height'];
         $roll_name=$rsdata['roll_name'];
        //  $roll_name=$rsdata['roll_name'];
         //  echo $roll_name;  
         $sq_mtr = explode('-', $roll_name);  
         if(count($sq_mtr) == 2) {  
             $width = $sq_mtr[0];   
             $height = $sq_mtr[1]; 
             $squ = ($width * 2.54) / 100;
                        //  echo number_format($squ, 2);  // Display the square meters with 2 decimal places
         } 
         
	//	 $roll_size=$rsdata['roll_size'];
         $total_qty=$rsdata['plan_qty'];
	//	 $order_qty=$rsdata['order_qty'];
         $gap_mtr=$rsdata['gap_mtr'];
    //   $operator_name=$rsdata['operator_name'];
	//	$steps=$rsdata['steps'];
	//	$steps_used=$rsdata['steps_used'];
		$gap_mtrs = $rsdata['tot_req_by'];

       $squre_mettrs= $squ*$gap_mtrs;
       
	//	$gap=$rsdata['gap'];
	//	$total_steps=$rsdata['total_steps'];
	//	$req_by=$rsdata['req_by'];
		$sqr_meter=($roll_name/39.4)*$gap_mtr;	
          
        $i=$i+1;

        $sql_3="select customer_name  from jobcard_sublist where jobcard_no='$jobcard_no'  ";


        $rs_1=mysql_query($sql_3);
        while($rsdata_1=mysql_fetch_array($rs_1))
        {
          $customer_name_1=$rsdata_1['customer_name'];


        }
        
        
    ?>
        <tr>
           <td  align="center" style="border:1px solid #ddd" ><?php  echo $i; ?>&nbsp;&nbsp;</td>
          <td  height="28" align="center" style="border:1px solid #ddd;width: 195px;" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($media_date)); ?></td>
		   <td  align="center" style="border:1px solid #ddd;width: 150px;" ><?php  echo $job_types; ?>&nbsp;&nbsp;</td>
		   <td  align="center" style="border:1px solid #ddd;width: 350px;" ><?php  echo $customer_name_1; ?>&nbsp;&nbsp;</td> 
		  <td  align="center" style="border:1px solid #ddd;width: 200px;" ><?php  echo $jobcard_no; ?>&nbsp;&nbsp;</td>
		  <!--<td  align="center" style="border:1px solid #ddd" ><?php  echo number_format($order_qty,2); ?>&nbsp;&nbsp;</td>-->
          <td  align="center" style="border:1px solid #ddd" ><?php  echo number_format($total_qty,2); ?>&nbsp;&nbsp;</td>
		  <td  align="center" style="border:1px solid #ddd;width: 100px;" ><?php  echo $roll_name; ?>&nbsp;&nbsp;</td>
		    <td align="right" style="border:1px solid #ddd"><?php echo number_format($gap_mtrs,2);?>&nbsp;&nbsp;</td>
          <td  align="right" style="border:1px solid #ddd" ><?php  echo number_format($squre_mettrs,2); ?>&nbsp;&nbsp;</td>
    
     
     </tr>
      <?php    
      $sum_roll2+=$roll_name;
      $sum_mtr2+=$gap_mtrs;
      $sum_tot2+=$squre_mettrs;
     // $sum_sqy2+=$sqr_meter;
      }
      }
      ?>
         <tr>
       <th height="28" colspan="7" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
       
       <!-- <th width="187" align="center" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_roll2,2); ?>&nbsp;&nbsp;</strong></th> -->
       <th width="187" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_mtr2,2); ?>&nbsp;&nbsp;</strong></th>
       <th width="187" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</strong></th>
       <!--<th width="87" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_sqy2,2); ?>&nbsp;&nbsp;</strong></th>-->
    </tr>
    </table>
 </td>
  