<?php
	include('../conexiones/conex.php');
    include('../includes/validador.php');
    include('../includes/funciones.php');

    $func = $_SESSION['MM_Fun'];
    $datos[] = "";
    $anhoActual = date('Y');
	$sqlPersonas = "SELECT MT2.montoCuota, PS.Persona_id, PS.Nombre AS nomAlumno, PS.Apellido apeAlumno, PS.Direccion, AL.FechaNacimiento AS nac, PS.NroDocumento AS cedula, MT2.AhoLectivo, (SELECT PMT.matricula_INT FROM pagos_matriculas PMT RIGHT JOIN matricula MT ON MT.Matricula_id = PMT.matricula_INT WHERE MT.Persona_id = PS.Persona_id AND MT.AhoLectivo = MT2.AhoLectivo ORDER BY PMT.idPago DESC LIMIT 1) AS matrid, (SELECT CS.Descripcion FROM curso CS INNER JOIN matricula MT ON MT.Curso_id = CS.Curso_id WHERE MT.Persona_id = PS.Persona_id AND MT.AhoLectivo = MT2.AhoLectivo ORDER BY MT.Matricula_id DESC LIMIT 1) AS curso,(SELECT PMT.monto_matricula FROM pagos_matriculas PMT INNER JOIN matricula MT ON MT.Matricula_id = PMT.matricula_INT WHERE PMT.monto_matricula != '' AND MT.Persona_id = PS.Persona_id AND MT.AhoLectivo = MT2.AhoLectivo ORDER BY MT.Matricula_id DESC LIMIT 1) AS matricula FROM alumno AL INNER JOIN persona PS ON AL.Persona_id = PS.Persona_id INNER JOIN matricula MT2 ON MT2.Persona_id = PS.Persona_id ORDER BY PS.Persona_id ASC";
	$queryPersonas = mysqli_query($con, $sqlPersonas);
    $total = mysqli_num_rows($queryPersonas);

	if($total > 0){
		while($row = mysqli_fetch_assoc($queryPersonas)){
			$datos["data"][] = $row;
		}
	}else{
		$datos["data"][] = [];
	}

    echo json_encode($datos);		
$con->close();
?>