From 40585222d7dbb8a98f505d8c1f2ada15000c5ced Mon Sep 17 00:00:00 2001 From: Ricsi Date: Sat, 18 Feb 2017 00:14:40 +0100 Subject: [PATCH] balance list can be sorted. balanace can be updated --- _include/include_balance_list.php | 36 ++-- _include/include_money_update.php | 200 ++++++++++++----------- template/templates/user_balance_list.tpl | 8 + 3 files changed, 132 insertions(+), 112 deletions(-) diff --git a/_include/include_balance_list.php b/_include/include_balance_list.php index f913fd9..c90b4d2 100644 --- a/_include/include_balance_list.php +++ b/_include/include_balance_list.php @@ -1,27 +1,37 @@ is_id()) { - # EMPTY + # RENDEZÉS + /* + 1 - egyenleg szerint növekvő + */ + + $order_by = 'uk_balance ASC'; + $url_postfix = '/' . $this->get_id(); } else { # EGYENLEG LISTA - - $active_kid_assoc_array = $sql->assoc_array('select * from user_kid where uk_deleted = 0 and uk_is_active = 1 order by uk_name asc;'); - $user_kids = array(); - foreach ($active_kid_assoc_array as $kid) { - $new_kid = new user_kid(); - $new_kid->set_user_data_by_id($kid['uk_id']); - $user_kids[] = $new_kid; - } - - $smarty->assign('user_kids', $user_kids); - $smarty->display('user_balance_list.tpl'); + $order_by = 'uk_name ASC'; + $url_postfix = ''; } + +$active_kid_assoc_array = $sql->assoc_array('select * from user_kid where uk_deleted = 0 and uk_is_active = 1 order by '. $order_by .';'); +$user_kids = array(); +foreach ($active_kid_assoc_array as $kid) { + $new_kid = new user_kid(); + $new_kid->set_user_data_by_id($kid['uk_id']); + $user_kids[] = $new_kid; +} + +$smarty->assign('user_kids', $user_kids); +$smarty->assign('url_postfix', $url_postfix); +$smarty->display('user_balance_list.tpl'); + ?> \ No newline at end of file diff --git a/_include/include_money_update.php b/_include/include_money_update.php index 12e425a..97fe401 100644 --- a/_include/include_money_update.php +++ b/_include/include_money_update.php @@ -9,28 +9,64 @@ - # EDZÉS LISTA + # EDZÉS LISTA - $action_list_query = " - SELECT - object_id, - timestamp(object_date) as object_date, - object_type, - (SELECT - count(distinct date(tr_date)) - FROM - presence - JOIN - training ON tr_id = pr_training_tr_id - WHERE - YEAR(tr_date) = YEAR(object_date) - AND MONTH(tr_date) = MONTH(object_date) - AND tr_date <= object_date - AND pr_user_kid_uk_id = ".$user->get_uk_id()." - AND tr_date > (select - if(max(trd) is null, - '1900-01-01', - max(trd)) + $action_list_query = " + SELECT + object_id, + timestamp(object_date) as object_date, + object_type, + (SELECT + count(distinct date(tr_date)) + FROM + presence + JOIN + training ON tr_id = pr_training_tr_id + WHERE + YEAR(tr_date) = YEAR(object_date) + AND MONTH(tr_date) = MONTH(object_date) + AND tr_date <= object_date + AND pr_user_kid_uk_id = ".$user->get_uk_id()." + AND tr_date > (select + if(max(trd) is null, + '1900-01-01', + max(trd)) + from + (select + tr_date trd + from + presence + join training ON tr_id = pr_training_tr_id + join user_kid ON uk_id = pr_user_kid_uk_id + where + pr_user_kid_uk_id = ".$user->get_uk_id()." + and tr_date >= (SELECT + tr_date + from + presence + join training ON tr_id = pr_training_tr_id + join user_kid ON uk_id = pr_user_kid_uk_id + where + pr_user_kid_uk_id = ".$user->get_uk_id()." + and date(tr_date) = uk_first_training + ORDER BY tr_date ASC + limit 1) + order by tr_date ASC + limit 2) as elso_ket_edzes)) as 'training_per_month', + (SELECT + count(pr_id) + FROM + presence + JOIN + training ON tr_id = pr_training_tr_id + WHERE + DATE(tr_date) = DATE(object_date) + AND tr_date <= object_date + AND pr_user_kid_uk_id = ".$user->get_uk_id().") as 'training_per_day', + (select + if(sum(if(trd = object_date, 1, 0)) > 0, + 1, + 0) from (select tr_date trd @@ -52,95 +88,61 @@ ORDER BY tr_date ASC limit 1) order by tr_date ASC - limit 2) as elso_ket_edzes)) as 'training_per_month', - (SELECT - count(pr_id) + limit 2) elso2edzes) as 'first_two' FROM - presence - JOIN - training ON tr_id = pr_training_tr_id - WHERE - DATE(tr_date) = DATE(object_date) - AND tr_date <= object_date - AND pr_user_kid_uk_id = ".$user->get_uk_id().") as 'training_per_day', - (select - if(sum(if(trd = object_date, 1, 0)) > 0, - 1, - 0) - from - (select - tr_date trd - from + ((SELECT + pr_training_tr_id as object_id, + timestamp(tr_date) as object_date, + if(pr_training_tr_id is not null, 'training', null) as object_type + FROM presence - join training ON tr_id = pr_training_tr_id - join user_kid ON uk_id = pr_user_kid_uk_id - where + JOIN training ON tr_id = pr_training_tr_id + WHERE pr_user_kid_uk_id = ".$user->get_uk_id()." - and tr_date >= (SELECT - tr_date - from - presence - join training ON tr_id = pr_training_tr_id - join user_kid ON uk_id = pr_user_kid_uk_id - where - pr_user_kid_uk_id = ".$user->get_uk_id()." - and date(tr_date) = uk_first_training - ORDER BY tr_date ASC - limit 1) - order by tr_date ASC - limit 2) elso2edzes) as 'first_two' -FROM - ((SELECT - pr_training_tr_id as object_id, - timestamp(tr_date) as object_date, - if(pr_training_tr_id is not null, 'training', null) as object_type - FROM - presence - JOIN training ON tr_id = pr_training_tr_id - WHERE - pr_user_kid_uk_id = ".$user->get_uk_id()." - AND tr_deleted = 0) UNION (SELECT - mod_id, - timestamp(mod_date), - if(mod_id is not null, 'money_deposit', null) as object_type - FROM - money_deposit - WHERE - mod_user_kid_uk_id = ".$user->get_uk_id()." - and mod_deleted = 0)) actions -order by object_date ASC; - "; + AND tr_deleted = 0) UNION (SELECT + mod_id, + timestamp(mod_date), + if(mod_id is not null, 'money_deposit', null) as object_type + FROM + money_deposit + WHERE + mod_user_kid_uk_id = ".$user->get_uk_id()." + and mod_deleted = 0)) actions + order by object_date ASC; + "; - $action_assoc_array = $sql->assoc_array($action_list_query); + $action_assoc_array = $sql->assoc_array($action_list_query); - $actions = array(); - $de_array = array(); - foreach ($action_assoc_array as $action) { + $actions = array(); + $de_array = array(); + foreach ($action_assoc_array as $action) { - if ($action['object_type'] == 'training') { - $new_training = new training(); - $new_training->set_training_data_by_id($action['object_id']); - //$actions[] = $new_training; - $new_diary_entry = new diary_entry($action['object_id'], $action['object_date'], $action['object_type'], $action['training_per_month'], $action['training_per_day'], $action['first_two'], $new_training); - } - elseif ($action['object_type'] == 'money_deposit') { - $new_mod = new money_deposit(); - $new_mod->set_mod_data_by_id($action['object_id']); - //$actions[] = $new_mod; - $new_diary_entry = new diary_entry($action['object_id'], $action['object_date'], $action['object_type'], $action['training_per_month'], $action['training_per_day'], $action['first_two'], null, $new_mod); - } + if ($action['object_type'] == 'training') { + $new_training = new training(); + $new_training->set_training_data_by_id($action['object_id']); + //$actions[] = $new_training; + $new_diary_entry = new diary_entry($action['object_id'], $action['object_date'], $action['object_type'], $action['training_per_month'], $action['training_per_day'], $action['first_two'], $new_training); + } + elseif ($action['object_type'] == 'money_deposit') { + $new_mod = new money_deposit(); + $new_mod->set_mod_data_by_id($action['object_id']); + //$actions[] = $new_mod; + $new_diary_entry = new diary_entry($action['object_id'], $action['object_date'], $action['object_type'], $action['training_per_month'], $action['training_per_day'], $action['first_two'], null, $new_mod); + } - $de_array[] = $new_diary_entry; + $de_array[] = $new_diary_entry; - } + } - //itt csak hivatkozással adjuk át a tömböt, a calculate_balance kiszámolja, belerakja és visszadja - $user->calculate_balance($de_array, $user); - //var_dump($de_array); - //$smarty->assign('actions', $actions); + //itt csak hivatkozással adjuk át a tömböt, a calculate_balance kiszámolja, belerakja és visszadja + $user->calculate_balance($de_array, $user); + //var_dump($de_array); + //$smarty->assign('actions', $actions); -} + } + + header('Location: /admin/balance_list' . ($this->is_id()?'/'.$this->get_id():'')); ?> \ No newline at end of file diff --git a/template/templates/user_balance_list.tpl b/template/templates/user_balance_list.tpl index bd68b78..238ff0d 100644 --- a/template/templates/user_balance_list.tpl +++ b/template/templates/user_balance_list.tpl @@ -1,3 +1,11 @@ +
+ + Név szerinti rendezés + Egyenleg szerinti rendezés + Egyenleg frissítése + +
+
{foreach $user_kids as $user}