<?php
    class MotherCar{
        private $con;
        private $nr_1 = 1;
        private $nr_2 = 2;
        private $tipo = 'VO';

        private $codigo_vehiculo_tabla_vehiculos;
        private $usuario_session;
        private $id_car;
        private $marca_tabla_vehiculos;
        private $modelo_tabla_vehiculos;
        private $version_tabla_vehiculos;
        private $mostrar_tabla_vehiculos;
        private $matricula_tabla_vehiculos;
        private $bastidor_tabla_vehiculos;
        private $activo_tabla_vehiculos = 1;
        private $combustible;
        private $carroceria;
        private $km;
        private $cajacambios;
        private $matriculacion;
        private $color_principal_literal;
        private $color_principal;
        private $color_comercial;
        private $ano_fabricacion ;
        private $papelera = 0;
        private $garantia;
        private $itv_ultima;
        private $precio_venta;
        private $venta_total_sin_dto;
        private $venta_total;
        private $venta_dto_imp;
        private $venta_dto_prc;
        private $venta_base;
        private $venta_tipo_iva;
        private $venta_minimo;
        private $precio_compra;
        private $precio_compra_total;
        private $precio_compra_base;
        private $compra_tipo_iva;
        private $potencia;
        private $estado;
        private $itv_proxima;
        private $velocidades;
        private $llaves;
        private $codigo_radio;
        private $codigo_navegador;
        private $importacion;
        private $otros_equip;
        private $reserva;
        private $distintivo_ambiental;
        private $num_not;
        private $mantenimiento_sellado;
        private $tipo_seguro;
        private $rebu;
        private $motor_cc;
        private $alta;
        private $baja;
        private $destacado_venta_vo;
        private $ubic_direccion;
        private $eurotax;
        private $stock;
        private $ubic_poblacion;
        private $ubic_provincia;
        private $procedencia;
        private $notas;
        private $importacion_excel;
        private $manual;
        private $libro_mant;
        private $gastos_gestion;
        private $precio_compra_pff;
        private $precio_venta_pff;

        private $tipo_precios_extra;
        private $base_precios_extra;
        private $dto_imp_precios_extra;
        private $dto_prc_precios_extra;
        private $total_sin_dto_precios_extra;
        private $total_precios_extra;
        private $limite_precios_extra;

        private $vehiculo_notas;
        private $nota_vehiculos_notas;
        private $codigo_tas_vehiculos_notas;
        private $variable_tas_vehiculos_notas;

        public function __construct($con){
            $this->con = $con;
        }

        public function getCarData($codigo){
            global $lg;
            /* $uno = 1;
            $dos = 2;
            $tipo = 'VO'; */
            $sql = "SELECT DISTINCT V.CODIGO AS CODIGO_COCHE, V.IDCAR AS ID_CAR, V.MARCA AS M, V.MODELO AS VEHMOD, V.*,
            P1.TOTAL AS TOTAL_FINANCIADO, P1.TOTALSINDTO AS TOTAL_SIN_DTO_FINANCIADO, P1.BASE AS BASE_FINANCIADO, P1.DTOIMP AS DTOIMP_FINANCIADO, P1.DTOPRC AS DTOPOR_FINANCIADO, P1.LIMITE AS LIMITE_FINANCIADO,
            P2.TOTAL AS TOTAL_PRO, P2.TOTALSINDTO AS TOTAL_SIN_DTO_PRO, P2.BASE AS BASE_PRO, P2.DTOIMP AS DTOIMP_PRO, P2.DTOPRC AS DTOPOR_PRO, P2.LIMITE AS LIMITE_PRO,
            L5.EXTRA1, PR.DESCRIPCION AS PROVINCIA, CI.POBLACION AS CIUDAD, CODE_EXT,
            M.DESCRIPCION AS MARCAS,
            MO.DESCRIPCION AS MODELOS,
            S.DESCRIPCION AS VEHICULO_STOCK,
            L1.DESCRIPCION_$lg AS DESCRIPCION_LG1,
            L2.DESCRIPCION_$lg AS DESCRIPCION_LG2,
            L3.DESCRIPCION_$lg AS DESCRIPCION_LG3,
            L5.DESCRIPCION_$lg AS DESCRIPCION_LG5,
            L6.DESCRIPCION_$lg AS DESCRIPCION_LG6,
            L8.DESCRIPCION_$lg AS DESCRIPCION_LG8
            FROM (((((((((((((VEHICULOS V
            LEFT JOIN VEHICULOS_MARCAS M ON M.CODIGO = V.MARCA)
            LEFT JOIN VEHICULOS_MODELOS MO ON MO.CODIGO = V.MODELO)
            LEFT JOIN VEHICULOS_LITERALES L1 ON L1.CODIGO = V.COMBUSTIBLE AND L1.TIPO = 'TIP_COM')
            LEFT JOIN VEHICULOS_LITERALES L2 ON L2.CODIGO = V.CAJACAMBIOS AND L2.TIPO = 'TIP_CAJ')
            LEFT JOIN VEHICULOS_LITERALES L3 ON L3.CODIGO = V.CARROCERIA AND L3.TIPO = 'TIP_CAR')
            LEFT JOIN VEHICULOS_LITERALES L5 ON L5.CODIGO = V.COLOR_PRINCIPAL AND L5.TIPO = 'COL_PRI')
            LEFT JOIN VEHICULOS_LITERALES L6 ON L6.CODIGO = V.PROCEDENCIA AND L6.TIPO = 'TIP_PRO')
            LEFT JOIN VEHICULOS_LITERALES L8 ON L8.CODIGO = V.DISTINTIVO_AMB AND L8.TIPO = 'DIS_AMB')
            LEFT JOIN VEHICULOS_PRECIOSEXTRAS P1 ON V.CODIGO = P1.CODIGO AND P1.TIPO = ?)
            LEFT JOIN VEHICULOS_PRECIOSEXTRAS P2 ON V.CODIGO = P2.CODIGO AND P2.TIPO = ?)
            LEFT JOIN COMUN_PROVINCIAS PR ON V.UBIC_POBLACION = PR.CODIGO)
            LEFT JOIN COMUN_CIUDADES CI ON V.UBIC_PROVINCIA = CI.CODIGO)
            LEFT JOIN VEHICULOS_STOCKS S ON V.STOCK = S.CODIGO)
            WHERE V.ACTIVO = ?
            AND V.TIPO = ?
            AND V.CODIGO = ?";
            $stmt = $this->con->prepare($sql);
            $stmt->bind_param('iiisi', $this->nr_1, $this->nr_2, $this->nr_1, $this->tipo, $codigo);
            $stmt->execute();
            $res = $stmt->get_result();
            if($res->num_rows)
            {
                $row = $res->fetch_assoc();
                return $row;
            }
            else
            {
                return FALSE;
            }
        }

        public function set_codigo_vehiculo_tabla_vehiculos ($codigo_vehiculo_tabla_vehiculos) {
            $this->codigo_vehiculo_tabla_vehiculos = $codigo_vehiculo_tabla_vehiculos;
            return $this;
        }
        public function get_codigo_vehiculo_tabla_vehiculos () {
            return $this->codigo_vehiculo_tabla_vehiculos;
        }
        public function set_usuario_session ($usuario_session) {
            $this->usuario_session = $usuario_session;
            return $this;
        }
        public function get_usuario_session () {
            return $this->usuario_session;
        }
        public function set_tipo ($tipo) {
            $this->tipo = $tipo;
            return $this;
        }
        public function get_tipo () {
            return $this->tipo;
        }
        public function set_id_car ($id_car) {
            $this->id_car = $id_car;
            return $this;
        }
        public function get_id_car () {
            return $this->id_car;
        }
        public function set_marca ($marca_tabla_vehiculos) {
            $this->marca_tabla_vehiculos = $marca_tabla_vehiculos;
            return $this;
        }
        public function get_marca () {
            return $this->marca_tabla_vehiculos;
        }
        public function set_modelo ($modelo_tabla_vehiculos) {
            $this->modelo_tabla_vehiculos = $modelo_tabla_vehiculos;
            return $this;
        }
        public function get_modelo () {
            return $this->modelo_tabla_vehiculos;
        }
        public function set_version ($version_tabla_vehiculos) {
            $this->version_tabla_vehiculos = $version_tabla_vehiculos;
            return $this;
        }
        public function get_version () {
            return $this->version_tabla_vehiculos;
        }
        public function set_mostrar ($mostrar_tabla_vehiculos) {
            $this->mostrar_tabla_vehiculos = $mostrar_tabla_vehiculos;
            return $this;
        }
        public function get_mostrar () {
            return $this->mostrar_tabla_vehiculos;
        }
        public function set_matricula ($matricula_tabla_vehiculos) {
            $this->matricula_tabla_vehiculos = $matricula_tabla_vehiculos;
            return $this;
        }
        public function get_matricula () {
            return $this->matricula_tabla_vehiculos;
        }
        public function set_bastidor ($bastidor_tabla_vehiculos) {
            $this->bastidor_tabla_vehiculos = $bastidor_tabla_vehiculos;
            return $this;
        }
        public function get_bastidor () {
            return $this->bastidor_tabla_vehiculos;
        }
        public function set_activo ($activo_tabla_vehiculos) {
            $this->activo_tabla_vehiculos = $activo_tabla_vehiculos;
            return $this;
        }
        public function get_activo () {
            return $this->activo_tabla_vehiculos;
        }
        public function set_combustible ($combustible) {
            $this->combustible = $combustible;
            return $this;
        }
        public function get_combustible () {
            return $this->combustible;
        }
        public function set_carroceria ($carroceria) {
            $this->carroceria = $carroceria;
            return $this;
        }
        public function get_carroceria () {
            return $this->carroceria;
        }
        public function set_km ($km) {
            $this->km = $km;
            return $this;
        }
        public function get_km () {
            return $this->km;
        }
        public function set_cajacambios ($cajacambios) {
            $this->cajacambios = $cajacambios;
            return $this;
        }
        public function get_cajacambios () {
            return $this->cajacambios;
        }
        public function set_matriculacion ($matriculacion) {
            $this->matriculacion = $matriculacion;
            return $this;
        }
        public function get_matriculacion () {
            return $this->matriculacion;
        }
        public function set_color_principal ($color_principal) {
            $this->color_principal = $color_principal;
            return $this;
        }
        public function get_color_principal () {
            return $this->color_principal;
        }
        public function set_color_comercial ($color_comercial) {
            $this->color_comercial = $color_comercial;
            return $this;
        }
        public function get_color_comercial () {
            return $this->color_comercial;
        }
        public function set_color_principal_literal ($color_principal_literal) {
            $this->color_principal_literal = $color_principal_literal;
            return $this;
        }
        public function get_color_principal_literal () {
            return $this->color_principal_literal;
        }
        public function set_ano_fabricacion ($ano_fabricacion) {
            $this->ano_fabricacion = $ano_fabricacion;
            return $this;
        }
        public function get_ano_fabricacion () {
            return $this->ano_fabricacion;
        }
        public function set_papelera ($papelera) {
            $this->papelera = $papelera;
            return $this;
        }
        public function get_papelera () {
            return $this->papelera;
        }
        public function set_garantia ($garantia) {
            $this->garantia = $garantia;
            return $this;
        }
        public function get_garantia () {
            return $this->garantia;
        }
        public function set_itv_ultima ($itv_ultima) {
            $this->itv_ultima = $itv_ultima;
            return $this;
        }
        public function get_itv_ultima () {
            return $this->itv_ultima;
        }
        public function set_precio_venta_pff ($precio_venta_pff) {
            $this->precio_venta_pff = $precio_venta_pff;
            return $this;
        }
        public function get_precio_venta_pff () {
            return $this->precio_venta_pff;
        }
        public function set_precio_venta ($precio_venta) {
            $this->precio_venta = $precio_venta;
            return $this;
        }
        public function get_precio_venta () {
            return $this->precio_venta;
        }
        public function set_venta_total_sin_dto ($venta_total_sin_dto) {
            $this->venta_total_sin_dto = $venta_total_sin_dto;
            return $this;
        }
        public function get_venta_total_sin_dto () {
            return $this->venta_total_sin_dto;
        }
        public function set_venta_total ($venta_total) {
            $this->venta_total = $venta_total;
            return $this;
        }
        public function get_venta_total () {
            return $this->venta_total;
        }
        public function set_venta_dto_imp ($venta_dto_imp) {
            $this->venta_dto_imp = $venta_dto_imp;
            return $this;
        }
        public function get_venta_dto_imp () {
            return $this->venta_dto_imp;
        }
        public function set_venta_dto_prc ($venta_dto_prc) {
            $this->venta_dto_prc = $venta_dto_prc;
            return $this;
        }
        public function get_venta_dto_prc () {
            return $this->venta_dto_prc;
        }
        public function set_venta_base ($venta_base) {
            $this->venta_base = $venta_base;
            return $this;
        }
        public function get_venta_base () {
            return $this->venta_base;
        }
        public function set_venta_financiado ($venta_financiado) {
            $this->venta_financiado = $venta_financiado;
            return $this;
        }
        public function set_venta_tipo_iva ($venta_tipo_iva) {
            $this->venta_tipo_iva = $venta_tipo_iva;
            return $this;
        }
        public function get_venta_tipo_iva () {
            return $this->venta_tipo_iva;
        }
        public function set_venta_minimo ($venta_minimo) {
            $this->venta_minimo = $venta_minimo;
            return $this;
        }
        public function get_venta_minimo () {
            return $this->venta_minimo;
        }
        public function set_precio_compra ($precio_compra) {
            $this->precio_compra = $precio_compra;
            return $this;
        }
        public function get_precio_compra () {
            return $this->precio_compra;
        }
        public function set_precio_compra_total ($precio_compra_total) {
            $this->precio_compra_total = $precio_compra_total;
            return $this;
        }
        public function get_precio_compra_total () {
            return $this->precio_compra_total;
        }
        public function set_precio_compra_base ($precio_compra_base) {
            $this->precio_compra_base = $precio_compra_base;
            return $this;
        }
        public function get_precio_compra_base () {
            return $this->precio_compra_base;
        }
        public function set_precio_compra_pff ($precio_compra_pff) {
            $this->precio_compra_pff = $precio_compra_pff;
            return $this;
        }
        public function get_precio_compra_pff () {
            return $this->precio_compra_pff;
        }
        public function set_compra_tipo_iva ($compra_tipo_iva) {
            $this->compra_tipo_iva = $compra_tipo_iva;
            return $this;
        }
        public function get_compra_tipo_iva () {
            return $this->compra_tipo_iva;
        }
        public function set_potencia ($potencia) {
            $this->potencia = $potencia;
            return $this;
        }
        public function get_potencia () {
            return $this->potencia;
        }
        public function set_estado ($estado) {
            $this->estado = $estado;
            return $this;
        }
        public function get_estado () {
            return $this->estado;
        }
        public function set_itv_proxima ($itv_proxima) {
            $this->itv_proxima = $itv_proxima;
            return $this;
        }
        public function get_itv_proxima () {
            return $this->itv_proxima;
        }
        public function set_velocidades ($velocidades) {
            $this->velocidades = $velocidades;
            return $this;
        }
        public function get_velocidades () {
            return $this->velocidades;
        }
        public function set_llaves ($llaves) {
            $this->llaves = $llaves;
            return $this;
        }
        public function get_llaves () {
            return $this->llaves;
        }
        public function set_codigo_radio ($codigo_radio) {
            $this->codigo_radio = $codigo_radio;
            return $this;
        }
        public function get_codigo_radio () {
            return $this->codigo_radio;
        }
        public function set_codigo_navegador ($codigo_navegador) {
            $this->codigo_navegador = $codigo_navegador;
            return $this;
        }
        public function get_codigo_navegador () {
            return $this->codigo_navegador;
        }
        public function set_importacion ($importacion) {
            $this->importacion = $importacion;
            return $this;
        }
        public function get_importacion () {
            return $this->importacion;
        }
        public function set_otros_equip ($otros_equip) {
            $this->otros_equip = $otros_equip;
            return $this;
        }
        public function get_otros_equip () {
            return $this->otros_equip;
        }
        public function set_reserva ($reserva) {
            $this->reserva = $reserva;
            return $this;
        }
        public function get_reserva () {
            return $this->reserva;
        }
        public function set_distintivo_ambiental ($distintivo_ambiental) {
            $this->distintivo_ambiental = $distintivo_ambiental;
            return $this;
        }
        public function get_distintivo_ambiental () {
            return $this->distintivo_ambiental;
        }
        public function set_num_not ($num_not) {
            $this->num_not = $num_not;
            return $this;
        }
        public function get_num_not () {
            return $this->num_not;
        }
        public function set_mantenimiento_sellado ($mantenimiento_sellado) {
            $this->mantenimiento_sellado = $mantenimiento_sellado;
            return $this;
        }
        public function get_mantenimiento_sellado () {
            return $this->mantenimiento_sellado;
        }
        public function set_tipo_seguro ($tipo_seguro) {
            $this->tipo_seguro = $tipo_seguro;
            return $this;
        }
        public function get_tipo_seguro () {
            return $this->tipo_seguro;
        }
        public function set_rebu ($rebu) {
            $this->rebu = $rebu;
            return $this;
        }
        public function get_rebu () {
            return $this->rebu;
        }
        public function set_motor_cc ($motor_cc) {
            $this->motor_cc = $motor_cc;
            return $this;
        }
        public function get_motor_cc () {
            return $this->motor_cc;
        }
        public function set_alta ($alta) {
            $this->alta = $alta;
            return $this;
        }
        public function get_alta () {
            return $this->alta;
        }
        public function set_baja ($baja) {
            $this->baja = $baja;
            return $this;
        }
        public function get_baja () {
            return $this->baja;
        }
        public function set_destacado_venta_vo ($destacado_venta_vo) {
            $this->destacado_venta_vo = $destacado_venta_vo;
            return $this;
        }
        public function get_destacado_venta_vo () {
            return $this->destacado_venta_vo;
        }
        public function set_ubic_direccion ($ubic_direccion) {
            $this->ubic_direccion = $ubic_direccion;
            return $this;
        }
        public function get_ubic_direccion () {
            return $this->ubic_direccion;
        }
        public function set_eurotax ($eurotax) {
            $this->eurotax = $eurotax;
            return $this;
        }
        public function get_eurotax () {
            return $this->eurotax;
        }
        public function set_stock ($stock) {
            $this->stock = $stock;
            return $this;
        }
        public function get_stock () {
            return $this->stock;
        }
        public function set_ubic_poblacion ($ubic_poblacion) {
            $this->ubic_poblacion = $ubic_poblacion;
            return $this;
        }
        public function get_ubic_poblacion () {
            return $this->ubic_poblacion;
        }
        public function set_ubic_provincia ($ubic_provincia) {
            $this->ubic_provincia = $ubic_provincia;
            return $this;
        }
        public function get_ubic_provincia () {
            return $this->ubic_provincia;
        }
        public function set_procedencia ($procedencia) {
            $this->procedencia = $procedencia;
            return $this;
        }
        public function get_procedencia () {
            return $this->procedencia;
        }
        public function set_notas ($notas) {
            $this->notas = $notas;
            return $this;
        }
        public function get_notas () {
            return $this->notas;
        }
        public function set_importacion_excel ($importacion_excel) {
            $this->importacion_excel = $importacion_excel;
            return $this;
        }
        public function get_importacion_excel () {
            return $this->importacion_excel;
        }
        public function set_manual ($manual) {
            $this->manual = $manual;
            return $this;
        }
        public function get_manual () {
            return $this->manual;
        }
        public function set_libro_mant ($libro_mant) {
            $this->libro_mant = $libro_mant;
            return $this;
        }
        public function get_libro_mant () {
            return $this->libro_mant;
        }
        public function set_gastos_gestion ($gastos_gestion) {
            $this->gastos_gestion = $gastos_gestion;
            return $this;
        }
        public function get_gastos_gestion () {
            return $this->gastos_gestion;
        }

        public function insert_vehiculo () {
            $Schema = new Schema($this->con);
            date_default_timezone_set('Europe/Madrid');

            $codigo_vehiculo = $this->get_codigo_vehiculo_tabla_vehiculos();
            $usuario_session = $this->get_usuario_session();
            $tipo = $this->get_tipo();
            $id_car = $this->get_id_car();
            $marca = $this->get_marca();
            $modelo = $this->get_modelo();
            $version = $this->get_version();
            $mostrar = $this->get_mostrar();
            $matricula = $this->get_matricula();
            $bastidor = $this->get_bastidor();
            $activo = $this->get_activo();
            $combustible = $this->get_combustible();
            $carroceria = $this->get_carroceria();
            $km = $this->get_km();
            $cajacambios = $this->get_cajacambios();
            $matriculacion = $this->get_matriculacion();
            $color_principal = $this->get_color_principal();
            $color_comercial = $this->get_color_comercial();
            $ano_fabricacion = $this->get_ano_fabricacion();
            $papelera = $this->get_papelera();
            $garantia = $this->get_garantia();
            $itv_ultima = $this->get_itv_ultima();
            $precio_venta = $this->get_precio_venta();
            $precio_venta_pff = $this->get_precio_venta_pff();
            $venta_total_sin_dto = $this->get_venta_total_sin_dto();
            $venta_total = $this->get_venta_total();
            $venta_dto_imp = $this->get_venta_dto_imp();
            $venta_dto_prc = $this->get_venta_dto_prc();
            $venta_base = $this->get_venta_base();
            $venta_tipo_iva = $this->get_venta_tipo_iva();
            $venta_minimo = $this->get_venta_minimo();
            $precio_compra = $this->get_precio_compra();
            $precio_compra_total = $this->get_precio_compra_total();
            $precio_compra_base = $this->get_precio_compra_base();
            $precio_compra_pff = $this->get_precio_compra_pff();
            $compra_tipo_iva = $this->get_compra_tipo_iva();
            $potencia = $this->get_potencia();
            $estado = $this->get_estado();
            $itv_proxima = $this->get_itv_proxima();
            $color_principal_literal = $this->get_color_principal_literal();
            $llaves = $this->get_llaves();
            $velocidades = $this->get_velocidades();
            $codigo_radio = $this->get_codigo_radio();
            $codigo_navegador = $this->get_codigo_navegador();
            $otros_equip = $this->get_otros_equip();
            $importacion = $this->get_importacion();
            $distintivo_ambiental = $this->get_distintivo_ambiental();
            $reserva = $this->get_reserva();
            $num_not = $this->get_num_not();
            $mantenimiento_sellado = $this->get_mantenimiento_sellado();
            $tipo_seguro = $this->get_tipo_seguro();
            $rebu = $this->get_rebu();
            $motor_cc = $this->get_motor_cc();
            $eurotax = $this->get_eurotax();
            $notas = $this->get_notas();
            $importacion_excel = $this->get_importacion_excel();
            $manual = $this->get_manual();
            $libro_mant = $this->get_libro_mant();
            $gastos_gestion = $this->get_gastos_gestion() ? $this->get_gastos_gestion() : 0;
            $stock = $this->get_stock();
            $ubic_poblacion = $this->get_ubic_poblacion();
            $now = date('Y-m-d H:i:s');
            $valores_obligatorios = [$codigo_vehiculo, $usuario_session, $tipo, $id_car];

            if (in_array(NULL, $valores_obligatorios)) {
                return FALSE;
            } else {
                $sql = 'INSERT INTO VEHICULOS(CODIGO, USUARIO, TIPO, IDCAR, MARCA, MODELO, VERSION, MOSTRAR, MATRICULA, BASTIDOR, ACTIVO, ALTA, COMBUSTIBLE, CARROCERIA, KM, CAJACAMBIOS, MATRICULACION, COLOR_PRINCIPAL, COLOR_COMERCIAL, ANO_FAB, PAPELERA, GARANTIA, ITV_ULTIMA, PRECIO_VENTA, VENTA_TOTALSINDTO, VENTA_TOTAL, VENTA_DTOIMP, VENTA_DTOPRC, VENTA_BASE, VENTA_TIPOIVA, VENTA_MINIMO, PRECIO_COMPRA, COMPRA_TOTAL, COMPRA_BASE, COMPRA_TIPOIVA, POTENCIA, ESTADO, ITV_PROXIMA, COLORPRI_LIT, VELOCIDADES, LLAVES, CODIGO_RAD, CODIGO_NAV, IMPORTACION, OTROS_EQUIP, RESERVA, DISTINTIVO_AMB, NUMNOT, MANT_SELLADO, TIPO_SEGURO, REBU, MOTOR, EUROTAX, NOTAS, IMPORTACION_EXCEL, MANUAL, LIBRO_MANT, GASTOS_GESTION, STOCK, UBIC_POBLACION, COMPRA_PFF, VENTA_PFF) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
                
                $Schema->executeQuery($sql, 'isssiissssisiiiisiiiiisdddddddddddiisssiiisissiiiiisssiiiiiiii', [$codigo_vehiculo, $usuario_session, $tipo, $id_car, $marca, $modelo, $version, $mostrar, $matricula, $bastidor, $activo, $now, $combustible, $carroceria, $km, $cajacambios, $matriculacion, $color_principal, $color_comercial, $ano_fabricacion, $papelera, $garantia, $itv_ultima, $precio_venta, $venta_total_sin_dto, $venta_total, $venta_dto_imp, $venta_dto_prc, $venta_base, $venta_tipo_iva, $venta_minimo, $precio_compra, $precio_compra_total, $precio_compra_base, $compra_tipo_iva, $potencia, $estado, $itv_proxima, $color_principal_literal, $velocidades, $llaves, $codigo_radio, $codigo_navegador, $importacion, $otros_equip, $reserva, $distintivo_ambiental, $num_not, $mantenimiento_sellado, $tipo_seguro, $rebu, $motor_cc, $eurotax, $notas, $importacion_excel, $manual, $libro_mant, $gastos_gestion, $stock, $ubic_poblacion, $precio_compra_pff, $precio_venta_pff]);


                return true;  
            }

            

        }

        public function update_vehiculo () {
            $Schema = new Schema($this->con);
            date_default_timezone_set('Europe/Madrid');
            $codigo_vehiculo = $this->get_codigo_vehiculo_tabla_vehiculos();

            $condition = ' CODIGO = ? ';
            $type = 'i';
            $variables = [$this->get_codigo_vehiculo_tabla_vehiculos()];
            
            if(isset($this->marca_tabla_vehiculos)) {
                $condition .= ',MARCA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_marca());
            }
            if(isset($this->modelo_tabla_vehiculos)) {
                $condition .= ',MODELO = ? ';
                $type .= 'i';
                array_push($variables, $this->get_modelo());
            }
            if(isset($this->version_tabla_vehiculos)) {
                $condition .= ',VERSION = ? ';
                $type .= 's';
                array_push($variables, $this->get_version());
            }
            if(isset($this->mostrar_tabla_vehiculos)) {
                $condition .= ',MOSTRAR = ? ';
                $type .= 's';
                array_push($variables, $this->get_mostrar());
            }
            if(isset($this->matricula_tabla_vehiculos)) {
                $condition .= ',MATRICULA = ? ';
                $type .= 's';
                array_push($variables, $this->get_matricula());
            }
            if(isset($this->bastidor_tabla_vehiculos)) {
                $condition .= ',BASTIDOR = ? ';
                $type .= 's';
                array_push($variables, $this->get_bastidor());
            }
            if(isset($this->activo_tabla_vehiculos)) {
                $condition .= ',ACTIVO = ? ';
                $type .= 'i';
                array_push($variables, $this->get_activo());
            }
            if(isset($this->combustible)) {
                $condition .= ',COMBUSTIBLE = ? ';
                $type .= 'i';
                array_push($variables, $this->get_combustible());
            }
            if(isset($this->carroceria)) {
                $condition .= ',CARROCERIA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_carroceria());
            }
            if(isset($this->km)) {
                $condition .= ',KM = ? ';
                $type .= 'i';
                array_push($variables, $this->get_km());
            }
            if(isset($this->cajacambios)) {
                $condition .= ',CAJACAMBIOS = ? ';
                $type .= 'i';
                array_push($variables, $this->get_cajacambios());
            }
            if(isset($this->matriculacion)) {
                $condition .= ',MATRICULACION = ? ';
                $type .= 's';
                array_push($variables, $this->get_matriculacion());
            }
            if(isset($this->color_principal)) {
                $condition .= ',COLOR_PRINCIPAL = ? ';
                $type .= 'i';
                array_push($variables, $this->get_color_principal());
            }
            if(isset($this->color_comercial)) {
                $condition .= ',COLOR_COMERCIAL = ? ';
                $type .= 'i';
                array_push($variables, $this->get_color_comercial());
            }
            if(isset($this->ano_fabricacion)) {
                $condition .= ',ANO_FAB = ? ';
                $type .= 'i';
                array_push($variables, $this->get_ano_fabricacion());
            }
            if(isset($this->papelera)) {
                $condition .= ',PAPELERA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_papelera());
            }
            if(isset($this->garantia)) {
                $condition .= ',GARANTIA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_garantia());
            }
            if(isset($this->itv_ultima)) {
                $condition .= ',ITV_ULTIMA = ? ';
                $type .= 's';
                array_push($variables, $this->get_itv_ultima());
            }
            if(isset($this->precio_venta)) {
                $condition .= ',PRECIO_VENTA = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_venta());
            }
            if(isset($this->precio_venta_pff)) {
                $condition .= ', VENTA_PFF = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_venta_pff());
            }
            if(isset($this->venta_total_sin_dto)) {
                $condition .= ',VENTA_TOTALSINDTO = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_total_sin_dto());
            }
            if(isset($this->venta_total)) {
                $condition .= ',VENTA_TOTAL = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_total());
            }
            if(isset($this->venta_dto_imp)) {
                $condition .= ',VENTA_DTOIMP = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_dto_imp());
            }
            if(isset($this->venta_dto_prc)) {
                $condition .= ',VENTA_DTOPRC = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_dto_prc());
            }
            if(isset($this->venta_base)) {
                $condition .= ',VENTA_BASE = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_base());
            }
            if(isset($this->venta_tipo_iva)) {
                $condition .= ',VENTA_TIPOIVA = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_tipo_iva());
            }
            if(isset($this->venta_minimo)) {
                $condition .= ',VENTA_MINIMO = ? ';
                $type .= 'd';
                array_push($variables, $this->get_venta_minimo());
            }
            if(isset($this->precio_compra)) {
                $condition .= ',PRECIO_COMPRA = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_compra());
            }
            if(isset($this->precio_compra_total)) {
                $condition .= ',COMPRA_TOTAL = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_compra_total());
            }
            if(isset($this->precio_compra_base)) {
                $condition .= ',COMPRA_BASE = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_compra_base());
            }
            if(isset($this->precio_compra_pff)) {
                $condition .= ',COMPRA_PFF = ? ';
                $type .= 'd';
                array_push($variables, $this->get_precio_compra_pff());
            }
            if(isset($this->compra_tipo_iva)) {
                $condition .= ',COMPRA_TIPOIVA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_compra_tipo_iva());
            }
            if(isset($this->potencia)) {
                $condition .= ',POTENCIA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_potencia());
            }
            if(isset($this->estado)) {
                $condition .= ', ESTADO = ? ';
                $type .= 's';
                array_push($variables, $this->get_estado());
            }
            if(isset($this->itv_proxima)) {
                $condition .= ',ITV_PROXIMA = ? ';
                $type .= 's';
                array_push($variables, $this->get_itv_proxima());
            }
            if(isset($this->color_principal_literal)) {
                $condition .= ',COLORPRI_LIT = ? ';
                $type .= 's';
                array_push($variables, $this->get_color_principal_literal());
            }
            if(isset($this->llaves)) {
                $condition .= ',LLAVES = ? ';
                $type .= 'i';
                array_push($variables, $this->get_llaves());
            }
            if(isset($this->velocidades)) {
                $condition .= ',VELOCIDADES = ? ';
                $type .= 'i';
                array_push($variables, $this->get_velocidades());
            }
            if(isset($this->codigo_radio)) {
                $condition .= ',CODIGO_RAD = ? ';
                $type .= 'i';
                array_push($variables, $this->get_codigo_radio());
            }
            if(isset($this->codigo_navegador)) {
                $condition .= ',CODIGO_NAV = ? ';
                $type .= 's';
                array_push($variables, $this->get_codigo_navegador());
            }
            if(isset($this->otros_equip)) {
                $condition .= ',OTROS_EQUIP = ? ';
                $type .= 's';
                array_push($variables, $this->get_otros_equip());
            }
            if(isset($this->importacion)) {
                $condition .= ',IMPORTACION = ? ';
                $type .= 'i';
                array_push($variables, $this->get_importacion());
            }
            if(isset($this->distintivo_ambiental)) {
                $condition .= ',DISTINTIVO_AMB = ? ';
                $type .= 'i';
                array_push($variables, $this->get_distintivo_ambiental());
            }
            if(isset($this->reserva)) {
                if(empty($this->reserva)) {
                    $condition .= ', RESERVA = NULL ';
                } else {
                    $condition .= ', RESERVA = ? ';
                    $type .= 's';
                    array_push($variables, $this->get_reserva());
                }
            }
            if(isset($this->num_not)) {
                $condition .= ',NUMNOT = ? ';
                $type .= 'i';
                array_push($variables, $this->get_num_not());
            }
            if(isset($this->mantenimiento_sellado)) {
                $condition .= ',MANT_SELLADO = ? ';
                $type .= 'i';
                array_push($variables, $this->get_mantenimiento_sellado());
            }
            if(isset($this->tipo_seguro)) {
                $condition .= ',TIPO_SEGURO = ? ';
                $type .= 'i';
                array_push($variables, $this->get_tipo_seguro());
            }
            if(isset($this->rebu)) {
                $condition .= ',REBU = ? ';
                $type .= 'i';
                array_push($variables, $this->get_rebu());
            }
            if(isset($this->motor_cc)) {
                $condition .= ',MOTOR = ? ';
                $type .= 's';
                array_push($variables, $this->get_motor_cc());
            }
            if(isset($this->alta)) {
                $condition .= ',ALTA = ? ';
                $type .= 's';
                array_push($variables, $this->get_alta());
            }
            if(isset($this->baja)) {
                $condition .= ',BAJA = ? ';
                $type .= 's';
                array_push($variables, $this->get_baja());
            }
            if(isset($this->destacado_venta_vo)) {
                $condition .= ',DESTACADO_VENTA_VO = ? ';
                $type .= 'i';
                array_push($variables, $this->get_baja());
            }
            if(isset($this->ubic_direccion)) {
                $condition .= ', UBIC_DIRECCION = ? ';
                $type .= 's';
                array_push($variables, $this->get_ubic_direccion());
            }
            if(isset($this->eurotax)) {
                $condition .= ', EUROTAX = ? ';
                $type .= 's';
                array_push($variables, $this->get_eurotax());
            }
            if(isset($this->stock)) {
                $condition .= ', STOCK = ? ';
                $type .= 'i';
                array_push($variables, $this->get_stock());
            }
            if(isset($this->ubic_poblacion)) {
                $condition .= ', UBIC_POBLACION = ? ';
                $type .= 'i';
                array_push($variables, $this->get_ubic_poblacion());
            }
            if(isset($this->ubic_provincia)) {
                $condition .= ', UBIC_PROVINCIA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_ubic_provincia());
            }
            if(isset($this->procedencia)) {
                $condition .= ', PROCEDENCIA = ? ';
                $type .= 'i';
                array_push($variables, $this->get_procedencia());
            }
            if(isset($this->notas)) {
                $condition .= ', NOTAS = ? ';
                $type .= 's';
                array_push($variables, $this->get_notas());
            }
            if(isset($this->manual)) {
                $condition .= ', MANUAL = ? ';
                $type .= 'i';
                array_push($variables, $this->get_manual());
            }
            if(isset($this->libro_mant)) {
                $condition .= ', LIBRO_MANT = ? ';
                $type .= 'i';
                array_push($variables, $this->get_libro_mant());
            }
            if(isset($this->gastos_gestion)) {
                $condition .= ', GASTOS_GESTION = ? ';
                $type .= 'i';
                array_push($variables, $this->get_gastos_gestion());
            }
            if(isset($this->importacion_excel)) {
                $condition .= ', IMPORTACION_EXCEL = ? ';
                $type .= 'i';
                array_push($variables, $this->get_importacion_excel());
            }
            

            $condition .= 'WHERE CODIGO = ?';
            $type .= 'i';
            array_push($variables, $codigo_vehiculo);
            $Schema->executeQuery('UPDATE VEHICULOS SET ' . $condition, $type, $variables); 

            
        }

        public function set_tipo_precios_extra ($tipo_precios_extra) {
            $this->tipo_precios_extra = $tipo_precios_extra;
            return $this;
        }
        public function get_tipo_precios_extra () {
            return $this->tipo_precios_extra;
        }
        public function set_base_precios_extra ($base_precios_extra) {
            $this->base_precios_extra = $base_precios_extra;
            return $this;
        }
        public function get_base_precios_extra () {
            return $this->base_precios_extra;
        }
        public function set_dto_imp_precios_extra ($dto_imp_precios_extra) {
            $this->dto_imp_precios_extra = $dto_imp_precios_extra;
            return $this;
        }
        public function get_dto_imp_precios_extra () {
            return $this->dto_imp_precios_extra;
        }
        public function set_dto_prc_precios_extra ($dto_prc_precios_extra) {
            $this->dto_prc_precios_extra = $dto_prc_precios_extra;
            return $this;
        }
        public function get_dto_prc_precios_extra () {
            return $this->dto_prc_precios_extra;
        }
        public function set_total_sin_dto_precios_extra ($total_sin_dto_precios_extra) {
            $this->total_sin_dto_precios_extra = $total_sin_dto_precios_extra;
            return $this;
        }
        public function get_total_sin_dto_precios_extra () {
            return $this->total_sin_dto_precios_extra;
        }
        public function set_total_precios_extra ($total_precios_extra) {
            $this->total_precios_extra = $total_precios_extra;
            return $this;
        }
        public function get_total_precios_extra () {
            return $this->total_precios_extra;
        }
        public function set_limite_precios_extra ($limite_precios_extra) {
            $this->limite_precios_extra = $limite_precios_extra;
            return $this;
        }
        public function get_limite_precios_extra () {
            return $this->limite_precios_extra;
        }

        public function insert_precios_extra () {
            $Schema = new Schema($this->con);

            $codigo_vehiculo = $this->get_codigo_vehiculo_tabla_vehiculos();
            $tipo_precios_extra = $this->get_tipo_precios_extra();
            $base_precios_extra = $this->get_base_precios_extra();
            $dto_imp_precios_extra = $this->get_dto_imp_precios_extra();
            $dto_prc_precios_extra = $this->get_dto_prc_precios_extra();
            $total_sin_dto_precios_extra = $this->get_total_sin_dto_precios_extra();
            $total_precios_extra = $this->get_total_precios_extra();
            $limite_precios_extra = $this->get_limite_precios_extra();

            $sql = 'INSERT INTO VEHICULOS_PRECIOSEXTRAS(CODIGO, TIPO, BASE, DTOIMP, DTOPRC, TOTALSINDTO, TOTAL, LIMITE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)';
            $Schema->executeQuery($sql, 'iiddddds', [$codigo_vehiculo, $tipo_precios_extra, $base_precios_extra, $dto_imp_precios_extra, $dto_prc_precios_extra, $total_sin_dto_precios_extra, $total_precios_extra, $limite_precios_extra]);
        }

        public function update_precios_extra () {
            $Schema = new Schema($this->con);

            $condition = ' CODIGO = ? ';
            $type = 'i';
            $variables = [$this->get_codigo_vehiculo_tabla_vehiculos()];

            if(isset($this->base_precios_extra)) {
                $condition .= ',BASE = ? ';
                $type .= 'd';
                array_push($variables, $this->get_base_precios_extra());
            }
            if(isset($this->dto_imp_precios_extra)) {
                $condition .= ',DTOIMP = ? ';
                $type .= 'd';
                array_push($variables, $this->get_dto_imp_precios_extra());
            }
            if(isset($this->dto_prc_precios_extra)) {
                $condition .= ',DTOPRC = ? ';
                $type .= 'd';
                array_push($variables, $this->get_dto_prc_precios_extra());
            }
            if(isset($this->total_sin_dto_precios_extra)) {
                $condition .= ',TOTALSINDTO = ? ';
                $type .= 'd';
                array_push($variables, $this->get_total_sin_dto_precios_extra());
            }
            if(isset($this->total_precios_extra)) {
                $condition .= ',TOTAL = ? ';
                $type .= 'd';
                array_push($variables, $this->get_total_precios_extra());
            }
            if(isset($this->limite_precios_extra)) {
                $condition .= ',LIMITE = ? ';
                $type .= 's';
                array_push($variables, $this->get_limite_precios_extra());
            }
            $condition .= 'WHERE CODIGO = ? AND TIPO = ?';
            $type .= 'ii';
            array_push($variables, $this->get_codigo_vehiculo_tabla_vehiculos());
            array_push($variables, $this->get_tipo_precios_extra());


            $Schema->executeQuery('UPDATE VEHICULOS_PRECIOSEXTRAS SET ' . $condition, $type, $variables);
        }

        public function set_vehiculo_notas_extra ($vehiculo_notas) {
            $this->vehiculo_notas = $vehiculo_notas;
            return $this;
        }
        public function get_vehiculo_notas_extra () {
            return $this->vehiculo_notas;
        }
        public function set_nota_vehiculos_notas_extra ($nota_vehiculos_notas) {
            $this->nota_vehiculos_notas = $nota_vehiculos_notas;
            return $this;
        }
        public function get_nota_vehiculos_notas_extra () {
            return $this->nota_vehiculos_notas;
        }
        public function set_codigo_tas_vehiculos_notas_extra ($codigo_tas_vehiculos_notas) {
            $this->codigo_tas_vehiculos_notas = $codigo_tas_vehiculos_notas;
            return $this;
        }
        public function get_codigo_tas_vehiculos_notas_extra () {
            return $this->codigo_tas_vehiculos_notas;
        }
        public function set_variable_tas_notas_extra ($variable_tas_vehiculos_notas) {
            $this->variable_tas_vehiculos_notas = $variable_tas_vehiculos_notas;
            return $this;
        }
        public function get_variable_tas_notas_extra () {
            return $this->variable_tas_vehiculos_notas;
        }
        public function insert_vehiculos_notas() {
            $Schema = new Schema($this->con);
            date_default_timezone_set('Europe/Madrid');
            $now = date('Y-m-d H:i:s');

            $max = $this->con->query('SELECT MAX(POS) AS MAX FROM VEHICULOS_NOTAS')->fetch_array();
            $max = $max['MAX'] + 1;

            if(!isset($this->nota_vehiculos_notas)) {
                return FALSE;
            } else {
                $condition = 'CLAVE, POS, FECHA, USUARIO, NOTA';
                $question = '?, ?, ?, ?, ?';
                $type = 'iisss';
                $values = [nl2br($this->get_vehiculo_notas_extra()), $max, $now, $this->get_usuario_session(), $this->get_nota_vehiculos_notas_extra()];

                if(isset($this->codigo_tas_vehiculos_notas)) {
                    $condition .= ', CODIGO_TAS';
                    $question .= ', ?';
                    $type .= 's';
                    array_push($values, $this->get_codigo_tas_vehiculos_notas_extra());
                }
                if(isset($this->variable_tas_vehiculos_notas)) {
                    $condition .= ', VARIABLE_TAS';
                    $question .= ', ?';
                    $type .= 's';
                    array_push($values, $this->get_variable_tas_notas_extra());
                }
                $Schema->ExecuteQuery("INSERT INTO VEHICULOS_NOTAS ($condition) VALUES($question)", $type, $values);
            }

            return TRUE;
        }

        public function marca_modelo($style = FALSE, $label = FALSE, $label_2 = FALSE, $icono = FALSE, $required = TRUE, $select_marca = FALSE, $select_modelo = FALSE){
        //$style = col, margin etc
        //$label & $Label_2 == ture =>label
        //$icono == true se activa el icono en el label 
        //$required por defecto viene true lo que resulta que los input necesitan una acción
        //select_marca y select_modelo son para dejar seleccionadas las opciones si el vehiculo existe en las bbdd
            global $elige_la_marca_lg;
            global $elige_el_modelo_lg;
            global $marca_lg;
            global $modelo_lg;
            global $campo_obligatorio_lg;

            $required = !$required ? '' : 'required';
            $star_required =  $required ? '*' : '';

            $style = !$style ? 'col-md-3 col-12 mb-3' : $style;
            $icono_1 = $icono ? '<i class="fas fa-car-alt text-muted"></i>' : '';
            $label = $label ? '<label for="validation_marca">' . $icono_1 . ' ' . $marca_lg . $star_required . '</label>' : '';
            $icono_2 = $icono ? '<i class="fas fa-car text-muted"></i>' : '';
            $label_2 = $label_2 ? '<label for="validation_modelo">' . $icono_2 . ' ' . $modelo_lg . $star_required . '</label>' : '';
        
            
            $html = '<div class="' . $style . '">';
                $html .= $label;
                $html .= '<select name="marca" class="custom-select" id="validation_marca" ' . $required . '>';
                    $html .= '<option value="">' . $elige_la_marca_lg . '</option>';
                    $sql = "SELECT M.CODIGO, M.DESCRIPCION FROM VEHICULOS_MARCAS M WHERE M.ACTIVO = 1 ORDER BY DESCRIPCION ASC";
                    $res = $this->con->query($sql);
                    while($fila = $res->fetch_array())
                    {
                        if( $fila['CODIGO'] != 0) {
                            $selected_marca = $select_marca == $fila['CODIGO']? 'selected' : '';
                        } else {
                            $select_marca = '';
                        }
                        $html .= '<option value="' . $fila['CODIGO'] . '" ' . $selected_marca . '>' . $fila['DESCRIPCION'] . '</option>';
                    }
                $html .= '</select>';
                $html .= '<div class="invalid-feedback">';
                    $html .= $campo_obligatorio_lg;
                $html .= '</div>';
            $html .= '</div>';

            $html .= '<div class="' . $style . '">';
                $html .= $label_2;
                $html .= '<select name="modelo" class="custom-select" id="validation_modelo" ' . $required . '>';
                    if ($select_modelo) {
                        $res = $this->con->query('SELECT M.DESCRIPCION FROM VEHICULOS_MODELOS M WHERE M.ACTIVO = 1 AND M.CODIGO = ' . $select_modelo . ' ORDER BY DESCRIPCION ASC');
                        $fila = $res->fetch_array();
                        $html .= '<option value="' . $select_modelo . '">' . $fila['DESCRIPCION'] . '</option>';
                    } else {
                        $html .= '<option value="">' . $elige_el_modelo_lg . '</option>';
                    }
                $html .= '</select>';
                $html .= '<div class="invalid-feedback">';
                    $html .= $campo_obligatorio_lg;
                $html .= '</div>';
            $html .= '</div>';

            return $html;
            
        }
        
        //OBSOLETO=======================================================================================================================================================
        public function slider ($codigo_vehiculo, $style_controllers = FALSE, $ruta = FALSE) {
            $Schema = new Schema($this->con);
            $img = '';
            $imgSlider = '';

            $res = $Schema->executeQuery('SELECT LINK, ORDEN FROM VEHICULOS_MULTIMEDIA_LINKS WHERE VEHICULO = ? AND TIPO = ?', 'ii', [$codigo_vehiculo, 1]);
            if($res->num_rows) {
                while($row = $res->fetch_array()) {
                    $active = $row['ORDEN'] == 1 ? 'active' : '';
                    $img .= '<div class="carousel-item div-sorting ' . $active . '">';
                        $img .= '<img src="' . $row['LINK'] . '" class="img-fit" width="100%">';
                    $img .= '</div>';
                    $imgSlider .= '<div class="carousel-item ' . $active . '">';
                        $imgSlider .= '<img src="' . $row['LINK'] . '" class="img-fit" width="100%">';
                    $imgSlider .= '</div>';
                }
            } else {
                $style_controllers = $style_controllers ? $style_controllers : 'text-white';
                $ruta = $ruta ? $ruta : 'tmp_img/';
                $ESQUEMA = $Schema->select_esquema_o_esquema_estructura(TRUE); 
                $GRUPO = $Schema->select_esquema_o_esquema_estructura(); 
                $GRUPOE_TIPO = $Schema->select_esquema_estructura_valores('TIPO',$ESQUEMA);
                $LISTA = $Schema->select_esquema_estructura_valores('TIPO', $ESQUEMA, 'LISTA');

                $sql_codigo_etiqueta = "SELECT CODIGO FROM ETIQUETAS WHERE GRUPO = $LISTA AND DESCRIPCION = 'FOTO'";
                $res_codigo_etiqueta = $this->con->query($sql_codigo_etiqueta);
                $row_codigo_etiqueta = $res_codigo_etiqueta->fetch_array(); 
                $ETIQUETA = $row_codigo_etiqueta['CODIGO'];
                $GRUPOE_PUBLICABLE = $Schema->select_esquema_estructura_valores('PUBLICABLE', $ESQUEMA);

                $sql = "SELECT E.CLAVE, E.NOMBRE, E.SUFIJO, E.PARTES, E.POS
                FROM BIBLIOTECA_ELEMENTOS E INNER JOIN BIBLIOTECA_ETIQUETAS T1 ON E.CLAVE = T1.CLAVE
                INNER JOIN BIBLIOTECA_ETIQUETAS T2 ON E.CLAVE = T2.CLAVE
                INNER JOIN BIBLIOTECA_ETIQUETAS T3 ON E.CLAVE = T3.CLAVE
                WHERE T1.ESQUEMA = ? AND T1.GRUPOE = ? AND T1.ETIQUETA = ?
                AND T2.ESQUEMA = ? AND T2.GRUPOE = ? AND T2.ETIQUETA = ?
                AND T3.ESQUEMA = ? AND T3.GRUPOE = ? AND T3.ETIQUETA = ?
                AND E.PAPELERA = ?
                AND E.CLAVE NOT IN (SELECT DOCUMENTO FROM VEHICULOS_TASACIONES_DOCS) ORDER BY E.POS ASC";
                $res = $Schema->executeQuery($sql, 'iiiiiiiiii', [$ESQUEMA, $GRUPO, $codigo_vehiculo, $ESQUEMA, $GRUPOE_TIPO, $ETIQUETA, $ESQUEMA, $GRUPOE_PUBLICABLE, 1, 0]);
                if($res->num_rows) {
                    while($row = $res->fetch_array()) {
                        $tmp_file = $ruta . $row['NOMBRE'];
                        $Schema->create_file($tmp_file, $row['PARTES'], $row['SUFIJO'], $row['CLAVE']);
                        $active = $row['POS'] == 1 ? 'active' : '';
                        
                        $img .= '<div class="carousel-item div-sorting ' . $active . '">';
                            $img .= '<img src="' . $tmp_file . '" class="img-fit" width="100%" alt="' . $row['NOMBRE'] . '">';
                        $img .= '</div>';
                        $imgSlider .= '<div class="carousel-item ' . $active . '">';
                            $imgSlider .= '<img src="' . $tmp_file . '" class="img-fit" width="100%" alt="' . $row['NOMBRE'] . '">';
                        $imgSlider .= '</div>';

                    }
                } else {
                    $img .= '<div class="carousel-item active border text-center p-5 mt-4">';
                        $img .= '<i class="fas fa-image fa-10x text-muted p-5 m-5"></i>';
                    $img .= '</div>';
                    $imgSlider .= '<div class="carousel-item active border text-center p-5 mt-4">';
                        $imgSlider .= '<i class="fas fa-image fa-10x text-muted p-5 m-5"></i>';
                    $imgSlider .= '</div>';
                }
            }

            $html = '<div id="carouselExampleIndicators" class="carousel slide carousel-fade">';
                $html .= '<div class="carousel-inner" data-ride="carousel" data-toggle="modal" data-target=".bd-example-modal-xl-slider-car">';
                    $html .= $img;
                $html .= '</div>';
                $html .= '<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">';
                    $html .= '<i class="fas fa-chevron-left ' . $style_controllers . '" aria-hidden="true"></i>';
                    $html .= '<span class="sr-only">Previous</span>';
                $html .= '</a>';
                $html .= '<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">';
                    $html .= '<i class="fas fa-chevron-right ' . $style_controllers . '" aria-hidden="true"></i>';
                    $html .= '<span class="sr-only">Next</span>';
                $html .= '</a>';
            $html .= '</div>';

            $html .= '<div class="modal fade bd-example-modal-xl-slider-car" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">';
            $html .= '<div class="modal-dialog modal-xl">';
                $html .= '<div class="modal-content">';
                    $html .= '<div id="carouselExampleIndicatorsModal" class="carousel slide carousel-fade">'; 
                        $html .= '<div class="carousel-inner" data-ride="carousel">';
                            $html .= $imgSlider;
                        $html .= '</div>';
                            $html .= '<a class="carousel-control-prev" href="#carouselExampleIndicatorsModal" role="button" data-slide="prev">';
                                $html .= '<i class="fas fa-chevron-left text-white" aria-hidden="true"></i>';
                                $html .= '<span class="sr-only">Previous</span>';
                            $html .= '</a>';
                            $html .= '<a class="carousel-control-next" href="#carouselExampleIndicatorsModal" role="button" data-slide="next">';
                                $html .= '<i class="fas fa-chevron-right text-white" aria-hidden="true"></i>';
                                $html .= '<span class="sr-only">Next</span>';
                            $html .= '</a>';
                        $html .= '</div>';
                    $html .= '</div>';
                $html .= '</div>';
            $html .= '</div>';

            return $html;
        }
        //=================================================================================================================================================================================================================
        public function listadoVehiculoFicha($titulo1, $icono1 = NULL, $info1, $titulo2 = NULL, $icono2 = NULL, $info2 = NULL, $style = FALSE){
        //public function listadoVehiculoFicha($titulo1, $info1, $icono1 = NULL, $titulo2 = NULL, $icono2 = NULL, $info2 = NULL, $style = FALSE){
            
            $iconoFirst = !empty($icono1) ? '<i class="fas fa-' . $icono1 . ' mr-2"></i>' : '';
            

            $style = $style ? $style : 'text-muted';

            $html = '<li class="list-group-item d-flex justify-content-between lh-condensed ' . $style . '">';
                $html .= '<div class="my-1  text-left">';
                    $html .= '<h6 class="my-1">' . $titulo1 .'</h6>';
                    $html .= '<h6 class="font-weight-normal">' . $iconoFirst . $info1 . '</h6>';
                $html .= '</div>';

                if($titulo2)
                {
                    $html .= '<div class="my-1 text-right">';
                        $html .= '<h6 class="my-1">' . $titulo2 .'</h6>';
                        $html .= '<h6 class="font-weight-normal"><i class="fas fa-' . $icono2 . ' mr-2"></i>' . $info2 . '</h6>';
                    $html .= '</div>';
                }
            $html .= '</li>';

            echo $html;
        }

        public function listado_vehiculo_lista_horizontal($titulo_categoria, $info_categoria, $style = FALSE) {

            $style = $style ? $style : 'bg-white';
            $html = '<li class="list-group-item d-flex justify-content-between lh-condensed ' . $style . '">';
                $html .= '<h6 class="my-1 text-muted">' . $titulo_categoria . '</h6>';
                $html .= '<span class="text-muted">' . $info_categoria . '</span>';
            $html .= '</li>';

            echo $html;
        }

        public function car_price ($venta_total, $total_sindto, $tag = FALSE) {

            $html = '';
            if($venta_total == 0) {
                $venta_total = $total_sindto;
            }
            elseif($venta_total != $total_sindto) {
                $html .= '<span class="d-block text-danger"><i class="fas fa-tag fa-sm mr-1"></i><strike>' . number_format($total_sindto, '2', '.', ',') . '</strike></span>';
            }
            if ($tag) {
                $tag = explode('#', $tag);
                $tag1 = $tag[0] . ' ' . $tag[1];
                $tag2 = $tag[0];
            } else {
                $tag1 = $tag2 = 'span';
            }

            
            $html .= '<' . $tag1 . '>' . number_format($venta_total,'2','.',',') . '</' . $tag2 . '>';


            return $html;

        }

        public function selectLiterales ($id, $label = FALSE, $tipo_literal, $select = NULL, $required = FALSE, $firstOption = FALSE) {
            //$id = id y name
            //$label = nombre etiqueta
            //$tipo = tipo de litarales
            //$selected seleccionar una opcion
            global $lg;
            global $elige_lg;
            global $campo_obligatorio_lg;

            $required = $required ? 'required' : '';
            $elige = $firstOption ? $firstOption : $elige_lg;
            

            $html = $label ? '<label for="' . $id . '">' . $label . '</label>' : '';
            $html .= '<select class="custom-select" id="' . $id . '" name="' . $id . '" ' . $required . '>';
                $sql = "SELECT VEHICULOS_LITERALES.*, DESCRIPCION_$lg AS DESCRIPCION_LG FROM VEHICULOS_LITERALES WHERE TIPO = '$tipo_literal' ORDER BY CODIGO";
                $res = $this->con->query($sql);
                $html .= '<option value="">' . $elige . '</option>';
                while($fila = $res->fetch_array())
                {
                    $selected = $fila['CODIGO'] == $select ? 'selected' : '';
                    $html .= '<option value="' . $fila['CODIGO'] . '" ' . $selected . '>' . $fila['DESCRIPCION_LG'] . '</option>';
                }
            $html .= '</select>';
            $html .= '<div class="invalid-tooltip">' . $campo_obligatorio_lg . '</div>';

            return $html;
        }

        public function equipamiento () {
            //global $lg;
            $html = '';

            if(isset($this->codigo_vehiculo_tabla_vehiculos)) {
                /* $codigos_predefinidos = [7, 8, 9, 10, 13, 19, 17, 24]; */
                $codigo_coche = $this->get_codigo_vehiculo_tabla_vehiculos();
                $sql = "SELECT E.CODIGO, E.DESCRIPCION, O.OPCION
                FROM VEHICULOS_EQUIPAMIENTOS E
                LEFT JOIN VEHICULOS_OPCIONES O ON E.CODIGO = O.OPCION
                AND O.VEHICULO = $codigo_coche";
                $res = $this->con->query($sql);
                $nr = 0;
                while($fila = $res->fetch_array())
                {
                    $nr++;
                    $checked = $fila['OPCION'] != NULL ? 'checked' : FALSE;
                    /* $checked = in_array($fila['CODIGO'], $codigos_predefinidos) ? 'checked' : FALSE; */
                    $html .= '<div class="col-md-4 mb-3">';
                        $html .= '<div class="custom-control custom-checkbox">';
                            $html .= '<input type="checkbox" name="equipamiento[]" value="' . $fila['CODIGO'] .'" class="custom-control-input" id="customCheck' . $nr .'" ' . $checked . '>';
                            $html .= '<label class="custom-control-label text-muted" for="customCheck' . $nr .'">' . $fila['DESCRIPCION'] .'</label>';
                        $html .= '</div>';
                    $html .= '</div>';
                }
            } else {
                $sql = "SELECT E.* FROM VEHICULOS_EQUIPAMIENTOS E";
                $res = $this->con->query($sql);
                $nr = 0;
                while($fila = $res->fetch_array())
                {
                    $nr++;
                    $html .= '<div class="col-md-4 mb-3">';
                        $html .= '<div class="custom-control custom-checkbox">';
                            $html .= '<input type="checkbox" name="equipamiento[]" value="' . $fila['CODIGO'] .'" class="custom-control-input" id="customCheck' . $nr .'">';
                            $html .= '<label class="custom-control-label text-muted" for="customCheck' . $nr .'">' . $fila['DESCRIPCION'] .'</label>';
                        $html .= '</div>';
                    $html .= '</div>';
                }
            }

            return $html;
        }

        public function nombre_vehiculo($marca, $modelo, $separador = FALSE) {
            $separador = $separador ? $separador : " - ";
            $sql = "SELECT M.DESCRIPCION AS M_DESC, MO.DESCRIPCION AS MO_DESC
            FROM VEHICULOS_MARCAS M
            INNER JOIN VEHICULOS_MODELOS MO ON M.CODIGO = MO.MARCA
            WHERE M.CODIGO = ? AND MO.CODIGO = ?";
            $stmt = $this->con->prepare($sql);
            $stmt->bind_param('ii',$marca,$modelo);
            $stmt->execute();
            $res = $stmt->get_result();
            $fila = $res->fetch_array();
            $mostrar = strtoupper($fila['M_DESC']) . $separador . strtoupper($fila['MO_DESC']);
            return $mostrar;
        }

        public function construir_mostrar_vehiculo ($id_car, $marca_codigo, $modelo_codigo, $matricula) {
            $sql = "SELECT M.DESCRIPCION AS M_DESC, MO.DESCRIPCION AS MO_DESC
            FROM VEHICULOS_MARCAS M
            INNER JOIN VEHICULOS_MODELOS MO ON M.CODIGO = MO.MARCA
            WHERE M.CODIGO = ? AND MO.CODIGO = ?";
            $stmt = $this->con->prepare($sql);
            $stmt->bind_param('ii', $marca_codigo, $modelo_codigo);
            $stmt->execute();
            $res = $stmt->get_result();
            $fila = $res->fetch_array();
            $mostrar = $id_car . " - " .strtoupper($fila['M_DESC']) . " - " . strtoupper($fila['MO_DESC']) . " - " . $matricula;
            return $mostrar;
        }

        public function smartFind($condition, $string) {
            $response = [];
            $i = 0;
            $score = 0;
            //$Schema = new Schema($this->con);
            $res = $this->con->query($condition);
            if($res->num_rows) {
                while($row = $res->fetch_assoc()) {
                    $i++;
                    $searchScore = Statics::StringsScore($row['DESCRIPTIONS'], $string);
                    if($score <= $searchScore) {
                       $response['key'] = $row['CODIGO'];
                       $response['title'] = $row['DESCRIPTIONS'];
                    }
                }
            }
            return $response;
        }

        public function StringsScore($str1, $str2) {
            similar_text($str1, $str2, $firstScore);//get a first comparation between strings 
            if($firstScore >= 80) {// if is almost a perfect match return this score
                $score = strlen($str1) == strlen($str2) ? 100 : $firstScore;
            } else {
                
                $new = [];//new array
                $str = preg_replace('/[^a-zA-Z0-9]/', ' ', $str1);//Get rid of non alphanumeric caracters
                $origin = explode(' ', $str);//Convert first string into array to compare, in case string contains more than 1 word
                $str2 = strtoupper($str2);//Convert second string to uppercase
                $str2 = str_replace('NUEVO', '', $str2);//Get rid of this word
                $str2 = preg_replace('/[^a-zA-Z0-9]/', ' ', $str2);//Get rid of non alphanumeric caracters
                $str2 = preg_replace('/\s+/', ' ', $str2);//Remain with only one space between words
                $str2 = $str2 == 'MB' ? 'MERCEDES BENZ' : $str2;//Check if string is mb and change to Mercedes benz
                $explode = explode(' ', $str2);//Convert second string into array to compare
                for($i = 0; $i <= count($explode) - 1; $i++) {
                    for($j = 0; $j <= count($origin) - 1; $j++) {
                        similar_text($explode[$i], $origin[$j], $score);//Get score of words comparation
                        if($score >= 70) {
                            array_push($new, $explode[$i]);//Create a new array for all words that score more than 70%
                        }
                    }
                }
                sort($origin);//Order to increment the score
                sort($new);//Order to increment the score
                similar_text(implode(' ', $origin), implode(' ', $new), $score);//Get the final score

                $score = $score;
            }

            return $score;
        }

        public function smart_score($str1, $str2) {
            $str1 = strtoupper($str1);
            $str2 = strtoupper($str2);
            $str2 = trim($str2); // Remove spaces from start and end
            $str2 = $str2 == 'MB' ? 'MERCEDES-BENZ' : $str2;
            $str2 = $str2 == 'ELECTRICO ENCHUFABLE' ? 'ELÉCTRICO ENCHUFABLE' : $str2;
            $str2 = $str2 == 'CITROEN' ? 'CITROËN' : $str2;
            $str2 = $str2 == 'CITROEN' ? 'CITROËN' : $str2;
            $str2 = str_replace('NEW', '', $str2);
            $str2 = str_replace('NUEVO', '', $str2);
            $str2 = preg_replace('/[^a-zA-Z0-9]/', ' ', $str2);
            $str2 = preg_replace('/\s+/', ' ', $str2);
            $str1 = preg_replace('/[^a-zA-Z0-9]/', ' ', $str1);
    
            $firstString = explode(' ', $str1);
            sort($firstString);
            $secondString = explode(' ', $str2);
            sort($secondString);
            $show = '';
            $new = [];
            for($i = 0; $i <= count($secondString) - 1; $i++) {
                if(isset($firstString[$i])) {
                    similar_text($secondString[$i],$firstString[$i], $score);
                    if($score >= 88) {
                        array_push($new, $firstString[$i]);
                        $show .= $secondString[$i] . " = " . $firstString[$i] . " " . $score . " <br>";
                    }
                }
    
            }
    
            $a = implode(' ', $firstString);
            $b = implode(' ', $new);
            similar_text($a, $b, $s);
    
    
    
           /*  return ['score' => $s, 'title' => $new]; */
            return ['score' => $s, 'title' => $b, 'old_title' => $a];
        }

        public function find_my_code($query, $string, $literales = false) {
            $x = [];

            if(!$literales) {
                while($row = $query->fetch_array()) {
                    $smartSearch = $this->smart_score($row['D'], $string);
                    if($smartSearch['score'] >= 85) {
                        similar_text($string, $smartSearch['title'], $r);
                        $x["$r"] = $row['CODIGO'];
                    }
                }
                if(!empty($x)) {
                    $result = $x[max(array_keys($x))];
                } else {
                    $result = null;
                }
            } else {
                $i = 0;
                $score = 0;
                while($row = $query->fetch_array()) {
                    $i++;
                    $search = $this->StringsScore($row['D'], $string);
                    $lengthUser = strlen($string);
                    if($score <= $search) {
                        $score = $search;
                        $x[0]['score'] = $search;
                        $x[0]['title'] = $row['D'];
                        $x[0]['string'] = $string;
                        $x[0]['lengthUser'] = $lengthUser;
                        $x[0]['id'] = $row['CODIGO'];
                    }
                    
                }
                $result = $x[0]['id'];
            }



            

            return $result;
        }

        //Eurotax================================================
        public function set_client_secret($client_secret) {
            $this->client_secret = $client_secret;
            return $this;
        }
        public function get_client_secret() {
            return $this->client_secret;
        }
        public function set_client_id($client_id) {
            $this->client_id = $client_id;
            return $this;
        }
        public function get_client_id() {
            return $this->client_id;
        }
        public function set_url($url) {
            $this->url = $url;
            return $this;
        }
        public function get_url() {
            return $this->url;
        }
        private function give_keys() {
            $save = false;
            $Schema = new Schema($this->con);
            if(isset($this->codigo_vehiculo_tabla_vehiculos)) {
                $res = $Schema->executeQuery('SELECT V.MARCA, V.MODELO, MO.DESCRIPCION AS MODELOS, V.EUROTAX, V.VERSION 
                FROM VEHICULOS V
                INNER JOIN VEHICULOS_MODELOS MO ON V.MODELO = MO.CODIGO 
                WHERE V.CODIGO = ?', 'i', [$this->get_codigo_vehiculo_tabla_vehiculos()]);
                if($res->num_rows) {
                    $save = $res->fetch_assoc();
                }
            }
            return $save;
        }
        public function make_model_type($codigo_coche = false) {
            //$row['EUROTAX] es el codigo de marca/modelo en eurotax
            //$keys['EUROTAX] es el codigo de eurotax del vehiculos en concreto
            $keys = false;
            //$Schema = new Schema($this->con);
            global $marca_lg;
            global $modelo_lg;
            global $version_lg;
            if($codigo_coche) {
                $this->set_codigo_vehiculo_tabla_vehiculos($codigo_coche);
                $keys = $this->give_keys();
            }
            $html = '<div class="form-group col-12 col-md-6 col-lg-3">';
            $html .= '<label for="make">' . $marca_lg . '</label>';
            $html .= '<select class="form-control" id="make" required>';
            $html .= '<option value="">' . $marca_lg . '</option>';
            $res = $this->con->query('SELECT * FROM VEHICULOS_MARCAS');
            if($res->num_rows) {
                while($row = $res->fetch_array()) {
                    $select = !empty($keys['MARCA']) && ($keys['MARCA'] === $row['CODIGO']) ? 'selected' : false;
                    $html .= '<option value="' . $row['CODIGO'] . '" data-eurotax="' . $row['EUROTAX'] . '" ' . $select . '>' . $row['DESCRIPCION'] . '</option>';
                }
            }
            $html .= '</select>';
            $html .= '</div>';

            $html .= '<div class="form-group col-12 col-md-6 col-lg-3">';
            $html .= '<label for="model">' . $modelo_lg . '</label>';
            $html .= '<select class="form-control" id="model" required>';
            $html .= $keys ? '<option value="' . $keys['MODELO'] . '" data-eurotax="' . $row['EUROTAX'] . '">' . $keys['MODELOS'] . '</option>' : '<option value="">' . $modelo_lg . '</option>';
            $html .= '</select>';
            $html .= '</div>';

            $html .= '<div class="form-group col-12 col-sm-12 col-md-6" id="for-type">';
            $html .= '<label for="type">' . $version_lg . '</label>';
            $html .= '<select class="form-control" id="type" required>';
            $html .= $keys ? '<option data-eurotax="' . $keys['EUROTAX'] . '">' . $keys['VERSION'] . '</option>' : '<option value="">' . $version_lg . '</option>';
            $html .= '</select>';
            $html .= '</div>';
            return $html;
        }
    }