diff --git a/_class/class_diary_entry.php b/_class/class_diary_entry.php
new file mode 100644
index 0000000..ba6b860
--- /dev/null
+++ b/_class/class_diary_entry.php
@@ -0,0 +1,138 @@
+set_de_presence_id($_pr_id);
+ $this->set_de_date($_date);
+ $this->set_de_type($_type);
+ $this->set_de_training_per_month($_tpm);
+ $this->set_de_training_per_day($_tpd);
+ $this->set_de_first_two($_ft);
+ $this->set_de_training($_tr);
+ $this->set_de_money_deposit($_mod);
+
+ }
+
+ public function set_de_presence_id($_item) {
+ $this->de_presence_id = $_item;
+ }
+
+ /* ez majd akkor jöhet, ha lesz presence class
+ public function set_de_presence($_item) {
+ $this->de_presence = $_item;
+ }
+ */
+
+ public function set_de_date($_item) {
+ $this->de_date = $_item;
+ }
+
+ public function set_de_type($_item) {
+ $this->de_type = $_item;
+ }
+
+ public function set_de_training_per_month($_item) {
+ $this->de_training_per_month = $_item;
+ }
+
+ public function set_de_training_per_day($_item) {
+ $this->de_training_per_day = $_item;
+ }
+
+ public function set_de_first_two($_item) {
+ $this->de_first_two = $_item;
+ }
+
+ public function set_de_training($_item) {
+ $this->de_training = $_item;
+ }
+
+ public function set_de_money_deposit($_item) {
+ $this->de_money_deposit = $_item;
+ }
+
+ public function set_de_transaction($_item) {
+ $this->de_transaction = $_item;
+ }
+
+ public function set_de_balance($_item) {
+ $this->de_balance = $_item;
+ }
+
+ public function set_de_has_discount($_item) {
+ $this->de_has_discount = $_item;
+ }
+
+ public function set_de_discount_id($_item) {
+ $this->de_discount_id = $_item;
+ }
+
+ public function get_de_presence_id() {
+ return $this->de_presence_id;
+ }
+
+ public function get_de_date() {
+ return $this->de_date;
+ }
+
+ public function get_de_type() {
+ return $this->de_type;
+ }
+
+ public function get_de_training_per_month() {
+ return $this->de_training_per_month;
+ }
+
+ public function get_de_training_per_day() {
+ return $this->de_training_per_day;
+ }
+
+ public function get_de_first_two() {
+ return $this->de_first_two;
+ }
+
+ public function get_de_training() {
+ return $this->de_training;
+ }
+
+ public function get_de_money_deposit() {
+ return $this->de_money_deposit;
+ }
+
+ public function get_de_transaction() {
+ return $this->de_transaction;
+ }
+
+ public function get_de_balance() {
+ return $this->de_balance;
+ }
+
+ public function get_de_has_discount() {
+ return $this->de_has_discount;
+ }
+
+ public function get_de_discount_id() {
+ return $this->de_discount_id;
+ }
+
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/_class/class_page.php b/_class/class_page.php
index 4ad28eb..7ac0566 100755
--- a/_class/class_page.php
+++ b/_class/class_page.php
@@ -137,6 +137,10 @@ class page {
# EDZÉS ZÁROLÁS, FELOLDÁS
include('include_lock_training.php');
break;
+ case 'view_deposit':
+ # BEFIZETÉSEK / USER
+ include('include_view_deposit.php');
+ break;
case 'delete_training_type':
# EDZÉS TÍPUS TÖRLÉS
include('include_delete_training_type.php');
diff --git a/_class/class_user_kid.php b/_class/class_user_kid.php
index d56f665..82e123e 100644
--- a/_class/class_user_kid.php
+++ b/_class/class_user_kid.php
@@ -7,6 +7,7 @@ class user_kid extends user_parent {
private $user_id;
private $user_name;
private $user_is_active;
+ private $user_balance;
private $user_last_name;
private $user_first_name;
private $user_password;
@@ -242,6 +243,12 @@ class user_kid extends user_parent {
public function get_uk_school() {
return $this->user_school;
}
+ public function set_uk_balance($_balance) {
+ $this->user_balance = $_balance;
+ }
+ public function get_uk_balance() {
+ return $this->user_balance;
+ }
public function is_logged_in() {
//leellenőrzi cookie alapján h be vagyunk-e jelentkezve
//JAVÍTVA: adja vissza az adattag igazságértékét
@@ -446,5 +453,59 @@ class user_kid extends user_parent {
if (!isset($_user_value_array['uk_is_active'])) $_user_value_array['uk_is_active'] = 0;
$sql->update_table('user_kid', $_user_value_array, array('uk_id' => $_user_id));
}
+
+ public function calculate_balance(&$_de_obj_array, $_user_obj = null) {
+ //kiszámolja az egyenleget a diary entry-k alapján, amik tömbben érkeznek
+ //a tömbben feltölti a pénzmozgást, és minden lépésben befrissíti az egyenleget
+ //az update-elt tömböt adja vissza
+ //ha user_obj null, akkor az aktuális usernél állítja be
+ global $sql;
+
+ //kezdetben 0
+ $balance = 0;
+ foreach ($_de_obj_array as $i => $_de) {
+ //minden lépésben az balance-t be kell állítani az előző lépésben updatelt balance-ra
+ if (isset($_de_obj_array[$i-1])) {
+ $_de->set_de_balance($_de_obj_array[$i-1]->get_de_balance());
+ }
+ if ($_de->get_de_type() == 'training') {
+ //ha edzés, akkor -1000 levonás, kivéve, ha kedvezményes:
+ //1-nél több edzés / nap
+ //8-nál több edzés / hónap
+ //első két alkalom egyike
+ //var_dump($_de);
+ //echo $_de->get_de_first_two() . '
';
+ //echo $_de->get_de_training_per_month() . '
';
+ //echo $_de->get_de_training_per_day() . '
';
+ if ($_de->get_de_first_two() > 0 || $_de->get_de_training_per_month() > 8 || $_de->get_de_training_per_day() > 1) {
+ //do nothing
+ $_de->set_de_transaction(0);
+ $_de->set_de_has_discount(true);
+ //TODO: ha van már havi 8+ akk ne nézze a duplázót!
+ if ($_de->get_de_first_two() > 0) $_de->set_de_discount_id(1);
+ if ($_de->get_de_training_per_day() > 1) $_de->set_de_discount_id(3);
+ if ($_de->get_de_training_per_month() > 8) $_de->set_de_discount_id(2);
+ }
+ else {
+ //$balance -= 1000;
+ $_de->set_de_transaction(-1000); //beállítjuk, mennyivel csökken az egyenleg
+ $_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction()); //beállítjuk az új egyenleget
+ //echo $_de->get_de_date() . " minusz 1000
";
+ }
+ }
+ elseif ($_de->get_de_type() == 'money_deposit') {
+ $_de->set_de_transaction($_de->get_de_money_deposit()->get_mod_sum());
+ $_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction());
+ //$balance += $_de->get_de_money_deposit()->get_mod_sum();
+ //echo $_de->get_de_date() . " plussz " . $_de->get_de_money_deposit()->get_mod_sum() . "
";
+ }
+ }
+
+
+
+ $sql->update_table('user_kid', (array('uk_balance' => $_de->get_de_balance())), array('uk_id' => (is_object($_user_obj)?$_user_obj->get_uk_id():$this->get_uk_id())), false);
+
+ return $_de_obj_array;
+ }
}
?>
\ No newline at end of file
diff --git a/_css/default.css b/_css/default.css
index 0b41982..f82b2f4 100644
--- a/_css/default.css
+++ b/_css/default.css
@@ -211,6 +211,10 @@ td.create a {
border-left: 2px solid #000;
}
+.side_block:hover {
+ background-color: #B7B7B7;
+}
+
.list .list_item img, .list .name_tag img, .list .name_tag_checked img{
width: 20px;
height: 20px;
@@ -263,6 +267,17 @@ td.create a {
margin: 10px 0px !important;
}
+.balance {
+ clear: both;
+ text-align: center;
+ margin: 10px 0px 15px 0px;
+ font-size: 20px;
+ font-weight: bold;
+ padding: 0px 5px;
+ border-bottom: 2px solid;
+ width: 100%;
+}
+
.transp {
opacity: 0.5;
}
@@ -338,26 +353,21 @@ table.log tr.delete:hover {
@media (min-width: 680px) {
-/* */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
.list .date_separator {
width: 100%;
}
+.balance {
+ clear: both;
+ text-align: left;
+ margin: 10px 0px 15px 0px;
+ font-size: 20px;
+ font-weight: bold;
+ padding-left: 5px;
+ border-bottom: 2px solid;
+ width: 30%;
+}
}
@@ -411,4 +421,6 @@ table.log tr.delete:hover {
width: 100%;
}
+
+
}
\ No newline at end of file
diff --git a/_css/diary.css b/_css/diary.css
new file mode 100644
index 0000000..d7a138a
--- /dev/null
+++ b/_css/diary.css
@@ -0,0 +1,45 @@
+@media (min-width: 1000px) {
+
+.list {
+ width: 80%;
+}
+
+.row {
+ display: flex;
+}
+
+.list .list_item {
+ width: 54%;
+ display: inline-block;
+ float: none;
+}
+
+.side_block {
+ float: right;
+ display: inline-block;
+ width: 35%;
+ clear: right;
+ margin: 10px 0px 10px 11% !important;
+ padding: 5px;
+ font-size: 18px;
+ line-height: 1.4;
+ background-color: #e6e6e6;
+}
+
+.extra_row {
+ display: none;
+}
+
+}
+
+@media (max-width: 999px) {
+ .side_block {
+ display: none;
+ }
+
+ .extra_row {
+ display: block;
+ margin-top: 5px;
+ line-height: 1.2;
+ }
+}
\ No newline at end of file
diff --git a/_include/include_diary.php b/_include/include_diary.php
index 2a695dc..69db8d0 100644
--- a/_include/include_diary.php
+++ b/_include/include_diary.php
@@ -9,44 +9,135 @@ else {
$action_list_query = "
SELECT
- *
- FROM
- ((SELECT
- pr_training_tr_id as object_id,
- 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,
- 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 DESC;
+ 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_id 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
+ 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_id 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;
";
$action_assoc_array = $sql->assoc_array($action_list_query);
$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;
+ //$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;
+ //$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;
+
}
- $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);
+ $de_array = array_reverse($de_array);
+ $smarty->assign('actions', $de_array);
+ //$smarty->assign('balance', $balance);
$smarty->display('user_diary.tpl');
}
diff --git a/_include/include_view_deposit.php b/_include/include_view_deposit.php
new file mode 100644
index 0000000..ba1691b
--- /dev/null
+++ b/_include/include_view_deposit.php
@@ -0,0 +1,31 @@
+is_id()) {
+ # USERHEZ TARTOZÓ BEFIZETÉSEK
+ $user_mod_query = "SELECT * FROM money_deposit WHERE mod_user_kid_uk_id = " . $this->get_id() . " and mod_deleted = 0 ORDER BY mod_date DESC;";
+ $umod_assoc_array = $sql->assoc_array($user_mod_query);
+
+ $mods = array();
+ foreach ($umod_assoc_array as $key => $value) {
+ $new_mod = new money_deposit();
+ $new_mod->set_mod_data_by_id($value['mod_id']);
+ $mods[] = $new_mod;
+ }
+
+ $smarty->assign("mod_array", $mods);
+ $smarty->assign("balance", $sql->single_variable('SELECT uk_balance FROM user_kid WHERE uk_id = ' . $this->get_id()));
+ $smarty->assign("mod_user_kid_id", $this->get_id());
+ $smarty->display("view_deposit.tpl");
+
+}
+else {
+ # EMPTY
+
+}
+
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index d5c43e9..fd42391 100644
--- a/index.php
+++ b/index.php
@@ -35,6 +35,10 @@ setlocale(LC_ALL, 'hu_HU');
echo '';
}
+
+ if ($page->is_subpage() && $page->get_subpage() == "diary"|| $page->get_page() == "view" && !$page->is_subpage())
+ echo '';
+
?>
diff --git a/template/templates/money_deposit.tpl b/template/templates/money_deposit.tpl
index d1f0043..ae61e7c 100644
--- a/template/templates/money_deposit.tpl
+++ b/template/templates/money_deposit.tpl
@@ -33,7 +33,7 @@
{$mod->get_mod_date()}
| SZERKESZTÉS | -TÖRLÉS | -
| Dátum: | -{$training_data.tr_date} | -
| Típus: | -- - | -
| Edzés időtartama: | -- - | -
| Edző(k): | -
- {foreach $trc_coaches as $coach}
- {$coach->get_ua_name()} - {/foreach} - |
-
| SZERKESZTÉS | -|
| {$user_data.uk_name} | -|
| Aktív: | -- |
| Utolsó módosítás dátuma: | -- |
| Jelszó: | -- |
| Nem: | -- Fiú - - Lány - - | -
| Születési dátum: | -- |
| Születés éve: | -- |
| Lakcím: | -- |
| Első edzés dátuma: | -- |
| Kéz: | -- Balkezes - - Jobbkezes - - | -
| Email cím: | -{$user_data.uk_email} | -
| Telefonszám: | -{$user_data.uk_phone} | -
| Facebbok: | -{$user_data.uk_facebook} | -
| Pólóméret: | -- - | -
| Iskola neve: | -- - | -
| Iskola települése: | -- - | -
| Iskola kerülete: | -- |
| Szülő1: | -- - | -
| Szülő2: | -- - | -
+ {$actions[$action@index]->get_de_training()->get_tr_date()|substr:0:4}.
+ {$months[$actions[$action@index]->get_de_training()->get_tr_date()|substr:5:2]}
+ ({$user_login->get_training_number_in_month({$action->get_de_training()->get_tr_date()|substr:0:4},{$action->get_de_training()->get_tr_date()|substr:5:2})} edzés)
+
-
+ {$actions[$action@index]->get_de_training()->get_tr_date()|substr:0:4}.
+ {$months[$actions[$action@index]->get_de_training()->get_tr_date()|substr:5:2]}
+ ({$user_login->get_training_number_in_month({$action->get_de_training()->get_tr_date()|substr:0:4},{$action->get_de_training()->get_tr_date()|substr:5:2})} edzés)
+
-
+ {$actions[$action@index]->get_de_money_deposit()->get_mod_date()|substr:0:4}.
+ {$months[$actions[$action@index]->get_de_money_deposit()->get_mod_date()|substr:5:2]}
+
-
+ {$actions[$action@index]->get_de_money_deposit()->get_mod_date()|substr:0:4}.
+ {$months[$actions[$action@index]->get_de_money_deposit()->get_mod_date()|substr:5:2]}
+
-
+
+
+ {/if}
+
+ {/foreach}
+
+