<?php


class money_income {
	private $mi_id;
	private $mi_date;
	private $mi_item;
	private $mi_sum;
	private $mi_mic_id = null;
	private $mi_mic = null;
	private $mi_payment_type;
	private $mi_deleted;


	public function set_mi_id($_item) {
		$this->mi_id = $_item;
	}

	public function set_mi_date($_item) {
		$this->mi_date = $_item;
	}

	public function set_mi_item($_item) {
		$this->mi_item = $_item;
	}

	public function set_mi_sum($_item) {
		$this->mi_sum = $_item;
	}

	public function set_mi_money_income_category_mic_id($_item) {
		$this->mi_mic_id = $_item;
	}

	public function set_mi_mic($_item) {
		$this->mi_mic = $_item;
	}

	public function set_mi_payment_type_pt_id($_payment_type) {
		$this->mi_payment_type = $_payment_type;
	}

	public function set_mi_deleted($_item) {
		$this->mi_deleted = $_item;
	}

	public function get_mi_id() {
		return $this->mi_id;
	}

	public function get_mi_date($_formatted = false) {
		return !$_formatted ? $this->mi_date : date("Y. m. d.", strtotime($this->mi_date));
	}

	public function get_mi_date_day() {
		$day = date("d", strtotime($this->mi_date));
		if (substr($day, 0, 1) == '0') return substr($day, 1, 1);
		return date("d", strtotime($this->mi_date));
	}

	public function get_mi_item() {
		return $this->mi_item;
	}

	public function get_mi_sum() {
		return $this->mi_sum;
	}

	public function get_mi_mic() {
		return $this->mi_mic;
	}

	public function get_mi_money_income_category_mic_id() {
		return $this->mi_mic_id;
	}

	public function get_mi_payment_type_pt_id() {
		return $this->mi_payment_type;
	}

	public function get_mi_deleted() {
		return $this->mi_deleted;
	}

	public function set_mi_data_by_id($_id) {
		global $sql;
		$set_data_assoc_array = $sql->assoc_array("select * from money_income where mi_id = " . $_id);
		$set_data_array = $set_data_assoc_array[0];
		foreach ($set_data_array as $field => $value) {
			$function_name = "set_" . $field;
			$this->$function_name($value); //alapadatok beállítása

			if ($field == 'mi_money_income_category_mic_id' && $value != null) {
				$new_mic = new money_income_category();
				$new_mic->set_mic_data_by_id($value);
				$this->set_mi_mic($new_mic);
			}
			if ($field == "mi_payment_type") {
				$new_pt = new payment_type();
				$new_pt->set_pt_data_by_id($value);
				$this->set_mi_payment_type_pt_id($new_pt);
			}
		}

	}

	public static function create_money_income($_date, $_item, $_sum, $_mic_id, $_pt) {
		global $sql;

		return $sql->insert_into('money_income', array(
				'mi_date' => $_date,
				'mi_item' => $_item,
				'mi_sum' => $_sum,
				'mi_money_income_category_mic_id' => $_mic_id,
				'mi_payment_type_pt_id' => $_pt
			));
	}

	public static function update_money_income($_date, $_item, $_sum, $_mic_id, $_id, $_pt) {
		global $sql;

		$sql->update_table('money_income',
			array(
				'mi_date' => $_date,
				'mi_item' => $_item,
				'mi_sum' => $_sum,
				'mi_money_income_category_mic_id' => $_mic_id,
				'mi_payment_type_pt_id' => $_pt
			),
			array(
				'mi_id' => $_id
			)


		);
	}
}


?>
