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'])) {
89 $this->addField($name, $paymentField['attributes'], $paymentField['is_required']);
92 $this->add($paymentField['htmlType'],
94 $paymentField['title'],
95 $paymentField['attributes'],
96 $paymentField['is_required']
101 $this->assign('currency', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', $this->_values
['currency'], 'symbol', 'name'));
102 $this->addFormRule(array(__CLASS__
, 'formRule'), $this);
104 $this->addButtons(array(
107 'name' => ts('Update'),
112 'name' => ts('Cancel'),
120 * @param array $fields
121 * The input form values.
122 * @param array $files
123 * The uploaded files if any.
127 * true if no errors, else array of errors
129 public static function formRule($fields, $files, $self) {
132 // if Credit Card is chosen and pan_truncation is not NULL ensure that it's value is numeric else throw validation error
133 if (CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $fields['payment_instrument_id']) == 'Credit Card' &&
134 !empty($fields['pan_truncation']) &&
135 !CRM_Utils_Rule
::numeric($fields['pan_truncation'])
137 $errors['pan_truncation'] = ts('Please enter a valid Card Number');
144 * Process the form submission.
146 public function postProcess() {
149 'payment_instrument_id' => $this->_submitValues
['payment_instrument_id'],
150 'trxn_id' => CRM_Utils_Array
::value('trxn_id', $this->_submitValues
),
151 'trxn_date' => CRM_Utils_Array
::value('trxn_date', $this->_submitValues
, date('YmdHis')),
154 $paymentInstrumentName = CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $params['payment_instrument_id']);
155 if ($paymentInstrumentName == 'Credit Card') {
156 $params['card_type_id'] = CRM_Utils_Array
::value('card_type_id', $this->_submitValues
);
157 $params['pan_truncation'] = CRM_Utils_Array
::value('pan_truncation', $this->_submitValues
);
159 elseif ($paymentInstrumentName == 'Check') {
160 $params['check_number'] = CRM_Utils_Array
::value('check_number', $this->_submitValues
);
163 // update the financial trxn
164 civicrm_api3('FinancialTrxn', 'create', $params);
165 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath()));
171 public function getPaymentFields() {
172 $paymentFields = array(
173 'payment_instrument_id' => array(
174 'is_required' => TRUE,
176 'attributes' => array(
177 'entity' => 'FinancialTrxn',
178 'name' => 'payment_instrument_id',
181 'check_number' => array(
182 'is_required' => FALSE,
184 'attributes' => array(
185 'entity' => 'FinancialTrxn',
186 'name' => 'check_number',
189 // @TODO we need to show card type icon in place of select field
190 'card_type_id' => array(
191 'is_required' => FALSE,
193 'attributes' => array(
194 'entity' => 'FinancialTrxn',
195 'name' => 'card_type_id',
198 'pan_truncation' => array(
199 'is_required' => FALSE,
201 'attributes' => array(
202 'entity' => 'FinancialTrxn',
203 'name' => 'pan_truncation',
207 'htmlType' => 'text',
208 'title' => ts('Transaction ID'),
209 'is_required' => FALSE,
210 'attributes' => array(
214 'trxn_date' => array(
215 'htmlType' => 'datepicker',
216 'name' => 'trxn_date',
217 'title' => ts('Transaction Date'),
218 'is_required' => TRUE,
219 'attributes' => array(
220 'date' => 'yyyy-mm-dd',
224 'total_amount' => array(
225 'htmlType' => 'text',
226 'name' => 'total_amount',
227 'title' => ts('Total Amount'),
228 'is_required' => TRUE,
229 'attributes' => array(
236 return $paymentFields;