<?php

/*
    MONEY_DEPOSIT CLASS
*/

class money_deposit {
    private $mod_id;
    private $mod_user_kid_uk_id; //ID
    private $mod_user_kid; //OBJECT
    private $mod_money_income_mi_id; //ID
    private $mod_money_income; //OBJECT
    private $mod_deleted;
    private $mod_sets_expire_date;

    public function set_mod_id($_id) {
        $this->mod_id = $_id;
    }

    public function set_mod_user_kid_uk_id($_user_kid_uk_id) {
        $this->mod_user_kid_uk_id = $_user_kid_uk_id;
    }

    public function set_mod_user_kid($_user_kid) {
        $this->mod_user_kid = $_user_kid;
    }

    public function set_mod_money_income_mi_id($_money_income_mi_id) {
        $this->mod_money_income_mi_id = $_money_income_mi_id;
    }

    public function set_mod_money_income($_money_income) {
        $this->mod_money_income = $_money_income;
    }

    public function set_mod_deleted($_deleted) {
        $this->mod_deleted = $_deleted;
    }

    public function set_mod_sets_expire_date($_sets_expire_date) {
        $this->mod_sets_expire_date = $_sets_expire_date;
    }

    public function get_mod_id() {
        return $this->mod_id;
    }

    public function get_mod_user_kid_uk_id() {
        return $this->mod_user_kid_uk_id;
    }

    public function get_mod_user_kid() {
        return $this->mod_user_kid;
    }

    public function get_mod_money_income_mi_id() {
        return $this->mod_money_income_mi_id;
    }

    public function get_mod_money_income() {
        return $this->mod_money_income;
    }

    public function get_mod_deleted() {
        return $this->mod_deleted;
    }

    public function get_mod_sets_expire_date() {
        return $this->mod_sets_expire_date;
    }

    public function set_mod_data_by_id($_id) {
        global $sql;
        $mod_query = "SELECT * FROM money_deposit WHERE mod_id = " . $_id . ";";
        $mod_assoc_array = $sql->assoc_array($mod_query);
        //var_dump($mod_assoc_array);
        foreach ($mod_assoc_array[0] as $field => $value) {
            $function_name = "set_" . $field;
            $this->$function_name($value); //alapadatok beállítása
            if ($field == "mod_user_kid_uk_id") {
                $new_user = new user_kid();
                $new_user->set_user_data_by_id($value);
                $this->set_mod_user_kid($new_user);
            }
            if ($field == "mod_money_income_mi_id") {
                $new_mi = new money_income();
                $new_mi->set_mi_data_by_id($value);
                $this->set_mod_money_income($new_mi);
            }
        }
    }

    public static function create_money_deposit($_user_id, $_date, $_sum, $_pt, $_sets_date = false) {
        global $sql;

        $income_id = $sql->insert_into('money_income', array(
                'mi_date' => $_date,
                'mi_payment_type_pt_id' => $_pt,
                'mi_sum' => $_sum,
                'mi_item' => 'Edzésdíj',
                'mi_money_income_category_mic_id' => 4,
            )
        );

        if ($_sets_date) {
            $sql->update_table('user_kid', array(
                'uk_last_deposit' => date('Y-m-d')
            ), array(
                'uk_id' => $_user_id,
            ));
        }

        return $sql->insert_into('money_deposit', array(
            'mod_user_kid_uk_id' => $_user_id,
            'mod_money_income_mi_id' => $income_id,
            'mod_sets_expire_date' => $_sets_date
        ));
    }

    public static function update_money_deposit($_user_id, $_date, $_sum, $_mod_id, $_pt, $_mi_id) {
        global $sql;
        $sql->update_table('money_income', array(
                //'mod_user_kid_uk_id' => $_user_id,
                'mi_date' => $_date,
                'mi_payment_type_pt_id' => $_pt,
                'mi_sum' => $_sum
            ), array(
                'mi_id' => $_mi_id
        ));

        $sql->update_table('money_deposit', array(
                'mod_user_kid_uk_id' => $_user_id,
            ), array(
                'mod_id' => $_mod_id
        ));

    }


}

?>
