diff --git a/application/controllers/system/MigrateContract.php b/application/controllers/system/MigrateContract.php index 99b894473..f011be356 100644 --- a/application/controllers/system/MigrateContract.php +++ b/application/controllers/system/MigrateContract.php @@ -677,4 +677,35 @@ class MigrateContract extends CLI_Controller else return 0; } + + /** + * Habilitation wird aus der Tabelle bis.tbl_bisverwendung in die Tabelle public.tbl_mitarbeiter uebernommen + * Sofern die Person einmal in den Verwendungen eine habiliation eingetragen hat wird diese in den MA-Datensatz übernommen + * Da es in der regel öfter vorkommt dass das hakerl vergessen wurde beim Vertragswechsel als dass die person die habiliation verliert. + */ + public function migrateHabilitation() + { + $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); + $db = new DB_Model(); + + $qry = " + SELECT + distinct mitarbeiter_uid + FROM + bis.tbl_bisverwendung + WHERE + habilitation=true"; + + $resultHabilitation = $db->execReadOnlyQuery($qry); + + if (isSuccess($resultHabilitation) && hasData($resultHabilitation)) + { + $habilitationen = getData($resultHabilitation); + + foreach ($habilitationen as $row_habilitationen) + { + $this->MitarbeiterModel->update($row_habilitationen->mitarbeiter_uid, array('habilitation'=>true)); + } + } + } } diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 8fb3900d5..6abbd81f9 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -26,30 +26,35 @@ class VertragsbestandteilLib { const INCLUDE_FUTURE = true; const DO_NOT_INCLUDE_FUTURE = false; - + protected $CI; /** @var Dienstverhaeltnis_model */ protected $DienstverhaeltnisModel; /** @var Vertragsbestandteil_model */ protected $VertragsbestandteilModel; - /** + /** @var Benutzer_model */ + protected $BenutzerModel; + /** * @var GehaltsbestandteilLib */ protected $GehaltsbestandteilLib; - + protected $loggedInUser; - + public function __construct() { $this->loggedInUser = getAuthUID(); $this->CI = get_instance(); - $this->CI->load->model('vertragsbestandteil/Dienstverhaeltnis_model', + $this->CI->load->model('vertragsbestandteil/Dienstverhaeltnis_model', 'DienstverhaeltnisModel'); $this->DienstverhaeltnisModel = $this->CI->DienstverhaeltnisModel; - $this->CI->load->model('vertragsbestandteil/Vertragsbestandteil_model', + $this->CI->load->model('vertragsbestandteil/Vertragsbestandteil_model', 'VertragsbestandteilModel'); $this->VertragsbestandteilModel = $this->CI->VertragsbestandteilModel; - $this->CI->load->library('vertragsbestandteil/GehaltsbestandteilLib', + $this->CI->load->model('person/benutzer_model', + 'BenutzerModel'); + $this->BenutzerModel = $this->CI->BenutzerModel; + $this->CI->load->library('vertragsbestandteil/GehaltsbestandteilLib', null, 'GehaltsbestandteilLib'); $this->GehaltsbestandteilLib = $this->CI->GehaltsbestandteilLib; } @@ -63,7 +68,7 @@ class VertragsbestandteilLib } catch (Exception $ex) { log_message('debug', "Error handling json data from GUI. " . $ex->getMessage()); - } + } return $ret; } @@ -72,40 +77,40 @@ class VertragsbestandteilLib { $result = $this->DienstverhaeltnisModel->load($dienstverhaeltnis_id); $dv = null; - if(null !== ($row = getData($result))) + if(null !== ($row = getData($result))) { $dv = new Dienstverhaeltnis(); $dv->hydrateByStdClass($row[0], true); } return $dv; } - + public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false) { $vbs = $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture); $gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture); - + $gbsByVBid = array(); - foreach( $gbs as $gb ) + foreach( $gbs as $gb ) { - if( intval($gb->getVertragsbestandteil_id()) > 0 ) + if( intval($gb->getVertragsbestandteil_id()) > 0 ) { - if( !isset($gbsByVBid[$gb->getVertragsbestandteil_id()]) + 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()]) ) + if( isset($gbsByVBid[$vb->getVertragsbestandteil_id()]) ) { $vb->setGehaltsbestandteile($gbsByVBid[$vb->getVertragsbestandteil_id()]); } } - + return $vbs; } @@ -113,22 +118,22 @@ class VertragsbestandteilLib { return $this->VertragsbestandteilModel->getVertragsbestandteil($vertragsbestandteil_id); } - + public function storeDienstverhaeltnis(Dienstverhaeltnis $dv) { if( intval($dv->getDienstverhaeltnis_id()) > 0 ) { $this->updateDienstverhaeltnis($dv); } - else + else { - $this->insertDienstverhaeltnis($dv); + $this->insertDienstverhaeltnis($dv); } } - - public function storeVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) + + public function storeVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) { - $this->CI->db->trans_begin(); + $this->CI->db->trans_begin(); try { $this->setUIDtoPGSQL(); @@ -144,7 +149,7 @@ class VertragsbestandteilLib { log_message('debug', "Transaction failed"); throw new Exception("Transaction failed"); - } + } $this->CI->db->trans_commit(); } catch (Exception $ex) @@ -152,7 +157,7 @@ class VertragsbestandteilLib log_message('debug', "Transaction rolled back. " . $ex->getMessage()); $this->CI->db->trans_rollback(); throw new Exception('Storing Vertragsbestandteil failed.'); - } + } } public function deleteDienstverhaeltnis(Dienstverhaeltnis $dv) @@ -220,13 +225,13 @@ class VertragsbestandteilLib throw new Exception('Delete Vertragsbestandteil failed.'); } } - + protected function insertDienstverhaeltnis(Dienstverhaeltnis $dv) { $dv->setInsertvon($this->loggedInUser) ->setInsertamum(strftime('%Y-%m-%d %H:%M:%S')); $ret = $this->DienstverhaeltnisModel->insert($dv->toStdClass()); - if( hasData($ret) ) + if( hasData($ret) ) { $dv->setDienstverhaeltnis_id(getData($ret)); } @@ -235,14 +240,14 @@ class VertragsbestandteilLib throw new Exception('error inserting dienstverhaeltnis'); } } - + protected function insertVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) { $vertragsbestandteil->setInsertvon($this->loggedInUser) ->setInsertamum(strftime('%Y-%m-%d %H:%M:%S')); $vertragsbestandteil->beforePersist(); $ret = $this->VertragsbestandteilModel->insert($vertragsbestandteil->baseToStdClass()); - if( hasData($ret) ) + if( hasData($ret) ) { $vertragsbestandteil->setVertragsbestandteil_id(getData($ret)); } @@ -254,19 +259,19 @@ class VertragsbestandteilLib $specialisedModel = VertragsbestandteilFactory::getVertragsbestandteilDBModel( $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); $retspecial = $specialisedModel->insert($vertragsbestandteil->toStdClass()); - + if(isError($retspecial) ) { - throw new Exception('error updating vertragsbestandteil ' + throw new Exception('error updating vertragsbestandteil ' . $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); } - - try + + try { $gehaltsbestandteile = $vertragsbestandteil->getGehaltsbestandteile(); $this->GehaltsbestandteilLib->storeGehaltsbestandteile($gehaltsbestandteile); - } - catch(Exception $ex) + } + catch(Exception $ex) { throw new Exception('VertragsbestandteilLib insertVertragsbestandteil ' . 'failed to store Gehaltsbestandteile. ' . $ex->getMessage()); @@ -278,7 +283,7 @@ class VertragsbestandteilLib if(!$dv->isDirty()) { return; } - + $dv->setUpdatevon($this->loggedInUser) ->setUpdateamum(strftime('%Y-%m-%d %H:%M:%S')); $ret = $this->DienstverhaeltnisModel->update($dv->getDienstverhaeltnis_id(), @@ -288,20 +293,20 @@ class VertragsbestandteilLib throw new Exception('error updating dienstverhaeltnis'); } } - + private function deleteVertragsbestandteilHelper(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()); } - + try { $gehaltsbestandteile = $vertragsbestandteil->getGehaltsbestandteile(); @@ -320,76 +325,118 @@ class VertragsbestandteilLib { throw new Exception('error deleting vertragsbestandteil'); } - + $vertragsbestandteil->afterDelete(); } protected function updateVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) { - if($vertragsbestandteil->isDirty()) { + if($vertragsbestandteil->isDirty()) { $vertragsbestandteil->setUpdatevon($this->loggedInUser) ->setUpdateamum(strftime('%Y-%m-%d %H:%M:%S')); $vertragsbestandteil->beforePersist(); $basedata = $vertragsbestandteil->baseToStdClass(); - if( count((array) $basedata) > 0 ) + if( count((array) $basedata) > 0 ) { $ret = $this->VertragsbestandteilModel->update( - $vertragsbestandteil->getVertragsbestandteil_id(), + $vertragsbestandteil->getVertragsbestandteil_id(), $basedata); if(isError($ret) ) { throw new Exception('error updating vertragsbestandteil'); - } + } } $specialisedData = $vertragsbestandteil->toStdClass(); - if( count((array) $specialisedData) > 0 ) + if( count((array) $specialisedData) > 0 ) { $specialisedModel = VertragsbestandteilFactory::getVertragsbestandteilDBModel( $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); $retspecial = $specialisedModel->update( - $vertragsbestandteil->getVertragsbestandteil_id(), + $vertragsbestandteil->getVertragsbestandteil_id(), $specialisedData); if(isError($retspecial) ) { - throw new Exception('error updating vertragsbestandteil ' + throw new Exception('error updating vertragsbestandteil ' . $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); } } } - - try + + try { $gehaltsbestandteile = $vertragsbestandteil->getGehaltsbestandteile(); $this->GehaltsbestandteilLib->storeGehaltsbestandteile($gehaltsbestandteile); - } - catch(Exception $ex) + } + catch(Exception $ex) { throw new Exception('VertragsbestandteilLib updateVertragsbestandteil ' . 'failed to store Gehaltsbestandteile. ' . $ex->getMessage()); } } - - public function isOverlappingExistingDV(Dienstverhaeltnis $dv) + + public function isOverlappingExistingDV(Dienstverhaeltnis $dv) { return $this->DienstverhaeltnisModel->isOverlappingExistingDV( - $dv->getMitarbeiter_uid(), - $dv->getOe_kurzbz(), - $dv->getVon(), + $dv->getMitarbeiter_uid(), + $dv->getOe_kurzbz(), + $dv->getVon(), $dv->getBis(), $dv->getDienstverhaeltnis_id() ); } - + + protected function hasOtherActiveDV(Dienstverhaeltnis $dv, $duedate) + { + $hasotheractivedv = false; + $result = $this->DienstverhaeltnisModel->getDVByPersonUID($dv->getMitarbeiter_uid(), null, $duedate); + $dvs = getData($result); + foreach ($dvs as $tmpdv) + { + if(intval($tmpdv->dienstverhaeltnis_id) !== intval($dv->getDienstverhaeltnis_id())) + { + $hasotheractivedv = true; + break; + } + } + return $hasotheractivedv; + } + + /** + * like endDienstverhaeltnis, but also sets aktiv flag to false + */ + public function deactivateDienstverhaeltnis(Dienstverhaeltnis $dv, $enddate, $deactivate) + { + $result = $this->endDienstverhaeltnis($dv, $enddate); + if ( $result === true) + { + if (!$deactivate) return $result; + + if(!$this->hasOtherActiveDV($dv, $enddate)) + { + $result = $this->BenutzerModel->update( + array('uid' => $dv->getMitarbeiter_uid()), + array( + 'aktiv' => false, + 'updateaktivam' => date('Y-m-d'), + 'updateaktivvon' => $this->loggedInUser + ) + ); + } + } + + return $result; + } + public function endDienstverhaeltnis(Dienstverhaeltnis $dv, $enddate) { - if( $dv->getBis() !== null && $dv->getBis() < $enddate ) + if( $dv->getBis() !== null && $dv->getBis() < $enddate ) { return 'Dienstverhältnis ist bereits beendet.'; } - + $this->CI->db->trans_begin(); try { @@ -401,13 +448,13 @@ class VertragsbestandteilLib { $this->GehaltsbestandteilLib->endGehaltsbestandteil($gb, $enddate); } - + $vbs = $this->fetchVertragsbestandteile($dv->getDienstverhaeltnis_id()); foreach ($vbs as $vb) { $this->endVertragsbestandteil($vb, $enddate); - } - + } + $dv->setBis($enddate); $this->updateDienstverhaeltnis($dv); @@ -428,23 +475,23 @@ class VertragsbestandteilLib } return true; } - + public function endVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil, $enddate) { - if( $vertragsbestandteil->getBis() !== null && $vertragsbestandteil->getBis() < $enddate ) + if( $vertragsbestandteil->getBis() !== null && $vertragsbestandteil->getBis() < $enddate ) { return; } - + $vertragsbestandteil->setBis($enddate); $this->updateVertragsbestandteil($vertragsbestandteil); } - + protected function setUIDtoPGSQL() { $ret = $this->VertragsbestandteilModel - ->execReadOnlyQuery('SET LOCAL pv21.uid TO \'' + ->execReadOnlyQuery('SET LOCAL pv21.uid TO \'' . $this->loggedInUser . '\''); - if(isError($ret)) + if(isError($ret)) { throw new Exception('error setting uid to pgsql'); } diff --git a/application/models/ressource/Zeitaufzeichnung_model.php b/application/models/ressource/Zeitaufzeichnung_model.php index b44861d13..8639a716a 100644 --- a/application/models/ressource/Zeitaufzeichnung_model.php +++ b/application/models/ressource/Zeitaufzeichnung_model.php @@ -21,4 +21,26 @@ class Zeitaufzeichnung_model extends DB_Model return $this->execQuery($qry); } + + public function getFullInterval($uid, $fromDate, $toDate) + { + $qry = <<execQuery($qry, array($uid, $fromDate, $toDate, $uid, $fromDate, $toDate, $fromDate, $toDate)); + } } diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index ca43763f2..72b07721f 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -48,6 +48,7 @@ require_once('dbupdate_3.4/30181_tabelle_anrechnung_neue_attribute_fuer_begruend require_once('dbupdate_3.4/29529_infocenter_anpassungen.php'); require_once('dbupdate_3.4/29835_uhstat1_erfassung_der_uhstat1_daten_ueber_das_bewerbungstool.php'); require_once('dbupdate_3.4/33714_erhoehter_studienbeitrag_fuer_drittsaatenangehoerig.php'); +require_once('dbupdate_3.4/33003_bis_meldung_personal.php'); require_once('dbupdate_3.4/36275_zeitaufzeichnung_karenz.php'); require_once('dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php'); require_once('dbupdate_3.4/36530_bis_internationsalisierung_codextabelle_neuerungen.php'); diff --git a/system/dbupdate_3.4/33003_bis_meldung_personal.php b/system/dbupdate_3.4/33003_bis_meldung_personal.php new file mode 100644 index 000000000..eb49217ea --- /dev/null +++ b/system/dbupdate_3.4/33003_bis_meldung_personal.php @@ -0,0 +1,14 @@ +db_query("SELECT habilitation FROM public.tbl_mitarbeiter LIMIT 1")) +{ + $qry = "ALTER TABLE public.tbl_mitarbeiter ADD COLUMN habilitation boolean NOT NULL DEFAULT false; + COMMENT ON COLUMN public.tbl_mitarbeiter.habilitation IS 'Zeigt an, ob Mitarbeiter habilitiert ist (BIS relevant).';"; + + if(!$db->db_query($qry)) + echo 'public.tbl_mitarbeiter '.$db->db_last_error().'
'; + else + echo '
Spalte habilitation zu Tabelle public.tbl_mitarbeiter hinzugefügt'; +} diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 1144eed90..a0fd65819 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -23978,6 +23978,26 @@ array( ) ) ), + array( + 'app' => 'personalverwaltung', + 'category' => 'person', + 'phrase' => 'habilitation', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Habilitation', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Habilitation', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), array( 'app' => 'personalverwaltung', 'category' => 'person', @@ -24298,6 +24318,26 @@ array( ) ) ), + array( + 'app' => 'personalverwaltung', + 'category' => 'zeitaufzeichnung', + 'phrase' => 'id', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'ID', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'ID', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), // Personalverwaltung end array( 'app' => 'core',