From 5bef1596f4cfeb802494a20b3c5df45942b5def0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20Rich=C3=A1rd?= Date: Mon, 26 Aug 2019 13:38:51 +0200 Subject: [PATCH] add, remove, edit lease --- _class/class_lease.php | 244 +++++++++++++++++++++++++ _class/class_page.php | 8 + _include/include_create.php | 8 + _include/include_delete_lease.php | 9 + _include/include_lease.php | 29 +++ common.php | 1 + event_handler.php | 15 ++ queries/lease_201908241.sql | 30 +++ template/templates/lease_create.tpl | 81 ++++++++ template/templates/lease_data_edit.tpl | 87 +++++++++ template/templates/lease_list.tpl | 13 ++ template/templates/money_deposit.tpl | 105 +++++------ 12 files changed, 578 insertions(+), 52 deletions(-) create mode 100644 _class/class_lease.php create mode 100644 _include/include_delete_lease.php create mode 100644 _include/include_lease.php create mode 100644 queries/lease_201908241.sql create mode 100644 template/templates/lease_create.tpl create mode 100644 template/templates/lease_data_edit.tpl create mode 100644 template/templates/lease_list.tpl diff --git a/_class/class_lease.php b/_class/class_lease.php new file mode 100644 index 0000000..0f65ab7 --- /dev/null +++ b/_class/class_lease.php @@ -0,0 +1,244 @@ +l_id; + } + + /** + * @param mixed $l_id + * + * @return self + */ + public function set_l_id($l_id) + { + $this->l_id = $l_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_deleted() + { + return $this->l_deleted; + } + + /** + * @param mixed $l_deleted + * + * @return self + */ + public function set_l_deleted($l_deleted) + { + $this->l_deleted = $l_deleted; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_name() + { + return $this->l_name; + } + + /** + * @param mixed $l_name + * + * @return self + */ + public function set_l_name($l_name) + { + $this->l_name = $l_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_sum() + { + return $this->l_sum; + } + + /** + * @param mixed $l_sum + * + * @return self + */ + public function set_l_sum($l_sum) + { + $this->l_sum = $l_sum; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_expire_type() + { + return $this->l_expire_type; + } + + /** + * @param mixed $l_expire_type + * + * @return self + */ + public function set_l_expire_type($l_expire_type) + { + $this->l_expire_type = $l_expire_type; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_expire_date() + { + return $this->l_expire_date; + } + + /** + * @param mixed $l_expire_date + * + * @return self + */ + public function set_l_expire_date($l_expire_date) + { + $this->l_expire_date = $l_expire_date; + + return $this; + } + + /** + * @return mixed + */ + public function get_l_expire_deleted() + { + return $this->l_expire_deleted; + } + + /** + * @param mixed $l_expire_deleted + * + * @return self + */ + public function set_l_expire_deleted($l_expire_deleted) + { + $this->l_expire_deleted = $l_expire_deleted; + + return $this; + } + + public static function create_lease($_values) { + global $sql; + + if (isset($_values['l_expire_date'])) { + $expDate = $_values['l_expire_date']; + } + else { + $expDate = $_values['l_expire_date_hidden']; + } + + $l_id = $sql->insert_into('lease', array( + 'l_name' => $_values['l_name'], + 'l_sum' => $_values['l_sum'], + 'l_expire_type' => $_values['l_expire_type'], + 'l_expire_date' => $expDate, + )); + + if (isset($_values['l_training_types']) && is_array($_values['l_training_types'])) { + foreach ($_values['l_training_types'] as $key => $trt_id) { + $sql->insert_into('lease_training_type', array( + 'ltt_training_type_trt_id' => $trt_id, + 'ltt_lease_l_id' => $l_id, + )); + } + } + + return $l_id; + } + + public static function update_lease($_values, $_l_id) { + global $sql; + + if (isset($_values['l_expire_date'])) { + $expDate = $_values['l_expire_date']; + } + else { + $expDate = $_values['l_expire_date_hidden']; + } + + $sql->update_table('lease', array( + 'l_name' => $_values['l_name'], + 'l_sum' => $_values['l_sum'], + 'l_expire_type' => $_values['l_expire_type'], + 'l_expire_date' => $expDate, + ), array( + 'l_id' => $_l_id, + )); + + $sql->execute_query('DELETE FROM lease_training_type WHERE ltt_lease_l_id = ' . $_l_id); + if (isset($_values['l_training_types']) && is_array($_values['l_training_types'])) { + foreach ($_values['l_training_types'] as $key => $trt_id) { + $sql->insert_into('lease_training_type', array( + 'ltt_training_type_trt_id' => $trt_id, + 'ltt_lease_l_id' => $_l_id, + )); + } + } + } + + public function set_l_data_by_id($_l_id) { + global $sql; + $lease_data_assoc_array = $sql->assoc_array("select * from lease where l_id = " . $_l_id); + $l_data_array = $lease_data_assoc_array[0]; + foreach ($l_data_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); //alapadatok beállítása + } + + $l_trt_assoc_array = $sql->assoc_array('SELECT * FROM lease_training_type WHERE ltt_lease_l_id = '.$_l_id); + foreach ($l_trt_assoc_array as $key => $l_trt) { + $trt = new training_type(); + $trt->set_trt_data_by_id($l_trt['ltt_training_type_trt_id']); + + $this->l_training_types[] = $trt; + } + } + + public function has_training($_trt_id) { + foreach ($this->l_training_types as $trt) { + if ($trt->get_trt_id() == $_trt_id) { + return true; + } + } + + return false; + } +} + + +?> diff --git a/_class/class_page.php b/_class/class_page.php index f571675..76d0ade 100644 --- a/_class/class_page.php +++ b/_class/class_page.php @@ -205,6 +205,10 @@ class page { # BEFIZETÉSEK include('include_money_deposit.php'); break; + case 'lease': + # BÉRLETTÍPUSOK + include('include_lease.php'); + break; case 'lock_training': # EDZÉS ZÁROLÁS, FELOLDÁS include('include_lock_training.php'); @@ -296,6 +300,10 @@ class page { # HÍR TÖRLÉS include('include_delete_news.php'); break; + case 'delete_lease': + # BÉRLETTÍPUS TÖRLÉS + include('include_delete_lease.php'); + break; case 'logout': # kijelentkezés $from = "admin"; diff --git a/_include/include_create.php b/_include/include_create.php index f4abb94..6187e0b 100644 --- a/_include/include_create.php +++ b/_include/include_create.php @@ -190,6 +190,14 @@ switch ($this->get_id()) { # hír létrehozása $smarty->display('news_create.tpl'); break; + case 'lease': + # bérlettípus létrehozása + $training_type_query = "SELECT * FROM training_type ORDER BY trt_name ASC;"; + $training_type_assoc_array = $sql->assoc_array($training_type_query); + $smarty->assign("training_type_assoc_array", $training_type_assoc_array); + + $smarty->display('lease_create.tpl'); + break; default: # code... break; diff --git a/_include/include_delete_lease.php b/_include/include_delete_lease.php new file mode 100644 index 0000000..6be5b4d --- /dev/null +++ b/_include/include_delete_lease.php @@ -0,0 +1,9 @@ +is_id()) { + $sql->update_table('lease', array('l_deleted' => 1), array('l_id' => $this->get_id())); + log::register('delete_lease', $this->get_id()); + header("Location: /admin/lease"); +} + +?> diff --git a/_include/include_lease.php b/_include/include_lease.php new file mode 100644 index 0000000..0617ea7 --- /dev/null +++ b/_include/include_lease.php @@ -0,0 +1,29 @@ +is_id()) { + # BÉRLETTÍPUS SZERKESZTÉSE + + $lease = new lease(); + $lease->set_l_data_by_id($this->get_id()); + + $training_type_query = "SELECT * FROM training_type ORDER BY trt_name ASC;"; + $training_type_assoc_array = $sql->assoc_array($training_type_query); + + $smarty->assign("training_type_assoc_array", $training_type_assoc_array); + $smarty->assign('lease',$lease); + + $smarty->display('lease_data_edit.tpl'); +} +else { + + # BÉRLETTÍPUS LISTA + + $l_query = "SELECT * FROM lease WHERE l_deleted = 0 ORDER BY l_name ASC"; + $l_assoc_array = $sql->assoc_array($l_query); + + $smarty->assign('l_assoc_array',$l_assoc_array); + $smarty->display('lease_list.tpl'); +} +?> diff --git a/common.php b/common.php index a1ba806..acf4ff8 100644 --- a/common.php +++ b/common.php @@ -147,6 +147,7 @@ $structure = array( 'balance_list', 'money_update', 'money_deposit', + 'lease' ), 'money_expense' => array( 'money_expense_category', diff --git a/event_handler.php b/event_handler.php index 5f7efef..3f0da6a 100644 --- a/event_handler.php +++ b/event_handler.php @@ -594,6 +594,21 @@ if (isset($_POST['action'])) { log::register('update_news', $n_id); header('Location: /admin/news/'.$n_id); break; + case 'lease_create': + # új bérlettípus + unset($_POST['action']); + $new_lease_id = lease::create_lease($_POST); + log::register('new_lease', $new_lease_id); + header('Location: /admin/lease/'.$new_lease_id); + break; + case 'lease_update': + unset($_POST['action']); + $l_id = $_POST['l_id']; + unset($_POST['l_id']); + lease::update_lease($_POST, $l_id); + log::register('update_lease', $l_id); + header('Location: /admin/lease/'.$l_id); + break; default: # code... break; diff --git a/queries/lease_201908241.sql b/queries/lease_201908241.sql new file mode 100644 index 0000000..2c79271 --- /dev/null +++ b/queries/lease_201908241.sql @@ -0,0 +1,30 @@ +CREATE TABLE `lease` ( + `l_id` INT NOT NULL AUTO_INCREMENT, + `l_name` VARCHAR(128) NOT NULL, + `l_expire_type` TINYINT(3) NOT NULL, + `l_sum` INT NOT NULL, + `l_expire_date` DATE NOT NULL, + `l_deleted` INT NULL DEFAULT 0, + PRIMARY KEY (`l_id`)); + +CREATE TABLE `lease_training_type` ( + `ltt_id` INT NOT NULL AUTO_INCREMENT, + `ltt_lease_l_id` INT NOT NULL, + `ltt_training_type_trt_id` INT NOT NULL, + PRIMARY KEY (`ltt_id`), + INDEX `fk_lease_training_type_1_idx` (`ltt_lease_l_id` ASC), + INDEX `fk_lease_training_type_2_idx` (`ltt_training_type_trt_id` ASC), + CONSTRAINT `fk_lease_training_type_1` + FOREIGN KEY (`ltt_lease_l_id`) + REFERENCES `lease` (`l_id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_lease_training_type_2` + FOREIGN KEY (`ltt_training_type_trt_id`) + REFERENCES `training_type` (`trt_id`) + ON DELETE CASCADE + ON UPDATE CASCADE); + +INSERT INTO `log_category` (`logc_id`, `logc_name`, `logc_title`, `logc_type`, `logc_table`, `logc_field`, `logc_selector`) VALUES (NULL, 'new_lease', 'Új bérlettípus', '1', 'lease', 'l_name', 'l_id'); +INSERT INTO `log_category` (`logc_id`, `logc_name`, `logc_title`, `logc_type`, `logc_table`, `logc_field`, `logc_selector`) VALUES (NULL, 'update_lease', 'Bérlettípus módosítása', '1', 'lease', 'l_name', 'l_id'); +INSERT INTO `log_category` (`logc_id`, `logc_name`, `logc_title`, `logc_type`, `logc_table`, `logc_field`, `logc_selector`) VALUES (NULL, 'delete_lease', 'Bérlettípus törlése', '1', 'lease', 'l_name', 'l_id'); diff --git a/template/templates/lease_create.tpl b/template/templates/lease_create.tpl new file mode 100644 index 0000000..712d157 --- /dev/null +++ b/template/templates/lease_create.tpl @@ -0,0 +1,81 @@ +
+
+ + + +
+ +
+
+ +
+ +
+
+ +
+ Lejárati dátum: +
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+ Edzés típusok: + + {foreach $training_type_assoc_array as $trt_array} + + + + + {/foreach} +
+ + +
+
+ +
+
+ + + + + diff --git a/template/templates/lease_data_edit.tpl b/template/templates/lease_data_edit.tpl new file mode 100644 index 0000000..9c05b0e --- /dev/null +++ b/template/templates/lease_data_edit.tpl @@ -0,0 +1,87 @@ +
+ +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ Lejárati dátum: +
+ get_l_expire_type() == 1}checked{/if}> + +
+
+ get_l_expire_type() == 2}checked{/if}> + +
+
+ get_l_expire_type() == 3}checked{/if}> + +
+
+ +
+
+ +
+ Edzés típusok: +
+ {foreach $training_type_assoc_array as $trt_array} + + + + + {/foreach} +
has_training($trt_array.trt_id)}checked{/if}>
+ + +
+
+ +
+
+ + + + + diff --git a/template/templates/lease_list.tpl b/template/templates/lease_list.tpl new file mode 100644 index 0000000..317faa4 --- /dev/null +++ b/template/templates/lease_list.tpl @@ -0,0 +1,13 @@ + +
+ {foreach $l_assoc_array as $lease} + +
+ {$lease.l_name} + +
+
+ {/foreach} +
diff --git a/template/templates/money_deposit.tpl b/template/templates/money_deposit.tpl index 2f6ab27..cf48729 100644 --- a/template/templates/money_deposit.tpl +++ b/template/templates/money_deposit.tpl @@ -1,56 +1,57 @@
- {foreach $mod_array as $mod} + {foreach $mod_array as $mod} - {if !$mod@first && $mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2 != $mod_array[$mod@index-1]->get_mod_money_income()->get_mi_date()|substr:5:2} -
- {/if} + {if !$mod@first && $mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2 != $mod_array[$mod@index-1]->get_mod_money_income()->get_mi_date()|substr:5:2} + + {/if} - {if $mod@first || $mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2 != $mod_array[$mod@index-1]->get_mod_money_income()->get_mi_date()|substr:5:2} - {$mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:0:4}. - {$months[$mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2]} - - -
+ {if $mod@first || $mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2 != $mod_array[$mod@index-1]->get_mod_money_income()->get_mi_date()|substr:5:2} + {$mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:0:4}. + {$months[$mod_array[$mod@index]->get_mod_money_income()->get_mi_date()|substr:5:2]} + + +
- {/if} - -
-
- - - - - - + {/if} + +
+
- {if $mod->get_mod_money_income()->get_mi_payment_type_pt_id() == 1} - - {else} - - {/if} - - {$mod->get_mod_user_kid()->get_uk_name()} - - {$mod->get_mod_money_income()->get_mi_date(true)} - - {$mod->get_mod_money_income()->get_mi_sum()|number_format:0:'':' '} Ft -
+ + + + + + -
+ {if $mod->get_mod_money_income()->get_mi_payment_type_pt_id() == 1} + + {else} + + {/if} + + {$mod->get_mod_user_kid()->get_uk_name()} + + {$mod->get_mod_money_income()->get_mi_date(true)} + + {$mod->get_mod_money_income()->get_mi_sum()|number_format:0:'':' '} Ft +
-
- + +
+ - {if $mod@last} - - {/if} + {if $mod@last} + + {/if} - {/foreach} + {/foreach} @@ -58,29 +59,29 @@