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

class Busquedas extends CI_Controller {

	public function __construct() {
		parent::__construct();
		if (!$this->Usuario->try()) {
			redirect('login');
		}

		$this->load->model('Categoria_model', 'Categoria', true);
	}

	public function index(){
		$s = $this->input->get('s');
		$data['s'] = $s;
		if (!empty($s)) {

			//quitar (ç)
			$s = str_replace("ç", "", $s);

			$data['result']['productos'] = $this->Producto->search($s);
			$data['result']['clientes'] = $this->Cliente->search($s);
			$data['result']['proveedores'] = $this->Proveedor->search($s);
			$data['result']['ventas'] = $this->Venta->search($s);
		}

		$data['distribuidores'] = $this->Proveedor->lista(true);
		$data['categorias'] = $this->Categoria->list();
		$data['ps_productos'] = $this->Producto->ps_list();
		$data['rankings'] = $this->Producto->list_rankings();

		$data = $this->Venta->get_globales($data);
		$data = $this->Producto->get_globales($data);

		$data['title'] = 'Busquedas';
		$data['content'] = $this->load->view('busquedas/index', $data , true);
		$this->load->view('default', $data);
	}
}