<?PHP
ini_set('max_execution_time', '1200'); //300 seconds = 5 minutes
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Follow Up Report</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Follow Up Report
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->
<br />

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->
                                
<script src="assets/js/jquery.js"></script>
<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#work').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
	});
	
});	

</script>

<?php 



if(isset($_GET['submit']))
{
$fromdate=$_GET['fromdate'];
$todate=$_GET['todate'];
$executive=$_GET['executive'];

echo"<center><table><tr><td style='width:30%;'></td><td style='width:40%;'><b>Follow Up Report Between - ".$fromdate." - ".$todate."</b></td><td style='width:30%; text-align:right;'><a href='followupreport.php'>Back</a></td></tr></table></center><br />";
/*
$fromdate=date('Y-m-d',strtotime($fromdate));
$todate=date('Y-m-d',strtotime($todate));
*/
echo"<table style='width:95%; margin:auto;'>

<tr><td><table id='example' class='table table-bordered table-condensed' style='font-size:11px;'>

<thead><tr>
<th></th>
<th style='width:8%;'>Date</th>
<th>Customer</th>
<th>District</th>
<th>Crop</th>
<th>Mobile</th>
<th>Time</th>
<th style='width:13%;'>L.Remarks</th>
<th style='width:13%;'>Remarks</th>
<th>Executive</th>
<th>Status</th></tr></thead>";

$sel=mysql_query("select * from admin where username='$user'");
$nmrw=mysql_num_rows($sel);
$sel1=mysql_fetch_array($sel);

if($nmrw>0)
{

if($executive!='')
{
$exct=$executive;
}
else
{
$exct='0';
}

}
else
{
	
	$empd=mysql_query("select * from employee where username='$user'");
	$empd1=mysql_fetch_array($empd);

	$exct=$empd1['ID'];

}

echo"</table></td></tr></table>";

$exct=$exct;
$fromdate=$fromdate;
$todate=$todate;

}

else
{
	
	
	if (isset($_GET['s'])) 
	{
	 $status=$_GET['s'];
		 if($status=='1')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					Values Updated Successfully !
			  </div>';
		}
		elseif($status=='2')
		 {
		 echo '<div class="alert alert-danger">
				<a class="close" data-dismiss="alert">x</a>
					Values not edited. please try again.
			  </div>';
		}
	}
	

?>



<center>



<form action="followupreport.php" method="get" id="work">



<table width="50%" style="line-height:35px;">

<tr><td>From Date <span class="red">*</span></td><td>:</td>
<td> <input type="text" name="fromdate" id="required" title="*" class="datepicker" autocomplete="off" /></td></tr>

<tr><td>To Date <span class="red">*</span></td><td>:</td>
<td> <input type="text" name="todate" id="required" title="*" class="popupdatepicker" autocomplete="off" /></td></tr>

<tr><td>Executive </td><td>:</td>
<td><select name="executive" class="chosen" style="width:220px;"><option value="">-- Select --</option>

<?php

$sel=mysql_query("select * from admin where username='$user'");
$nmrw=mysql_num_rows($sel);
$sel1=mysql_fetch_array($sel);

if($nmrw>0)
{
$exec=mysql_query("select employee.ID as ID, employee.name as name from employee left join department on employee.department=department.ID where department.crm='1' order by employee.ID asc");
while($exec1=mysql_fetch_array($exec))
{
	echo"<option value='".$exec1['ID']."'>".$exec1['name']."</option>";
}
}
else
{

$empd=mysql_query("select * from employee where username='$user'");
$empd1=mysql_fetch_array($empd);

$usr=$empd1['ID'];

echo"<option value='".$usr."'>".$empd1['name']."</option>";

}

?>

</select></td></tr>

</table><br />



<button type="submit" name="submit" class="btn btn-sm btn-primary" value="submit">Go</button>



</form>



</center>



<?php


}

$exct=$exct;
$fromdate="'".$fromdate."'";
$todate="'".$todate."'";

?>                             
                               
							<br>
<br>


<script type="text/javascript" language="javascript" class="init">

		var fromdate=<?php echo $fromdate; ?>;
		var todate=<?php echo $todate; ?>;
		var exct=<?php echo $exct; ?>;

		$(document).ready(function() {
			$('#example').dataTable( {
				"processing": true,
				"serverSide": true,
				"ajax": "followupreportserver.php?exct="+ exct +"&fromdate="+ fromdate +"&todate="+ todate,
				"language": {
                    "processing": '<i class="fa fa-spinner fa-spin" style="font-size:24px;color:rgb(75, 183, 245);"></i>'
                 },
				 'columnDefs' : [
						//hide the second & fourth column
						{ 'visible': false, 'targets': [0] }
					]
			} );
		} );

</script>


								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					

</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->


<?php

include 'bottom.php';

}
else
{

 header("location:login.php");
}

ob_flush();

?>