presence + money update query fix
This commit is contained in:
@@ -9,135 +9,66 @@
|
|||||||
|
|
||||||
|
|
||||||
$action_list_query = "
|
$action_list_query = "
|
||||||
SELECT
|
SELECT
|
||||||
object_id,
|
object_id,
|
||||||
timestamp(object_date) as object_date,
|
TIMESTAMP(object_date) AS object_date,
|
||||||
object_type,
|
object_type,
|
||||||
(SELECT
|
expire_date,
|
||||||
count(distinct date(tr_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
|
FROM
|
||||||
presence
|
presence
|
||||||
JOIN
|
JOIN training ON (tr_id = pr_training_tr_id
|
||||||
training ON tr_id = pr_training_tr_id
|
AND tr_locked = 1)
|
||||||
WHERE
|
WHERE
|
||||||
YEAR(tr_date) = YEAR(object_date)
|
pr_user_kid_uk_id = {$user->get_uk_id()}
|
||||||
AND MONTH(tr_date) = MONTH(object_date)
|
AND tr_deleted = 0) UNION (SELECT
|
||||||
AND tr_date <= object_date
|
mod_id,
|
||||||
AND pr_user_kid_uk_id = ".$user->get_uk_id()."
|
TIMESTAMP(mi_date),
|
||||||
AND tr_date > (select
|
IF(mod_id IS NOT NULL, 'money_deposit', NULL) AS object_type,
|
||||||
if(max(trd) is null,
|
mod_expire_date AS expire_date
|
||||||
'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
|
FROM
|
||||||
presence
|
money_deposit
|
||||||
JOIN
|
JOIN money_income ON mi_id = mod_money_income_mi_id
|
||||||
training ON tr_id = pr_training_tr_id
|
|
||||||
WHERE
|
WHERE
|
||||||
DATE(tr_date) = DATE(object_date)
|
mod_user_kid_uk_id = {$user->get_uk_id()}
|
||||||
AND tr_date <= object_date
|
AND mod_deleted = 0)) actions
|
||||||
AND pr_user_kid_uk_id = ".$user->get_uk_id().") as 'training_per_day',
|
ORDER BY object_date ASC;
|
||||||
(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;
|
|
||||||
";
|
|
||||||
|
|
||||||
$action_assoc_array = $sql->assoc_array($action_list_query);
|
$action_assoc_array = $sql->assoc_array($action_list_query);
|
||||||
|
|
||||||
$actions = array();
|
$actions = array();
|
||||||
$de_array = array();
|
$de_array = array();
|
||||||
foreach ($action_assoc_array as $action) {
|
foreach ($action_assoc_array as $action) {
|
||||||
|
|
||||||
|
|
||||||
if ($action['object_type'] == 'training') {
|
if ($action['object_type'] == 'training') {
|
||||||
$new_training = new training();
|
$new_training = new training();
|
||||||
$new_training->set_training_data_by_id($action['object_id']);
|
$new_training->set_training_data_by_id($action['object_id']);
|
||||||
//$actions[] = $new_training;
|
//$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);
|
$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') {
|
elseif ($action['object_type'] == 'money_deposit') {
|
||||||
$new_mod = new money_deposit();
|
$new_mod = new money_deposit();
|
||||||
$new_mod->set_mod_data_by_id($action['object_id']);
|
$new_mod->set_mod_data_by_id($action['object_id']);
|
||||||
//$actions[] = $new_mod;
|
//$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);
|
$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
|
//itt csak hivatkozással adjuk át a tömböt, a calculate_balance kiszámolja, belerakja és visszadja
|
||||||
$user->calculate_balance($de_array, $user);
|
$user->calculate_balance($de_array, $user);
|
||||||
//var_dump($de_array);
|
//var_dump($de_array);
|
||||||
//$smarty->assign('actions', $actions);
|
//$smarty->assign('actions', $actions);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ if ($this->is_id()) {
|
|||||||
/*
|
/*
|
||||||
$rest_user_query = "
|
$rest_user_query = "
|
||||||
SELECT
|
SELECT
|
||||||
*
|
uk_id
|
||||||
FROM
|
FROM
|
||||||
user_kid
|
user_kid
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
@@ -96,13 +96,32 @@ if ($this->is_id()) {
|
|||||||
*/
|
*/
|
||||||
$rest_user_query = "
|
$rest_user_query = "
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT uktt_user_kid_uk_id uk_id
|
*
|
||||||
FROM
|
FROM
|
||||||
user_kid
|
(SELECT DISTINCT
|
||||||
JOIN
|
uk_id, uk_name
|
||||||
user_kid_training_type ON uktt_user_kid_uk_id = uk_id
|
FROM
|
||||||
WHERE
|
user_kid
|
||||||
uktt_training_type_tt_id = {$training->get_tr_training_type_trt_id()};
|
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);
|
//var_dump($rest_user_query);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@
|
|||||||
{if !$action->get_de_expired()}
|
{if !$action->get_de_expired()}
|
||||||
<div class="side_block">
|
<div class="side_block">
|
||||||
{assign var="discount" value=""}
|
{assign var="discount" value=""}
|
||||||
<span class="bold" style="font-size: 20px;">{if $action->get_de_balance()>0}+{/if}{$action->get_de_balance()|number_format:0:'':' '} Ft</span><br>{$discount}
|
<span class="bold" style="font-size: 20px;">{$action->get_de_balance()|number_format:0:'':' '} Ft</span><br>{$discount}
|
||||||
</div>
|
</div>
|
||||||
{else}
|
{else}
|
||||||
<div class="side_block">
|
<div class="side_block">
|
||||||
|
|||||||
Reference in New Issue
Block a user