diff --git a/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php b/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php index 94b0c75eb..f81a2d518 100644 --- a/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php +++ b/application/models/vertragsbestandteil/Dienstverhaeltnis_model.php @@ -59,7 +59,14 @@ class Dienstverhaeltnis_model extends DB_Model } $qry .=" - ORDER BY COALESCE(dv.bis, '2999-12-31'::date) DESC, dv.von DESC + ORDER BY + CASE + WHEN (COALESCE(dv.bis, '2999-12-31'::date) - NOW()::date) < 0 THEN NULL + ELSE + (COALESCE(dv.bis, '2999-12-31'::date) - NOW()::date) + END ASC NULLS LAST, + COALESCE(dv.bis, '2999-12-31'::date) DESC, + dv.von DESC "; return $this->execQuery($qry, $data);