mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
add Models for Vertragsbestandteiltyp and VertragsbestandteilFreitexttyp, implement IValidation Interface on AbstrcatBestandteil, add OverlapChecker checking for overlapping VBs against DB
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
<?php
|
||||
namespace vertragsbestandteil;
|
||||
|
||||
use vertragsbestandteil\IValidation;
|
||||
|
||||
/**
|
||||
* Description of AbstractBestandteil
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
abstract class AbstractBestandteil
|
||||
abstract class AbstractBestandteil implements IValidation
|
||||
{
|
||||
protected $isvalid;
|
||||
protected $validationerrors;
|
||||
|
||||
protected $modifiedcolumns;
|
||||
protected $fromdb;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) )
|
||||
|
||||
@@ -13,4 +13,6 @@ interface IValidation
|
||||
public function getValidationErrors();
|
||||
|
||||
public function validate();
|
||||
|
||||
public function addValidationError($errormsg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace vertragsbestandteil;
|
||||
|
||||
use vertragsbestandteil\Vertragsbestandteil;
|
||||
use vertragsbestandteil\VertragsbestandteilFreitext;
|
||||
|
||||
/**
|
||||
* Description of OverlapChecker
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
class OverlapChecker
|
||||
{
|
||||
protected $CI;
|
||||
/**
|
||||
* @var Vertragsbestandteil_model
|
||||
*/
|
||||
protected $VertragsbestandteilModel;
|
||||
/**
|
||||
* @var VertragsbestandteilFreitext_model
|
||||
*/
|
||||
protected $VertragsbestandteilFreitextModel;
|
||||
/**
|
||||
* @var VertragsbestandteilTyp_model
|
||||
*/
|
||||
protected $VertragsbestandteilTypModel;
|
||||
/**
|
||||
* @var VertragsbestandteilFreitexttyp_model
|
||||
*/
|
||||
protected $VertragsbestandteilFreitexttypModel;
|
||||
|
||||
protected static $instance = null;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if( null === self::$instance )
|
||||
{
|
||||
self::$instance = new OverlapChecker();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->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() {}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -129,4 +129,6 @@ EOTXT;
|
||||
|
||||
return parent::validate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = <<<EOSQL
|
||||
SELECT
|
||||
count(*) AS overlappingvbs
|
||||
FROM
|
||||
hr.tbl_vertragsbestandteil v
|
||||
JOIN
|
||||
hr.tbl_vertragsbestandteil_freitext vbft USING(vertragsbestandteil_id)
|
||||
WHERE
|
||||
v.dienstverhaeltnis_id = ?
|
||||
AND
|
||||
v.vertragsbestandteiltyp_kurzbz = ?
|
||||
AND
|
||||
vbft.freitexttyp_kurzbz = ?
|
||||
AND
|
||||
COALESCE(?::date, '2170-12-31'::date) >= 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class VertragsbestandteilFreitexttyp_model extends DB_Model
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'hr.tbl_vertragsbestandteil_freitexttyp';
|
||||
$this->pk = 'freitexttyp_kurzbz';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class VertragsbestandteilTyp_model extends DB_Model
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'hr.tbl_vertragsbestandteiltyp';
|
||||
$this->pk = 'vertragsbestandteiltyp_kurzbz';
|
||||
}
|
||||
}
|
||||
@@ -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 = <<<EOSQL
|
||||
SELECT
|
||||
count(*) AS overlappingvbs
|
||||
FROM
|
||||
hr.tbl_vertragsbestandteil v
|
||||
WHERE
|
||||
v.dienstverhaeltnis_id = ?
|
||||
AND
|
||||
v.vertragsbestandteiltyp_kurzbz = ?
|
||||
AND
|
||||
COALESCE(?::date, '2170-12-31'::date) >= 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user