show check number on View/edit contribution form

This commit is contained in:
CiviWare Solutions 2018-12-18 17:18:24 +00:00
parent 889293c1aa
commit 66082cc24e
2 changed files with 26 additions and 21 deletions

View File

@ -185,30 +185,14 @@ function checknumberpaymentmethod_civicrm_preProcess($formName, &$form) {
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*/ */
function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) { function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
if ('CRM_Contribute_Form_AdditionalPayment' == $formName if (('CRM_Contribute_Form_AdditionalPayment' == $formName
&& $form->getVar('_view') == 'transaction' && $form->getVar('_view') == 'transaction'
&& ($form->getVar('_action') & CRM_Core_Action::BROWSE) && ($form->getVar('_action') & CRM_Core_Action::BROWSE))
|| 'CRM_Contribute_Form_Contribution' == $formName
|| 'CRM_Contribute_Form_ContributionView' == $formName
) { ) {
$paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
'name' => 'check_payment_instrument_ids',
]);
$payments = $form->get_template_vars('payments'); $payments = $form->get_template_vars('payments');
foreach ($payments as &$payment) { _checknumberpaymentmethod_alterpayments($payments);
try {
$checkNumber = civicrm_api3('FinancialTrxn', 'getvalue', [
'return' => "check_number",
'id' => $payment['id'],
'payment_instrument_id' => ['IN' => $paymentInstrumentsFromSettings],
]);
if (!empty($checkNumber)) {
$payment['payment_instrument'] .= " (#{$checkNumber})";
}
}
catch (Exception $e) {
// Ignore
}
}
$form->assign('payments', $payments); $form->assign('payments', $payments);
} }
if ('CRM_Admin_Form_Preferences_Contribute' == $formName) { if ('CRM_Admin_Form_Preferences_Contribute' == $formName) {
@ -272,3 +256,24 @@ function checknumberpaymentmethod_civicrm_pre($op, $objectName, $id, &$params) {
} }
} }
} }
function _checknumberpaymentmethod_alterpayments(&$payments) {
$paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
'name' => 'check_payment_instrument_ids',
]);
foreach ($payments as &$payment) {
try {
$checkNumber = civicrm_api3('FinancialTrxn', 'getvalue', [
'return' => "check_number",
'id' => $payment['id'],
'payment_instrument_id' => ['IN' => $paymentInstrumentsFromSettings],
]);
if (!empty($checkNumber)) {
$payment['payment_instrument'] .= " (#{$checkNumber})";
}
}
catch (Exception $e) {
// Ignore
}
}
}