diff --git a/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php index e72de9cd9..2e6f78b80 100644 --- a/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php @@ -93,4 +93,24 @@ class GehaltsbestandteilLib throw new Exception('error updating gehaltsbestandteil'); } } + + public function deleteGehaltsbestandteile($gehaltsbestandteile) + { + foreach( $gehaltsbestandteile as $gehaltsbestandteil ) + { + $this->deleteGehaltsbestandteil($gehaltsbestandteil); + } + } + + protected function deleteGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + $ret = $this->GehaltsbestandteilModel->delete($gehaltsbestandteil->getGehaltsbestandteil_id()); + + if (isError($ret)) + { + throw new Exception('error deleting gehaltsbestandteil'); + } + } + + } diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index d0ca06126..4ef97348f 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -148,6 +148,70 @@ class VertragsbestandteilLib throw new Exception('Storing Vertragsbestandteil failed.'); } } + + public function deleteDienstverhaeltnis(Dienstverhaeltnis $dv) + { + $this->CI->db->trans_begin(); + try + { + if( intval($dv->getDienstverhaeltnis_id()) > 0 ) + { + $vbs = $this->fetchVertragsbestandteile($dv->getDienstverhaeltnis_id()); + foreach ($vbs as $vb) + { + $this->deleteVertragsbestandteil($vb); + } + + $ret = $this->DienstverhaeltnisModel->delete($dv->getDienstverhaeltnis_id()); + if(isError($ret) ) + { + log_message('debug', "Delete DV failed"); + throw new Exception('error deleting dienstverhaeltnis ' + . $dv->getDienstverhaeltnis_id()); + } + + if( $this->CI->db->trans_status() === false ) + { + log_message('debug', "Transaction failed"); + throw new Exception("Transaction failed"); + } + $this->CI->db->trans_commit(); + } + } + catch (Exception $ex) + { + log_message('debug', "Transaction rolled back. " . $ex->getMessage()); + $this->CI->db->trans_rollback(); + return $ex->getMessage(); + } + + return true; + + } + + public function deleteVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) + { + $this->CI->db->trans_begin(); + try + { + if( intval($vertragsbestandteil->getVertragsbestandteil_id()) > 0 ) + { + $this->deleteVertragsbestandteilHelper($vertragsbestandteil); + } + if( $this->CI->db->trans_status() === false ) + { + log_message('debug', "Transaction failed"); + throw new Exception("Transaction failed"); + } + $this->CI->db->trans_commit(); + } + catch (Exception $ex) + { + log_message('debug', "Transaction rolled back. " . $ex->getMessage()); + $this->CI->db->trans_rollback(); + throw new Exception('Delete Vertragsbestandteil failed.'); + } + } protected function insertDienstverhaeltnis(Dienstverhaeltnis $dv) { @@ -213,12 +277,45 @@ class VertragsbestandteilLib } } + private function deleteVertragsbestandteilHelper(Vertragsbestandteil $vertragsbestandteil) + { + + $specialisedModel = VertragsbestandteilFactory::getVertragsbestandteilDBModel( + $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); + $retspecial = $specialisedModel->delete($vertragsbestandteil->getVertragsbestandteil_id()); + + if(isError($retspecial) ) + { + throw new Exception('error deleting vertragsbestandteil ' + . $vertragsbestandteil->getVertragsbestandteiltyp_kurzbz()); + } + + try + { + $gehaltsbestandteile = $vertragsbestandteil->getGehaltsbestandteile(); + $this->GehaltsbestandteilLib->deleteGehaltsbestandteile($gehaltsbestandteile); + } + catch(Exception $ex) + { + throw new Exception('VertragsbestandteilLib updateVertragsbestandteil ' + . 'failed to store Gehaltsbestandteile. ' . $ex->getMessage()); + } + + + $ret = $this->VertragsbestandteilModel->delete($vertragsbestandteil->getVertragsbestandteil_id()); + + if(isError($ret) ) + { + throw new Exception('error deleting vertragsbestandteil'); + } + } + protected function updateVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) { $vertragsbestandteil->setUpdatevon($this->loggedInUser) ->setUpdateamum(strftime('%Y-%m-%d %H:%M:%S')); $vertragsbestandteil->beforePersist(); - $ret = $this->VertragsbestandteilModel->update($vertragsbestandteil->getVertragsbestandteil_id(), + $ret = $this->VertragsbestandteilModel->update($vertragsbestandteil->getVertragsbestandteil_id(), $vertragsbestandteil->baseToStdClass()); if(isError($ret) ) diff --git a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php index e3da82766..b09531702 100644 --- a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php @@ -27,46 +27,89 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption ); } - public function getCurrentGBTByDV($dienstverhaeltnis_id) - {/* - $qry = " - SELECT - gehaltsbestandteil_id, - von, - bis, - anmerkung, - dienstverhaeltnis_id, - gehaltstyp_kurzbz, - valorisierungssperre, - gbt.valorisierung, - grundbetrag as grund_betrag_decrypted, - betrag_valorisiert as betrag_val_decrypted, - gt.bezeichnung as gehaltstyp_bezeichnung - FROM hr.tbl_gehaltsbestandteil gbt JOIN hr.tbl_gehaltstyp gt using(gehaltstyp_kurzbz) - WHERE gbt.dienstverhaeltnis_id=? AND - (gbt.von<=CURRENT_DATE::text::date and (gbt.bis is null OR gbt.bis>=CURRENT_DATE::text::date)) - ORDER BY gt.sort - "; */ + public function getCurrentGBTByDV($dienstverhaeltnis_id, $dateAsUnixTS) + { + $date = DateTime::createFromFormat( 'U', $dateAsUnixTS ); + $datestring = $date->format("Y-m-d"); $qry = " SELECT gehaltsbestandteil_id, - von, - bis, - anmerkung, - dienstverhaeltnis_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 - FROM hr.tbl_gehaltsbestandteil gbt JOIN hr.tbl_gehaltstyp gt using(gehaltstyp_kurzbz) + 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 + "; + + return $this->execQuery($qry, + array($dienstverhaeltnis_id, $datestring, $datestring), + $this->getEncryptedColumns()); + } + + public function getGBTChartDataByDV($dienstverhaeltnis_id) + { + + $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=? ORDER BY gt.sort "; - return $this->execQuery($qry, array($dienstverhaeltnis_id), $this->getEncryptedColumns()); + return $this->execQuery($qry, + array($dienstverhaeltnis_id, $datestring, $datestring), + $this->getEncryptedColumns()); } public function getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null, $includefuture=false)