Commit | Line | Data |
---|---|---|
d75f2f47 | 1 | <?php |
c73475ea WA |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.6 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2015 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
9d4da082 RK |
35 | |
36 | /** | |
37 | * This class generates form components for the display preferences | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { | |
e0d19757 WA |
41 | protected $_settings = array( |
42 | 'cvv_backoffice_required' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, | |
43 | ); | |
1be9403d | 44 | /** |
eceb18cc | 45 | * Process the form submission. |
1be9403d | 46 | * |
1be9403d | 47 | * |
48 | * @return void | |
49 | */ | |
00be9182 | 50 | public function preProcess() { |
fff0f449 | 51 | $config = CRM_Core_Config::singleton(); |
9d4da082 RK |
52 | CRM_Utils_System::setTitle(ts('CiviContribute Component Settings')); |
53 | $this->_varNames = array( | |
9d72cede | 54 | CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array( |
353ffa53 TO |
55 | 'invoice_prefix' => array( |
56 | 'html_type' => 'text', | |
57 | 'title' => ts('Invoice Prefix'), | |
58 | 'weight' => 1, | |
59 | 'description' => ts('Enter prefix to be display on PDF for invoice'), | |
60 | ), | |
61 | 'credit_notes_prefix' => array( | |
62 | 'html_type' => 'text', | |
63 | 'title' => ts('Credit Notes Prefix'), | |
64 | 'weight' => 2, | |
65 | 'description' => ts('Enter prefix to be display on PDF for credit notes.'), | |
66 | ), | |
67 | 'due_date' => array( | |
68 | 'html_type' => 'text', | |
69 | 'title' => ts('Due Date'), | |
70 | 'weight' => 3, | |
71 | ), | |
72 | 'due_date_period' => array( | |
73 | 'html_type' => 'select', | |
74 | 'title' => ts('For transmission'), | |
75 | 'weight' => 4, | |
76 | 'description' => ts('Select the interval for due date.'), | |
77 | 'option_values' => array( | |
78 | 'select' => ts('- select -'), | |
79 | 'days' => ts('Days'), | |
80 | 'months' => ts('Months'), | |
81 | 'years' => ts('Years'), | |
9d72cede | 82 | ), |
353ffa53 TO |
83 | ), |
84 | 'notes' => array( | |
85 | 'html_type' => 'wysiwyg', | |
86 | 'title' => ts('Notes or Standard Terms'), | |
87 | 'weight' => 5, | |
88 | 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), | |
89 | 'attributes' => array('rows' => 2, 'cols' => 40), | |
90 | ), | |
91 | 'is_email_pdf' => array( | |
92 | 'html_type' => 'checkbox', | |
93 | 'title' => ts('Automatically email invoice when user purchases online'), | |
94 | 'weight' => 6, | |
95 | ), | |
96 | 'tax_term' => array( | |
97 | 'html_type' => 'text', | |
98 | 'title' => ts('Tax Term'), | |
99 | 'weight' => 7, | |
100 | ), | |
101 | 'tax_display_settings' => array( | |
102 | 'html_type' => 'select', | |
103 | 'title' => ts('Tax Display Settings'), | |
104 | 'weight' => 8, | |
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]'), | |
fff0f449 | 115 | ), |
116 | ), | |
353ffa53 | 117 | ), |
fff0f449 | 118 | ); |
9d4da082 RK |
119 | parent::preProcess(); |
120 | } | |
d75f2f47 | 121 | |
9d4da082 | 122 | /** |
eceb18cc | 123 | * Build the form object. |
9d4da082 RK |
124 | * |
125 | * @return void | |
9d4da082 | 126 | */ |
00be9182 | 127 | public function buildQuickForm() { |
e0d19757 WA |
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') { | |
135 | $this->$add( | |
136 | $props['html_type'], | |
137 | $setting, | |
138 | ts($props['title']), | |
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 | |
141 | ); | |
142 | } | |
143 | else { | |
144 | $this->$add($setting, ts($props['title'])); | |
145 | } | |
146 | } | |
147 | $this->assign("{$setting}_description", ts($props['description'])); | |
148 | } | |
e0d683cf | 149 | $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing')); |
9d4da082 RK |
150 | parent::buildQuickForm(); |
151 | } | |
1be9403d | 152 | |
153 | /** | |
c490a46a | 154 | * Set default values for the form. |
1be9403d | 155 | * default values are retrieved from the database |
156 | * | |
1be9403d | 157 | * |
158 | * @return void | |
159 | */ | |
00be9182 | 160 | public function setDefaultValues() { |
9d72cede | 161 | $defaults = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
e0d19757 WA |
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', | |
166 | array( | |
167 | 'name' => $setting, | |
168 | 'group' => $group, | |
169 | 'default_value' => CRM_Utils_Array::value('default', $settingMetaData['values'][$setting]), | |
170 | ) | |
171 | ); | |
172 | } | |
1be9403d | 173 | return $defaults; |
174 | } | |
175 | ||
176 | /** | |
eceb18cc | 177 | * Process the form after the input has been submitted and validated. |
1be9403d | 178 | * |
1be9403d | 179 | * |
180 | * @return void | |
181 | */ | |
182 | public function postProcess() { | |
183 | // store the submitted values in an array | |
184 | $params = $this->controller->exportValues($this->_name); | |
fff0f449 | 185 | unset($params['qfKey']); |
186 | unset($params['entryURL']); | |
1be9403d | 187 | $setInvoiceSettings = CRM_Core_BAO_Setting::setItem($params, CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
e0d683cf PB |
188 | |
189 | // to set default value for 'Invoices / Credit Notes' checkbox on display preferences | |
190 | $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences"); | |
9148c277 | 191 | $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name'); |
e0d683cf PB |
192 | $setKey = array_search('Invoices / Credit Notes', $optionValues); |
193 | ||
194 | if (isset($params['invoicing'])) { | |
195 | $value = array($setKey => $optionValues[$setKey]); | |
9d72cede EM |
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'); | |
e0d683cf PB |
201 | } |
202 | else { | |
203 | $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1)); | |
9d72cede | 204 | $invoiceKey = array_search($setKey, $setting); |
e0d683cf | 205 | unset($setting[$invoiceKey]); |
9d72cede EM |
206 | $settingName = CRM_Core_DAO::VALUE_SEPARATOR . |
207 | implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) . | |
208 | CRM_Core_DAO::VALUE_SEPARATOR; | |
e0d683cf PB |
209 | CRM_Core_BAO_Setting::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options'); |
210 | } | |
e0d19757 WA |
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); | |
74a7714e | 214 | CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success"); |
1be9403d | 215 | } |
96025800 | 216 | |
9d4da082 | 217 | } |