diff --git a/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php b/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php index 5cc264138..3bd36aa78 100644 --- a/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php +++ b/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php @@ -204,8 +204,11 @@ EOTXT; return $this->validationerrors; } - public function validate() { + public function validate() { //do Validation here + $ci = get_instance(); + $ci->load->library('vertragsbestandteil/VertragsbestandteilLib', + null, 'VertragsbestandteilLib'); if( empty($this->mitarbeiter_uid) ) { $this->validationerrors[] = 'Mitarbeiter_UID fehlt.'; @@ -219,6 +222,27 @@ EOTXT; $this->validationerrors[] = 'Vertragsart fehlt.'; } + $von = \DateTimeImmutable::createFromFormat('Y-m-d', $this->von); + $bis = \DateTimeImmutable::createFromFormat('Y-m-d', $this->bis); + + if( false === $von ) { + $this->validationerrors[] = 'Beginn muss ein gültiges Datum sein.'; + } + + if( $this->bis !== null && $bis === false ) { + $this->validationerrors[] = 'Ende muss ein gültiges Datum oder leer sein.'; + } + + if( $this-> bis !== null && $von && $bis && $von > $bis ) { + $this->validationerrors[] = 'Das Beginndatum muss vor dem Endedatum liegen.'; + } + + // TODO check for overlapping DVs + if( $ci->VertragsbestandteilLib->isOverlappingExistingDV($this) ) + { + $this->validationerrors[] = 'Es existiert bereits ein überlappendes Dienstverhältnis'; + } + // return status after Validation if( count($this->validationerrors) > 0 ) { $this->isvalid = false; diff --git a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php index 3c0824f25..b3b2271db 100644 --- a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php @@ -298,6 +298,22 @@ EOTXT; { $this->validationerrors[] = "Betrag fehlt."; } + + $von = \DateTimeImmutable::createFromFormat('Y-m-d', $this->von); + $bis = \DateTimeImmutable::createFromFormat('Y-m-d', $this->bis); + + if( false === $von ) { + $this->validationerrors[] = 'Beginn muss ein gültiges Datum sein.'; + } + + if( $this->bis !== null && $bis === false ) { + $this->validationerrors[] = 'Ende muss ein gültiges Datum oder leer sein.'; + } + + if( $this-> bis !== null && $von && $bis && $von > $bis ) { + $this->validationerrors[] = 'Das Beginndatum muss vor dem Endedatum liegen.'; + } + // return status after Validation if( count($this->validationerrors) > 0 ) { $this->isvalid = false; diff --git a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php index 7f0b2946f..04a8161c4 100644 --- a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php @@ -219,6 +219,21 @@ EOTXT; } public function validate() { + $von = \DateTimeImmutable::createFromFormat('Y-m-d', $this->von); + $bis = \DateTimeImmutable::createFromFormat('Y-m-d', $this->bis); + + if( false === $von ) { + $this->validationerrors[] = 'Beginn muss ein gültiges Datum sein.'; + } + + if( $this->bis !== null && $bis === false ) { + $this->validationerrors[] = 'Ende muss ein gültiges Datum oder leer sein.'; + } + + if( $this-> bis !== null && $von && $bis && $von > $bis ) { + $this->validationerrors[] = 'Das Beginndatum muss vor dem Endedatum liegen.'; + } + if( count($this->validationerrors) > 0 ) { $this->isvalid = false; } else { diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilBefristung.php b/application/libraries/vertragsbestandteil/VertragsbestandteilBefristung.php deleted file mode 100644 index a3d062577..000000000 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilBefristung.php +++ /dev/null @@ -1,92 +0,0 @@ -setVertragsbestandteiltyp_kurzbz( - VertragsbestandteilFactory::VERTRAGSBESTANDTEIL_BEFRISTUNG); - } - - public function hydrateByStdClass($data) - { - parent::hydrateByStdClass($data); - isset($data->befristet) && $this->setBefristet($data->befristet); - isset($data->befristet_bis) && $this->setBefristetBis($data->befristet_bis); - } - - - /** - * Get the value of befristet - */ - public function getBefristet() - { - return $this->befristet; - } - - /** - * Set the value of befristet - */ - public function setBefristet($befristet): self - { - $this->befristet = $befristet; - - return $this; - } - - /** - * Get the value of befristet_bis - */ - public function getBefristetBis() - { - return $this->befristet_bis; - } - - /** - * Set the value of befristet_bis - */ - public function setBefristetBis($befristet_bis): self - { - $this->befristet_bis = $befristet_bis; - - return $this; - } - - public function toStdClass(): \stdClass - { - $tmp = array( - 'vertragsbestandteil_id' => $this->getVertragsbestandteil_id(), - 'befristet' => $this->getBefristet(), - 'befristet_bis' => $this->getBefristetBis() - ); - - $tmp = array_filter($tmp, function($v) { - return !is_null($v); - }); - - return (object) $tmp; - } - - public function __toString() - { - $txt = <<getBefristet()} - befristet_bis: {$this->getBefristetBis()} - -EOTXT; - return parent::__toString() . $txt; - } - - public function validate() - { - return parent::validate(); - } -} diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilFactory.php b/application/libraries/vertragsbestandteil/VertragsbestandteilFactory.php index a00417272..220ee5dff 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilFactory.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilFactory.php @@ -35,39 +35,13 @@ class VertragsbestandteilFactory $vertragsbestandteil = null; switch ($vertragsbestandteiltyp_kurzbz) { - - case self::VERTRAGSBESTANDTEIL_STUNDEN: - $vertragsbestandteil = new VertragsbestandteilStunden(); - $vertragsbestandteil->hydrateByStdClass($data); - break; - - case self::VERTRAGSBESTANDTEIL_FUNKTION: - $vertragsbestandteil = new VertragsbestandteilFunktion(); - $vertragsbestandteil->hydrateByStdClass($data); - break; - - case self::VERTRAGSBESTANDTEIL_GEHALT: - $vertragsbestandteil = new VertragsbestandteilGehalt(); - $vertragsbestandteil->hydrateByStdClass($data); - break; - - case self::VERTRAGSBESTANDTEIL_KUENDIGUNGSFRIST: - $vertragsbestandteil = new VertragsbestandteilKuendigungsfrist(); - $vertragsbestandteil->hydrateByStdClass($data); - break; - case self::VERTRAGSBESTANDTEIL_FREITEXT: $vertragsbestandteil = new VertragsbestandteilFreitext(); $vertragsbestandteil->hydrateByStdClass($data); break; - - case self::VERTRAGSBESTANDTEIL_ZEITAUFZEICHNUNG: - $vertragsbestandteil = new VertragsbestandteilZeitaufzeichnung(); - $vertragsbestandteil->hydrateByStdClass($data); - break; - - case self::VERTRAGSBESTANDTEIL_BEFRISTUNG: - $vertragsbestandteil = new VertragsbestandteilBefristung(); + + case self::VERTRAGSBESTANDTEIL_FUNKTION: + $vertragsbestandteil = new VertragsbestandteilFunktion(); $vertragsbestandteil->hydrateByStdClass($data); break; @@ -76,11 +50,26 @@ class VertragsbestandteilFactory $vertragsbestandteil->hydrateByStdClass($data); break; + case self::VERTRAGSBESTANDTEIL_KUENDIGUNGSFRIST: + $vertragsbestandteil = new VertragsbestandteilKuendigungsfrist(); + $vertragsbestandteil->hydrateByStdClass($data); + break; + + case self::VERTRAGSBESTANDTEIL_STUNDEN: + $vertragsbestandteil = new VertragsbestandteilStunden(); + $vertragsbestandteil->hydrateByStdClass($data); + break; + case self::VERTRAGSBESTANDTEIL_URLAUBSANSPRUCH: $vertragsbestandteil = new VertragsbestandteilUrlaubsanspruch(); $vertragsbestandteil->hydrateByStdClass($data); break; - + + case self::VERTRAGSBESTANDTEIL_ZEITAUFZEICHNUNG: + $vertragsbestandteil = new VertragsbestandteilZeitaufzeichnung(); + $vertragsbestandteil->hydrateByStdClass($data); + break; + default: throw new Exception('Unknown vertragsbestandteiltyp_kurzbz ' . $vertragsbestandteiltyp_kurzbz); @@ -96,28 +85,22 @@ class VertragsbestandteilFactory $vertragsbestandteildbmodel = null; switch ($vertragsbestandteil_kurzbz) { - case self::VERTRAGSBESTANDTEIL_STUNDEN: - $CI->load->model('vertragsbestandteil/VertragsbestandteilStunden_model', - 'VertragsbestandteilStunden_model'); - $vertragsbestandteildbmodel = $CI->VertragsbestandteilStunden_model; + case self::VERTRAGSBESTANDTEIL_FREITEXT: + $CI->load->model('vertragsbestandteil/VertragsbestandteilFreitext_model', + 'VertragsbestandteilFreitext_model'); + $vertragsbestandteildbmodel = $CI->VertragsbestandteilFreitext_model; break; - + case self::VERTRAGSBESTANDTEIL_FUNKTION: $CI->load->model('vertragsbestandteil/VertragsbestandteilFunktion_model', 'VertragsbestandteilFunktion_model'); $vertragsbestandteildbmodel = $CI->VertragsbestandteilFunktion_model; break; - - case self::VERTRAGSBESTANDTEIL_GEHALT: - $CI->load->model('vertragsbestandteil/Gehaltsbestandteil_model', - 'Gehaltsbestandteil_model'); - $vertragsbestandteildbmodel = $CI->Gehaltsbestandteil_model; - break; - - case self::VERTRAGSBESTANDTEIL_FREITEXT: - $CI->load->model('vertragsbestandteil/VertragsbestandteilFreitext_model', - 'VertragsbestandteilFreitext_model'); - $vertragsbestandteildbmodel = $CI->VertragsbestandteilFreitext_model; + + case self::VERTRAGSBESTANDTEIL_KARENZ: + $CI->load->model('vertragsbestandteil/VertragsbestandteilKarenz_model', + 'VertragsbestandteilKarenz_model'); + $vertragsbestandteildbmodel = $CI->VertragsbestandteilKarenz_model; break; case self::VERTRAGSBESTANDTEIL_KUENDIGUNGSFRIST: @@ -125,24 +108,24 @@ class VertragsbestandteilFactory 'VertragsbestandteilKuendigungsfrist_model'); $vertragsbestandteildbmodel = $CI->VertragsbestandteilKuendigungsfrist_model; break; - - case self::VERTRAGSBESTANDTEIL_KARENZ: - $CI->load->model('vertragsbestandteil/VertragsbestandteilKarenz_model', - 'VertragsbestandteilKarenz_model'); - $vertragsbestandteildbmodel = $CI->VertragsbestandteilKarenz_model; + + case self::VERTRAGSBESTANDTEIL_STUNDEN: + $CI->load->model('vertragsbestandteil/VertragsbestandteilStunden_model', + 'VertragsbestandteilStunden_model'); + $vertragsbestandteildbmodel = $CI->VertragsbestandteilStunden_model; break; - - case self::VERTRAGSBESTANDTEIL_ZEITAUFZEICHNUNG: - $CI->load->model('vertragsbestandteil/VertragsbestandteilZeitaufzeichnung_model', - 'VertragsbestandteilZeitaufzeichnung_model'); - $vertragsbestandteildbmodel = $CI->VertragsbestandteilZeitaufzeichnung_model; - break; - + case self::VERTRAGSBESTANDTEIL_URLAUBSANSPRUCH: $CI->load->model('vertragsbestandteil/VertragsbestandteilUrlaubsanspruch_model', 'VertragsbestandteilUrlaubsanspruch_model'); $vertragsbestandteildbmodel = $CI->VertragsbestandteilUrlaubsanspruch_model; break; + + case self::VERTRAGSBESTANDTEIL_ZEITAUFZEICHNUNG: + $CI->load->model('vertragsbestandteil/VertragsbestandteilZeitaufzeichnung_model', + 'VertragsbestandteilZeitaufzeichnung_model'); + $vertragsbestandteildbmodel = $CI->VertragsbestandteilZeitaufzeichnung_model; + break; default: throw new Exception('Unknown vertragsbestandteil_kurzbz ' diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLehre.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLehre.php deleted file mode 100644 index 28a9447a4..000000000 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLehre.php +++ /dev/null @@ -1,69 +0,0 @@ -setVertragsbestandteiltyp_kurzbz( - VertragsbestandteilFactory::VERTRAGSBESTANDTEIL_LEHRE); - } - - public function hydrateByStdClass($data) - { - parent::hydrateByStdClass($data); - isset($data->inkludierte_lehre) && $this->setInkludierteLehre($data->inkludierte_lehre); - } - - /** - * Get the value of inkludierte_lehre - */ - public function getInkludierteLehre() - { - return $this->inkludierte_lehre; - } - - /** - * Set the value of inkludierte_lehre - */ - public function setInkludierteLehre($inkludierte_lehre): self - { - $this->inkludierte_lehre = $inkludierte_lehre; - - return $this; - } - - public function toStdClass(): \stdClass - { - $tmp = array( - 'vertragsbestandteil_id' => $this->getVertragsbestandteil_id(), - 'inkludierte_lehre' => $this->getInkludierteLehre(), - ); - - $tmp = array_filter($tmp, function($v) { - return !is_null($v); - }); - - return (object) $tmp; - } - - public function __toString() - { - $txt = <<getInkludierteLehre()} - -EOTXT; - return parent::__toString() . $txt; - } - - public function validate() - { - return parent::validate(); - } -} diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 8e1420495..0928255ee 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -222,4 +222,14 @@ class VertragsbestandteilLib . 'failed to store Gehaltsbestandteile. ' . $ex->getMessage()); } } + + public function isOverlappingExistingDV(Dienstverhaeltnis $dv) + { + return $this->DienstverhaeltnisModel->isOverlappingExistingDV( + $dv->getMitarbeiter_uid(), + $dv->getOe_kurzbz(), + $dv->getVon(), + $dv->getBis() + ); + } } diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilStunden.php b/application/libraries/vertragsbestandteil/VertragsbestandteilStunden.php index fd4436f72..b5c522e8b 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilStunden.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilStunden.php @@ -15,7 +15,7 @@ use vertragsbestandteil\VertragsbestandteilFactory; class VertragsbestandteilStunden extends Vertragsbestandteil { protected $wochenstunden; - protected $karenz; + protected $teilzeittyp_kurzbz; public function __construct() { @@ -28,7 +28,7 @@ class VertragsbestandteilStunden extends Vertragsbestandteil { parent::hydrateByStdClass($data); isset($data->wochenstunden) && $this->setWochenstunden($data->wochenstunden); - isset($data->karenz) && $this->setKarenz($data->karenz); + isset($data->teilzeittyp_kurzbz) && $this->setTeilzeittyp_kurzbz($data->teilzeittyp_kurzbz); } public function getWochenstunden() @@ -36,9 +36,9 @@ class VertragsbestandteilStunden extends Vertragsbestandteil return $this->wochenstunden; } - public function getKarenz() + public function getTeilzeittyp_kurzbz() { - return $this->karenz; + return $this->teilzeittyp_kurzbz; } public function setWochenstunden($wochenstunden) @@ -47,9 +47,9 @@ class VertragsbestandteilStunden extends Vertragsbestandteil return $this; } - public function setKarenz($karenz) + public function setTeilzeittyp_kurzbz($teilzeittyp_kurzbz) { - $this->karenz = $karenz; + $this->teilzeittyp_kurzbz = $teilzeittyp_kurzbz; return $this; } @@ -58,7 +58,7 @@ class VertragsbestandteilStunden extends Vertragsbestandteil $tmp = array( 'vertragsbestandteil_id' => $this->getVertragsbestandteil_id(), 'wochenstunden' => $this->getWochenstunden(), - 'karenz' => $this->getKarenz() + 'teilzeittyp_kurzbz' => $this->getTeilzeittyp_kurzbz() ); $tmp = array_filter($tmp, function($v) { @@ -72,7 +72,7 @@ class VertragsbestandteilStunden extends Vertragsbestandteil { $txt = <<getWochenstunden()} - karenz: {$this->getKarenz()} + teilzeittyp_kurzbz: {$this->getTeilzeittyp_kurzbz()} EOTXT; return parent::__toString() . $txt; @@ -80,8 +80,15 @@ EOTXT; public function validate() { - if( (floatval($this->wochenstunden) < 1 ) ) { - $this->validationerrors[] = 'Stunden zu niedrig.'; + if( !(filter_var($this->wochenstunden, FILTER_VALIDATE_FLOAT, + array( + 'options' => array( + 'min_range' => 0, + 'max_range' => 100 + ) + ) + )) ) { + $this->validationerrors[] = 'Stunden muss eine Kommazahl im Bereichs 0 bis 100 sein.'; } return parent::validate(); diff --git a/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php b/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php index 3c43a6fb1..00b2b764d 100644 --- a/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php +++ b/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php @@ -73,4 +73,30 @@ class Dienstverhaeltnis_model extends DB_Model return $this->execQuery($qry, array($uid)); } + public function isOverlappingExistingDV($mitarbeiter_uid, $oe_kurzbz, $von, $bis) + { + $query = <<= dv.von +EOSQL; + + $ret = $this->execReadOnlyQuery($query, + array($mitarbeiter_uid, $oe_kurzbz, $von, $bis)); + + if( ($dvcount = getData($ret)) && ($dvcount[0]->dvcount > 0) ) { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/application/models/vertragsbestandteil/VertragsbestandteilBefristung_model.php b/application/models/vertragsbestandteil/VertragsbestandteilBefristung_model.php deleted file mode 100644 index 9166b1c06..000000000 --- a/application/models/vertragsbestandteil/VertragsbestandteilBefristung_model.php +++ /dev/null @@ -1,14 +0,0 @@ -dbTable = 'hr.tbl_vertragsbestandteil_befristung'; - $this->pk = 'vertragsbestandteil_id'; - } -} diff --git a/application/models/vertragsbestandteil/VertragsbestandteilKV_model.php b/application/models/vertragsbestandteil/VertragsbestandteilKV_model.php deleted file mode 100644 index 197d44530..000000000 --- a/application/models/vertragsbestandteil/VertragsbestandteilKV_model.php +++ /dev/null @@ -1,12 +0,0 @@ -dbTable = 'hr.tbl_vertragsbestandteil_kv'; - $this->pk = 'vertragsbestandteil_id'; - } -} diff --git a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php index 3dd6bf6cb..74a3e6964 100644 --- a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php @@ -31,21 +31,29 @@ class Vertragsbestandteil_model extends DB_Model $sql = <<escape($dienstverhaeltnis_id)} {$stichtagclause} @@ -77,21 +85,29 @@ EOSQL; $sql = <<escape($id)} ;