Skip to content
Snippets Groups Projects
Commit ffb08477 authored by Erik Hommel's avatar Erik Hommel
Browse files

fix #77 condition specific amount

parent e17185b6
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ class CRM_CivirulesConditions_Contribution_SpecificAmount extends CRM_Civirules_
}
break;
default:
if ($dao->countContributions == $this->conditionParams['no_of_contribution']) {
if ($dao->countContributions == $this->conditionParams['no_of_contributions']) {
$isConditionValid = TRUE;
}
break;
......@@ -99,10 +99,22 @@ class CRM_CivirulesConditions_Contribution_SpecificAmount extends CRM_Civirules_
$this->whereClauses[] = 'total_amount '.$this->setOperator($this->conditionParams['amount_operator']).' %'.$index;
$this->whereParams[$index] = array($this->conditionParams['amount'], 'Money');
}
if (!empty($this->conditionParams['financial_type'])) {
$index++;
$this->whereClauses[] = 'financial_type_id = %'.$index;
$this->whereParams[$index] = array($this->conditionParams['financial_type'], 'Integer');
if (!empty($this->conditionParams['financial_type_id'])) {
$finTypeClauses = array();
foreach ($this->conditionParams['financial_type_id'] as $finTypeId) {
$index++;
$finTypeClauses[] = 'financial_type_id = %'.$index;
$this->whereParams[$index] = array($finTypeId, 'Integer');
}
$this->whereClauses[] = '('.implode(' OR ', $finTypeClauses).')';
}
switch ($this->conditionParams['count_type']) {
case 0:
$this->whereClauses[] = 'contribution_recur_id IS NULL';
break;
case 1:
$this->whereClauses[] = 'contribution_recur_id IS NOT NULL';
break;
}
}
......
......@@ -20,6 +20,10 @@ class CRM_CivirulesConditions_Form_Contribution_SpecificAmount extends CRM_Civir
$operatorList[3] = 'is more than or equal (>=)';
$operatorList[4] = 'is less than (<)';
$operatorList[5] = 'is less than or equal (<=)';
$countTypeList[0] = "do not count contributions that are part of a recurring one";
$countTypeList[1] = "count only contributions that are part of a recurring one";
$countTypeList[2] = "count all contributions (one-time and recurring)";
$financialTypes = CRM_Civirules_Utils::getFinancialTypes();
$financialTypes[0] = ts(' - any -');
......@@ -27,8 +31,10 @@ class CRM_CivirulesConditions_Form_Contribution_SpecificAmount extends CRM_Civir
$this->add('hidden', 'rule_condition_id');
$this->add('select', 'count_operator', ts('Operator'), $operatorList, true);
$this->add('select', 'count_type', ts('Count What?'), $countTypeList, true);
$this->add('select', 'amount_operator', ts('where Operator'), $operatorList, true);
$this->add('select', 'financial_type', ts('of Financial Type'), $financialTypes, true);
$this->add('select', 'financial_type_id', ts('of Financial Type(s)'), $financialTypes, true,
array('id' => 'financial_type_ids', 'multiple' => 'multiple','class' => 'crm-select2'));
$this->add('text', 'no_of_contributions', ts('Number of Contributions'), array(), true);
$this->addRule('no_of_contributions','Number of contributions must be a whole number','numeric');
$this->addRule('no_of_contributions','Number of contributions must be a whole number','nopunctuation');
......@@ -55,8 +61,11 @@ class CRM_CivirulesConditions_Form_Contribution_SpecificAmount extends CRM_Civir
if (!empty($data['no_of_contributions'])) {
$defaultValues['no_of_contributions'] = $data['no_of_contributions'];
}
if (!empty($data['financial_type'])) {
$defaultValues['financial_type'] = $data['financial_type'];
if (!empty($data['count_type'])) {
$defaultValues['count_type'] = $data['count_type'];
}
if (!empty($data['financial_type_id'])) {
$defaultValues['financial_type_id'] = $data['financial_type_id'];
}
if (!empty($data['amount_operator'])) {
$defaultValues['amount_operator'] = $data['amount_operator'];
......@@ -76,7 +85,8 @@ class CRM_CivirulesConditions_Form_Contribution_SpecificAmount extends CRM_Civir
public function postProcess() {
$data['count_operator'] = $this->_submitValues['count_operator'];
$data['no_of_contributions'] = $this->_submitValues['no_of_contributions'];
$data['financial_type'] = $this->_submitValues['financial_type'];
$data['count_type'] = $this->_submitValues['count_type'];
$data['financial_type_id'] = $this->_submitValues['financial_type_id'];
$data['amount_operator'] = $this->_submitValues['amount_operator'];
$data['amount'] = $this->_submitValues['amount'];
$this->ruleCondition->condition_params = serialize($data);
......
......@@ -14,8 +14,13 @@
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.financial_type.label}</div>
<div class="content">{$form.financial_type.html}</div>
<div class="label">{$form.count_type.label}</div>
<div class="content">{$form.count_type.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.financial_type_id.label}</div>
<div class="content crm-select-container">{$form.financial_type_id.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment