diff --git a/application/controllers/jobs/SponsionJob.php b/application/controllers/jobs/SponsionJob.php index 93ac17cfb..5af16d60b 100644 --- a/application/controllers/jobs/SponsionJob.php +++ b/application/controllers/jobs/SponsionJob.php @@ -3,7 +3,7 @@ * FH-Complete * * - * Cronjobs to be run for inserting the date of Sponsion as Date ZGV for further applications. + * Cronjobs to be run for inserting the date of Sponsion as Date ZGV of absolvents */ // ------------------------------------------------------------------------ @@ -20,29 +20,40 @@ class SponsionJob extends JOB_Controller // Load models $this->load->model('education/Abschlusspruefung_model', 'AbschlusspruefungModel'); - - // Load libraries - $this->load->library('PermissionLib'); - - // Load helpers - $this->load->helper('hlp_sancho_helper'); + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); } public function insertDate() { + $allAbsolventsWithDateSponsion = $this->AbschlusspruefungModel->getAbsolventsWithSponsionDate()->retval; + $count = 0; + $countBewerbungen = 0; + print_r("-----------------------------------------------------------------\n"); + print_r("Cronjob START\n"); + print_r("Sponsionsdatum als ZGV-Datum eintragen:\n"); + + foreach ($allAbsolventsWithDateSponsion as $absolvent) + { + $this->AbschlusspruefungModel->insertDatumSponsionAsZgvmadatum($absolvent->prestudent_id, $absolvent->sponsion); + + //get all prestudents of person_id with Status Interessent + $allBewerbungen = $this->PrestudentModel->getPrestudentsOfPersonId($absolvent->person_id, 'Interessent')->retval; + foreach ($allBewerbungen as $bewerbung) + { + $this->AbschlusspruefungModel->insertDatumSponsionAsZgvmadatum($bewerbung->prestudent_id, $absolvent->sponsion); + print_r (" Bewerbung: personId: " . $absolvent->person_id . " prestudentId: " . $bewerbung->prestudent_id. " DateSponsion: " . $absolvent->sponsion."\n"); + $countBewerbungen++; + } + $count++; + } + + print_r("\nAnzahl Absolventen: " . $count); + print_r("\nAnzahl Inserts Bewerbungen: " . $countBewerbungen); + print_r("\nCronjob END\n"); + print_r("-----------------------------------------------------------------\n"); + + return true; } - //****************************************************************************************************************** -// PRIVATE FUNCTIONS -//****************************************************************************************************************** - -private function getAbsolventsWithSponsion() -{ - $mResult = $this->AbschlusspruefungModel->getAbsolventsWithSponsionDate(); - $absolventList = getData($mResult); - // $vorgesetzte = array(); - // $toSend = array(); -} - } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index b7804952e..14009c4fb 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -667,4 +667,25 @@ class Prestudent_model extends DB_Model return $this->execQuery($query, array($prestudent_id)); } + /** + * get all prestudents of a Person_id with certain status + * @param $personId + * @param $prestudentStatus + * @return array all prestudents of the person (with certain status) + */ + public function getPrestudentsOfPersonId($personId, $prestudentStatus) + { + return $this->execQuery( + 'SELECT prestudent_id + FROM public.tbl_prestudent + JOIN public.tbl_prestudentstatus USING (prestudent_id) + WHERE person_id = ? + AND get_rolle_prestudent(prestudent_id, null) = ?', + array( + $personId, + $prestudentStatus + ) + ); + } + } diff --git a/application/models/education/Abschlusspruefung_model.php b/application/models/education/Abschlusspruefung_model.php index 66e6b4554..3de2aac03 100644 --- a/application/models/education/Abschlusspruefung_model.php +++ b/application/models/education/Abschlusspruefung_model.php @@ -114,18 +114,40 @@ class Abschlusspruefung_model extends DB_Model return success($abschlusspruefungdata); } +/** +* get all Absolvents with a Date Sponsion without filled master zgv field +*/ public function getAbsolventsWithSponsionDate() { - $qry = "SELECT ps.prestudent_id + $qry = "SELECT ps.prestudent_id, ap.sponsion, p.person_id FROM lehre.tbl_abschlusspruefung ap JOIN public.tbl_student st USING (student_uid) JOIN public.tbl_prestudent ps USING (prestudent_id) JOIN public.tbl_prestudentstatus pstatus USING (prestudent_id) + JOIN public.tbl_person p USING (person_id) + JOIN public.tbl_studiengang sg ON (sg.studiengang_kz = ps.studiengang_kz) WHERE ap.sponsion < now() - AND ap.sponsion >= '2022-07-01' --just for testing AND ps.zgvmadatum is NULL AND pstatus.status_kurzbz in ('Absolvent') + AND sg.typ != 'l' ORDER BY ap.Sponsion DESC"; return $this->execQuery($qry); } + + /** + * update ZGV Master + */ +public function insertDatumSponsionAsZgvmadatum($prestudentId, $datumSponsion) +{ + return $this->execQuery( + 'UPDATE public.tbl_prestudent + SET zgvmadatum = ? + WHERE prestudent_id = ?', + array( + $datumSponsion, + $prestudentId + ) + ); +} + }