<?php
require_once('../Web_Admin/conexion.php');
require_once('Class_Fecha.php');
class Estadistica_C {
	function __construct()
	{
		
	}

	public function Estadistica($Lista, $Anio)
	{
		$Muni=str_replace('[','(',$Lista);
		$Muni=str_replace(']',')',$Muni);
		
		$db = new Conexion();
		$Sql="SELECT B.nombre, COUNT(A.Id) as Mov, sum(if(MONTH(A.Fecha_Emi)=1,1,0)) as Ene, sum(if(MONTH(A.Fecha_Emi)=2,1,0)) as Feb, sum(if(MONTH(A.Fecha_Emi)=3,1,0)) as Mar, sum(if(MONTH(A.Fecha_Emi)=4,1,0)) as Abr, sum(if(MONTH(A.Fecha_Emi)=5,1,0)) as May, sum(if(MONTH(A.Fecha_Emi)=6,1,0)) as Jun, sum(if(MONTH(A.Fecha_Emi)=7,1,0)) as Jul, sum(if(MONTH(A.Fecha_Emi)=8,1,0)) as Ags, sum(if(MONTH(A.Fecha_Emi)=9,1,0)) as Sep,  sum(if(MONTH(A.Fecha_Emi)=10,1,0)) as Oct, sum(if(MONTH(A.Fecha_Emi)=11,1,0)) as Nov, sum(if(MONTH(A.Fecha_Emi)=12,1,0)) as Dic, Year(A.Fecha_Emi) as Anio FROM O_Folios_Asig A INNER JOIN C_Municipios B on A.Id=B.id WHERE A.Act=1 and A.Id in $Muni and YEAR(A.Fecha_Emi)=$Anio GROUP By A.Id ORDER BY B.nombre ASC";
		//echo "Rut ".$Sql;
		$resultado= $db->query($Sql);
		return($resultado);
	}
	
	public function List_Client(){
		
		$db = new Conexion();
		$resultado= $db->query("SELECT A.Id, B.nombre from O_Folios_Asig A INNER JOIN C_Municipios B on A.Id= B.id GROUP BY B.nombre");
		
		echo "Municipios: <br><p><select name='Muni_' id='Muni_' size='10' multiple>";
		while ($row=$resultado->fetch_assoc()){
			echo '<option value="'.$row['Id'].'">'.$row['nombre'].'</option>';
		}
		echo "</select></p>";
	}
	
	public function Alta_Anios($Opc){
		$Opc=($Opc==1 ? 'Anio_U' : 'Anio_D');
		$db = new Conexion();
		$resultado= $db->query("SELECT DISTINCT(YEAR(Fecha_Emi)) as Anios from O_Folios_Asig where Act=1 ORDER BY YEAR(Fecha_Emi) ASC");
		
		echo "Año: <br><p><select name=".$Opc." id=".$Opc." >";
		while ($row=$resultado->fetch_assoc()){
			echo '<option value="'.$row['Anios'].'">'.$row['Anios'].'</option>';
		}
		echo "</select></p>";
	}
	
} // Fin de class de Estadistica