From ec000fbf833fbfd01706932af5d31ade33ca76c6 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Tue, 30 May 2023 19:13:27 +0200 Subject: [PATCH] changes for aenderung and korrektur --- .../GehaltsbestandteilLib.php | 13 +++++++-- .../VertragsbestandteilFunktion.php | 29 +++++++++++++++++-- .../VertragsbestandteilLib.php | 29 ++++++++++++++++--- .../Gehaltsbestandteil_model.php | 3 +- .../Vertragsbestandteil_model.php | 26 ++++++++++------- 5 files changed, 80 insertions(+), 20 deletions(-) diff --git a/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php index e72de9cd9..e182b53d0 100644 --- a/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php @@ -26,9 +26,9 @@ class GehaltsbestandteilLib $this->GehaltsbestandteilModel = $this->CI->GehaltsbestandteilModel; } - public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null) + public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false) { - return $this->GehaltsbestandteilModel->getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag); + return $this->GehaltsbestandteilModel->getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture); } public function fetchGehaltsbestandteil($gehaltsbestandteil_id) @@ -93,4 +93,13 @@ class GehaltsbestandteilLib throw new Exception('error updating gehaltsbestandteil'); } } + + public function deleteGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + $ret = $this->GehaltsbestandteilModel->delete($gehaltsbestandteil->getGehaltsbestandteil_id()); + if(isError($ret) ) + { + throw new Exception('error deleting gehaltsbestandteil'); + } + } } diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php b/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php index 727d2b548..21cb861d4 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php @@ -31,6 +31,31 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil public function beforePersist() { + if( isset($this->benutzerfunktion_id) && intval($this->benutzerfunktion_id) > 0 ) + { + $this->beforePersitExisting(); + } + else + { + $this->beforePersitNew(); + } + } + + protected function beforePersitExisting() { + $data = (object) array( + 'datum_bis' => $this->getBis(), + 'updateamum' => strftime('%Y-%m-%d %H:%M:%S'), + 'updatevon' => getAuthUID() + ); + $ret = $this->CI->BenutzerfunktionModel->update($this->getBenutzerfunktion_id(), $data); + + if(isError($ret) ) + { + throw new Exception('failed to update Benutzerfunktion'); + } + } + + protected function beforePersitNew() { if( $this->benutzerfunktiondata === null) { return; @@ -43,9 +68,9 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil throw new Exception('failed to create Benutzerfunktion'); } - $this->setBenutzerfunktion_id(getData($ret)); + $this->setBenutzerfunktion_id(getData($ret)); } - + public function toStdClass() { $tmp = array( diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index d0ca06126..e178e6a59 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -21,7 +21,10 @@ use vertragsbestandteil\VertragsbestandteilFactory; * @author bambi */ class VertragsbestandteilLib -{ +{ + const INCLUDE_FUTURE = true; + const DO_NOT_INCLUDE_FUTURE = false; + protected $CI; /** @var Dienstverhaeltnis_model */ protected $DienstverhaeltnisModel; @@ -75,10 +78,10 @@ class VertragsbestandteilLib return $dv; } - public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null) + public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false) { - $vbs = $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag); - $gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag); + $vbs = $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture); + $gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture); $gbsByVBid = array(); foreach( $gbs as $gb ) @@ -259,4 +262,22 @@ class VertragsbestandteilLib $dv->getDienstverhaeltnis_id() ); } + + public function deleteVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) + { + $specialisedModel = VertragsbestandteilFactory::getVertragsbestandteilDBModel( + $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); + $retspecial = $specialisedModel->delete($vertragsbestandteil->getVertragsbestandteil_id()); + if(isError($retspecial) ) + { + throw new Exception('error deleting vertragsbestandteil ' + . $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); + } + + $ret = $this->VertragsbestandteilModel->delete($vertragsbestandteil->getVertragsbestandteil_id()); + if(isError($ret) ) + { + throw new Exception('error deleting vertragsbestandteil'); + } + } } diff --git a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php index e3da82766..ef63a12a9 100644 --- a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php @@ -80,7 +80,7 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption . ' AND COALESCE(bis, \'2170-01-01\'::date)'; if( $includefuture ) { - $stichtagclause .= ' OR COALESCE(v.von, \'1970-01-01\'::date) > ' + $stichtagclause .= ' OR COALESCE(von, \'1970-01-01\'::date) > ' . $this->escape($date); } $stichtagclause .= ')'; @@ -113,6 +113,7 @@ EOSQL; public function getGehaltsbestandteil($id) { + $this->addSelect('*'); $query = $this->load($id, $this->getEncryptedColumns()); $gehaltsbestandteil = null; diff --git a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php index 913fd6c34..a5df8ed0d 100644 --- a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php @@ -120,19 +120,23 @@ EOSQL; ; EOSQL; - // echo $sql . "\n\n"; - $query = $this->db->query($sql); - - $vertragsbestandteil = array(); - try + $query = $this->execReadOnlyQuery($sql); + + $vertragsbestandteil = null; + + if( hasData($query) ) { - $vertragsbestandteile = VertragsbestandteilFactory::getVertragsbestandteil($row); // TODO add decryption + $data = getData($query)[0]; + try + { + $vertragsbestandteil = VertragsbestandteilFactory::getVertragsbestandteil($data); // TODO add decryption + } + catch (Exception $ex) + { + echo $ex->getMessage() . "\n"; + } } - catch (Exception $ex) - { - echo $ex->getMessage() . "\n"; - } - + return $vertragsbestandteil; }