<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_buyerwise_overall_excel(from_date,to_date,buyer_name,roll_size,type_1)
{
//	,job_card_no,jobtype
//+"&job_card_no="+job_card_no+"&jobtype="+jobtype
window.location.href="report/media_usage_console_report/buyer_usage_excel.php?from_date="+from_date+"&to_date="+to_date+"&buyer_name="+buyer_name+"&roll_size="+roll_size+"&type_1="+type_1;
}
</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_buyerwise_overall_excel('<?php echo $_GET['from_date']; ?>','<?php echo $_GET['to_date']; ?>','<?php echo $buyer_name; ?>','<?php echo $roll_size; ?>','<?php echo $type_1; ?>')" style="float:right"><img  align="right" src="img/excel-icon.png" width="30" height="30" border="0" title="click to export"></a>
        </td> 
<!--'<?php echo $job_card_no; ?>',,'<?php echo $jobtype; ?>'-->
<!--&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_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">Buyer Wise</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>
  <!--  <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;
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 in_cust_name,roll_name order by in_cust_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 in_cust_name,roll_name order by in_cust_name ASC ";
}
 // echo $sql; exit;
    $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'];
		 $customer_name=$rsdata['in_cust_name'];
         $jobcard_no=$rsdata['jobcard_no'];
        // $width=$rsdata['width'];
       //   $height=$rsdata['height'];
         $roll_name=$rsdata['roll_name'];
		//  $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;width: 15px;" ><?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;width: 200px;" ><?php  echo $jobcard_no; ?>&nbsp;&nbsp;</td>-->
		   <td  align="left" style="border:1px solid #ddd;width: 200px;" ><?php  echo $customer_name_1; ?>&nbsp;&nbsp;</td> 
         <!--<td  align="left" style="border:1px solid #ddd;width: 150px;" ><?php  echo $media_particular; ?>&nbsp;&nbsp;</td>-->
		  <td  align="left" style="border:1px solid #ddd;width: 100px;" ><?php  echo $roll_name; ?>&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;width: 120px;" ><?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;width: 120px;"><?php echo number_format($gap_mtr,2);?>&nbsp;&nbsp;</td>
          <td  align="left" style="border:1px solid #ddd;width: 120px;" ><?php  echo number_format($sqr_meter,2); ?>&nbsp;&nbsp;</td>
     
     </tr>
      <?php 
      $sum_qty2+=$total_qty;
      $sum_mtr2+=$gap_mtr;
      $sum_sqy2+=$sqr_meter;
      }
      }
      ?>
         <tr>
       <th height="28" colspan="3" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
          <th  align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_qty2,2); ?>&nbsp;&nbsp;</strong></th>
          <th  align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_mtr2,2); ?>&nbsp;&nbsp;</strong></th>
          <th  align="left" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_sqy2,2); ?>&nbsp;&nbsp;</strong></th>
    </tr>
    </table>
 </td>