diff --git a/application/libraries/vertragsbestandteil/AbstractBestandteil.php b/application/libraries/vertragsbestandteil/AbstractBestandteil.php index 62c6a2c31..ccd05f5e2 100644 --- a/application/libraries/vertragsbestandteil/AbstractBestandteil.php +++ b/application/libraries/vertragsbestandteil/AbstractBestandteil.php @@ -1,18 +1,26 @@ isvalid = false; + $this->validationerrors = array(); + $this->modifiedcolumns = array(); $this->fromdb = false; } @@ -37,5 +45,25 @@ abstract class AbstractBestandteil } } + public function isValid() + { + return $this->isvalid; + } + + public function getValidationErrors() + { + return $this->validationerrors; + } + + + public function addValidationError($errormsg) + { + if( !in_array($errormsg, $this->validationerrors, true) ) + { + $this->validationerrors[] = $errormsg; + } + $this->isvalid = false; + } + abstract public function hydrateByStdClass($data, $fromdb=false); } diff --git a/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php b/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php index d452f3982..4267432ae 100644 --- a/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php +++ b/application/libraries/vertragsbestandteil/Dienstverhaeltnis.php @@ -16,7 +16,7 @@ const TYPE_ECHT_FREI = 'echterfreier'; const TYPE_WERKVERTRAG = 'werkvertrag'; const TYPE_UEBERLASSUNG = 'ueberlassungsvertrag'; -class Dienstverhaeltnis extends AbstractBestandteil implements IValidation { +class Dienstverhaeltnis extends AbstractBestandteil { protected $dienstverhaeltnis_id; protected $mitarbeiter_uid; protected $vertragsart_kurzbz; @@ -27,15 +27,10 @@ class Dienstverhaeltnis extends AbstractBestandteil implements IValidation { protected $insertvon; protected $updateamum; protected $updatevon; - - protected $isvalid; - protected $validationerrors; public function __construct() { parent::__construct(); - $this->isvalid = false; - $this->validationerrors = array(); } public function hydrateByStdClass($data, $fromdb=false) @@ -211,16 +206,6 @@ EOTXT; return $this; } - public function isValid() - { - return $this->isvalid; - } - - public function getValidationErrors() - { - return $this->validationerrors; - } - public function validate() { //do Validation here $ci = get_instance(); diff --git a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php index 3ad74704b..22f8ee2ae 100644 --- a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php @@ -7,7 +7,7 @@ use DateTimeImmutable; /** * Salary always depends on employment (Dienstverhältnis) and optionally on part of contract (Vetragsbestandteil) */ -class Gehaltsbestandteil extends AbstractBestandteil implements IValidation, \JsonSerializable +class Gehaltsbestandteil extends AbstractBestandteil implements \JsonSerializable { protected $gehaltsbestandteil_id; protected $dienstverhaeltnis_id; @@ -26,15 +26,10 @@ class Gehaltsbestandteil extends AbstractBestandteil implements IValidation, \Js protected $insertvon; protected $updateamum; protected $updatevon; - - protected $isvalid; - protected $validationerrors; public function __construct() { parent::__construct(); - $this->isvalid = false; - $this->validationerrors = array(); } public function hydrateByStdClass($data, $fromdb=false) @@ -326,16 +321,6 @@ EOTXT; return $txt; } - public function isValid() - { - return $this->isvalid; - } - - public function getValidationErrors() - { - return $this->validationerrors; - } - public function validate() { //do Validation here if( empty($this->gehaltstyp_kurzbz) ) diff --git a/application/libraries/vertragsbestandteil/IValidation.php b/application/libraries/vertragsbestandteil/IValidation.php index 2898ec41b..c55e33bcd 100644 --- a/application/libraries/vertragsbestandteil/IValidation.php +++ b/application/libraries/vertragsbestandteil/IValidation.php @@ -13,4 +13,6 @@ interface IValidation public function getValidationErrors(); public function validate(); + + public function addValidationError($errormsg); } diff --git a/application/libraries/vertragsbestandteil/OverlapChecker.php b/application/libraries/vertragsbestandteil/OverlapChecker.php new file mode 100644 index 000000000..816b4a3b9 --- /dev/null +++ b/application/libraries/vertragsbestandteil/OverlapChecker.php @@ -0,0 +1,111 @@ +CI = get_instance(); + $this->CI->load->model('vertragsbestandteil/Vertragsbestandteil_model', + 'VertragsbestandteilModel'); + $this->VertragsbestandteilModel = $this->CI->VertragsbestandteilModel; + $this->CI->load->model('vertragsbestandteil/VertragsbestandteilFreitext_model', + 'VertragsbestandteilFreitextModel'); + $this->VertragsbestandteilFreitextModel = $this->CI->VertragsbestandteilFreitextModel; + $this->CI->load->model('vertragsbestandteil/Vertragsbestandteiltyp_model', + 'VertragsbestandteilTypModel'); + $this->VertragsbestandteilTypModel = $this->CI->VertragsbestandteilTypModel; + $this->CI->load->model('vertragsbestandteil/VertragsbestandteilFreitexttyp_model', + 'VertragsbestandteilFreitexttypModel'); + $this->VertragsbestandteilFreitexttypModel = $this->CI->VertragsbestandteilFreitexttypModel; + } + + public function overlapsVB(Vertragsbestandteil $vb) + { + $result = $this->VertragsbestandteilTypModel->load($vb->getVertragsbestandteiltyp_kurzbz()); + if( null === ($vertragsbestandteiltyp = getData($result)) ) + { + throw new Exception('vertragsbestandteiltyp: ' + . $vb->getVertragsbestandteiltyp_kurzbz() . ' not found.'); + } + + if( true === $vertragsbestandteiltyp[0]->ueberlappend ) + { + // vertragsbestandteiltyp can overlap + return false; + } + + if( $this->VertragsbestandteilModel->countOverlappingVBsOfSameType($vb) === 0 ) + { + return false; + } + else + { + return true; + } + } + + public function overlapsFreitext(VertragsbestandteilFreitext $vbft) + { + $result = $this->VertragsbestandteilFreitexttypModel->load($vbft->getFreitexttypKurzbz()); + if( null === ($vertragsbestandteilfreitexttyp = getData($result)) ) + { + throw new Exception('vertragsbestandteilfreitexttyp: ' + . $vbft->getFreitexttypKurzbz() . ' not found.'); + } + + if( true === $vertragsbestandteilfreitexttyp[0]->ueberlappend ) + { + // freitexttyp can overlap + return false; + } + + if( $this->VertragsbestandteilFreitextModel->countOverlappingVBFreitextsOfSameType($vbft) === 0 ) + { + return false; + } + else + { + return true; + } + } + + private function __clone() {} +} diff --git a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php index beda78773..2f70f02d8 100644 --- a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php @@ -8,7 +8,7 @@ use vertragsbestandteil\AbstractBestandteil; * * @author bambi */ -abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonSerializable, IValidation +abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonSerializable { protected $vertragsbestandteil_id; protected $dienstverhaeltnis_id; @@ -21,16 +21,11 @@ abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonS protected $updatevon; protected $gehaltsbestandteile; - - protected $isvalid; - protected $validationerrors; public function __construct() { parent::__construct(); $this->gehaltsbestandteile = array(); - $this->isvalid = false; - $this->validationerrors = array(); } public function hydrateByStdClass($data, $fromdb=false) @@ -237,16 +232,6 @@ EOTXT; // can be overridden in childs } - public function isValid() - { - return $this->isvalid; - } - - public function getValidationErrors() - { - return $this->validationerrors; - } - 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/VertragsbestandteilFreitext.php b/application/libraries/vertragsbestandteil/VertragsbestandteilFreitext.php index 8d16e0ef0..07e8a3c58 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilFreitext.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilFreitext.php @@ -129,4 +129,6 @@ EOTXT; return parent::validate(); } + + } diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 053453025..46d9b00c8 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -11,6 +11,7 @@ require_once __DIR__ . '/VertragsbestandteilUrlaubsanspruch.php'; require_once __DIR__ . '/VertragsbestandteilFreitext.php'; require_once __DIR__ . '/VertragsbestandteilKarenz.php'; require_once __DIR__ . '/VertragsbestandteilFactory.php'; +require_once __DIR__ . '/OverlapChecker.php'; use vertragsbestandteil\Dienstverhaeltnis; use vertragsbestandteil\Vertragsbestandteil; diff --git a/application/models/vertragsbestandteil/VertragsbestandteilFreitext_model.php b/application/models/vertragsbestandteil/VertragsbestandteilFreitext_model.php index 7da091f11..3ef815884 100644 --- a/application/models/vertragsbestandteil/VertragsbestandteilFreitext_model.php +++ b/application/models/vertragsbestandteil/VertragsbestandteilFreitext_model.php @@ -9,4 +9,43 @@ class VertragsbestandteilFreitext_model extends DB_Model $this->dbTable = 'hr.tbl_vertragsbestandteil_freitext'; $this->pk = 'vertragsbestandteil_id'; } + + public function countOverlappingVBFreitextsOfSameType(vertragsbestandteil\VertragsbestandteilFreitext $vbft) + { + $notselfclause = (intval($vbft->getVertragsbestandteil_id()) > 0) + ? 'AND v.vertragsbestandteil_id <> ' . $this->escape($vbft->getVertragsbestandteil_id()) + : ''; + $sql = <<= COALESCE(v.von, '1970-01-01'::date) + AND + ?::date <= COALESCE(v.bis, '2170-12-31') + {$notselfclause} +EOSQL; + $ret = $this->execReadOnlyQuery($sql, array( + $vbft->getDienstverhaeltnis_id(), + $vbft->getVertragsbestandteiltyp_kurzbz(), + $vbft->getFreitexttypKurzbz(), + $vbft->getBis(), + $vbft->getVon() + )); + + if( null === ($vbcount = getData($ret)) ) { + throw new Exception('failed to fetch overlappingvbs count'); + } + + return $vbcount[0]->overlappingvbs; + } } diff --git a/application/models/vertragsbestandteil/VertragsbestandteilFreitexttyp_model.php b/application/models/vertragsbestandteil/VertragsbestandteilFreitexttyp_model.php new file mode 100644 index 000000000..09d2380b6 --- /dev/null +++ b/application/models/vertragsbestandteil/VertragsbestandteilFreitexttyp_model.php @@ -0,0 +1,12 @@ +dbTable = 'hr.tbl_vertragsbestandteil_freitexttyp'; + $this->pk = 'freitexttyp_kurzbz'; + } +} diff --git a/application/models/vertragsbestandteil/VertragsbestandteilTyp_model.php b/application/models/vertragsbestandteil/VertragsbestandteilTyp_model.php new file mode 100644 index 000000000..f64cb70f4 --- /dev/null +++ b/application/models/vertragsbestandteil/VertragsbestandteilTyp_model.php @@ -0,0 +1,12 @@ +dbTable = 'hr.tbl_vertragsbestandteiltyp'; + $this->pk = 'vertragsbestandteiltyp_kurzbz'; + } +} diff --git a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php index 028080c4c..fae728fd9 100644 --- a/application/models/vertragsbestandteil/Vertragsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Vertragsbestandteil_model.php @@ -143,4 +143,38 @@ EOSQL; return $vertragsbestandteil; } + + public function countOverlappingVBsOfSameType(vertragsbestandteil\Vertragsbestandteil $vb) + { + $notselfclause = (intval($vb->getVertragsbestandteil_id()) > 0) + ? 'AND v.vertragsbestandteil_id <> ' . $this->escape($vb->getVertragsbestandteil_id()) + : ''; + $sql = <<= COALESCE(v.von, '1970-01-01'::date) + AND + ?::date <= COALESCE(v.bis, '2170-12-31') + {$notselfclause} +EOSQL; + $ret = $this->execReadOnlyQuery($sql, array( + $vb->getDienstverhaeltnis_id(), + $vb->getVertragsbestandteiltyp_kurzbz(), + $vb->getBis(), + $vb->getVon() + )); + + if( null === ($vbcount = getData($ret)) ) { + throw new Exception('failed to fetch overlappingvbs count'); + } + + return $vbcount[0]->overlappingvbs; + } }