From 4fdbccffabdc41379f698bc665c6c3512e0b2cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20Rich=C3=A1rd?= Date: Fri, 4 Oct 2019 19:42:24 +0200 Subject: [PATCH] presence + money update query fix --- _include/include_money_update.php | 165 +++++++++--------------------- _include/include_presence.php | 33 ++++-- template/templates/user_diary.tpl | 2 +- 3 files changed, 75 insertions(+), 125 deletions(-) diff --git a/_include/include_money_update.php b/_include/include_money_update.php index 993f511..ae3d985 100644 --- a/_include/include_money_update.php +++ b/_include/include_money_update.php @@ -9,135 +9,66 @@ $action_list_query = " - SELECT - object_id, - timestamp(object_date) as object_date, - object_type, - (SELECT - count(distinct date(tr_date)) + SELECT + object_id, + TIMESTAMP(object_date) AS object_date, + object_type, + expire_date, + IF(expire_date <= NOW(), 1, 0) AS expired + 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, + NULL AS expire_date FROM presence - JOIN - training ON tr_id = pr_training_tr_id + JOIN training ON (tr_id = pr_training_tr_id + AND tr_locked = 1) 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) + pr_user_kid_uk_id = {$user->get_uk_id()} + AND tr_deleted = 0) UNION (SELECT + mod_id, + TIMESTAMP(mi_date), + IF(mod_id IS NOT NULL, 'money_deposit', NULL) AS object_type, + mod_expire_date AS expire_date FROM - presence - JOIN - training ON tr_id = pr_training_tr_id + money_deposit + JOIN money_income ON mi_id = mod_money_income_mi_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 - 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) 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(mi_date), - if(mod_id is not null, 'money_deposit', null) as object_type - FROM - money_deposit - JOIN - money_income ON mi_id = mod_money_income_mi_id - WHERE - mod_user_kid_uk_id = ".$user->get_uk_id()." - and mod_deleted = 0)) actions - order by object_date ASC; - "; + 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'], 0, 0, 0, 0, $new_training, null); + } + 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'], 0, 0, 0, $action['expired'], 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); } diff --git a/_include/include_presence.php b/_include/include_presence.php index bdfabe3..8295e95 100644 --- a/_include/include_presence.php +++ b/_include/include_presence.php @@ -75,7 +75,7 @@ if ($this->is_id()) { /* $rest_user_query = " SELECT - * + uk_id FROM user_kid LEFT JOIN @@ -96,13 +96,32 @@ if ($this->is_id()) { */ $rest_user_query = " SELECT - DISTINCT uktt_user_kid_uk_id uk_id + * FROM - user_kid - JOIN - user_kid_training_type ON uktt_user_kid_uk_id = uk_id - WHERE - uktt_training_type_tt_id = {$training->get_tr_training_type_trt_id()}; + (SELECT DISTINCT + uk_id, uk_name + FROM + user_kid + LEFT JOIN user_kid_training_type ON uktt_user_kid_uk_id = uk_id + WHERE + (uk_deleted = 0 AND uk_is_active = 1) + AND (uktt_training_type_tt_id = {$training->get_tr_training_type_trt_id()} + OR uk_lease = 0) UNION SELECT DISTINCT + uk_id, uk_name + FROM + user_kid + LEFT JOIN money_deposit ON mod_user_kid_uk_id = uk_id + AND mod_expire_date > NOW() + AND mod_deleted = 0 + LEFT JOIN lease ON l_id = mod_lease_l_id + LEFT JOIN lease_training_type ON ltt_lease_l_id = l_id + WHERE + uk_deleted = 0 AND uk_is_active = 1 + AND ((uk_lease = 1 AND mod_id IS NOT NULL + AND ltt_training_type_trt_id = {$training->get_tr_training_type_trt_id()}) + OR (uk_lease = 0 AND mod_lease_l_id IS NULL))) AS res + ORDER BY uk_name + ; "; //var_dump($rest_user_query); diff --git a/template/templates/user_diary.tpl b/template/templates/user_diary.tpl index 6fe94f4..3094841 100644 --- a/template/templates/user_diary.tpl +++ b/template/templates/user_diary.tpl @@ -153,7 +153,7 @@ {if !$action->get_de_expired()}
{assign var="discount" value=""} - {if $action->get_de_balance()>0}+{/if}{$action->get_de_balance()|number_format:0:'':' '} Ft
{$discount} + {$action->get_de_balance()|number_format:0:'':' '} Ft
{$discount}
{else}