<?php 
$PageSecurity = 11;
$title = _('Size Master');
include('includes/SQL_CommonFunctions.inc');

if($_GET['id']!='' && $_GET['action']=='delete')
{
	$delete_sql=DB_query("Delete from size_master where id='".$_GET['id']."'",$db);	
	echo "<script>location.href='index.php?route=size_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'] != '')
{
	 $Chk=DB_query("select * from size_master where CompanyId='".$_SESSION['ACGCompanyId']."' and type_product='".$_REQUEST['type_product']."' and size='".$_REQUEST['size']."'",$db);
	$Chk1=DB_fetch_array($Chk);
	if(DB_num_rows($Chk)>0)
	{	
		if($Chk1['security']=='Deactivate')
		{
			echo '<script>alert("This Size Is Already Available Please Activate It");</script>';
		}
		else
		{
			echo '<script>alert("This Size Is Already Available");</script>';
		}
		
 	}
	else{
	$data['type_product']=$_REQUEST['type_product'];
	$data['desc1']=$_REQUEST['desc'];
	$data['width']=$_REQUEST['width'];
	$data['height']=$_REQUEST['height'];
	$data['size']=$_REQUEST['size'];
	$data['area']=$_REQUEST['area'];
	$data['door_uom']=$_REQUEST['door_uom'];
	$data['frame']=$_REQUEST['frame'];
	$data['frame_uom']=$_REQUEST['frame_uom'];
	$data['frame_category']=$_REQUEST['frame_category'];
	$data['sutter']=$_REQUEST['sutter'];
	$data['shutter_uom']=$_REQUEST['shutter_uom'];
	$data['shutter_category']=$_REQUEST['shutter_category'];
	$data['security']=$_REQUEST['security'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['created_by']=$_SESSION['UserID'];
	$data['created_date']=date('Y-m-d');
	$s->RecordInsert('size_master', $data);
	prnMsg( _('Record Inserted Successfully!'),'success');
	echo "<script>location.href='index.php?route=size_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	}
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from size_master where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	extract($get_row);
}
if($_REQUEST['Update'] != '' && $_REQUEST['row_id']!='')
{
	$data1['type_product']=$_REQUEST['type_product'];
	$data1['desc1']=$_REQUEST['desc'];
	$data1['width']=$_REQUEST['width'];
	$data1['height']=$_REQUEST['height'];
	$data1['size']=$_REQUEST['size'];
	$data1['area']=$_REQUEST['area'];
	$data1['door_uom']=$_REQUEST['door_uom'];
	$data1['frame']=$_REQUEST['frame'];
	$data1['frame_uom']=$_REQUEST['frame_uom'];
	$data1['frame_category']=$_REQUEST['frame_category'];
	$data1['sutter']=$_REQUEST['sutter'];
	$data1['shutter_uom']=$_REQUEST['shutter_uom'];
	$data1['shutter_category']=$_REQUEST['shutter_category'];
	$data1['security']=$_REQUEST['security'];
	$cond="id='".$_REQUEST['id']."'";
	$s->RecordEdit('size_master', $data1, $cond);
prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=size_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<input type="hidden" name="companyId" id="companyId" value="<?php echo $_SESSION['ACGCompanyId']; ?>" />
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo 'Size Master'; ?></h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td colspan="4" class="tabledata1"><h3>General Information</h3></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Type of Product</strong></td>
    <td colspan="3"><select name="type_product" id="type_product" style="width:150px;">
    	<option value="0">--Select--</option>
		<?php $typepro=DB_query("SELECT * FROM stockcategory where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($ProductName=DB_fetch_array($typepro)){ ?>
			<option value="<?php echo $ProductName['id']?>"<?php echo($type_product==$ProductName['id']?'selected':'');?>><?php echo $ProductName['categorydescription']?></option>	
		<?php }?>
		</select></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Description</strong></td>
    <td colspan="3"><input type="text" class="cap" name="desc" id="desc" value="<?php echo $desc1; ?>" style="width:150px;" /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td colspan="6" class="tabledata1"><h3>Size Information</h3></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Width(mm)</strong></td>
    <td><input name="width" type="text" id="width" value="<?php echo $width; ?>"  style="width:150px;"></td>
	 <td class="tabledata1"><strong>Height(mm)</strong></td>
    <td><input name="height" type="text" id="height" value="<?php echo $height; ?>" onkeyup="calsize(this.value)"  style="width:150px;"></td>
	 <td class="tabledata1"><strong>Size</strong></td>
    <td><input name="size" type="text" id="size" value="<?php echo $size; ?>" readonly=""   style="width:150px;">
		<div id="duplicate" style="display:none;"></div>
	</td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Area(SMT)</strong></td>
    <td><input name="area" type="text" id="area" readonly="" value="<?php echo $area; ?>"  style="width:30%;">
	<select name="door_uom" style="width:65%;">
	<option value="">Select UOM For Door</option>
	<?php 
	$sql3=DB_query("Select * from unitsofmeasure",$db);
	while($row3=DB_fetch_array($sql3))
	{?>
		<option value="<?php echo $row3['unitid'];?>" <?php echo ($door_uom==$row3['unitid']?'selected':'')?>><?php echo $row3['unitname'];?></option>
	<?php 
	}
	?>
	</select>
	</td>
	 <td class="tabledata1"><strong>Frame(RMT)</strong></td>
    <td><input name="frame" type="text" id="frame" value="<?php echo $frame; ?>" readonly=""  style="width:30%;">&nbsp;<select name="frame_uom" style="width:65%;">
	<option value="">Select UOM For Frame</option>
	<?php 
	$sql3=DB_query("Select * from unitsofmeasure",$db);
	while($row3=DB_fetch_array($sql3))
	{?>
		<option value="<?php echo $row3['unitid'];?>" <?php echo ($frame_uom==$row3['unitid']?'selected':'')?>><?php echo $row3['unitname'];?></option>
	<?php 
	}
	?>
	</select>
	<select name="frame_category" id="frame_category" >
	<option value="">Map RMT To Frame Category</option>
	<?php $sql1=DB_query("Select id,categoryid,categorydescription from stockcategory where CompanyId=".$_SESSION['ACGCompanyId'],$db);
	while($row1=DB_fetch_array($sql1))
	{?>
		<option value="<?php echo $row1['id'];?>" <?php echo ($frame_category==$row1['id']?'selected':'')?>><?php echo $row1['categorydescription'];?></option>
	<?php 
	}
	?>
	</select></td>
	 <td class="tabledata1"><strong>Shutter(SMT)</strong></td>
     <td><input name="sutter" type="text" id="sutter" value="<?php echo $sutter; ?>" readonly=""  style="width:30%;">&nbsp;<select name="shutter_uom" style="width:65%;">
	<option value="">Select UOM For Shutter</option>
	<?php 
	$sql3=DB_query("Select * from unitsofmeasure",$db);
	while($row3=DB_fetch_array($sql3))
	{?>
		<option value="<?php echo $row3['unitid'];?>" <?php echo ($shutter_uom==$row3['unitid']?'selected':'')?>><?php echo $row3['unitname'];?></option>
	<?php 
	}
	?>
	</select><select name="shutter_category" id="shutter_category" >
	<option value="">Map Area To Shutter Category</option>
	<?php $sql2=DB_query("Select id,categoryid,categorydescription from stockcategory where CompanyId=".$_SESSION['ACGCompanyId'],$db);
	while($row2=DB_fetch_array($sql2))
	{?>
		<option value="<?php echo $row2['id'];?>" <?php echo ($shutter_category==$row2['id']?'selected':'')?>><?php echo $row2['categorydescription'];?></option>
	<?php 
	}
	?>
	</select></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Security</strong></td>
    <td colspan="5">Activate<input name="security" type="radio" checked="checked" id="security" <?php echo($security=='Activate'?'checked':''); ?> value="Activate"  style="width:50px;">
	Deactivate<input name="security" type="radio" id="security" <?php echo($security=='Deactivate'?'checked':''); ?> value="Deactivate"  style="width:50px;"></td>
</tr>
</table>
<p align="center">
<?php if($_GET['action']=='edit'){?>
<input type="submit" class="search" value="Update" name="Update">
<input type="hidden" name="row_id" value="<?php echo $_GET['id'];?>" id="row_id">
<?php } else {?>
<input type="submit" class="search" value="Submit" name="Submit">
<?php } ?>
</p>
</form>
<br>	
<br>
<?php 
$size_sql=DB_query("Select * from size_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
?>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1"><strong>Type Of Product</strong></td>
	<td class="tabledata1"><strong>Size</strong></td>
	<td class="tabledata1"><strong>Status</strong></td>
	<td style="text-align:center;" class="tabledata1" colspan="2"><strong>ACTION</strong></td>
</tr>
<?php
if(DB_num_rows($size_sql)>0){
while($size_row=DB_fetch_array($size_sql))
{ 
?>
<tr class="row1">
	<td><?php echo $s->GetFieldVAlue('stockcategory',"id='".$size_row['type_product']."'",'categorydescription');?></td>
	<td><?php echo stripslashes($size_row['size']);?></td>
	<td><?php echo stripslashes($size_row['security']);?></td>
	<td><a href="index.php?route=size_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $size_row['id'];?>&action=edit">Edit</a></td>
	<td><a href="index.php?route=size_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $size_row['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this record?')">Delete</a></td>
</tr>
<?php } }
else
{?>
<tr class="row1">
<td class="tabledata1" colspan="5"><h3 align="center"><strong><font color="#FF0000">NO RECORD FOUND!</font></strong></h3></td>
</tr>
<?php 
}?>
</table>
<?php 
include('includes/footer.inc');
?>
<script language="javascript" type="text/javascript">
function calsize(str)
{
	var desc=document.getElementById("desc").value.toUpperCase();
	var width=document.getElementById("width").value;
	var height=document.getElementById("height").value;
	var sy=" x ";
	var sp=" ";
	Varfin=width.concat(sy,height,sp,desc);
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("duplicate").innerHTML=xmlhttp.responseText;
	
	var data=document.getElementById("gky").value;
	
	if(data==1)
	{
		alert("This Value Is Already Exist");
		document.getElementById("gky").value='';
		return false;
	}
	}
	}
	
	var pro=document.getElementById("type_product").value;
	var size23=document.getElementById("size").value;
	var Copm=document.getElementById("companyId").value;
	xmlhttp.open("GET","Checksizemaster.php?newsize="+str+"&Prod="+pro+"&oldsize="+Varfin+"&companyId="+Copm,true);
	xmlhttp.send();	
	
	
	document.getElementById("size").value=Varfin;
	
	var area1=(width*height)/1000000;
	document.getElementById("area").value=area1;
	
	
	var hei=2*height;
	var hei1=parseInt(hei)+parseInt(width);
	var frame1=(hei1)/1000;
	document.getElementById("frame").value=frame1;
	
	
	var wi1=parseInt(width);
	var wi2=wi1-100;
	var h1=parseInt(height);
	var h2=h1-50;
	var sutter1=(wi2*h2)/1000000;
	document.getElementById("sutter").value=sutter1;
	
	
	
}
</script>
<style>
.cap
{
text-transform:uppercase;
}
</style>