diff --git a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php index 2f70f02d8..bf5ec6211 100644 --- a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php @@ -232,6 +232,10 @@ EOTXT; // can be overridden in childs } + public function afterDelete() { + // can be overridden in childs + } + public function validate() { $von = \DateTimeImmutable::createFromFormat('Y-m-d', $this->von); $bis = \DateTimeImmutable::createFromFormat('Y-m-d', $this->bis); diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php b/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php index 7b9d35906..70e24bf8c 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilFunktion.php @@ -27,6 +27,8 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil $this->CI = get_instance(); $this->CI->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $this->CI->load->library('vertragsbestandteil/VertragsbestandteilLib', + null, 'VertragsbestandteilLib'); } public function beforePersist() @@ -41,23 +43,129 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil } } - protected function beforePersitExisting() { - $data = array(); - - $curbfres = $this->CI->BenutzerfunktionModel->load($this->getBenutzerfunktion_id()); - if(hasData($curbfres)) + protected function loadBenutzerfunktion($bfid) + { + $bfres = $this->CI->BenutzerfunktionModel->load($bfid); + if(!hasData($bfres)) { - $curbf = (getData($curbfres))[0]; - if($this->getVon() < $curbf->datum_von) + throw new Exception('failed to load existing Benutzerfunktion'); + } + return (getData($bfres))[0]; + } + + protected function loadPersitedVB($vbid) + { + $vb = $this->CI->VertragsbestandteilLib->fetchVertragsbestandteil($vbid); + if( $vb === null ) + { + throw new Exception('failed to load persited Vertragsbestandteil'); + } + return $vb; + } + + protected function areVbAndBfInSync($bf) + { + $vbvon = $this->getVon(); + $vbbis = $this->getBis(); + if( intval($this->getVertragsbestandteil_id()) > 0 ) + { + $vb = $this->loadPersitedVB($this->getVertragsbestandteil_id()); + $vbvon = $vb->getVon(); + $vbbis = $vb->getBis(); + } + + if( ($bf->datum_von === $vbvon) && ($bf->datum_bis === $vbbis) ) + { + return true; + } + return false; + } + + protected function isBefore($a, $b) + { + if($b === null) { + return false; + } + elseif($a === null) { + return true; + } + else { + return $a < $b; + } + } + + protected function isAfter($a, $b) + { + if($b === null) { + return false; + } + elseif($a === null) { + return true; + } + else { + return $a > $b; + } + } + + protected function beforePersitExisting() + { + $bf = $this->loadBenutzerfunktion($this->getBenutzerfunktion_id()); + if( $this->areVbAndBfInSync($bf) ) + { + // vb or stored vb von bis is in sync so update benutzerfunktion + $this->updateBenutzerfunktion($bf, $this->getVon(), $this->getBis()); + } + else + { + $daybeforevon = \DateTime::createFromFormat('Y-m-d', $this->getVon(), + new \DateTimeZone('Europe/Vienna')); + $daybeforevon->sub(new \DateInterval('P1D')); + + if( $this->isBefore($this->getVon(), $bf->datum_von) && + $this->isAfter($this->getBis(), $bf->datum_bis) ) { - $data['datum_von'] = $this->getVon(); + $this->updateBenutzerfunktion($bf, $this->getVon(), $this->getBis()); } - if($this->getBis() === null - || ($curbf->datum_bis !== null && ($this->getBis() < $curbf->datum_bis))) + elseif( $this->isBefore($bf->datum_von, $this->getVon()) && + $this->isAfter($this->getBis(), $bf->datum_von) ) { - $data['datum_bis'] = $this->getBis(); + $this->updateBenutzerfunktion($bf, $bf->datum_von, $daybeforevon->format('Y-m-d')); + $data = (object) array( + 'mitarbeiter_uid' => $bf->uid, + 'funktion' => $bf->funktion_kurzbz, + 'orget' => $bf->oe_kurzbz + ); + $this->createBenutzerfunktionData($data); + $bfid = $this->insertBenutzerfunktion($this->benutzerfunktiondata); + $this->setBenutzerfunktion_id($bfid); + } + elseif( $this->isBefore($bf->datum_von, $this->getVon()) && + $this->isBefore($bf->datum_von, $this->getBis()) ) + { + $data = (object) array( + 'mitarbeiter_uid' => $bf->uid, + 'funktion' => $bf->funktion_kurzbz, + 'orget' => $bf->oe_kurzbz + ); + $this->createBenutzerfunktionData($data); + $bfid = $this->insertBenutzerfunktion($this->benutzerfunktiondata); + $this->setBenutzerfunktion_id($bfid); } } + } + + protected function updateBenutzerfunktion($bf, $von, $bis) + { + $data = array(); + + if($von !== $bf->datum_von) + { + $data['datum_von'] = $von; + } + if($bis !== $bf->datum_bis) + { + $data['datum_bis'] = $bis; + } if( count($data) === 0 ) { @@ -67,7 +175,7 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil $data['updateamum'] = strftime('%Y-%m-%d %H:%M:%S'); $data['updatevon'] = getAuthUID(); - $ret = $this->CI->BenutzerfunktionModel->update($this->getBenutzerfunktion_id(), $data); + $ret = $this->CI->BenutzerfunktionModel->update($bf->benutzerfunktion_id, $data); if(isError($ret) ) { @@ -75,22 +183,49 @@ class VertragsbestandteilFunktion extends Vertragsbestandteil } } - protected function beforePersitNew() { - if( $this->benutzerfunktiondata === null) - { - return; - } - - $ret = $this->CI->BenutzerfunktionModel->insert($this->benutzerfunktiondata); + protected function insertBenutzerfunktion($benutzerfunktiondata) + { + $ret = $this->CI->BenutzerfunktionModel->insert($benutzerfunktiondata); if(isError($ret) ) { throw new Exception('failed to create Benutzerfunktion'); } - $this->setBenutzerfunktion_id(getData($ret)); + return getData($ret); } + protected function deleteBenutzerfunktion($benutzerfunktion_id) + { + $ret = $this->CI->BenutzerfunktionModel->delete($benutzerfunktion_id); + + if(isError($ret) ) + { + throw new Exception('failed to delete Benutzerfunktion'); + } + } + + protected function beforePersitNew() { + if( $this->benutzerfunktiondata === null) + { + return; + } + + $bfid = $this->insertBenutzerfunktion($this->benutzerfunktiondata); + + $this->setBenutzerfunktion_id($bfid); + } + + public function afterDelete() + { + if( !(intval($this->getBenutzerfunktion_id()) > 0) ) + { + return; + } + + $this->deleteBenutzerfunktion($this->getBenutzerfunktion_id()); + } + public function toStdClass() { $tmp = array( diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 46d9b00c8..a6c99ab43 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -309,8 +309,8 @@ class VertragsbestandteilLib } catch(Exception $ex) { - throw new Exception('VertragsbestandteilLib updateVertragsbestandteil ' - . 'failed to store Gehaltsbestandteile. ' . $ex->getMessage()); + throw new Exception('VertragsbestandteilLib deleteVertragsbestandteil ' + . 'failed to delete Gehaltsbestandteile. ' . $ex->getMessage()); } @@ -320,6 +320,8 @@ class VertragsbestandteilLib { throw new Exception('error deleting vertragsbestandteil'); } + + $vertragsbestandteil->afterDelete(); } protected function updateVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) diff --git a/composer.json b/composer.json index c5b173e81..0c8cc15b9 100644 --- a/composer.json +++ b/composer.json @@ -330,9 +330,9 @@ "type": "package", "package": { "name": "vuejs/vuejs3", - "version": "3.2.33", + "version": "3.3.8", "dist": { - "url": "https://unpkg.com/vue@3.2.33/dist/vue.global.prod.js", + "url": "https://unpkg.com/vue@3.3.8/dist/vue.global.prod.js", "type": "file" } } @@ -441,7 +441,7 @@ "twbs/bootstrap3": "3.4.*", "twbs/bootstrap5": "5.1.*", - "vuejs/vuejs3": "3.2.33", + "vuejs/vuejs3": "3.3.8", "vuejs/vuerouter4": "4.1.3", "vuejs/vuedatepicker_js": "7.2.0", "vuejs/vuedatepicker_css": "7.2.0" diff --git a/composer.lock b/composer.lock index 30f4ba875..204bfbc71 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4e21d344f075957e02d2dba4f9410325", + "content-hash": "0c2983ac2d380bfba68f9837de857844", "packages": [ { "name": "afarkas/html5shiv", @@ -1868,10 +1868,10 @@ }, { "name": "vuejs/vuejs3", - "version": "3.2.33", + "version": "3.3.8", "dist": { "type": "file", - "url": "https://unpkg.com/vue@3.2.33/dist/vue.global.prod.js" + "url": "https://unpkg.com/vue@3.3.8/dist/vue.global.prod.js" }, "type": "library" }, diff --git a/public/js/components/filter/Filter/Columns.js b/public/js/components/filter/Filter/Columns.js index 47d66d5f1..be29e5f19 100644 --- a/public/js/components/filter/Filter/Columns.js +++ b/public/js/components/filter/Filter/Columns.js @@ -26,8 +26,8 @@ export default { default: [] }, names: { - type: Array, - default: [] + type: Object, + default: {} } }, emits: {