<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function jobcard_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");
?>
<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:jobcard_report_print('report/job_no_wise_fusing/job_no_wise_print.php?job_card_no=<?php echo $_GET['job_card_no'];?>');" 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" >Date</th>
    <th  align="center" style="border:1px solid #ddd" >Jobcard No</th>

     <th width="111"  align="left" style="border:1px solid #ddd" >Date&nbsp;</th>
     <th width="111"  align="left" style="border:1px solid #ddd" > &nbsp;Shift</th>
    <th width="101"  align="left" style="border:1px solid #ddd" >&nbsp;Machine No</th>
    <th width="115"  align="left" style="border:1px solid #ddd" >&nbsp;Operator</th>
    <th width="188"  align="left" style="border:1px solid #ddd" >&nbsp;Particulars</th>
            <th width="127"  align="right" style="border:1px solid #ddd" >Order Qty&nbsp;</th>

        <th  align="right" style="border:1px solid #ddd" >Product Qty&nbsp;&nbsp;</th>
        <th  align="right" style="border:1px solid #ddd" >Balance Qty</th>
    </tr>
  <?php
include("../../include/db.php"); 

function get_operator_name1($ope_name)
{
$sql="select * from operator_creation where id='$ope_name'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$operator_namess=$rsdata['operator_name'];
}
return $operator_namess;
}

function get_total_quants($job_card_nos)
{
 $sql="select sum(qty) as qty from jobcard_sublist where jobcard_no='$job_card_nos'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$qty1=$rsdata['qty'];
}
return $qty1;
}

function get_shift_time1($shift_id)
{
$sql="select * from shift_creation where id='$shift_id'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
{
$from_time[0]=$rsdata['from_time'];
$from_time[1]=$rsdata['to_time'];
$from_time[2]=$rsdata['shift_name'];
}
return $from_time;
}

function get_machine_no1($machine_no)
{
$sql="select * from machine_creation where id='$machine_no'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$machine_no=$rsdata['machine_no'];
}
return $machine_no;
}

$job_card_no=$_GET['job_card_no'];
if($job_card_no!=""){ $job_card_no1 = "job_card_no='$job_card_no'";}else{$job_card_no1="";}
{
$all_value102 = $job_card_no1;
}
$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 fusing_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 fusing_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 fusing_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($_GET['job_card_no']!='')
{
 $sql="select * from  fusing_production_main where $get_query103 p_id!='' order by job_card_no ASC ";
}
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $id=$rsdata['p_id'];
                 $job_card_nos=$rsdata['job_card_no'];
				 $print_date=$rsdata['print_date'];
				 $cust_name=$rsdata['cust_name'];
				 $fabric_type=$rsdata['fabric_type'];
				 $printer_status=$rsdata['billed_status'];
				 $job_type=$rsdata['job_type'];
				 $printed_qty=$rsdata['printed_qty'];
				 $total_quant=get_total_quants($job_card_nos);
				 
 ?>
    <tr>
    <td width="52"  align="center" style="border:1px solid #ddd">&nbsp;<?php echo $from; ?></td>
    <td width="52" align="center" style="border:1px solid #ddd" >&nbsp;<?php echo date("d-m-Y",strtotime($print_date));?></td>
    <td width="115" align="center" style="border:1px solid #ddd" >&nbsp;<?php echo $job_card_nos; ?></td>
   <td colspan="8"><table width="100%" style="border:0px; color:#000">
   <tbody>   
   <?php
   if($_GET['job_card_no']!='')
{
     $sql_user="select * from fusing_production_sublist where job_card_no='$job_card_nos' order by prod_size ASC";	
}
    $rs_user=mysql_query($sql_user);
	$usercount=mysql_num_rows($rs_user);
	
	if($usercount!='0')
	{
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$pr_id=$rsdata_user->pr_id;
	$shift_id=$rsdata_user->shift_time;
	$shift_time=get_shift_time1($shift_id);
	$machine_id=$rsdata_user->machine_no;
	$machine_no=get_machine_no1($machine_id);
	$operator_id=$rsdata_user->operator_name;
	$operator_name=get_operator_name1($operator_id);
	$production_time=$rsdata_user->production_time;
	$prod_size=$rsdata_user->prod_size;
	$prod_qty=$rsdata_user->prod_qty;
	$total_qty=$rsdata_user->total_qty;
	$balance_qty=$rsdata_user->balance_qty;
	$job_card_no=$rsdata_user->job_card_no;
	$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>
      <th width="12%" align="left" style="border:0px;color:#000;">&nbsp;<?php echo date('d-m-y h:m a',strtotime($production_time)); ?></th>
    <th width="12%" align="left" style="border:0px;color:#000;"><?php echo $shift_time[2]."(".$shift_time[0]."-".$shift_time[1].")"; ?>&nbsp;</th>
    <th width="10%" align="left" style="border:0px;color:#000">&nbsp;<?php echo $machine_no; ?></th>
    <th width="12%" align="left" style="border:0px;color:#000">&nbsp;<?php echo $operator_name; ?></th>
    <th width="20%" align="left" style="border:0px;color:#000">&nbsp;<?php echo $prod_size; ?></th>
  
   
      <th width="13%"  style="border:0px;color:#000;align:right;"><?php echo $qty; ?>&nbsp;</th>

    <th width="11%" align="right" style="border:0px;color:#000">	<?php echo number_format($prod_qty,2); ?>&nbsp;</th>
      <th width="22%" align="right" style="border:0px;color:#000"><?php echo $balance_qty; ?>&nbsp;</th>
    </tr>
	<?php $total1+=$qty; 
	$prod_qty1+=$prod_qty; }}?></tbody></table></td>
       </tr>
  <?php } ?>
   <tr>
   <td colspan="8" align="right" class="style1"><strong>Total</strong></td>
   <td align="right" class="style1" ><strong><?php echo $total1 ?></strong></td>
      <td width="128" align="right" class="style1"><strong><?php echo number_format($prod_qty1,2); ?></strong></td>

   <td width="203" align="right" class="style1"><strong><?php echo number_format($total1-$prod_qty1,2); ?></strong></td>
    </tr>
  </thead>
</table>
</div>
</div>
</div>
</div>

