refactor creation of benutzerfunktiondata, add check for already used benutzerfunktionen in another vb

This commit is contained in:
Harald Bamberger
2023-11-20 09:19:32 +01:00
parent 72210867a5
commit 11926ca9b2
3 changed files with 62 additions and 11 deletions
@@ -15,4 +15,21 @@ class VertragsbestandteilFunktion_model extends DB_Model
$this->dbTable = 'hr.tbl_vertragsbestandteil_funktion';
$this->pk = 'vertragsbestandteil_id';
}
public function isBenutzerfunktionAlreadyAttachedToAnotherVB($benutzerfunktion_id, $vertragsbestandteil_id)
{
$where = array('benutzerfunktion_id' => $benutzerfunktion_id);
if( intval($vertragsbestandteil_id) > 0 )
{
$where['vertragsbestandteil_id != '] = $vertragsbestandteil_id;
}
$this->addSelect('count(*) AS vbscount');
$res = $this->loadWhere($where);
if(isError($res))
{
throw new Exception('failed to check if benutzerfunktionid is already attached to another vertragsbestanteil');
}
$count = (getData($res))[0]->vbscount;
return $count > 0;
}
}
@@ -22,8 +22,9 @@ class Vertragsbestandteil_model extends DB_Model
$sql = <<<EOSQL
SELECT
v.*,
bf.funktion_kurzbz, funktion.beschreibung funktion_bezeichnung,
oe.oe_kurzbz, oe.bezeichnung oe_bezeichnung, sap.oe_kurzbz_sap,
bf.funktion_kurzbz, bf.uid AS mitarbeiter_uid,
funktion.beschreibung AS funktion_bezeichnung,
oe.oe_kurzbz, oe.bezeichnung AS oe_bezeichnung, sap.oe_kurzbz_sap,
oet.organisationseinheittyp_kurzbz AS oe_typ_kurzbz, oet.bezeichnung AS oe_typ_bezeichnung,
ft.freitexttyp_kurzbz, ft.titel, ft.anmerkung,
f.benutzerfunktion_id,