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 $defaults = $this->_values
;
77 if (!empty($defaults['card_type_id'])) {
78 // See comments in getPaymentFields function about why this nastiness exists.
79 $defaults['credit_card_type'] = CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', $defaults['card_type_id']);
88 public function buildQuickForm() {
89 CRM_Utils_System
::setTitle(ts('Update Payment details'));
91 $paymentFields = $this->getPaymentFields();
92 $this->assign('paymentFields', $paymentFields);
93 foreach ($paymentFields as $name => $paymentField) {
94 $this->add($paymentField['htmlType'],
95 $paymentField['name'],
96 $paymentField['title'],
97 $paymentField['attributes'],
100 if (!empty($paymentField['rules'])) {
101 foreach ($paymentField['rules'] as $rule) {
102 $this->addRule($name,
103 $rule['rule_message'],
105 $rule['rule_parameters']
111 $this->assign('currency', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_Currency', $this->_values
['currency'], 'symbol', 'name'));
112 $this->addButtons(array(
115 'name' => ts('Update'),
120 'name' => ts('Cancel'),
126 * Process the form submission.
128 public function postProcess() {
131 'check_number' => CRM_Utils_Array
::value('check_number', $this->_submitValues
),
132 'pan_truncation' => CRM_Utils_Array
::value('pan_truncation', $this->_submitValues
),
133 'trxn_date' => CRM_Utils_Array
::value('trxn_date', $this->_submitValues
, date('YmdHis')),
135 if (!empty($this->_submitValues
['credit_card_type'])) {
136 // See comments in getPaymentFields function about why this nastiness exists.
137 $params['card_type_id'] = CRM_Core_PseudoConstant
::getKey(
138 'CRM_Financial_DAO_FinancialTrxn',
140 $this->_submitValues
['credit_card_type']
143 // update the financial trxn
144 civicrm_api3('FinancialTrxn', 'create', $params);
145 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath()));
151 public function getPaymentFields() {
152 $paymentFields = array();
153 $paymentInstrument = CRM_Core_PseudoConstant
::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $this->_values
['payment_instrument_id']);
154 if ($paymentInstrument == 'Check') {
155 $paymentFields['check_number'] = array(
156 'htmlType' => 'text',
157 'name' => 'check_number',
158 'title' => ts('Check Number'),
159 'is_required' => FALSE,
160 'attributes' => NULL,
163 elseif ($paymentInstrument == 'Credit Card') {
164 // Ideally we would use $this->addField('card_type_id', array('entity' => 'FinancialTrxn'));
165 // to assign this field (& other fields on this form). However, the addCreditCardJs
166 // adds some 'pretty' to the credit card selection. The 'cost' of this is that because it
167 // was originally written to comply with front end needs (use of the word rather than the id)
168 // we have to do a lot of wrangling with our fields to make the BillingBlock.js code work.
169 // If you are reading this it means it's time to fix the BillingBlock.js to work with
170 // card_type_id and the pseudoconstant options & set this code free. No returns.
171 CRM_Financial_Form_Payment
::addCreditCardJs(NULL, 'payment-edit-block');
172 $paymentFields['credit_card_type'] = array(
173 'htmlType' => 'select',
174 'name' => 'credit_card_type',
175 'title' => ts('Card Type'),
176 'attributes' => array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::creditCard(),
178 $paymentFields['pan_truncation'] = array(
179 'htmlType' => 'text',
180 'name' => 'pan_truncation',
181 'title' => ts('Last 4 digits of the card'),
182 'attributes' => array(
186 'autocomplete' => 'off',
190 'rule_message' => ts('Please enter valid last 4 digit card number.'),
191 'rule_name' => 'numeric',
192 'rule_parameters' => NULL,
197 $paymentFields +
= array(
198 'trxn_date' => array(
199 'htmlType' => 'datepicker',
200 'name' => 'trxn_date',
201 'title' => ts('Transaction Date'),
202 'attributes' => array(
203 'date' => 'yyyy-mm-dd',
207 'total_amount' => array(
208 'htmlType' => 'text',
209 'name' => 'total_amount',
210 'title' => ts('Total Amount'),
211 'attributes' => array(
218 return $paymentFields;