<!DOCTYPE html>
<html lang="en">

<?php
Include("../includes/con_cliente.php");

//Include ROOT_PATH . '/includes/con_cliente.php';

 require_once('../connection.php');
    session_start();

    if(isset($_SESSION['User']))
    {
        $query="select * from tbusuario where nomeuser='".$_SESSION['User']."'";
        $result=mysqli_query($con,$query);
        $resultado = mysqli_fetch_assoc($result);
        $r_resultado = $resultado;
    }
    else
    {
        header("location:index.php");
    }

    $result_orchoje = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE `dtOrcamento` = date(now())";
    $resultado_orchoje = mysqli_query($con,$result_orchoje);
    $row_orchoje = mysqli_fetch_assoc($resultado_orchoje);

    $result_orcmes = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW())";
    $resultado_orcmes = mysqli_query($con,$result_orcmes);
    $row_orcmes = mysqli_fetch_assoc($resultado_orcmes);

    //$result_orcmesm = "SELECT avg(dias) as Media FROM (SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW()))teste";
    $result_orcmesm = "SELECT COUNT(DISTINCT(`dtOrcamento`)) AS DIAS FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW())";
    $resultado_orcmesm = mysqli_query($con,$result_orcmesm);
    $row_orcmesm = mysqli_fetch_assoc($resultado_orcmesm);

    $result_vlrorca = "SELECT sum(`vlrOrcado`) AS vlr FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW())";
    $resultado_vlrorca = mysqli_query($con,$result_vlrorca);
    $row_vlrorca = mysqli_fetch_assoc($resultado_vlrorca);




    $result_vlrfat = "SELECT `situacao`, SUM(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='faturado'))";
    $resultado_vlrfat = mysqli_query($con,$result_vlrfat);
    $row_vlrfat = mysqli_fetch_assoc($resultado_vlrfat);

    $result_vlrvencer = "SELECT `situacao`, SUM(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='A vencer'))";
    $resultado_vlrvencer = mysqli_query($con,$result_vlrvencer);
    $row_vlrvencer = mysqli_fetch_assoc($resultado_vlrvencer);

    $result_vlrpos = "SELECT `situacao`, SUM(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by motivoRepro HAVING (((motivoRepro)='POS CIRURGICO'))";
    $resultado_vlrpos = mysqli_query($con,$result_vlrpos);
    $row_vlrpos = mysqli_fetch_assoc($resultado_vlrpos);

    $result_vlrautor = "SELECT `situacao`, SUM(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='Aprovado'))";
    $resultado_vlrautor = mysqli_query($con,$result_vlrautor);
    $row_vlrautor = mysqli_fetch_assoc($resultado_vlrautor);


    $result_vlrreprov = "SELECT `situacao`, SUM(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='Reprovad'))";
    $resultado_vlrreprov = mysqli_query($con,$result_vlrreprov);
    $row_vlrreprov = mysqli_fetch_assoc($resultado_vlrreprov);





    $result_qtdfat = "SELECT `situacao`, COUNT(`vlrOrcado`) as QTD from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='faturado'))";
    $resultado_qtdfat = mysqli_query($con,$result_qtdfat);
    $row_qtdfat = mysqli_fetch_assoc($resultado_qtdfat);

    $result_qtdvencer = "SELECT `situacao`, COUNT(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='A vencer'))";
    $resultado_qtdvencer = mysqli_query($con,$result_qtdvencer);
    $row_qtdvencer = mysqli_fetch_assoc($resultado_qtdvencer);

    $result_qtdpos = "SELECT `situacao`, COUNT(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by motivoRepro HAVING (((motivoRepro)='POS CIRURGICO'))";
    $resultado_qtdpos = mysqli_query($con,$result_qtdpos);
    $row_qtdpos = mysqli_fetch_assoc($resultado_qtdpos);

    $result_qtdautor = "SELECT `situacao`, COUNT(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='Aprovado'))";
    $resultado_qtdautor = mysqli_query($con,$result_qtdautor);
    $row_qtdautor = mysqli_fetch_assoc($resultado_qtdautor);


    $result_qtdreprov = "SELECT `situacao`, COUNT(`vlrOrcado`) as Valor from tborcamentocirurgia GROUP by situacao HAVING (((situacao)='Reprovad'))";
    $resultado_qtdreprov = mysqli_query($con,$result_qtdreprov);
    $row_qtdreprov = mysqli_fetch_assoc($resultado_qtdreprov);


    $result_mAprov = "SELECT avg(dias) as Media FROM (SELECT nrorc, TIMESTAMPDIFF(DAY,dtOrcamento,dtAprovacao) AS Dias FROM tborcamentocirurgia WHERE situacao = 'Aprovado')teste";
    $resultado_mAprov = mysqli_query($con,$result_mAprov);
    $row_mAprov = mysqli_fetch_assoc($resultado_mAprov);



?>
<head>


  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Controle SCA">
  <meta name="author" content="Fabio Freitas">

  <title>SCA - Acompanhamento de Orçamentos</title>

  <!-- Bootstrap core CSS -->
  <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!--<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">-->

  <!-- Custom styles for this template -->
  <link href="../css/simple-sidebar.css" rel="stylesheet">

</head>

<body>
    <div class="d-flex" id="wrapper">
        <!-- Sidebar -->
        <div class="bg-light border-right" id="sidebar-wrapper">
          <div class="sidebar-heading">SCA - Orçamentos </div>
          <div class="list-group list-group-flush">
            <a href="#" class="list-group-item list-group-item-action bg-light">Dashboard</a>
            <a href="apontorcamento.php" class="list-group-item list-group-item-action bg-light">Apontamentos</a>
            <a href="#" class="list-group-item list-group-item-action bg-light">Workflow</a>
            <!--<a href="#" class="list-group-item list-group-item-action bg-light">Events</a>
            <a href="#" class="list-group-item list-group-item-action bg-light">Profile</a>
            <a href="#" class="list-group-item list-group-item-action bg-light">Status</a> -->
          </div>
        </div>
    </div>
    <div id="page-content-wrapper">
        <nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
        <button class="btn btn-primary" id="menu-toggle">Ocultar Menu</button>

        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav ml-auto mt-2 mt-lg-0">
            <li class="nav-item active">
              <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Link</a>
            </li>
           <!-- <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Dropdown
              </a>
              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Something else here</a>
              </div> 
            </li>-->
          </ul>
        </div>
      </nav>
    </div>
<script src="../vendor/jquery/jquery.min.js"></script>
  <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Menu Toggle Script -->
  <script>
    $("#menu-toggle").click(function(e) {
      e.preventDefault();
      $("#wrapper").toggleClass("toggled");
    });
  </script>
</body>
</html>



