<?php

include('../../path.php');

require_once(ROOT_CONFIG);



    class subramos_fianzas

    {

        public function insert_subramos_fianzas($Subramo)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="INSERT INTO subramos_fianzas(Subramo) VALUES ('$Subramo') ";

            $conexion->query($consulta);

            $whatsmyid=$conexion->insert_id;

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='registrar';

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_crud($_Tabla,$_Evento_Log,$_Consulta);

            return $whatsmyid;

        }



        public function get_subramos_fianzas($_Clausula_Fk,$_IdFk)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                //$consulta="SELECT *,  count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk ORDER BY Id_Subramo_Fianza DESC";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk";

            }else{

                //$consulta="SELECT *,  count(*) as numregis FROM subramos_fianzas ORDER BY Id_Subramo_Fianza DESC";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas";

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function get_subramos_fianzaspg($inicio,$TAMANO_PAGINA,$_Clausula_Fk,$_IdFk)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                $consulta="SELECT * FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk ORDER BY Id_Subramo_Fianza DESC";

            }else{

                $consulta="SELECT * FROM subramos_fianzas ORDER BY Id_Subramo_Fianza DESC";

            }

            

            if ($TAMANO_PAGINA != "Todos") {

                $consulta .= " LIMIT $inicio, $TAMANO_PAGINA";

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function update_subramos_fianzas($Id_Subramo_Fianza, $Subramo)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="UPDATE subramos_fianzas SET Id_Subramo_Fianza='$Id_Subramo_Fianza', Subramo='$Subramo' WHERE Id_Subramo_Fianza = '$Id_Subramo_Fianza'";

            $conexion->query($consulta);

            $rowaffected=$conexion->affected_rows;

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='editar';

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_crud($_Tabla,$_Evento_Log,$_Consulta);

            return $rowaffected;

        }



        public function delete_subramos_fianzas($Id_Subramo_Fianza)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="DELETE FROM subramos_fianzas WHERE Id_Subramo_Fianza='$Id_Subramo_Fianza'";

            $conexion->query($consulta);

            $rowaffected=$conexion->affected_rows;

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='eliminar';

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_crud($_Tabla,$_Evento_Log,$_Consulta);

            return $rowaffected;

        }



        //Funciones adicionales.

        public function getorderby_subramos_fianzas($Nombre,$Orderby,$_Clausula_Fk,$_IdFk)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                //$consulta="SELECT *,  count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk ORDER BY $Nombre $Orderby";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk";

            }else{

                //$consulta="SELECT *,  count(*) as numregis FROM subramos_fianzas ORDER BY $Nombre $Orderby";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas";

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function getorderby_subramos_fianzaspg($Nombre,$Orderby,$inicio,$TAMANO_PAGINA,$_Clausula_Fk,$_IdFk)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                $consulta="SELECT * FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk ORDER BY $Nombre $Orderby";

            }else{

                $consulta="SELECT * FROM subramos_fianzas ORDER BY $Nombre $Orderby";

            }

            if ($TAMANO_PAGINA != "Todos") {

                $consulta .= " LIMIT $inicio, $TAMANO_PAGINA";

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function getbyid_subramos_fianzas($Id_Subramo_Fianza)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="SELECT * FROM subramos_fianzas WHERE Id_Subramo_Fianza='$Id_Subramo_Fianza'";

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function get_subramos_fianzas_paginador_frm()

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="SELECT * FROM subramos_fianzas";

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function search_subramos_fianzas($Buscar,$_Clausula_Fk,$_IdFk)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                $consulta="SELECT *, count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk AND (Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%') ORDER BY Id_Subramo_Fianza DESC";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk AND (Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%')";

            }else{

                //$consulta="SELECT *, count(*) as numregis FROM subramos_fianzas WHERE Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%' ORDER BY Id_Subramo_Fianza DESC";

                $consulta="SELECT count(*) as numregis FROM subramos_fianzas WHERE Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%'";  

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='busco:'.$Buscar;

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_consultas($_Tabla,$_Evento_Log,$_Consulta);

            return $Array_adapter;

        }



        public function search_subramos_fianzaspg($Buscar,$inicio,$TAMANO_PAGINA,$_Clausula_Fk,$_IdFk)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            if($_Clausula_Fk!='' && $_IdFk!=''){

                $consulta="SELECT * FROM subramos_fianzas WHERE $_Clausula_Fk=$_IdFk AND (Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%') ORDER BY Id_Subramo_Fianza DESC";

            }else{

                $consulta="SELECT * FROM subramos_fianzas WHERE Id_Subramo_Fianza LIKE '%$Buscar%' || Subramo LIKE '%$Buscar%' ORDER BY Id_Subramo_Fianza DESC";

            }

            if ($TAMANO_PAGINA != "Todos") {

                $consulta .= " LIMIT $inicio, $TAMANO_PAGINA";

            }

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }



        public function searchbyparameter_subramos_fianzas($Parametro,$Buscar)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="SELECT * FROM subramos_fianzas WHERE $Parametro LIKE '%$Buscar%' ORDER BY Id_Subramo_Fianza DESC";

            $Array_adapter=$conexion->query($consulta);

            $conexion->close();

            return $Array_adapter;

        }

  

        public function execute_subramos_fianzas($query)

        {

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $Array_adapter=$conexion->query($query);

            $conexion->close();

            return $Array_adapter;

        }



        public function update_field_subramos_fianzas($Field,$Value,$Id_Subramo_Fianza)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Valueinto=strtoupper($Value);

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="UPDATE subramos_fianzas SET $Field='$Valueinto' WHERE Id_Subramo_Fianza= '$Id_Subramo_Fianza'";

            $conexion->query($consulta);

            $rowaffected=$conexion->affected_rows;

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='editar';

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_crud($_Tabla,$_Evento_Log,$_Consulta);

            return $rowaffected;                          

        }



        public function update_field_front_subramos_fianzas($Field,$Value,$Id_Subramo_Fianza)

        {

            require_once('../../log/controller/log.php');

            $Obj_log = new log();

            $Odbj_conexion = new odbconexion;

            $conexion=$Odbj_conexion->openconection();

            $consulta="UPDATE subramos_fianzas SET $Field='$Value' WHERE Id_Subramo_Fianza= '$Id_Subramo_Fianza'";

            $conexion->query($consulta);

            $rowaffected=$conexion->affected_rows;

            $conexion->close();

            $_Tabla='subramos_fianzas';

            $_Evento_Log='editar';

            $_Consulta = '"'.$consulta.'"';

            $Obj_log->insert_log_crud($_Tabla,$_Evento_Log,$_Consulta);

            return $rowaffected;                          

        }



}



?>