<?php
session_start();

if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.php");
include("Functions_UserAccess.php");
include("function.inc.php");
include("function2.inc.php");

		
$roundedcorner = '	-moz--radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;';

$vTabFocus = $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];}		

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");
 mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

 class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
	var $focusfields=Array();
	var $TabVisibility=Array();
	
function start($name,$connection){

		if (empty($this->active) && CheckTab($name,$_SESSION['dbLabel'],$_SESSION['accessschemaid'],'parameterform',$connection)==1){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run($connection){
	
	//	$focusfields['Info']='clientfirstname';
	//	$focusfields['Locations']='clientlocation';
	//	$focusfields['LoginUser']='accesscode';
		
		$TabVisibility['Parameters']=CheckTab('Parameters',$_SESSION['dbLabel'],$_SESSION['accessschemaid'],'parameterform',$connection);
		
			
		
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
			
				if($TabVisibility[$tabname]==1) {
					$tabid = "tab_".$this->name."_$tabname";
					$contentid = "tabcontent_".$this->name."_$tabname";
					
					$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
					$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
				}
			}
			
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			
			echo "	$jsClear";
			echo "	\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "	\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			echo"	if(fieldname!='')
						document.getElementById(fieldname).focus();";
			echo "}\n";
					
			echo "</script>\n";
			
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$tabfield=$focusfields[$tabname];
				
				if($TabVisibility[$tabname]==1) {
					echo "<DIV CLASS='";
					if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
					echo "' ID='$tabid' ";
					echo "onClick=\"tab_".$this->name."('$tabname','$tabfield');\">$tabname</DIV>\n";
				}
			}
			
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				
				if($TabVisibility[$tabname]==1) {
					echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
					if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
					echo ";'>$tabcontent</DIV>\n";
				}
				else{
					echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display:none ";
					
						echo ";'>$tabcontent</DIV>\n";
				
				}		
			}
			echo "<DIV STYLE='clear: both;'></DIV>";
			echo "</DIV>";
			
		}
	}
}	
	



print <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>

input:focus {border:1px solid #1e87a5;background-color:#f2f2f2;}
select:focus {border:1px solid #1e87a5;}

input:hover {border:1px solid #1e87a5;background-color:#f2f2f2;}
select:hover {border:1px solid #1e87a5;}

#table1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	cursor:pointer;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;

}
#table2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt1:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#tabledt2:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;

}

#tabledt3:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table5:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table6:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table7:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}
#table8:hover {
	background-color:#f2f2f2;
	border:1px solid #E2E2E2;
	-o-transition:.9s;
  -ms-transition:.9s;
  -moz-transition:.9s;
  -webkit-transition:.9s;
  /* ...and now for the proper property */
  transition:.9s;
cursor:pointer;
}

table.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
table.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
table.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


tablesalary.sample {
	border-width: 0px;
	border-spacing: 3px;
	border-style: double;
	border-color: gray;
	border-collapse: collapse;
	background-color: white;
}
tablesalary.sample th {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #DCDCDC;
	-moz-border-radius: ;
}
tablesalary.sample td {
	border-width: 1px;
	padding: 0px;
	border-style: solid;
	border-color: #E5E5E5;
	-moz-border-radius: ;
}


</style>


<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>

<SCRIPT type="text/javascript">

function deletesalesmencommission(id) {

if (confirm ( "Are you sure you want to Delete this Record ?")){
	var value2 = document.getElementById('salesmen_code').value;value2 = encodeURIComponent(value2);

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('commission').innerHTML=xmlhttp.responseText;
					document.getElementById('commissiondt').innerHTML="";
				
				}
		}
  }


xmlhttp.open("GET","Form_salesmencommission_Action.php?salesmencommissionid="+id+"&salesmen_code="+value2
										+"&actionmode=deletesalesmencommission",true);

xmlhttp.send();

	}



}
function showrelationtoparameter(vid){
	if (vid == "") {
	document.getElementById('commissiondt').innerHTML="";
	
	}
	
	else{
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('commissiondt').innerHTML=xmlhttp.responseText;
				
				
					
				
				}
		}
  }
 
xmlhttp.open("GET","Form_salesmencommission_Action.php?vid="+vid+"&actionmode=changerelationtodetail",true);
xmlhttp.send();

}
}
function submitsalesmenbudget(vrec,id) {

var immediate_payout = 'immediate_payout['+vrec+']';
var salesmen_mst = 'salesmen_mst['+vrec+']';
var salesmen_cst = 'salesmen_cst['+vrec+']';
var salesmen_startdate = 'salesmen_startdate['+vrec+']';
var salesmen_enddate = 'salesmen_enddate['+vrec+']';
var monthly_achievmentfrom = 'monthly_achievmentfrom['+vrec+']';
var monthly_achievmentto = 'monthly_achievmentto['+vrec+']';
var salesmen_sip = 'salesmen_sip['+vrec+']';




var value2 = document.getElementById('salesmen_code').value;value2 = encodeURIComponent(value2);
var value3 = document.getElementById(immediate_payout).value;value3 = encodeURIComponent(value3);
var value4 = document.getElementById(salesmen_mst).value;value4 = encodeURIComponent(value4);
var value5 = document.getElementById(salesmen_startdate).value;value5 = encodeURIComponent(value5);
var value6 = document.getElementById(salesmen_enddate).value;value6 = encodeURIComponent(value6);
var value7 = document.getElementById(monthly_achievmentfrom).value;value7 = encodeURIComponent(value7);	
var value8 = document.getElementById(monthly_achievmentto).value;value8 = encodeURIComponent(value8);	
var value9 = document.getElementById(salesmen_sip).value;value9 = encodeURIComponent(value9);	
var value10 = document.getElementById(salesmen_cst).value;value10 = encodeURIComponent(value10);	



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)
    {				data = xmlhttp.responseText.split("[BRK]");
					document.getElementById('commission').innerHTML=data[0];
					document.getElementById('commissiondt').innerHTML=data[1];
					
					
				
		}
  }

  

xmlhttp.open("GET","Form_salesmencommission_Action.php?salesmen_code="+value2
											+"&immediate_payout="+value3
											+"&salesmensbudgetid="+id
											+"&salesmen_mst="+value4
											+"&salesmen_cst="+value10
											+"&salesmen_startdate="+value5
											+"&salesmen_enddate="+value6
											+"&monthly_achievmentfrom="+value7
											+"&monthly_achievmentto="+value8
											+"&salesmen_sip="+value9+"&actionmode=editsalesmenbudget",true);


xmlhttp.send();



}

function insertsalesmenbudget(vrec) {

var immediate_payout = 'immediate_payout['+vrec+']';
var salesmen_mst = 'salesmen_mst['+vrec+']';
var salesmen_cst = 'salesmen_cst['+vrec+']';
var salesmen_startdate = 'salesmen_startdate['+vrec+']';
var salesmen_enddate = 'salesmen_enddate['+vrec+']';
var monthly_achievmentfrom = 'monthly_achievmentfrom['+vrec+']';
var monthly_achievmentto = 'monthly_achievmentto['+vrec+']';
var salesmen_sip = 'salesmen_sip['+vrec+']';



var value2 = document.getElementById('salesmen_code').value;value2 = encodeURIComponent(value2);
var value3 = document.getElementById(immediate_payout).value;value3 = encodeURIComponent(value3);
var value4 = document.getElementById(salesmen_mst).value;value4 = encodeURIComponent(value4);
var value5 = document.getElementById(salesmen_startdate).value;value5 = encodeURIComponent(value5);
var value6 = document.getElementById(salesmen_enddate).value;value6 = encodeURIComponent(value6);
var value7 = document.getElementById(monthly_achievmentfrom).value;value7 = encodeURIComponent(value7);	
var value8 = document.getElementById(monthly_achievmentto).value;value8 = encodeURIComponent(value8);	
var value9 = document.getElementById(salesmen_sip).value;value9 = encodeURIComponent(value9);	
var value10 = document.getElementById(salesmen_cst).value;value10 = encodeURIComponent(value10);	

if(value2 == "" || value3 == "" || value4 == "" || value5 == "" || value6 == "" || value7 == "" || value8== "" || value9== "" ){

alert("All Fields Are Required");

}
else {

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('commission').innerHTML=xmlhttp.responseText;
					
					
				
		}
  }

  

xmlhttp.open("GET","Form_salesmencommission_Action.php?salesmen_code="+value2
											+"&immediate_payout="+value3
											+"&salesmen_mst="+value4
											+"&salesmen_cst="+value10
											+"&salesmen_startdate="+value5
											+"&salesmen_enddate="+value6
											+"&monthly_achievmentfrom="+value7
											+"&monthly_achievmentto="+value8
											+"&salesmen_sip="+value9+"&actionmode=insertsalesmenbudget",true);


xmlhttp.send();


}
}



function returncolor(vobj,vtextname,vcolorname){

 

if (document.getElementById(vtextname).value=='')
	{
		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
	}	
else {
var prevobj = document.getElementById(vtextname).value;
document.getElementById(prevobj).style.backgroundColor = document.getElementById(vcolorname).value;

		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
}	
vobj.style.backgroundColor='#B8EDFF';
}

function PrintPreview() {
	x=document.salesmen_commission;
	var vfromdate=x.txtFromDate.value;
	var vtodate=x.txtToDate.value;

	var details;
	if(x.showdetail.checked == true)
	details = "yes";
	else details = "no";
	


	var orderby=x.orderby.value;
	var employeeid=x.employeeid.value;
	var absentismid = x.absentism2.value;
for (var i=0; i < document.salesmen_commission.groupby.length; i++)
  {
    if (document.salesmen_commission.groupby[i].checked)
    {
      var groupby = document.salesmen_commission.groupby[i].value;
    }
  }
for (var i=0; i < document.salesmen_commission.orderby.length; i++)
  {
    if (document.salesmen_commission.orderby[i].checked)
    {
      var orderby = document.salesmen_commission.orderby[i].value;
    }
  }	
	
	
	
	window.open('Rep_Vacation.php?vFromDate='+vfromdate+'&vToDate='+vtodate+'&groupby='+groupby+'&employeeid='+employeeid+'&absentismid='+absentismid+'&orderby='+orderby+"&details="+details,"Rep_Services", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function showemployees(vwidth,vheight){

	 

	win = window.open('list_employees.php?', 'Search', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+vwidth+',height='+vheight+',top=100,left=100');		
	win.creator = self;
	win.focus();	
	}	
	
	function showsalesmen(i){

	

 win = window.open('Form_SearchSalesmen.php?rownumber='+i, 'Form_hscodesSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=550,top=100,left=100');		
	win.creator = self;
	win.focus();	
} 

function showreport(){

	var salesmencode =	document.getElementById('salesmen_code').value;
	var fromdate =	document.getElementById('fromdate').value;
	if(fromdate == "") {
		alert("Date Is Required");
	}
	else{

		win = window.open('rep_salesmencommission.php?salesmen_code='+salesmencode+'&fromdate='+fromdate, 'SalesmenReport', 							'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=550,top=100,left=100');		
		win.creator = self;
		win.focus();	
	}
} 

	function excelexpp(){

		var salesmencode =	document.getElementById('salesmen_code').value;
		var fromdate =	document.getElementById('fromdate').value;
		if(fromdate == "") {
		alert("Date Is Required");
		}
else{

 win = window.open('exp_salesmencommission.php?salesmen_code='+salesmencode+'&fromdate='+fromdate, 'Salesmen Report Excel', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=550,top=100,left=100');		
	win.creator = self;
	win.focus();	}
} 

</script>

	<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus','.roundedtext_datee', function() {
			$('.roundedtext_datee').datepick({showTrigger: '#calImg'});
		});
	
	
	
	
	});
	
	
</script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus','.roundedtext2', function() {
			$('.roundedtext2').datepick({showTrigger: '#calImg'});
		});
	
	
	
	
	});
	
	
</script>


<title>Salesmen Commission</title>

</head>
<body >
<form  enctype="multipart/form-data"  id='salesmen_commission' name='salesmen_commission' method='post' >
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='mandatoryfields' value='$vMandatoryFields'>
<input type='hidden' name='user' value='$user' >
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";



				

echo'<table cellpadding="0" cellspacing="0" border="0"  align="center"  class ="layout-width" >';

print <<<HERE

<tr>
  <td  height="26"  valign="top" align=center id='content-top'>
	<table class ="layout-width" border="0" cellpadding="0" cellspacing="0">
	<tr  height='26'>
      <td width="38" height="26">&nbsp;</td>
      <td width="300" valign="middle" height="26" align = left><span class="title">Salesmen Commission</span></td><td class='message' valign="middle">&nbsp; $message</td>
	</tr>
	
	</table></td></tr>
HERE;

print <<<HERE



<tr>
  <td  height="34"  valign="top" id='content-top2'>
	<table class ="layout-width" border="0" cellpadding="0" cellspacing="0">
	<tr  >
      <td width="38"  height="34">&nbsp; </td>
	<td valign='middle' height="34">
HERE;


	
	

	
		
		
		
	echo"<span class='style4'>&nbsp;&nbsp;Salesman:</span><input type='text'   style='width:120px;' readonly  name='salesmen_code' id='salesmen_code'    class='roundedtext' value='".$salesmen_code."' ".$KeyDown." ></span></span> &nbsp;&nbsp;<input type='text'   style='width:200px;' readonly  name='salesmen_name' id='salesmen_name'    class='roundedtext' value='".$salesmen_name."' ".$KeyDown." >&nbsp;&nbsp;<img src='img/openlist.png' onmouseover=\"style.cursor='pointer'\" onclick=\"showsalesmen()\"></td>	<td colspan = 9><span class='style4'>From Date:</span>&nbsp;<input type='text'   style='width:120px;' readonly  name='fromdate' id='fromdate'    class='roundedtext2' value='".$fromdate."' ".$KeyDown." ></span></span><span class='style4'>&nbsp;&nbsp;<button type='button' id='btnClear' name='btnClear' onclick='showreport();' title='Print'><span><span>Print</span></span></button><button type='button' id='excelexp' name='excelexp' onclick='excelexpp();' title='Print'><span><span>Excel</span></span></button></td></tr>";
	
	
echo"	</table></td></tr>";
echo"<tr height=480><td id='content-body' valign=top align=left>";



echo"<br><table border=0 style='table-layout:fixed;border:0px solid black;border-spacing:0;width:1150px;'><tr align = left><td>";

	
echo"<div id='commission' style='overflow-x:auto;height:150px;width:1150px'>";
draw_salesmencommission($connection,$salesmen_code);
echo"</div></tr>";
echo" <tr align = left><td><br>";

	
echo"<div id='commissiondt' style='overflow-x:auto;height:300px;width:1150px'>";
//draw_salesmenbudgetdt($connection);
echo"</div></tr>";

echo"</table><br>";

		





echo "<input name='employeeid'  id='employeeid' type='hidden'  >";

echo "<input name='absentismid'  id='absentismid' type='hidden'  >";

echo"   <tr height='30'><td colspan='4' align='center' id='content-bottom' ></td></tr>";

include("footer.php");	
echo" </table>";



if($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}
	
mysql_close($connection);

echo"</form>";
print <<< HERE
</body>
<html>
HERE;
?>	