<?php include('meta.php');
if ($_GET['call'] == 1){
     echo "<div id='alert' class='alert alert-success'>Archivo subido correctamente</div>";
  };
 $bg_header = "bg_sala"; include('header.php')
 ?>
<script type="text/javascript">
	$(document).ready(function() {
    $('#allpatient').DataTable( {
    	paging: false,
    	searching: false,
        "language": {
        	"search": "Buscar:",
        	"lengthMenu":    "Mostrar _MENU_  citas activas",
            "info":           "Total de  _TOTAL_ registros",
            "infoEmpty":      "No hay elementos en la tabla"      
            "infoPostFix":    "",
            "infoFiltered": "(filtered from _MAX_ total records)",
            "loadingRecords": "Cargando registros...",
            "zeroRecords":    "No hay pacientes actualmente",
            "emptyTable":     "No hay pacientes actualmente",
            "paginate": {
            			"first":      "Primero",
            			"previous":   "Anterior",
            			"next":       "Siguiente",
            			"last":       "&Uacuteltimo"
            			},
        }
	} );
} );
</script>
	<div id="box_body"><!-- body center -->
		<br /><span class="big_title_h2">Reportes</span>
		<br /><br>
		<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
		   		<div class="col-md-4">
		   			<div class="panel panel-default" >
					  <div class="panel-heading" style="background-color:#F3DC64">
					    <h3 class="panel-title">Reporte de citas por Dia</h3>
					  </div>
					  <div class="panel-body">
					  	<select name="day_day" >
									<option>Dia</option>
									<option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
					</select>
					<select name="day_month">
									<option value="0"> Mes </option>
									<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
					</select>
					Año <input type="text" style="width:55px" name="year_month" value="<?php echo date('Y') ?>" >
					  </div>
					</div>						
		   		</div>
		   		<div class="col-md-4">
		   		<div class="panel panel-default" >
					  <div class="panel-heading" style="background-color:#F3DC64">
					    <h3 class="panel-title">Reporte de citas por Mes</h3>
					  </div>
					  <div class="panel-body">
					  	<select name="month_month">
									<option value="0"> Mes </option>
									<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
						</select>
						Año <input type="text" style="width:55px" name="year" value="<?php echo date('Y') ?>" >   
					  </div>
					</div>	
		   		</div>
		   		<div class="col-md-4">
		   			<div class="panel panel-default" >
					  <div class="panel-heading" style="background-color:#F3DC64">
					    <h3 class="panel-title">Reporte por "tipo de cita"</h3>
					  </div>
					  <div class="panel-body">
					  	<select name="day_tipo" >
									<option>Dia</option>
									<option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
						</select>
						<select name="month_tipo">
										<option value="0"> Mes </option>
										<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
						</select>
						Año <input type="text" style="width:55px" name="year_tipo" value="<?php echo date('Y') ?>" >				  						    
					  </div>
					</div>			
		   		</div><div align="center"><input type="submit" name="submit" value="Consultar" style="display:inline"> </div>
			</form>
		   	<!--- segunda linea -->
		   	<form name="form2" method="POST" action="reports_list.php" >
		   	<div class="row" style="display:initial">
		   		<div class="col-md-4">
		   			<div class="panel panel-default" >
					  <div class="panel-heading" style="background-color:#F3DC64">
					    <h3 class="panel-title">Ver listado de citas por día</h3>
					  </div>
					  <div class="panel-body">
					  	<select name="day_view" >
									<option>Dia</option>
									<option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
					</select>
					<select name="month_view">
									<option value="0"> Mes </option>
									<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
					</select>
					Año <input type="text" style="width:55px" name="year_view" value="<?php echo date('Y') ?>" >
					<br><br><input type="submit" name="submit2" value="Consultar listado">					
					  </div>
					</div>	
		   		</div>

		   		</form>
		   		<!--
		   		<div class="col-md-8">
		   		<div class="panel panel-default" >
					 <div class="panel-heading" style="background-color:#F3DC64">

					    <h3 class="panel-title"> <span class="glyphicon glyphicon-earphone" aria-hidden="true"></span> Reporte Call Center (en pruebas)</h3></div>
					  <div class="panel-body">
					 	 <form action="importar.php" enctype="multipart/form-data" method="post">
					 	  Fecha del call center:
					  		<select name="day_call" >
									<option>Dia</option>
									<option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
							</select>
							<select name="month_call">
									<option value="0"> Mes </option>
									<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
							</select>
							Año <input type="text" style="width:55px" name="year_call" value="<?php echo date('Y') ?>" >
							<br /><br />
							Fecha Limite para las citas (hasta el): 
							<select name="day_call_end" >
									<option>Dia</option>
									<option value="01">1</option><option value="02">2</option><option value="03">3</option><option value="04">4</option><option value="05">5</option><option value="06">6</option><option value="07">7</option><option value="08">8</option><option value="09">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
							</select>
							<select name="month_call_end">
									<option value="0"> Mes </option>
									<option value="01">Ene</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Abr</option><option value="05">may</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Ago</option><option value="09">Sept</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dic</option>
							</select>
							Año <input type="text" style="width:55px" name="year_call_end" value="<?php echo date('Y') ?>" >
							<br /><br />	
						 	<input id="archivo" accept=".csv" name="archivo" type="file" /> 
						 	<br />					 	
   							<input name="MAX_FILE_SIZE" type="hidden" value="20000" /> 	<input name="enviar" type="submit" value="Consultar" />
							</form>
					  </div>
					</div>	
						
		   		</div>
		   		-->
		   		<!--
		   		<div class="col-md-4">
		   		
		   			<div class="panel panel-default" >
					  <div class="panel-heading" style="background-color:#F3DC64">
					    <h3 class="panel-title"></h3>
					  </div>
					  <div class="panel-body">					  					  						    
					  </div>
					</div>	
				
		   		</div>
		   		-->
		   		</div>
		   		
		<?php
		if(isset($_POST['submit'])) 
		{ 
		    $day_day = $_POST['day_day'];
		    $day_month = $_POST['day_month'];
		    $month_month = $_POST['month_month'];
		    $year_month = $_POST['year_month'];
		    $date1 = $year_month."-".$day_month."-".$day_day;
		    if($day_month != "0"){
		    	echo "<br /><span class='big_title'>Reporte de citas para el <strong>día:</strong> ".$day_day." del mes ".$day_month." del ".$year_month."</span> <div style='float:right'><a href='report_export.php?date1=$date1' class='btn btn-info btn-xs'><span class='glyphicon glyphicon-download-alt'></span> Descargar</a>
</div>";	
		    	$result = mysqli_query($con,"SELECT * FROM se_evenement WHERE start LIKE '$date1%' ORDER BY name");

					echo "<table id='allpatient' class='display table table-hover'> \n"; 
					echo "
					<thead>
						<tr>
						<th>Nombre</th>
						<th>Tipo_doc</th>
						<th>Cedula</th>
						<th>Teléfono</th>
						<th>Fecha</th>
						<th>Descripción</th>
						<th>Servicio</th>
						<th>Estado</th>
						<th>Debe</th>
						<th>Continuo</th>
						<th>se_entero</th>
						<th>Atendido</th>
						</tr>
					</thead>
					<tbody>	\n"; 
					while ($row = mysqli_fetch_row($result))
					{ 
						echo "<tr> 
								<td ><strong>$row[1]</strong></td>
								<td>$row[34]</td>
						      	<td>$row[2]</td>
						      	<td>$row[29]</td>
						      	<td>$row[4]</td>
						      	<td>$row[3]</td>
						      	<td>";
						if ($row[8] != "") {
						   	echo "SCH ";					  
						};
						if ($row[9] != ""){					   
						        echo "ST ";
						};
						if ($row[10] != ""){					   
						        echo "CMF ";					        
						};
						if ($row[11] != ""){					   
						        echo "CEL ";					        
						};
						if ($row[12] != ""){					   
						        echo "CM ";					        
						};
						if ($row[13] != ""){
						        echo "SEF ";					      
						};
						if ($row[14] != ""){					   
						        echo "SEV ";					        
						};
						if ($row[15] != ""){					   
						        echo "SEH ";    
						};
						if ($row[16] != ""){					   
						        echo "SET ";					        
						};
						if ($row[17] != ""){					   
						        echo "SEG ";
						};
						if ($row[18] != ""){					   
						        echo "SEP ";
						};
						if ($row[32] != ""){					   
						        echo "SEC ";
						};
						if ($row[33] != ""){					   
						        echo "SEL ";
						};
						if ($row[19] != ""){					   
						        echo "CHC ";
						};
						if ($row[20] != ""){					   
						        echo "CMD ";					        
						};
						if ($row[21] != ""){					   
						        echo "CMT ";
						};
						if ($row[22] != ""){					   
						        echo "CTO ";					        
						};
						if ($row[23] != ""){					   
						        echo "CAT ";					        
						};
						if ($row[24] != ""){					   
						        echo "CPA ";					        
						};
						if ($row[25] != ""){					   
						        echo "CAF ";
						};
						if ($row[26] != ""){					   
						        echo "CMA ";
						};
						if ($row[39] != ""){					   
						        echo "LAB ";
						};
						if ($row[40] != ""){					   
						        echo "CMG ";
						};
						if ($row[41] != ""){					   
						        echo "MG ";
						};
						echo  "</td>
						      	<td>$row[27]</td>
						      	<td>$row[28]</td>
						      	<td>$row[30]</td>
						      	<td>$row[31]</td>
						      	<td>$row[35]</td>
						      </tr>";
					};
					echo " \n"; 
					echo " </tbody></table> \n"; 	    	
		    }		    
		}
		?>
		<!-- citas x mes -->
		<?php
		if(isset($_POST['submit'])) 
		{ 
		    $day_day = $_POST['day_day'];
		    $day_month = $_POST['day_month'];
		    $month_month = $_POST['month_month'];
		    $year = $_POST['year'];
		    $date2 = $year."-".$month_month;
		    if($month_month != "0"){
		    	echo "<br /><span class='big_title'>Reporte de citas para el <strong>mes:</strong> ".$month_month." del año ".$year."</span><div style='float:right'><a href='report_export.php?date2=$date2' class='btn btn-info btn-xs'><span class='glyphicon glyphicon-download-alt'></span> Descargar</a></div>";	
		    	$result = mysqli_query($con,"SELECT * FROM se_evenement WHERE start like '%$date2%' ORDER BY name");
					echo "<table id='allpatient' class='display table table-hover'> \n"; 
					echo "
					<thead>
						<tr>
						<th>Nombre</th>
						<th>Tipo_doc</th>
						<th>Cedula</th>
						<th>Teléfono</th>
						<th>Fecha cita</th>
						<th>Descripción</th>
						<th>Servicio</th>
						<th>Estado</th>
						<th>Pago</th>
						<th>Continuo</th>
						<th>se_entero</th>
						<th>Atendido</th>
						</tr>
					</thead>
					<tbody>	\n"; 
					while ($row = mysqli_fetch_row($result))
					{ 
						echo "<tr> 
								<td ><strong>$row[1]</strong></td>
								<td>$row[34]</td>
						      	<td>$row[2]</td>
						      	<td>$row[29]</td>
						      	<td>$row[4]</td>
						      	<td>$row[3]</td>
						      	<td>";
						if ($row[8] != "") {
						   	echo "SCH ";					  
						};
						if ($row[9] != ""){					   
						        echo "ST ";
						};
						if ($row[10] != ""){					   
						        echo "CMF ";					        
						};
						if ($row[11] != ""){					   
						        echo "CEL ";					        
						};
						if ($row[12] != ""){					   
						        echo "CM ";					        
						};
						if ($row[13] != ""){
						        echo "SEF ";					      
						};
						if ($row[14] != ""){					   
						        echo "SEV ";					        
						};
						if ($row[15] != ""){					   
						        echo "SEH ";    
						};
						if ($row[16] != ""){					   
						        echo "SET ";					        
						};
						if ($row[17] != ""){					   
						        echo "SEG ";
						};
						if ($row[18] != ""){					   
						        echo "SEP ";
						};
						if ($row[32] != ""){					   
						        echo "SEC ";
						};
						if ($row[33] != ""){					   
						        echo "SEL ";
						};
						if ($row[19] != ""){					   
						        echo "CHC ";
						};
						if ($row[20] != ""){					   
						        echo "CMD ";					        
						};
						if ($row[21] != ""){					   
						        echo "CMT ";
						};
						if ($row[22] != ""){					   
						        echo "CTO ";					        
						};
						if ($row[23] != ""){					   
						        echo "CAT ";					        
						};
						if ($row[24] != ""){					   
						        echo "CPA ";					        
						};
						if ($row[25] != ""){					   
						        echo "CAF ";
						};
						if ($row[26] != ""){					   
						        echo "CMA ";
						};
						if ($row[39] != ""){					   
						        echo "LAB ";
						};
						if ($row[40] != ""){					   
						        echo "CMG ";
						};
						if ($row[41] != ""){					   
						        echo "MG ";
						};
						echo  "</td>
						      	<td>$row[27]</td>
						      	<td>$row[28]</td>
						      	<td>$row[30]</td>
						      	<td>$row[31]</td>
						      	<td>$row[35]</td>
						      </tr>";
					};
					echo " \n"; 
					echo " </tbody></table> \n"; 	    	
		    }		    
		}
		?>
		<!-- reporte x tipo de cita -->
		<?php
		if(isset($_POST['submit'])) 
		{ 
		    $day_tipo= $_POST['day_tipo'];
		    $month_tipo = $_POST['month_tipo'];
		    $year_tipo = $_POST['year_tipo'];
		    $date3 = $year_tipo."-".$month_tipo."-".$day_tipo;
		    if($month_tipo != "0"){
		    	echo "<br /><span class='big_title'>Reporte de Tipos de citas para el <strong>día:</strong> ".$day_tipo." del mes ".$month_tipo." del ".$year_tipo."</span> </div>";	
		    	/* Camara H */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Camara H'");
		        $camarah =  mysqli_result($result0);
		        /* Estética */
				$result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Estética'");
				$estetica =  mysqli_result($result0);
				/* Consulta MF */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Consulta MF'");
		        $consultamf =  mysqli_result($result0);
		        /* Control MF */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Control MF'");
		        $controlmf =  mysqli_result($result0);
		        /* Control P.A. */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Control P.A.'");
		        $controlpa =  mysqli_result($result0);
		        /* General */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'General'");
		        $general =  mysqli_result($result0);
		        /* Inicio P.A. */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Inicio P.A.'");
		        $iniciopa =  mysqli_result($result0);
		        /* Laboratorio */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Laboratorio'");
		        $laboratorio =  mysqli_result($result0);
		        /* Terapia */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Terapia'");
		        $terapia =  mysqli_result($result0);
		        /* Valoracion */
		        $result = mysqli_query($con,"SELECT  COUNT(*) FROM se_evenement WHERE start like '%$date3%' AND t_servicio = 'Valoracion'");
		        $valoracion =  mysqli_result($result0);		
		        /* total */
		        $total = $camarah + $consultamf + $controlmf + $controlpa + $estetica + $general + $iniciopa + $laboratorio + $terapia + $valoracion;
				/* */
				/* */
				echo   "<div style='padding:8px' >
							<table class='display table table-hover' style='width:40%'>
								<thead>
									<tr>
									<th style='width:250px'>Tipo de Cita</th>
									<th>Cantidad</th>
									</tr>
								</thead>
								<tbody>
								<tr>
									<td>Cámara Hiperbárica:</td>
									<td>$camarah</td>
								</tr>
								<tr>
									<td>Consulta MF:</td>
									<td>$consultamf</td>
								</tr>
								<tr>
									<td>Control MF:</td>
									<td>$controlmf</td>
								</tr>
								<tr>
									<td>Control PA:</td>
									<td>$controlpa</td>
								</tr>
								<tr>
									<td>Estética:</td>
									<td>$estetica</td>
								</tr>
								<tr>
									<td>General:</td>
									<td>$general</td>
								</tr>
								<tr>
									<td>Inicio PA:</td>
									<td>$iniciopa</td>
								</tr>
								<tr>
									<td>Laboratorio:</td>
									<td>$laboratorio</td>
								</tr>
								<tr>
									<td>Terapia:</td>
									<td>$terapia</td>
								</tr>
								<tr>
									<td>Valoración:</td>
									<td>$valoracion</td>
								</tr>
								<tr>
									<td style='text-align:right'><strong>Total</strong></td>
									<td>$total</td>
								</tr>
								</tbody>
							</table>							
						</div>";	    		    	
		    }		    
		}
		?>
		<!-- ver cita por dia -->
		<?php
		if(isset($_POST['submit'])) 
		{ 
		    $day_view = $_POST['day_view'];
		    $month_view= $_POST['month_view'];
		    $year_view = $_POST['year_view'];
		    $date4 = $year_view."-".$month_view."-".$day_view;
		    if($day_view != "0"){
		    	echo "<br /><span class='big_title'>Listado de citas para el <strong>día:</strong> ".$day_view." del mes ".$month_view." del ".$year_view."</span> <div style='float:right'>
		    	<form action='update_list_event.php' method='POST'><input type='submit' name='submit' value='Guardar'></div>";	
		    	$result = mysqli_query($con,"SELECT * FROM se_evenement WHERE start LIKE '$date4%' ORDER BY name" );

					echo "<table id='allpatient' class='display table table-hover'> \n"; 
					echo "
					<thead>
						<tr>
						<th>Nombre</th>
						<th>Tipo de cita </th>
						<th>Cedula</th>
						<th>Teléfono</th>
						<th>Comentario</th>
						<th>Fecha y hora</th>
						<th>Estado</th>
						</tr>
					</thead>
					<tbody>	\n"; 
					while ($row = mysqli_fetch_row($result))
					{ 
						echo "<tr> 
								<td><strong>$row[1]</strong></td>
								<td>$row[36]</td>
						      	<td>$row[2]</td>
						      	<td>$row[29]</td>
						      	<td>$row[37]</td>
						      	<td>$row[4]</td>
						      	<td><select name='status'>
									<option value='$row[27]' selected>$row[27]</option>
									<option></option>
									<option value='Sala de espera'>Sala de espera</option>
									<option value='Reagendado'>Reagendado</option>
								    <option value='Confirmada'>Confirmada</option>
								    <option value='Cancelada'>Cancelada</option>
								    <option value='No contesta'>No contesta</option>
								    </select>
						      	</td>
						      </tr>";
					};
					echo " \n"; 
					echo " </tbody></table> \n";
					echo "</form> <br>";
					 }		    
		}
		?>
	</div><!-- END body center -->
<?php include('../footer.php') ?>