<link rel="stylesheet" href="css/new_mxerp.css">

<?php
if(isset($_POST['Save']))
{
 $qty=$_REQUEST['sop_no'];

for($i=0;$i<count($qty);$i++)
{
 $sql="insert into tbl_monthwise_production set sop_no='".$_REQUEST['sop_no'][$i]."',delivery_schudule='".$_REQUEST['orderdate'][$i]."',item_code='".$_REQUEST['itemcode'][$i]."',quantity='".$_REQUEST['qty1'][$i]."',schedule_form='".$_REQUEST['s_from_time'][$i]."'
 ,schedule_to='".$_REQUEST['s_to_time'][$i]."',total_hrs='".$_REQUEST['totalhrs'][$i]."',CompanyId='".$_SESSION['ACGCompanyId'][$i]."'";
 
 $query=DB_query($sql,$db);
}
}	  
?>


<div class="body_contain">
<div class="tab_div">
	<h1>Month wise Production Schedule Against S.O.P</h1>



		<form name="frm" action="" method="post">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
		<tr>
		<td class="tabledata1">Branch</td>
	
		
		<td colspan="3">
	 <?php	
 		$sql = "SELECT loccode, locationname FROM locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
	 	$resultStkLocs = DB_query($sql,$db);
		?>
	<select name="site" style="width:100%" onchange="getdata1(this.value);" id="site">
	<option value="000">Select</option>
      <?php    
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
      <option value="<?php echo $myrow['loccode']; ?>"><?php echo $myrow['locationname'];?></option>
      <?php  }	?> 
    </select></td></tr>
		<tr>
		<td class="tabledata1">From Date</td>
		<td><input type="text" name="frmdate" id="frmdate" class="datepicker" style="width:100%" /></td>
		<td class="tabledata1">To Date</td>
		<td><input type="text" name="todate" id="todate" class="datepicker"  style="width:100%" /></td>
		
		
		
		</tr>			
		</table>
		<p align="left" style="margin:0px;"><input type="submit" name="Search"  value="Search"/></p>
		
		
		</form>
		
		
		
	<form action="" method="post">	
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata">Sr. No.</td>
    <td class="tabledata">S.O.P</td>
    <td class="tabledata">Delivery Schedule</td>
    <td class="tabledata">Item</td>
    <td class="tabledata">Quantity</td>
    <td class="tabledata">Schedule From</td>
     <td class="tabledata">Schedule To</td>
      <td class="tabledata">Total Hrs</td>
  </tr>
  <?php 
  if(isset($_POST['Search']))
  {
  	$fordate = $_POST['frmdate'];
	$todate = $_POST['todate'];
	$fromdate = explode("/", $fordate);
	$daydate = $fromdate['0'];
	$Monthdate = $fromdate['1'];
	$yeardate = $fromdate['2'];
	$fdate = $yeardate."-".$Monthdate."-".$daydate;					   
	$tredate   = explode("/", $todate);
	$dayda     = $tredate['0'];
	$Monthda   = $tredate['1'];
	$yearda    = $tredate['2'];
	$toyrdate  = $yearda."-".$Monthda."-".$dayda;
	$filter = array();	
	if(isset($_REQUEST['site']) && $_REQUEST['site'] != '000')
  	$filter[]="branch='".$_REQUEST['site']."' ";
	if($_REQUEST['frmdate'] != '' && $_REQUEST['todate'] != '')
 	$filter[]="orderDate between '".$fdate."' and '".$toyrdate."'  ";
	  if($filter != '')
	  {
		$filter1 = implode(" and ",$filter);
       }
    	 $sql="select * from salesorder where $filter1";
			 $query=DB_query($sql,$db);
			 $num1=DB_num_rows($query);
			 if($num1>0)
			 {
			 $i=1;	
			 while($row=DB_fetch_array($query))
			 {
			
			 $sql1=DB_query("select * from job_route_card where sop_no='".$row['id']."'",$db);
			  $num2=DB_num_rows($sql1);	
			  if($num2<=0)
			  { 
			  $item=$s->getField('item_master','id',$row['id'],'StockID');
			  $itemname=$s->getField('item_master','StockID',$item,'item_name');	
			  $qty=$s->getField('salesorder_details','masterId',$row['id'],'Quantity');	
			  	?>
  
<tr bgcolor="#c1c1c1">
    <td><?php echo $i; ?></td>
<td><?php echo $row['orderNo']; ?><input type="hidden" name="sop_no[]" value="<?php echo $row['orderNo']; ?> " /></td>
   <td><?php echo $row['orderDate']; ?>
   	<input type="hidden" name="orderdate[]" value="<?php echo $row['orderDate'];?> " />
   </td>
   <td><?php echo $itemname; ?> <input type="hidden" name="itemcode[]" value="<?php echo $item;  ?>" /></td>
   <td><?php echo $qty; ?><input type="hidden" name="qty1[]" value="<?php echo $qty; ?>" /></td>
   <td><a href="javascript:NewCal('s_from_time_<?php echo $i; ?>','ddmmmyyyy',true,24)"><input type="text" name="s_from_time[]"  id="s_from_time_<?php echo $i; ?>" /></a>
   </td>
    <td><a href="javascript:NewCal('s_to_time_<?php echo $i; ?>','ddmmmyyyy',true,24)"><input type="text" name="s_to_time[]"  id="s_to_time_<?php echo $i; ?>"/></a></td>
    <td><input type="text" name="totalhrs[]"  id="totalhrs_<?php echo $i; ?>" onfocus="totalhrs(<?php echo $i; ?>)"/></td>
  </tr><?php $i++; } } } }?>

</table>
<p align="center"><input type="submit" name="Save" value="Save" /></p>
</form>


</div>
</div>
<script language="javascript" type="text/javascript" src="js/datetimepicker.js"></script>

<script>
	
function totalhrs(i)
{
alert("jell");
var msecPerMinute = 1000 * 60;
var msecPerHour = msecPerMinute * 60;
var msecPerDay = msecPerHour * 24;
var today1 =document.getElementById("s_to_time_"+i).value;
var today2=today1.format();
alert(today1);
//var today2=today.split(" ");
var before = document.getElementById("s_from_time_"+i).value;
//var before2=before.split(" ");
//var today2=today1.split(" ");
var today=dateFormat(today1,"dddd, mmmm dS, yyyy, h:MM:ss TT");
var before=dateFormat(before1, "dddd, mmmm dS, yyyy, h:MM:ss TT");
//alert(Date());
var interval = today.getTime() - before.getTime();
alert(interval);
var days = Math.floor(interval / msecPerDay );
interval = interval - (days * msecPerDay );
var hours = Math.floor(interval / msecPerHour );
interval = interval - (hours * msecPerHour );
var minutes = Math.floor(interval / msecPerMinute );
interval = interval - (minutes * msecPerMinute );
var seconds = Math.floor(interval / 1000 );
var msg = days + " days, " + hours + " hours, "
 + minutes + " minutes, " + seconds + " seconds.";
 document.getElementById("totalhrs_"+i).value=msg;
	
	
}	
	
	
</script>

