<script>

var sm = jQuery.noConflict();
sm().ready(function() 
{ 
	sm("#book_particulars").autocomplete("include/autocomplete/particulars_auto.php", {
	width: 650,
	matchContains: true,
	selectFirst: true
	});	
});
</script>
<style>
.style1 {border-top: solid 1px;border-top-color: #CCCCCC;}
.style21 {border-bottom: solid 1px;border-bottom-color: #CCCCCC;}
.style5 {border-left: solid 1px;border-left-color: #CCCCCC;}
.style3{ border-right: solid 1px;border-right-color: #CCCCCC; }
.style4 {border-bottom: solid 1px;border-bottom-color: #CCCCCC;}
.text{ font-family: Verdana; font-size:13px;}
#tot_amt::-webkit-input-placeholder { color:#666; }
</style>
<?php error_reporting(0);
date_default_timezone_set('Asia/Kolkata');
/***************************** PREVIOUS NEXT CODING ****************************************/
 include("../../include/db.php");
ob_start();
session_start();
$user_id11 = $_SESSION['login_user_id'];
 function get_shift_name($shift_time)
 {
	$sql_user="select * from  shift_creation where id='$shift_time'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$shift_name=$rsdata_user->shift_name;
	}
	return $shift_name;

 }
  function get_operator_name($operator_name)
 {
	$sql_user="select * from  operator_creation where id='$operator_name'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$operator_name=$rsdata_user->operator_name;
	}
	return $operator_name;

 }
  function get_machine_name($machine_no)
 {
	$sql_user="select * from  machine_creation where id='$machine_no'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$machine_no=$rsdata_user->machine_no;
	}
	return $machine_no;

 }
 
 
 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;
}	  

$sql1 = "select * from jobcard_main where (jobcard_no ='$_POST[job_card_no]' or jobcard_no ='$_GET[job_card_no]')";

//(job_card_no LIKE'%$_POST[job_card_no]%' or job_card_no LIKE '%$_GET[job_card_no]%')

//echo "select * from jobcard_main where fabric_type != 'F EMBOSS GEL   EMBOSING ' and (jobcard_no LIKE'%$_POST[job_card_no]%' or jobcard_no LIKE '%$_GET[job_card_no]%')";

$rsd1 = mysql_query($sql1);

while($rs1 = mysql_fetch_array($rsd1)) 
{
	$job_type= $rs1['job_type'];
} 

//echo $job_type;
$sql12="select * from job_type_creation where job_type='$job_type'";
$rs12=mysql_query($sql12);
while($rsdata12=mysql_fetch_array($rs12))
			{
				$fusing_production_status = $rsdata12['fusing_production_status'];
				
			}
			if($fusing_production_status == 'Inactive')
			{
				echo "<h3>Fusing Production Status Inactive</h3>";
				
			}
			else{?>

<div style="height:200px; width:98%; padding-left:0px;  overflow-x:hidden; overflow-y:scroll; white-space:nowrap; ">
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr bgcolor="#F2F2F2">
    <td width="144" height="25" class="text style5 style1 style21"><strong>&nbsp;Date&nbsp;</strong></td>
    <td width="95" class="text style1 style5 style21"><strong>&nbsp;Shift</strong><span style="color:#FF0000">*</span><div id="shift_time_validation_div" style="color:#F00"></div><strong></strong></td>
    <td width="155" class="text style1 style5 style21" align="center"><strong>Machine No</strong><span style="color:#FF0000">*</span><div id="machine_no_validation_div" style="color:#F00"></div></td>
    <td width="241" class="text style1 style5 style21" align="center"><strong>Operator</strong><span style="color:#FF0000">*</span><div id="operator_name_validation_div" style="color:#F00"></div></td>
    <td width="198" class="text style1 style5 style21" align="center"><strong>Size</strong><span style="color:#FF0000">*</span><div id="prod_size_validation_div" style="color:#F00"></div></td>
    <td width="83" class="text style1 style5 style3 style21" align="right"><strong>T.Qty</strong></td>
    <td width="144" class="text style1 style5 style3 style21" align="right"><strong>P.Qty</strong><span style="color:#FF0000">*</span><div id="prod_qty_validation_div" style="color:#F00"></div></td>
    <td width="144" class="text style1 style5 style3 style21" align="right"><strong>Balance</strong></td>
    <td width="95" height="25" class="text style5 style1 style21" align="center"><strong>&nbsp;Action&nbsp;</strong></td>
 </tr>
   
   
  
  <?php
   	$sql_user2="select * from  fusing_production_sublist where (job_card_no='$_POST[job_card_no]' or job_card_no='$_GET[job_card_no]') order by pr_id asc";
		$rs_user2=mysql_query($sql_user2);
		$rs_count=mysql_num_rows($rs_user2);
			while($rsdata_user2=mysql_fetch_object($rs_user2))
			{ 
			$pr_id=$rsdata_user2->pr_id;
			$job_card_no=$rsdata_user2->job_card_no;
			$production_time=$rsdata_user2->production_time;
			$shift_time=$rsdata_user2->shift_time;
			$shift_dis_name=get_shift_name($shift_time);
			$machine_no=$rsdata_user2->machine_no;
			$machine_name=get_machine_name($machine_no);
			$operator_name=$rsdata_user2->operator_name;
			$operator_dis_name=get_operator_name($operator_name);
			$prod_size=$rsdata_user2->prod_size;
			$width=$rsdata_user2->width;
			$height=$rsdata_user2->height;
			$total_qty=$rsdata_user2->total_qty;
			$prod_qty=$rsdata_user2->prod_qty;
			$balance_qty=$rsdata_user2->balance_qty;
			$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 height="25px">
    <td class="text style4  style5">&nbsp;<?php echo date("d-m-Y H:i",strtotime($production_time));?>&nbsp;</td>
    <td class="text style4  style5">&nbsp;<?php echo $shift_dis_name;?>&nbsp;</td>
    <td class="text style4  style5">&nbsp;<?php echo $machine_name;?>&nbsp;</td>
    <td class="text style4  style5">&nbsp;<?php echo $operator_dis_name;?>&nbsp;</td>
    <td class="text style4  style5">&nbsp;<?php echo $prod_size."  (".$width." x ".$height.")";?>&nbsp;</td>
    <td class="text style4  style5" align="right"><?php echo number_format($total_qty,3);?>&nbsp;</td>
    <td class="text style4  style5" align="right"><?php echo number_format($prod_qty,3);?>&nbsp;</td>
    <td class="text style4  style5" align="right"><?php echo number_format($balance_qty,3);?>&nbsp;</td>
  <?php if(($user_id11=='1')||($user_id11=='3'))
	 { 
	 ?>   <td class="text style4  style5" align="center"><img src="img/cross-small.png"  title="Delete" onClick="del_fusing_prod_sub('<?php echo $pr_id;?>','<?php echo $job_card_no;?>')" width="20px" height="20px"></td><?php } ?>

  </tr>
  <?php 
  $tot_total_qty+=$qty;
  $tot_prod_qty+=$prod_qty;
  $tot_balance_qty=$tot_total_qty-$tot_prod_qty;
  }?>
  <tr height="20px">
    <td   class="text  style5"><input type="datetime-local" name="production_time" tabindex="3" id="production_time" class="types_class" style="width:100%; height:29px; font-size:14px" value="<?php echo date('Y-m-d').'T'.date('H:i');?>" onKeyUp="enterevent(event,'shift_time','production_time')" /></td>
    <td class="text style5"><select name="shift_time" id="shift_time" tabindex="4" class="types_class" style="width:100%; height:30px; font-size:14px" onChange="get_fusing_size(job_card_no.value),fusing_clear_validation(this.value),enterevent(event,'machine_no','shift_time')">
    <option value="">--Select--</option>
    <?php
	$sql_user="select * from  shift_creation order by shift_name asc";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$shift_name=$rsdata_user->shift_name;
			$shiftid=$rsdata_user->id;

	?>
    <option value="<?php echo $shiftid;?>"><?php echo $shift_name;?></option>
    <?php } ?>
    </select></td>
        <td class="style5">
    <select name="machine_no" id="machine_no" class="types_class" tabindex="5" style="width:100%; height:30px; font-size:14px" onChange="fusing_clear_validation(this.value),enterevent(event,'operator_name','machine_no'),printer_clear_validation(this.value)" >
    <option value="">--Select--</option>
    <?php
	$sql_user="select * from  machine_creation where mach_type='Fusing' order by machine_no asc";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$machine_no=$rsdata_user->machine_no;
			$machine_id=$rsdata_user->id;

	?>
    <option value="<?php echo $machine_id;?>"><?php echo $machine_no;?></option>
    <?php } ?>
    </select></td>

    <td class="style5"><select name="operator_name"  id="operator_name" tabindex="6" class="types_class" style="width:100%; height:30px; font-size:14px" onChange="enterevent(event,'prod_size','operator_name'),fusing_clear_validation(this.value)" >
    <option value="">--Select--</option>
    <?php
	$sql_user1="select * from  operator_creation where operator_type='Fusing Operator' order by operator_name asc";
		$rs_user1=mysql_query($sql_user1);
			while($rsdata_user1=mysql_fetch_object($rs_user1))
			{ 
			$operator_name=$rsdata_user1->operator_name;
			$operatorid=$rsdata_user1->id;

	?>
    <option value="<?php echo $operatorid;?>"><?php echo $operator_name;?></option>
    
    <?php } ?></select></td>
    <td class="style5"><div id="get_size_div"> <select name="prod_size" id="prod_size" class="types_class" onChange="enterevent(event,'total_qty','prod_size'),fusing_clear_validation(this.value)" tabindex="7" style="width:100%; height:30px; font-size:14px" >
    <option value="">--Select--</option>
    </select></div></td>
    <td class="style5"><div id="get_tot_qty_div"><input type="text" class="types_class1" tabindex="8" name="total_qty" id="total_qty" onkeypress="enterevent(event,'prod_qty','total_qty')" style="width:100%; height:27px; font-size:14px"/></div></td>
    <td class="style5"><input type="text" class="types_class1" name="prod_qty" tabindex="9" id="prod_qty"style="width:100%; height:27px; font-size:14px" onKeyUp="get_fusing_calc_qty(total_qty.value,prod_qty.value),fusing_clear_validation(this.value),fusing_entry_qty_validation(total_qty.value,prod_qty.value)" onkeypress="enterevent(event,'balance_qty','prod_qty')"/></td>
    <td class="style5"><input type="text" class="types_class1" name="balance_qty" tabindex="10" id="balance_qty" onkeypress="enterevent(event,'add','balance_qty')" style="width:100%; height:27px; font-size:14px"/></td>
    <td class="style5"><input type="button" name="add" id="add" value="ADD" tabindex="11" style="width:100%; height:27px; font-size:14px" onClick="add_fusing_prod_sub(job_card_no.value,production_time.value,shift_time.value,machine_no.value,operator_name.value,prod_size.value,total_qty.value,prod_qty.value,balance_qty.value,this.value)"></td>
  </tr>
   <tr height="120px">
   <td colspan="9"  align="center" class="style4 style3 style5" ><table width="100%" border="0" cellpadding="0" cellspacing="0">
    
   </table></td>
   </tr>
 
</table>

</div>
 <table width="98%">

  <tr>
   <td width="8%"><input type="hidden" name="count" id="count" value="<?php echo $rs_count;?>"></td>
   <td width="8%"></td>
   <td width="8%"></td>
   <td width="8%"></td>
   <td width="21%" align="right" class="text"><strong>Total</strong></td>
   <td width="16%" class="text" align="right"><strong><?php echo number_format($tot_total_qty,3);?></strong></td>
   <td width="12%" align="right" class="text"><strong><?php echo number_format($tot_prod_qty,3);?></strong></td>
   <td width="11%" align="right" class="text"><strong><?php echo number_format($tot_balance_qty,3);?></strong></td>
   <td width="8%"></td>
   </tr>
</table>
<?php } ?>
