diff --git a/admin/systemsortprocess.php b/admin/systemsortprocess.php index 9a3da1fe..6a805899 100644 --- a/admin/systemsortprocess.php +++ b/admin/systemsortprocess.php @@ -267,7 +267,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 `call`.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, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC"; + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC, qs.sort_order ASC"; $rs = $db->GetAll($sql); @@ -308,7 +308,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL) AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 GROUP BY s.sample_id,qs.questionnaire_id - ORDER BY qsep.priority DESC, rand() * qs.random_select, s.sample_id"; + ORDER BY qsep.priority DESC, rand() * qs.random_select, qs.sort_order ASC"; $rs = $db->GetAll($sql); diff --git a/functions/functions.operator.php b/functions/functions.operator.php index e2e39c4c..40acf1de 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -708,7 +708,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, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC, qs.sort_order ASC LIMIT 1"; //apn.appointment_id contains the id of an appointment if we are calling on an appointment @@ -762,7 +762,7 @@ function get_case_id($operator_id, $create = false) AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL) AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL) AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 - ORDER BY qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC, rand() * qs.random_select, s.sample_id + ORDER BY qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC, rand() * qs.random_select, qs.sort_order ASC LIMIT 1"; }