Compare commits

..

2 Commits

Author SHA1 Message Date
Civiware Solutions
9f05f9fb13 added validation 2018-11-01 22:59:22 +05:30
Civiware Solutions
2d8ca3f2a3 added 'other' option for designation 2018-11-01 22:51:40 +05:30
2 changed files with 52 additions and 6 deletions

View File

@ -240,6 +240,9 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
$submitValues = $form->_params;
if (!empty($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,
['class' => 'crm-select2']
);
$form->add(
'text',
'designation_note',
''
);
CRM_Core_Region::instance('page-body')->add(array(
'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'])) {
$designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation');
if (!empty($designation)) {
$params['financial_type_id'] = $designation;
CRM_Core_Smarty::singleton()->assign('contribution_designation', '');
if ($designation == 'other_financial_type') {
// Ignore
}
else {
$params['financial_type_id'] = $designation;
}
}
}
@ -304,6 +316,22 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
}
}
/**
* Implements hook_civicrm_validateForm().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_validateForm
*/
function ftoverride_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if ('CRM_Contribute_Form_Contribution_Main' == $formName) {
if (!empty($fields['designation'])
&& $fields['designation'] == 'other_financial_type'
&& empty($fields['designation_note'])
) {
$errors['designation_note'] = ts('Please provide other information about designation.');
}
}
}
/**
* Implements hook_civicrm_buildAmount().
*
@ -312,7 +340,7 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) {
if (!empty($amount) && $form->_flagSubmitted) {
$submitValues = $form->_submitValues;
if (!empty($submitValues['designation'])) {
if (!empty($submitValues['designation']) && $submitValues['designation'] != 'other_financial_type') {
foreach ($amount as &$priceFields) {
foreach ($priceFields['options'] as &$options) {
$options['financial_type_id'] = $submitValues['designation'];
@ -338,6 +366,9 @@ function ftoverride_get_designation($pageId) {
function ftoverride_get_financialType($action) {
$financialTypes = [];
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action);
if (empty($financialTypes)) {
return $financialTypes;
}
$result = civicrm_api3('FinancialType', 'get', [
'return' => ["description"],
'description' => ['!=' => ""],
@ -347,5 +378,5 @@ function ftoverride_get_financialType($action) {
if (!empty($result['values'])) {
$descFinancialType = array_column($result['values'], 'description', 'id');
}
return $descFinancialType + $financialTypes;
return $descFinancialType + $financialTypes + ['other_financial_type' => ts('Other')];
}

View File

@ -1,12 +1,27 @@
<div class="crm-public-form-item crm-section ft_override_designation-section">
<div class="label">{$form.designation.label}</div>
<div class="content">{$form.designation.html}</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="content designation_note-div">{$form.designation_note.html}</div>
<div class="clear"></div>
</div>
{literal}
<script type="text/javascript">
CRM.$(function($) {
$('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>
{/literal}