<?php

    class Ofertas
    {
        private $con;
        private $codigo;
        private $vehiculo;
        private $usuario;//Usuario conectado
        private $contacto;//Codigo del contacto
        private $importe;//Precio del vehículo
        private $descuento;//Descuento normal
        private $descuento_financiado;//Descuento financiado
        private $subtotal;//Restando los descuento se obtiene este precio
        private $impuesto;//Impuesto en nuemros
        private $iva;//codigo del iva
        private $pvp;//Sumando subtotal y impuestos
        private $gastos_gestion;//Gastos 
        private $importe_oferta;//Importe final
        private $garantia;//Meses de garantía
        private $estado;//Estado de oferta == 1 / pedido == 2 / vendido == 3 
        private $email_envio;//Email del contacto
        private $financiacion;////Precio financiado
        private $observacioens;//Observacioens 
        private $activo;//0/1

        public function __construct($con) {
            $this->con = $con;
        }
        
        public function set_codigo($codigo) {
            $this->codigo = $codigo;
            return $this;
        }
        public function get_codigo() {
            return  $this->codigo;
        }
        public function set_vehiculo($vehiculo) {
            $this->vehiculo = $vehiculo;
            return $this;
        }
        public function get_vehiculo() {
            return  $this->vehiculo;
        }
        public function set_usuario($usuario) {
            $this->usuario = $usuario;
            return $this;
        }
        public function get_usuario() {
            return  $this->usuario;
        }
        public function set_contacto($contacto) {
            $this->contacto = $contacto;
            return $this;
        }
        public function get_contacto() {
            return  $this->contacto;
        }
        public function set_importe($importe) {
            $this->importe = $importe;
            return $this;
        }
        public function get_importe() {
            return  $this->importe;
        }
        public function set_descuento($descuento) {
            $this->descuento = $descuento;
            return $this;
        }
        public function get_descuento() {
            return  $this->descuento;
        }
        public function set_descuento_financiado($descuento_financiado) {
            $this->descuento_financiado = $descuento_financiado;
            return $this;
        }
        public function get_descuento_financiado() {
            return  $this->descuento_financiado;
        }
        public function set_subtotal($subtotal) {
            $this->subtotal = $subtotal;
            return $this;
        }
        public function get_subtotal() {
            return  $this->subtotal;
        }
        public function set_impuesto($impuesto) {
            $this->impuesto = $impuesto;
            return $this;
        }
        public function get_impuesto() {
            return  $this->impuesto;
        }
        public function set_iva($iva) {
            $this->iva = $iva;
            return $this;
        }
        public function get_iva() {
            return  $this->iva;
        }
        public function set_pvp($pvp) {
            $this->pvp = $pvp;
            return $this;
        }
        public function get_pvp() {
            return  $this->pvp;
        }
        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 set_importe_oferta($importe_oferta) {
            $this->importe_oferta = $importe_oferta;
            return $this;
        }
        public function get_importe_oferta() {
            return  $this->importe_oferta;
        }
        public function set_garantia($garantia) {
            $this->garantia = $garantia;
            return $this;
        }
        public function get_garantia() {
            return  $this->garantia;
        }
        public function set_estado($estado) {
            $this->estado = $estado;
            return $this;
        }
        public function get_estado() {
            return  $this->estado;
        }
        public function set_email_envio($email_envio) {
            $this->email_envio = $email_envio;
            return $this;
        }
        public function get_email_envio() {
            return  $this->email_envio;
        }
        public function set_financiacion($financiacion) {
            $this->financiacion = $financiacion;
            return $this;
        }
        public function get_financiacion() {
            return  $this->financiacion;
        }
        public function set_observacioens($observacioens) {
            $this->observacioens = $observacioens;
            return $this;
        }
        public function get_observacioens() {
            return  $this->observacioens;
        }
        public function set_activo($activo) {
            $this->activo = $activo;
            return $this;
        }
        public function get_activo() {
            return  $this->activo;
        }


        public function insert() {
            $Schema = new Schema($this->con);
            $question = '?';//Start without ","
            $values = [
                $this->get_codigo(), 
                $this->get_vehiculo(), 
                $this->get_usuario(), 
                $this->get_contacto(), 
                $this->get_importe(),
                $this->get_descuento(),
                $this->get_descuento_financiado(),
                $this->get_subtotal(),
                $this->get_impuesto(),
                $this->get_iva(),
                $this->get_pvp(),
                $this->get_gastos_gestion(),
                $this->get_importe_oferta(),
                $this->get_garantia(),
                $this->get_estado(),
                $this->get_email_envio(),
                date('Y-m-d H:i:s'),
                $this->get_financiacion(),
                $this->get_observacioens()
            ];
            for($i = 1; $i < count($values); $i++) {
                $question .= ', ?';
            }
            $Schema->executeQuery('INSERT INTO 
            VEHICULOS_OFERTAS(CODIGO, VEHICULO, USUARIO, CONTACTO, IMPORTE_ACTUAL, DESCUENTO, DESCUENTO_FINANCIADO, SUBTOTAL, IMPUESTO, IVA, PVP, GASTOS_GESTION, IMPORTE_OFERTA, GARANTIA, ESTADO, EMAIL_ENVIO, FECHA, FINANCIACION, OBSERVACIONES) 
            VALUES(' . $question . ')', 'sisidddddddddiissis', $values);
        }

        public function update() {
            $Schema = new Schema($this->con);

            $values = [$this->get_estado(), $this->get_codigo()];
            $Schema->executeQuery('UPDATE VEHICULOS_OFERTAS SET ESTADO = ? WHERE CODIGO = ?', 'ii', $values);
        }

        
        
    }

?>