<?PHP
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">Customer History</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>
								Customer History
							</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 -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery-2.1.4.min.js"></script>
<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#course').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($_GET['customer'])
{

$customer=$_GET['customer'];

$cust=mysql_query("select * from customer where ID='$customer'");
$cust1=mysql_fetch_array($cust);

$emp=mysql_query("select * from employee where ID='$cust1[executive]'");
$emp1=mysql_fetch_array($emp);

echo"<br /><table style='width:75%; margin:auto;'>

<tr><td>Customer : <b style='font-size:17px;'>".$cust1['name']."</b></td><td style='text-align:right;'><a href='referance.php?id=".$customer."'>+ Add Referance</a></td></tr>

<tr><td colspan='2' style='height:15px;'></td></tr>

<tr><td style='width:50%;' valign='top'>

<table style='line-height:27px;'>

<tr><td>Address</td><td style='padding:0 11px;'>:</td><td>".$cust1['address']."</td></tr>

<tr><td>Email</td><td style='padding:0 11px;'>:</td><td>".$cust1['address']."</td></tr>

</table>

</td>

<td valign='top'>

<table style='line-height:27px;'>

<tr><td>Contact</td><td style='padding:0 11px;'>:</td><td>".$cust1['phone']."</td></tr>

<tr><td>Executive</td><td style='padding:0 11px;'>:</td><td>".$emp1['name']."</td></tr>

</table>

</td></tr>


<tr><td colspan='2' style='height:15px;'></td></tr>


<tr>

<td>

<table style='line-height:27px;'>

<tr><td>Irregation System</td><td style='padding:0 11px;'>:</td><td>".$cust1['irregationsystem']."</td></tr>

<tr><td>Total Land</td><td style='padding:0 11px;'>:</td><td>".$cust1['totalland']."</td></tr>

<tr><td>Crop Stage</td><td style='padding:0 11px;'>:</td><td>".$cust1['cropstage']."</td></tr>

<tr><td>Next Application(Date)</td><td style='padding:0 11px;'>:</td><td>";

if($cust1['nextapply']!='0000-00-00' && $cust1['nextapply']!='1970-01-01')
{
echo"".date('d-m-Y',strtotime($cust1['nextapply']))."";
}

echo"</td></tr>

</table>

</td>

<td>

<table style='line-height:27px;'>

<tr><td>Type of Soil</td><td style='padding:0 11px;'>:</td><td>".$cust1['typeofsoil']."</td></tr>

<tr><td>Cultivating Crop</td><td style='padding:0 11px;'>:</td><td>".$cust1['cultivatingcrop']."</td></tr>

<tr><td>Last Applied(Date)</td><td style='padding:0 11px;'>:</td><td>";

if($cust1['lastapplied']!='0000-00-00' && $cust1['lastapplied']!='1970-01-01')
{
echo"".date('d-m-Y',strtotime($cust1['lastapplied']))."";
}

echo"</td></tr>

<tr><td>Wanted Qty</td><td style='padding:0 11px;'>:</td><td>".$cust1['wantedqty']."</td></tr>

</table>

</td>

</tr>

</table><br /><br />";


echo"<table class='table table-bordered table-condensed' style='width:75%; margin:auto;'>

<thead><tr><th>Last Purchased</th><th>Quantity</th><th>Which Corp</th><th>Satisfied(Yes/No)</th><th>Reason</th></tr></thead>

<tr><td>".$cust1['lastpurchased']."</td><td>".$cust1['qty']."</td><td>".$cust1['crop']."</td><td>".$cust1['satisfied']."</td><td>".$cust1['reason']."</td></tr>

</table><br /><br />";


echo"<center><b>Follow Up Details</b></center>

<table style='width:90%; margin:auto;'><tr><td><table id='dynamic-table' class='table table-bordered table-condensed'>

<thead><tr><th style='width:13%;'>Date</th><th>Time</th><th style='width:25%;'>Remarks</th><th>Executive</th><th>Status</th></tr></thead>";

$getr=mysql_query("select * from followup where customer='$customer'");
while($getr1=mysql_fetch_array($getr))
{
	
	$cust=mysql_query("select * from customer where ID='$getr1[customer]'");
	$cust1=mysql_fetch_array($cust);
	
	$exec=mysql_query("select * from employee where ID='$getr1[executive]'");
	$exec1=mysql_fetch_array($exec);
	
	echo"<tr><td>".date('d-m-Y',strtotime($getr1['date']))."</td><td>".$getr1['time']."</td><td>".$getr1['remarks']."</td>
	
	<td>".$exec1['name']."</td><td>";
	
	if($getr1['status']!='')
	{
		echo"".$getr1['status']."";
	}
	
	echo"</td></tr>";
}

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


<center><h4>Referances</h4></center>

<table class='table table-bordered table-condensed' style='width:55%; margin:auto;'>

<thead><tr><th>Name</th><th>Address</th><th>Contact</th></tr></thead>";

$rfn=mysql_query("select * from customer_referances where referredby='$customer'");
while($rfn1=mysql_fetch_array($rfn))
{
	echo"<tr><td>".$rfn1['name']."</td><td>".$rfn1['address']."</td><td>".$rfn1['phone']."</td></tr>";
}

echo"</table><br /><br />

<center><a href='viewcustomer.php'>Back</a></center>";

}

?>
                                        
                                            
                                            							

										<!-- 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();
?>