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 | /** |
2f6c641a | 49 | * Our standards for settings are to have a setting per value with defined metadata. |
50 | * | |
51 | * Unfortunately the 'contribution_invoice_settings' has been added in non-compliance. | |
52 | * We use this array to hack-handle. | |
53 | * | |
54 | * I think the best way forwards would be to covert to multiple individual settings. | |
55 | * | |
56 | * @var array | |
1be9403d | 57 | */ |
2f6c641a | 58 | protected $invoiceSettings = []; |
d75f2f47 | 59 | |
9d4da082 | 60 | /** |
eceb18cc | 61 | * Build the form object. |
9d4da082 | 62 | */ |
00be9182 | 63 | public function buildQuickForm() { |
2f6c641a | 64 | parent::buildQuickForm(); |
65 | $config = CRM_Core_Config::singleton(); | |
66 | $this->invoiceSettings = [ | |
67 | 'invoice_prefix' => [ | |
68 | 'html_type' => 'text', | |
69 | 'title' => ts('Invoice Prefix'), | |
70 | 'weight' => 1, | |
71 | 'description' => ts('Enter prefix to be display on PDF for invoice'), | |
72 | ], | |
73 | 'credit_notes_prefix' => [ | |
74 | 'html_type' => 'text', | |
75 | 'title' => ts('Credit Notes Prefix'), | |
76 | 'weight' => 2, | |
77 | 'description' => ts('Enter prefix to be display on PDF for credit notes.'), | |
78 | ], | |
79 | 'due_date' => [ | |
80 | 'html_type' => 'text', | |
81 | 'title' => ts('Due Date'), | |
82 | 'weight' => 3, | |
83 | ], | |
84 | 'due_date_period' => [ | |
85 | 'html_type' => 'select', | |
86 | 'title' => ts('For transmission'), | |
87 | 'weight' => 4, | |
88 | 'description' => ts('Select the interval for due date.'), | |
89 | 'option_values' => [ | |
90 | 'select' => ts('- select -'), | |
91 | 'days' => ts('Days'), | |
92 | 'months' => ts('Months'), | |
93 | 'years' => ts('Years'), | |
94 | ], | |
95 | ], | |
96 | 'notes' => [ | |
97 | 'html_type' => 'wysiwyg', | |
98 | 'title' => ts('Notes or Standard Terms'), | |
99 | 'weight' => 5, | |
100 | 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), | |
101 | 'attributes' => ['rows' => 2, 'cols' => 40], | |
102 | ], | |
103 | 'is_email_pdf' => [ | |
104 | 'html_type' => 'checkbox', | |
105 | 'title' => ts('Automatically email invoice when user purchases online'), | |
106 | 'weight' => 6, | |
107 | 'description' => ts('Should a pdf invoice be emailed automatically?'), | |
108 | ], | |
109 | 'tax_term' => [ | |
110 | 'html_type' => 'text', | |
111 | 'title' => ts('Tax Term'), | |
112 | 'weight' => 7, | |
113 | ], | |
114 | 'tax_display_settings' => [ | |
115 | 'html_type' => 'select', | |
116 | 'title' => ts('Tax Display Settings'), | |
117 | 'weight' => 8, | |
118 | 'option_values' => [ | |
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]'), | |
128 | ], | |
129 | ], | |
130 | ]; | |
131 | ||
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']) { | |
136 | case 'text': | |
137 | $this->addElement('text', | |
138 | $fieldName, | |
139 | $fieldValue['title'], | |
140 | [ | |
141 | 'maxlength' => 64, | |
142 | 'size' => 32, | |
143 | ] | |
144 | ); | |
145 | break; | |
146 | ||
147 | case 'checkbox': | |
148 | $this->add($fieldValue['html_type'], | |
149 | $fieldName, | |
150 | $fieldValue['title'] | |
151 | ); | |
152 | break; | |
153 | ||
154 | case 'select': | |
155 | $this->addElement('select', | |
156 | $fieldName, | |
157 | $fieldValue['title'], | |
158 | $fieldValue['option_values'], | |
159 | CRM_Utils_Array::value('attributes', $fieldValue) | |
160 | ); | |
161 | break; | |
162 | ||
163 | case 'wysiwyg': | |
164 | $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']); | |
165 | break; | |
e0d19757 | 166 | } |
e0d19757 | 167 | } |
2f6c641a | 168 | |
169 | $this->assign('htmlFields', $this->invoiceSettings); | |
9d4da082 | 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() { |
2f6c641a | 178 | $defaults = parent::setDefaultValues(); |
179 | $defaults = array_merge($defaults, Civi::settings()->get('contribution_invoice_settings')); | |
1be9403d | 180 | return $defaults; |
181 | } | |
182 | ||
183 | /** | |
eceb18cc | 184 | * Process the form after the input has been submitted and validated. |
1be9403d | 185 | */ |
186 | public function postProcess() { | |
187 | // store the submitted values in an array | |
188 | $params = $this->controller->exportValues($this->_name); | |
2f6c641a | 189 | $invoiceParams = array_intersect_key($params, $this->invoiceSettings); |
190 | Civi::settings()->set('contribution_invoice_settings', $invoiceParams); | |
191 | parent::postProcess(); | |
e0d683cf | 192 | |
2f6c641a | 193 | // @todo - all this should be handled by defining an on change action in the metadata. |
e0d683cf PB |
194 | // to set default value for 'Invoices / Credit Notes' checkbox on display preferences |
195 | $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences"); | |
9148c277 | 196 | $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name'); |
e0d683cf PB |
197 | $setKey = array_search('Invoices / Credit Notes', $optionValues); |
198 | ||
199 | if (isset($params['invoicing'])) { | |
200 | $value = array($setKey => $optionValues[$setKey]); | |
9d72cede EM |
201 | $setInvoice = CRM_Core_DAO::VALUE_SEPARATOR . |
202 | implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) . | |
203 | CRM_Core_DAO::VALUE_SEPARATOR; | |
08ef4ddd | 204 | Civi::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice); |
e0d683cf PB |
205 | } |
206 | else { | |
207 | $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1)); | |
9d72cede | 208 | $invoiceKey = array_search($setKey, $setting); |
3ff9e824 | 209 | if ($invoiceKey !== FALSE) { |
8077138d | 210 | unset($setting[$invoiceKey]); |
211 | } | |
9d72cede EM |
212 | $settingName = CRM_Core_DAO::VALUE_SEPARATOR . |
213 | implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) . | |
214 | CRM_Core_DAO::VALUE_SEPARATOR; | |
08ef4ddd | 215 | Civi::settings()->set('user_dashboard_options', $settingName); |
e0d683cf | 216 | } |
1be9403d | 217 | } |
96025800 | 218 | |
9d4da082 | 219 | } |