3 +--------------------------------------------------------------------+
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 * Our standards for settings are to have a setting per value with defined metadata.
51 * Unfortunately the 'contribution_invoice_settings' has been added in non-compliance.
52 * We use this array to hack-handle.
54 * I think the best way forwards would be to covert to multiple individual settings.
58 protected $invoiceSettings = [];
61 * Build the form object.
63 public function buildQuickForm() {
64 parent
::buildQuickForm();
65 $config = CRM_Core_Config
::singleton();
66 $this->invoiceSettings
= [
68 'html_type' => 'text',
69 'title' => ts('Invoice Prefix'),
71 'description' => ts('Enter prefix to be display on PDF for invoice'),
73 'credit_notes_prefix' => [
74 'html_type' => 'text',
75 'title' => ts('Credit Notes Prefix'),
77 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
80 'html_type' => 'text',
81 'title' => ts('Due Date'),
84 'due_date_period' => [
85 'html_type' => 'select',
86 'title' => ts('For transmission'),
88 'description' => ts('Select the interval for due date.'),
90 'select' => ts('- select -'),
92 'months' => ts('Months'),
93 'years' => ts('Years'),
97 'html_type' => 'wysiwyg',
98 'title' => ts('Notes or Standard Terms'),
100 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
101 'attributes' => ['rows' => 2, 'cols' => 40],
104 'html_type' => 'checkbox',
105 'title' => ts('Automatically email invoice when user purchases online'),
107 'description' => ts('Should a pdf invoice be emailed automatically?'),
110 'html_type' => 'text',
111 'title' => ts('Tax Term'),
114 'tax_display_settings' => [
115 'html_type' => 'select',
116 'title' => ts('Tax Display Settings'),
119 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
120 $config->defaultCurrencySymbol
. '120.00'),
121 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
122 $config->defaultCurrencySymbol
.
123 '120.00 (includes [tax term] of ' .
124 $config->defaultCurrencySymbol
. '20.00)'),
125 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
126 $config->defaultCurrencySymbol
. '100.00 + ' .
127 $config->defaultCurrencySymbol
. '20.00 [tax term]'),
132 // @todo this is a faux metadata approach - we should be honest & add them correctly or find a way to make this
133 // compatible with our settings standards.
134 foreach ($this->invoiceSettings
as $fieldName => $fieldValue) {
135 switch ($fieldValue['html_type']) {
137 $this->addElement('text',
139 $fieldValue['title'],
148 $this->add($fieldValue['html_type'],
155 $this->addElement('select',
157 $fieldValue['title'],
158 $fieldValue['option_values'],
159 CRM_Utils_Array
::value('attributes', $fieldValue)
164 $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']);
169 $this->assign('htmlFields', $this->invoiceSettings
);
173 * Set default values for the form.
175 * default values are retrieved from the database
177 public function setDefaultValues() {
178 $defaults = parent
::setDefaultValues();
179 $defaults = array_merge($defaults, Civi
::settings()->get('contribution_invoice_settings'));
184 * Process the form after the input has been submitted and validated.
186 public function postProcess() {
187 // store the submitted values in an array
188 $params = $this->controller
->exportValues($this->_name
);
189 $invoiceParams = array_intersect_key($params, $this->invoiceSettings
);
190 // This is a hack - invoicing is it's own setting but it is being used from invoice params
191 // too. This means that saving from api will not have the desired core effect.
192 // but we should fix that elsewhere - ie. stop abusing the settings
193 // and fix the code repetition associated with invoicing
194 $invoiceParams['invoicing'] = CRM_Utils_Array
::value('invoicing', $params, 0);
195 Civi
::settings()->set('contribution_invoice_settings', $invoiceParams);
196 parent
::postProcess();
198 // @todo - all this should be handled by defining an on change action in the metadata.
199 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
200 $values = CRM_Core_BAO_Setting
::getItem("CiviCRM Preferences");
201 $optionValues = CRM_Core_OptionGroup
::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
202 $setKey = array_search('Invoices / Credit Notes', $optionValues);
204 if (isset($params['invoicing'])) {
205 $value = array($setKey => $optionValues[$setKey]);
206 $setInvoice = CRM_Core_DAO
::VALUE_SEPARATOR
.
207 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_keys($value)) .
208 CRM_Core_DAO
::VALUE_SEPARATOR
;
209 Civi
::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice);
212 $setting = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($values['user_dashboard_options'], 1, -1));
213 $invoiceKey = array_search($setKey, $setting);
214 if ($invoiceKey !== FALSE) {
215 unset($setting[$invoiceKey]);
217 $settingName = CRM_Core_DAO
::VALUE_SEPARATOR
.
218 implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_values($setting)) .
219 CRM_Core_DAO
::VALUE_SEPARATOR
;
220 Civi
::settings()->set('user_dashboard_options', $settingName);