abfrage ob die tbl vorhanden ist hinzugefuegt

This commit is contained in:
ma0048
2021-10-28 12:30:10 +02:00
parent 7805784214
commit e6a11d0dc2
3 changed files with 136 additions and 57 deletions
+72 -30
View File
@@ -420,45 +420,86 @@ class projekt extends basis_db
function getProjekteListForMitarbeiter($mitarbeiter_uid, $projektphasen = false)
{
$projectList = array();
$exists = @$this->db_query('SELECT 1 FROM sync.tbl_projects_timesheets_project LIMIT 1;');
$qry = "SELECT DISTINCT
tbl_projekt.*, tbl_projects_timesheets_project.projects_timesheet_id
FROM
fue.tbl_ressource
JOIN fue.tbl_projekt_ressource USING(ressource_id)
JOIN fue.tbl_projekt USING(projekt_kurzbz)
LEFT JOIN sync.tbl_projects_timesheets_project USING(projekt_id)
WHERE (beginn<=now() or beginn is null)
tbl_projekt.*
";
if ($exists)
{
$qry .= ", tbl_sap_projects_timesheets.project_id
";
}
$qry .= "FROM
fue.tbl_ressource
JOIN fue.tbl_projekt_ressource USING(ressource_id)
JOIN fue.tbl_projekt USING(projekt_kurzbz)
";
if ($exists)
{
$qry .= "LEFT JOIN sync.tbl_projects_timesheets_project USING(projekt_id)
LEFT JOIN sync.tbl_sap_projects_timesheets USING(projects_timesheet_id)
";
}
$qry .= "WHERE (beginn<=now() or beginn is null)
AND (ende + interval '1 month 1 day' >=now() OR ende is null)
AND
(
mitarbeiter_uid=" . $this->db_add_param($mitarbeiter_uid) . " OR
student_uid=" . $this->db_add_param($mitarbeiter_uid) . "
)
AND tbl_projects_timesheets_project.projektphase_id IS NULL
";
if ($projektphasen == true)
$qry .= "UNION
if ($exists)
{
$qry .= "AND tbl_projects_timesheets_project.projektphase_id IS NULL
";
}
SELECT DISTINCT
tbl_projekt.*, tbl_projects_timesheets_project.projects_timesheet_id
FROM
fue.tbl_projektphase
JOIN fue.tbl_projekt USING (projekt_kurzbz)
LEFT JOIN sync.tbl_projects_timesheets_project USING(projektphase_id)
JOIN fue.tbl_projekt_ressource USING (projektphase_id)
JOIN fue.tbl_ressource ON (tbl_ressource.ressource_id=tbl_projekt_ressource.ressource_id)
WHERE
(
(
(tbl_projekt.beginn<=now() or tbl_projekt.beginn is null)
AND (tbl_projekt.ende + interval '1 month 1 day' >=now() OR tbl_projekt.ende is null)
) OR (
(tbl_projektphase.start<=now() or tbl_projektphase.start is null)
AND (tbl_projektphase.ende + interval '1 month 1 day' >=now() OR tbl_projektphase.ende is null)
)
)
AND mitarbeiter_uid=" . $this->db_add_param($mitarbeiter_uid);
if ($projektphasen == true)
{
$qry .= "UNION
SELECT DISTINCT
tbl_projekt.*
";
if ($exists)
{
$qry .= ", tbl_sap_projects_timesheets.project_task_id
";
}
$qry .= "FROM fue.tbl_projektphase
JOIN fue.tbl_projekt USING (projekt_kurzbz)
JOIN fue.tbl_projekt_ressource USING(projektphase_id)
JOIN fue.tbl_ressource ON (tbl_ressource.ressource_id=tbl_projekt_ressource.ressource_id)
";
if ($exists)
{
$qry .= "LEFT JOIN sync.tbl_projects_timesheets_project ON tbl_projects_timesheets_project.projektphase_id = tbl_projekt_ressource.projektphase_id
LEFT JOIN sync.tbl_sap_projects_timesheets USING(projects_timesheet_id)
";
}
$qry .= "WHERE
(
(
(tbl_projekt.beginn<=now() or tbl_projekt.beginn is null)
AND (tbl_projekt.ende + interval '1 month 1 day' >=now() OR tbl_projekt.ende is null)
) OR (
(tbl_projektphase.start<=now() or tbl_projektphase.start is null)
AND (tbl_projektphase.ende + interval '1 month 1 day' >=now() OR tbl_projektphase.ende is null)
)
)
";
};
$qry .= "AND mitarbeiter_uid=" . $this->db_add_param($mitarbeiter_uid);
if ($result = $this->db_query($qry)) {
while ($row = $this->db_fetch_object($result)) {
@@ -471,7 +512,8 @@ class projekt extends basis_db
$obj->beginn = $row->beginn;
$obj->ende = $row->ende;
$obj->oe_kurzbz = $row->oe_kurzbz;
$obj->sap_project_id = $row->projects_timesheet_id;
if ($exists)
$obj->sap_project_id = $row->project_id;
$this->result[] = $obj;