<?php
    Include("../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");
    }


    //Orçadas --------------------------
    $result_orchoje = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE `dtOrcamento` = date(now())-1";
    $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 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);


    //Autorizadas -----------------------

    $result_autchoje = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA' AND `dtOrcamento` = date(now())";
    $resultado_autchoje = mysqli_query($con,$result_autchoje);
    $row_autchoje = mysqli_fetch_assoc($resultado_autchoje);

    $result_autmesm = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA' and MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW())";
    $resultado_autmesm = mysqli_query($con,$result_autmesm);
    $row_autmesm = mysqli_fetch_assoc($resultado_autmesm);

    $result_auttot = "SELECT COUNT(`nrorc`) AS qtd FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA'";
    $resultado_auttot = mysqli_query($con,$result_auttot);
    $row_auttot = mysqli_fetch_assoc($resultado_auttot);

    $result_auttotvlr = "SELECT SUM(`vlrOrcado`) AS vlr FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA'";
    $resultado_auttotvlr = mysqli_query($con,$result_auttotvlr);
    $row_auttotvlr = mysqli_fetch_assoc($resultado_auttotvlr);

    //Pós-Cirúrgicos -----------------------

    $result_poschoje = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE `motivoRepro` = 'POS CIRURGICO' AND `dtOrcamento` = date(now())";
    $resultado_poschoje = mysqli_query($con,$result_poschoje);
    $row_poschoje = mysqli_fetch_assoc($resultado_poschoje);

    $result_posmesm = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE `motivoRepro` = 'POS CIRURGICO' and MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW())";
    $resultado_posmesm = mysqli_query($con,$result_posmesm);
    $row_posmesm = mysqli_fetch_assoc($resultado_posmesm);

    $result_postot = "SELECT COUNT(`nrorc`) AS qtd FROM tborcamentocirurgia WHERE `motivoRepro` = 'POS CIRURGICO'";
    $resultado_postot = mysqli_query($con,$result_postot);
    $row_postot = mysqli_fetch_assoc($resultado_postot);

    $result_postotvlr = "SELECT SUM(`vlrOrcado`) AS vlr FROM tborcamentocirurgia WHERE `motivoRepro` = 'POS CIRURGICO'";
    $resultado_postotvlr = mysqli_query($con,$result_postotvlr);
    $row_postotvlr = mysqli_fetch_assoc($resultado_postotvlr);

    $result_pos30 = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 30 AND`motivoRepro` like 'POS%'";
    $resultado_pos30 = mysqli_query($con,$result_pos30);
    $row_pos30 = mysqli_fetch_assoc($resultado_pos30);

    $result_pos60 = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 30 AND TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 60 AND`motivoRepro` like 'POS%'";
    $resultado_pos60 = mysqli_query($con,$result_pos60);
    $row_pos60 = mysqli_fetch_assoc($resultado_pos60);

    $result_pos90 = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 60 AND TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 90 AND`motivoRepro` like 'POS%'";
    $resultado_pos90 = mysqli_query($con,$result_pos90);
    $row_pos90 = mysqli_fetch_assoc($resultado_pos90);

    $result_posmais = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 90 AND`motivoRepro` like 'POS%'";
    $resultado_posmais = mysqli_query($con,$result_posmais);
    $row_posmais = mysqli_fetch_assoc($resultado_posmais);


     //Faturado -----------------------

    $result_fathoje = "SELECT COUNT(`nrorc`) AS QTD FROM tborcamentocirurgia WHERE `situacao` = 'Faturado' AND `dtOrcamento` = date(now())-1";
    $resultado_fathoje = mysqli_query($con,$result_fathoje);
    $row_fathoje = mysqli_fetch_assoc($resultado_fathoje);
    
    $result_fatmesm = "SELECT COUNT(`nrorc`) AS DIAS FROM tborcamentocirurgia  WHERE `situacao` = 'Faturado' and MONTH(`dtAprovacao`) = MONTH(NOW()) AND YEAR(`dtAprovacao`) = YEAR(NOW())";
    $resultado_fatmesm = mysqli_query($con,$result_fatmesm);
    $row_fatmesm = mysqli_fetch_assoc($resultado_fatmesm);

    $result_fattotvlr = "SELECT SUM(`vlrOrcado`) AS vlr FROM tborcamentocirurgia WHERE `situacao` = 'Faturado' and MONTH(`dtAprovacao`) = MONTH(NOW()) AND YEAR(`dtAprovacao`) = YEAR(NOW())";
    $resultado_fattotvlr = mysqli_query($con,$result_fattotvlr);
    $row_fattotvlr = mysqli_fetch_assoc($resultado_fattotvlr);


 ?>

<!DOCTYPE html>
<html lang="pt-br">


<head>

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

  <title>SCA - Orçamentos - Ajumed </title>

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

  <!-- Custom styles for this template -->
  <link href="../css/simple-sidebar.css" rel="stylesheet">
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="../css/style.css">
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
  <script src="../js/jquery-latest.js"></script>
  <script src="../js/jquery.tablesorter.min.js"></script>
  <script src="../js/scripts.js"></script>


</head>

<body>

  <nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
    <button class="btn btn-primary btn-sm my-2 my-sm-0">
                <a href="../dashboards/menuorcamento.php" style="color:inherit"> Voltar </a></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="../m.php">Home <span class="sr-only">(current)</span></a>
        </li>
      </ul>
    </div>
  </nav>

   <script>
        function Mudarestado(el) {
          var display = document.getElementById(el).style.display;
          if(display == "none")
              document.getElementById(el).style.display = 'block';
          else
              document.getElementById(el).style.display = 'none';
        }

      </script>


  <div>
    <h1 class="mt-4">Ajumed - <?php echo date('d/m/yy') . '<br />';?></h1>
    <div class="card-deck">
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-primary shadow h-100 py-2">
              <div class="card-body">
                <div class="row no-gutters align-items-center">
                  <div class="col mr-2">
                    <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Orçamentos</div>
                    <!--<div class="h5 mb-0 font-weight-bold text-gray-800">R$ Total = <?php echo number_format(($row_vlrfat['Valor']),2, ',', '.'); ?></div> -->
                    <div class="h6 mb-0 font-weight-bold text-gray-800">Cotados no Dia = <?php echo $row_orchoje['QTD']; ?></div>
                    <div class="h6 mb-0 font-weight text-gray-800">Cotados no Mês = <?php echo $row_orcmes['QTD']; ?></div>
                    <div class="h6 mb-0 font-weight text-gray-800">Dias com Cotações = <?php echo number_format($row_orcmesm['DIAS']);?></div>
                    <div class="h6 mb-0 font-weight text-gray-800">Média de Cotações = <?php echo number_format($row_orcmes['QTD'] / number_format($row_orcmesm['DIAS']),2, ',', '.') ?></div>
                    <div class="h6 mb-0 font-weight text-gray-800" style="margin-top: 10px">Total Cotado Mês R$ = <?php echo number_format(($row_vlrorca['vlr']),2, ',', '.') ?></div>
                    <div class="h6 mb-0 font-weight text-gray-800" style="margin-top: 10px">Qtd Negociado Mês =</div>
                    <div class="h6 mb-0 font-weight text-gray-800">Qtd Reprovado Mês =</div>
                  </div>
                </div>
              </div>
              <div class="card-footer bg-transparent">
                <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#modalExemplo">Detalhes</button>
                <button type="button" class="btn btn-outline-primary btn-sm" onclick="Mudarestado('realizadas'),Mudarestado('teste') ">Gráficos</button>
                <div class="h6 mb-0 font-italic text-gray-800" style="margin-top: 1rem">Dados até dia <?php echo date('d/m/y')-1 . '<br />';?></div>
              </div>
            </div>

            <!-- Modal -->
            <div class="modal fade" id="modalExemplo" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos do Mês Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT *,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW()) AND YEAR(`dtOrcamento`) = YEAR(NOW()) ORDER BY `planoSaude`");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>


        </div>
        <div class="col-xl-3 col-md-6 mb-4">
          <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
              <div class="row no-gutters align-items-center">
                <div class="col mr-2">
                  <div class="text-xs font-weight-bold text-info text-uppercase mb-1">Autorizados</div>
                  <div class="h6 mb-0 font-weight-bold text-gray-800">Autorizados no Dia = <?php echo $row_autchoje['QTD']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Autorizados no Mês = <?php echo $row_autmesm['DIAS']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Autorizados Qtd Total = <?php echo $row_auttot['qtd']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Vendedor 01 = <?php echo $row_auttot['qtd']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800" style="margin-top: 1rem">Aut. Aguard. Cirurg. Total R$ = <?php echo number_format(($row_auttotvlr['vlr']),2, ',', '.'); ?></div>

                </div>
              </div>
            </div>
            <div class="card-footer bg-transparent">
              <button type="button" class="btn btn-outline-info btn-sm" data-toggle="modal" data-target="#modalRealizado">Detalhes</button>
              <button type="button" class="btn btn-outline-info btn-sm" onclick="Mudarestado('autorizadas'),Mudarestado('teste1') ">Gráficos</button>
              <div class="h6 mb-0 font-italic text-gray-800" style="margin-top: 1rem">Dados até dia <?php echo date('d/m/y')-1 . '<br />';?></div>
            </div>
          </div>

          <!-- Modal Realizados -->

            <div class="modal fade" id="modalRealizado" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos Autorizados Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT *,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA' ORDER BY `planoSaude`");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>



        </div>
         <div class="col-xl-3 col-md-6 mb-4">
          <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
              <div class="row no-gutters align-items-center">
                <div class="col mr-2">
                  <div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Pós-Cirúrgicos</div>
                  <div class="h6 mb-0 font-weight-bold text-gray-800">Pós no Dia = <?php echo $row_poschoje['QTD']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Pós no Mês = <?php echo $row_posmesm['DIAS']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Pós Qtd Total = <?php echo $row_postot['qtd']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800"style="margin-top: 1rem">Pós Total R$ = <?php echo number_format(($row_postotvlr['vlr']),2, ',', '.'); ?></div>
				  <!--<div class="h6 mb-0 font-weight text-gray-800" style="color:#008000">Em Aberto com &ensp;30 dias = <?php echo $row_pos30['DIAS']; ?></div> -->
                  <div class="h6 mb-0 font-weight text-gray-800"style="margin-top: 1rem"><a data-toggle="modal" href="#modalPos30" style="color:#008000">Em Aberto com &ensp;30 dias = <?php echo $row_pos30['DIAS']; ?>	</a>
                  </div>
                  <div class="h6 mb-0 font-weight text-gray-800" ><a data-toggle="modal" href="#modalPos60" style="color:#FF7F50">Em Aberto com &ensp;60 dias = <?php echo $row_pos60['DIAS']; ?></a></div>
                  <div class="h6 mb-0 font-weight text-gray-800"><a data-toggle="modal" href="#modalPos90" style="color:#FF0000">Em Aberto com &ensp;90 dias = <?php echo $row_pos90['DIAS']; ?></a></div>
                  <div class="h6 mb-0 font-weight text-gray-800" ><a data-toggle="modal" href="#modalPos90M" style="color:#8B008B">Em Aberto mais &ensp;90 dias = <?php echo $row_posmais['DIAS']; ?></a></div>
                </div>
              </div>
            </div>
            <div class="card-footer bg-transparent">
              <button type="button" class="btn btn-outline-danger btn-sm" data-toggle="modal" data-target="#modalPos">Detalhes</button>
              <button type="button" class="btn btn-outline-danger btn-sm" onclick="Mudarestado('POS'),Mudarestado('teste2') ">Gráficos</button>
              <div class="h6 mb-0 font-italic text-gray-800" style="margin-top: 1rem">Dados até dia <?php echo date('d/m/y')-1 . '<br />';?></div>
            </div>

            <!-- Modal Realizados -->

            <div class="modal fade" id="modalPos" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos em Pós-Cirurgicos (total) Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT *,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE `motivoRepro` like 'POS%' ORDER BY `planoSaude`");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>
            
            <!-- MODAL POS30---->

            <div class="modal fade" id="modalPos30" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos em Pós-Cirurgicos (Até 30 Dias) Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT `nrorc`,`dtOrcamento`,`dtCirurgia`,`planoSaude`,`cliente`,`hospital`,`medico`,`paciente`,`vlrOrcado`,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 30 AND`motivoRepro` like 'POS%'");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>

            <!-- MODAL POS60---->

            <div class="modal fade" id="modalPos60" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos em Pós-Cirurgicos (Até 60 Dias) Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT `nrorc`,`dtOrcamento`,`dtCirurgia`,`planoSaude`,`cliente`,`hospital`,`medico`,`paciente`,`vlrOrcado`,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 30 AND TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 60 AND`motivoRepro` like 'POS%'");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>

            <!-- MODAL POS90---->

              <div class="modal fade" id="modalPos90" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos em Pós-Cirurgicos (Até 90 Dias) Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT `nrorc`,`dtOrcamento`,`dtCirurgia`,`planoSaude`,`cliente`,`hospital`,`medico`,`paciente`,`vlrOrcado`,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 60 AND TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) <= 90 AND`motivoRepro` like 'POS%'");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>

            <!-- MODAL POS90 Mais---->
              
              <div class="modal fade" id="modalPos90M" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos em Pós-Cirurgicos (Mais de 90 Dias) Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT `nrorc`,`dtOrcamento`,`dtCirurgia`,`planoSaude`,`cliente`,`hospital`,`medico`,`paciente`,`vlrOrcado`,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE TIMESTAMPDIFF(DAY,dtOrcamento,NOW()) > 90 AND`motivoRepro` like 'POS%'");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>




          </div>
        </div>
        <div class="col-xl-3 col-md-6 mb-4">
          <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
              <div class="row no-gutters align-items-center">
                <div class="col mr-2">
                  <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">Faturamento</div>
                  <div class="h6 mb-0 font-weight-bold text-gray-800">Orc. Aprovados no Dia = <?php echo $row_fathoje['QTD']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800">Orc. Aprovados no Mês = <?php echo $row_fatmesm['DIAS']; ?></div>
                  <div class="h6 mb-0 font-weight text-gray-800"style="margin-top: 1rem">Total de Orc. Aprov. no Mês R$ = <?php echo number_format(($row_fattotvlr['vlr']),2, ',', '.'); ?></div>
                </div>
              </div>
            </div>
            <div class="card-footer bg-transparent">
              <button type="button" class="btn btn-outline-warning btn-sm" data-toggle="modal" data-target="#modalFaturados">Detalhes</button>
              <button type="button" class="btn btn-outline-warning btn-sm" onclick="Mudarestado('Lib'),Mudarestado('teste3') ">Gráficos</button>
              <div class="h6 mb-0 font-italic text-gray-800" style="margin-top: 1rem">Dados até dia <?php echo date('d/m/y')-1 . '<br />';?></div>
            </div>

            <!-- Modal Realizados -->

            <div class="modal fade" id="modalFaturados" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
              <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Orçamentos Liberados para Faturamento no Mês - Ajumed</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <?php
                        $connect = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
                        if(mysqli_connect_errno($connect)){
                        echo 'Falha ao conectar com o Banco de Dados !'.mysqli_connect_error();}


                        $result= mysqli_query($connect, "SELECT *,TIMESTAMPDIFF(DAY,`dtOrcamento`,NOW()) AS Dias FROM tborcamentocirurgia WHERE `situacao` = 'Faturado' and MONTH(`dtAprovacao`) = MONTH(NOW()) AND YEAR(`dtAprovacao`) = YEAR(NOW()) ORDER BY `planoSaude`");
                    ?>
                    <div class="table-responsive">
                            <!--<table style="font-size: 9px;" class="table table-striped table-bordered table-hover table-condensed"> -->
                            <table style="font-size: 10px; overflow: auto; font-color:#0000FF; " class="tablesorter table-striped table-responsive-md btn-table table-hover table-bordered">
                                <thead>
                                    <tr>
                                       <!-- <th>Id</th> -->
                                        <th>Orç.</th>
                                        <th>Dt.Orçamento</th>
                                        <th>Dt.Cirurgia</th>
                                        <th>Convênio</th>
                                        <th>Cliente</th>
                                        <th>Hospital</th>
                                        <th>Médico</th>
                                        <th>Paciente</th>
                                        <th>R$ Orçado</th>
                                        <th>Dias</th>

                                    </tr>
                                </thead>
                                <?php while($rows = mysqli_fetch_array($result)): ?>

                                <tr>
                                   <!-- <td style="width: 30px;"><?php echo $rows['id']; ?></td> -->
                                    <!--<td style="text-align: center;vertical-align:middle"><?php echo date ("d/m/y", strtotime($rows['data'])); ?></td> -->
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['nrorc']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtOrcamento'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo date("d/m/y",strtotime($rows['dtCirurgia'])); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['planoSaude']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['cliente']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['hospital']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['medico']; ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['paciente']; ?></td>
                                    <td style="text-align: right;vertical-align:middle"><?php echo number_format(($rows['vlrOrcado']),2, ',', '.'); ?></td>
                                    <td style="text-align: center;vertical-align:middle"><?php echo $rows['Dias']; ?></td>
                                </tr>
                                <?php endwhile; ?>
                            </table>
                           
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                  </div>
                </div>
              </div>
            </div>


          </div>
        </div>

      </div>

<!---Grárico ORÇAMENTOS -->
      <?php
        $connect1 = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
        $query1 =  "SELECT `planoSaude`, sum(`vlrOrcado`) as valor, count(nrorc) as qtd  FROM tborcamentocirurgia WHERE MONTH(`dtOrcamento`) = MONTH(NOW())  AND YEAR(`dtOrcamento`) = YEAR(NOW()) GROUP BY `planoSaude` ORDER BY valor desc";
        $result1= mysqli_query($connect1,$query1);
        $chart_data = '';
         while ($row = mysqli_fetch_array($result1)) 
         {
           $data[] = array(
            'label'     =>    $row["planoSaude"],
            'value'     =>    $row["valor"],
            'qtd'       =>    $row["qtd"]
           );
         }
         $chart_data = substr($chart_data,0, -2);
         $data = json_encode($data);
      ?>
      <h4 class="container text-center" id="teste"> Orçamentos Realizados no Mês R$</h4>
      <div class="container" id="realizadas" style="height: 250px;">
        <script type="text/javascript">
          Morris.Bar
            ({
              element: 'realizadas',
              data: <?php echo $data; ?>,
              xkey: 'label',
              ykeys: ['value','qtd'],
              labels: ['Orçado', 'Qtd'],
              resize: true
            });
        </script>
      </div>

      <!---Grárico AUTORIZADOS -->
      <?php
        $connect2 = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
        $query2 =  "SELECT `planoSaude`, sum(`vlrOrcado`) as valor, count(nrorc) as qtd  FROM tborcamentocirurgia WHERE `motivoRepro` = 'AUTORIZADO AGUARDANDO CIRURGIA' GROUP BY `planoSaude` ORDER BY valor desc";
        $result2= mysqli_query($connect2,$query2);
        $chart_data2 = '';
         while ($row2 = mysqli_fetch_array($result2)) 
         {
           $data2[] = array(
            'label2'     =>    $row2["planoSaude"],
            'value2'     =>    $row2["valor"],
            'qtd2'       =>    $row2["qtd"]
           );
         }
         $chart_data2 = substr($chart_data2,0, -2);
         $data2 = json_encode($data2);
      ?>
      <h4 class="container text-center" id="teste1"> Orçamentos Autorizados Total R$</h4>
      <div class="container" id="autorizadas" style="height: 250px;">
        <script type="text/javascript">
          Morris.Bar
            ({
              element: 'autorizadas',
              data: <?php echo $data2; ?>,
              xkey: 'label2',
              ykeys: ['value2','qtd2'],
              labels: ['Autorizado', 'Qtd'],
              resize: true,
              barColors: ['#20B2AA']
            });
        </script>
      </div>

      <!---Grárico POS -->
      <?php
        $connect3 = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
        $query3 =  "SELECT cliente, sum(`vlrOrcado`) as valor, count(nrorc) as qtd  FROM tborcamentocirurgia WHERE `motivoRepro` = 'POS CIRURGICO' GROUP BY `cliente` ORDER BY valor desc";
        $result3= mysqli_query($connect3,$query3);
        $chart_data3 = '';
         while ($row3 = mysqli_fetch_array($result3)) 
         {
           $data3[] = array(
            'label3'     =>    $row3["cliente"],
            'value3'     =>    $row3["valor"],
            'qtd3'       =>    $row3["qtd"]
           );
         }
         $chart_data3 = substr($chart_data3,0, -2);
         $data3 = json_encode($data3);
      ?>
      <h4 class="container text-center" id="teste2"> Orçamentos Pós-Cirúrgicos Total R$</h4>
      <div class="container" id="POS" style="height: 250px;">
        <script type="text/javascript">
          Morris.Bar
            ({
              element: 'POS',
              data: <?php echo $data3; ?>,
              xkey: 'label3',
              ykeys: ['value3','qtd3'],
              labels: ['PÓS', 'Qtd'],
              resize: true,
              barColors: ['#FF0000']
            });
        </script>
      </div>

      <!---Grárico Faturamento -->
      <?php
        $connect4 = mysqli_connect('127.0.0.1', 'root', 'fcf2778@', 'administrativo');
        $query4 =  "SELECT `planoSaude`, sum(`vlrOrcado`) as valor, count(nrorc) as qtd  FROM tborcamentocirurgia WHERE `situacao` = 'Faturado' AND MONTH(`dtAprovacao`) = MONTH(NOW())  AND YEAR(`dtAprovacao`) = YEAR(NOW()) GROUP BY `planoSaude` ORDER BY valor desc";
        $result4= mysqli_query($connect4,$query4);
        $chart_data4 = '';
         while ($row4 = mysqli_fetch_array($result4)) 
         {
           $data4[] = array(
            'label4'     =>    $row4["planoSaude"],
            'value4'     =>    $row4["valor"],
            'qtd4'       =>    $row4["qtd"]
           );
         }
         $chart_data4 = substr($chart_data4,0, -2);
         $data4 = json_encode($data4);
      ?>
      <h4 class="container text-center" id="teste3"> Orçamentos Liberados para Faturamento no Mês R$</h4>
      <div class="container" id="Lib" style="height: 250px;">
        <script type="text/javascript">
          Morris.Bar
            ({
              element: 'Lib',
              data: <?php echo $data4; ?>,
              xkey: 'label4',
              ykeys: ['value4','qtd4'],
              labels: ['PÓS', 'Qtd'],
              resize: true,
              barColors: ['#FFA500']
            });
        </script>
      </div>



  </div>
      
</body>