diff --git a/admin/systemsortprocess.php b/admin/systemsortprocess.php index ac79a429..f043c104 100644 --- a/admin/systemsortprocess.php +++ b/admin/systemsortprocess.php @@ -257,7 +257,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max)) AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 GROUP BY c.case_id - ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, a.start ASC, qsep.priority DESC"; + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, a.start ASC"; $rs = $db->GetAll($sql); diff --git a/functions/functions.operator.php b/functions/functions.operator.php index 0d7226dd..d7a31d47 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -638,7 +638,7 @@ function get_case_id($operator_id, $create = false) AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max)) AND (apn.require_operator_id IS NULL OR apn.require_operator_id = '$operator_id') AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 - ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, a.start ASC, qsep.priority DESC + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, a.start ASC LIMIT 1"; //apn.appointment_id contains the id of an appointment if we are calling on an appointment