<?php
session_start();
include "../class/class.MySQL.php";
require '../class/resizeImage.php';
$db=new MySQL();

$from_date1='';
$to_date1='';
$add_date1='';
$branch='';
$memberid='';
$yearid='';
$monthid='';


//echo $_REQUEST['action'];

if(!empty($_REQUEST['add_date'])){
$add_date=$_REQUEST['add_date'];
$add_date1 = date('Y-m-d', strtotime($add_date));
}

if(!empty($_REQUEST['from_date'])){
$from_date=$_REQUEST['from_date'];
$from_date1 = date('Y-m-d', strtotime($from_date));
}

if(!empty($_REQUEST['to_date'])){
$to_date=$_REQUEST['to_date'];
$to_date1 = date('Y-m-d', strtotime($to_date));
}

if(!empty($_REQUEST['branch'])){
$branch=$_REQUEST['branch'];
}

if(!empty($_REQUEST['memberid'])){
$memberid=$_REQUEST['memberid'];
}

if(!empty($_REQUEST['yearid'])){
$yearid=$_REQUEST['yearid'];
}

if(!empty($_REQUEST['monthid'])){
$monthid=$_REQUEST['monthid'];
}

$query = "SELECT * FROM  `productivity` as p join `employee` as e  on p.prd_empid = e.e_id join `branches` as b on b.branch_id = e.branchid where 1  ";

if($add_date1!=''){
$query.=" and p.prd_date = '".$add_date1."' ";
}

if($from_date1!="" && $to_date1!=""){
$query.=" and p.prd_date between '$from_date1' and '$to_date1'";
}

if($yearid!=''){
$query.=" and p.prd_date like '".$yearid."%' ";
}

if($monthid!=''){
$query.=" and MONTH(p.prd_date) = '".$monthid."' ";
}

if($_SESSION['admin_id'] == 1)
{
	if($memberid!=''){
		$query.=" and e.e_id = '".$memberid."' ";
	}
	
}
else
{
	$query.=" and e.e_id = '".$_SESSION['admin_id']."' ";
}

if($branch!=''){
$query.=" and p.prd_branch_id = '".$branch."' ";
}

include "pagingserch.php";

$query.=" LIMIT $start, $limit";

//echo $query;
if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=15;
}


$pagecnt=$start;
$getproductivity = $db->fetchQuery($query);
	
	//echo $count = count($getrecruitment);
	
	//echo $getrecruitment[] = $pagination;
	
	$count = count($getproductivity);
	$getproductivity[$count-1]['totalrows'] = $total_pages;
	
	echo '{"getproductivity":'.json_encode($getproductivity).'}';





?>

	
    
    
