<?php 
class ModelLocalisationGemstoneSales extends Model {
	

	public function editGemstoneSales($order_status_id, $data) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "'");

		$this->db->query("INSERT INTO " . DB_PREFIX . "order_status SET order_status_id = '" . (int)$order_status_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
				
		$this->cache->delete('order_status');
	}	
		
	public function getGemstoneSales($order_status_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "gemstone_sales WHERE gemstone_sales_id = '" . (int)$gemstone_sales_id . "' ");
		
		return $query->row;
	}
		
	public function getGemstoneSales($data = array()) {
      	if ($data) {
			$sql = "SELECT * FROM " . DB_PREFIX . "gemstone_sales WHERE 1=1 ";
			
			$sql .= " ORDER BY Gemstone";	
			
			if (isset($data['order']) && ($data['order'] == 'DESC')) {
				$sql .= " DESC";
			} else {
				$sql .= " ASC";
			}
			
			if (isset($data['start']) || isset($data['limit'])) {
				if ($data['start'] < 0) {
					$data['start'] = 0;
				}				

				if ($data['limit'] < 1) {
					$data['limit'] = 20;
				}	
			
				$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
			}	
			
			$query = $this->db->query($sql);
			
			return $query->rows;
		} else {
			$order_status_data = $this->cache->get('order_status.' . (int)$this->config->get('config_language_id'));
		
			if (!$order_status_data) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "gemstone_sales WHERE  1=1 ORDER BY Gemstone");
	
				$order_status_data = $query->rows;
			
			}	
	
			return $order_status_data;				
		}
	}
	 
	
	public function getTotalGemstoneSales() {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "gemstone_sales WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'");
		
		return $query->row['total'];
	}	
}
?>