<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);
include("../../include/db.php");
ob_start();
session_start();
$user_id = $_SESSION['login_user_id'];
function get_roll_id_edit($roll_name_edit)
{
	$Isql=mysql_query("select * from consumable_creation where particulars='$roll_name_edit'");
    $rscount=mysql_num_rows($Isql);
	while($rsdata_user=mysql_fetch_object($Isql))
			{ 
			 $id11=$rsdata_user->id;
			 
			}
			return $id11;
}
$Isql="select start,end from gab_interval";
 $rs=mysql_query($Isql);
  while($Isql=mysql_fetch_array($rs))
  {
 $start = $Isql['start'];
 $end = $Isql['end'];
  }

  $edit_ids=$_POST['edit_id']; 
  $jobcard_no=$_POST['jobcard_no'];
  $sql="select * from media_sub_list where id='$_POST[edit_id]' ";
  // echo "select * from media_sub_list where id='$_POST[edit_id]' ";
  $rs=mysql_query($sql);
  while($rsdata=mysql_fetch_array($rs))
  {
				$sno=$sno+1;
				$id=$rsdata['id'];
				$jobcard_no_edit=$rsdata['jobcard_no'];
				$media_particular_edit=$rsdata['media_particular'];
				$roll_name_edit=$rsdata['roll_name'];
				$batch_no_edit=$rsdata['batch_no'];
     
				$roll_id_edit=get_roll_id_edit($roll_name_edit);
	      $order_qty_edit=$rsdata['order_qty'];
				$plan_qty_edit=$rsdata['plan_qty'];
				$steps_edit=$rsdata['steps'];
				$steps_used_edit=$rsdata['steps_used'];
		    $gap_mtr_edit = $rsdata['gap_mtr'];
        $gap_edit = $rsdata['gap'];
				$total_steps_edit=$rsdata['total_steps'];
				$req_by_edit=$rsdata['req_by'];
				$tot_req_by_edit=$rsdata['tot_req_by'];
				$roll_size_edit=$rsdata['roll_size'];
				$width_edit=$rsdata['width'];
				$height_edit=$rsdata['height'];
				$entrydates_edit=$rsdata['entrydates'];
				$width_hid_edit=$rsdata['width_hid'];
				$height_hid_edit=$rsdata['height_hid'];
        // echo $roll_id_edit;
	$media_part=mysql_fetch_array(mysql_query("select *,SUM(tot_mtr) as tot_qty from media_pur_batch_tot_value where particulars_id='$roll_id_edit' and `batch_no`='$batch_no_edit' group by batch_no "));

 $media_qty=$media_part['tot_qty'];			

 $media_part_tot=mysql_fetch_array(mysql_query("select *, SUM(total_meter)as total_meter from media_pur_batch_tot_value where particulars_id='$roll_id_edit' and `batch_no`='$batch_no_edit' group by batch_no "));
//  $media_qty=$media_part['tot_qty'];			
 $total_meter=$media_part_tot['total_meter'];

}
?>

<div style="height:200px; width:98%; padding-left:0px;  overflow-x:hidden; overflow-y:scroll; white-space:nowrap;" align="center">
<?php

$sql1 = "select * from jobcard_main where fabric_type != 'F EMBOSS GEL   EMBOSING ' and jobcard_no LIKE '%$jobcard_no%'";

$rsd1 = mysql_query($sql1);

while($rs1 = mysql_fetch_array($rsd1)) 
{
	$job_type= $rs1['job_type'];
	$approve_status=$rs1['approval_status'];
} 
// echo $approve_status;
$sql12="select * from job_type_creation where job_type='$job_type'";
$rs12=mysql_query($sql12);
while($rsdata12=mysql_fetch_array($rs12))
			{
				$job_type_status = $rsdata12['job_type_status'];
				
			}
			if($approve_status!=0){
			if($job_type_status == 'Inactive')
			{
				echo "<h3>Media Entry Status Inactive</h3>";
				
			}
			else{?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" >
    <tr bgcolor="#F2F2F2">
    <td width="40"  class="text style5 style1 style21"><strong>&nbsp;S.No&nbsp;</strong></td>
    <td width="121" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Date</strong></td>
    <td width="225" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Particulars</strong></td>
     <td width="61" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Width</strong></td>
      <td width="61" class="text style1 style5 style21"><strong>&nbsp;&nbsp;Height</strong></td>
    <td width="88" align="right" class="text style1 style5 style21"><strong>Order Qty</strong>&nbsp;</td>
    <td class="text style1 style5 style21" align="right"><strong>Plan Qty</strong>&nbsp;</td>
      <td width="109" class="text style1 style5 style21"><strong>Roll Size</strong></td>
    <td width="91" align="right" class="text style1 style5 style21"><strong>Req By</strong>&nbsp;</td>
     <td class="text style1 style5 style21" align="right"><strong>Steps Used</strong>&nbsp;</td>
    <td class="text style1 style5 style21" align="right"><strong>Steps</strong>&nbsp;</td>
     <td width="92" align="right" class="text style1 style5 style21"><strong>Total Repeats </strong>&nbsp;</td>
    <td class="text style1 style5 style21" align="right"><strong>Gap</strong>&nbsp;</td>
    

     <td width="92" align="right" class="text style1 style5 style21"><strong>Gap Mtr</strong>&nbsp;</td>
   
    <td width="93" align="right" class="text style1 style5 style21"><strong>Total Req</strong>&nbsp;</td>
    
     <td class="text style1 style5 style21" align="right"><strong>Batch No</strong>&nbsp;</td> 
     
    <td width="101" align="center" class="text style1 style5 style3 style21"><strong>Action</strong></td>
   
 </tr>
   <?php
    $jobcard_no_get=$_GET['jobcard_no'];
    $jobcard_no_post=$_POST['jobcard_no'];
    $sql="select * from  media_sub_list where jobcard_no='$jobcard_no_post' or jobcard_no='$jobcard_no_get'";
    $rs=mysql_query($sql);
	$sno=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{ 
          

   				$sno=$sno+1;
   				$id=$rsdata['id'];
				$jobcard_no=$rsdata['jobcard_no'];
				$roll_name=$rsdata['roll_name'];
				$batch_no=$rsdata['batch_no'];
				$entrydates=$rsdata['entrydates'];
				$media_date=$rsdata['media_date'];
   				$media_particular=$rsdata['media_particular'];
				$order_qty=$rsdata['order_qty'];
				$plan_qty=$rsdata['plan_qty'];
				 $steps=$rsdata['steps'];
				$steps_used=$rsdata['steps_used'];
                $gap = $rsdata['gap'];
                $gap_mtr = $rsdata['gap_mtr'];
                $req_by=$rsdata['req_by'];
				$total_steps=$rsdata['total_steps'];
				$tot_req_by=$rsdata['tot_req_by'];
				$roll_size=$rsdata['roll_size'];
				$width=$rsdata['width'];
				$height=$rsdata['height'];
				
				$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($media_date));?></td>
       <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $media_particular;?></td>
    
  
 <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $width;?></td>
  <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $height;?></td>
      <td align="right" class="text style5 style4"><?php echo $order_qty;?>&nbsp;&nbsp;</td>
      <td align="right" class="text style5 style4"><?php echo $plan_qty;?>&nbsp;&nbsp;</td>
        <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $roll_name;?></td>
	   <td align="right" class="text style5 style4"><?php echo $req_by;?>&nbsp;&nbsp;</td>
      <td align="right" class="text style5 style4"><?php echo $steps_used;?>&nbsp;&nbsp;</td> 
	    <td align="right" class="text style5 style4"><?php echo $steps;?>&nbsp;&nbsp;</td> 
		<td align="right" class="text style5 style4"><?php echo $total_steps;?>&nbsp;&nbsp;</td>
      <td align="right" class="text style5 style4"><?php echo $gap;?>&nbsp;&nbsp;</td>
 <td align="right" class="text style5 style4"><?php echo $gap_mtr;?>&nbsp;&nbsp;</td>
     
      
      <td align="right" class="text style5 style4"><?php echo  $tot_req_by;?>&nbsp;&nbsp;</td>
      
        <td align="left" class="text style5 style4" style="padding-left:2px;">&nbsp;<?php echo $batch_no;?></td>
     <?php if(($user_id=='1')||($user_id=='3'))
	 { ?>
      
      <td align="center" class="style5 style3 style4" ><img src="img/edit.png" onClick="mediaent_sublist_edit('<?php echo $id;?>','<?php  echo $jobcard_no;?>')" width="18px" height="18px">&nbsp;&nbsp;<img src="img/cross-small.png"  title="Delete" onClick="delete_sublist_media('<?php echo $id;?>','<?php echo $jobcard_no; ?>')" width="20px" height="20px"></td><?php } ?></tr>
<?php 
$tot_req_by3+=$tot_req_by;
} 
?>
<tr>
    <input type="hidden" name="start" id="start" value="<?php echo $start; ?>"/> 
   <input type="hidden" name="end" id="end" value="<?php echo $end; ?>"/>
    <td align="center"  class="text style4 style5"><?php echo $sno+1; ?></td>
    <td  align="left" class="text style4 style5" ><input type="datetime-local"  <?php if($_SESSION['user_type']!=1) { ?> readonly <?php } ?>  name="entrydates" id="entrydates"   tabindex="3" value="<?php if($edit_ids!='') { echo $entrydates_edit; } else{ echo date('Y-m-d').'T'.date('H:i'); } ?>" style="height:28px; width:100%;" class="types_class1" /></td>
  
     <td align="left" class="text style4 style5"><div id="media_partic_divs"><select name="media_particular"  class="types_class1" id="media_particular"  tabindex="4"  onchange="get_qty_sub_media(in_jobcard_no_media.value,media_particular.value),media_sub_clear_validation(this.value)"  style=" height:30px; width:100%;">
      <?php if($edit_ids!=''){ ?>
      <option value="<?php if($edit_ids!=''){ echo $media_particular_edit; } else {  }?>"><?php if($edit_ids!=''){ echo $media_particular_edit; } else {  }?></option>    <?php } ?>
    </select></div></td>
        <td  class="text style4 style5"><div id="width1_sub_divs"><input type="text" class="types_class1" name="width1" id="width1"   onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false"   onKeyUp="media_sub_clear_validation(this.value),get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value),get_total_steps_used(req_by.value,roll_name.value,width1.value,height1.value)"  style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $width_edit; } else {  }?>" /><input type="hidden" name="width_hid" id="width_hid" value="<?php if($edit_ids!=''){  echo $width_hid_edit; } else {echo $tot_mtr;} ?>"></div></td>

    <td  class="text style4 style5"><div id="height1_sub_divs"><input type="text" class="types_class1" name="height1" id="height1"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false"   onKeyUp="media_sub_clear_validation(this.value),get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value),get_total_steps_used(req_by.value,roll_name.value,width1.value,height1.value)"  style="height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $height_edit; } else {  }?>" /><input type="hidden" name="height_hid" id="height_hid" value="<?php  if($edit_ids!=''){  echo $height_hid_edit; } else { echo $tot_mtr; } ?>"></div></td>

    <td  class="text style4 style5"><div id="qty_sub_divs"><input type="text" class="types_class1" name="order_qty" id="order_qty" readonly onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false"  style="height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $order_qty_edit; } else {  }?>" /></div></td>

  <td width="76"  class="text style4 style5"><input type="text" class="types_class1" name="plan_qty" id="plan_qty"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false,media_sub_clear_validation(this.value)"  style="height:30px; width:100%;" onkeyup="media_sub_clear_validation(this.value),get_tot_steps(plan_qty.value,steps.value,tot_qty_hid.value,tot_qty_hid1.value),media_entry_qty_validation(order_qty.value,plan_qty.value),get_gap_mtr(total_steps.value,gap.value),get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)" value="<?php if($edit_ids!=''){ echo $plan_qty_edit; } else {  }?>" /></td>
  
    <td align="left" class="text style4 style5" ><select name="roll_name" id="roll_name" class="types_class1" onChange="media_sub_clear_validation(this.value),get_total_steps_used(req_by.value,roll_name.value,width1.value,height1.value),get_batch_no(this.value,in_jobcard_no_media.value)"    tabindex="4"  style="width:100%; height:30px;">
     <option value="">Select</option>

	 <?php error_reporting(0);
 include("../../include/db.php");
	$sql_user="select * from  media_pur_sublist where status_type = 'Active' group by particulars  ";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$id=$rsdata_user->particulars_id;
			$particulars=$rsdata_user->particulars;
			?>
<option value="<?php  echo $particulars; ?>" <?php if($id==$roll_id_edit){echo "selected";}?>><?php echo $particulars;?></option><?php } ?></select><div id="in_jobcard_roll_media_validation_div" style="color:#FF0000;"></div></td>
 
  <td  class="text style4 style5"><select name="req_by"  id="req_by"  tabindex="4"  class="types_class1" style="height:30px; width:100%;" onChange="get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value),media_sub_clear_validation(this.value),get_total_steps_used(req_by.value,roll_name.value,width1.value,height1.value),get_total_steps(req_by.value,roll_name.value,width1.value,height1.value)" onfocus="get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)">
     <option value="">select</option>
     <option value="Width"  <?php if($req_by_edit=='Width') {echo "Selected";}?>>Width</option>
      <option value="Height"  <?php if($req_by_edit=='Height') {echo "Selected";}?>>Height</option>
</select>
<input type="hidden" name="tot_qty_hid" id="tot_qty_hid" value="<?php   if($edit_ids!=''){ echo $media_qty;} else {  } ?>"></td>

<input type="hidden" name="tot_qty_hid1" id="tot_qty_hid1" value="<?php   if($edit_ids!=''){ echo $total_meter;} else {  } ?>"></td>

 <td width="92"  class="text style4 style5"><input type="text" class="types_class1" name="steps_used" id="steps_used" readonly onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="media_sub_clear_validation(this.value)"   style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo  $steps_used_edit; } else {  }?>"  /></td> 
  
   <!-- <td width="92"  class="text style4 style5"><input type="text" class="types_class1" name="steps" id="steps" onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="get_tot_steps(plan_qty.value,steps.value,tot_qty_hid.value,tot_qty_hid1.value),media_sub_clear_validation(this.value)"   style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $steps_edit; } else {  }?>"  /></td> 
 -->


   <td width="92"  class="text style4 style5"><input type="text" class="types_class1" name="steps" id="steps" readonly onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="get_tot_steps(plan_qty.value,steps.value,tot_qty_hid.value,tot_qty_hid1.value),media_sub_clear_validation(this.value)"   style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo  $steps_edit; } else {  }?>"  /></td> 

  
   <td  class="text style4 style5"><input type="text" class="types_class1" name="total_steps" id="total_steps"  readonly onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onKeyUp="get_gap_mtr(total_steps.value,gap.value),get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)" style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $total_steps_edit; } else {  }?>" /></td>
   
  <td width="92"  class="text style4 style5"><input type="text" class="types_class1" name="gap" id="gap" onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false"  onKeyUp="get_gap_mtr(total_steps.value,gap.value),get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)"
  onchange="media_sub_clear_validation(this.value)"  oninput="" style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $gap_edit; } else {  }?>"  /></td>



  <td  class="text style4 style5"><input type="text" class="types_class1" name="gap_mtr" id="gap_mtr"  readonly onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false" onchange="get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)"onfocus="get_tot_req(req_by.value,width_hid.value,height_hid.value,total_steps.value,gap_mtr.value)" style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $gap_mtr_edit; } else {  }?>" /></td>

  <td  class="text style4 style5"><input type="text" class="types_class1" name="total_req" id="total_req" readonly="readonly"  onKeyPress="if ((event.keyCode &lt; 46) || (event.keyCode &gt; 57)) event.returnValue = false"  style=" height:30px; width:100%;" value="<?php if($edit_ids!=''){ echo $tot_req_by_edit; } else {  }?>" /></td>
  
  <td align="left" class="text style4 style5">
  <div id="batch_no_divs">
    <select name="batch_no" id="batch_no" class="types_class1" 
      onChange="media_sub_clear_validation(this.value),get_total_steps_used(req_by.value,roll_name.value,width1.value,height1.value)" 
      tabindex="4" style="width:100%; height:30px;">

      <option value="">Select</option>

      <?php  
      if($edit_ids != '') {
          error_reporting(0);
          include("../../include/db.php");

          $sql_user = "SELECT *, SUM(tot_mtr) as tot_qty 
                       FROM media_pur_batch_tot_value 
                       WHERE particulars='$roll_name_edit' AND batch_no!='' 
                       GROUP BY batch_no 
                       ORDER BY batch_no ASC";

          $rs_user = mysql_query($sql_user);

          while($rsdata_user = mysql_fetch_object($rs_user)) { 
              $id = $rsdata_user->id;
              $particulars = $rsdata_user->particulars;
              $batch_nos = $rsdata_user->batch_no;
              $tot_qty01 = $rsdata_user->tot_qty;

              // Fetch corresponding media_sub_list details
              $media_part_query = "SELECT *,SUM(tot_req_by) as tot_req_by FROM media_sub_list 
WHERE roll_name='$particulars' AND batch_no='$batch_nos'";
              $media_part_result = mysql_query($media_part_query);
              $media_part01 = mysql_fetch_array($media_part_result);

              $media_qty01 = $media_part01['tot_req_by'];

              // Calculate remaining quantity
              $tot_qty23 = $tot_qty01 - $media_qty01;

              // Output the option
              $selected = ($batch_nos == $batch_no_edit) ? 'selected' : '';
              ?>
              <option value="<?php echo $batch_nos; ?>" <?php echo $selected; ?>>
                  <?php echo $batch_nos . ' (' . number_format($tot_qty23, 2) . ')'; ?>
              </option>
              <?php 
          }
      }
      ?>
    </select>
    <div id="in_jobcard_roll_media_validation_div" style="color:#FF0000;"></div>
  </div>
</td>



  
<td class="text style4 style5"><input type="button" name="add" id="add" tabindex="6" value="<?php if($edit_ids!='') { echo "EDIT"; } else { echo "ADD"; } ?>"  style="height:30px; width:100%;" onClick="media_sublist(in_jobcard_no_media.value,in_cust_name.value,media_date.value,roll_name.value,batch_no.value,media_particular.value,order_qty.value,plan_qty.value,gap.value,total_steps.value,req_by.value,total_req.value,width1.value,fabric_type.value,created_by.value,job_types.value,entrydates.value,height1.value,width_hid.value,height_hid.value,'<?php echo $edit_ids;?> ',this.value,start.value,end.value,steps_used.value,steps.value,gap_mtr.value,tot_qty_hid.value,tot_qty_hid1.value)"></td>
  </tr>
  <tr>
  <td></td> 
  <td ></td> 
 
  <td><div id="media_particular_validation_div22" style="color:#FF0000;"></div></td>
  <td><div id="media_width_validation_div" style="color:#FF0000;"></div></td>
  <td><div id="media_height_validation_div" style="color:#FF0000;"></div></td>
  <td ></td> 
  <td><div id="media_paln_qty_validation_div" style="color:#FF0000;"></div></td>
   
  <td></td>
  <td><div id="media_req_by_validation_div" style="color:#FF0000;"></div></td>
	 <td ></td> 
	  <td><div id="media_steps_validation_div" style="color:#FF0000;"></div></td>
	   <td ></td> 
    <td><div id="media_gap_validation_div" style="color:#FF0000;"></div></td>
	
  </tr>
  <tr height="100px">
  <td></td> 
  <td></td> 
  <td></td>
  <td></td>
  <td></td>
  <td><input type="hidden" name="total_net" id="total_net" value="<?php  echo number_format($tot_req_by3,2); ?>"/></td>
 </tr>
</table>
</div>
<table width="98%">
  <tr>
  <td width="6"></td> 
  <td colspan="2"></td> 
  <td width="6"></td>
  <td width="6"></td>
  <td width="6"></td>
  <td width="6"></td>
  <td width="6"></td>
  <td width="6"></td>
  <td width="199" class="text"><strong>Total</strong></td>
 
  <td width="137" align="right" class="text"><strong><?php echo number_format($tot_req_by3,2); ?></strong></td>
   <td width="59"></td>
  <td width="49" align="right"></td>
  </tr></table>
  <?php }
} ?>