Commit | Line | Data |
---|---|---|
d75f2f47 | 1 | <?php |
c73475ea WA |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
c73475ea | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
c73475ea WA |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
c73475ea | 16 | */ |
9d4da082 RK |
17 | |
18 | /** | |
ce064e4f | 19 | * This class generates form components for the display preferences. |
9d4da082 RK |
20 | */ |
21 | class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { | |
ce064e4f | 22 | |
1be9403d | 23 | /** |
2f6c641a | 24 | * Our standards for settings are to have a setting per value with defined metadata. |
25 | * | |
26 | * Unfortunately the 'contribution_invoice_settings' has been added in non-compliance. | |
27 | * We use this array to hack-handle. | |
28 | * | |
71bbdae1 | 29 | * These are now stored as individual settings but this form still does weird & wonderful things. |
30 | * | |
31 | * Note the 'real' settings on this form are added via metadata definition - ie | |
32 | * 'settings_pages' => ['contribute' => ['weight' => 1]], in their metadata. | |
2f6c641a | 33 | * |
34 | * @var array | |
1be9403d | 35 | */ |
2f6c641a | 36 | protected $invoiceSettings = []; |
d75f2f47 | 37 | |
9d4da082 | 38 | /** |
eceb18cc | 39 | * Build the form object. |
71bbdae1 | 40 | * |
41 | * @throws \CiviCRM_API3_Exception | |
42 | * @throws \CRM_Core_Exception | |
9d4da082 | 43 | */ |
00be9182 | 44 | public function buildQuickForm() { |
2f6c641a | 45 | parent::buildQuickForm(); |
2f6c641a | 46 | $this->invoiceSettings = [ |
47 | 'invoice_prefix' => [ | |
48 | 'html_type' => 'text', | |
49 | 'title' => ts('Invoice Prefix'), | |
50 | 'weight' => 1, | |
51 | 'description' => ts('Enter prefix to be display on PDF for invoice'), | |
52 | ], | |
2f6c641a | 53 | 'due_date' => [ |
54 | 'html_type' => 'text', | |
55 | 'title' => ts('Due Date'), | |
56 | 'weight' => 3, | |
b0464b2f | 57 | 'description' => '', |
2f6c641a | 58 | ], |
59 | 'due_date_period' => [ | |
60 | 'html_type' => 'select', | |
61 | 'title' => ts('For transmission'), | |
62 | 'weight' => 4, | |
63 | 'description' => ts('Select the interval for due date.'), | |
64 | 'option_values' => [ | |
65 | 'select' => ts('- select -'), | |
66 | 'days' => ts('Days'), | |
67 | 'months' => ts('Months'), | |
68 | 'years' => ts('Years'), | |
69 | ], | |
70 | ], | |
71 | 'notes' => [ | |
72 | 'html_type' => 'wysiwyg', | |
73 | 'title' => ts('Notes or Standard Terms'), | |
74 | 'weight' => 5, | |
75 | 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '), | |
76 | 'attributes' => ['rows' => 2, 'cols' => 40], | |
77 | ], | |
78 | 'is_email_pdf' => [ | |
79 | 'html_type' => 'checkbox', | |
80 | 'title' => ts('Automatically email invoice when user purchases online'), | |
81 | 'weight' => 6, | |
82 | 'description' => ts('Should a pdf invoice be emailed automatically?'), | |
83 | ], | |
84 | 'tax_term' => [ | |
85 | 'html_type' => 'text', | |
86 | 'title' => ts('Tax Term'), | |
87 | 'weight' => 7, | |
b0464b2f | 88 | 'description' => '', |
2f6c641a | 89 | ], |
90 | 'tax_display_settings' => [ | |
91 | 'html_type' => 'select', | |
92 | 'title' => ts('Tax Display Settings'), | |
93 | 'weight' => 8, | |
b0464b2f | 94 | 'description' => '', |
2f6c641a | 95 | 'option_values' => [ |
6dabf459 ML |
96 | 'Do_not_show' => ts('Do not show breakdown, only show total - i.e %1', [ |
97 | 1 => CRM_Utils_Money::format(120), | |
98 | ]), | |
99 | 'Inclusive' => ts('Show [tax term] inclusive price - i.e. %1', [ | |
100 | 1 => ts('%1 (includes [tax term] of %2)', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), | |
101 | ]), | |
102 | 'Exclusive' => ts('Show [tax term] exclusive price - i.e. %1', [ | |
103 | 1 => ts('%1 + %2 [tax term]', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), | |
104 | ]), | |
2f6c641a | 105 | ], |
106 | ], | |
107 | ]; | |
108 | ||
109 | // @todo this is a faux metadata approach - we should be honest & add them correctly or find a way to make this | |
110 | // compatible with our settings standards. | |
111 | foreach ($this->invoiceSettings as $fieldName => $fieldValue) { | |
112 | switch ($fieldValue['html_type']) { | |
113 | case 'text': | |
114 | $this->addElement('text', | |
115 | $fieldName, | |
116 | $fieldValue['title'], | |
117 | [ | |
118 | 'maxlength' => 64, | |
119 | 'size' => 32, | |
120 | ] | |
121 | ); | |
122 | break; | |
123 | ||
124 | case 'checkbox': | |
125 | $this->add($fieldValue['html_type'], | |
126 | $fieldName, | |
127 | $fieldValue['title'] | |
128 | ); | |
129 | break; | |
130 | ||
131 | case 'select': | |
132 | $this->addElement('select', | |
133 | $fieldName, | |
134 | $fieldValue['title'], | |
135 | $fieldValue['option_values'], | |
136 | CRM_Utils_Array::value('attributes', $fieldValue) | |
137 | ); | |
138 | break; | |
139 | ||
140 | case 'wysiwyg': | |
141 | $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']); | |
142 | break; | |
e0d19757 | 143 | } |
e0d19757 | 144 | } |
2f6c641a | 145 | |
146 | $this->assign('htmlFields', $this->invoiceSettings); | |
9d4da082 | 147 | } |
1be9403d | 148 | |
149 | /** | |
c490a46a | 150 | * Set default values for the form. |
1be9403d | 151 | * |
ce064e4f | 152 | * default values are retrieved from the database |
1be9403d | 153 | */ |
00be9182 | 154 | public function setDefaultValues() { |
2f6c641a | 155 | $defaults = parent::setDefaultValues(); |
156 | $defaults = array_merge($defaults, Civi::settings()->get('contribution_invoice_settings')); | |
1be9403d | 157 | return $defaults; |
158 | } | |
159 | ||
160 | /** | |
eceb18cc | 161 | * Process the form after the input has been submitted and validated. |
1be9403d | 162 | */ |
163 | public function postProcess() { | |
164 | // store the submitted values in an array | |
165 | $params = $this->controller->exportValues($this->_name); | |
2f6c641a | 166 | $invoiceParams = array_intersect_key($params, $this->invoiceSettings); |
47279db3 | 167 | // This is a hack - invoicing is it's own setting but it is being used from invoice params |
168 | // too. This means that saving from api will not have the desired core effect. | |
169 | // but we should fix that elsewhere - ie. stop abusing the settings | |
170 | // and fix the code repetition associated with invoicing | |
171 | $invoiceParams['invoicing'] = CRM_Utils_Array::value('invoicing', $params, 0); | |
2f6c641a | 172 | Civi::settings()->set('contribution_invoice_settings', $invoiceParams); |
173 | parent::postProcess(); | |
1be9403d | 174 | } |
96025800 | 175 | |
9d4da082 | 176 | } |