more changes

This commit is contained in:
CiviWare Solutions 2018-12-14 02:58:52 +00:00
parent f71e682614
commit 889293c1aa

View File

@ -185,6 +185,32 @@ function checknumberpaymentmethod_civicrm_preProcess($formName, &$form) {
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*/
function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
if ('CRM_Contribute_Form_AdditionalPayment' == $formName
&& $form->getVar('_view') == 'transaction'
&& ($form->getVar('_action') & CRM_Core_Action::BROWSE)
) {
$paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
'name' => 'check_payment_instrument_ids',
]);
$payments = $form->get_template_vars('payments');
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
}
}
$form->assign('payments', $payments);
}
if ('CRM_Admin_Form_Preferences_Contribute' == $formName) {
$form->addElement(
'select',
@ -221,3 +247,28 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
$form->assign('paymentInstrumentsFromSettings', json_encode($paymentInstrumentsFromSettings));
}
}
/**
* Implements hook_civicrm_pre().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
*/
function checknumberpaymentmethod_civicrm_pre($op, $objectName, $id, &$params) {
if ($objectName == 'Contribution' && in_array($op, ['create', 'edit'])) {
if (!CRM_Utils_System::isNull($params['check_number']) || !empty($_POST['check_number'])) {
$paymentInstrumentId = !empty($params['payment_instrument_id']) ? $params['payment_instrument_id'] : $params['prevContribution']->payment_instrument_id;
$paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
'name' => 'check_payment_instrument_ids',
]);
if (!in_array($paymentInstrumentId, $paymentInstrumentsFromSettings)) {
return;
}
if (!CRM_Utils_System::isNull($params['check_number'])) {
$params['check_number'] = $params['check_number'];
}
else {
$params['check_number'] = $_POST['check_number'];
}
}
}
}