Commit | Line | Data |
---|---|---|
d75f2f47 | 1 | <?php |
c73475ea WA |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
c73475ea | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
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 { | |
be2fb01f | 38 | protected $_settings = [ |
e0d19757 | 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, |
be2fb01f | 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' => [ | |
6dabf459 ML |
119 | 'Do_not_show' => ts('Do not show breakdown, only show total - i.e %1', [ |
120 | 1 => CRM_Utils_Money::format(120), | |
121 | ]), | |
122 | 'Inclusive' => ts('Show [tax term] inclusive price - i.e. %1', [ | |
123 | 1 => ts('%1 (includes [tax term] of %2)', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), | |
124 | ]), | |
125 | 'Exclusive' => ts('Show [tax term] exclusive price - i.e. %1', [ | |
126 | 1 => ts('%1 + %2 [tax term]', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), | |
127 | ]), | |
2f6c641a | 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); |
47279db3 | 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); | |
2f6c641a | 195 | Civi::settings()->set('contribution_invoice_settings', $invoiceParams); |
196 | parent::postProcess(); | |
1be9403d | 197 | } |
96025800 | 198 | |
9d4da082 | 199 | } |