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

<script src="assets/js/jquery.js"></script>

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->
                                
                                <?php
								
								if (isset($_GET['s'])) 	
								{
								 $status=$_GET['s'];
									
									 if($status=='1')
									 {
										 
										echo'<div class="alert alert-block alert-success">
											<button type="button" class="close" data-dismiss="alert">
												<i class="ace-icon fa fa-times"></i>
											</button>
		
											<i class="ace-icon fa fa-check green"></i>
		
											Logged in
											<strong class="green">Successfully.</strong>
			
										</div>';
										
									 }
								}



echo"<center><b>Date - ".date('d-m-Y')."</b></center>";

$date=date('Y-m-d');

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

if($nmrw>0)
{

echo"<br /><table class='table table-bordered table-condensed' style='width:65%; margin:auto; font-size:12px;'>

<thead><tr><th style='width:28%;'>Executive</th><th style='width:18%;'>Todays Calls</th>
<th style='width:18%;'>Calls Updated</th><th style='width:18%;'>Order Confirmed</th>
<th style='width:18%;'>New Customers</th></tr></thead>";

$fir=0;
$sec=0;
$thr=0;
$fur=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))
{

$flu=mysql_query("select * from followup where date='$date' and executive='$exec1[ID]'");
$flu1=mysql_num_rows($flu);

$uflu=mysql_query("select * from followup where date='$date' and (status!='' and status!='Confirmed') and executive='$exec1[ID]'");
$uflu1=mysql_num_rows($uflu);

$cflu=mysql_query("select * from followup where date='$date' and status='Confirmed' and executive='$exec1[ID]'");
$cflu1=mysql_num_rows($cflu);

$cc=mysql_query("select * from crm_customer where date='$date' and executive='$exec1[ID]'");
$cc1=mysql_num_rows($cc);

echo"<tr><td style='width:28%;'>".$exec1['name']."</td>
<td style='width:18%; text-align:right;'>".$flu1."</td>
<td style='width:18%; text-align:right;'>".$uflu1."</td>
<td style='width:18%; text-align:right;'>".$cflu1."</td>
<td style='width:18%; text-align:right;'>".$cc1."</td></tr>";

$fir=$fir+$flu1;
$sec=$sec+$uflu1;
$thr=$thr+$cflu1;
$fur=$fur+$cc1;
}

echo"<tr><td style='text-align:right;'>Total</td><td style='text-align:right;'>".$fir."</td>
<td style='text-align:right;'>".$sec."</td><td style='text-align:right;'>".$thr."</td>
<td style='text-align:right;'>".$fur."</td></tr></table><br />";


//Sales & Purchase


$tsl=mysql_query("select sum(total) as total from invoice where date='$date'");
$tsl1=mysql_fetch_array($tsl);

$trc=mysql_query("select sum(amount) as amount from receipt where date='$date'");
$trc1=mysql_fetch_array($trc);

$tpr=mysql_query("select sum(total) as total from purchase where date='$date'");
$tpr1=mysql_fetch_array($tpr);

$tpy=mysql_query("select sum(amount) as amount from payment where date='$date'");
$tpy1=mysql_fetch_array($tpy);


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

<tr><td style='width:70%;'>Today Sales</td><td style='width:30%; text-align:right;'>".number_format($tsl1['total'],2,'.','')."</td></tr>
<tr><td style='width:70%;'>Amount Received Today</td><td style='width:30%; text-align:right;'>".number_format($trc1['amount'],2,'.','')."</td></tr>
<tr><td colspan='2' style='height:15px;'></td></tr>
<tr><td style='width:70%;'>Today Purchase</td><td style='width:30%; text-align:right;'>".number_format($tpr1['total'],2,'.','')."</td></tr>
<tr><td style='width:70%;'>Amount Paid Today</td><td style='width:30%; text-align:right;'>".number_format($tpy1['amount'],2,'.','')."</td></tr>

</table>";


}


echo"<br /><center><b>Today's Follow Up - ".date('d-m-Y')."</b></center>";

echo"<br /><table style='width:90%; margin:auto;'>
<tr><td><table id='example' class='table table-bordered table-condensed' style='font-size:12px;'>
<thead><tr><th>Customer</th><th>District</th><th>Crop</th><th>Mobile</th><th>Time</th><th style='width:15%;'>Last Remarks</th><th style='width:15%;'>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)
{
$exct=0;
}
else
{
	
	$empd=mysql_query("select * from employee where username='$user'");
	$empd1=mysql_fetch_array($empd);

	$usr=$empd1['ID'];
	
	$exct=$usr;
}

$ddt="'".$date."'";

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


echo"<br /><center><table style='width:90%;'><tr>
<td style='width:25%;'></td>
<td style='width:50%; text-align:center;'><b>Today Order Confirmed - ".date('d-m-Y')."</b></td>
<td style='width:25%; text-align:center;'><a href='printorderconfirmed.php' target='_blank'><button type='submit' class='btn btn-sm btn-primary'>Print</button></a></td></tr></table></center><br />";

$date=date('Y-m-d');

echo"<table style='width:90%; margin:auto;'>
<tr><td><table id='dynamic-table1' class='table table-bordered table-condensed' style='font-size:12px;'>
<thead><tr><th>Customer</th><th>District</th><th>Crop</th>
<th>Mobile</th><th>Executive</th><th>Rate</th><th>Order Value</th><th>View</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)
{
$getr=mysql_query("select * from followup where date='$date' and status='Confirmed'");
}
else
{

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

$usr=$empd1['ID'];

$getr=mysql_query("select * from followup where date='$date' and executive='$usr' and status='Confirmed'");
}

while($getr1=mysql_fetch_array($getr))
{
	
	$cust=mysql_query("select * from crm_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);
	
	$sl=mysql_query("select *,sum(total) as total from sales_order where orderno='$getr1[salesorderno]'");
	$sl1=mysql_fetch_array($sl);

        $dis=mysql_query("select * from districts where ID='$cust1[district]'");
	$dis1=mysql_fetch_array($dis);
	
	echo"<tr><td>".$cust1['name']."</td><td>".$dis1['district']."</td><td>".$cust1['cultivatingcrop']."</td>
	
	<td>".$cust1['mobile']."</td>

	<td>".$exec1['name']."</td>
	
	<td style='text-align:right;'>".$sl1['rate']."</td>
	
	<td style='text-align:right;'>".$sl1['total']."</td>
	
	<td><a href='viewsalesorder.php?id=".$getr1['salesorderno']."'>View</a></td></tr>";

}

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



echo"<br /><center><b>New Customers - ".date('d-m-Y')."</b></center><br />";

$date=date('Y-m-d');

echo"<table style='width:90%; margin:auto;'>
<tr><td><table id='dynamic-table2' class='table table-bordered table-condensed' style='font-size:12px;'>
<thead><tr><th>Customer</th><th>Taluk</th><th>District</th><th>Crop</th><th>Mobile</th>
<th>Executive</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)
{
$getr=mysql_query("select * from crm_customer where date='$date'");
}
else
{

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

$usr=$empd1['ID'];

$getr=mysql_query("select * from crm_customer where date='$date' and executive='$usr'");
}

while($getr1=mysql_fetch_array($getr))
{
	
	$exec=mysql_query("select * from employee where ID='$getr1[executive]'");
	$exec1=mysql_fetch_array($exec);
	
	$dis=mysql_query("select * from districts where ID='$getr1[district]'");
	$dis1=mysql_fetch_array($dis);
	
	$tlk=mysql_query("select * from taluk where ID='$getr1[taluk]'");
	$tlk1=mysql_fetch_array($tlk);
	
	echo"<tr><td>".$getr1['name']."</td>
	
	<td>".$dis1['district']."</td>
	
	<td>".$tlk1['taluk']."</td>
	
	<td>".$getr1['cultivatingcrop']."</td>

	<td>".$getr1['mobile']."</td>
	
	<td>".$exec1['name']."</td></tr>";
	
}

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


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

if($nmrw>0)
{

echo"<br /><center><b>Today Sales - ".date('d-m-Y')."</b></center><br />";

$date=date('Y-m-d');

echo"<table style='width:90%; margin:auto;'>
<tr><td><table id='dynamic-table3' class='table table-bordered table-condensed' style='font-size:12px;'>
<thead><tr><th>Invoice No.</th><th>Customer</th><th>Taluk</th><th>Distirct</th>
<th>Mobile</th><th>Executive</th><th>Amount</th></tr></thead>";

$getr=mysql_query("select *,sum(total) as total from invoice where date='$date' group by invoiceno");
while($getr1=mysql_fetch_array($getr))
{
	
	$exec=mysql_query("select * from employee where ID='$getr1[executive]'");
	$exec1=mysql_fetch_array($exec);
	
	$dis=mysql_query("select * from districts where ID='$getr1[district]'");
	$dis1=mysql_fetch_array($dis);
	
	$cus=mysql_query("select * from customer where ID='$getr1[customer]'");
	$cus1=mysql_fetch_array($cus);
	
	$tlk=mysql_query("select * from taluk where ID='$getr1[taluk]'");
	$tlk1=mysql_fetch_array($tlk);
	
	echo"<tr><td>".$getr1['invno']."</td>
	
	<td>".$cus1['name']."</td>
	
	<td>".$tlk1['taluk']."</td>
	
	<td>".$dis1['district']."</td>

	<td>".$cus1['mobile']."</td>
	
	<td>".$exec1['name']."</td>
	
	<td>".$getr1['total']."</td></tr>";
	
}

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


}

?>



                                <table style="margin:10% auto auto auto;">

                                <tr><td><img src="assets/images/logo.png" style="width:180px;" /></td><td valign="middle"><b style="font-size:21px; color:#06C; text-transform:uppercase;"><?php echo $compname; ?></b></td></tr>

                                </table>


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

		var nmrw=<?php echo $nmrw; ?>;
		var date=<?php echo $ddt; ?>;
		var exct=<?php echo $exct; ?>;
		
		$(document).ready(function() {
			$('#example').dataTable( {
				"processing": true,
				"serverSide": true,
				"ajax": "dailyfollowupserver.php?exct="+ exct +"&date="+ date +"&nmrw="+ nmrw,
				"language": {
                    "processing": '<i class="fa fa-spinner fa-spin" style="font-size:24px;color:rgb(75, 183, 245);"></i>'
                 }
			} );
		} );

</script>


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

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


<?php

include 'bottom.php';

}
else
{

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


?>