3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * This class generates form components for the display preferences
40 class CRM_Admin_Form_Preferences_Contribute
extends CRM_Admin_Form_Preferences
{
41 protected $_settings = array(
42 'cvv_backoffice_required' => CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,
45 * Process the form submission.
50 public function preProcess() {
51 $config = CRM_Core_Config
::singleton();
52 CRM_Utils_System
::setTitle(ts('CiviContribute Component Settings'));
53 $this->_varNames
= array(
54 CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
=> array(
55 'invoice_prefix' => array(
56 'html_type' => 'text',
57 'title' => ts('Invoice Prefix'),
59 'description' => ts('Enter prefix to be display on PDF for invoice'),
61 'credit_notes_prefix' => array(
62 'html_type' => 'text',
63 'title' => ts('Credit Notes Prefix'),
65 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
68 'html_type' => 'text',
69 'title' => ts('Due Date'),
72 'due_date_period' => array(
73 'html_type' => 'select',
74 'title' => ts('For transmission'),
76 'description' => ts('Select the interval for due date.'),
77 'option_values' => array(
78 'select' => ts('- select -'),
80 'months' => ts('Months'),
81 'years' => ts('Years'),
85 'html_type' => 'wysiwyg',
86 'title' => ts('Notes or Standard Terms'),
88 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
89 'attributes' => array('rows' => 2, 'cols' => 40),
91 'is_email_pdf' => array(
92 'html_type' => 'checkbox',
93 'title' => ts('Automatically email invoice when user purchases online'),
97 'html_type' => 'text',
98 'title' => ts('Tax Term'),
101 'tax_display_settings' => array(
102 'html_type' => 'select',
103 'title' => ts('Tax Display Settings'),
105 'option_values' => array(
106 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
107 $config->defaultCurrencySymbol
. '120.00'),
108 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
109 $config->defaultCurrencySymbol
.
110 '120.00 (includes [tax term] of ' .
111 $config->defaultCurrencySymbol
. '20.00)'),
112 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
113 $config->defaultCurrencySymbol
. '100.00 + ' .
114 $config->defaultCurrencySymbol
. '20.00 [tax term]'),
119 parent
::preProcess();
123 * Build the form object.
127 public function buildQuickForm() {
128 //CRM-16691: Changes made related to settings of 'CVV'.
129 foreach ($this->_settings
as $setting => $group) {
130 $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
131 $props = $settingMetaData['values'][$setting];
132 if (isset($props['quick_form_type'])) {
133 $add = 'add' . $props['quick_form_type'];
134 if ($add == 'addElement') {
139 CRM_Utils_Array
::value($props['html_type'] == 'select' ?
'option_values' : 'html_attributes', $props, array()),
140 $props['html_type'] == 'select' ? CRM_Utils_Array
::value('html_attributes', $props) : NULL
144 $this->$add($setting, ts($props['title']));
147 $this->assign("{$setting}_description", ts($props['description']));
149 $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing'));
150 parent
::buildQuickForm();
154 * Set default values for the form.
155 * default values are retrieved from the database
160 public function setDefaultValues() {
161 $defaults = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
162 //CRM-16691: Changes made related to settings of 'CVV'.
163 foreach ($this->_settings
as $setting => $group) {
164 $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
165 $defaults[$setting] = civicrm_api3('setting', 'getvalue',
169 'default_value' => CRM_Utils_Array
::value('default', $settingMetaData['values'][$setting]),
177 * Process the form after the input has been submitted and validated.
182 public function postProcess() {
183 // store the submitted values in an array
184 $params = $this->controller
->exportValues($this->_name
);
185 unset($params['qfKey']);
186 unset($params['entryURL']);
187 $setInvoiceSettings = CRM_Core_BAO_Setting
::setItem($params, CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
189 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
190 $values = CRM_Core_BAO_Setting
::getItem("CiviCRM Preferences");
191 $optionValues = CRM_Core_OptionGroup
::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
192 $setKey = array_search('Invoices / Credit Notes', $optionValues);
194 if (isset($params['invoicing'])) {
195 $value = array($setKey => $optionValues[$setKey]);
196 $setInvoice = CRM_Core_DAO
::VALUE_SEPARATOR
.
197 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_keys($value)) .
198 CRM_Core_DAO
::VALUE_SEPARATOR
;
199 CRM_Core_BAO_Setting
::setItem($values['user_dashboard_options'] .
200 $setInvoice, 'CiviCRM Preferences', 'user_dashboard_options');
203 $setting = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($values['user_dashboard_options'], 1, -1));
204 $invoiceKey = array_search($setKey, $setting);
205 unset($setting[$invoiceKey]);
206 $settingName = CRM_Core_DAO
::VALUE_SEPARATOR
.
207 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_values($setting)) .
208 CRM_Core_DAO
::VALUE_SEPARATOR
;
209 CRM_Core_BAO_Setting
::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options');
211 //CRM-16691: Changes made related to settings of 'CVV'.
212 $settings = array_intersect_key($params, $this->_settings
);
213 $result = civicrm_api3('setting', 'create', $settings);
214 CRM_Core_Session
::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success");