<?php
//require_once '../app/model/db.class.php';

function calculardef($valor){

    $sw = "true";
    $obj = new database();

    $obj->conectar(); $obj->consulta("set names 'utf8'");
    $resultado=$obj->consulta("select * from rangos order by orden");


     while(($row = $obj->fetch_assoc($resultado)) && ($sw == "true") ){
      
             if (($row['inferior']== ">") && ($row['superior']== "<")) {

                if ($valor > $row['v1'] && $valor < $row['v2']) {
                    return $row['descripcion'];
                    $sw = "false";
                }
            }
            elseif (($row['inferior']== ">") && ($row['superior']== "<=")) {

                if ($valor > $row['v1'] && $valor <= $row['v2']) {
                    return $row['descripcion'];
                    $sw = "false";
                }
            }
            elseif (($row['inferior']== ">=") && ($row['superior']== "<")) {

                if ($valor >= $row['v1'] && $valor < $row['v2']) {
                    return $row['descripcion'];
                    $sw = "false";

                }
            }
            elseif (($row['inferior']== ">=") && ($row['superior']== "<=")) {

                if ($valor >= $row['v1'] && $valor <= $row['v2']) {
                    return $row['descripcion'];
                    $sw = "false";

                }

            }
    

      }

      $obj->disconnect();
}

//--------------------------------

function calculardef_codigo($valor){

    $sw = "true";
    $obj = new database();

    $obj->conectar(); $obj->consulta("set names 'utf8'");
    $resultado=$obj->consulta("select * from rangos order by orden");


     while(($row = $obj->fetch_assoc($resultado)) && ($sw == "true") ){

             if (($row['inferior']== ">") && ($row['superior']== "<")) {

                if ($valor > $row['v1'] && $valor < $row['v2']) {
                    return $row['codigo'];
                    $sw = "false";
                }
            }
            elseif (($row['inferior']== ">") && ($row['superior']== "<=")) {

                if ($valor > $row['v1'] && $valor <= $row['v2']) {
                    return $row['codigo'];
                    $sw = "false";
                }
            }
            elseif (($row['inferior']== ">=") && ($row['superior']== "<")) {

                if ($valor >= $row['v1'] && $valor < $row['v2']) {
                    return $row['codigo'];
                    $sw = "false";

                }
            }
            elseif (($row['inferior']== ">=") && ($row['superior']== "<=")) {

                if ($valor >= $row['v1'] && $valor <= $row['v2']) {
                    return $row['codigo'];
                    $sw = "false";

                }

            }


      }
   $obj->disconnect();

}


?>
