<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function operator_report_print(url)
{
onmouseover43= window.open(url,'onmouseover43','height=580,width=1100,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
</script>
<?php error_reporting(0);
include("../../include/db.php");
function get_shift_name_from($shift_time)
{
$sql_query11="select * from shift_creation where id='$shift_time' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
  $to_time=$rsdata11->to_time;
  $shift_name=$rsdata11->shift_name;
  $from_time=$rsdata11->from_time;
 } 
 $tot_shift=array($from_time,$to_time,$shift_name);
 return $tot_shift;
}


function get_shift_name_to($shift_time)
{
 $sql_query11="select * from shift_creation where id='$shift_time' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $to_time=$rsdata11->to_time;
 } 
return $to_time;
}

function get_machine_name($machine_no)
{
$sql_query11="select * from machine_creation where id='$machine_no' and  mach_type='printer'";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $machine_no=$rsdata11->machine_no;
 } 
return $machine_no;
}

function get_operator_name($operator_no)
{
$sql_query11="select * from operator_creation where id='$operator_no' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $operator_name=$rsdata11->operator_name;
 } 
return $operator_name;
}


function get_operator_id($operator_name)
{
   $sql_query11="select * from printer_production_sublist where id='$operator_name' ";
  
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $operator_id=$rsdata11->operator_name;
 } 
return $operator_id;
}
function get_customer($customer_name)
{
        $sql="select * from  customer_entry where  customer_name='$customer_name' ";
        $rs=mysql_query($sql);
	    $s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $id=$rsdata['id'];
	        }
return $id;
}
function get_id($operator_no)
{
  $sql="select * from operator_creation where operator_name='$operator_no'";
    $rs=mysql_query($sql);
   		while($rsdata=mysql_fetch_array($rs))
  			{
			 $operator_number=$rsdata['id'];
			}
			return  $operator_number;
}

$show = 20;
$num_links = 9;
$from = $_GET['from'];
if (empty($from))
	 {
		$from = "0";
	 } 
else 
	{
	    $html_query = $html_query. "&from=$from";
	}
	
include("../../include/db.php"); 
  $from_date=$_GET['from_date']; 
  $to_date=$_GET['to_date']; 
  $operator_name=$_GET['operator_name']; 
    $operator_no=get_id($operator_name); 

 $current_date=date('Y-m-d');
 if($from_date!=""){ $from_date1= "DATE_FORMAT(production_time,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(production_time,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date'";}
if($operator_name!=""){ $operator_name1 = "operator_name='$operator_no'";}else{$operator_name1="";}

{
$all_value102 = $from_date1."@".$to_date1."@".$operator_name1;
}
$all_array102 = explode('@',$all_value102);
foreach($all_array102 as $value102)
{ 
if($value102!='')
{
  $get_query105 .= $value102." AND ";
}
}	

if($from_date!='')
{
$sql="select * from printer_production_sublist where $get_query103 pr_id!=' ' order by job_card_no,operator_name,prod_size ASC";
}
else
{  
$sql="select * from  printer_production_sublist where DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date' order by job_card_no,operator_name,prod_size ASC";
}


$html_query = "main_fram.php?file=operator_wise_printer";
$result=mysql_query($sql);
 $num_results=mysql_num_rows($result);
if ($num_results == 0) 
{
 $confirmation = "No Records!";
} 
elseif ($num_results == 1) 
{
$confirmation = "Found 1 Record.";
} 
else 
{
$confirmation = "Found $num_results Records.";
} 




$job_card_no=$_GET['job_card_no'];
$customer_name=$_GET['customer_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
?>
<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 href="javascript:operator_report_print('report/operator_wise_printer/operator_wise_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&operator_name=<?php echo $_GET['operator_name'];?>');" 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="97%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
<thead>
<tr>
    <th  height="23"  align="center" style="border:1px solid #ddd" >S.No</th>
    <th  align="center" style="border:1px solid #ddd" > &nbsp;Date</th>
    <th  align="center" style="border:1px solid #ddd" >Jobcard No</th>
        <th  align="left" style="border:1px solid #ddd" >Operator Name</th>

	<th  align="left" style="border:1px solid #ddd" >Shift</th>
        <th  align="left" style="border:1px solid #ddd" >Machine No</th>

        <th  align="left" style="border:1px solid #ddd" >Particulars</th>
        <th  align="right" style="border:1px solid #ddd" >Order Qty</th>
                        <th  align="right" style="border:1px solid #ddd" >Product Qty</th>

        <th  align="right" style="border:1px solid #ddd" >Balance Qty</th>

    
    </tr>
  <?php
include("../../include/db.php"); 
  $from_date=$_GET['from_date']; 
  $to_date=$_GET['to_date']; 
  $operator_name=$_GET['operator_name'];
  $operator_no=get_id($operator_name); 

  
$current_date=date('Y-m-d');
 if($from_date!=""){ $from_date1= "DATE_FORMAT(production_time,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(production_time,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date'";}
if($operator_name!=""){ $operator_number1 = "operator_name='$operator_no'";}else{$operator_number1="";}

{
  $all_value102 = $from_date1."@".$to_date1."@".$operator_number1;
}
$all_array102 = explode('@',$all_value102);
foreach($all_array102 as $value102)
{ 
if($value102!='')
{
  $get_query103 .= $value102." AND ";
}
}	

function get_order_qty($job_card_no,$prod_size)
{
	$sql_query="select * from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
    $rs=mysql_query($sql_query);
    $rscount=mysql_num_rows($rs);
	return $rscount;
 }
 
 
 function get_max_order_qty($job_card_no,$prod_size)
{
$sql_query="select max(total_qty) as total_qty from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
    $rs11=mysql_query($sql_query);
 while($rsdata=mysql_fetch_array($rs11))
 {
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}

 function get_order_qty1($job_card_no,$prod_size,$pr_id)
{
 $sql_query="select total_qty from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' and pr_id='$pr_id'  ";
    $rs11=mysql_query($sql_query);
 while($rsdata=mysql_fetch_array($rs11))
 {
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}	  
if($from_date!='')
{
  $sql="select * from printer_production_sublist where $get_query103 pr_id!=' ' order by job_card_no,operator_name,prod_size ASC";
}
else
{  
 $sql="select * from  printer_production_sublist where DATE_FORMAT(production_time,'%Y-%m-%d')='$current_date' order by job_card_no,operator_name,prod_size ASC";
}
//echo $sql;

    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $pr_id=$rsdata['pr_id'];
                 $job_card_no=$rsdata['job_card_no'];
				 $production_time=$rsdata['production_time'];
				 $shift_time=$rsdata['shift_time'];
				list($frm_time,$to_ti,$type)=get_shift_name_from($shift_time);
				
				 $machine_no=$rsdata['machine_no'];
				 $machine_name=get_machine_name($machine_no);

				 $operator_no=$rsdata['operator_name'];
				 $operator_name=get_operator_name($operator_no);

				 $prod_size=$rsdata['prod_size'];
				 $total_qty=$rsdata['total_qty'];
				 $prod_qty=$rsdata['prod_qty'];
				 $balance_qty=$rsdata['balance_qty'];
				  $count_order_qty = get_order_qty($job_card_no,$prod_size); 
	 $max_order_qty = get_max_order_qty($job_card_no,$prod_size);
	 $qty=  get_order_qty1($job_card_no,$prod_size,$pr_id);
	if($max_order_qty==$qty)
	{
		$qty=$max_order_qty;
	}
	else
	{
				$qty='';

		}


 ?>
    <tr>
    <td width="63"  align="center" style="border:1px solid #ddd">&nbsp;<?php echo $from; ?></td>
    <td width="103" align="center" style="border:1px solid #ddd" >&nbsp;<?php echo date("d-m-Y",strtotime($production_time));?></td>
     <td width="152" align="center" style="border:1px solid #ddd" >&nbsp;<?php echo $job_card_no; ?></td>
         <td width="164" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo $operator_name; ?></td>

    <td width="155" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo  $type."(".$frm_time."-".$to_ti.")"; ?></td>
        <td width="141" align="left" style="border:1px solid #ddd" >&nbsp;<?php  echo $machine_name;?></td>

    <td width="118" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo $prod_size; ?></td>
    <td width="127" align="right" style="border:1px solid #ddd" ><?php echo $qty; ?>&nbsp;</td>
            <td width="123" align="right" style="border:1px solid #ddd" >&nbsp;<?php echo number_format($prod_qty,2); ?></td>

    <td width="148" align="right" style="border:1px solid #ddd" ><?php echo $balance_qty; ?>&nbsp;</td>



    </tr>
  <?php 
  $total1+=$qty; 
	$total2+=$prod_qty; 
	$total3+=$balance_qty; } ?>
    <tr>
   <td colspan="7" align="right" class="style1"><strong>Total</strong></td>
   <td align="right" class="style1"><strong><?php echo number_format($total1,2); ?></strong></td>
      <td align="right" class="style1"><strong><?php echo number_format($total2,2); ?></strong></td>

   <td align="right" class="style1"><strong><?php echo number_format($total1-$total2,2); ?></strong></td>

    </tr>
  </thead>
  
</table>
</div>
</div>
</div>
</div>

