<?php
class ModelSaleGemstoneprice extends Model {
	public function addCustomerGroup($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "gemstone_price SET  code = '" . $this->db->escape($data['code']) . "', gemstone_id = '" . $this->db->escape($data['gemstone_id']) . "',lowclarity = '" . $this->db->escape($data['lowclarity']) . "',highclarity = '" . $this->db->escape($data['highclarity']) . "',lowcolour = '" . $this->db->escape($data['lowcolour']) . "',highcolour = '" . $this->db->escape($data['highcolour']) . "',lowweight = '" . $this->db->escape($data['lowweight']) . "',highweight = '" . $this->db->escape($data['highweight']) . "',price = '" . $this->db->escape($data['price']) . "',pricetype = '" . $this->db->escape($data['pricetype']) . "',ccurrency = '" . $this->db->escape($data['ccurrency']) . "',shape = '" . $this->db->escape($data['shape']) . "'");
	}
	 
	public function editCustomerGroup($gemstoneprice_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "gemstone_price SET  code = '" . $this->db->escape($data['code']) . "', gemstone_id = '" . $this->db->escape($data['gemstone_id']) . "',lowclarity = '" . $this->db->escape($data['lowclarity']) . "',highclarity = '" . $this->db->escape($data['highclarity']) . "',lowcolour = '" . $this->db->escape($data['lowcolour']) . "',highcolour = '" . $this->db->escape($data['highcolour']) . "',lowweight = '" . $this->db->escape($data['lowweight']) . "',highweight = '" . $this->db->escape($data['highweight']) . "',pricetype = '" . $this->db->escape($data['pricetype']) . "',price = '" . $this->db->escape($data['price']) . "',ccurrency = '" . $this->db->escape($data['ccurrency']) . "',shape = '" . $this->db->escape($data['shape']) . "' WHERE gemstoneprice_id = '" . (int)$gemstoneprice_id . "'");
	}
	
	public function deleteCustomerGroup($gemstoneprice_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "gemstone_price WHERE gemstoneprice_id = '" . (int)$gemstoneprice_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE gemstoneprice_id = '" . (int)$gemstoneprice_id . "'");
	}
	
	public function getGemStoneInfo($gemstoneprice_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "gemstone_price WHERE gemstoneprice_id = '" . (int)$gemstoneprice_id . "'");
		
		return $query->row;
	}
	
	public function getGemStonePrices($data = array()) {
		$sql = "SELECT a.*,b.gemname  FROM " . DB_PREFIX . "gemstone_price a,gemstone b where a.gemstone_id=b.gemstone_id";
		
		$sql .= " ORDER BY  code";	
			
		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 getTotalCustomerGroups() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "gemstone_price");
		
		return $query->row['total'];
	}
}
?>