added 'other' option for designation

This commit is contained in:
Civiware Solutions 2018-11-01 22:51:40 +05:30
parent 53ddc10ca1
commit 2d8ca3f2a3
2 changed files with 36 additions and 6 deletions

View File

@ -240,6 +240,9 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
$submitValues = $form->_params; $submitValues = $form->_params;
if (!empty($submitValues['designation'])) { if (!empty($submitValues['designation'])) {
$form->assign('contribution_designation', $submitValues['designation']); $form->assign('contribution_designation', $submitValues['designation']);
if ($submitValues['designation'] == 'other_financial_type') {
$form->_params['contribution_note'] = $submitValues['designation_note'];
}
} }
} }
@ -260,6 +263,11 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
FALSE, FALSE,
['class' => 'crm-select2'] ['class' => 'crm-select2']
); );
$form->add(
'text',
'designation_note',
''
);
CRM_Core_Region::instance('page-body')->add(array( CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl', 'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl',
)); ));
@ -280,8 +288,12 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == 'create' && $objectName == 'Contribution' && !empty($params['contribution_page_id'])) { if ($op == 'create' && $objectName == 'Contribution' && !empty($params['contribution_page_id'])) {
$designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation'); $designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation');
if (!empty($designation)) { if (!empty($designation)) {
if ($designation == 'other_financial_type') {
// Ignore
}
else {
$params['financial_type_id'] = $designation; $params['financial_type_id'] = $designation;
CRM_Core_Smarty::singleton()->assign('contribution_designation', ''); }
} }
} }
@ -312,7 +324,7 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) { function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) {
if (!empty($amount) && $form->_flagSubmitted) { if (!empty($amount) && $form->_flagSubmitted) {
$submitValues = $form->_submitValues; $submitValues = $form->_submitValues;
if (!empty($submitValues['designation'])) { if (!empty($submitValues['designation']) && $submitValues['designation'] != 'other_financial_type') {
foreach ($amount as &$priceFields) { foreach ($amount as &$priceFields) {
foreach ($priceFields['options'] as &$options) { foreach ($priceFields['options'] as &$options) {
$options['financial_type_id'] = $submitValues['designation']; $options['financial_type_id'] = $submitValues['designation'];
@ -338,6 +350,9 @@ function ftoverride_get_designation($pageId) {
function ftoverride_get_financialType($action) { function ftoverride_get_financialType($action) {
$financialTypes = []; $financialTypes = [];
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action); CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action);
if (empty($financialTypes)) {
return $financialTypes;
}
$result = civicrm_api3('FinancialType', 'get', [ $result = civicrm_api3('FinancialType', 'get', [
'return' => ["description"], 'return' => ["description"],
'description' => ['!=' => ""], 'description' => ['!=' => ""],
@ -347,5 +362,5 @@ function ftoverride_get_financialType($action) {
if (!empty($result['values'])) { if (!empty($result['values'])) {
$descFinancialType = array_column($result['values'], 'description', 'id'); $descFinancialType = array_column($result['values'], 'description', 'id');
} }
return $descFinancialType + $financialTypes; return $descFinancialType + $financialTypes + ['other_financial_type' => ts('Other')];
} }

View File

@ -2,11 +2,26 @@
<div class="label">{$form.designation.label}</div> <div class="label">{$form.designation.label}</div>
<div class="content">{$form.designation.html}</div> <div class="content">{$form.designation.html}</div>
<div class="clear"></div> <div class="clear"></div>
</div> <div class="content designation_note-div">{$form.designation_note.html}</div>
<div class="clear"></div>
</div>
{literal} {literal}
<script type="text/javascript"> <script type="text/javascript">
CRM.$(function($) { CRM.$(function($) {
$('div#priceset:first').after($('div.ft_override_designation-section')); $('div#priceset:first').after($('div.ft_override_designation-section'));
hideShowDesignation();
$('#designation').change(hideShowDesignation);
function hideShowDesignation() {
var fT = $('#designation').val();
if (fT == 'other_financial_type') {
$('div.ft_override_designation-section div.designation_note-div').show();
}
else {
$('div.ft_override_designation-section div.designation_note-div').hide();
}
}
}); });
</script> </script>
{/literal} {/literal}