Commit | Line | Data |
---|---|---|
d75f2f47 | 1 | <?php |
c73475ea WA |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
c73475ea | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
c73475ea WA |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
c73475ea | 32 | */ |
9d4da082 RK |
33 | |
34 | /** | |
ce064e4f | 35 | * This class generates form components for the display preferences. |
9d4da082 RK |
36 | */ |
37 | class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { | |
e0d19757 WA |
38 | protected $_settings = array( |
39 | 'cvv_backoffice_required' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, | |
268a84f2 | 40 | 'update_contribution_on_membership_type_change' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
201b45e2 | 41 | 'acl_financial_type' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
4af9c91d | 42 | 'always_post_to_accounts_receivable' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
201b45e2 PN |
43 | 'deferred_revenue_enabled' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
44 | 'default_invoice_page' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, | |
201b45e2 | 45 | 'invoicing' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
e0d19757 | 46 | ); |
ce064e4f | 47 | |
1be9403d | 48 | /** |
eceb18cc | 49 | * Process the form submission. |
1be9403d | 50 | */ |
00be9182 | 51 | public function preProcess() { |
fff0f449 | 52 | $config = CRM_Core_Config::singleton(); |
9d4da082 RK |
53 | CRM_Utils_System::setTitle(ts('CiviContribute Component Settings')); |
54 | $this->_varNames = array( | |
9d72cede | 55 | CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array( |
353ffa53 TO |
56 | 'invoice_prefix' => array( |
57 | 'html_type' => 'text', | |
58 | 'title' => ts('Invoice Prefix'), | |
59 | 'weight' => 1, | |
60 | 'description' => ts('Enter prefix to be display on PDF for invoice'), | |
61 | ), | |
62 | 'credit_notes_prefix' => array( | |
63 | 'html_type' => 'text', | |
64 | 'title' => ts('Credit Notes Prefix'), | |
65 | 'weight' => 2, | |
66 | 'description' => ts('Enter prefix to be display on PDF for credit notes.'), | |
67 | ), | |
68 | 'due_date' => array( | |
69 | 'html_type' => 'text', | |
70 | 'title' => ts('Due Date'), | |
71 | 'weight' => 3, | |
72 | ), | |
73 | 'due_date_period' => array( | |
74 | 'html_type' => 'select', | |
75 | 'title' => ts('For transmission'), | |
76 | 'weight' => 4, | |
77 | 'description' => ts('Select the interval for due date.'), | |
78 | 'option_values' => array( | |
79 | 'select' => ts('- select -'), | |
80 | 'days' => ts('Days'), | |
81 | 'months' => ts('Months'), | |
82 | 'years' => ts('Years'), | |
9d72cede | 83 | ), |
353ffa53 TO |
84 | ), |
85 | 'notes' => array( | |
86 | 'html_type' => 'wysiwyg', | |
87 | 'title' => ts('Notes or Standard Terms'), | |
88 | 'weight' => 5, | |
89 | 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), | |
90 | 'attributes' => array('rows' => 2, 'cols' => 40), | |
91 | ), | |
92 | 'is_email_pdf' => array( | |
93 | 'html_type' => 'checkbox', | |
94 | 'title' => ts('Automatically email invoice when user purchases online'), | |
95 | 'weight' => 6, | |
96 | ), | |
97 | 'tax_term' => array( | |
98 | 'html_type' => 'text', | |
99 | 'title' => ts('Tax Term'), | |
100 | 'weight' => 7, | |
101 | ), | |
102 | 'tax_display_settings' => array( | |
103 | 'html_type' => 'select', | |
104 | 'title' => ts('Tax Display Settings'), | |
105 | 'weight' => 8, | |
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]'), | |
fff0f449 | 116 | ), |
117 | ), | |
353ffa53 | 118 | ), |
fff0f449 | 119 | ); |
9d4da082 RK |
120 | parent::preProcess(); |
121 | } | |
d75f2f47 | 122 | |
9d4da082 | 123 | /** |
eceb18cc | 124 | * Build the form object. |
9d4da082 | 125 | */ |
00be9182 | 126 | public function buildQuickForm() { |
201b45e2 | 127 | $htmlFields = array(); |
e0d19757 WA |
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') { | |
201b45e2 PN |
134 | if (in_array($props['html_type'], array('checkbox', 'textarea'))) { |
135 | $this->add($props['html_type'], | |
136 | $setting, | |
137 | $props['title'] | |
138 | ); | |
139 | } | |
140 | else { | |
141 | if ($props['html_type'] == 'select') { | |
142 | $functionName = CRM_Utils_Array::value('name', CRM_Utils_Array::value('pseudoconstant', $props)); | |
143 | if ($functionName) { | |
144 | $props['option_values'] = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::$functionName(); | |
145 | } | |
146 | } | |
147 | $this->$add( | |
148 | $props['html_type'], | |
149 | $setting, | |
150 | ts($props['title']), | |
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 | |
153 | ); | |
154 | } | |
155 | } | |
156 | elseif ($add == 'addMonthDay') { | |
157 | $this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d')); | |
158 | } | |
159 | elseif ($add == 'addDate') { | |
160 | $this->addDate($setting, ts($props['title']), FALSE, array('formatType' => $props['type'])); | |
e0d19757 WA |
161 | } |
162 | else { | |
163 | $this->$add($setting, ts($props['title'])); | |
164 | } | |
165 | } | |
201b45e2 | 166 | $htmlFields[$setting] = ts($props['description']); |
e0d19757 | 167 | } |
201b45e2 | 168 | $this->assign('htmlFields', $htmlFields); |
9d4da082 RK |
169 | parent::buildQuickForm(); |
170 | } | |
1be9403d | 171 | |
172 | /** | |
c490a46a | 173 | * Set default values for the form. |
1be9403d | 174 | * |
ce064e4f | 175 | * default values are retrieved from the database |
1be9403d | 176 | */ |
00be9182 | 177 | public function setDefaultValues() { |
aaffa79f | 178 | $defaults = Civi::settings()->get('contribution_invoice_settings'); |
e0d19757 | 179 | //CRM-16691: Changes made related to settings of 'CVV'. |
201b45e2 | 180 | foreach (array('cvv_backoffice_required') as $setting) { |
e0d19757 WA |
181 | $defaults[$setting] = civicrm_api3('setting', 'getvalue', |
182 | array( | |
183 | 'name' => $setting, | |
201b45e2 | 184 | 'group' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, |
e0d19757 WA |
185 | ) |
186 | ); | |
187 | } | |
1be9403d | 188 | return $defaults; |
189 | } | |
190 | ||
191 | /** | |
eceb18cc | 192 | * Process the form after the input has been submitted and validated. |
1be9403d | 193 | */ |
194 | public function postProcess() { | |
195 | // store the submitted values in an array | |
196 | $params = $this->controller->exportValues($this->_name); | |
fff0f449 | 197 | unset($params['qfKey']); |
198 | unset($params['entryURL']); | |
08ef4ddd | 199 | Civi::settings()->set('contribution_invoice_settings', $params); |
268a84f2 | 200 | Civi::settings()->set('update_contribution_on_membership_type_change', |
201 | CRM_Utils_Array::value('update_contribution_on_membership_type_change', $params) | |
202 | ); | |
e0d683cf PB |
203 | |
204 | // to set default value for 'Invoices / Credit Notes' checkbox on display preferences | |
205 | $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences"); | |
9148c277 | 206 | $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name'); |
e0d683cf PB |
207 | $setKey = array_search('Invoices / Credit Notes', $optionValues); |
208 | ||
209 | if (isset($params['invoicing'])) { | |
210 | $value = array($setKey => $optionValues[$setKey]); | |
9d72cede EM |
211 | $setInvoice = CRM_Core_DAO::VALUE_SEPARATOR . |
212 | implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) . | |
213 | CRM_Core_DAO::VALUE_SEPARATOR; | |
08ef4ddd | 214 | Civi::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice); |
e0d683cf PB |
215 | } |
216 | else { | |
217 | $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1)); | |
9d72cede | 218 | $invoiceKey = array_search($setKey, $setting); |
3ff9e824 | 219 | if ($invoiceKey !== FALSE) { |
8077138d | 220 | unset($setting[$invoiceKey]); |
221 | } | |
9d72cede EM |
222 | $settingName = CRM_Core_DAO::VALUE_SEPARATOR . |
223 | implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) . | |
224 | CRM_Core_DAO::VALUE_SEPARATOR; | |
08ef4ddd | 225 | Civi::settings()->set('user_dashboard_options', $settingName); |
e0d683cf | 226 | } |
e0d19757 | 227 | //CRM-16691: Changes made related to settings of 'CVV'. |
201b45e2 | 228 | $settings = array_intersect_key($params, array('cvv_backoffice_required' => 1)); |
e0d19757 | 229 | $result = civicrm_api3('setting', 'create', $settings); |
74a7714e | 230 | CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success"); |
1be9403d | 231 | } |
96025800 | 232 | |
9d4da082 | 233 | } |