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
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
,
43 * Process the form submission.
45 public function preProcess() {
46 $config = CRM_Core_Config
::singleton();
47 CRM_Utils_System
::setTitle(ts('CiviContribute Component Settings'));
48 $this->_varNames
= array(
49 CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
=> array(
50 'invoice_prefix' => array(
51 'html_type' => 'text',
52 'title' => ts('Invoice Prefix'),
54 'description' => ts('Enter prefix to be display on PDF for invoice'),
56 'credit_notes_prefix' => array(
57 'html_type' => 'text',
58 'title' => ts('Credit Notes Prefix'),
60 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
63 'html_type' => 'text',
64 'title' => ts('Due Date'),
67 'due_date_period' => array(
68 'html_type' => 'select',
69 'title' => ts('For transmission'),
71 'description' => ts('Select the interval for due date.'),
72 'option_values' => array(
73 'select' => ts('- select -'),
75 'months' => ts('Months'),
76 'years' => ts('Years'),
80 'html_type' => 'wysiwyg',
81 'title' => ts('Notes or Standard Terms'),
83 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
84 'attributes' => array('rows' => 2, 'cols' => 40),
86 'is_email_pdf' => array(
87 'html_type' => 'checkbox',
88 'title' => ts('Automatically email invoice when user purchases online'),
92 'html_type' => 'text',
93 'title' => ts('Tax Term'),
96 'tax_display_settings' => array(
97 'html_type' => 'select',
98 'title' => ts('Tax Display Settings'),
100 'option_values' => array(
101 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
102 $config->defaultCurrencySymbol
. '120.00'),
103 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
104 $config->defaultCurrencySymbol
.
105 '120.00 (includes [tax term] of ' .
106 $config->defaultCurrencySymbol
. '20.00)'),
107 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
108 $config->defaultCurrencySymbol
. '100.00 + ' .
109 $config->defaultCurrencySymbol
. '20.00 [tax term]'),
114 parent
::preProcess();
118 * Build the form object.
120 public function buildQuickForm() {
121 //CRM-16691: Changes made related to settings of 'CVV'.
122 foreach ($this->_settings
as $setting => $group) {
123 $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
124 $props = $settingMetaData['values'][$setting];
125 if (isset($props['quick_form_type'])) {
126 $add = 'add' . $props['quick_form_type'];
127 if ($add == 'addElement') {
132 CRM_Utils_Array
::value($props['html_type'] == 'select' ?
'option_values' : 'html_attributes', $props, array()),
133 $props['html_type'] == 'select' ? CRM_Utils_Array
::value('html_attributes', $props) : NULL
137 $this->$add($setting, ts($props['title']));
140 $this->assign("{$setting}_description", ts($props['description']));
142 $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing'));
143 $this->add('checkbox', 'acl_financial_type', ts('Enable Access Control by Financial Type'));
144 parent
::buildQuickForm();
148 * Set default values for the form.
150 * default values are retrieved from the database
152 public function setDefaultValues() {
153 $defaults = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
154 //CRM-16691: Changes made related to settings of 'CVV'.
155 foreach ($this->_settings
as $setting => $group) {
156 $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
157 $defaults[$setting] = civicrm_api3('setting', 'getvalue',
161 'default_value' => CRM_Utils_Array
::value('default', $settingMetaData['values'][$setting]),
169 * Process the form after the input has been submitted and validated.
171 public function postProcess() {
172 // store the submitted values in an array
173 $params = $this->controller
->exportValues($this->_name
);
174 unset($params['qfKey']);
175 unset($params['entryURL']);
176 $setInvoiceSettings = CRM_Core_BAO_Setting
::setItem($params, CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
178 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
179 $values = CRM_Core_BAO_Setting
::getItem("CiviCRM Preferences");
180 $optionValues = CRM_Core_OptionGroup
::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
181 $setKey = array_search('Invoices / Credit Notes', $optionValues);
183 if (isset($params['invoicing'])) {
184 $value = array($setKey => $optionValues[$setKey]);
185 $setInvoice = CRM_Core_DAO
::VALUE_SEPARATOR
.
186 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_keys($value)) .
187 CRM_Core_DAO
::VALUE_SEPARATOR
;
188 CRM_Core_BAO_Setting
::setItem($values['user_dashboard_options'] .
189 $setInvoice, 'CiviCRM Preferences', 'user_dashboard_options');
192 $setting = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($values['user_dashboard_options'], 1, -1));
193 $invoiceKey = array_search($setKey, $setting);
194 unset($setting[$invoiceKey]);
195 $settingName = CRM_Core_DAO
::VALUE_SEPARATOR
.
196 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_values($setting)) .
197 CRM_Core_DAO
::VALUE_SEPARATOR
;
198 CRM_Core_BAO_Setting
::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options');
200 //CRM-16691: Changes made related to settings of 'CVV'.
201 $settings = array_intersect_key($params, $this->_settings
);
202 $result = civicrm_api3('setting', 'create', $settings);
203 CRM_Core_Session
::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success");