<link rel="stylesheet" href="css/jquery-ui.css" />
<link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
<link rel="stylesheet" href="css/font.css" type="text/css" />
<script type="text/javascript" src="js/printer_production_ajax.js"></script>
<script src="js/jquery/jquery.js" type="text/javascript"></script>
<script src="js/jquery/jquery-1.8.2.js"></script>
<script src="js/jquery/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery/autocomplete_jquery_plugin.js"></script>
<script src="js/shortcut.js"  type="text/javascript"></script>
<script type="text/javascript" src="js/enter_event_ajax.js"></script><script>

var sm = jQuery.noConflict();
sm().ready(function() 
{ 
	sm("#book_particulars").autocomplete("include/autocomplete/particulars_auto.php", {
	width: 650,
	matchContains: true,
	selectFirst: true
	});	
});

function get_tot_qty_print(jobcard_no,size)
{ 
  jQuery.ajax({
		type: "POST",
		url: "production/printer_production/get_total_qty.php",
		data: "jobcard_no="+jobcard_no+"&size="+size,
		success: function(msg){jQuery("#get_tot_qty_div").html(msg);

 }
		});
}

</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 printer_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 printer_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'];
	$approve_status=$rs1['approval_status'];
} 

//echo $job_type;
$sql12="select * from job_type_creation where job_type='$job_type'";
$rs12=mysql_query($sql12);
while($rsdata12=mysql_fetch_array($rs12))
			{
				$printer_production_status = $rsdata12['printer_production_status'];
				
			}
			if($approve_status!=0){
			if($printer_production_status == 'Inactive')
			{
				echo "<h3>Printer Prodution Status Inactive</h3>";
				
			}
			else{?>

<div style="height:255px; 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="132" height="30" class="text style5 style1 style21"><strong>&nbsp;Date&nbsp;</strong></td>
    <td width="116" class="text style1 style5 style21"><strong>&nbsp;Shift</strong><span style="color:#FF0000">*</span><div id="shift_validation_div" style="color:#F00"></div></td>
    <td width="148" class="text style1 style5 style21" align="left"><strong>&nbsp;Machine No</strong><span style="color:#FF0000">*</span><div id="machine_validation_div" style="color:#F00"></div></td>
    <td width="241" class="text style1 style5 style21" align="left"><strong>&nbsp;Operator</strong><span style="color:#FF0000">*</span><div id="operator_validation_div" style="color:#F00"></div></td>
    <td width="198" class="text style1 style5 style21" align="left"><strong>&nbsp;Size</strong><span style="color:#FF0000">*</span><div id="size_validation_div" style="color:#F00"></div></td>
    <td width="84" class="text style1 style5 style3 style21" align="right"><strong>T.Qty&nbsp;</strong></td>
    <td width="145" class="text style1 style5 style3 style21" align="right"><strong>P.Qty&nbsp;</strong><span style="color:#FF0000">*</span><div id="pqty_validation_div" style="color:#F00"></div></td>
    <td width="145" class="text style1 style5 style3 style21" align="right"><strong>Balance&nbsp;</strong></td>
    <td width="100" height="30" class="text style5 style1 style21" align="center"><strong>&nbsp;Action&nbsp;</strong></td>
 </tr>
   <?php
   	$sql_user2="select * from  printer_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);
			while($rsdata_user2=mysql_fetch_object($rs_user2))
			{ 
			$pr_id=$rsdata_user2->pr_id;
			$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;
			$job_card_no=$rsdata_user2->job_card_no;
			 $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 height="29" class="text style4  style5">&nbsp;<?php echo date("d-m-Y H:i",strtotime($production_time));?></td>
    <td class="text style4  style5">&nbsp;<?php echo $shift_dis_name;?></td>
    <td class="text style4  style5">&nbsp;<?php echo $machine_name;?></td>
    <td class="text style4  style5">&nbsp;<?php echo $operator_dis_name;?></td>
    <td class="text style4  style5">&nbsp;<?php echo $prod_size."  (".$width." x ".$height.")";?></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_print_prod_sub('<?php echo $pr_id;?>','<?php echo $_POST[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" readonly id="production_time" tabindex="3" value="<?php echo date('Y-m-d').'T'.date('H:i');?>" class="types_class" style="width:100%; height:28px; font-size:14px" 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:29px; font-size:14px" onChange="get_size(job_card_no.value),printer_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:29px; font-size:14px" onChange="printer_clear_validation(this.value),enterevent(event,'operator_name','machine_no')" >
    <option value="">--Select--</option>
    <?php
	$sql_user="select * from  machine_creation where mach_type='printer' 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:29px; font-size:14px" onChange="printer_clear_validation(this.value),enterevent(event,'prod_size','operator_name')">
    <option value="">--Select--</option>
    <?php
	$sql_user1="select * from  operator_creation where operator_type='Printing 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" tabindex="7" class="types_class" style="width:100%; height:29px; font-size:14px" onChange="enterevent(event,'total_qty','prod_size'),printer_clear_validation(this.value),get_tot_qty('<?php echo $jobcard_no;?>',this.value),printer_clear_validation(this.value)">
    <option value="">--Select--</option>
    </select></div></td>
    <td class="style5"><div id="get_tot_qty_div"><input type="text" class="types_class1" name="total_qty" tabindex="8" onKeyUp="enterevent(event,'prod_qty','total_qty'),get_tot_qty('<?php echo $jobcard_no;?>',this.value)" id="total_qty" style="width:100%; height:26px; font-size:14px;"/></div></td>
    <td class="style5"><input type="text" class="types_class1" name="prod_qty" id="prod_qty" style="width:100%; height:26px; " onKeyUp="get_calc_qty(total_qty.value,prod_qty.value),printer_clear_validation(this.value),enterevent(event,'balance_qty','prod_qty')"/></td>
    <td class="style5"><input type="text" class="types_class1" name="balance_qty" id="balance_qty" onKeyUp="enterevent(event,'add','balance_qty')" tabindex="9" style="width:100%; height:26px;"/></td>
    <td class="style5"><input type="button" name="add" id="add" value="ADD" tabindex="10" style="width:100%; height:120%;" onClick="add_print_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="190px">
   <td colspan="9"  align="center" class="style4 style3 style5" valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr height="25px">
    <td width="11%">&nbsp;</td>
    <td width="9%" >&nbsp;</td>
    <td width="11%" >&nbsp;</td>
    <td width="18%" >&nbsp;</td>
    <td width="10%" ></td>
    <td width="11% " align="right"></td>
    <td width="12% "  align="right"></td>
    <td width="12% "  align="right"></td>
    <td width="6%" >&nbsp;</td>
  </tr>

   </table></td>
   </tr>
   
</table>
</div><table width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr >
   <td colspan="9"  align="center" class=" " valign="bottom">
    <tr height="25px">
    <td width="11%" class="text   ">&nbsp;</td>
    <td width="9%" class="text   ">&nbsp;</td>
    <td width="11%" class="text   ">&nbsp;</td>
    <td width="18%" class="text   ">&nbsp;</td>
    <td width="10%" class="text   "><strong>Total:</strong>&nbsp;</td>
    <td width="11%" class="text   " align="right"><strong><?php echo number_format($tot_total_qty,3);?></strong>&nbsp;</td>
    <td width="12%" align="right" class="text   " ><strong><?php echo number_format($tot_prod_qty,3);?></strong>&nbsp;</td>
    <td width="12%" align="right" class="text   " ><strong><?php echo number_format($tot_balance_qty,3);?></strong>&nbsp;</td>
    <td width="6%" class="text   ">&nbsp;</td>
  </tr></table>

  <?php } }?>