<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function ink_report_print(url)
{
onmouseover432= window.open(url,'onmouseover432','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);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
$type_1=$_GET['type_1'];

?>
<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:ink_report_print('report/ink_report/ink_report_print.php?item_name=<?php echo $_GET['item_name'];?>&from_date=<?php echo $_GET['from_date']; ?>&to_date=<?php echo $_GET['to_date']; ?>');" 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>
  <?php if($type_1=='Purchases'){?>
 <th height="23" colspan="2"  valign="middle">Purchases</th>
 <?php }else{ ?>
 <th width="48%" height="23"  colspan="2" valign="middle">Usages</th>
<?php
}
?>
</tr>
<tr>  
 <?php if($type_1=='Purchases'){?> 
    <th height="23" colspan="2" valign="middle">
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0"  >
<tr>
    <th width="16%"  align="left" >Date</th>
    <th width="18%"  align="left" >Invoice No</th>
    <th width="24%"  align="left" >Supplier</th>
    <th width="30%"  align="left" >Particulars</th>
    <th width="12%"  align="right" >Qty</th>
    </tr>
    </table>
    </td>
    <?php }else{?>
    <th  colspan="2" valign="middle">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >
    <tr>
    <th width="15%"  align="left" >Date</th>
    <th width="17%"  align="left" >Shift</th>
    <th width="19%"  align="left" >Operator</th>
    <th width="18%"  align="left" >Machine No</th>
    <th width="22%"  align="left" >Particulars</th>
    <th width="9%"  align="right" >Qty</th>
    </tr>
    </table>
    </td>
    <?php }?>
    </tr>
  <?php
include("../../include/db.php"); 
function get_shift_name_from_mach($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_machine_name($machine_no)
{
 $sql_query11="select * from machine_creation where id='$machine_no' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $machine_no=$rsdata11->machine_no;
 } 
return $machine_no;
}

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


 $item_name4=$_GET['item_name'];
  $from_date=$_GET['from_date'];
 $to_date=$_GET['to_date'];
 $cur_date=date("Y-m-d");
if($from_date!=""){ $from_date1= "DATE_FORMAT(ink_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1=""; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(ink_date,'%Y-%m-%d')<='$to_date'";}else{$to_date1="";}
if($item_name4!=""){ $item_name41 = "particulars='$item_name4'";}else{$item_name41="";}

$all_value10 = $from_date1."@".$to_date1."@".$item_name41;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query102 .= $value10." AND ";
}
}	   ?>
<?php if($type_1=='Purchases'){ ?>
    <tr> 
    <td colspan="2">
      <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
      <?php if($from_date!='')
{
 $sql="select sum(qty) as qty,entrydates,invoice_no,supplier_name,particulars from ink_pur_sublist where $get_query102 id!=''  group by invoice_no,supplier_name,particulars,entrydates order by particulars ASC ";
}
else
{  
 $sql="select sum(qty) as qty,entrydates,invoice_no,supplier_name,particulars from ink_pur_sublist where DATE_FORMAT(ink_date,'%Y-%m-%d')='$cur_date' group by invoice_no,supplier_name,particulars,entrydates  order by particulars ASC ";

}
    $rs=mysql_query($sql);
	$rscount1=mysql_num_rows($rs);
	if($rscount1!='')
	{
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
				 $invoice_no=$rsdata['invoice_no'];
				 $supplier_name=$rsdata['supplier_name'];
				 $particulars=$rsdata['particulars'];
			     $qty=$rsdata['qty'];
				 $entrydates=$rsdata['entrydates'];
		?>
        <tr>
          <th width="109" height="28" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($entrydates)); ?></th>
          <th width="122" align="left" style="border:1px solid #ddd" ><?php  echo $invoice_no; ?>&nbsp;&nbsp;</th>
          <th width="168" align="left" style="border:1px solid #ddd" ><?php  echo $supplier_name; ?>&nbsp;&nbsp;</th>
          <th width="203" align="left" style="border:1px solid #ddd" ><?php  echo $particulars; ?>&nbsp;&nbsp;</th>
          <th width="84" align="right" style="border:1px solid #ddd" ><?php  echo number_format($qty,2); ?>&nbsp;&nbsp;</th>
          </tr>
		  <?php 
		  $sum_tot+=$qty;
		  }
		  }
		  ?>
        </table>
        <?php }else{?>
    </td>
    <td colspan="2" valign="top">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd"  >
    <?php $item_name4=$_GET['item_name'];
  $from_date=$_GET['from_date'];
 $to_date=$_GET['to_date'];
 $cur_date=date("Y-m-d");
if($from_date!=""){ $from_date1= "DATE_FORMAT(ink_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1=""; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(ink_date,'%Y-%m-%d')<='$to_date'";}else{$to_date1="";}
if($item_name4!=""){ $item_name41 = "prod_size='$item_name4'";}else{$item_name41="";}

$all_value10 = $from_date1."@".$to_date1."@".$item_name41;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query105 .= $value10." AND ";
}
}	   ?>
     <?php if($from_date!='')
{
$sql="select *  from ink_sublist where $get_query105 ink_sub_id!='' order by prod_size ASC ";
}
else
{  
  $sql="select * from ink_sublist where  DATE_FORMAT(ink_date,'%Y-%m-%d')='$cur_date' order by prod_size ASC ";

}
    $rs=mysql_query($sql);
		 $rscount=mysql_num_rows($rs);
	if($rscount!='')
	{
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
				 $ink_date=$rsdata['ink_date'];
				 $shift_time=$rsdata['shift_time'];
				 $machine_no=$rsdata['machine_no'];
				 $prod_size=$rsdata['prod_size'];
				 $total_qty=$rsdata['total_qty'];
				 $operator_name=$rsdata['operator_name'];
					list($frm_time,$to_ti,$type)=get_shift_name_from_mach($shift_time);
					$machine_names=get_machine_name($machine_no);
					$operatorss=get_operator_id($operator_name);
				  
				
		?>
    <tr>  
    <th width="94" height="29" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($ink_date)); ?></th>
  
    <th width="107" align="left" style="border:1px solid #ddd" ><?php  echo $type; ?>&nbsp;&nbsp;</th>
        <th width="120" align="left" style="border:1px solid #ddd" ><?php  echo $operatorss; ?>&nbsp;&nbsp;</th>

    <th width="114" align="left" style="border:1px solid #ddd" ><?php  echo $machine_names; ?>&nbsp;&nbsp;</th>

    <th width="143" align="left" style="border:1px solid #ddd" ><?php  echo $prod_size; ?>&nbsp;&nbsp;</th>

    <th width="55" align="right" style="border:1px solid #ddd" ><?php  echo number_format($total_qty,2); ?>&nbsp;&nbsp;</th>

    </tr><?php $sum_tot2+=$total_qty;} } else {?>
     <?php } ?>
    <?php }?>  
          
    </table>
    </td>
    </tr>
    <?php if($type_1=='Purchases'){?>
 <tr>
 <td colspan="2">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
    <tr>
       <th height="28" colspan="5" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
          
          <th width="87" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot,2); ?>&nbsp;&nbsp;</strong></th>
    </tr>
    </table>
 </td>
 <?php }else{?>
 <td colspan="2">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
    <tr>
       <th height="28" colspan="5" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
          
          <th width="55" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</strong></th>
    </tr>
    </table>
 </td>
 </tr>
  </thead>
</table>
<?php }?>

</div>
</div>
</div>
</div>

