<?php session_name('CAKEPHP'); session_start();
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
$CompanyId =$_SESSION['ACGCompanyId'];
	if($CompanyId) {
	    $sql_query = "SELECT * FROM tbl_itemname_auto where CompanyId=".$CompanyId;
		$sqlQuery =DB_query($sql_query,$db);
		$row=DB_fetch_array($sqlQuery);
	}

 	if($_REQUEST['action']=='setItemnameAuto'){
 	
	 $item_name_auto = $_POST['item_name_auto']; 
	
		if($item_name_auto!='1'){
			$item_name_auto=0;
		}
	
		if($row['CompanyID']){
			
			$res = DB_query("update  tbl_itemname_auto set item_name_auto ='$item_name_auto' where CompanyId ='$CompanyId'",$db);
			$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
			$sql ="insert into tbl_itemname_auto(CompanyId,item_name_auto) values('$CompanyId','$item_name_auto')";//exit;	
			$res = DB_query($sql,$db);
			$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
	
  }
  
  //<!-------DPARTMENT HEAD APPROVAL-----START HERE-----------------23-04-2013-------LOKESH--------------------------------->
  if($CompanyId) {
	    $sql_query = "SELECT * FROM tbl_values_update where CompanyId=".$CompanyId;
		$sqlQuery =DB_query($sql_query,$db);
		$row1=DB_fetch_array($sqlQuery);
	}
  if($_REQUEST['action1']=='setItemRate'){
  
	 $Excise_Duty_value = $_POST['Excise_Duty_value']; 
	
		if($Excise_Duty_value!='1'){
			$Excise_Duty_value=0;
		}
	
		if($row1['CompanyID']){		
		
 
			
		$res = DB_query("update  tbl_values_update set Excise_Duty_value ='$Excise_Duty_value' where CompanyId ='$CompanyId'",$db);
		$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}		else{
		$sql ="insert into tbl_values_update(CompanyId,Excise_Duty_value) values('$CompanyId','$Excise_Duty_value')";//exit;	
			$res = DB_query($sql,$db);
		$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
	}
	
  }
  if($CompanyId) {
	    $sql_query = "SELECT * FROM tbl_values_update where CompanyId=".$CompanyId;
		$sqlQuery =DB_query($sql_query,$db);
		$row2=DB_fetch_array($sqlQuery);
	}
   if($_REQUEST['action1']=='setItemRate'){
 	
	 $vat_cst = $_POST['vat_cst']; 
	
		if($vat_cst!='1'){
			$vat_cst=0;
		}
	
		if($row2['CompanyID']){
			
			$res = DB_query("update  tbl_values_update set vat_cst ='$vat_cst' where CompanyId ='$CompanyId'",$db);
$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
	}
		else{
		$sql ="insert into tbl_values_update(CompanyId,vat_cst) values('$CompanyId','$vat_cst')";//exit;	
			$res = DB_query($sql,$db);
		$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
	
  }
  
  
if($_REQUEST['save'])
{
	if($_REQUEST['status']!='')
	{
	$k=implode(",",$_REQUEST['status']);
	}
	
	$data['CompanyId']=$_REQUEST['companyid'];
	$data['branch']=$_REQUEST['branch'];
	$data['department']=$_REQUEST['department'];
	$data['ApprovalType']=$_REQUEST['ApprovalType'];
	$data['userid']=$k;
	$cond="CompanyId='".$_SESSION['ACGCompanyId']."' and branch='".$_REQUEST['branch']."' and department='".$_REQUEST['department']."' and ApprovalType='".$_REQUEST['ApprovalType']."'";
	$s->DeleteRecord('dept_indet_approval',$cond);
	$s->RecordInsert('dept_indet_approval',$data);
	$s->pageLocation("index.php?route=Setup/elementmanagement".$rurl);
}
?>
<link href="css/accountbook_css.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<h1>Inventory Management</h1>
<form method="post" name="nz" id="frm">
<div id="container">
 <div id="tabs">
    <ul>
	<li><a href="index.php?route=Setup/elementmanagement&modid=<?php echo $rurl; ?>&ApprovalType=GRNApproval&tabid=1">GRN Approval</a></li>
	<li><a href="index.php?route=Setup/elementmanagement&modid=<?php echo $rurl; ?>&ApprovalType=StoreHeadApproval&tabid=2">Required GRN Approval</a></li>
	<li><a href="index.php?route=Setup/elementmanagement&modid=<?php echo $rurl; ?>&ApprovalType=PurchaseHeadApproval&tabid=3">Other Configuration</a></li>
	
	</ul>
<?php if(isset($_REQUEST['tabid'])) {?>

<!-------DPARTMENT HEAD APPROVAL-----START HERE-----------------23-04-2013-------AMITSINGH------------------------------->

<?php if($_REQUEST['tabid']==1){ ?>
<table width="98%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td class="tabledata1"><strong>Company</strong></td>
	<td><select name="companyid" id="companyid" style="width:150px;">
			<option value="">Select</option>
	<?php $SQLComp=DB_query("select * from companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($CompId=db_fetch_array($SQLComp)){?>
			<option value="<?php echo $CompId['CompanyId']; ?>"<?php echo($_REQUEST['companyid']==$CompId['CompanyId']?'selected':''); ?>><?php echo $CompId['CompanyName']; ?></option>
	<?php }?>
		</select>
	</td>
	<td class="tabledata1"><strong>Branch</strong></td>
	<td><select name="branch" id="branch" style="width:150px;">
			<option value="">Select</option>
	<?php $SQLBra=DB_query("SELECT * FROM locations where mst_companyid='".$_SESSION['ACGCompanyId']."'",$db);
	while($BranId=db_fetch_array($SQLBra)){?>
			<option value="<?php echo $BranId['loccode']; ?>"<?php echo($_REQUEST['branch']==$BranId['loccode']?'selected':''); ?>><?php echo $BranId['locationname']; ?></option>
	<?php }?>
		</select>
	</td>
	<td class="tabledata1"><strong>Department</strong></td>
	<td><select name="department" id="department" style="width:150px;">
			<option value="">Select</option>
	<?php $SQLDept=DB_query("SELECT * FROM deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($DeptId=db_fetch_array($SQLDept)){?>
			<option value="<?php echo $DeptId['id']; ?>"<?php echo($_REQUEST['department']==$DeptId['id']?'selected':''); ?>><?php echo $DeptId['deptname']; ?></option>
	<?php }?>
		</select>
	</td>
	<td class="tabledata1"><input type="submit" name="search" class="search" value="Go"></td>
</tr>
</table>
<br/>
<?php if($_REQUEST['search']) {
if($_REQUEST['companyid']!='')
{
	$filter[]="companyid='".$_REQUEST['companyid']."'";
}
if($_REQUEST['branch']!='')
{
	$filter[]="mst_site='".$_REQUEST['branch']."'";
}
if($_REQUEST['department']!='')
{
	$filter[]="department='".$_REQUEST['department']."'";
}

if($filter!='')
{
	$filter1=implode(" and ",$filter);
	$sqlindet=DB_query("SELECT * FROM www_users where $filter1",$db);
}


$SQlGet=DB_query("select * from dept_indet_approval where department='".$_REQUEST['department']."' and branch='".$_REQUEST['branch']."' and CompanyId='".$_SESSION['ACGCompanyId']."' and ApprovalType='".$_REQUEST['ApprovalType']."'",$db);

?>
<table width="98%" cellpadding="3" cellspacing="0" border="1">
<tr class="row1">
	<td class="tabledata"><strong>Sr no.</strong></td>
	<td class="tabledata"><strong>User Name</strong></td>
	<td class="tabledata"><strong>Status</strong></td>
</tr>
<?php $GetUserId=DB_fetch_array($SQlGet);
$data1=explode(",",$GetUserId['userid']);
?>

<?php $i=0; while($indentaap=DB_fetch_array($sqlindet)) 
{
if(in_array($indentaap['id'],$data1))
{
	$sela='checked';
}
else
{
	$sela='';
}?>
<tr class="row1">
	<td style="width:50px;"><?php echo $i+1; ?></td>
	<td><?php echo $indentaap['realname']; ?></td>
	<td style="width:50px;padding-left:10px;"><input type="checkbox" name="status[]" <?php echo $sela; ?> value="<?php echo $indentaap['id'] ?>" id=""></td>
</tr>
<?php $i++;}?>
<tr class="row1">
	<td style="text-align:center;" colspan="3"><input type="submit" name="save" value="Save" class="search"></td>
</tr>
</table>
<?php } ?>

<?php }?>

<!-------DPARTMENT HEAD APPROVAL-----END HERE-----------------23-04-2013-------AMITSINGH--------------------------------->


<!-------DPARTMENT HEAD APPROVAL-----START HERE-----------------23-04-2013-------AMITSINGH------------------------------->

<?php if($_REQUEST['tabid']==2){ ?>

<table width="98%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td class="tabledata1"><strong>Required GRN Approval</strong></td>
	<td><input type="checkbox" name="" /></td>
</tr>
</table>
<?php } ?>



<!-------DPARTMENT HEAD APPROVAL-----END HERE-----------------23-04-2013-------AMITSINGH--------------------------------->


<!-------DPARTMENT HEAD APPROVAL-----START HERE-----------------23-04-2013-------AMITSINGH------------------------------->
<?php if($_REQUEST['tabid']==3){?>
<input type="hidden" name="action" value="setItemnameAuto" />
<input type="hidden" name="action1" value="setItemRate" />
<table width="98%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td class="tabledata1"><strong>Auto Item Name creation</strong></td>
	<td><input type="checkbox" <?php if($row['item_name_auto']=="1"){ ?> checked="checked" <?php }?> value="1" name="item_name_auto" id="item_name_auto" onclick="checkupdate(this.value);"/></td>
</tr>
<!-------DPARTMENT HEAD APPROVAL-----START HERE-----------------23-04-2013-------LOKESH------------------------------->

<tr class="row1">
	<td class="tabledata1"><strong>Auto Item Rate Updation</strong></td>
	<td>Excise&nbsp;&nbsp;&nbsp;<input type="checkbox" <?php if($row1['Excise_Duty_value']=="1"){ ?> checked="checked" <?php }?> value="1" name="Excise_Duty_value" id="Excise_Duty_value" onclick="checkupdate(this.value);" />&nbsp;&nbsp;&nbsp;Vat<input type="checkbox" <?php if($row2['vat_cst']=="1"){ ?> checked="checked" <?php }?> value="1" name="vat_cst" id="vat_cst" onclick="checkupdate(this.value);" /></td>
</tr>
<!-------DPARTMENT HEAD APPROVAL-----END HERE-----------------23-04-2013-------LOKESH--------------------------------->
<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="2">
		<!--<input type="submit" name="submit" class="search" value="save" />-->
	</td>
</tr>
</table>
</div>
<?php }?>


<!-------DPARTMENT HEAD APPROVAL-----END HERE-----------------23-04-2013-------AMITSINGH--------------------------------->

<?php }else{?>
<table width="98%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td class="tabledata1">&nbsp;</td>
</tr>
</table>
<?php }?>
</div>
</div>
</form>
</div>
</div>
<script language="javascript" type="text/javascript">
function checkupdate(str)
{
//alert('lokesh');
		if(document.getElementById("Excise_Duty_value").value=='0'){
		document.getElementById("Excise_Duty_value").value==1;
		//document.frm.getElementById("Excise_Duty_value").submit();
		}
		else if(document.getElementById("vat_cst").value=='0'){
		document.getElementById("vat_cst").value==1;
		//document.frm.getElementById("vat_cst").submit();
		}
		else if(document.getElementById("item_name_auto").value=='0'){
		document.getElementById("item_name_auto").value==1;
		//document.frm.getElementById("vat_cst").submit();
		}
	document.getElementById("frm").submit();
}
</script>