add valorized data for chart display

This commit is contained in:
Werner Masik
2025-01-21 12:58:09 +01:00
parent 0770ec2bd8
commit 1853e44cf3
2 changed files with 95 additions and 0 deletions
@@ -28,6 +28,11 @@ class GehaltsbestandteilLib
$this->GehaltsbestandteilModel = $this->CI->GehaltsbestandteilModel;
}
public function fetchGehaltsbestandteileValorisiert($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
{
return $this->GehaltsbestandteilModel->getGehaltsbestandteileValorisiert($dienstverhaeltnis_id, $stichtag, $includefuture);
}
public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
{
return $this->GehaltsbestandteilModel->getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag, $includefuture);
@@ -129,6 +129,96 @@ EOSQL;
return $gehaltsbestandteile;
}
public function getGehaltsbestandteileValorisiert($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)
{
$stichtagclause = '';
if( !is_null($stichtag) )
{
$date = strftime('%Y-%m-%d', strtotime($stichtag));
$stichtagclause = 'AND (' . $this->escape($date)
. ' BETWEEN COALESCE(von, \'1970-01-01\'::date)'
. ' AND COALESCE(bis, \'2170-01-01\'::date)';
if( $includefuture )
{
$stichtagclause .= ' OR COALESCE(von, \'1970-01-01\'::date) > '
. $this->escape($date);
}
$stichtagclause .= ')';
}
// Note: replaced gb.betrag_valorisiert with vh.betrag_valorisiert!
$qry = "
SELECT
gb.gehaltsbestandteil_id,gb.dienstverhaeltnis_id,gb.vertragsbestandteil_id,gb.gehaltstyp_kurzbz,
gb.von,gb.bis,gb.anmerkung,gb.grundbetrag as grundbetrag,gb.valorisierungssperre,gb.insertamum,
gb.insertvon,gb.updateamum,gb.updatevon,gb.valorisierung,gb.auszahlungen,
vh.valorisierungsdatum, vh.betrag_valorisiert as betrag_valorisiert
FROM hr.tbl_gehaltsbestandteil gb LEFT JOIN hr.tbl_valorisierung_historie vh using (gehaltsbestandteil_id)
WHERE dienstverhaeltnis_id=?
$stichtagclause
ORDER BY gb.von,vh.valorisierungsdatum, gb.gehaltsbestandteil_id;
";
$encryptedColumns = array(
'gb.grundbetrag' => array(
DB_Model::CRYPT_CAST => 'numeric',
DB_Model::CRYPT_PASSWORD_NAME => 'ENCRYPTIONKEYGEHALT'
),
'vh.betrag_valorisiert' => array(
DB_Model::CRYPT_CAST => 'numeric',
DB_Model::CRYPT_PASSWORD_NAME => 'ENCRYPTIONKEYGEHALT'
)
);
$query = $this->execQuery($qry,
array($dienstverhaeltnis_id),
$encryptedColumns);
$gehaltsbestandteile = array();
if( null !== ($rows = getData($query)) )
{
// store for preserving the last records of every gehaltsbestandteil_id
$lastRecords = array();
foreach( $rows as $row ) {
$tmpgb = new Gehaltsbestandteil();
$tmpgb->hydrateByStdClass($row, true);
// prevent duplication (caused by the join with historic values)
if (!isset($lastRecords[(string)$row->gehaltsbestandteil_id])) {
$gehaltsbestandteile[] = $tmpgb;
$lastRecords[(string)$row->gehaltsbestandteil_id] = $tmpgb;
}
if ($row->betrag_valorisiert != null && $row->valorisierungsdatum != null
&& $row->valorisierungsdatum != $row->von && $row->valorisierungsdatum != $row->bis) {
// create additional row
$tmpgbv = new Gehaltsbestandteil();
$tmpgbv->hydrateByStdClass($row, true);
$tmpgbv->setVon($row->valorisierungsdatum);
$tmpgbv->setBis($lastRecords[(string)$row->gehaltsbestandteil_id]->getBis());
// overwrite Grundbetrag with the current valorized loan
// (otherwise the chart would show the wrong value)
$tmpgbv->setGrundbetrag($row->betrag_valorisiert);
$gehaltsbestandteile[] = $tmpgbv;
// finish previous
$daybefore = new DateTimeImmutable($row->valorisierungsdatum);
$daybefore = $daybefore->sub(new \DateInterval('P1D'));
$lastRecords[(string)$row->gehaltsbestandteil_id]->setBis($daybefore->format('Y-m-d'));
// preserve as last row, because there might be another valorization
$lastRecords[(string)$row->gehaltsbestandteil_id] = $tmpgbv;
}
}
}
return $gehaltsbestandteile;
}
public function getGehaltsbestandteil($id)
{