<?php
    require_once('../connection.php');

    //Cirurgias Ajumed  --------------------------
    $result_cirhojeajumed = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE `Empresa` = 'AJUMED' AND MONTH(`DtCirurgia`) = MONTH(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirhojeajumed = mysqli_query($con,$result_cirhojeajumed);
    $row_cirhojeajumed = mysqli_fetch_assoc($resultado_cirhojeajumed);

    //Cirurgias Best CAre  --------------------------
    $result_cirhojebest = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE `Empresa` = 'BEST CARE' AND MONTH(`DtCirurgia`) = MONTH(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirhojebest = mysqli_query($con,$result_cirhojebest);
    $row_cirhojebest = mysqli_fetch_assoc($resultado_cirhojebest);

    //Cirurgias Brasil  --------------------------
    $result_cirhojebrasil = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE `Empresa` = 'BRASIL ORTOPEDIA' AND MONTH(`DtCirurgia`) = MONTH(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirhojebrasil = mysqli_query($con,$result_cirhojebrasil);
    $row_cirhojebrasil = mysqli_fetch_assoc($resultado_cirhojebrasil);

    //Cirurgias Orthomac  --------------------------
    $result_cirhojehorto = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE `Empresa` = 'ORTHOMAC' AND MONTH(`DtCirurgia`) = MONTH(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirhojehorto = mysqli_query($con,$result_cirhojehorto);
    $row_cirhojehorto= mysqli_fetch_assoc($resultado_cirhojehorto);

    //Cirurgias Grupo  --------------------------
    $result_cirhoje = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE MONTH(`DtCirurgia`) = MONTH(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirhoje = mysqli_query($con,$result_cirhoje);
    $row_cirhoje= mysqli_fetch_assoc($resultado_cirhoje);

    //Cirurgias Grupo Mes Anterior  --------------------------
    $result_cirmantes = "SELECT COUNT(`id`) AS QTD FROM tbcirurgias WHERE MONTH(`DtCirurgia`) = MONTH(NOW())-1 AND DAY(`DtCirurgia`)<= DAY(NOW()) AND YEAR(`DtCirurgia`) = YEAR(NOW())";
    $resultado_cirmantes = mysqli_query($con,$result_cirmantes);
    $row_cirmantes= mysqli_fetch_assoc($resultado_cirmantes);

    //Metas Cirurgias Mes Atual  --------------------------
    $result_metamesatual = "SELECT `Meta` FROM `tbmetacirurgia` WHERE `Mes` = MONTH(NOW()) and `Ano`= YEAR(NOW())";
    $resultado_metamesatual = mysqli_query($con,$result_metamesatual);
    $row_metamesatual= mysqli_fetch_assoc($resultado_metamesatual);



    
    
?>

<!DOCTYPE html>
<html lang="pt-br">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" href="images/favicon.ico" type="image/ico" />

    <title>SCA - Dashboard</title>

    <!-- Bootstrap -->
    
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="../vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="../vendor/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="../vendor/iCheck/skins/flat/green.css" rel="stylesheet">
	
    <!-- bootstrap-progressbar -->
    <link href="../vendor/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">
    <!-- JQVMap -->
    <link href="../vendor/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link href="../vendor/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="../build/css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title"><i class="fa fa-dashboard"></i> <span>SCA</span></a>
            </div>

            <div class="clearfix"></div>

          

            <br />

            <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
                <!--<h3>General</h3> -->
                <ul class="nav side-menu">
                  <li><a><i class="fa fa-money"></i> Comercial <span class="fa fa-chevron-down"></span></a>
                    <ul class="nav child_menu">
                      <!--<li><a href="index.html"></a></li>
                      <li><a href="index2.html">Dashboard2</a></li>
                      <li><a href="index3.html">Dashboard3</a></li> -->
                    </ul>
                  </li>
                  <li><a><i class="fa fa-usd"></i> Financeiro <span class="fa fa-chevron-down"></span></a>
                    <ul class="nav child_menu">
                      <li><a href="form.html">General Form</a></li>
                      <li><a href="form_advanced.html">Advanced Components</a></li>
                      <li><a href="form_validation.html">Form Validation</a></li>
                      <li><a href="form_wizards.html">Form Wizard</a></li>
                      <li><a href="form_upload.html">Form Upload</a></li>
                      <li><a href="form_buttons.html">Form Buttons</a></li>
                    </ul>
                  </li>
                  <li><a><i class="fa fa-medkit"></i> Materiais <span class="fa fa-chevron-down"></span></a>
                    <ul class="nav child_menu">
                      <li><a href="general_elements.html">General Elements</a></li>
                      <li><a href="media_gallery.html">Media Gallery</a></li>
                      <li><a href="typography.html">Typography</a></li>
                      <li><a href="icons.html">Icons</a></li>
                      <li><a href="glyphicons.html">Glyphicons</a></li>
                      <li><a href="widgets.html">Widgets</a></li>
                      <li><a href="invoice.html">Invoice</a></li>
                      <li><a href="inbox.html">Inbox</a></li>
                      <li><a href="calendar.html">Calendar</a></li>
                    </ul>
                  </li>
       
                </ul>
              </div>

            </div>
            <!-- /sidebar menu -->

            <!-- /menu footer buttons -->
            <div class="sidebar-footer hidden-small">
              <a data-toggle="tooltip" data-placement="top" title="Settings">
                <span class="glyphicon glyphicon-cog" aria-hidden="true"></span>
              </a>
              <a data-toggle="tooltip" data-placement="top" title="FullScreen">
                <span class="glyphicon glyphicon-fullscreen" aria-hidden="true"></span>
              </a>
              <a data-toggle="tooltip" data-placement="top" title="Lock">
                <span class="glyphicon glyphicon-eye-close" aria-hidden="true"></span>
              </a>
              <a data-toggle="tooltip" data-placement="top" title="Logout" href="login.html">
                <span class="glyphicon glyphicon-off" aria-hidden="true"></span>
              </a>
            </div>
            <!-- /menu footer buttons -->
          </div>
        </div>

        <!-- top navigation -->
        <div class="top_nav">
          <div class="nav_menu">
              <div class="nav toggle">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
              </div>
              <nav class="nav navbar-nav">
              <ul class=" navbar-right">
                <li class="nav-item dropdown open" style="padding-left: 15px;">
                  <a href="javascript:;" class="user-profile dropdown-toggle" aria-haspopup="true" id="navbarDropdown" data-toggle="dropdown" aria-expanded="false">
                    <img src="images/img.jpg" alt="">John Doe
                  </a>
                 <!-- <div class="dropdown-menu dropdown-usermenu pull-right" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item"  href="javascript:;"> Profile</a>
                      <a class="dropdown-item"  href="javascript:;">
                        <span class="badge bg-red pull-right">50%</span>
                        <span>Settings</span>
                      </a>
                  <a class="dropdown-item"  href="javascript:;">Help</a>
                    <a class="dropdown-item"  href="login.html"><i class="fa fa-sign-out pull-right"></i> Log Out</a>
                  </div> -->
                </li>
               
              </ul>
            </nav>
          </div>
        </div>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
          <!-- top tiles -->

          <div class="row" style="display: inline-block;" >
            <div class="tile_count">
            	<h3>Cirurgias Realizadas este Mês até dia <?php echo date('d/m/yy')-1 . '<br />';?></h3>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Ajumed</span>
                <div class="count"><?php echo $row_cirhojeajumed['QTD']; ?></div>
                <span class="count_bottom"><i class="green"><?php echo  number_format(($row_cirhojeajumed['QTD']/$row_cirhoje['QTD'])*100,2, ',', '.'); ?>%</i>&ensp;do Grupo</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Best Care</span>
                <div class="count"><?php echo $row_cirhojebest['QTD']; ?></div>
                <span class="count_bottom"><i class="green"><?php echo  number_format(($row_cirhojebest['QTD']/$row_cirhoje['QTD'])*100,2, ',', '.'); ?>%</i>&ensp;do Grupo</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Brasil Ortopedia</span>
                <div class="count"><?php echo $row_cirhojebrasil['QTD']; ?></div>
                <span class="count_bottom"><i class="green"><?php echo  number_format(($row_cirhojebrasil['QTD']/$row_cirhoje['QTD'])*100,2, ',', '.'); ?>%</i>&ensp;do Grupo</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Orthomac</span>
                <div class="count"><?php echo $row_cirhojehorto['QTD']; ?></div>
                <span class="count_bottom"><i class="green"><?php echo  number_format(($row_cirhojehorto['QTD']/$row_cirhoje['QTD'])*100,2, ',', '.'); ?>%</i>&ensp;do Grupo</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Total Grupo</span>
                <div class="count"><?php echo $row_cirhoje['QTD']; ?></div>
                <span class="count_bottom"><i class="green"><?php echo  number_format(($row_cirhoje['QTD']/$row_metamesatual['Meta'])*100,2, ',', '.'); ?>%</i>&ensp;da Meta</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Media</span>
                <div class="count green"><?php echo $row_cirhoje['QTD']/ (idate('d')-1); ?></div>
                <span class="count_bottom"><i class="green"><?php echo (idate('d')-1); ?></i>&ensp;dias do Mês</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Dias Restantes</span>
                <div class="count green"><?php echo  date("t") - idate('d')+1; ?></div>
                <span class="count_bottom"><i class="green"><?php echo number_format(((idate('d')-1) / idate('t'))*100,2, ',', '.') ; ?></i>&ensp;% do Mês</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Projeção</span>
                <div class="count green"><?php echo ($row_cirhoje['QTD']/ (idate('d')-1)) * (date("t") - idate('d')+1) + $row_cirhoje['QTD'] ;  ?></div>
                <span class="count_bottom"><i class="green"><?php echo number_format((($row_cirhoje['QTD']/ (idate('d')-1)) * (date("t") - idate('d')+1) + $row_cirhoje['QTD']) / ($row_metamesatual['Meta'])*100,2, ',', '.'); ?>%</i>&ensp;da Meta</span>
              </div>
              <div class="col-md-2 col-sm-4  tile_stats_count">
                <span class="count_top"><i class="fa fa-user"></i> Meta</span>
                <div class="count purple"><?php echo $row_metamesatual['Meta']; ?></div>
                <span class="count_bottom">Mês de <?php echo date('F'); ?> </span>
              </div>
            </div>
          </div>
                    <!-- /top tiles -->

        <!--  <div class="row">
            <div class="col-md-12 col-sm-12 ">
              <div class="dashboard_graph">

                <div class="row x_title">
                  <div class="col-md-6">
                    <h3>Network Activities <small>Graph title sub-title</small></h3>
                  </div>
                  
                </div>

                <div class="col-md-9 col-sm-9 ">
                  <div id="chart_plot_01" class="demo-placeholder"></div>
                </div>
                <div class="col-md-3 col-sm-3  bg-white">
                  <div class="x_title">
                    <h2>Cirurgias Realizadas no Mês</h2>
                    <div class="clearfix"></div>
                  </div>

                  <div class="col-md-12 col-sm-12 ">
                    <div>
                      <p>Grupo BRO</p>
                      <div class="">
                        <div class="progress progress_sm" style="width: 76%;">
                          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal=<?php echo $row_cirhoje['QTD']; ?>></div>
                        </div>
                      </div>
                    </div>
                    <div>
                      <p>Brasil Ortopedia</p>
                      <div class="">
                        <div class="progress progress_sm" style="width: 76%;">
                          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal=<?php echo $row_cirhojebrasil['QTD']; ?>></div>
                        </div>
                      </div>
                    </div>
                    <div>
                      <p>Orthomac Saúde</p>
                      <div class="">
                        <div class="progress progress_sm" style="width: 76%;">
                          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal=<?php echo $row_cirhojehorto['QTD']; ?>></div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12 col-sm-12 ">
                    <div>
                      <p>Ajumed</p>
                      <div class="">
                        <div class="progress progress_sm" style="width: 76%;">
                          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal=<?php echo $row_cirhojeajumed['QTD']; ?>></div>
                        </div>
                      </div>
                    </div>
                    <div>
                      <p>Best Care</p>
                      <div class="">
                        <div class="progress progress_sm" style="width: 76%;">
                          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal=<?php echo $row_cirhojebest['QTD']; ?>></div>
                        </div>
                      </div>
                    </div>
                  </div>

                </div>

                <div class="clearfix"></div>
              </div>
            </div>

          </div> -->


          <br />
        </div>
      </div>
    </div>

    <!-- jQuery -->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <!-- FastClick -->
    <script src="../vendor/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../vendor/nprogress/nprogress.js"></script>
    <!-- Chart.js -->
   <!-- <script src="../vendor/Chart.js/dist/Chart.min.js"></script> -->
    <!-- gauge.js -->
    <script src="../vendor/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="../vendor/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="../vendor/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="../vendor/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="../vendor/Flot/jquery.flot.js"></script>
    <script src="../vendor/Flot/jquery.flot.pie.js"></script>
    <script src="../vendor/Flot/jquery.flot.time.js"></script>
    <script src="../vendor/Flot/jquery.flot.stack.js"></script>
    <script src="../vendor/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="../vendor/flot.orderbars/js/jquery.flot.orderBars.js"></script>
    <script src="../vendor/flot-spline/js/jquery.flot.spline.min.js"></script>
    <script src="../vendor/flot.curvedlines/curvedLines.js"></script>
    <!-- DateJS -->
    <script src="../vendor/DateJS/build/date.js"></script>
    <!-- JQVMap -->
    <script src="../vendor/jqvmap/dist/jquery.vmap.js"></script>
    <script src="../vendor/jqvmap/dist/maps/jquery.vmap.world.js"></script>
    <script src="../vendor/jqvmap/examples/js/jquery.vmap.sampledata.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="../vendor/moment/min/moment.min.js"></script>
    <script src="../vendor/bootstrap-daterangepicker/daterangepicker.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
  </body>
</html>
