3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * This class generates form components for the display preferences.
37 class CRM_Admin_Form_Preferences_Contribute
extends CRM_Admin_Form_Preferences
{
38 protected $_settings = array(
39 'cvv_backoffice_required' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
40 'update_contribution_on_membership_type_change' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
41 'acl_financial_type' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
42 'always_post_to_accounts_receivable' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
43 'deferred_revenue_enabled' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
44 'default_invoice_page' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
45 'invoicing' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
49 * Process the form submission.
51 public function preProcess() {
52 $config = CRM_Core_Config
::singleton();
53 CRM_Utils_System
::setTitle(ts('CiviContribute Component Settings'));
54 $this->_varNames
= array(
55 CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
=> array(
56 'invoice_prefix' => array(
57 'html_type' => 'text',
58 'title' => ts('Invoice Prefix'),
60 'description' => ts('Enter prefix to be display on PDF for invoice'),
62 'credit_notes_prefix' => array(
63 'html_type' => 'text',
64 'title' => ts('Credit Notes Prefix'),
66 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
69 'html_type' => 'text',
70 'title' => ts('Due Date'),
73 'due_date_period' => array(
74 'html_type' => 'select',
75 'title' => ts('For transmission'),
77 'description' => ts('Select the interval for due date.'),
78 'option_values' => array(
79 'select' => ts('- select -'),
81 'months' => ts('Months'),
82 'years' => ts('Years'),
86 'html_type' => 'wysiwyg',
87 'title' => ts('Notes or Standard Terms'),
89 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
90 'attributes' => array('rows' => 2, 'cols' => 40),
92 'is_email_pdf' => array(
93 'html_type' => 'checkbox',
94 'title' => ts('Automatically email invoice when user purchases online'),
98 'html_type' => 'text',
99 'title' => ts('Tax Term'),
102 'tax_display_settings' => array(
103 'html_type' => 'select',
104 'title' => ts('Tax Display Settings'),
106 'option_values' => array(
107 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
108 $config->defaultCurrencySymbol
. '120.00'),
109 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
110 $config->defaultCurrencySymbol
.
111 '120.00 (includes [tax term] of ' .
112 $config->defaultCurrencySymbol
. '20.00)'),
113 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
114 $config->defaultCurrencySymbol
. '100.00 + ' .
115 $config->defaultCurrencySymbol
. '20.00 [tax term]'),
120 parent
::preProcess();
124 * Build the form object.
126 public function buildQuickForm() {
127 $htmlFields = array();
128 foreach ($this->_settings
as $setting => $group) {
129 $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
130 $props = $settingMetaData['values'][$setting];
131 if (isset($props['quick_form_type'])) {
132 $add = 'add' . $props['quick_form_type'];
133 if ($add == 'addElement') {
134 if (in_array($props['html_type'], array('checkbox', 'textarea'))) {
135 $this->add($props['html_type'],
141 if ($props['html_type'] == 'select') {
142 $functionName = CRM_Utils_Array
::value('name', CRM_Utils_Array
::value('pseudoconstant', $props));
144 $props['option_values'] = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::$functionName();
151 CRM_Utils_Array
::value($props['html_type'] == 'select' ?
'option_values' : 'html_attributes', $props, array()),
152 $props['html_type'] == 'select' ? CRM_Utils_Array
::value('html_attributes', $props) : NULL
156 elseif ($add == 'addMonthDay') {
157 $this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues
::date(NULL, 'M d'));
159 elseif ($add == 'addDate') {
160 $this->addDate($setting, ts($props['title']), FALSE, array('formatType' => $props['type']));
163 $this->$add($setting, ts($props['title']));
166 $htmlFields[$setting] = ts($props['description']);
168 $this->assign('htmlFields', $htmlFields);
169 parent
::buildQuickForm();
173 * Set default values for the form.
175 * default values are retrieved from the database
177 public function setDefaultValues() {
178 $defaults = Civi
::settings()->get('contribution_invoice_settings');
179 //CRM-16691: Changes made related to settings of 'CVV'.
180 foreach (array('cvv_backoffice_required') as $setting) {
181 $defaults[$setting] = civicrm_api3('setting', 'getvalue',
184 'group' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
192 * Process the form after the input has been submitted and validated.
194 public function postProcess() {
195 // store the submitted values in an array
196 $params = $this->controller
->exportValues($this->_name
);
197 unset($params['qfKey']);
198 unset($params['entryURL']);
199 Civi
::settings()->set('contribution_invoice_settings', $params);
200 Civi
::settings()->set('update_contribution_on_membership_type_change',
201 CRM_Utils_Array
::value('update_contribution_on_membership_type_change', $params)
204 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
205 $values = CRM_Core_BAO_Setting
::getItem("CiviCRM Preferences");
206 $optionValues = CRM_Core_OptionGroup
::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
207 $setKey = array_search('Invoices / Credit Notes', $optionValues);
209 if (isset($params['invoicing'])) {
210 $value = array($setKey => $optionValues[$setKey]);
211 $setInvoice = CRM_Core_DAO
::VALUE_SEPARATOR
.
212 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_keys($value)) .
213 CRM_Core_DAO
::VALUE_SEPARATOR
;
214 Civi
::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice);
217 $setting = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($values['user_dashboard_options'], 1, -1));
218 $invoiceKey = array_search($setKey, $setting);
219 if ($invoiceKey !== FALSE) {
220 unset($setting[$invoiceKey]);
222 $settingName = CRM_Core_DAO
::VALUE_SEPARATOR
.
223 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_values($setting)) .
224 CRM_Core_DAO
::VALUE_SEPARATOR
;
225 Civi
::settings()->set('user_dashboard_options', $settingName);
227 //CRM-16691: Changes made related to settings of 'CVV'.
228 $settings = array_intersect_key($params, array('cvv_backoffice_required' => 1));
229 $result = civicrm_api3('setting', 'create', $settings);
230 CRM_Core_Session
::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success");