<?php
class ModelSaleDesignDist extends Model {
	public function addSize($data) {
		//$this->db->query("INSERT INTO " . DB_PREFIX . "designer_rewards_distribution SET designer_customer = '" . $this->db->escape($data['designer_customer']) . "',reward_amount = '" . $this->db->escape($data['reward_amount']) . "',payment_date = '" . $this->db->escape($data['payment_date']) . "'");
	}
	
	public function editSize($designer_reward_distribution_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "designer_rewards_distribution SET payment_details = '" . $this->db->escape($data['payment_details']) . "',payment_date = NOW() WHERE designer_reward_distribution_id = '" . (int)$designer_reward_distribution_id . "'");
	}
	
	public function deleteSize($designer_reward_distribution_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "designer_rewards_distribution WHERE designer_reward_distribution_id = '" . (int)$designer_reward_distribution_id . "'");
		
	}
	
	public function getSize($designer_reward_distribution_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "designer_rewards_distribution WHERE designer_reward_distribution_id = '" . (int)$designer_reward_distribution_id . "'");
		
		return $query->row;
	}
	
	public function getSizes($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "designer_rewards_distribution";
		
		$sql .= " ORDER BY designer_reward_distribution_id";	
			
		if (isset($data['order']) && ($data['order'] == 'DESC')) {
			$sql .= " ASC";
		} else {
			$sql .= " DESC";
		}
		
		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 getTotalSizes() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "designer_rewards_distribution");
		
		return $query->row['total'];
	}
}
?>