extended user diary, added diary entry class, added view deposit option to user list

This commit is contained in:
Ricsi
2017-02-04 22:29:24 +01:00
parent 1ef4323c64
commit 805a5bc440
15 changed files with 593 additions and 439 deletions

View File

@@ -0,0 +1,138 @@
<?php
/**
*
*/
class diary_entry {
private $de_presence_id;
private $de_date;
private $de_type; //money deposit or training
private $de_training_per_month; //hányadik edzés a hónapban
private $de_training_per_day; //hányadik edzés a napon
private $de_first_two; //boolean; első két edzés egyike-e
private $de_training = null;
private $de_money_deposit = null;
private $de_transaction = 0; //ez adja meg, hogy mennyivel csökken, vagy nő az egyenleg
private $de_balance = 0; //a felhasználóhoz tartozó aktuális egyenleg
private $de_has_discount = false; //van-e kedvzemény
private $de_discount_id; //kedvezmény ID
function __construct($_pr_id, $_date, $_type, $_tpm, $_tpd, $_ft, $_tr = null, $_mod = null) {
$this->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;
}
}
?>

View File

@@ -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');

View File

@@ -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() . '<br>';
//echo $_de->get_de_training_per_month() . '<br>';
//echo $_de->get_de_training_per_day() . '<br><br><br>';
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<br><br>";
}
}
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() . "<br><br>";
}
}
$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;
}
}
?>