<?php
ini_set("display_errors", 1);
if (!defined('BASEPATH'))
	exit('No direct script access allowed');


class Md_almacenes extends CI_Model {

	public function getNearby($lat, $long) {
		$otherdb = $this->load->database('cargo', TRUE);
		$otherdb->select('*, (ACOS(COS(RADIANS('.$lat.')) * COS(RADIANS(latitud)) * COS(RADIANS(longitud) - RADIANS('.$long.')) + SIN(RADIANS('.$lat.')) * SIN(RADIANS(latitud)))) / 0.000156961230576 AS distance FROM sucursales_almacenes HAVING distance <= 10 ORDER BY distance ASC');
		$otherdb->limit(5);
		$return = $otherdb->get()->result_array();
		return $return;
	}

	public function getFamilia() {
		$otherdb = $this->load->database('almacenes', TRUE);
		$otherdb->distinct();
		$otherdb->select('familia');
		$otherdb->from('inventario_bot');
		return $otherdb->get()->result_array();
	}

	public function getSubFamilia($boton) {
		$otherdb = $this->load->database('almacenes', TRUE);
		$otherdb->distinct();
		$otherdb->select('subfamilia');
		$otherdb->from('inventario_bot');
		$otherdb->where('familia', $boton);
		return $otherdb->get()->result_array();
	}

	public function getGenerico($boton) {
		$otherdb = $this->load->database('almacenes', TRUE);
		$otherdb->distinct();
		$otherdb->select('generico');
		$otherdb->from('inventario_bot');
		$otherdb->where('subfamilia', $boton);
		return $otherdb->get()->result_array();
	}

	public function getMarca($boton) {
		$otherdb = $this->load->database('almacenes', TRUE);
		$otherdb->distinct();
		$otherdb->select('marca');
		$otherdb->from('inventario_bot');
		$otherdb->where('generico', $boton);
		return $otherdb->get()->result_array();
	}

	public function getProductos($familia,$subfamilia,$generico,$marca) {
		$otherdb = $this->load->database('almacenes', TRUE);
		$otherdb->select('*');
		$otherdb->from('inventario_bot');
		$otherdb->where('familia', $familia);
		$otherdb->where('subfamilia', $subfamilia);
		$otherdb->where('generico', $generico);
		$otherdb->where('marca', $marca);
		return $otherdb->get()->result_array();
	}

}
