<?php

# HA NINCS ID, AKKOR BEFIZETÉS LISTA
# HA VAN ID, AKKOR BEFIZETÉS ADATINAK MEGTEKINTÉSE/MÓDOSÍTÁSA

if ($this->is_id()) {
    # ADOTT BEFIZETÉS ADATINAK MEGTEKINTÉSE/MÓDOSÍTÁSA
    $mod = new money_deposit();
    $mod->set_mod_data_by_id($this->get_id());

    $user_kid_query = "SELECT * FROM user_kid WHERE uk_is_active = 1 AND uk_deleted = 0 order by uk_name ASC;";
    $user_kid_assoc_array = $sql->assoc_array($user_kid_query);
    $user_kids = array();
    foreach ($user_kid_assoc_array as $key => $value) {
        $new_kid = new user_kid();
        $new_kid->set_user_data_by_id($value['uk_id']);
        $user_kids[] = $new_kid;
    }

    $pt_assoc_array = $sql->assoc_array('SELECT * FROM payment_type ORDER BY pt_id ASC;');

    $l_assoc_array = $sql->assoc_array('SELECT * FROM lease WHERE l_deleted = 0 ORDER BY l_name ASC;');
    $l_array = array();

    foreach ($l_assoc_array as $key => $lease) {
        $new_lease = new lease();
        $new_lease->set_l_data_by_id($lease['l_id']);
        $l_array[] = $new_lease;
    }

    $smarty->assign('lease_array',$l_array);
    $smarty->assign('user_kids', $user_kids);
    $smarty->assign("mod", $mod);
    $smarty->assign('pt_assoc_array', $pt_assoc_array);
    $smarty->display("money_deposit_update.tpl");

}
else {
    # BEFIZETÉS LISTA
    $mod_query = "SELECT * FROM money_deposit JOIN money_income ON mod_money_income_mi_id = mi_id WHERE mod_deleted = 0 ORDER BY mi_date DESC, mi_id DESC;";
    $mod_array = array();
    $mod_assoc_array = $sql->assoc_array($mod_query);

    foreach ($mod_assoc_array as $mod) {
        $new_mod = new money_deposit();
        $new_mod->set_mod_data_by_id($mod['mod_id']);
        $mod_array[] = $new_mod;
    }

    $smarty->assign("mod_array", $mod_array);
    $smarty->display("money_deposit.tpl");

}

?>
