<?php 
extract($_POST);
include_once dirname( __DIR__ ) . '/Model/db.php';
include_once dirname( __DIR__ ) . '/Model/Buscar.php';
include_once dirname( __DIR__ ) . '/add/funciones.php';

$periodo = periodo($mes,$anio);

$buscar = new Buscar();
$buscar->setFechaCargoInicial($periodo['finicial']);
$buscar->setFechaCargoFinal($periodo['ffinal']);
$buscar->setEjecutivo($inputEjecutivo);

foreach($buscar->obtieneDatosSubMedios() as $resp){
	
	if( $resp['noches'] == 1 && $resp['semanas']==0 && $resp['meses']==0 && $resp['anios']==0 && ($resp['ffc'] != $resp['salida_prematura']) ){
			$hora[] = $resp['noches'];
			
	}
	if($resp['noches'] > 0 && $resp['semanas']==0 && $resp['meses']==0 && $resp['anios']==0 ){
		
		if($resp['noches'] == 1 && ($resp['ffc'] != $resp['salida_prematura']) ){
		}else{
			$noches[] = $resp['noches'];
		}
			
			
	}
	if($resp['semanas']>0 && $resp['meses']==0 && $resp['anios']==0){
			$semanas[] = $resp['semanas'];
	}
	if($resp['meses']>0 && $resp['anios']==0){
			$meses[] = $resp['meses'];
	}
	if($resp['anios']>0){
			$anios[] = $resp['anios'];
	}
}

$response[] = array('tipo'=>'HORA', 'total' => count($hora));
$response[] = array('tipo'=>'NOCHE', 'total' => count($noches));
$response[] = array('tipo'=>'SEMANA', 'total' => count($semanas));
$response[] = array('tipo'=>'MES', 'total' => count($meses));
$response[] = array('tipo'=>'ANIO', 'total' => count($anios));

echo json_encode( ($response) );

?>