if ($tipo == 3) {
     if (isset($inscr) && !empty($inscr)) {
         if ($result = debitos_inscricao_var($inscr, 0, $tipo, $DB_DATACALC, db_getsession("DB_anousu"))) {
             echo "<script> inscr = '{$inscr}'; </script>\n";
         } else {
             db_redireciona("cai3_gerfinanc007.php?erro1=1");
         }
     } elseif (isset($numcgm) && !empty($numcgm)) {
         if ($result = debitos_numcgm_var($numcgm, 0, $tipo, $DB_DATACALC, db_getsession("DB_anousu"))) {
             echo "<script> numcgm = '{$numcgm}'; </script>\n";
         } else {
             db_redireciona("cai3_gerfinanc007.php?erro1=1");
         }
     } else {
         if (isset($numpre) && !empty($numpre)) {
             if ($result = debitos_numpre_var($numpre, 0, $tipo, $DB_DATACALC, db_getsession("DB_anousu"))) {
                 echo "<script> numpre = '{$numpre}'; </script>\n";
             } else {
                 db_redireciona("cai3_gerfinanc007.php?erro1=1");
             }
         }
     }
 } else {
     if (isset($numcgm) && !empty($numcgm) && (isset($matric) && empty($matric)) && (isset($inscr) && empty($inscr))) {
         if ($result = debitos_numcgm($numcgm, 0, $tipo, $DB_DATACALC, db_getsession("DB_anousu"))) {
             echo "<script> numcgm = '{$numcgm}'; </script>\n";
         } else {
             db_redireciona("cai3_gerfinanc007.php?erro1=1");
         }
     } else {
         if (isset($matric) && !empty($matric)) {
 }
 //verifica o tipo e da o select dependendo se é numcgm, matric numpre ou inscr
 if (isset($tipo)) {
     if ($tipo == 3) {
         if (isset($numcgm)) {
             $acesso = "1";
             $campo = $numcgm;
             $result = debitos_numcgm_var($numcgm, 0, $tipo, time(), date("Y"));
         } else {
             if (isset($inscricao)) {
                 $acesso = "2";
                 $campo = $inscricao;
                 $result = debitos_inscricao_var($inscricao, 0, $tipo, time(), date("Y"));
             } else {
                 if (isset($numpre)) {
                     $result = debitos_numpre_var($numpre, 0, $tipo, time(), date("Y"));
                 }
             }
         }
     } else {
         if (isset($numcgm) && $numcgm != "") {
             $acesso = "1";
             $campo = $numcgm;
             $result = debitos_numcgm($numcgm, 0, $tipo, time(), date("Y"));
         } else {
             if (isset($matricula) && $matricula != "") {
                 $acesso = "3";
                 $campo = $matricula;
                 $result = debitos_matricula($matricula, 0, $tipo, time(), date("Y"));
             } else {
                 if (isset($inscricao) && $inscricao != "") {