<?php 
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];

if($_REQUEST['id']!='' && $_REQUEST['action']=='Delete') 
{ 
$del="delete from prd_model_group where id='".$_REQUEST['id']."'";
$query=DB_query($del,$db);
 $s->pageLocation("index.php?route=Production/model_group_index".$rurl);//PAGE REDIRCTION
}

if(isset($_POST['Save']))
{
for($i=0;$i<count($_REQUEST['vendorId']);$i++)
{
   $val=$_REQUEST['vendorId'][$i];
    $data['mst_itemid']=$_REQUEST['vendorId'][$i];
	$data['parentid']=$_REQUEST['modelid'];
	$data['qty']=$_REQUEST['quantity'][$val];
	$data['Created_by']=$_SESSION['UserID'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['Created_date']=date('Y-m-d');
	$s->RecordInsert('prd_model_sub_group',$data);
}


}


?>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div style="display:none" id="div_id">
</div>
<div class="body_contain">
<div class="tab_div">
<h3 align="center"><strong>Model Group</strong></h3>
<div align="left"><a href="#" onClick="showSlidingDiv(); return false;"><input type="button" class="search" value="Show Search" style="width:140px;cursor:pointer;"/></a>
<?php //if($_SESSION['frmAdd']=='1') {?>
<!--<a href="index.php?route=Production/model_group&modid=<?php //echo $_REQUEST['modid'];?>&frmid=<?php //echo $_REQUEST['frmid'];?>&NewIssue=yes" class="search" style="text-decoration:none;"><input type="button" class="search" value="Add New Model Group" style="width:140px;cursor:pointer;"/></a>-->
<?php //} ?>
<form action="" method="post">
<div id="slidingDiv" class="centre" >
<table width="100%" border="1" cellspacing="1" cellpadding="2" align="center">
  <tr class="row1">
	<td class="tabledata1" ><strong>Model Code</strong></td>
    <td class="tabledata1">
	<?php	
		$ss="Select * from prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	 ?>
	 <select name="modelcode"> 
    <option  value="000">Select Model Code</option>
	<?php 
	
		while ($myrow=DB_fetch_array($site_sql)){
 				echo '<option Value="' . $myrow['id'] . '">' . $myrow['model_group_code'].'</option>';
 		}
      

	?> </select></td>
	<td class="tabledata1" ><strong>Model Name</strong></td>
     <td class="tabledata1">
	
    <?php	
		$ss="Select * from prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	 ?>
	 <select name="modelname"> 
    <option  value="000">Select Model Code</option>
	<?php 
	
		while ($myrow=DB_fetch_array($site_sql)){
 				echo '<option Value="' . $myrow['id'] . '">' . $myrow['model_group_name'].'</option>';
 		}
      

	?> </select>
	
	</td></tr>
   
	<tr class="row1">
	<td class="tabledata1" colspan="4" align="center" style="text-align:center;" ><input name="Search" type="submit" value="Search" class="search" /></td>
	</tr>
  </table>

</div>
<br/>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">
  <tr>
    <td class="tabledata"><strong>Sr. No.</strong></td>
    <td class="tabledata"><strong>Model Group Code </strong></td>
    <td class="tabledata"><strong>Model Group Name</strong></td>
	<td class="tabledata"><strong>Validate Sub Model Group</strong></td>
  </tr>
  <?php
     if(isset($_POST['Search']))
	 {
	 
       
		$modelcode=$_REQUEST['modelcode'];
		$modelname=$_REQUEST['modelname'];
		
		if($modelcode!='000')
		{
		$filter[]="id='".$modelcode."'";
		}
		if($modelname!='000')
		{
		$filter[]="id ='".$modelname."'";
		}
		
      
      if(isset($filter))
		{
		
		 if(count($filter)>0)		 
			{
			$filter1=implode(" and ",$filter);
		    $SQL ="SELECT * FROM prd_model_group where $filter1 order by id DESC";			   
			}
		else
			{			
			 $SQL ="SELECT * FROM prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."'  order by id DESC";
	        }
			
		}
		else 
		{
		$SQL ="SELECT * FROM prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."'  order by id DESC";
		}
	}	
	
else 
{   

 $SQL = "SELECT * FROM prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."'  order by id DESC";
  
}  


  
  $sql=DB_query($SQL,$db);
 
  $i=1;
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
   $check=$s->getField('prd_model_sub_group','parentid',$myrow['id'],'id');
  ?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo $i;?><input type="hidden" name="modlegroup[]" id="modlegroup_<?php echo $i; ?>" value="<?php echo $myrow['id']; ?>" ></td>
    <td><?php echo $myrow['model_group_code'];?></td>
     <td><?php echo $myrow['model_group_name'];
	 //$s->getField('item_master','id',$myrow['model_group_name'],'item_name');?></td>
	  <td><input type="button" name="ShowMappedVendors" id="ShowMappedVendors_<?php echo $i?>" value="Validate Sub Model" class="search"/></td>
    
  </tr>
  <?php $i++;} }
  else
  {?>
 
  <tr>
  <td colspan="12"><h3 align="center"><strong>No Record Found</strong></h3></td>
  </tr>
  <?php 	
  }
  ?>
   <input type="hidden" id="count" value="<?php echo $i; ?>" />
</table>
</form>
</div></div>


<script type="text/javascript" language="javascript">
$.noConflict();	


$(document).ready(function(){	


		var cnt=document.getElementById("count").value;
		
		$('input[name=ShowMappedVendors]').click(function(){
		
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		
		var id=document.getElementById("modlegroup_"+tt2).value;
		
			$("#div_id").dialog({
				title:'Mapped Sub Group Item',
				modal: true,
				resizable: false,
				width:700,
				height:500,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
						Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
			
		CheckVendors(id);
		});
		
	
	});
	
	function CheckVendors(id)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("div_id").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","Getsubmodelgroup.php?id="+id,true);
	xmlhttp.send();
}


function validateadd()
{
	var count=document.getElementById("count").value;
	var counter=0;
	for(var i=0;i<count;i++)
	{
		var chkbox=document.getElementById("vendorId_"+i).checked;
		if(chkbox==true)
		{
			counter=1;
		}
	}
	if(counter=='0')
	{
		alert("Please Ckeck At Least One Leave For Update !");
		return false;
	}
}

function getDetails(i)
{
if(document.getElementById("quantity_"+i).value=='')
{
alert("Must Enter Quantity");
document.getElementById("quantity_"+i).focus();
document.getElementById("vendorId_"+i).checked=false;
}


}


</script>