<?php 

//include('includes/SQL_CommonFunctions.inc');
require_once('CRM/functions.php');
//************************INCLUDE ROOT FILES********************START HERE***********AMIT SINGH*****16-10-2012**************** 


//***********************INCLUDE ROOT FILES********************START HERE***********AMIT SINGH*******16-10-2012**************    

$site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
$site_row=DB_fetch_array($site_sql);// GET BRANCH

$month=array("Jan","Feb","March","Apr","May","Jun","July","Aug","Sept","Oct","Nov","Dec","Jan","Feb","March");


$s=new db_query();
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');
$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($LowerDeptList);
 if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'";



$Leaveaunto=explode(",",$lowerlist);

//print_r($Leaveaunto);
if($_SESSION['UserID']!='44')
{
if(count($Leaveaunto)>1)
{
if(($key = array_search($_SESSION['UserID'], $Leaveaunto)) !== false) {
    unset($Leaveaunto[$key]);
	}
	
	//print_r($Leaveaunto);
}
else
	{
	unset($Leaveaunto);
	}
}
else
{
	$Leaveaunto=$Leaveaunto;
}


if(!empty($Leaveaunto))
{

 $FinA=implode(",",$Leaveaunto);

for($i=0;$i<count($Leaveaunto);$i++)
{
	$EMPIS=DB_query("select id,mst_www_userid from empmaster where mst_www_userid='".$Leaveaunto[$i]."'",$db);
	$EAID=DB_fetch_array($EMPIS);
	if($EAID['mst_www_userid']!='')
	{
	$AKIds[]=$EAID['id'];
	}
}

$IDSTA=implode(",",$AKIds);
}
else
{
$IDSTA='0';
}

$IDSTA;
//echo $_SESSION['UserID'];
 
$table="emp_leave_register";
$table1="emp_leave";
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$status=true;
$viewrurl="index.php?route=HRModule/view_leave_request&modid=".$modid."&frmid=".$frmid."";


function leave_calculation($empid,$type)
{
	global $db;
	$calLeaveRecord = "Select sum(total_approval_days) as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' group by leave_type  ";	   
	$ResultData = DB_query($calLeaveRecord,$db);
	$RowData = DB_fetch_array($ResultData);
	return($RowData['total']);
}


function leave_calculationForApplied($empid,$type)
{
	global $db;
	$calLeaveRecord = "Select sum(total_days) as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' group by leave_type  ";	   
	$ResultData = DB_query($calLeaveRecord,$db);
	$RowData = DB_fetch_array($ResultData);
	return($RowData['total']);
}

function dateDiff1($d1, $d2)
	{
		return round(abs(strtotime($d1)-strtotime($d2))/86400)+1;
	}  

//**************INSERT RERORD HERE***************START HERE********AS*************************************************



if($_REQUEST['period_from'])
{
	
	$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
	 $sql="Select leave_request_no from emp_leave_apply where 
	 INSTR(`leave_request_no`, '$financial') > 0 order by leave_request_no desc limit 0,1";

	$result=DB_query($sql,$db);
	$myrow=DB_fetch_array($result);
	//echo DB_num_rows($result);
	if(DB_num_rows($result)>0)
	{
	//$Reqno=$myrow['Reqno'];
	//$req_part1=substr($Reqno,-4);
	$ExplBill=explode("/",$myrow['leave_request_no']);
	$maxval = $ExplBill[3];
	//echo $req_part1;
	$req_final=$maxval+1;
	//echo "<br>".$req_final;
	}
	else
	{
	$req_final="1";
	}
	
	$string=$_REQUEST['branchCode']."/".$financial."/".'LRN/';
	$final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
	
	
	
	$startdate=FormatDateForSQL($_REQUEST['period_from']);
	$enddate=FormatDateForSQL($_REQUEST['period_to']);
	$year_s = date("Y",strtotime($startdate));
	$month_s = date("m",strtotime($startdate));
	$month_e = date("m",strtotime($enddate));
	$abscl = 0;
	$workingdays=cal_days_in_month(CAL_GREGORIAN, $month_s, $year_s);
	if($month_s!=$month_e)
	{
	$emp_leave_query=DB_query("SELECT * FROM emp_leave where emp_id='".$_REQUEST['empid']."' and leave_type='".$_REQUEST['leave_type']."'",$db);
	$emp_leave_row=DB_fetch_array($emp_leave_query);
	
	$emp_bm_query=DB_query("SELECT sum(pending_cl) AS pcl FROM cl_emp where emp_id='".$_REQUEST['empid']."'",$db);
	$emp_bm_row=DB_fetch_array($emp_bm_query);
	
	$ResultEmpABSDatamm=DB_query("Select period_to, period_from, MONTH(period_to) AS tomonth, MONTH(period_from) AS frommonth from emp_leave_apply where empid='".$_REQUEST['empid']."' AND MONTH(period_from)='".$month_s."' AND YEAR(period_from)='".$year_s."'",$db);
	if(DB_num_rows($ResultEmpABSDatamm)>0){
	while($RowEmpABSDatamm = DB_fetch_array($ResultEmpABSDatamm)){
	if($RowEmpABSDatamm['tomonth']==$RowEmpABSDatamm['frommonth']){
	$offdays = strtotime($RowEmpABSDatamm['period_to']) - strtotime($RowEmpABSDatamm['period_from']);
	$abscl +=($offdays/(60 * 60 * 24))+1;
	}else if($RowEmpABSDatamm['frommonth']==$month_s){
	$offdays = $workingdays - date('j', strtotime($RowEmpABSDatamm['period_from']));
	$abscl += $offdays+1;
	}else if($RowEmpABSDatamm['tomonth']==$month_s){
	$offdays = date('j', strtotime($RowEmpABSDatamm['period_from']))-1;
	$abscl += $offdays+1;
	}
	}
	}else{
	$abscl = 0;
	}
	$f_month = (($emp_leave_row['leave_days']/12)+$emp_bm_row['pcl'])-$abscl;
	$f_mday = ($workingdays - date('j', strtotime($startdate)))+1;
	if($f_mday>$f_month){
	echo "<script>alert('You take only ".$f_month." days Leave in month of ".date('F', strtotime($startdate)).".');</script>";
	}
	}
	else
	{
	$difference=dateDiff1($startdate,$enddate);
	
	
	for($k=0;$k<$difference;$k++)
	{
		$date2= strtotime(date("Y-m-d", strtotime($startdate)) . " +$k day");
        $date11[]= date("Y-m-d",$date2);
	}
	
	$betweendate=implode(",",$date11);
	
	$noOfDaysAllowed=$_REQUEST['NoOfLeaveDays'];
	
	if($difference>$noOfDaysAllowed)
	{
	echo "<script>alert('You Cannot take So Many Leave');</script>";
	
	}
	else
	{
	$data['empid']=$_REQUEST['empid'];
	$data['leave_request_no']=$final_string;
	$data['period_from']=FormatDateForSQL($_REQUEST['period_from']);
	$data['period_to']=FormatDateForSQL($_REQUEST['period_to']);
	$data['total_days']=$s->FinedDays($data['period_from'],$data['period_to']);
	$data['between_date']=$betweendate;
	$data['leave_reason']=$_REQUEST['leave_reason'];
	$data['leave_type']=$_REQUEST['leave_type'];
	//echo "<pre>";
	//print_r($data);
	//exit;
	if($data['period_from']>$data['period_to'])
	{
	$msgErr[]="From date can't be greater then To date";
	$status=false;
	
	}
	
	
	
	if($status)
	{
	$insert=$s->RecordInsert('emp_leave_apply', $data);
	if(!$insert){
	die("can't insert record");
	
	}
	
	}	
	}
	}
$s->pageLocation("index.php?Application=emp&modid=15".$rurl);	
}


//**************INSERT RERORD HERE***************END HERE********AS*************************************************



//**************UPDATE RERORD HERE***************START HERE********AS*************************************************


if($_REQUEST['checkboxEdit'])
{

	
	//$betweendate=implode(",",$date11);
	for($i=0;$i<count($_REQUEST['checkboxEdit']);$i++)
	{
		
		$cnt=$_REQUEST['checkboxEdit'][$i];
		$SD=FormatDateForSQL($_REQUEST['fromdate'][$cnt]);
		$ED=FormatDateForSQL($_REQUEST['todate'][$cnt]);
		$datediffA=dateDiff1($SD,$ED);
		for($k=0;$k<$datediffA;$k++)
		{
			$date2= strtotime(date("Y-m-d", strtotime($SD)) . " +$k day");
			$date11[]= date("Y-m-d",$date2);
		}
	
		$betweendate=implode(",",$date11);
		
		
		$dataArrE['period_from']=FormatDateForSQL($_REQUEST['fromdate'][$cnt]);
		$dataArrE['period_to']=FormatDateForSQL($_REQUEST['todate'][$cnt]);
		$dataArrE['total_days']=$_REQUEST['reqleave'][$cnt];
		$dataArrE['between_date']=$betweendate;
		$dataArrE['leave_reason']=$_REQUEST['leave_reason'][$cnt];
		$cond="id='".$_REQUEST['leaveappid'][$cnt]."'";
		
		
		$s->RecordEdit('emp_leave_apply',$dataArrE,$cond);
	}
	//exit;
	$s->pageLocation("index.php?Application=emp&modid=15".$rurl);
}

//**************UPDATE RERORD HERE***************END HERE********AS*************************************************
	


if($_REQUEST['Apprved'])
{
	for($m=1;$m<=count($_REQUEST['Mst_Leave_ApplyId']);$m++)
	{
		if($_REQUEST['chkApproval'][$m]==1)
		{
			$date11='';
			$ApprFDateA=FormatDateForSQL($_REQUEST['ApprovePeriodFrom'][$m]);
			$ApprTDateA=FormatDateForSQL($_REQUEST['ApprovePeriodTo'][$m]);
			$datediffA=dateDiff1($ApprFDateA,$ApprTDateA);
			for($k=0;$k<$datediffA;$k++)
			{
				$date2= strtotime(date("Y-m-d", strtotime($ApprFDateA)) . " +$k day");
				$date11[]= date("Y-m-d",$date2);
			}
	
			$betweendate=implode(",",$date11);
			$data['approved_date_from']=FormatDateForSQL($_REQUEST['ApprovePeriodFrom'][$m]);
			$data['approved_date_to']=FormatDateForSQL($_REQUEST['ApprovePeriodTo'][$m]);
			$data['total_approval_days']=$_REQUEST['TotalApprovalDays'][$m];
			$data['between_date']=$betweendate;
			$data['approve_status']='Y';
			
			$cond="id='".$_REQUEST['Mst_Leave_ApplyId'][$m]."'";
			//echo "<pre>";
			//print_r($data);
			$s->RecordEdit('emp_leave_apply',$data,$cond);
		}
	}
$s->pageLocation("index.php?Application=emp&modid=15".$rurl);
}


?>
<style type="text/css">
.week_days{background-color:#e5f1f9; border:#aed0ea 1px solid; border-right:none; font-family:Arial; font-size:12px; font-weight:bold;}
.days{background-color:#fafbfc; border:#dddddd 1px solid; font-family:Arial; font-size:12px; border-top:none;}
</style>
<link href="css/colorbox1.css" rel="stylesheet" type="text/css" media="screen">
<link href="css/cal.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/jquery_002.js"></script>
<script type="text/javascript" language="javascript"></script>
<script type="text/javascript" >
function showsalesdata()	
{
	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("divdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getsaleorderpending.php",true);
	xmlhttp.send();	
}




function showpendingordapproval()
{
//alert("hiiiii");
	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("divdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GetpendingordapprovalExe.php",true);
	xmlhttp.send();	
}


function showhighestsale()
{
//alert("hiiiii");
	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("divdata2").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GethighestsaleExe.php",true);
	xmlhttp.send();	
}
</script>

<script>

	$(document).ready(function() {
		$('#navigation > li > a').click(function(event){
		event.preventDefault();//stop browser to take action for clicked anchor
 
		//get displaying tab content jQuery selector
		var active_tab_selector = $('#navigation > li.active > a').attr('href');					
 
		//find actived navigation and remove 'active' css
		var actived_nav = $('#navigation > li.active');
		actived_nav.removeClass('active');
 
		//add 'active' css into clicked navigation
		$(this).parents('li').addClass('active');
 
		//hide displaying tab content
		$(active_tab_selector).removeClass('active');
		$(active_tab_selector).addClass('hide');
 
		//show target tab content
		var target_tab_selector = $(this).attr('href');
		$(target_tab_selector).removeClass('hide');
		$(target_tab_selector).addClass('active');
	     });
	  });

	</script>
<link href="css/dashboard1.css" rel="stylesheet" type="text/css" />
<script src="ui/jquery.ui.timepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
 <style type="text/css">
section{display:block;}
* {margin: 0; padding: 0; outline: none;}

ul {list-style: none;}

#navigation {
background-color:#FFFFFF;
padding-top:10px;
padding-bottom:10px;
	font: bold 12px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
	text-transform: uppercase;
	color: #444;
	width:98%;
	float:left;
	padding-left:20px;
}

#navigation:after {
	clear: both;
    content: ".";
    display: block;
    height: 0;
    visibility: hidden;
}

#navigation ul {	
	float: left;

    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.07);
	-webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.07);
    overflow: hidden;
}

#navigation li {
	margin-left:5px;
	float: left;
	border-style: solid; 
	border-width: 1px;
    border-color: #BABABA #BABABA #BABABA #BABABA;
	box-shadow: 0 1px rgba(255,255,255,1) inset;
	-webkit-box-shadow: 0 1px rgba(255,255,255,1) inset;
	background: #EDEDED; /* Old browsers */
	background: -moz-linear-gradient(top, #EDEDED 0%, #dad8d8 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#EDEDED), color-stop(100%,#dad8d8)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, #EDEDED 0%,#dad8d8 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, #EDEDED 0%,#dad8d8 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, #EDEDED 0%,#dad8d8 100%); /* IE10+ */
	background: linear-gradient(top, #EDEDED 0%,#dad8d8 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#EDEDED', endColorstr='#dad8d8',GradientType=0 ); /* IE6-9 */	
	border-radius: 5px;
	moz-border-radius: 5px;
	webkit-border-radius: 5px;
}

#navigation li:hover, #navigation li.active {
	box-shadow: 0 1px rgba(255,255,255,0.2) inset;
	-webkit-box-shadow: 0 1px rgba(255,255,255,0.2) inset;
	border-color: #262626 !important;
	background: #4D4D4D; /* Old browsers */
	background: -moz-linear-gradient(top, #4D4D4D 0%, #262626 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4D4D4D), color-stop(100%,#262626)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* IE10+ */
	background: linear-gradient(top, #4D4D4D 0%,#262626 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4D4D4D', endColorstr='#262626',GradientType=0 ); /* IE6-9 */
}

#navigation a {
	display: block;
	padding: 10px 12px;
	color: #444;
	text-decoration: none;
	text-shadow: 0 1px #FFF;
}

#navigation a:hover, #navigation li.active a {
	color: #FFF;
	text-shadow: 0 0px #fff;
}

#navigation li:first-child {
	border-left-color: #BABABA;
}

#navigation li:last-child {

}
.tab-content.active{
				display: block;
				width:95%;
				margin:auto;
	
			}
 
			.tab-content.hide{
				display: none;
			}
.style1 {font-style: italic;}

.nav {

			}
 
			.nav > li > a {
	
			}
 
			.nav-tabs{
		
			}
 
			.nav-tabs:before,
			.nav-tabs:after {
			 
			}
 
			.nav-tabs:after {
	
			}
 
			.nav-tabs > li {
			  float: left;
			}
 
			.nav-tabs > li > a {
			 
			}
 
			.nav-tabs {
			
			}
 
			.nav-tabs > li {
			
			}
 
			.nav-tabs > li > a {
		
		
			}
 
			.nav-tabs > li > a:hover {
			
			}
 
			.nav-tabs > .active > a,
			.nav-tabs > .active > a:hover {
				box-shadow: 0 1px rgba(255,255,255,0.2) inset;
	-webkit-box-shadow: 0 0px rgba(255,255,255,0.2) inset;
	background: #4D4D4D; /* Old browsers */
	background: -moz-linear-gradient(top, #4D4D4D 0%, #262626 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4D4D4D), color-stop(100%,#262626)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* IE10+ */
	background: linear-gradient(top, #4D4D4D 0%,#262626 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4D4D4D', endColorstr='#262626',GradientType=0 );
	border-radius: 5px;
	moz-border-radius: 5px;
	webkit-border-radius: 5px;
	 /* IE6-9 */
	
	 /* IE6-9 */
			}
 
			li {
			  line-height: 18px;
			}
 
			.tab-content .active{
				display: block;
				color:#FFFFFF;
				
			}
 
			.tab-content .hide{
				display: none;}
.clr{clear:both;}
.topnav{width:98%; height:auto;}
.bottomContener{width:98%; height:auto; min-height:500px; background:#FFFFFF;} 
.pad_left{padding-left:8px; padding-top:1px; padding-bottom:1px;} 
 </style>



<div class="maindiv" style="width:100%; background:none;">
	<!--insert table 1 start -->
	<div class="topnav">
<nav>
 <?php   $tab_data=$_REQUEST['tabid']; ?>
		<ul id="navigation">
         <li <?php if($tab_data=='') { ?>class="active" <?php } ?>><a href="#tab1">Dashboard</a></li>
         <li <?php if($tab_data==2) { ?>class="active" <?php } ?>><a href="#tab2" >Task Assignment</a></li>
			<li><a href="#tab3">Task Execution</a></li>
                        <li <?php if($tab_data==10) { ?>class="active" <?php } ?>><a href="#tab10">Task Report</a></li>
			<li><a href="#tab4">To Do</a></li>
			<li><a href="#tab5">Follow Ups</a></li>
			<li><a href="#tab6">Meetings</a></li>
			<li><a href="#tab7">TA DA CLAIM</a></li>
			<li><a href="#tab8">Leave Management</a></li>
			<li><a href="#tab12">My Calender</a></li>
		</ul>
	</nav>
	</div><!--insert table 1 close -->
	<!--insert table 2 start --><!--<div>
	<img src="images/executive_img.jpg" width="100%" />
	</div>--><!--insert table 2 close -->
<div id="tab1"  <?php if($tab_data=='') { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?>>
    <div id="body_part">
	<!-- left part of main body -->	
	  <div class="body_left" style="width:99%;">
			  
		<div style="margin-top:3px; margin-bottom:5px;">
			<?php 
			
$SQLTask=DB_query("SELECT * FROM tsk_taskassignment where assigned_by = ".$_SESSION['UserID']." and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
?>
<table width="100%" cellpadding="3" cellspacing="0" border="1">
<tr class="row1">
          <td colspan="9" bgcolor="#333333"><div style="float:left;"><h1 style="text-align:left;">Task Status </h1></div><div style="width:15px; height:15px; background: red; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Pending Overdue</div><div style="width:15px; height:15px; background:#FFFFFF; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Pending</div><div style="width:15px; height:15px; background: orange; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Progress Overdue</div><div style="width:15px; height:15px; background:yellow ; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Progress </div><div style="width:15px; height:15px; background:cadetblue; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Closed Overdue</div><div style="width:15px; height:15px; background: forestgreen; float:left; margin-left:5px; margin-top:5px;"></div><div style="color:#FFFFFF; margin-top:6px; margin-left:5px; margin-right:5px; float:left;">Closed</div></td>
          </tr>
	<tr class="row1">
		 <th class="tabledata">Branch</th>
          <th class="tabledata">Task No.</th>
		  <th class="tabledata">Start Date</thd>
          <th class="tabledata">End Date</th>
          <th class="tabledata">End Time</th>
		  <th class="tabledata">Assigned To</th>
          <th class="tabledata">Assigned By</th>
		  <th class="tabledata">Task</th>
		  <th class="tabledata">Status</th>  
         </tr>
<?php while($TaskView=DB_fetch_array($SQLTask)) {
   
    if($TaskView['status']=='pending')
    {
     $status=DB_query("select * from tsk_taskassignment where id='".$TaskView['id']."' and concat(end_date,' ',end_time)>='".date('Y-m-d H:i:s')."'" ,$db);
        if(DB_num_rows($status)==1)
            $bg='';
        else
            $bg='red';
    }  
    else if($TaskView['status']=='progress')
    {
        $status=DB_query("select * from tsk_taskassignment where id='".$TaskView['id']."' and concat(end_date,' ',end_time)>='".date('Y-m-d H:i:s')."' " ,$db);
        if(DB_num_rows($status)==1)
            $bg='yellow';
        else
            $bg='orange';
    }
     else if($TaskView['status']=='closed')
    { 
        
        $status=DB_query("select * from tsk_taskassignment where id='".$TaskView['id']."' and concat(end_date,' ',end_time)>='".$TaskView['closing_time']."' " ,$db);
        if(DB_num_rows($status)==1)
            $bg='forestgreen';
        else  
            $bg='cadetblue';
    }
    ?>
        <tr class="row1" style=" background-color: <?php echo $bg;  ?>">
		<td style="padding-left:5px;"><?php  echo $s->GetFieldValue('locations',"loccode='".$TaskView['branch']."'",'locationname'); ?></td>
		<td style="background-color:  ; padding-left:5px;"><?php echo $TaskView['task_no']; ?></td>
		<td style="padding-left:5px;"><?php echo ConvertSQLDate($TaskView['start_date']); ?></td>
		<td style="padding-left:5px;"><?php echo ConvertSQLDate($TaskView['end_date']); ?></td>
                <td style="padding-left:5px;"><?php echo $TaskView['end_time']; ?></td>
		<td style="padding-left:5px;"><?php if($TaskView['assign_to']=='user'){echo $s->getField('www_users','id',$TaskView['user_id'],'realname');;} else{echo $TaskView['assign_to'];} ?></td>
		<td style="padding-left:5px;"><?php echo $s->getField('www_users','id',$TaskView['assigned_by'],'realname') ?></td>
		<td style="padding-left:5px;"><?php echo $TaskView['task_description']; ?></td>
		<td style="padding-left:5px;"><?php if($TaskView['status']=="progress"){ echo "WIP";} else{ echo ucwords($TaskView['status']); }  ?></td>  
	</tr>
        
<?php }?>
</table>
		</div>
	
		
		<!--<h1>Task Execution Status  </h1>	  
		<div style="margin-top:3px;margin-bottom:5px; overflow:auto; height:155px;">
		<div id="divdata">
			<?php 
$SQLTask=DB_query("SELECT * FROM tsk_taskassignment where user_id= ".$_SESSION['UserID']." and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
?>
<table width="100%" cellpadding="3" cellspacing="0" border="1">
	<tr class="row1">
		 <td class="tabledata">Branch</td>
          <td class="tabledata">Task No.</td>
		  <td class="tabledata">Start Date</td>
          <td class="tabledata">End Date</td>
		  <td class="tabledata">Assigned By</td>
		  <td class="tabledata">Task</td>
		  <td class="tabledata">Status</td>
	</tr>
<?php while($TaskView=DB_fetch_array($SQLTask)) {?>
	<tr class="row1">
		<td><?php  echo $s->GetFieldValue('locations',"loccode='".$TaskView['branch']."'",'locationname'); ?></td>
		<td><?php echo $TaskView['task_no']; ?></td>
		<td><?php echo ConvertSQLDate($TaskView['start_date']); ?></td>
		<td><?php echo ConvertSQLDate($TaskView['end_date']); ?></td>
		<td><?php if($TaskView['assign_to']=='user'){echo $s->getField('www_users','id',$TaskView['assigned_by'],'realname');;} else{echo $TaskView['assign_to'];} ?></td>
		
		<td><?php echo $TaskView['task_description']; ?></td>
		<td><?php echo $TaskView['status']; ?></td>
	</tr>
<?php }?>
</table>
			</div>
		</div>-->
	  </div>	<!-- left part of main body close -->	
       	<!-- right part of main body -->		
	  <!--<div class="body_right" style="width:48%;">
  		<h1>My Calendar</h1>	  
		<div style="margin-top:3px;margin-bottom:5px; overflow:auto; height:185px;">
		
		
		 <strong></strong>
		 <div id="calenderdata">
		   <span class="style1">
		   
		   <?php //include('Activity_calander.php'); ?>
	      </span>         </div>
		</div>
		
		  		<h1>My Leave </h1>	  
				<div style="margin-top:3px;margin-bottom:5px; overflow:auto; height:150px;">
				<?php


$sql=DB_query("select * from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
while($RowData=DB_fetch_array($sql))
{

	$qdesig=DB_query("select desigcode,designame from desigmaster where id='".$RowData['designation']."'",$db);
		$rsdesig=DB_fetch_array($qdesig);
?>	
			<div align="right"></div>
		<table border="0" cellpadding="0" cellspacing="0"  width="100%" style="border-collapse:collapse; border:#999999 solid 1px;">
<tr class="row1">
	<td colspan="4" class="tabledata1">
		<p align="left" style="font-size:12px; font-family:Arial; font-weight:bold;">
EMP Code : <?php echo $RowData['emp_code'];?> , EMP Name : <?php echo $RowData['emp_name'];?> , Desgination : <?php echo $rsdesig['designame']; ?> 
</p>
	</td>
</tr>
<tr class="row1">
	<td colspan="4"  valign="top">
	<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse; border:#999999 solid 1px;">
	<tr >
				<tr><th><strong>Leave Type</strong></th>
					<th><strong>Allowed Leave</strong></th>
					<th><strong>Leave Taken</strong></th>
					<th><strong>Remaining Leave</strong></th>
					<th><strong>Detailed View</strong></th>
				</tr>
	<?php 
	     $GetEmpLeave = "Select * from emp_leave where  emp_id='".$RowData['id']."' and leave_type!='000' ";	   
   $ResultEmpLeave = DB_query($GetEmpLeave,$db);
   while($RowEmpLeave=DB_fetch_array($ResultEmpLeave))
   {
   	
  ?>
				<tr><td><?php
					 echo $s->getField('leavemaster','id',$RowEmpLeave['leave_type'],'leavename');
					  echo "( ".$RowEmpLeave['leave_type']." )";?> </td>
					 <td> 
					  <?php $emp_leave_query1=DB_query("SELECT doj FROM empmaster where id='".$RowData['id']."'",$db);
					$emp_leave_row1=DB_fetch_array($emp_leave_query1);
					$ddoj = date("d/m/Y", strtotime($emp_leave_row1['doj']));
					$ddoj1 = explode("/", $ddoj);
					$pdate = date("Y");
					if($ddoj1[2]==$pdate){
						$linyear = $RowEmpLeave['leave_days']/12;
						$lm = (12-$ddoj1[1])+1;
						$levetake = $linyear*$lm;
						echo $levetake;
					}else{
						echo $levetake = $RowEmpLeave['leave_days'];
					}	
						?> </td>
					<td> <?php echo $leaves=leave_calculation($RowData['id'],$RowEmpLeave['leave_type'])?></td>
					<td><?php echo $levetake-$leaves;?> </td>
					<td><a href="<?php echo $viewrurl; ?>&empid=<?php echo $RowData['id']; ?>&leave_type=<?php echo $RowEmpLeave['leave_type']?>">View</a></td>
				</tr>
<?php } ?>				
		</table>
		
		</td>
	</tr>
</table>
<?php } ?>
		</div>
	  </div>--><!-- left part of main body close -->	
	  <div class="cl"></div>
	<div style="height:15px;"></div>
 
	  <div class="cl"></div>	  
    </div>
	
	</div>	
        

 
<div id="tab2" <?php if($tab_data==2) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> style="float:left;">
<?php // print_r ($_REQUEST); 
if(count($_REQUEST['taskid'])>0)
{
    foreach($_REQUEST['taskid'] as $val)
    {
        DB_query("delete from tsk_taskassignment where id='".$val."'",$db);
       DB_query("delete from tsk_taskassignment_remarks where task_id='".$val."' ",$db) ;
    }
    $s->pageLocation("index.php?Application=emp&modid=".$_REQUEST['modid']);
}

?>		
<div>
<table width="100%" border="0" cellpadding="3" cellspacing="0" align="center">

<tr class="row1">
	<td colspan="8" style="text-align:center"><a href="<?php echo "index.php?route=TaskMgt/task_assign".$rurl.'&action=AddNew'?>">
				<input type="button" name="Create" value="Assign Tasks" class="search" style="margin-top:5px; margin-bottom:5px;" /></a>
            <input type="button" onclick="document.getElementById('delete_form').submit()"  name="Delete" value="Delete Tasks" class="search" style="margin-top:5px; margin-bottom:5px;" />
				
	</td>
</tr>
<tr class="row1">
	<td colspan="8">
	<form name="delete_form" id="delete_form" method="post" action="">
	<table width="100%" border="1" cellpadding="1" cellspacing="1" style="border-collapse:collapse;">
	<tr>
    <th width="8%"><strong>Branch</strong></th>
    <th width="8%"><strong>Task No.</strong></th>
	<th width="7%"><strong>Start Date</strong></th>
    <th width="7%"><strong>End Date</strong></th>
	<th width="9%"><strong>Assigned To</strong></th>
	<th><strong>Task</strong></th>
	<th width="6%"><strong>Status</strong></th>
	 <th width="3%"><strong>Delete</strong></th>
    <th width="3%"><strong>Edit</strong></th>
    <th width="3%"><strong>View  </strong></th>
    </tr>


<?php 
		//$query = "SELECT * FROM tsk_taskassignment where assigned_by in($lowerlist) and CompanyId='".$_SESSION['ACGCompanyId']."'";
		$query = "SELECT * FROM tsk_taskassignment where assigned_by = ".$_SESSION['UserID']." and CompanyId='".$_SESSION['ACGCompanyId']."'";
		$query .= " ORDER BY start_date desc";
		$gettt = DB_query($query,$db);
		$_SESSION['Ticket']=$query;
		$i=0;
		while($row_quotes = DB_fetch_array($gettt)){?>
		<tr>
			
          <td valign="top" class="pad_left"><?php  echo $s->GetFieldValue('locations',"loccode='".$row_quotes['branch']."'",'locationname'); ?></td>
          <td valign="top" class="pad_left"><?php echo $row_quotes['task_no'];?> </td>
          <td valign="top" class="pad_left"><?php echo ConvertSQLDate($row_quotes['start_date']);?> </td>
		  <td valign="top" class="pad_left"><?php echo ConvertSQLDate($row_quotes['end_date']);?></td>
          <td valign="top" class="pad_left"><?php  if($row_quotes['assign_to']=='user'){echo $s->getField('www_users','id',$row_quotes['user_id'],'realname');;} else{echo $row_quotes['assign_to'];}//echo $s->GetFieldValue('www_users',"id='".$row_quotes['createdBy']."'",'userid'); ?></td>
		  <td valign="top" class="pad_left"><?php echo $row_quotes['task_description'];?> </td>
                  <td valign="top" class="pad_left"><?php if($row_quotes['status']=="progress"){ echo "WIP";} else{ echo ucwords($row_quotes['status']); }  ?></td>
				  <td valign="top" class="pad_left">
			<?php
                $SOURL="index.php?route=TaskMgt/task_assign_edit&action=Edit&id=".$row_quotes['id'].$rurl;
               // $REURL="index.php?route=TaskMgt/task_assign&action=SHRem&id=".$row_quotes['id'].$rurl;
		//$REURL1="index.php?route=TaskMgt/task_assign&action=AddRem&id=".$row_quotes['id'].$rurl;
		$SO_VIEW="index.php?route=TaskMgt/task_assign_view&action=View&id=".$row_quotes['id'].$rurl;
			?>
                           <input name="taskid[<?php echo $row_quotes['id'] ?>]" type="checkbox" id="leadid_<?php echo $i+1; ?>" <?php if($row_quotes['status']=='closed'|| $row_quotes['status']=='progress'){ echo "disabled"; $p='title="Not Allowed"'; }?> <?php echo $p; ?>  value="<?php  echo $row_quotes['id']?>"  />
                           
			 
			 <!--<a href="<?php //echo $SO_VIEW?>" ><img src="images/search.gif" width="10px"  height="10" /></a>-->
			 </td>
                        
            <td  valign="top" class="pad_left"><?php if($row_quotes['status']=='pending'){ ?><a href="<?php echo $SOURL ;?>"> <img src="images/icon_edit.gif" width="15"  height="15"  title="Edit task"  /></a> <?php } else{ ?><img src="images/icon_edit.gif" width="15"  height="15" title="Not Allowed" /><?php } ?></td>
            <td  valign="top" class="pad_left"><a href="<?php echo $SO_VIEW ;?>"><img src="images/search.gif" title="View task" width="15"  height="15"></a></td>
			<!--  <td valign="middle"><?php if($row_quotes['status']=='pending'){?><a href="<?php echo $REURL1 ;?>"><input type="button" name="Create" value="Add Remarks" class="search" /></a><?php } else echo "Add Remarks"; ?></td>
			 <td valign="middle"><a href="<?php echo $REURL ;?>"><input type="button" name="Create" value="Show Remarks" class="search" /></a></td>-->
        </tr>
		<?php $i++;} ?>
      </table>
	  </form>
	</td>
</tr>
</table>
</div>  
	<div style="clear:both;"></div>
	</div>
	<div style="clear:both;"></div>
<div id="tab3" <?php if($tab_data==3) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?>  style="float:left;">
   <form action="" method="post" name="myform" >
   <table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr class="row1">
	<td colspan="8">
<table width="100%" border="1" cellpadding="1" cellspacing="1" style="border-collapse:collapse;">
<tr>
           <th width="8%"><strong>Branch</strong></th>
           <th width="8%"><strong>Task No.</strong></th>
           <th width="7%"><strong>Start Date</strong></th>
           <th width="7%"><strong>End Date</strong></th>
           <th width="9%"><strong>Assigned By</strong></th>
           <th><strong>Task</strong></th>           
           <th width="6%"><strong>Status</strong></th>
           <th><strong>Assigned To </strong></th>
           <th width="5%"><div align="center"><strong>Reply</strong></div></th>
           <th width="5%"><div align="center"><strong>Close</strong></div></th>
</tr>
		<?php 
		$query = "SELECT * FROM tsk_taskassignment where CompanyId='".$_SESSION['ACGCompanyId']."' and (user_id= ".$_SESSION['UserID']." || assigned_by='".$_SESSION['UserID']."') ";
		$query .= " ORDER BY start_date desc";
		$gettt = DB_query($query,$db);
		$_SESSION['Ticket']=$query;
		while($row_quotes = DB_fetch_array($gettt)){?>
		<tr>
			<!--<td style="white-space:nowrap; padding-left:5px;" valign="top">
			<?php
			// $SOURL="index.php?route=TaskMgt/task_assign&action=Edit&id=".$row_quotes['id'].$rurl;
			 $REURL="index.php?route=TaskMgt/task_assign_addrem&action=AddRem&id=".$row_quotes['id'].$rurl;
			 $CLURL="index.php?route=TaskMgt/task_assign_addrem&action=AddRem&Close=true&id=".$row_quotes['id'].$rurl;
			 //$SO_VIEW="index.php?route=TaskMgt/task_assign&action=View&ttid=".$row_quotes['id'].$rurl;
			?>
			   <input name="salesid[]" type="checkbox" id="salesid_<?php echo $i; ?>"   value="<?php  echo $row_quotes['id']?>"  />
			 <a href="<?php echo $SOURL ;?>"><img src="images/icon_edit.gif" width="10px"  height="10" /></a>
			 <a href="<?php //echo $SO_VIEW?>" ><img src="images/search.gif" width="10px"  height="10" /></a>		  </td>-->
          <td valign="top" class="pad_left"><?php  echo $s->GetFieldValue('locations',"loccode='".$row_quotes['branch']."'",'locationname'); ?></td>
          <td valign="top" class="pad_left"><?php echo $row_quotes['task_no'];?> </td>
          <td valign="top" class="pad_left"><?php echo ConvertSQLDate($row_quotes['start_date']);?> </td>
		  <td valign="top" class="pad_left"><?php echo ConvertSQLDate($row_quotes['end_date']);?></td>
          <td valign="top" class="pad_left"><?php  echo $s->getField('www_users','id',$row_quotes['assigned_by'],'realname');//echo $s->GetFieldValue('www_users',"id='".$row_quotes['createdBy']."'",'userid'); ?></td>
		  <td valign="top" class="pad_left"><?php echo $row_quotes['task_description'];?> </td>
          <td valign="top" class="pad_left"><?php if($row_quotes['status']=="progress"){ echo "WIP";} else{ echo ucwords($row_quotes['status']); }  ?></td>
          <td valign="top" class="pad_left"><?php  echo $s->getField('www_users','id',$row_quotes['user_id'],'realname');//echo $s->GetFieldValue('www_users',"id='".$row_quotes['createdBy']."'",'userid'); ?></td>
		  <td valign="top" class="pad_left"><?php if($row_quotes['status']=='pending' || $row_quotes['status']=='progress'){?><a href="<?php echo $REURL ;?>"><input name="" type="button"  value="Add" class="search"/></a><?php } else echo 'Closed'; ?></td>
		<?php if($_SESSION['UserID']==$row_quotes['user_id']){ ?>	  
                <td valign="top" class="pad_left"><?php if($row_quotes['status']=='pending' || $row_quotes['status']=='progress'){?><a href="<?php echo $CLURL ;?>"><input name="" type="button"  value="Close" class="search"/></a><?php }else {echo 'Closed';} ?></td> <?php } else {echo "<td>Not Allowed</td>";}?>
        </tr>
		<?php } ?>
      </table>
	</td>
</tr>
</table>
  </form>
	
	</div>
	<div style="clear:both;"></div>
<div id="tab4" <?php if($tab_data==4) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?>>
	<a href="<?php echo "index.php?route=TaskMgt/TODO".$rurl.'&action=AddNew'?>">
				<input type="button" name="Create" value="Add To Do" class="search" style="margin-top:5px; margin-bottom:5px;" /></a>
	<?php 
$SQLTODO=DB_query("select * from to_do",$db);
?>
<?php
if($_REQUEST['todoconfrm']=='true' && $_REQUEST['toid']!='')
{
    DB_query("update to_do set status1='Confirm' where id='".$_REQUEST['toid']."' ",$db);
    $s->pageLocation("index.php?Application=emp&modid=".$_REQUEST['modid']);
}

?>
<table width="100%" cellpadding="1" cellspacing="1" border="1" style="border-collapse:collapse;">
	<tr>
		<th width="15%"><strong>To Do</strong></th>
		<th><strong>ToDo Description</strong></th>
        <th width="5%"><strong>Priority</strong></th>
		<th width="7%"><strong>Date</strong></th>
        <th width="7%"><strong>Status</strong></th>
	</tr>
<?php while($TODOView=DB_fetch_array($SQLTODO)) {?>
	<tr>
        <td class="pad_left"><?php echo $TODOView['to_do']; ?></td>
		<td class="pad_left"><?php echo $TODOView['description']; ?></td>
        <td class="pad_left"><?php echo $TODOView['periority']; ?></td>	
		<td class="pad_left"><?php echo ConvertSQLDate($TODOView['due_date']); ?></td>
        <td class="pad_left"><?php if($TODOView['status1']=='Pending'){ echo "<a href=index.php?Application=emp&modid=".$_REQUEST['modid']."&toid=".$TODOView['id']."&todoconfrm=true><button>Confirm</button></a>"; } else {echo "Confirmed"; } ?></td>
	</tr>
<?php }?>
</table>
	</div>
  
	<div id="tab10" <?php if($tab_data==10) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> >
 <?php include ('task_assignment_report.php');?>
</div>  	
   
<div id="tab5" <?php if($tab_data==5) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> >
	<?php 
$SQLFollow=DB_query("select * from follow_up",$db);
?>
<a href="<?php echo "index.php?route=TaskMgt/FollowUp".$rurl.'&action=AddNew'?>">
				<input type="button" name="Create" value="Add Follow Up" class="search" style="margin-top:5px; margin-bottom:5px;" /></a>
<table width="100%" cellpadding="1" cellspacing="1" border="1" style="border-collapse:collapse;">
	<tr>
		<th width="20%">Client</th>
		<th width="9%">FollowUp Type</th>
		<th width="9%">FollowUp Date</th>
		<th>Comments</th>
	</tr>
<?php while($FollowView=DB_fetch_array($SQLFollow)) {?>
	<tr>
		<td class="pad_left"><?php echo $s->getField('clientmaster','id',$FollowView['client_id'],'c_name'); ?></td>
		<td class="pad_left"><?php echo $FollowView['fillowup_type']; ?></td>
		<td class="pad_left"><?php echo ConvertSQLDate($FollowView['followup_date']); ?></td>
		<td class="pad_left"><?php echo $FollowView['comments']; ?></td>
	</tr>
<?php }?>
</table>
	</div>
<div id="tab6"  <?php if($tab_data==6) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?>>
	<?php 
$SQLEV=DB_query("select * from event",$db);
?>
<a href="<?php echo "index.php?route=TaskMgt/Event".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add Event" class="search" style="margin-bottom:5px; margin-top:5px;" /></a>
				
<table width="100%" cellpadding="1" cellspacing="1" border="1" style="border-collapse:collapse;">
	<tr>
		<th width="7%">Event Type</th>
		<th>Event Name</th>
		<th width="9%">Event Location</th>
		<th width="8%">Status</th>
		<th width="8%">Date</th>
	</tr>
<?php while($EventView=DB_fetch_array($SQLEV)) {?>
	<tr>
		<td class="pad_left"><?php echo $EventView['event_type']; ?></td>
		<td class="pad_left"><?php echo $EventView['event_name']; ?></td>
		<td class="pad_left"><?php echo $EventView['event_location']; ?></td>
		<td class="pad_left"><?php echo $EventView['event_status']; ?></td>
		<td class="pad_left"><?php echo ConvertSQLDate($EventView['event_start_date']); ?></td>
	</tr>
<?php }?>
</table>
	</div>
<div id="tab7"  <?php if($tab_data==7) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> >
<?php include('CRM/ta_da_index.php'); ?>
</div>
<div id="tab8" <?php if($tab_data==8) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> >
<?php include('Leave_management.php'); ?>
</div>
    <div id="tab12" <?php if($tab_data==12) { ?> class="tab-content active" <?php } else { ?> class="tab-content hide"<?php } ?> >
 <?php 
 //echo $tab_data;
 include("CRM/CalenderManagement.php");?>
</div>   
        
<div class="clr"></div>

</div>
<div class="clr"></div>
<script language="javascript" >

function LeadData()
{
	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}


$(document).ready(function(){	

		//var cnt=document.getElementById("count").value;
		$('input[name=viewleaveA]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var EmpId=document.getElementById("empId_"+tt2).value;
		var LeaveType=document.getElementById("LeaveType_"+tt2).value;		
			$("#div_id").dialog({
				title:'Applied Leave Details',
				modal: true,
				resizable: false,
				width:910,
				height:350,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: [
        {
            id: "button-Update",
            text: "Update",
            click: function() {
                $("#editdatafor").closest("form").submit();
            }
        },
        {
            id: "button-Exit",
            text: "Exit",
            click: function() {
                $(this).dialog("close");
            }
        }
    ]
				
			});
			$("#button-Update").hide();
		ViewappliedLeave(EmpId,LeaveType);
		});
		
	
	});
	



function ViewappliedLeave(EmpId,LeaveType)
{

	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.split("__");
		
	}
	}
	xmlhttp.open("GET","view_leave_request_new.php?EMPID="+EmpId+"&LT="+LeaveType,true);
	xmlhttp.send();
}


$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=LeaveApplly]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var EmpId=document.getElementById("empId_"+tt2).value;
		var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#Apply_div").dialog({
				title:'Apply For Leave',
				modal: true,
				resizable: false,
				width:500,
				height:300,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Save: function()
					{
						$("#myform").closest("form").submit();
					},
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		ApplyForLeave(EmpId,LeaveType);
		});
	});


function ApplyForLeave(EmpId,LeaveType)
{
	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)
	{
		var data=xmlhttp.responseText.split("__");
		document.getElementById("fetchdata").innerHTML=data[0];
		document.getElementById("LTYPE").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","leave_request_new.php?EMPID="+EmpId+"&LT="+LeaveType,true);
	xmlhttp.send();
}

function LeaveJoin(str,strid)
{
	
			if(str=="")
			{
				alert("Please enter leave period from.");
				document.getElementById(strid).focus();
				return false;
			}
			var doj = document.getElementById("doj").value;
			if(doj=="")
			{
				alert("You not take leave. Please enter date of joining in Employee Master.");
				document.getElementById(strid).value="";
				document.getElementById(strid).focus();
				return false;
			}
			
			var f = str.split("/");
			var d = doj.split("/");
			
			var x=new Date();
			x.setFullYear(d[2],d[1]-1,d[0]);
			var y = new Date();
			y.setFullYear(f[2],f[1]-1,f[0]);
			
			
			if (x>y)
  			{
  				alert("You not take leave before joining date. Your joining date is "+d[0]+"/"+d[1]+"/"+d[2]);
				document.getElementById(strid).value="";
				document.getElementById(strid).focus();
				return false;
  			}
			return true;
		
}
	
	
	
function LeaveJoinEdit(str,strid)
{
			var idA=strid.split("_");

			var i=idA[1];
			if(str=="")
			{
				alert("Please enter leave period from.");
				document.getElementById(strid).focus();
				return false;
			}
			
			var doj = document.getElementById("dojAE").value;
			if(doj=="")
			{
				alert("You not take leave. Please enter date of joining in Employee Master.");
				document.getElementById(strid).value="";
				document.getElementById(strid).focus();
				return false;
			}
			
			
			
			var f = str.split("/");
			var d = doj.split("/");
			
			var x=new Date();
			x.setFullYear(d[2],d[1]-1,d[0]);
			var y = new Date();
			y.setFullYear(f[2],f[1]-1,f[0]);
			
			
			if (x>y)
  			{
  				alert("You not take leave before joining date. Your joining date is "+d[0]+"/"+d[1]+"/"+d[2]);
				document.getElementById(strid).value="";
				document.getElementById(strid).focus();
				return false;
  			}
			return true;
		
}	
	
	
		
function LeaveTypeValue()
{
	var doj = document.getElementById("doj").value;
	if(document.getElementById("leave_type").value!='')
	{
		var str = document.getElementById("leave_type").value;
	}
	
	
	if(document.getElementById("period_from").value!='')
	{
		var date_from = document.getElementById("period_from").value;
	}
	else
	{
		alert("First Fill The Leave From Date !");
		document.getElementById("period_to").value='';
		return false;
	}
	
	
	if(document.getElementById("period_to").value!='')
	{
		var date_to = document.getElementById("period_to").value;
	}
	
	
	
	var FD = date_from.split("/");
	var TD = date_to.split("/");
	
	var x1=new Date();
	x1.setFullYear(FD[2],FD[1]-1,FD[0]);
	var y1 = new Date();
	y1.setFullYear(TD[2],TD[1]-1,TD[0]);
	
	if(x1>y1)
	{
		alert("Leave Period From Can't Less Than Leave Period To");
		document.getElementById("period_from").value='';
		document.getElementById("period_to").value='';
		document.getElementById("reqleave").value='';
		document.getElementById("NoOfLeaveDays").value='';
		//document.getElementById("period_from").focus();
		return false;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		//alert(xmlhttp.responseText);
		var data=xmlhttp.responseText.split("__");
		if(data[2]=='1')
		{
			alert("This Date Not Allowed For Leave Because You have Already Taken Some Leave Between These Date");
			document.getElementById("period_from").value='';
			document.getElementById("period_to").value='';
			return false;
		}
		else
		{
			document.getElementById("reqleave").value=data[0];
			document.getElementById("NoOfLeaveDays").value=data[1];
		}
	}
	
	}
	var empid=document.getElementById("empid").value;
	xmlhttp.open("GET","getNoOfDays.php?q="+str+"&empid="+empid+"&dfrom="+date_from+"&dto="+date_to+"&doj="+doj,true);
	xmlhttp.send();
}




function LeaveTypeValueEdit(i)
{
	var doj = document.getElementById("dojAE").value;
	if(document.getElementById("leave_typeEdit").value!='')
	{
		var str = document.getElementById("leave_typeEdit").value;
	}
	
	if(document.getElementById("fromdate_"+i).value!='')
	{
		var date_from = document.getElementById("fromdate_"+i).value;
	}
	
	
	if(document.getElementById("todate_"+i).value!='')
	{
		var date_to = document.getElementById("todate_"+i).value;
	}
	
	
	var FD = date_from.split("/");
	var TD = date_to.split("/");
	
	var x1=new Date();
	x1.setFullYear(FD[2],FD[1]-1,FD[0]);
	var y1 = new Date();
	y1.setFullYear(TD[2],TD[1]-1,TD[0]);
	
	if(x1>y1)
	{
		alert("Leave Period From Can't Less Than Leave Period To");
		document.getElementById("fromdate_"+i).value=document.getElementById("staticfrmdate_"+i).value;
		document.getElementById("todate_"+i).value=document.getElementById("statictodate_"+i).value;
		//document.getElementById("period_from").focus();
		return false;
	}
	
	
	
	var editid=document.getElementById("leaveappid_"+i).value;
	
	var preleavereq=document.getElementById("reqleave1_"+i).value;
	
	
	
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
			var data=xmlhttp.responseText.split("__");
			if(data[2]=='1')
			{
				alert("This Date Not Allowed For Leave Because You have Already Taken Some Leave Between These Date");
				document.getElementById("fromdate_"+i).value=document.getElementById("staticfrmdate_"+i).value;
				document.getElementById("todate_"+i).value=document.getElementById("statictodate_"+i).value;
				return false;
			}
			else
			{
				document.getElementById("reqleave_"+i).value=data[0];
				document.getElementById("NoOfLeaveDays_"+i).value=data[1];
			}
		}
		
	}
	var empid=document.getElementById("empidEdit").value;
	xmlhttp.open("GET","getNoOfDaysEdit.php?q="+str+"&empid="+empid+"&dfrom="+date_from+"&dto="+date_to+"&doj="+doj+"&Editid="+editid+"&pevlevereq="+preleavereq,true);
	xmlhttp.send();
}


function changestatus(i)
{
	var count=document.getElementById("cout").value;
	for(var k=0;k<count;k++)
	{
	if(k==i)
	{
		if(document.getElementById("checkboxEdit_"+i).checked==true)
		{
			$(function() {
		$( "#fromdate_"+i).datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
		$( "#todate_"+i).datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
 		 });
		 	
			document.getElementById("fromdateval_"+i).style.display='none';
			document.getElementById("fromdate_"+i).type='text';
			document.getElementById("todateval_"+i).style.display='none';
			document.getElementById("todate_"+i).type='text';
			document.getElementById("empleaveEdit_"+i).style.display='none';
			document.getElementById("NoOfLeaveDays_"+i).type='text';
			document.getElementById("reqleaveEdit_"+i).style.display='none';
			document.getElementById("reqleave_"+i).type='text';
			document.getElementById("empleaveEditReason_"+i).style.display='none';
			document.getElementById("leave_reason_"+i).type='text';
			document.getElementById("checkboxEdit_"+k).disabled='';
			$("#button-Update").show();
		}
		else
		{
			
			document.getElementById("fromdateval_"+i).style.display='block';
			document.getElementById("fromdate_"+i).type='hidden';
			document.getElementById("todateval_"+i).style.display='block';
			document.getElementById("todate_"+i).type='hidden';
			document.getElementById("empleaveEdit_"+i).style.display='block';
			document.getElementById("NoOfLeaveDays_"+i).type='hidden';
			document.getElementById("reqleaveEdit_"+i).style.display='block';
			document.getElementById("reqleave_"+i).type='hidden';
			document.getElementById("empleaveEditReason_"+i).style.display='block';
			document.getElementById("leave_reason_"+i).type='hidden';
			document.getElementById("checkboxEdit_"+k).disabled='';
			$("#button-Update").hide();
			for(var k=0;k<count;k++)
			{
				if(document.getElementById("approvalStatus_"+k).value!='Y')
				{
				document.getElementById("checkboxEdit_"+k).disabled='';
				}
			}
			
		}
	}
	else
	{
		document.getElementById("checkboxEdit_"+k).disabled='disabled';
	}
	}
}


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

function validateadd()
{
	if(document.getElementById("period_from").value=='')
	{
		alert("Please Select The From Date For Leave !");
		document.getElementById("period_from").focus();
		return false;
	}
	if(document.getElementById("period_to").value=='')
	{
		alert("Please Select The To Date For Leave !");
		document.getElementById("period_to").focus();
		return false;
	}
	var reqleave=document.getElementById("reqleave").value;
	var noofpendingleave=document.getElementById("NoOfLeaveDays").value;
	if(noofpendingleave<0)
	{
		alert("You Can't Take Leave For These Days Because You have Not More Leave");
		document.getElementById("period_from").value='';
		document.getElementById("period_to").value='';
		document.getElementById("reqleave").value='';
		document.getElementById("NoOfLeaveDays").value='';
		document.getElementById("period_from").focus();
		return false;
	}
}

function fillbranch(str)
{
   
	document.getElementById("branchCode").value=str;
}

function showappdiveid()
{
	document.getElementById("APPREAVE").style.display='none';
	document.getElementById("APPLEAVE").style.display='block';
}
function showapprdiveid()
{
	document.getElementById("APPREAVE").style.display='block';
	document.getElementById("APPLEAVE").style.display='none';
}
</script>
