big changes
everything with lease and expire dates
This commit is contained in:
@@ -16,8 +16,9 @@ class diary_entry {
|
||||
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
|
||||
private $de_expired = 0;
|
||||
|
||||
function __construct($_pr_id, $_date, $_type, $_tpm, $_tpd, $_ft, $_tr = null, $_mod = null) {
|
||||
function __construct($_pr_id, $_date, $_type, $_tpm, $_tpd, $_ft, $_expired = 0, $_tr = null, $_mod = null) {
|
||||
$this->set_de_presence_id($_pr_id);
|
||||
$this->set_de_date($_date);
|
||||
$this->set_de_type($_type);
|
||||
@@ -26,7 +27,7 @@ class diary_entry {
|
||||
$this->set_de_first_two($_ft);
|
||||
$this->set_de_training($_tr);
|
||||
$this->set_de_money_deposit($_mod);
|
||||
|
||||
$this->set_de_expired($_expired);
|
||||
}
|
||||
|
||||
public function set_de_presence_id($_item) {
|
||||
@@ -83,6 +84,10 @@ class diary_entry {
|
||||
$this->de_discount_id = $_item;
|
||||
}
|
||||
|
||||
public function set_de_expired($_item) {
|
||||
$this->de_expired = $_item;
|
||||
}
|
||||
|
||||
public function get_de_presence_id() {
|
||||
return $this->de_presence_id;
|
||||
}
|
||||
@@ -131,6 +136,10 @@ class diary_entry {
|
||||
return $this->de_discount_id;
|
||||
}
|
||||
|
||||
public function get_de_expired() {
|
||||
return $this->de_expired;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ class lease {
|
||||
$expDate = $_values['l_expire_date'];
|
||||
}
|
||||
else {
|
||||
$expDate = $_values['l_expire_date_hidden'];
|
||||
$expDate = 'null';
|
||||
}
|
||||
|
||||
$l_id = $sql->insert_into('lease', array(
|
||||
@@ -188,7 +188,7 @@ class lease {
|
||||
$expDate = $_values['l_expire_date'];
|
||||
}
|
||||
else {
|
||||
$expDate = $_values['l_expire_date_hidden'];
|
||||
$expDate = 'null';
|
||||
}
|
||||
|
||||
$sql->update_table('lease', array(
|
||||
|
||||
@@ -12,6 +12,7 @@ class money_deposit {
|
||||
private $mod_money_income; //OBJECT
|
||||
private $mod_deleted;
|
||||
private $mod_sets_expire_date;
|
||||
private $mod_expire_date;
|
||||
private $mod_lease_l_id; //OBJECT
|
||||
|
||||
public function set_mod_id($_id) {
|
||||
@@ -42,6 +43,10 @@ class money_deposit {
|
||||
$this->mod_sets_expire_date = $_sets_expire_date;
|
||||
}
|
||||
|
||||
public function set_mod_expire_date($_expire_date) {
|
||||
$this->mod_expire_date = $_expire_date;
|
||||
}
|
||||
|
||||
public function set_mod_lease_l_id($_lease_l_id) {
|
||||
$this->mod_lease_l_id = $_lease_l_id;
|
||||
}
|
||||
@@ -74,6 +79,10 @@ class money_deposit {
|
||||
return $this->mod_sets_expire_date;
|
||||
}
|
||||
|
||||
public function get_mod_expire_date() {
|
||||
return $this->mod_expire_date;
|
||||
}
|
||||
|
||||
public function get_mod_lease_l_id() {
|
||||
return $this->mod_lease_l_id;
|
||||
}
|
||||
@@ -103,6 +112,9 @@ class money_deposit {
|
||||
}
|
||||
}
|
||||
}
|
||||
public function is_expired() {
|
||||
return $this->get_mod_expire_date() <= date('Y-m-d');
|
||||
}
|
||||
|
||||
public static function create_money_deposit($_user_id, $_date, $_sum, $_lease, $_pt = 1, $_sets_date = false) {
|
||||
global $sql;
|
||||
@@ -116,12 +128,49 @@ class money_deposit {
|
||||
)
|
||||
);
|
||||
|
||||
$expireDate = 'null';
|
||||
|
||||
if ($_sets_date) {
|
||||
$sql->update_table('user_kid', array(
|
||||
'uk_last_deposit' => date('Y-m-d')
|
||||
), array(
|
||||
'uk_id' => $_user_id,
|
||||
));
|
||||
|
||||
//lekérjük, hogy milyen a lejárati típusa a bérletnek, és az alapján beállítjuk a lejárati dátumot az usernek
|
||||
|
||||
if ('null' != $_lease) {
|
||||
$lease = new lease();
|
||||
$lease->set_l_data_by_id($_lease);
|
||||
|
||||
if ($lease->get_l_expire_type() == 1) {
|
||||
//naptári hónap vége
|
||||
$sql->update_table('user_kid', array(
|
||||
'uk_balance_expire_date' => date('Y-m-t')
|
||||
), array(
|
||||
'uk_id' => $_user_id,
|
||||
));
|
||||
$expireDate = date('Y-m-t');
|
||||
}
|
||||
elseif ($lease->get_l_expire_type() == 2) {
|
||||
//következő hónapban
|
||||
$sql->update_table('user_kid', array(
|
||||
'uk_balance_expire_date' => date("Y-m-d", strtotime("+1 month", time())),
|
||||
), array(
|
||||
'uk_id' => $_user_id,
|
||||
));
|
||||
$expireDate = date("Y-m-d", strtotime("+1 month", time()));
|
||||
}
|
||||
elseif ($lease->get_l_expire_type() == 3) {
|
||||
//egyedi dátum
|
||||
$sql->update_table('user_kid', array(
|
||||
'uk_balance_expire_date' => $lease->get_l_expire_date(),
|
||||
), array(
|
||||
'uk_id' => $_user_id,
|
||||
));
|
||||
$expireDate = date("Y-m-d", strtotime($lease->get_l_expire_date()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sql->insert_into('money_deposit', array(
|
||||
@@ -129,10 +178,11 @@ class money_deposit {
|
||||
'mod_money_income_mi_id' => $income_id,
|
||||
'mod_sets_expire_date' => $_sets_date,
|
||||
'mod_lease_l_id' => $_lease,
|
||||
'mod_expire_date' => $expireDate,
|
||||
));
|
||||
}
|
||||
|
||||
public static function update_money_deposit($_user_id, $_date, $_sum, $_lease, $_mod_id, $_pt, $_mi_id) {
|
||||
public static function update_money_deposit($_date, $_sum, $_mod_id, $_pt, $_mi_id) {
|
||||
global $sql;
|
||||
$sql->update_table('money_income', array(
|
||||
//'mod_user_kid_uk_id' => $_user_id,
|
||||
@@ -143,15 +193,39 @@ class money_deposit {
|
||||
'mi_id' => $_mi_id
|
||||
));
|
||||
|
||||
$sql->update_table('money_deposit', array(
|
||||
'mod_user_kid_uk_id' => $_user_id,
|
||||
'mod_lease_l_id' => $_lease,
|
||||
), array(
|
||||
'mod_id' => $_mod_id
|
||||
));
|
||||
// $sql->update_table('money_deposit', array(
|
||||
// 'mod_user_kid_uk_id' => $_user_id,
|
||||
// //'mod_lease_l_id' => $_lease,
|
||||
// ), array(
|
||||
// 'mod_id' => $_mod_id
|
||||
// ));
|
||||
|
||||
}
|
||||
|
||||
public static function calculate_expire_date($_mod_id) {
|
||||
global $sql;
|
||||
|
||||
$mod = new money_deposit();
|
||||
$mod->set_mod_data_by_id($_mod_id);
|
||||
|
||||
$expireDate = null;
|
||||
|
||||
$lease = $mod->get_mod_lease_l_id();
|
||||
if (null !== $lease) {
|
||||
if ($lease->get_l_expire_type() == 1) {
|
||||
$expireDate = date('Y-m-t', strtotime($mod->get_mod_money_income()->get_mi_date()));
|
||||
}
|
||||
elseif ($lease->get_l_expire_type() == 2) {
|
||||
$expireDate = date("Y-m-d", strtotime("+1 month", strtotime($mod->get_mod_money_income()->get_mi_date())));
|
||||
}
|
||||
elseif ($lease->get_l_expire_type() == 3) {
|
||||
//egyedi dátum
|
||||
$expireDate = date("Y-m-d", strtotime("+1 month", strtotime($mod->get_mod_money_income()->get_mi_date())));
|
||||
}
|
||||
}
|
||||
|
||||
return $expireDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -587,7 +587,11 @@ class user_kid extends user_parent {
|
||||
}
|
||||
elseif ($_de->get_de_type() == 'money_deposit') {
|
||||
$_de->set_de_transaction($_de->get_de_money_deposit()->get_mod_money_income()->get_mi_sum());
|
||||
$_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction());
|
||||
if (!$_de->get_de_expired()) {
|
||||
$_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction());
|
||||
} else {
|
||||
$_de->set_de_balance(0);
|
||||
}
|
||||
//$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>";
|
||||
}
|
||||
@@ -600,20 +604,20 @@ class user_kid extends user_parent {
|
||||
return $_de_obj_array;
|
||||
}
|
||||
|
||||
public function get_groups() {
|
||||
global $sql;
|
||||
// public function get_groups() {
|
||||
// global $sql;
|
||||
|
||||
$group_array = array();
|
||||
$g_assoc = $sql->assoc_array("select * from user_group_kid join user_group on ug_id = ugk_user_group_ug_id where ug_is_automatic = 1 and ugk_user_kid_uk_id = ".$this->get_uk_id().";");
|
||||
// $group_array = array();
|
||||
// $g_assoc = $sql->assoc_array("select * from user_group_kid join user_group on ug_id = ugk_user_group_ug_id where ug_is_automatic = 1 and ugk_user_kid_uk_id = ".$this->get_uk_id().";");
|
||||
|
||||
foreach ($g_assoc as $g) {
|
||||
$group = new user_group();
|
||||
$group->set_ug_data_by_id($g['ugk_user_group_ug_id']);
|
||||
$group_array[] = $group;
|
||||
}
|
||||
// foreach ($g_assoc as $g) {
|
||||
// $group = new user_group();
|
||||
// $group->set_ug_data_by_id($g['ugk_user_group_ug_id']);
|
||||
// $group_array[] = $group;
|
||||
// }
|
||||
|
||||
return $group_array;
|
||||
}
|
||||
// return $group_array;
|
||||
// }
|
||||
|
||||
public function update_balance() {
|
||||
global $sql;
|
||||
@@ -622,35 +626,39 @@ class user_kid extends user_parent {
|
||||
|
||||
$action_list_query = "
|
||||
SELECT
|
||||
object_id,
|
||||
timestamp(object_date) as object_date,
|
||||
object_type
|
||||
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
|
||||
object_id,
|
||||
TIMESTAMP(object_date) AS object_date,
|
||||
object_type,
|
||||
expire_date,
|
||||
IF(expire_date <= NOW(), 1, 0) AS expired
|
||||
FROM
|
||||
presence
|
||||
JOIN training ON (tr_id = pr_training_tr_id AND tr_locked = 1)
|
||||
WHERE
|
||||
pr_user_kid_uk_id = ".$userId."
|
||||
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 = ".$userId."
|
||||
and mod_deleted = 0)) actions
|
||||
order by object_date ASC;
|
||||
((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
|
||||
AND tr_locked = 1)
|
||||
WHERE
|
||||
pr_user_kid_uk_id = ".$userId."
|
||||
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
|
||||
money_deposit
|
||||
JOIN money_income ON mi_id = mod_money_income_mi_id
|
||||
WHERE
|
||||
mod_user_kid_uk_id = ".$userId."
|
||||
AND mod_deleted = 0)) actions
|
||||
ORDER BY object_date ASC;
|
||||
";
|
||||
|
||||
$action_assoc_array = $sql->assoc_array($action_list_query);
|
||||
|
||||
var_dump($action_assoc_array);
|
||||
$actions = array();
|
||||
$de_array = array();
|
||||
foreach ($action_assoc_array as $action) {
|
||||
@@ -660,13 +668,14 @@ class user_kid extends user_parent {
|
||||
$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, $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']);
|
||||
//var_dump($new_mod);
|
||||
//$actions[] = $new_mod;
|
||||
$new_diary_entry = new diary_entry($action['object_id'], $action['object_date'], $action['object_type'], 0, 0, 0, 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;
|
||||
@@ -702,5 +711,42 @@ class user_kid extends user_parent {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function balance_meta_update() {
|
||||
global $sql;
|
||||
|
||||
$lastDeposit = 'null';
|
||||
$expireDate = 'null';
|
||||
|
||||
$deposits = $sql->assoc_array('
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
money_deposit
|
||||
JOIN
|
||||
money_income ON mi_id = mod_money_income_mi_id
|
||||
WHERE
|
||||
mod_user_kid_uk_id = '.$this->get_uk_id().'
|
||||
AND mod_deleted = 0
|
||||
AND mod_expire_date > NOW()
|
||||
ORDER BY mi_date DESC
|
||||
LIMIT 1;
|
||||
');
|
||||
|
||||
if (count($deposits)) {
|
||||
$lastDeposit = $deposits[0]['mi_date'];
|
||||
$expireDate = money_deposit::calculate_expire_date($deposits[0]['mod_id']);
|
||||
}
|
||||
|
||||
$sql->update_table('user_kid',
|
||||
array(
|
||||
'uk_last_deposit' => $lastDeposit,
|
||||
'uk_balance_expire_date' => $expireDate,
|
||||
),
|
||||
array(
|
||||
'uk_id' => $this->get_uk_id(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user