<?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);
		
		 $sql_query1 = "SELECT * FROM mrn_comercial_flag where company_id=".$CompanyId;
		$sqlQuery1 =DB_query($sql_query1,$db);
		$rowNew=DB_fetch_array($sqlQuery1);
		
		 $sql_query2 = "SELECT * FROM roundoff_flag where company_id=".$_SESSION['ACGCompanyId'];
		$sqlQuery2 =DB_query($sql_query2,$db);
		$rowNew2=DB_fetch_array($sqlQuery2);
		
		$sql_query3 = "SELECT * FROM grn_config where company_id=".$_SESSION['ACGCompanyId'];
		$sqlQuery3 =DB_query($sql_query3,$db);
		$rowNew3=DB_fetch_array($sqlQuery3);
		$sql_query4 = "SELECT * FROM issue_slip where company_id=".$_SESSION['ACGCompanyId'];
		$sqlQuery4 =DB_query($sql_query4,$db);
		$rowNew4=DB_fetch_array($sqlQuery4);
                
                $sql_query5 = "SELECT * FROM fin_Product where company_id=".$_SESSION['ACGCompanyId'];
		$sqlQuery5 =DB_query($sql_query5,$db);
		$rowNew5=DB_fetch_array($sqlQuery5);
	}
	
	  
		

 	if($_REQUEST['action']=='setItemnameAuto')
		{
		$roundFlag = $_REQUEST['round_flags1']; 
		if($roundFlag!='1'){
			$roundFlag=0;
		}
			
		if($rowNew2['company_id'])
		{
		
			$res1 = DB_query("update roundoff_flag set round_flag ='$roundFlag' where company_id ='".$_SESSION['ACGCompanyId']."' and  created_by='".$_SESSION['UserID']."'",$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
		
			$sql1 ="insert into roundoff_flag(round_flag, company_id, created_date, created_by) values('$roundFlag', '".$_SESSION['ACGCompanyId']."', '".date('Y-m-d')."', '".$_SESSION['UserID']."')";//exit;	
			$res1 = DB_query($sql1,$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
		
		
		$issueFlag = $_REQUEST['issue_slip_value']; 
		if($issueFlag!='1'){
			$issueFlag=0;
		}
			
		if($rowNew4['company_id'])
		{

			$res1 = DB_query("update issue_slip set issue_slip_flag ='$issueFlag' where company_id ='".$_SESSION['ACGCompanyId']."' and  created_by='".$_SESSION['UserID']."'",$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
		
			$sql1 ="insert into issue_slip(issue_slip_flag, company_id, created_date, created_by) values('$issueFlag', '".$_SESSION['ACGCompanyId']."', '".date('Y-m-d')."', '".$_SESSION['UserID']."')";//exit;	
			$res1 = DB_query($sql1,$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
 	
		$grnFlags = $_POST['grnFlag']; 
		if($grnFlags!='1'){
			$grnFlags=0;
		}
		
		if($rowNew3['company_id']){
			$res21 = DB_query("update grn_config set grn_flag ='$grnFlags' where company_id ='".$_SESSION['ACGCompanyId']."' and created_date='".date('Y-m-d')."' and created_by='".$_SESSION['UserID']."'",$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
			$sql2 ="insert into grn_config(grn_flag, company_id, created_date, created_by) values('$grnFlags', '".$_SESSION['ACGCompanyId']."', '".date('Y-m-d')."', '".$_SESSION['UserID']."')";//exit;	
			$res2 = DB_query($sql2,$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
		
		
		$mrnFlag = $_POST['mrn_flags']; 
		if($mrnFlag!='1'){
			$mrnFlag=0;
		}
		
		if($rowNew['company_id']){
			
			$res = DB_query("update mrn_comercial_flag set mrn_flag ='$mrnFlag' where company_id ='$CompanyId'",$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
			$sql ="insert into mrn_comercial_flag(company_id,mrn_flag) values('$CompanyId','$mrnFlag')";//exit;	
			$res = DB_query($sql,$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
                
                $fprFlag = $_POST['fpr_flags']; 
              
		if($fprFlag!='1'){
			$fprFlag=0;
		}
		
		if($rowNew5['company_id']){
			//echo "update fin_Product set fpr_flag ='$fprFlag' where company_id ='$CompanyId'";
                      
			$res = DB_query("update fin_Product set fpr_flag ='$fprFlag' where company_id ='$CompanyId'",$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");	
		}
		else{
			$sql ="insert into fin_Product(company_id,fpr_flag) values('$CompanyId','$fprFlag')";//exit;	
			$res = DB_query($sql,$db);
			//$s->pageLocation("index.php?route=Setup/elementmanagement&modid=9&frmid=406");
		}
		
		 
		
		 $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 loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$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){

	$sqlPoApp=DB_query("SELECT mrn_flag FROM mrn_comercial_flag order by id desc",$db);
	$PoApp=DB_fetch_array($sqlPoApp);
	
	$sqlPoApp1=DB_query("SELECT round_flag FROM roundoff_flag order by id desc",$db);
	$PoApp1=DB_fetch_array($sqlPoApp1);

	$sqlPoApp2=DB_query("SELECT grn_flag FROM grn_config order by id desc",$db);
	$PoApp2=DB_fetch_array($sqlPoApp2);
	
	$sqlPoApp3=DB_query("SELECT issue_slip_flag FROM issue_slip order by id desc",$db);
	$PoApp3=DB_fetch_array($sqlPoApp3);
        
        $sqlPoApp4=DB_query("SELECT fpr_flag FROM fin_Product order by id desc",$db);
	$PoApp4=DB_fetch_array($sqlPoApp4);
?>
<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>

<tr class="row1">
	<td class="tabledata1"><strong>Required GRN Approval</strong></td>
	<td><input type="checkbox" <?php if($PoApp2['grn_flag']=="1"){ ?> checked="checked" <?php }?> name="grnFlag" id="grnFlag" value="1" onclick="checkGrn(this.value);"/></td>
</tr>

<tr class="row1">
	<td class="tabledata1"><strong>MRN With Commercial Flag</strong></td>
	<td><input type="checkbox" <?php if($PoApp['mrn_flag']=="1"){ ?> checked="checked" <?php }?> value="1" name="mrn_flags" id="mrn_flags" onclick="checkmrn(this.value);"/></td>
</tr>

<tr class="row1">
	<td class="tabledata1"><strong>Auto Round Off</strong></td>
	<td><input type="checkbox" <?php if($PoApp1['round_flag']=="1"){ ?> checked="checked" <?php }?> value="1" name="round_flags1" id="round_flags" onclick="checkRoundOff(this.value);"/></td>
</tr>

<tr class="row1">
	<td class="tabledata1"><strong>Issue Slip With Job Card Details</strong></td>
	<td><input type="checkbox" <?php if($PoApp3['issue_slip_flag']=="1"){ ?> checked="checked" <?php }?> value="1" name="issue_slip_value" id="issue_slip_value" onclick="checkIssueSlip(this.value);"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Finished Product Received From QC Processwise</strong></td>
	<td><input type="checkbox" <?php if($PoApp4['fpr_flag']=="1"){ ?> checked="checked" <?php }?> value="1" name="fpr_flags" id="fpr_flags" onclick="checkfinishedProduct(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>

</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();
}

function checkmrn(str)
{
	document.getElementById("frm").submit();
}

function checkGrn(str)
{
	document.getElementById("frm").submit();
}


function checkRoundOff(str)
{
	document.getElementById("frm").submit();
}

function checkIssueSlip(str)
{
	document.getElementById("frm").submit();
}
function checkfinishedProduct(str)
{
	document.getElementById("frm").submit();
}
</script>