diff --git a/application/controllers/jobs/vertragsbestandteil_test/VertragsbestandteilTest.php b/application/controllers/jobs/vertragsbestandteil_test/VertragsbestandteilTest.php index 407a5ba24..d22ddb85f 100644 --- a/application/controllers/jobs/vertragsbestandteil_test/VertragsbestandteilTest.php +++ b/application/controllers/jobs/vertragsbestandteil_test/VertragsbestandteilTest.php @@ -17,6 +17,8 @@ class VertragsbestandteilTest extends JOB_Controller $this->load->library('vertragsbestandteil/VertragsbestandteilLib', null, 'VertragsbestandteilLib'); + $this->load->library('vertragsbestandteil/GehaltsbestandteilLib', + null, 'GehaltsbestandteilLib'); } public function testFetch() @@ -84,4 +86,29 @@ class VertragsbestandteilTest extends JOB_Controller echo "Insert failed.\n"; } } + + public function testGehaltsbestandteilInsert() + { + $data = new stdClass(); + $data->gehaltsbestandteil_id = 2; + /* + $data->dienstverhaeltnis_id = 39; + $data->vertragsbestandteil_id = 123; + $data->gehaltstyp_kurzbz = 'zulage'; + $data->von = '2023-04-01'; + $data->bis = '2023-08-31'; + $data->anmerkung = 'test anmerkung'; + $data->grundbetrag = 100; + $data->betrag_valorisiert = 100; + $data->valorisierung = true; + */ + $data->auszahlungen = 12; + + $gb = new \vertragsbestandteil\Gehaltsbestandteil(); + $gb->hydrateByStdClass($data); + + print_r($gb->toStdClass()); + + $this->GehaltsbestandteilLib->storeGehaltsbestandteil($gb); + } } diff --git a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php index e911c4228..0fc786124 100644 --- a/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Gehaltsbestandteil.php @@ -1,185 +1,245 @@ gehaltsbestandteil_id) && $this->setGehaltsbestandteil_id($data->gehaltsbestandteil_id); + isset($data->dienstverhaeltnis_id) && $this->setDienstverhaeltnis_id($data->dienstverhaeltnis_id); + isset($data->vertragsbestandteil_id) && $this->setVertragsbestandteil_id($data->vertragsbestandteil_id); + isset($data->gehaltstyp_kurzbz) && $this->setGehaltstyp_kurzbz($data->gehaltstyp_kurzbz); + isset($data->von) && $this->setVon($data->von); + isset($data->bis) && $this->setBis($data->bis); + isset($data->anmerkung) && $this->setAnmerkung($data->anmerkung); + isset($data->grundbetrag) && $this->setGrundbetrag($data->grundbetrag); + isset($data->betrag_valorisiert) && $this->setBetrag_valorisiert($data->betrag_valorisiert); + isset($data->valorisierungssperre) && $this->setValorisierungssperre($data->valorisierungssperre); + isset($data->valorisierung) && $this->setValorisierung($data->valorisierung); + isset($data->auszahlungen) && $this->setAuszahlungen($data->auszahlungen); + + isset($data->insertamum) && $this->setInsertamum($data->insertamum); + isset($data->insertvon) && $this->setInsertvon($data->insertvon); + isset($data->updateamum) && $this->setUpdateamum($data->updateamum); + isset($data->updatevon) && $this->setUpdatevon($data->updatevon); + } + + public function getGehaltsbestandteil_id() { return $this->gehaltsbestandteil_id; } - /** - * Set the value of gehaltsbestandteil_id - */ - public function setGehaltsbestandteilId($gehaltsbestandteil_id): self + public function getDienstverhaeltnis_id() { - $this->gehaltsbestandteil_id = $gehaltsbestandteil_id; - - return $this; + return $this->dienstverhaeltnis_id; + } + + public function getVertragsbestandteil_id() + { + return $this->vertragsbestandteil_id; + } + + public function getGehaltstyp_kurzbz() + { + return $this->gehaltstyp_kurzbz; + } + + public function getVon() + { + return $this->von; + } + + public function getBis() + { + return $this->bis; } - /** - * Get the value of anmerkung - */ public function getAnmerkung() { return $this->anmerkung; } - /** - * Set the value of anmerkung - */ - public function setAnmerkung($anmerkung): self - { - $this->anmerkung = $anmerkung; - - return $this; - } - - /** - * Get the value of grundbetrag - */ public function getGrundbetrag() { return $this->grundbetrag; } - /** - * Set the value of grundbetrag - */ - public function setGrundbetrag($grundbetrag): self - { - $this->grundbetrag = $grundbetrag; - - return $this; - } - - /** - * Get the value of betrag_valorisiert - */ - public function getBetragValorisiert() + public function getBetrag_valorisiert() { return $this->betrag_valorisiert; } - /** - * Set the value of betrag_valorisiert - */ - public function setBetragValorisiert($betrag_valorisiert): self - { - $this->betrag_valorisiert = $betrag_valorisiert; - - return $this; - } - - /** - * Get the value of valorisieren - */ - public function getValorisieren() - { - return $this->valorisieren; - } - - /** - * Set the value of valorisieren - */ - public function setValorisieren($valorisieren): self - { - $this->valorisieren = $valorisieren; - - return $this; - } - - /** - * Get the value of dienstverhaeltnis_id - */ - public function getGehaltDienstverhaeltnisID() - { - return $this->gehalt_dienstverhaeltnis_id; - } - - /** - * Set the value of dienstverhaeltnis_id - */ - public function setGehaltDienstverhaeltnisID($dienstverhaeltnis_id): self - { - $this->gehalt_dienstverhaeltnis_id = $dienstverhaeltnis_id; - - return $this; - } - - /** - * Get the value of gehaltstyp_kurzbz - */ - public function getGehaltstypKurzbz() - { - return $this->gehaltstyp_kurzbz; - } - - /** - * Set the value of gehaltstyp_kurzbz - */ - public function setGehaltstypKurzbz($gehaltstyp_kurzbz): self - { - $this->gehaltstyp_kurzbz = $gehaltstyp_kurzbz; - - return $this; - } - - /** - * Get the value of valorisierungssperre - */ public function getValorisierungssperre() { return $this->valorisierungssperre; } - /** - * Set the value of valorisierungssperre - */ - public function setValorisierungssperre($valorisierungssperre): self + public function getValorisierung() { - $this->valorisierungssperre = $valorisierungssperre; + return $this->valorisierung; + } + public function getAuszahlungen() + { + return $this->auszahlungen; + } + + public function getInsertamum() + { + return $this->insertamum; + } + + public function getInsertvon() + { + return $this->insertvon; + } + + public function getUpdateamum() + { + return $this->updateamum; + } + + public function getUpdatevon() + { + return $this->updatevon; + } + + public function setGehaltsbestandteil_id($gehaltsbestandteil_id) + { + $this->gehaltsbestandteil_id = $gehaltsbestandteil_id; return $this; } + public function setDienstverhaeltnis_id($dienstverhaeltnis_id) + { + $this->dienstverhaeltnis_id = $dienstverhaeltnis_id; + return $this; + } + + public function setVertragsbestandteil_id($vertragsbestandteil_id) + { + $this->vertragsbestandteil_id = $vertragsbestandteil_id; + return $this; + } + + public function setGehaltstyp_kurzbz($gehaltstyp_kurzbz) + { + $this->gehaltstyp_kurzbz = $gehaltstyp_kurzbz; + return $this; + } + + public function setVon($von) + { + $this->von = $von; + return $this; + } + + public function setBis($bis) + { + $this->bis = $bis; + return $this; + } + + public function setAnmerkung($anmerkung) + { + $this->anmerkung = $anmerkung; + return $this; + } + + public function setGrundbetrag($grundbetrag) + { + $this->grundbetrag = $grundbetrag; + return $this; + } + + public function setBetrag_valorisiert($betrag_valorisiert) + { + $this->betrag_valorisiert = $betrag_valorisiert; + return $this; + } + + public function setValorisierungssperre($valorisierungssperre) + { + $this->valorisierungssperre = $valorisierungssperre; + return $this; + } + + public function setValorisierung($valorisierung) + { + $this->valorisierung = $valorisierung; + return $this; + } + + public function setAuszahlungen($auszahlungen) + { + $this->auszahlungen = $auszahlungen; + return $this; + } + + public function setInsertamum($insertamum) + { + $this->insertamum = $insertamum; + return $this; + } + + public function setInsertvon($insertvon) + { + $this->insertvon = $insertvon; + return $this; + } + + public function setUpdateamum($updateamum) + { + $this->updateamum = $updateamum; + return $this; + } + + public function setUpdatevon($updatevon) + { + $this->updatevon = $updatevon; + return $this; + } + public function toStdClass(): \stdClass { - $tmp = array( - 'gueltig_ab' => $this->getGueltigAb(), - 'gueltig_bis' => $this->getGueltigBis(), - 'gehalt_dienstverhaeltnis_id' => $this->getGehaltDienstverhaeltnisID(), + $tmp = array( + 'gehaltsbestandteil_id' => $this->getGehaltsbestandteil_id(), + 'dienstverhaeltnis_id' => $this->getDienstverhaeltnis_id(), + 'vertragsbestandteil_id' => $this->getVertragsbestandteil_id(), + 'gehaltstyp_kurzbz' => $this->getGehaltstyp_kurzbz(), + 'von' => $this->getVon(), + 'bis' => $this->getBis(), + 'anmerkung' => $this->getAnmerkung(), 'grundbetrag' => $this->getGrundbetrag(), - 'betrag_valorisiert' => $this->getBetragValorisiert(), - 'valorisieren' => $this->getValorisieren(), - 'gehaltstyp_kurzbz' => $this->getGehaltstypKurzbz(), + 'betrag_valorisiert' => $this->getBetrag_valorisiert(), 'valorisierungssperre' => $this->getValorisierungssperre(), - 'anmerkung' => $this->getAnmerkung() + 'valorisierung' => $this->getValorisierung(), + 'auszahlungen' => $this->getAuszahlungen(), + 'insertamum' => $this->getInsertamum(), + 'insertvon' => $this->getInsertvon(), + 'updateamum' => $this->getUpdateamum(), + 'updatevon' => $this->getUpdatevon() ); $tmp = array_filter($tmp, function($v) { @@ -192,50 +252,24 @@ class Gehaltsbestandteil public function __toString() { $txt = <<getGehaltsbestandteil_id()} + dienstverhaeltnis_id: {$this->getDienstverhaeltnis_id()} + vertragsbestandteil_id: {$this->getVertragsbestandteil_id()} + gehaltstyp_kurzbz: {$this->getGehaltstyp_kurzbz()} von: {$this->getVon()} bis: {$this->getBis()} + anmerkung: {$this->getAnmerkung()} grundbetrag: {$this->getGrundbetrag()} - valorisieren: {$this->getValorisieren()} + betrag_valorisiert: {$this->getBetrag_valorisiert()} + valorisierungssperre: {$this->getValorisierungssperre()} + valorisierung: {$this->getValorisierung()} + auszahlungen: {$this->getAuszahlungen()} + insertamum: {$this->getInsertamum()} + insertvon: {$this->getInsertvon()} + updateamum: {$this->getUpdateamum()} + updatevon: {$this->getUpdatevon()} EOTXT; - return parent::__toString() . $txt; + return $txt; } - - - - /** - * Get the value of gueltig_ab - */ - public function getGueltigAb() - { - return $this->gueltig_ab; - } - - /** - * Set the value of gueltig_ab - */ - public function setGueltigAb($gueltig_ab): self - { - $this->gueltig_ab = $gueltig_ab; - - return $this; - } - - /** - * Get the value of gueltig_bis - */ - public function getGueltigBis() - { - return $this->gueltig_bis; - } - - /** - * Set the value of gueltig_bis - */ - public function setGueltigBis($gueltig_bis): self - { - $this->gueltig_bis = $gueltig_bis; - - return $this; - } } diff --git a/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php new file mode 100644 index 000000000..ad5418738 --- /dev/null +++ b/application/libraries/vertragsbestandteil/GehaltsbestandteilLib.php @@ -0,0 +1,89 @@ +CI = get_instance(); + $this->CI->load->model('vertragsbestandteil/Gehaltsbestandteil_model', + 'GehaltsbestandteilModel'); + $this->GehaltsbestandteilModel = $this->CI->GehaltsbestandteilModel; + } + + public function fetchGehaltsbestandteile($dienstverhaeltnis_id, $stichtag=null) + { + return $this->GehaltsbestandteilModel->getGehaltsbestandteile($dienstverhaeltnis_id, $stichtag); + } + + public function fetchGehaltsbestandteil($gehaltsbestandteil_id) + { + return $this->GehaltsbestandteilModel->getGehaltsbestandteil($gehaltsbestandteil_id); + } + + public function storeGehaltsbestandteile($gehaltsbestandteile) + { + foreach( $gehaltsbestandteile as $gehaltsbestandteil ) + { + $this->storeGehaltsbestandteil($gehaltsbestandteil); + } + } + + public function storeGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + try + { + if( intval($gehaltsbestandteil->getGehaltsbestandteil_id()) > 0 ) + { + $this->updateGehaltsbestandteil($gehaltsbestandteil); + } + else + { + $this->insertGehaltsbestandteil($gehaltsbestandteil); + } + } + catch (Exception $ex) + { + log_message('debug', "Storing Gehaltsbestandteil failed. " . $ex->getMessage()); + throw new Exception('Storing Gehaltsbestandteil failed.'); + } + } + + protected function insertGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + $ret = $this->GehaltsbestandteilModel->insert($gehaltsbestandteil->toStdClass(), + $this->GehaltsbestandteilModel->getEncryptedColumns()); + if( hasData($ret) ) + { + $gehaltsbestandteil->setGehaltsbestandteil_id(getData($ret)); + } + else + { + throw new Exception('error inserting gehaltsbestandteil'); + } + } + + protected function updateGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + $gehaltsbestandteil->setUpdateamum(strftime('%Y-%m-%d %H:%M:%S')); + $ret = $this->GehaltsbestandteilModel->update($gehaltsbestandteil->getGehaltsbestandteil_id(), + $gehaltsbestandteil->toStdClass(), + $this->GehaltsbestandteilModel->getEncryptedColumns()); + + if(isError($ret) ) + { + throw new Exception('error updating gehaltsbestandteil'); + } + } +} diff --git a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php index 1d1101e44..a8e600d7f 100644 --- a/application/libraries/vertragsbestandteil/Vertragsbestandteil.php +++ b/application/libraries/vertragsbestandteil/Vertragsbestandteil.php @@ -18,6 +18,13 @@ abstract class Vertragsbestandteil implements \JsonSerializable protected $updateamum; protected $updatevon; + protected $gehaltsbestandteile; + + public function __construct() + { + $this->gehaltsbestandteile = array(); + } + public function hydrateByStdClass($data) { isset($data->vertragsbestandteil_id) && $this->setVertragsbestandteil_id($data->vertragsbestandteil_id); @@ -30,6 +37,17 @@ abstract class Vertragsbestandteil implements \JsonSerializable isset($data->updatevon) && $this->setUpdatevon($data->updatevon); } + public function addGehaltsbestandteil(Gehaltsbestandteil $gehaltsbestandteil) + { + $this->gehaltsbestandteile[] = $gehaltsbestandteil; + return $this; + } + + public function getGehaltsbestandteile() + { + return $this->gehaltsbestandteile; + } + public function getVertragsbestandteil_id() { return $this->vertragsbestandteil_id; diff --git a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php index 38b152523..fd65c3972 100644 --- a/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php +++ b/application/libraries/vertragsbestandteil/VertragsbestandteilLib.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/VertragsbestandteilZeitaufzeichnung.php'; require_once __DIR__ . '/VertragsbestandteilKuendigungsfrist.php'; require_once __DIR__ . '/VertragsbestandteilFreitext.php'; require_once __DIR__ . '/VertragsbestandteilFactory.php'; +require_once __DIR__ . '/GehaltsbestandteilLib.php'; use vertragsbestandteil\Vertragsbestandteil; use vertragsbestandteil\VertragsbestandteilFactory; @@ -136,8 +137,7 @@ class VertragsbestandteilLib protected function updateVertragsbestandteil(Vertragsbestandteil $vertragsbestandteil) { - $vertragsbestandteil->setUpdateamum(strftime('%Y-%m-%d %H:%M')) - ->setUpdatevon('ma0080'); + $vertragsbestandteil->setUpdateamum(strftime('%Y-%m-%d %H:%M:%S')); $vertragsbestandteil->beforePersist(); $ret = $this->VertragsbestandteilModel->update($vertragsbestandteil->getVertragsbestandteil_id(), $vertragsbestandteil->baseToStdClass()); diff --git a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php index fce950012..ad48e68e0 100644 --- a/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php +++ b/application/models/vertragsbestandteil/Gehaltsbestandteil_model.php @@ -14,7 +14,16 @@ class Gehaltsbestandteil_model extends DB_Model implements IEncryption public function getEncryptedColumns(): array { - return ['grundbetrag' => 'ENCRYPTIONKEY', 'betrag_valorisiert' => 'ENCRYPTIONKEY']; + return array( + 'grundbetrag' => array( + DB_Model::CRYPT_CAST => 'numeric', + DB_Model::CRYPT_PASSWORD_NAME => 'ENCRYPTIONKEY' + ), + 'betrag_valorisiert' => array( + DB_Model::CRYPT_CAST => 'numeric', + DB_Model::CRYPT_PASSWORD_NAME => 'ENCRYPTIONKEY' + ) + ); } public function getCurrentGBTByDV($dienstverhaeltnis_id)