mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Quota row management - copy quota rows with recalculating quota
This commit is contained in:
@@ -159,7 +159,7 @@ if ($questionnaire_id)
|
||||
else
|
||||
{
|
||||
$completions = limesurvey_quota_completions($v['lime_sgqa'],$v['lime_sid'],$questionnaire_id,$sample_import_id,$v['value'],$v['comparison']);
|
||||
$perc = ROUND(($completions / ($v['completions'])) * 100,2);
|
||||
$perc = ($v['completions'] <= 0 ? 0 : ROUND(($completions / ($v['completions'])) * 100,2));
|
||||
}
|
||||
|
||||
//We need to calc Sample size, Sample drawn, Sample remain
|
||||
|
||||
@@ -141,6 +141,11 @@ if ($questionnaire_id != false)
|
||||
copy_row_quota($questionnaire_id,$sample_import_id,bigintval($_POST['copy_sample_import_id']));
|
||||
print "<h3>" . T_("Copied quotas") . "</h3>";
|
||||
}
|
||||
if (isset($_POST['copy_sample_import_id_with_adjustment']))
|
||||
{
|
||||
copy_row_quota_with_adjusting($questionnaire_id,$sample_import_id,bigintval($_POST['copy_sample_import_id_with_adjustment']));
|
||||
print "<h3>" . T_("Copied quotas") . "</h3>";
|
||||
}
|
||||
|
||||
print "<h1>" . T_("Current row quotas (click to delete)") . "</h1>";
|
||||
|
||||
@@ -191,6 +196,10 @@ if ($questionnaire_id != false)
|
||||
print "<form action='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id' method='post'><p>" . T_("Copy quotas for this sample to (No error/duplicate checking): ");
|
||||
display_chooser($ss,"copy_sample_import_id","copy_sample_import_id",false,false,false,false);
|
||||
print "<input type='submit' id='submit' value='" . T_("Copy") . "'/></p></form>";
|
||||
|
||||
print "<form action='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id' method='post'><p>" . T_("Copy quotas for this sample to (No error/duplicate checking) with adjusting: ");
|
||||
display_chooser($ss,"copy_sample_import_id_with_adjustment","copy_sample_import_id_with_adjustment",false,false,false,false);
|
||||
print "<input type='submit' id='submit' value='" . T_("Copy adjustments") . "'/></p></form>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1142,12 +1142,100 @@ function copy_row_quota($questionnaire_id,$sample_import_id,$copy_sample_import_
|
||||
AND sample_import_id = '$sample_import_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
update_quotas($questionnaire_id);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy row quotas from one sample to another with blocking
|
||||
* Set quota_reached to 0 by default
|
||||
*
|
||||
* @param int $questionnaire_id
|
||||
* @param int $sample_import_id
|
||||
* @param int $copy_sample_import_id The sample_import_id to copy to
|
||||
*/
|
||||
function copy_row_quota_with_blocking($questionnaire_id,$sample_import_id,$copy_sample_import_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
//Set quota_reached to 0 always
|
||||
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description)
|
||||
SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description
|
||||
FROM questionnaire_sample_quota_row
|
||||
WHERE questionnaire_id = '$questionnaire_id'
|
||||
AND sample_import_id = '$sample_import_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
update_quotas($questionnaire_id);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy row quotas from one sample to another and adjust completion number appropriately to completed in the sample.
|
||||
*
|
||||
* @param int $questionnaire_id
|
||||
* @param int $sample_import_id
|
||||
* @param int $copy_sample_import_id The sample_import_id to copy to
|
||||
*/
|
||||
function copy_row_quota_with_adjusting($questionnaire_id,$sample_import_id,$copy_sample_import_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// Copy quotas (defalt Quexs function)
|
||||
copy_row_quota_with_blocking($questionnaire_id,$sample_import_id,$copy_sample_import_id);
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
// Select quotas from the old sample rows and calculate
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var,qsq.exclude_val
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND q.questionnaire_id = '$questionnaire_id'
|
||||
#AND qsq.quota_reached != '1'
|
||||
AND qsq.lime_sgqa != -1
|
||||
AND sample_import_id='".$sample_import_id."'
|
||||
";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
if (isset($rs) && !empty($rs))
|
||||
{
|
||||
//include limesurvey functions
|
||||
include_once(dirname(__FILE__).'/functions.limesurvey.php');
|
||||
|
||||
//update all row quotas for this questionnaire
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
|
||||
if ($completions > 0)
|
||||
{
|
||||
//Update adjusting the completion number
|
||||
$sql = "UPDATE questionnaire_sample_quota_row
|
||||
SET completions = IF(completions>".$completions.",(completions-".$completions."),0), quota_reached = IF(quota_reached = 0,IF(completions=0,1,0),1)
|
||||
WHERE questionnaire_id = '".$questionnaire_id."'
|
||||
AND sample_import_id='".$copy_sample_import_id."'
|
||||
AND lime_sgqa='".$r['lime_sgqa']."'
|
||||
AND value='".$r['value']."'
|
||||
AND comparison='".$r['comparison']."'";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the row quota table
|
||||
*
|
||||
@@ -1253,7 +1341,7 @@ function end_case($operator_id)
|
||||
WHERE c.case_id = '$case_id'
|
||||
AND c.outcome_id = o.outcome_id
|
||||
AND o.tryanother = 0
|
||||
AND (o.outcome_type_id = 4)
|
||||
AND o.outcome_type_id = 4
|
||||
ORDER BY c.call_id DESC
|
||||
LIMIT 1";
|
||||
|
||||
@@ -1309,20 +1397,17 @@ function end_case($operator_id)
|
||||
ORDER BY o.contacted DESC,c.call_id DESC
|
||||
LIMIT 1";
|
||||
|
||||
$t = $db->GetRow($sql);
|
||||
$t = $db->GetRow($sql);
|
||||
|
||||
if (!empty($t))
|
||||
{
|
||||
$outcome = $t['outcome_id'];
|
||||
}
|
||||
if (!empty($t))
|
||||
$outcome = $t['outcome_id'];
|
||||
}
|
||||
else if ($count >= 1) //one or more numbers to be tried again - first code as eligible if ever eligible...
|
||||
{
|
||||
//$r[0]['contact_phone_id'];
|
||||
//code as eligible if ever eligible, or if referred to the supervisor, code as that if last call
|
||||
$sql = "SELECT c.outcome_id as outcome_id
|
||||
FROM `call` as c
|
||||
JOIN outcome AS o ON ( c.outcome_id = o.outcome_id AND (o.eligible = 1 OR o.outcome_type_id = 2) )
|
||||
JOIN outcome AS o ON ( c.outcome_id = o.outcome_id AND o.eligible = 1)
|
||||
WHERE c.case_id = '$case_id'
|
||||
ORDER BY c.call_id DESC";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user