From 38509d530aa90db203f1b39c6557787e0aab0ea1 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Wed, 24 May 2023 17:54:04 +0200 Subject: [PATCH] prepare list of vbs with gbs --- .../Gehaltsbestandteil.php | 9 +++++- .../Vertragsbestandteil.php | 6 ++++ .../VertragsbestandteilLib.php | 26 +++++++++++++++- .../Gehaltsbestandteil_model.php | 30 +++++++++---------- .../Vertragsbestandteil_model.php | 10 +++++-- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php index 130c18547..f48a969c8 100644 --- a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php @@ -4,7 +4,7 @@ namespace vertragsbestandteil; /** * Salary always depends on employment (Dienstverhältnis) and optionally on part of contract (Vetragsbestandteil) */ -class Gehaltsbestandteil implements IValidation +class Gehaltsbestandteil implements IValidation, \JsonSerializable { protected $gehaltsbestandteil_id; protected $dienstverhaeltnis_id; @@ -230,6 +230,13 @@ class Gehaltsbestandteil implements IValidation return $this; } + public function jsonSerialize() + { + $vars = get_object_vars($this); + unset($vars['CI']); + return $vars; + } + public function toStdClass(): \stdClass { $tmp = array( diff --git a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php index 73e2bcd8d..ffda62e08 100644 --- a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php @@ -100,6 +100,12 @@ abstract class Vertragsbestandteil implements \JsonSerializable, IValidation return $this->updatevon; } + public function setGehaltsbestandteile($gehaltsbestandteile) + { + $this->gehaltsbestandteile = $gehaltsbestandteile; + return $this; + } + public function setVertragsbestandteil_id($vertragsbestandteil_id) { $this->vertragsbestandteil_id = $vertragsbestandteil_id; diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 6df37263c..d47b89342 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -76,7 +76,31 @@ class VertragsbestandteilLib public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null) { - return $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag); + $vbs = $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag); + $gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag); + + $gbsByVBid = array(); + foreach( $gbs as $gb ) + { + if( intval($gb->getVertragsbestandteil_id()) > 0 ) + { + if( !isset($gbsByVBid[$gb->getVertragsbestandteil_id()]) + || !is_array($gbsByVBid[$gb->getVertragsbestandteil_id()]) ) { + $gbsByVBid[$gb->getVertragsbestandteil_id()] = array(); + } + $gbsByVBid[$gb->getVertragsbestandteil_id()][] = $gb; + } + } + + foreach ($vbs as $vb) + { + if( isset($gbsByVBid[$vb->getVertragsbestandteil_id()]) ) + { + $vb->setGehaltsbestandteile($gbsByVBid[$vb->getVertragsbestandteil_id()]); + } + } + + return $vbs; } public function fetchVertragsbestandteil($vertragsbestandteil_id) diff --git a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php index 8236867ba..e3da82766 100644 --- a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php @@ -69,31 +69,31 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption return $this->execQuery($qry, array($dienstverhaeltnis_id), $this->getEncryptedColumns()); } - public function getGehaltsbestandteile($dienstverhaeltnis_id=1, $stichtag=null) + public function getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false) { $stichtagclause = ''; if( !is_null($stichtag) ) { $date = strftime('%Y-%m-%d', strtotime($stichtag)); - $stichtagclause = 'AND ' . $this->escape($date) - . ' BETWEEN COALESCE(v.von, \'1970-01-01\'::date)' - . ' AND COALESCE(v.bis, \'2170-01-01\'::date)'; + $stichtagclause = 'AND (' . $this->escape($date) + . ' BETWEEN COALESCE(von, \'1970-01-01\'::date)' + . ' AND COALESCE(bis, \'2170-01-01\'::date)'; + if( $includefuture ) + { + $stichtagclause .= ' OR COALESCE(v.von, \'1970-01-01\'::date) > ' + . $this->escape($date); + } + $stichtagclause .= ')'; } - $sql = <<addSelect('*'); + $where = <<escape($dienstverhaeltnis_id)} {$stichtagclause} - ; EOSQL; - $query = $this->execReadOnlyQuery( - $query, - array($dienstverhaeltnis_id), + $query = $this->loadWhere( + $where, $this->getEncryptedColumns() ); diff --git a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php index 2c6273c8b..913fd6c34 100644 --- a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php @@ -59,15 +59,21 @@ EOSQL; return $sql; } - public function getVertragsbestandteile($dienstverhaeltnis_id=1, $stichtag=null) + public function getVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false) { $stichtagclause = ''; if( !is_null($stichtag) ) { $date = strftime('%Y-%m-%d', strtotime($stichtag)); - $stichtagclause = 'AND ' . $this->escape($date) + $stichtagclause = 'AND (' . $this->escape($date) . ' BETWEEN COALESCE(v.von, \'1970-01-01\'::date)' . ' AND COALESCE(v.bis, \'2170-01-01\'::date)'; + if( $includefuture ) + { + $stichtagclause .= ' OR COALESCE(v.von, \'1970-01-01\'::date) > ' + . $this->escape($date); + } + $stichtagclause .= ')'; } $sql = <<