3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 class CRM_Financial_Form_PaymentEdit
extends CRM_Core_Form
{
36 * The id of the financial trxn.
43 * The variable which holds the information of a financial transaction
50 * Explicitly declare the form context.
52 public function getDefaultContext() {
56 * Set variables up before form is built.
58 public function preProcess() {
59 $this->_action
= CRM_Core_Action
::UPDATE
;
61 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
62 $this->assign('id', $this->_id
);
64 $this->_values
= civicrm_api3('FinancialTrxn', 'getsingle', array('id' => $this->_id
));
65 if (!empty($this->_values
['payment_processor_id'])) {
66 CRM_Core_Error
::statusBounce(ts('You cannot update this payment'));
75 public function setDefaultValues() {
76 return $this->_values
;
82 public function buildQuickForm() {
83 CRM_Utils_System
::setTitle(ts('Update Payment details'));
85 $paymentFields = $this->getPaymentFields();
86 $this->assign('paymentFields', $paymentFields);
87 foreach ($paymentFields as $name => $paymentField) {
88 if (!empty($paymentField['add_field'])) {
90 'entity' => 'FinancialTrxn',
93 $this->addField($name, $attributes, $paymentField['is_required']);
96 $this->add($paymentField['htmlType'],
98 $paymentField['title'],
99 $paymentField['attributes'],
100 $paymentField['is_required']
105 $this->assign('currency', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', $this->_values
['currency'], 'symbol', 'name'));
106 $this->addFormRule(array(__CLASS__
, 'formRule'), $this);
108 $this->addButtons(array(
111 'name' => ts('Update'),
116 'name' => ts('Cancel'),
124 * @param array $fields
125 * The input form values.
126 * @param array $files
127 * The uploaded files if any.
131 * true if no errors, else array of errors
133 public static function formRule($fields, $files, $self) {
136 // if Credit Card is chosen and pan_truncation is not NULL ensure that it's value is numeric else throw validation error
137 if (CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $fields['payment_instrument_id']) == 'Credit Card' &&
138 !empty($fields['pan_truncation']) &&
139 !CRM_Utils_Rule
::numeric($fields['pan_truncation'])
141 $errors['pan_truncation'] = ts('Please enter a valid Card Number');
148 * Process the form submission.
150 public function postProcess() {
153 'payment_instrument_id' => $this->_submitValues
['payment_instrument_id'],
154 'trxn_id' => CRM_Utils_Array
::value('trxn_id', $this->_submitValues
),
155 'trxn_date' => CRM_Utils_Array
::value('trxn_date', $this->_submitValues
, date('YmdHis')),
158 $paymentInstrumentName = CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $params['payment_instrument_id']);
159 if ($paymentInstrumentName == 'Credit Card') {
160 $params['card_type_id'] = CRM_Utils_Array
::value('card_type_id', $this->_submitValues
);
161 $params['pan_truncation'] = CRM_Utils_Array
::value('pan_truncation', $this->_submitValues
);
163 elseif ($paymentInstrumentName == 'Check') {
164 $params['check_number'] = CRM_Utils_Array
::value('check_number', $this->_submitValues
);
167 // update the financial trxn
168 civicrm_api3('FinancialTrxn', 'create', $params);
169 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath()));
175 public function getPaymentFields() {
176 $paymentFields = array(
177 'payment_instrument_id' => array(
178 'is_required' => TRUE,
181 'check_number' => array(
182 'is_required' => FALSE,
185 // @TODO we need to show card type icon in place of select field
186 'card_type_id' => array(
187 'is_required' => FALSE,
190 'pan_truncation' => array(
191 'is_required' => FALSE,
196 'is_required' => FALSE,
198 'trxn_date' => array(
199 'htmlType' => 'datepicker',
200 'name' => 'trxn_date',
201 'title' => ts('Transaction Date'),
202 'is_required' => TRUE,
203 'attributes' => array(
204 'date' => 'yyyy-mm-dd',
208 'total_amount' => array(
209 'htmlType' => 'text',
210 'name' => 'total_amount',
211 'title' => ts('Total Amount'),
212 'is_required' => TRUE,
213 'attributes' => array(
220 return $paymentFields;