<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function stock_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);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
?>
<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:stock_report_print('report/stock_report/stock_report_print.php?item_name=<?php echo $_POST['item_name'];?>&from_date=<?php echo $_POST['from_date']; ?>&to_date=<?php echo $_POST['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="60%"  align="center" cellpadding="0" cellspacing="0"  >
<thead>
<tr>
    <th height="23" colspan="2" valign="middle">
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0"  >
<tr>
    <th width="33%"  align="left" >&nbsp;&nbsp;&nbsp;Media Particulars</th>
    
  <th width="23%"  align="center" >Batch No</th>
  
    <th width="20%"  align="center" >Qty</th>
    
    <th width="21%"  align="center" >Qty In MTR</th>
    </tr>
    </table>
    </td>
    <th width="401" colspan="5" valign="middle">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >
    <tr>
    <th width="36%"  align="left">&nbsp;&nbsp;&nbsp;Ink Particulars</th>
    
   <th width="14%"  align="center">Batch No</th>
   
   <th width="14%"  align="center">UOM</th>
   
   <th width="14%"  align="center">NOS</th>
   
    <th width="14%"  align="center">Qty In Litter</th>
    </tr>
    </table>
    </td>
    </tr>
  <?php
include("../../include/db.php"); 
function get_total_qty($item_id,$from_date)
{
	$current_dates = date('Y-m-d');
if($from_date!='')
{
$sql="select sum(in_qty) as in_qty,sum(out_qty) as out_qty from  stock_table where  item_id='$item_id' and date<='$from_date' ";
}
else
{
$sql="select sum(in_qty) as in_qty,sum(out_qty) as out_qty from  stock_table where  item_id='$item_id' and date<'$current_dates' ";
}
		
        $rs=mysql_query($sql);
	    $s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $in_qty=$rsdata['in_qty'];
				 $out_qty=$rsdata['out_qty'];
				 $totals=$in_qty-$out_qty; 
	        }
return $totals;
}


function get_total_qty_media($item_id,$from_date)
{
$current_dates = date('Y-m-d');
if($from_date!='')
{
   
$sql="select sum(in_qty) as in_qty,sum(out_qty) as out_qty from  stock_table where item_id='$item_id' and date<='$from_date' ";
}
else
{
  
$sql="select sum(in_qty) as in_qty,sum(out_qty) as out_qty from  stock_table where  item_id='$item_id' and date<='$current_dates' ";
}
        $rs=mysql_query($sql);
	    $s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $in_qty=$rsdata['in_qty'];
				 $out_qty=$rsdata['out_qty'];
				$total=$in_qty-$out_qty; 
				 //$total=$rsdata['total_mtr'];
	        }
return $total;
}
  $item_name4=$_POST['item_name'];
  $from_date=$_POST['from_date'];
  $to_date=$_POST['to_date'];
 ?>
    <tr> 
    <td colspan="2">
      <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
      <?php 
if($item_name4=='')
{
  $sql="select id,particulars from consumable_creation where item='Media' order by particulars ASC ";
}
else
{  
  $sql="select id,particulars from consumable_creation where particulars='$item_name4' and item='Media'  order by particulars ASC";
}
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 if($_POST['from_date']!='') { $from_date01="AND DATE_FORMAT(media_pur_sublist.media_date,'%Y-%m-%d')>='$from_date'";}else{ $from_date01=""; }
  			
  			$sql_batchno="select particulars,batch_no,sum(qty) as qty,SUM(tot_mtr) as tot_qty from media_pur_sublist where batch_no!='' AND particulars ='$rsdata[particulars]' $from_date01 group by batch_no order by particulars ASC ";
  		//	echo $sql_batchno;
  			$rs_batchno=mysql_query($sql_batchno);
   		    while($rsdata01=mysql_fetch_array($rs_batchno))
  			    {
                 $id=$rsdata01['id'];
				 $item_name2=$rsdata01['particulars'];
				 $batch_no2=$rsdata01['batch_no'];
				 $qty2=$rsdata01['qty'];
				 $tot_qty2=$rsdata01['tot_qty'];
				 
				 $media_part=mysql_fetch_array(mysql_query("select *,SUM(tot_req_by) as tot_req from media_sub_list where roll_name='$item_name2' and `batch_no`='$batch_no2' group by batch_no"));
            $media_qty=$media_part['tot_req'];
            $tot_qty2=$tot_qty2-$media_qty;
                 $total_qty2=get_total_qty($id,$from_date);
		?><?php 
		if($tot_qty2!=0.00 &&$tot_qty2>=0.00) 
		{ ?>
        <tr>
          
          <th width="260" height="28" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo ucfirst($item_name2); ?> </th>
          
          <th width="135" align="right" style="border:1px solid #ddd" ><?php  echo $batch_no2; ?>&nbsp;&nbsp;</th>
          
          <th width="135" align="right" style="border:1px solid #ddd" ><?php  echo number_format($qty2,2); ?>&nbsp;&nbsp;</th>
          
          <th width="135" align="right" style="border:1px solid #ddd" ><?php  echo number_format($tot_qty2,2); ?>&nbsp;&nbsp;</th>
          </tr><?php $sum_tot+=$qty2;} ?><?php } } ?>
        
        </table>
    </td>
    <td colspan="5">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
<?php 
if($item_name4=='')
{
$sql="select id,particulars from consumable_creation where item='Ink' order by particulars ASC ";
}
else
{  
$sql="select id,particulars from consumable_creation where particulars='$item_name4' and item='Ink' order by particulars ASC ";
} // echo $item_name4;
    $rs=mysql_query($sql);
   		while($rsdata=mysql_fetch_array($rs))
  			{
  			if($_POST['from_date']!='') { $from_date01="AND DATE_FORMAT(ink_pur_sublist.ink_date,'%Y-%m-%d')>='$from_date'";}else{ $from_date01=""; }
  			
  			$sql_batchno="select ink_pur_sublist.particulars,ink_pur_sublist.batch_no,ink_pur_sublist.uom,ink_pur_sublist.nos,ink_pur_sublist.qty from ink_pur_sublist JOIN ink_sublist ON ink_pur_sublist.batch_no != ink_sublist.batch_no where ink_pur_sublist.batch_no!='' AND ink_pur_sublist.particulars ='$rsdata[particulars]' $from_date01 group by ink_pur_sublist.batch_no order by ink_pur_sublist.particulars ASC ";
  		//	echo $sql_batchno;
  			$rs_batchno=mysql_query($sql_batchno);
   		    while($rsdata01=mysql_fetch_array($rs_batchno))
  			    {
                 $id=$rsdata01['id'];
				 $item_name2=$rsdata01['particulars'];
				 $batch_no2=$rsdata01['batch_no'];
				 $uom2=$rsdata01['uom'];
				 $nos2=$rsdata01['nos'];
				 $qty2=$rsdata01['qty'];
                 $total_qty2=get_total_qty($id,$from_date);
		?>
		<?php 
		if($qty2!=0.00) 
		{ ?>
    <tr>  
    <th width="252" height="29" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo ucfirst($item_name2); ?></th>
    
    <th width="94" align="right" style="border:1px solid #ddd" ><?php  echo $batch_no2; ?>&nbsp;&nbsp;</th>
    
    <th width="94" align="right" style="border:1px solid #ddd" ><?php  echo $uom2; ?>&nbsp;&nbsp;</th>
    
    <th width="90" align="right" style="border:1px solid #ddd" ><?php  echo $nos2; ?>&nbsp;&nbsp;</th>
    
    <th width="90" align="right" style="border:1px solid #ddd" ><?php  echo number_format($qty2,2); ?>&nbsp;&nbsp;</th>
    </tr><?php $sum_tot2+=$qty2;} ?><?php } } ?>
    </table>
    </td>
    </tr>
 <tr>
 <td colspan="2"><table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
 <tr>
          <th width="298" height="28" align="left" style="border:1px solid #ddd" >Total</th>
          <th width="97" align="right" style="border:1px solid #ddd" ><?php  echo number_format($sum_tot,2); ?>&nbsp;&nbsp;</th>
          </tr>
</table></td>
<td colspan="5">
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
 <tr>
          <th width="385" height="28" align="left" style="border:1px solid #ddd" >Total</th>
          <th width="35" align="right" style="border:1px solid #ddd" ><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</th>
          </tr>
</table></td></tr>
  </thead>
</table>
</div>
</div>
</div>
</div>

