<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: 12px;}

#tot_amt::-webkit-input-placeholder { color:#666; }
</style>
<?php 
error_reporting(0);
date_default_timezone_set('Asia/Kolkata');
include("../../include/db.php");
ob_start();
session_start();
$user_id = $_SESSION['login_user_id'];

  $edit_ids=$_POST['edit_id']; 
  $media_pur_no=$_POST['media_pur_no'];
  $sql="select * from ink_pur_sublist where id='$_POST[edit_id]' ";
  $rs=mysql_query($sql);
  while($rsdata=mysql_fetch_array($rs))
  {
				$sno=$sno+1;
				$id=$rsdata['id'];
				$ink_pur_no=$rsdata['ink_pur_no'];
				$entrydates1=$rsdata['entrydates'];
				$invoice_no1=$rsdata['invoice_no'];
				$supplier_name1=$rsdata['supplier_name'];
   				$particulars1=$rsdata['particulars'];
				 $batch_no1=$rsdata['batch_no'];
				 $uom1=$rsdata['uom'];
				 $nos1=$rsdata['nos'];
				 $qty1=$rsdata['qty'];
				
}
?>

<div style="height:200px; width:98%; padding-left:0px;  overflow-x:hidden; overflow-y:scroll; white-space:nowrap;" align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" >
    <tr bgcolor="#F2F2F2">
    <td width="41" height="35"  class="text style5 style1 style21"><strong>&nbsp;S.No&nbsp;</strong></td>
    <td width="146" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Date</strong></td>
    <td width="146" class="text style1 style5 style21"><strong>Invoice No</strong></td>
     <td width="216" class="text style1 style5 style21"><strong>Supplier Name</strong></td>
    <td width="223" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Particulars</strong></td>
     <td width="290" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Batch No</strong></td>
     <td width="290" class="text style1 style5 style21"><strong>&nbsp;&nbsp;UOM</strong></td>
     <td width="290" class="text style1 style5 style21"><strong>&nbsp;&nbsp;NOS</strong></td>
     <td width="290" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Qty</strong></td>
       
    <td width="101" align="center" class="text style1 style5 style3 style21"><strong>Action</strong></td>
 </tr>
   <?php
    $media_pur_no=$_GET['ink_pur_no'];
    $media_pur_no=$_POST['ink_pur_no'];
    $sql="select * from  ink_pur_sublist where (ink_pur_no='$_GET[ink_pur_no]' or ink_pur_no='$_POST[ink_pur_no]')";
    $rs=mysql_query($sql);
	$sno=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{ 
   				$sno=$sno+1;
   				$id=$rsdata['id'];
				$ink_pur_no=$rsdata['ink_pur_no'];
				$entrydates=$rsdata['entrydates'];
				$invoice_no=$rsdata['invoice_no'];
				$supplier_name=$rsdata['supplier_name'];
   				$particulars=$rsdata['particulars'];
				$batch_no=$rsdata['batch_no'];
				$uom=$rsdata['uom'];
				$nos=$rsdata['nos'];
				$qty=$rsdata['qty'];
			
				
				
				$row=$row+1;
								  $row1=$row%2;
								  if($row1==0)
								  {
								  $class='style="background-color:#f6faff;border-bottom:solid 1px;border-color:#E2E2E2"';
								  }
								  else
								  {
								  $class='style="background-color:#f3f3ff;border-bottom:solid 1px;border-color:#E2E2E2"';
								  }
  ?>
    <tr>
      <td align="center" class="text style4  style5"><?php echo $sno; ?></td>
      <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;&nbsp;<?php echo date('d-m-Y H:i',strtotime($entrydates));?></td>
      <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $invoice_no;?></td>
      <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;&nbsp;<?php echo $supplier_name;?></td>
            <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $particulars;?></td>
 <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $batch_no;?></td>
 <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $uom;?></td>
 <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $nos;?></td>
 <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $qty;?></td>
   <?php if(($user_id=='1')||($user_id=='3'))
	 { ?>
	  <td align="center" class="style5 style3 style4" ><img src="img/edit.png" onClick="inkpurchase_sublist_edit('<?php echo $id;?>','<?php  echo $ink_pur_no;?>')" width="18px" height="18px">&nbsp;&nbsp;<img src="img/cross-small.png"  title="Delete" onClick="delete_sublist_ink_pur('<?php echo $id;?>','<?php echo $ink_pur_no; ?>','<?php echo $particulars; ?>','<?php echo $batch_no; ?>')" width="20px" height="20px"></td><?php } ?>
</tr>
<?php 
$total_mtrs+=$qty;
} 
?>
<tr>
    <td class="text style4 style5"><?php echo $sno+1; ?></td>
    <td  align="left" class="text style4 style5" ><input type="datetime-local" name="entrydates" id="entrydates"  <?php if($_SESSION['user_type']!=1) { ?> readonly <?php } ?>   tabindex="3" style="width:100%; height:28px;" value="<?php if($edit_ids!='') { echo $entrydates; } else{ echo date('Y-m-d').'T'.date('H:i'); } ?>" class="types_class1" onkeypress="enterevent(event,'media_particular','entrydates')"/></td>
     <td align="left" class="text style4 style5" ><input name="invoice_no"  id="invoice_no" tabindex="4" value="<?php if($edit_ids!='') { echo $invoice_no; }  ?>" style="width:100%;  height:28px;"  onKeyUp="ink_pur_clear_validation(this.value)" class="types_class1"/>
   </td>
    <td align="left" class="text style4 style5" ><select name="sup_name"  class="types_class1" id="sup_name"  tabindex="4" style="width:100%;  height:28px;" onChange="ink_pur_clear_validation(this.value)" >
     <option value="">Select</option><?php error_reporting(0);
 include("../../include/db.php");
	$sql_user="select * from  party_creation where party_type='Supplier' ";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$id=$rsdata_user->party_id;
			$party_name=$rsdata_user->party_name;
			?>
<option value="<?php  echo $party_name; ?>"  <?php if($party_name==$supplier_name1){?> selected="selected" <?php }?>><?php echo $party_name;?></option><?php } ?></select></td>
 
    <td align="left" class="text style4 style5"><select name="particulars" class="types_class1" id="particulars"  tabindex="4" onChange="ink_pur_clear_validation(this.value)" style="width:100%;  height:28px;" >
     <option value="">Select</option><?php error_reporting(0);
 include("../../include/db.php");
	$sql_user="select * from  consumable_creation where item='Ink'  and status_type='Active' ";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$id=$rsdata_user->id;
			$particulars=$rsdata_user->particulars;
			?>
<option value="<?php  echo $particulars; ?>" <?php if($particulars==$particulars1){?> selected="selected" <?php }?>><?php echo $particulars;?></option><?php } ?></select></td>
        <td align="left" class="text style4 style5" ><input name="batch_no"  id="batch_no" tabindex="4" value="<?php if($edit_ids!='') { echo $batch_no1; }  ?>" style="width:100%;  height:28px;"  onKeyUp="ink_pur_clear_validation(this.value)" class="types_class1"/>
        <td  class="text style4 style5"><input type="text"  class="types_class1" name="uom" id="uom" style="width:100%;  height:28px;"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="ink_pur_clear_validation(this.value); updateQty();"  value="<?php if($edit_ids!=''){ echo $uom1; } else {  }?>" /></td>
        <td  class="text style4 style5"><input type="text"  class="types_class1" name="nos" id="nos" style="width:100%;  height:28px;"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="ink_pur_clear_validation(this.value); updateQty();"  value="<?php if($edit_ids!=''){ echo $nos1; } else {  }?>" /></td>
        <td  class="text style4 style5"><input type="text"  class="types_class1" name="qty" id="qty" style="width:100%;  height:28px;"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="ink_pur_clear_validation(this.value)"  value="<?php if($edit_ids!=''){ echo $qty1; } else {  }?>" readonly/><input type="hidden" name="width_hid" id="width_hid" value="<?php echo $width_hid; ?>"></td>

   
  
  
<td class="text style4 style5"><input type="button" name="add" style="width:100%;  height:28px;" id="add" tabindex="6" value="<?php if($edit_ids!='') { echo "EDIT"; } else { echo "ADD"; } ?>"   onClick="ink_pur_sub(ink_pur_no.value,ink_date.value,entrydates.value,invoice_no.value,sup_name.value,particulars.value,batch_no.value,uom.value,nos.value,qty.value,'<?php echo $edit_ids;?> ',this.value)"></td>
  </tr>
  <tr>
  <td></td> 
  <td> </td> 
  <td> <div id="invoice_no_valid_div" style="color:#F00;"></div></td>
  <td><div id="supp_name_valid_div" style="color:#F00;"></div></td>
  <td><div id="particulars_valid_div" style="color:#F00;"></div></td>
  <td><div id="batch_np_valid_div" style="color:#F00;"></div></td>
  <td><div id="uom_valid_div" style="color:#F00;"></div></td>
  <td><div id="nos_valid_div" style="color:#F00;"></div></td>
  <td><div id="qty_valid_div" style="color:#F00;"></div></td>
  <td width="1"></td>
 
  <td width="1"></td>
 
  </tr>
  <tr height="100px">
  <td></td> 
  <td></td> 
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
 </tr>
</table>
<input type="hidden" name="total" id="total" value="<?php echo $total_mtrs; ?>"/>
</div>
<table width="98%">
  <tr>

  <td colspan="8" align="right"  class="text"><strong>Total</strong></td>
 
  <td width="18%"  align="right" class="text"><strong><?php echo number_format($total_mtrs,2); ?></strong></td>
   <td width="15%" ></td>
  </tr></table>
  <script>
      function updateQty() {
    var uomValue = parseFloat(document.getElementById('uom').value);
    var nosValue = parseFloat(document.getElementById('nos').value);
    var qtyField = document.getElementById('qty');
    if (!isNaN(uomValue) && !isNaN(nosValue)) {
        var product = uomValue * nosValue;
        qtyField.value = product.toFixed(2); // Adjust to your precision requirement
    } else {
        qtyField.value = ''; // Clear the qty field if either uom or nos is not a valid number
    }
}
  </script>