<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Model_Unidades extends CI_Model{

	function __construct(){
		parent::__construct();
	}

	function get_cat_tipo_articulo(){
		$query = $this->db->query("SELECT * FROM cat_tipo_articulo WHERE status='A' ORDER BY descripcion");
		return $query->result();
	}

	function get_cat_marca($pk,$status = TRUE){
		$query = $this->db->query("SELECT cm.pk_cat_marca,cm.descripcion,cm.status 
									FROM cat_marca cm 
									WHERE ".(($status) ? "cm.status='A' and " : "")." cm.fk_subgpo_catalogo=".$pk);
		return $query->result();
	}

	function get_gpo_catalogo($pk,$status = TRUE){
		$query = $this->db->query("SELECT gc.pk_gpo_catalogo,gc.descripcion,gc.status 
									FROM gpo_catalogo gc 
									WHERE ".(($status) ? "gc.status='A' and " : "")." gc.fk_cat_tipo_articulo=".$pk);
		return $query->result();
	}

	function get_subgpo_catalogo($pk,$status = TRUE){
		$query = $this->db->query("SELECT sgc.pk_subgpo_catalogo,sgc.descripcion,sgc.status 
									FROM subgpo_catalogo sgc 
									WHERE ".(($status) ? "sgc.status='A' and " : "")." sgc.fk_gpo_catalogo=".$pk);
		return $query->result();
	}

	function get_cat_modelo($pk){
		$query = $this->db->query("SELECT cmo.pk_cat_modelo,cmo.descripcion,cmo.potencia,cmo.rodada,cmo.anio,cmo.precio,cmo.fk_cat_marca,cmo.status 
									FROM cat_modelo cmo 
									WHERE cmo.fk_cat_marca=".$pk);
		return $query->result();
	}

	function insert($registro,$tabla){
		$this->db->set($registro);
		$this->db->insert($tabla);
	}

	function update($registro,$pk_campo,$tabla){
		$this->db->set($registro);
		$this->db->where($pk_campo,$registro[$pk_campo]);
		$this->db->update($tabla);
	}
	
	function update_status ($pk,$status,$pk_campo,$tabla){
		$registro = array("status" => $status);
		$this->db->where($pk_campo,$pk);
		$this->db->update($tabla,$registro);
	}

	function v_unidades($filtro){
		$query = $this->db->query("SELECT * FROM v_unidades WHERE ".$filtro." ORDER BY descripcion");
		return $query->result();
	}

}