<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,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
function media_usage_report_overall_excel(from_date,to_date,job_card_no,buyer_name,roll_size,type_1,jobtype)
{
	
window.location.href="report/media_usage_console_report/usage_excel.php?from_date="+from_date+"&to_date="+to_date+"&job_card_no="+job_card_no+"&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;
}

$type_1=$_GET['type_1'];
// $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($roll_size!=""){ $roll_size41 = "roll_name='$roll_size'";}else{$roll_size41="";}
//if($jobtype!=""){ $job_type = "job_types='$jobtype'";}else{$job_type="";}
//"@".$job_card_no41.."@".$job_type
$all_value10 = $from_date1."@".$to_date1."@".$buyer_name41."@".$roll_size41;
$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="left" >&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 $job_card_no; ?>','<?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> -->
<!--&job_card_no=<?php //echo $job_card_no;?>&jobtype=<?php //echo $jobtype; ?>-->
<td width="7%" align="center"><a href="javascript:media_report_print('report/media_usage_console_report/media_usages_report_summary_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; ?>&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">Summary</th>


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

<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0"  >
<tr>
    <th   align="left" >S.No</th>
   <!-- <th   align="left" >Date</th>
	<th  align="left" >Jobcard No</th>-->
	<!--<th   align="left" >Buyer Name </th>    -->
 <!--   <th   align="left" >Particulars</th>   -->
	 <th   align="left" >Roll Size</th>
	 <?php
	    $job_types1 = array();
		$sql="select * from job_type_creation WHERE job_type != 'TBilling' and job_type != 'T fusing work' order by job_type ASC";
		$sql123 = mysql_query($sql);
		while($fetch_sql123=mysql_fetch_array($sql123))
			{
			     $job_type=$fetch_sql123['job_type'];
			     $job_types1[] = $job_type;
				?>
				<th   align="left" ><?php echo $job_type; ?></th>
		<?php } ?>
    <!--<th   align="left" >Job Types</th>-->
  <!--  <th   align="left" >Width</th>-->
  <!--  <th   align="left" >Height</th>-->
	 <!--<th   align="left" >Order Qty</th>-->
    <th   align="left" >Quantity</th>
	<!-- <th   align="left" >Req By</th>
	 <th   align="left" >Steps Used</th>
	 <th   align="left" >Steps</th>
	 <th   align="left" >Total Repeats</th>
	 <th   align="left" >Gap</th>-->
    <th   align="left" >Meter</th> 
    <th   align="left" >Sqr Meter</th> 
    <!--<th   align="left" >Total Req</th>-->
 </tr>
 
 </td>
 
 <td colspan="2">
 
   <?php
$i=0;
//   $sql="select * from media_sub_list where  DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date' order by jobcard_no ASC ";
if($from_date!='')
{
$sql="select entrydates ,media_date ,job_types ,in_cust_name ,jobcard_no ,sum(plan_qty) as qty ,roll_name ,SUM(gap_mtr) as gmeter,SUM(tot_req_by) as meter from media_sub_list where $get_query105 id!='' group by roll_name order by roll_name ASC ";
}
else
{  
   $sql="select entrydates ,media_date ,job_types ,in_cust_name ,jobcard_no ,sum(plan_qty) as qty ,roll_name ,SUM(gap_mtr) as gmeter,SUM(tot_req_by) as meter from media_sub_list where DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date' and id!='' group by roll_name order by roll_name ASC ";
}
 // echo $sql; exit;
    $rs=mysql_query($sql);
     $rscount=mysql_num_rows($rs);
  if($rscount!='')
  {
  $s_no=0;
     $overall_totals = array_fill_keys($job_types1, 0);
      while($rsdata=mysql_fetch_array($rs))
        {
         $media_date=$rsdata['media_date'];
		// $media_particular=$rsdata['media_particular'];
		// $customer_name=$rsdata['in_cust_name'];
        // $jobcard_no=$rsdata['jobcard_no'];
        // $width=$rsdata['width'];
        // $height=$rsdata['height'];
         $roll_name=$rsdata['roll_name'];
         $job_types=$rsdata['job_types'];
		// $roll_size=$rsdata['roll_size'];
         $total_qty=$rsdata['qty'];
		// $order_qty=$rsdata['order_qty'];
         $gap_mtr=$rsdata['meter'];
        // $operator_name=$rsdata['operator_name'];
		// $steps=$rsdata['steps'];
		// $steps_used=$rsdata['steps_used'];
		 $gap_mtrs = $rsdata['gmeter'];
		// $gap=$rsdata['gap'];
		// $total_steps=$rsdata['total_steps'];
		// $req_by=$rsdata['req_by'];
		 $sqr_meter=(($roll_name*39.37)/1550)*$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="left" style="border:1px solid #ddd" ><?php  echo $i; ?>&nbsp;&nbsp;</td>
          <!--<td  height="28" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($media_date)); ?></td>
		  <td  align="left" style="border:1px solid #ddd" ><?php // echo $jobcard_no; ?>&nbsp;&nbsp;</td>-->
      
		  <!-- <td  align="left" style="border:1px solid #ddd" ><?php // echo $customer_name_1; ?>&nbsp;&nbsp;</td> -->
    <!--     <td  align="left" style="border:1px solid #ddd" ><?php // echo $media_particular; ?>&nbsp;&nbsp;</td>-->
		  <td  align="left" style="border:1px solid #ddd" ><?php  echo $roll_name; ?>&nbsp;&nbsp;</td>
     <?php  
     if($from_date!=""){ $from_date01= "DATE_FORMAT(media_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date01="DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date'"; }
     if($to_date!=""){ $to_date01 = "DATE_FORMAT(media_date,'%Y-%m-%d')<='$to_date'";}else{$to_date01="DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date'";}
     $all_value010 = $from_date01."@".$to_date01;
    $all_array010 = explode('@',$all_value010);
    foreach($all_array010 as $value010)
    { 
    if($value010!='')
    {
    $get_query0105 .= $value010." AND ";
    }
    }   
     $job_types01 = array();
         $sql_4="select job_types,sum(tot_req_by) as tot from media_sub_list where $get_query0105 roll_name='$roll_name' and id!='' group by job_types ";
        $rs_14=mysql_query($sql_4);
        while($rsdata_14=mysql_fetch_array($rs_14))
        {
            $job_types01["$rsdata_14[job_types]"] = $rsdata_14['tot'];
        }
         foreach ($job_types1 as $job_types2) {
            $overall_totals[$job_types2] += isset($job_types01[$job_types2]) ? $job_types01[$job_types2] : 0;
     ?>
         <td  align="left" style="border:1px solid #ddd" ><?php
            if ($job_types01["$job_types2"] != '') {
                
                echo number_format($job_types01["$job_types2"], 2)."&nbsp;&nbsp;"; 
            } else {
                echo "&nbsp;&nbsp;"; 
            }
            ?></td>
    <?php } ?>
         <!--<td  align="left" style="border:1px solid #ddd" ><?php  echo $job_types; ?>&nbsp;&nbsp;</td>-->
    <!--      <td  align="left" style="border:1px solid #ddd" ><?php  echo $width; ?>&nbsp;&nbsp;</td>-->
    <!--      <td  align="left" style="border:1px solid #ddd" ><?php  echo $height; ?>&nbsp;&nbsp;</td>-->
		  <!--<td  align="left" style="border:1px solid #ddd" ><?php  echo number_format($order_qty,2); ?>&nbsp;&nbsp;</td>-->
          <td  align="left" style="border:1px solid #ddd" ><?php  echo number_format($total_qty,2); ?>&nbsp;&nbsp;</td>
		  <!--<td align="right" style="border:1px solid #ddd"><?php echo $req_by;?>&nbsp;&nbsp;</td>
		  <td align="right" style="border:1px solid #ddd"><?php echo $steps_used;?>&nbsp;&nbsp;</td>
		  <td align="right" style="border:1px solid #ddd"><?php echo $steps;?>&nbsp;&nbsp;</td>
			<td align="right" style="border:1px solid #ddd"><?php echo $total_steps;?>&nbsp;&nbsp;</td>
		  <td align="right" style="border:1px solid #ddd"><?php echo $gap;?>&nbsp;&nbsp;</td>-->
		    <td align="left" style="border:1px solid #ddd"><?php echo number_format($gap_mtr,2);?>&nbsp;&nbsp;</td>
          <td  align="left" style="border:1px solid #ddd" ><?php  echo number_format($sqr_meter,2); ?>&nbsp;&nbsp;</td>
     
     </tr>
      <?php 
      $sum_gap2+=$gap_mtr;
      $sum_tot2+=$sqr_meter;
      $sum_qty2+=$total_qty;
      
      }
      }
      ?>
         <tr>
        <th height="28" colspan="2" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
      <?php
        foreach ($job_types1 as $job_type3) {
            echo '<td align="left" style="border:1px solid #ddd"><strong>' . number_format($overall_totals[$job_type3], 2) . '&nbsp;&nbsp;</strong></td>';
        }
      ?>
          <th width="197" align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_qty2,2); ?>&nbsp;&nbsp;</strong></th>
          <th width="197" align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_gap2,2); ?>&nbsp;&nbsp;</strong></th>
          <th width="197" align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</strong></th>
    </tr>
    </table>
 </td>