<?php
class ModelSalelaboursettingcost extends Model {
	public function addCustomerGroup($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "laboursettingcost SET setting = '" . $this->db->escape($data['setting']) . "',cost = '" . $this->db->escape($data['cost']) . "',ccurrency = '" . $this->db->escape($data['ccurrency']) . "',supplier_group_id = '" . (int)$data['supplier_group_id'] . "'");
	}
	
	public function editCustomerGroup($setting_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "laboursettingcost SET setting = '" . $this->db->escape($data['setting']) . "',cost = '" . $this->db->escape($data['cost']) . "',ccurrency = '" . $this->db->escape($data['ccurrency']) . "',supplier_group_id = '" . (int)$data['supplier_group_id'] . "' WHERE setting_id = '" . (int)$setting_id . "'");
	}
	
	public function deleteCustomerGroup($setting_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "laboursettingcost WHERE setting_id = '" . (int)$setting_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE setting_id = '" . (int)$setting_id . "'");
	}
	
	public function getCustomerGroup($setting_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "laboursettingcost WHERE setting_id = '" . (int)$setting_id . "'");
		
		return $query->row;
	}
	
	public function getCustomerGroups($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "laboursettingcost";
		
		$sql .= " ORDER BY setting";	
			
		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 . "laboursettingcost");
		
		return $query->row['total'];
	}
}
?>