Merge branch 'master' into merge_FHC4_C4

This commit is contained in:
Harald Bamberger
2025-01-28 16:54:08 +01:00
6 changed files with 319 additions and 72 deletions
+22 -16
View File
@@ -991,14 +991,17 @@ class DB_Model extends CI_Model
// Find and replace all the occurrences of the provided encrypted columns
// with the postgresql decryption function
$query = preg_replace(
'/\b' . $encryptedColumn . '\b/',
sprintf(
self::CRYPT_WHERE_TEMPLATE,
$encryptedColumn,
$decryptionPassword,
$definition[self::CRYPT_CAST]
),
$query = preg_replace_callback(
'/(?<! (as|AS) )\b(\w+\.)?(' . $encryptedColumn . ')\b/',
function($matches) use (&$decryptionPassword, &$definition) {
$aliased_column = $matches[2] . $matches[3];
return sprintf(
self::CRYPT_WHERE_TEMPLATE,
$aliased_column,
$decryptionPassword,
$definition[self::CRYPT_CAST]
);
},
$query
);
}
@@ -1106,14 +1109,17 @@ class DB_Model extends CI_Model
{
// Find and replace all the occurrences of the provided encrypted columns
// with the postgresql decryption function
$where = preg_replace(
'/\b' . $encryptedColumn . '\b/',
sprintf(
self::CRYPT_WHERE_TEMPLATE,
$encryptedColumn,
$decryptionPassword,
$definition[self::CRYPT_CAST]
),
$where = preg_replace_callback(
'/(?<! (as|AS) )\b(\w+\.)?(' . $encryptedColumn . ')\b/',
function($matches) use (&$decryptionPassword, &$definition) {
$aliased_column = $matches[2] . $matches[3];
return sprintf(
self::CRYPT_WHERE_TEMPLATE,
$aliased_column,
$decryptionPassword,
$definition[self::CRYPT_CAST]
);
},
$where
);
}
@@ -28,9 +28,12 @@ class GehaltsbestandteilLib
$this->GehaltsbestandteilModel = $this->CI->GehaltsbestandteilModel;
}
public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null,
$includefuture=false, $withvalorisationhistory=true)
{
return $this->GehaltsbestandteilModel->getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture);
return $this->GehaltsbestandteilModel->getGehaltsbestandteile(
$dienstverhaeltnis_id, $stichtag, $includefuture, $withvalorisationhistory
);
}
public function fetchGehaltsbestandteil($gehaltsbestandteil_id)
@@ -26,6 +26,8 @@ class VertragsbestandteilLib
{
const INCLUDE_FUTURE = true;
const DO_NOT_INCLUDE_FUTURE = false;
const WITH_VALORISATION_HISTORY = true;
const NOT_WITH_VALORISATION_HISTORY = false;
protected $CI;
/** @var Dienstverhaeltnis_model */
@@ -90,10 +92,15 @@ class VertragsbestandteilLib
return $dv;
}
public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
public function fetchVertragsbestandteile($dienstverhaeltnis_id, $stichtag=null,
$includefuture=false, $withvalorisationhistory=true)
{
$vbs = $this->VertragsbestandteilModel->getVertragsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture);
$gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture);
$vbs = $this->VertragsbestandteilModel->getVertragsbestandteile(
$dienstverhaeltnis_id, $stichtag, $includefuture
);
$gbs = $this->GehaltsbestandteilLib->fetchGehaltsbestandteile(
$dienstverhaeltnis_id, $stichtag, $includefuture, $withvalorisationhistory
);
$gbsByVBid = array();
foreach( $gbs as $gb )
@@ -33,41 +33,84 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption
$datestring = $date->format("Y-m-d");
$qry = "
SELECT
gehaltsbestandteil_id,
gbt.von,
gbt.bis,
gbt.anmerkung,
gbt.dienstverhaeltnis_id,
gehaltstyp_kurzbz,
valorisierungssperre,
gbt.valorisierung,
grundbetrag as grund_betrag_decrypted,
betrag_valorisiert as betrag_val_decrypted,
gt.bezeichnung as gehaltstyp_bezeichnung,
vb.vertragsbestandteiltyp_kurzbz,
bf.funktion_kurzbz,
bf.oe_kurzbz,
fkt.beschreibung as fkt_beschreibung,
fb.bezeichnung as fb_bezeichnung,
org.bezeichnung as org_bezeichnung,
freitext.freitexttyp_kurzbz,
freitext.titel as freitext_titel
FROM hr.tbl_gehaltsbestandteil gbt LEFT JOIN hr.tbl_gehaltstyp gt using(gehaltstyp_kurzbz)
LEFT JOIN hr.tbl_vertragsbestandteil vb using(vertragsbestandteil_id)
LEFT JOIN hr.tbl_vertragsbestandteil_funktion vbf using(vertragsbestandteil_id)
LEFT JOIN public.tbl_benutzerfunktion bf using(benutzerfunktion_id)
LEFT JOIN public.tbl_funktion fkt using(funktion_kurzbz)
LEFT JOIN public.tbl_fachbereich fb using(fachbereich_kurzbz)
LEFT JOIN public.tbl_organisationseinheit org on (bf.oe_kurzbz=org.oe_kurzbz)
LEFT JOIN hr.tbl_vertragsbestandteil_freitext freitext on(vb.vertragsbestandteil_id=freitext.vertragsbestandteil_id)
WHERE gbt.dienstverhaeltnis_id=? AND
(gbt.von<=? and (gbt.bis is null OR gbt.bis>=?))
ORDER BY gt.sort
with gbt as (
select
gb.gehaltsbestandteil_id,
gb.von,
gb.bis,
gb.anmerkung,
gb.dienstverhaeltnis_id,
gb.gehaltstyp_kurzbz,
gb.valorisierungssperre,
gb.valorisierung,
gb.grundbetrag as grund_betrag_decrypted,
coalesce(vh.betrag_valorisiert, gb.grundbetrag) as betrag_val_decrypted,
gb.vertragsbestandteil_id
from
hr.tbl_gehaltsbestandteil gb
LEFT JOIN
hr.tbl_valorisierung_historie vh ON vh.gehaltsbestandteil_id = gb.gehaltsbestandteil_id AND vh.valorisierungsdatum = (
SELECT
vi.valorisierungsdatum
FROM
hr.tbl_valorisierung_instanz vi
JOIN
hr.tbl_dienstverhaeltnis d ON d.dienstverhaeltnis_id = ?
AND d.oe_kurzbz = vi.oe_kurzbz
WHERE
? >= valorisierungsdatum
ORDER BY
valorisierungsdatum DESC
LIMIT 1
)
where
dienstverhaeltnis_id = ?
and (
? BETWEEN COALESCE(von, '1970-01-01'::date) AND COALESCE(bis, '2170-01-01'::date)
)
)
select
gbt.gehaltsbestandteil_id,
gbt.von,
gbt.bis,
gbt.anmerkung,
gbt.dienstverhaeltnis_id,
gbt.gehaltstyp_kurzbz,
gbt.valorisierungssperre,
gbt.valorisierung,
gbt.grund_betrag_decrypted,
gbt.betrag_val_decrypted,
gt.bezeichnung as gehaltstyp_bezeichnung,
vb.vertragsbestandteiltyp_kurzbz,
bf.funktion_kurzbz,
bf.oe_kurzbz,
fkt.beschreibung as fkt_beschreibung,
fb.bezeichnung as fb_bezeichnung,
org.bezeichnung as org_bezeichnung,
freitext.freitexttyp_kurzbz,
freitext.titel as freitext_titel
from
gbt
LEFT JOIN
hr.tbl_gehaltstyp gt using(gehaltstyp_kurzbz)
LEFT JOIN
hr.tbl_vertragsbestandteil vb using(vertragsbestandteil_id)
LEFT JOIN
hr.tbl_vertragsbestandteil_funktion vbf using(vertragsbestandteil_id)
LEFT JOIN
public.tbl_benutzerfunktion bf using(benutzerfunktion_id)
LEFT JOIN
public.tbl_funktion fkt using(funktion_kurzbz)
LEFT JOIN
public.tbl_fachbereich fb using(fachbereich_kurzbz)
LEFT JOIN
public.tbl_organisationseinheit org on (bf.oe_kurzbz=org.oe_kurzbz)
LEFT JOIN
hr.tbl_vertragsbestandteil_freitext freitext on(vb.vertragsbestandteil_id=freitext.vertragsbestandteil_id)
";
return $this->execQuery($qry,
array($dienstverhaeltnis_id, $datestring, $datestring),
array($dienstverhaeltnis_id, $datestring, $dienstverhaeltnis_id, $datestring),
$this->getEncryptedColumns());
}
@@ -86,9 +129,38 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption
array($dienstverhaeltnis_id),
$this->getEncryptedColumns());
}
public function getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
public function getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null,
$includefuture=false, $withvalorisationhistory=true)
{
if( !is_null($stichtag) && (time() > strtotime($stichtag))
&& $withvalorisationhistory !== false )
{
$query = $this->getGehaltsbestandteileMitValorisierungsHistorie(
$dienstverhaeltnis_id, $stichtag, $includefuture
);
}
else
{
$query = $this->getGehaltsbestandteileOhneValorisierungsHistorie(
$dienstverhaeltnis_id, $stichtag, $includefuture
);
}
$gehaltsbestandteile = array();
if( null !== ($rows = getData($query)) )
{
foreach( $rows as $row ) {
$tmpgb = new Gehaltsbestandteil();
$tmpgb->hydrateByStdClass($row, true);
$gehaltsbestandteile[] = $tmpgb;
}
}
return $gehaltsbestandteile;
}
protected function getGehaltsbestandteileOhneValorisierungsHistorie($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
{
$stichtagclause = '';
if( !is_null($stichtag) )
@@ -111,24 +183,65 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption
{$stichtagclause}
EOSQL;
$query = $this->loadWhere(
$result = $this->loadWhere(
$where,
$this->getEncryptedColumns()
);
$gehaltsbestandteile = array();
if( null !== ($rows = getData($query)) )
{
foreach( $rows as $row ) {
$tmpgb = new Gehaltsbestandteil();
$tmpgb->hydrateByStdClass($row, true);
$gehaltsbestandteile[] = $tmpgb;
}
}
return $gehaltsbestandteile;
return $result;
}
protected function getGehaltsbestandteileMitValorisierungsHistorie($dienstverhaeltnis_id, $stichtag, $includefuture=false)
{
$date = strftime('%Y-%m-%d', strtotime($stichtag));
$includefuture_clause = ($includefuture)
? ' OR COALESCE(von, \'1970-01-01\'::date) > ' . $this->escape($date)
: '';
$sql = <<<EOSQL
SELECT
g.gehaltsbestandteil_id,
g.dienstverhaeltnis_id,
g.vertragsbestandteil_id,
g.gehaltstyp_kurzbz,
g.von,
g.bis,
g.anmerkung,
g.grundbetrag AS grundbetrag,
COALESCE(vh.betrag_valorisiert, g.grundbetrag) AS betrag_valorisiert,
g.valorisierungssperre,
g.insertamum,
g.insertvon,
g.updateamum,
g.updatevon,
g.valorisierung,
g.auszahlungen
FROM
hr.tbl_gehaltsbestandteil g
LEFT JOIN
hr.tbl_valorisierung_historie vh ON vh.gehaltsbestandteil_id = g.gehaltsbestandteil_id AND vh.valorisierungsdatum = (
SELECT
vi.valorisierungsdatum
FROM
hr.tbl_valorisierung_instanz vi
JOIN
hr.tbl_dienstverhaeltnis d ON d.dienstverhaeltnis_id = {$this->escape($dienstverhaeltnis_id)}
AND d.oe_kurzbz = vi.oe_kurzbz
WHERE
{$this->escape($date)} >= valorisierungsdatum
ORDER BY
valorisierungsdatum DESC
LIMIT 1
)
WHERE
g.dienstverhaeltnis_id = {$this->escape($dienstverhaeltnis_id)}
AND (
{$this->escape($date)} BETWEEN COALESCE(von, '1970-01-01'::date) AND COALESCE(bis, '2170-01-01'::date)
{$includefuture_clause}
)
EOSQL;
$result = $this->execReadOnlyQuery($sql, array(), $this->getEncryptedColumns());
return $result;
}
public function getGehaltsbestandteil($id)
{