<?php
class ModelSaleSketchesMaster extends Model {
	public function addCustomerGroup($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "sketches_master SET sketch_id = '" . $this->db->escape($data['sketch_id']) . "',product_id = '" . $this->db->escape($data['product_id']) . "'");
	}
	
	public function editCustomerGroup($sketch_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "sketches_master SET sketch_id = '" . $this->db->escape($data['sketch_id']) . "' , product_id = '" . $this->db->escape($data['product_id']) . "' WHERE sketch_id = '" . (int)$sketch_id . "'");
	}
	
	public function deleteCustomerGroup($sketch_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "sketches_master WHERE sketch_id = '" . (int)$sketch_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE sketch_id = '" . (int)$sketch_id . "'");
	}
	
	public function getCustomerGroup($sketch_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "sketches_master WHERE sketch_id = '" . (int)$sketch_id . "'");
		
		return $query->row;
	}
	
	public function getproductname($product_id) {
		$query = $this->db->query("SELECT name FROM " . DB_PREFIX . "product_description WHERE language_id=1 and product_id = '" . (int)$product_id . "'");
		
		if(isset($query->row['name']))
		{
		return $query->row['name'];
		} else {
		return '' ;
		}
	}
	
	public function getCustomerGroups($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "sketches_master";
		
		$sql .= " ORDER BY sketch_id";	
			
		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;
	}
	
	public function getproductdetails($data = array()) {
		$sql = "SELECT DISTINCT name , product_id FROM " . DB_PREFIX . "product_description where language_id=1";
		
		$sql .= " ORDER BY product_id";
		
		$query = $this->db->query($sql);
		
		return $query->rows;
	}
	
	public function getTotalCustomerGroups() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "sketches_master");
		
		return $query->row['total'];
	}
}
?>