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

$id = $_POST['id'];

$sqlConsultaMatricula = "SELECT MT.Matricula_id,
(SELECT PMT.monto_matricula FROM pagos_matriculas PMT WHERE PMT.matricula_INT = MT.Matricula_id GROUP BY PMT.matricula_INT) AS totalMatricula, 
(SELECT SUM(PMT.monto_abonado) FROM pagos_matriculas PMT WHERE PMT.matricula_INT = MT.Matricula_id) AS totalAbonadoMatricula,
(SELECT totalMatricula - totalAbonadoMatricula) AS saldoMatricula
FROM matricula MT WHERE MT.Persona_id = '$id'";
$queryConsultaMatricula = mysqli_query($con, $sqlConsultaMatricula);
$fetchConsultaMatricula = mysqli_fetch_assoc($queryConsultaMatricula);
$total = mysqli_num_rows($queryConsultaMatricula);

if($total > 1){
    $idmatr = $fetchConsultaMatricula['Matricula_id'];
    $datos = array(
        0 => 1,
        1 => $idmatr,
        );
    echo json_encode($datos);
}else{
    $idmatr = 0;
    $datos = array(
        0 => 2,
        1 => $sqlConsultaMatricula,
        );
    echo json_encode($datos);
}

?>