_action = CRM_Core_Action::UPDATE; parent::preProcess(); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); $this->_values = civicrm_api3('FinancialTrxn', 'getsingle', array('id' => $this->_id)); if (!empty($this->_values['payment_processor_id'])) { CRM_Core_Error::statusBounce(ts('You cannot update this payment')); } } /** * Set default values. * * @return array */ public function setDefaultValues() { $defaults = $this->_values; if (!empty($defaults['card_type_id'])) { // See comments in getPaymentFields function about why this nastiness exists. $defaults['credit_card_type'] = CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', $defaults['card_type_id']); } return $defaults; } /** * Build quickForm. */ public function buildQuickForm() { CRM_Utils_System::setTitle(ts('Update Payment details')); $paymentFields = $this->getPaymentFields(); $this->assign('paymentFields', $paymentFields); foreach ($paymentFields as $name => $paymentField) { $this->add($paymentField['htmlType'], $paymentField['name'], $paymentField['title'], $paymentField['attributes'], TRUE ); if (!empty($paymentField['rules'])) { foreach ($paymentField['rules'] as $rule) { $this->addRule($name, $rule['rule_message'], $rule['rule_name'], $rule['rule_parameters'] ); } } } $this->assign('currency', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $this->_values['currency'], 'symbol', 'name')); $this->addButtons(array( array( 'type' => 'submit', 'name' => ts('Update'), 'isDefault' => TRUE, ), array( 'type' => 'cancel', 'name' => ts('Cancel'), ), )); } /** * Process the form submission. */ public function postProcess() { $params = array( 'id' => $this->_id, 'check_number' => CRM_Utils_Array::value('check_number', $this->_submitValues), 'pan_truncation' => CRM_Utils_Array::value('pan_truncation', $this->_submitValues), 'trxn_date' => CRM_Utils_Array::value('trxn_date', $this->_submitValues, date('YmdHis')), ); if (!empty($this->_submitValues['credit_card_type'])) { // See comments in getPaymentFields function about why this nastiness exists. $params['card_type_id'] = CRM_Core_PseudoConstant::getKey( 'CRM_Financial_DAO_FinancialTrxn', 'card_type_id', $this->_submitValues['credit_card_type'] ); } // update the financial trxn civicrm_api3('FinancialTrxn', 'create', $params); CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath())); } /** * Get payment fields */ public function getPaymentFields() { $paymentFields = array(); $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $this->_values['payment_instrument_id']); if ($paymentInstrument == 'Check') { $paymentFields['check_number'] = array( 'htmlType' => 'text', 'name' => 'check_number', 'title' => ts('Check Number'), 'is_required' => FALSE, 'attributes' => NULL, ); } elseif ($paymentInstrument == 'Credit Card') { // Ideally we would use $this->addField('card_type_id', array('entity' => 'FinancialTrxn')); // to assign this field (& other fields on this form). However, the addCreditCardJs // adds some 'pretty' to the credit card selection. The 'cost' of this is that because it // was originally written to comply with front end needs (use of the word rather than the id) // we have to do a lot of wrangling with our fields to make the BillingBlock.js code work. // If you are reading this it means it's time to fix the BillingBlock.js to work with // card_type_id and the pseudoconstant options & set this code free. No returns. CRM_Financial_Form_Payment::addCreditCardJs(NULL, 'payment-edit-block'); $paymentFields['credit_card_type'] = array( 'htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'attributes' => array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(), ); $paymentFields['pan_truncation'] = array( 'htmlType' => 'text', 'name' => 'pan_truncation', 'title' => ts('Last 4 digits of the card'), 'attributes' => array( 'size' => 4, 'maxlength' => 4, 'minlength' => 4, 'autocomplete' => 'off', ), 'rules' => array( array( 'rule_message' => ts('Please enter valid last 4 digit card number.'), 'rule_name' => 'numeric', 'rule_parameters' => NULL, ), ), ); } $paymentFields += array( 'trxn_date' => array( 'htmlType' => 'datepicker', 'name' => 'trxn_date', 'title' => ts('Transaction Date'), 'attributes' => array( 'date' => 'yyyy-mm-dd', 'time' => 24, ), ), 'total_amount' => array( 'htmlType' => 'text', 'name' => 'total_amount', 'title' => ts('Total Amount'), 'attributes' => array( 'readonly' => TRUE, 'size' => 6, ), ), ); return $paymentFields; } }