<?php
include('conexao.php');
session_start();

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	
if(isset($_COOKIE['login']) && ($_COOKIE['login']<>""))
{
$login_cookie = $_COOKIE['login']; 
$sql = mysqli_query($mysqli,"SELECT * FROM login where login like '$login_cookie'");
$linha = mysqli_fetch_array($sql);
$Nome				= $linha["funcionario"];
}
?>
<!doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>SiGA</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/css/milligram/milligram.min.css">
  <link rel="stylesheet" href="assets/css/omega.css">
  <link rel="stylesheet" href="assets/css/style.css">
  
</head>
<body id="app">
<?php include("menu.php"); 	?> 
<main>
    <section>
	Ol&aacute;: <?php echo $Nome;?>
</section>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Receita</span>Cobrada por si</p>
<div class="bloc">
<div class="bloc--content">
<p>

	<?php 
			$ano = date('Y');
			$data = date('Y-m-d');
			$driver0 = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtodrivers WHERE agente = '$Nome' and datapagto = '$data'") or die(mysql_error());
			$rdriver0 = mysqli_fetch_array($driver0);$d0=$rdriver0['pagto'];
			$drivernr0 = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtodriversnregisted WHERE agente = '$Nome' and datapagto = '$data'") or die(mysql_error());
			$rdrivernr0 = mysqli_fetch_array($drivernr0);$dnr0=$rdrivernr0['pagto'];
			$vend0 = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtomresgistado WHERE agente = '$Nome' and datapagto = '$data'") or die(mysql_error());
			$rvend0 = mysqli_fetch_array($vend0);$v0=$rvend0['pagto'];
			$amb0 = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtonresgistado WHERE agente = '$Nome' and datapagto = '$data'") or die(mysql_error());
			$ramb0 = mysqli_fetch_array($amb0); $a0=$ramb0['pagto'];
			?>
	<h4 align="center">Total da receita por si cobrada hoje</h4>
	<table width="100%" class="table table-striped table-hover" id="dataTables-example">
		<thead>
			<tr style="background-Color: #EEEEEE;">
				<th>Descrição </th>
				<th>Valor</th>
			</tr>
		</thead>
		<tbody>
		
			<tr>
				<td>[1] Receita de mercados</td>
				<td align="right"><?php echo number_format($v0, 2); ?></td>
			</tr>
			<tr>
				<td>[2] Receita de ambulantes</td>
				<td align="right"><?php echo number_format($a0, 2); ?></td>
			</tr>
			<tr>
				<td>[3] Receita de Transportadores</td>
				<td align="right"><?php echo number_format($dnr0, 2); ?></td>
			</tr>
			<tr style="background-Color: #FAF0E6;">
				<td>Total da Receita do dia</td>
				<td align="right"><b><?php $totaldiario = ($d0+$dnr0+$v0+$a0); echo number_format($totaldiario, 2); ?></b></td>
			</tr>
		</tbody>
	</table>
	
		<?php 
			$ano = date('Y');
			
			$driver = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtodrivers WHERE ano = $ano and agente = '$Nome'") or die(mysql_error());
			$rdriver = mysqli_fetch_array($driver);$d=$rdriver['pagto'];
			$drivernr = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtodriversnregisted WHERE ano = $ano and agente = '$Nome'") or die(mysql_error());
			$rdrivernr = mysqli_fetch_array($drivernr);$dnr=$rdrivernr['pagto'];
			$vend = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtomresgistado WHERE ano = $ano and agente = '$Nome'") or die(mysql_error());
			$rvend = mysqli_fetch_array($vend);$v=$rvend['pagto'];
			$amb = mysqli_query($mysqli,"SELECT SUM(pago) as pagto FROM pagtonresgistado WHERE ano = $ano and agente = '$Nome'") or die(mysql_error());
			$ramb = mysqli_fetch_array($amb); $a=$ramb['pagto'];
			?>
			
		<br><br><br>
	 <h4 style="color: blue;" align="center">Total da receita por si cobrada durante as <?php echo date('W');?> semanas de <?php echo date('Y');?></h2>
	
	<table width="100%" class="table table-striped table-hover" id="dataTables-example">
		<thead>
			<tr style="background-Color: #EEEEEE;">
				<th>Descrição </th>
				<th>Valor</th>
			</tr>
		</thead>
		<tbody>
		
			<tr>
				<td>[1] Receita de mercados</td>
				<td align="right"><?php echo number_format($v, 2); ?></td>
			</tr>
			<tr>
				<td>[2] Receita de ambulantes</td>
				<td align="right"><?php echo number_format($a, 2); ?></td>
			</tr>
			<tr>
				<td>[3] Receita de Transportadores</td>
				<td align="right"><?php echo number_format($dnr, 2); ?></td>
			</tr>
			<tr style="background-Color: #FAF0E6;">
				<td>Tota da Receita durante o ano</td>
				<td align="right"><b><?php $total = ($d+$dnr+$v+$a); echo number_format($total, 2); ?></b></td>
			</tr>
		</tbody>
	</table>
	</p>
	
</div>
</div>
</main>
<footer>
  2019 <strong>acliven</strong> - <a href="https://www.acliven.it">www.acliven.it</a>
</footer>
<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>
<script src="assets/js/omega.js"></script>
</body>
</html>