<?php include('meta.php') ?>
<?php $bg_header = "bg_sala"; include('header.php') ?>
<style type="text/css">
  #box_html{
    width: 1024px;
  }
</style>
<script type="text/javascript">
	// haces referencia al elemento (en este caso div) e indicas el tiempo de espera en segundos
	var strCmd = "document.getElementById('alert').style.display = 'none'";
	var waitseconds = 4;
	// Calculas el tiempo en milisegundos y ejecutas la acción
	var timeOutPeriod = waitseconds * 800;
	var hideTimer = setTimeout(strCmdtimeOutPeriod);
	$(document).ready(function() {
    $('#allpatient').DataTable( {
    	"iDisplayLength": 50,
    	 "order": [[ 4"asc" ]],
        "language": {
        	"search": "Buscar:",
        	"lengthMenu":    "Mostrar _MENU_  productos en la tabla",
            "info":           "Mostrando de [ _START_ -  _END_ ] de un total de  _TOTAL_ registros",
            "infoEmpty":      "No hay elementos en la tabla"      
            "infoPostFix":    "",
            "infoFiltered": "(filtered from _MAX_ total records)",
            "loadingRecords": "Cargando registros...",
            "zeroRecords":    "No hay elementos en la tabla",
            "emptyTable":     "No hay elementos en la tabla",
            "paginate": {
            			"first":      "Primero",
            			"previous":   "Anterior",
            			"next":       "Siguiente",
            			"last":       "&Uacuteltimo"
            			},
        }
	} );
} );
</script>
	<div id="box_body"><!-- body center -->
		<br /><span class="big_title_h2">Reporte Call Center</span><br />

		<?php
		$date_start = $_GET['date_start']." 00:00:00";
		$date_end = $_GET['date_end']." 23:59:59";
		$total_citas = 0;
		$num_con = 0;
		/// suma de fila del file call center
		$result_call = mysqli_query($con,"SELECT COUNT(phone) FROM callcenter_tmp");
		$total_call =  mysqli_result($result_call0);
		
		// mostrar listado			
			echo "<table  class='display table table-hover' > \n"; 
		    echo " <thead>
		                <tr>
		                <th>N°</th>
		                <th>Nombre</th>
		                <th>Cedula</th>
		                <th>Tipo de cita</th>
		                <th>Teléfono Call center</th>
		                <th>Teléfono</th>
		                <th>Fecha/Hora</th>
		                </tr>
		              </thead>
		              <tbody> \n"; 
			$result = mysqli_query($con,"SELECT * FROM callcenter_tmp ");
			while ($row_user = mysqli_fetch_assoc($result)) {
			   $phone2 = $row_user['phone'];
			  /*  echo $phone2."<br>"; */
			   if (strlen($phone2) == 8){
				$phone3 = substr($phone21);				
				} else {
					$phone3 = $row_user['phone'];
				}
			// consulta si el cell existen el las citas 
			   $result1 = mysqli_query($con,'SELECT * FROM se_evenement WHERE start BETWEEN "'.$date_start.'" AND "'.$date_end.'" AND cell LIKE "%'.$phone3.'%"');			   		  			   
					if ($row_name = mysqli_fetch_assoc($result1)) {
						// suma de cantidad de cita de la bd que emparejan
						$total_citas++;
						$num_con++;
						echo "<tr> 
		                <td>$num_con</td>
		                <td><strong>".$row_name['name']."</strong></td>
		                <td>".$row_name['title']."</td>
		                <td>".$row_name['t_servicio']."</td>
		                <td>".$phone2."</td>
		                <td>".$row_name['cell']."</td>
		                <td>".$row_name['start']."</td>";				
					} 
				}
			echo " \n"; 
		    echo " </tbody></table> \n"; 
		$efec_call = ($total_citas/$total_call)*100;
		?>		
		<h4>Total de llamadas call center: <?php echo $total_call ?>
		<br>
		Total cita hechas: <?php echo $total_citas ?>
		<br>
		Porcentaje: <?php echo round($efec_call) ?>%
		</h4>		
		<!-- ver cita por dia y listado -->
	
	</div><!-- END body center -->
<?php include('../footer.php') ?>