<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function media_pur_print(url)
{
onmouseover650= window.open(url,'onmouseover650','height=580,width=1100,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
function mediapur_open1(edit_id,media_pur_no)
{
 
window.location.href="main_fram.php?file=media_purchase_entry&edit_id=" + edit_id + "&media_pur_no=" + media_pur_no;
window.location.reaload(true);
}
</script>
<?php error_reporting(0);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
function get_item_id_media($item_name4)
{
$sql_query11="select * from consumable_creation where particulars='$item_name4' and item='Media' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $id=$rsdata11->id;

 } 
 return $id;
}



 $item_name4=$_GET['item_name'];
 $item_id4=get_item_id_media($item_name4);
$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:media_pur_print('consumable/media_purchase/media_pur_print.php?from_date=<?php echo $_GET['from_date']; ?>&to_date=<?php echo $_GET['to_date']; ?>&item_name=<?php echo $item_id4; ?>');" 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="10%"  align="left" >Date</th>
    <th width="16%"  align="left" >Invoice No</th>
    <th width="21%"  align="left" >Supplier</th>
    <th width="24%"  align="left" >Particulars</th>
    <th width="10%"  align="left" >Qty</th>
      <th width="15%"  align="left" >Mtr Qty</th>
      <th width="15%"  align="left" >Edit</th>
      <th width="15%"  align="left" >Delete</th>
    </tr>
    </table>
    </td>
  <?php }else{?>
    <th  colspan="2" valign="middle">
    <table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >
     <tr>
    <th height="28" align="center" style=" font-family:Verdana, sans-serif; font-size:12px;"><strong>S.No</strong></th>
    <th width="222" align="left"  style=" font-family:Verdana, sans-serif; font-size:12px;"  scope="col"><strong>&nbsp;Date</strong><strong>&nbsp;</strong></th>
    <th scope="col" align="left" style=" font-family:Verdana, sans-serif; font-size:12px;"  ><strong>&nbsp;Media Pur.No</strong></th>
    <th scope="col" align="right" style=" font-family:Verdana, sans-serif; font-size:12px;"  ><strong>&nbsp;Total Mtr</strong></th>
    <th width="107" align="center" style=" font-family:Verdana, sans-serif; font-size:12px;"  ><strong>&nbsp;Edit</strong></th>
    <th width="110" align="center" style=" font-family:Verdana, sans-serif; font-size:12px;"  ><strong>&nbsp;Delete</strong></th>
  </tr>
    </table>
    </td>
  <?php }?>
    </tr>
  <?php
include("../../include/db.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(media_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1=""; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(media_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 ";
}
}   
// echo $get_query102; 
?>

<?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,sum(mtr_roll) as mtr_roll from media_pur_sublist where $get_query102 id!=''  group by invoice_no,supplier_name,particulars,entrydates,mtr_roll order by particulars ASC ";
}
else
{  
 $sql="select sum(qty) as qty,entrydates,invoice_no,supplier_name,particulars,sum(mtr_roll) as mtr_roll from media_pur_sublist where DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date' group by invoice_no,supplier_name,particulars,entrydates,mtr_roll  order by particulars ASC ";

}
    $rs=mysql_query($sql);
  $rscount1=mysql_num_rows($rs);
  if($rscount1!='')
  {
  $s_no=0;
      while($rsdata=mysql_fetch_array($rs))
        {
         $id=$rsdata['id'];
         $invoice_no=$rsdata['invoice_no'];
         $supplier_name=$rsdata['supplier_name'];
         $particulars=$rsdata['particulars'];
         $qty=$rsdata['qty'];
         $mtr_roll=$rsdata['mtr_roll'];
         $tot_mtr=$rsdata['tot_mtr'];
         $entrydates=$rsdata['entrydates'];
    ?>
        <tr>
          <th  height="28" align="left" style="border:1px solid #ddd;width: 195px;" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($entrydates)); ?></th>
          <th  align="left" style="border:1px solid #ddd;width: 315px;" ><?php  echo $invoice_no; ?>&nbsp;&nbsp;</th>
          <th  align="left" style="border:1px solid #ddd;width: 415px;" ><?php  echo $supplier_name; ?>&nbsp;&nbsp;</th>
          <th  align="left" style="border:1px solid #ddd;width: 450px;" ><?php  echo $particulars; ?>&nbsp;&nbsp;</th>
          <th  align="left" style="border:1px solid #ddd" ><?php  echo number_format($qty,2); ?>&nbsp;&nbsp;</th>
          <th  align="left" style="border:1px solid #ddd" ><?php  echo number_format($mtr_roll*$qty,2); ?>&nbsp;&nbsp;</th>
    <th align="center" style="cursor:pointer; border:1px solid #ddd;width:20px;"><img src="img/edit.png" width="17" height="20" title="EDIT" onclick="javascript:edit_print_prod_dfetails('<?php echo $id;?>','<?php echo $jobcard_no;?>');"/></th>
    <th align="center" style="border:1px solid #ddd;width:20px;" ><img src="img/trash.png" style="cursor:pointer" onClick="del_printer_main('<?php echo $id;?>','<?php echo  $jobcard_no;?>')" width="20px" height="22px"></th>
     
     </tr>
      <?php 
      $sum_tot+=$mtr_roll*$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(media_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1=""; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(media_date,'%Y-%m-%d')<='$to_date'";}else{$to_date1="";}
if($item_name4!=""){ $item_name41 = "roll_name='$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 media_purchase where $get_query105 main_id!='' and total_mtr!='0' order by media_pur_no  ASC ";
}
else
{  
  $sql="select * from media_purchase where  DATE_FORMAT(media_date,'%Y-%m-%d')='$cur_date' and total_mtr!='0' order by media_pur_no  ASC ";

}
    $rs=mysql_query($sql);
     $rscount=mysql_num_rows($rs);
  if($rscount!='')
  {
  $sno=0;
      while($rsdata=mysql_fetch_array($rs))
        {
          $sno=$sno+1;
         $main_id=$rsdata['main_id'];
         $media_pur_no=$rsdata['media_pur_no'];
         $media_date=$rsdata['media_date'];
         $jobcard_no=$rsdata['jobcard_no'];
         $total_mtr=$rsdata['total_mtr'];
         // $height=$rsdata['height'];
         // $roll_name=$rsdata['roll_name'];
         // $total_qty=$rsdata['plan_qty'];
         // $tot_req_by=$rsdata['tot_req_by'];
         // $operator_name=$rsdata['operator_name'];
          
        
          
        
    ?>
    <tr>  
      <th width="38" height="29" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo $sno; ?></th>
    <th width="50" height="29" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($media_date)); ?></th>
  
    <th width="108" align="left" style="border:1px solid #ddd" ><?php  echo $media_pur_no; ?>&nbsp;&nbsp;</th>
        <th width="75" align="right" style="border:1px solid #ddd" ><?php  echo $total_mtr; ?>&nbsp;&nbsp;</th>

    <!-- <th width="85" align="right" style="border:1px solid #ddd" ><?php  echo $width; ?>&nbsp;&nbsp;</th>

    <th width="68" align="right" style="border:1px solid #ddd" ><?php  echo $height; ?>&nbsp;&nbsp;</th>

    <th width="87" align="right" style="border:1px solid #ddd" ><?php  echo number_format($total_qty,2); ?>&nbsp;&nbsp;</th>
        <th width="85" align="right" style="border:1px solid #ddd" ><?php  echo number_format($tot_req_by,2); ?>&nbsp;&nbsp;</th> -->
        <th align="center" style="cursor:pointer; border:1px solid #ddd;width:20px;"><img src="img/edit.png" width="17" height="20" title="EDIT" onClick="javascript:mediapur_open1('<?php echo $main_id;?>','<?php echo $media_pur_no;?>');"/></th>
    <th align="center" style="border:1px solid #ddd;width:20px;" ><img src="img/trash.png" style="cursor:pointer" onClick="del_media_pur_main('<?php echo  $media_pur_no;?>')" width="20px" height="22px"></th>

<!--    <th width="84" align="right" style="border:1px solid #ddd" ><?php echo number_format($qty,2); ?>&nbsp;&nbsp;</th>
-->
    </tr><?php $sum_tot2+=$total_mtr;} } 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="3" align="left" 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="1">
    <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;padding-right: -50px;" ><strong>Total&nbsp;&nbsp;</strong></th>
          
          <th  align="right" style="border:1px solid #ddd; width: 330px;" ><strong><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</strong></th>
       <th height="28"  align="right" style="border:1px solid #ddd;width: 230px;" ><strong></strong></th>   
    </tr>
    </table>
 </td>
 </tr>
  </thead>
</table>
<?php }?>
</div>
</div>
</div>
</div>