forked from Wunderbyte-GmbH/moodle-local_shopping_cart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
198 lines (176 loc) · 7.37 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* Plugin administration pages are defined here.
*
* @package local_shopping_cart
* @category admin
* @copyright 2021 Wunderbyte GmbH<[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_shopping_cart\admin_setting_taxcategories;
defined('MOODLE_INTERNAL') || die();
$componentname = 'local_shopping_cart';
// Default for users that have site config.
if ($hassiteconfig) {
// Add the category to the local plugin branch.
$settings = new admin_settingpage('local_shopping_cart_settings', '');
$ADMIN->add('localplugins', new admin_category($componentname, get_string('pluginname', $componentname)));
$ADMIN->add($componentname, $settings);
$paymentaccountrecords = $DB->get_records_sql("
SELECT id, name
FROM {payment_accounts}
WHERE enabled = 1");
$paymentaccounts = [];
foreach ($paymentaccountrecords as $paymentaccountrecord) {
$paymentaccounts[$paymentaccountrecord->id] = $paymentaccountrecord->name;
}
if (empty($paymentaccounts)) {
$moodleurl = new moodle_url('/payment/accounts.php');
$urlobject = new stdClass;
$urlobject->link = $moodleurl->out(false);
// If we have no payment accounts then show a static text instead.
$settings->add(new admin_setting_description(
'nopaymentaccounts',
get_string('nopaymentaccounts', 'local_shopping_cart'),
get_string('nopaymentaccountsdesc', 'local_shopping_cart', $urlobject)
));
} else {
// Connect payment account.
$settings->add(
new admin_setting_configselect(
$componentname . '/accountid',
get_string('accountid', $componentname),
get_string('accountid:description', $componentname),
null,
$paymentaccounts
)
);
}
// Max items in cart.
$settings->add(
new admin_setting_configtext(
$componentname . '/maxitems',
get_string('maxitems', $componentname),
get_string('maxitems:description', $componentname),
10,
PARAM_INT
)
);
// Item expiriation time in minutes.
$settings->add(
new admin_setting_configtext(
$componentname . '/expirationtime',
get_string('expirationtime', $componentname),
get_string('expirationtime:description', $componentname),
15,
PARAM_INT
)
);
$settings->add(
new admin_setting_configtext(
$componentname . '/expirationtime',
get_string('expirationtime', $componentname),
get_string('expirationtime:description', $componentname),
15,
PARAM_INT
)
);
$settings->add(
new admin_setting_configtext(
$componentname . '/cancelationfee',
get_string('cancelationfee', $componentname),
get_string('cancelationfee:description', $componentname),
-1,
PARAM_FLOAT
)
);
// Setting to round percentage discounts to full integers.
$settings->add(
new admin_setting_configcheckbox($componentname . '/rounddiscounts',
get_string('rounddiscounts', 'local_shopping_cart'),
get_string('rounddiscounts_desc', 'local_shopping_cart'), 1));
$settings->add(
new admin_setting_confightmleditor(
$componentname . '/additonalcashiersection',
get_string('additonalcashiersection', $componentname),
get_string('additonalcashiersection:description', $componentname),
'..',
PARAM_RAW
)
);
$settings->add(
new admin_setting_configtextarea(
$componentname . '/receipthtml',
get_string('receipthtml', $componentname),
get_string('receipthtml:description', $componentname),
'..',
PARAM_RAW
)
);
$fileid = 'local_shopping_cart_receiptimage';
$name = 'local_shopping_cart/receiptimage';
$title = get_string('receiptimage', 'local_shopping_cart');
$description = get_string('receiptimage:description', 'local_shopping_cart');
$opts = array('accepted_types' => array('.png', '.jpg'), 'maxfiles' => 1);
$setting = new admin_setting_configstoredfile($name, $title, $description, $fileid, 0, $opts);
$settings->add($setting);
// Setting to enable taxes processing
$taxsettings = new admin_settingpage('local_shopping_cart_tax_settings', get_string('taxsettings', 'local_shopping_cart'));
$taxsettings->add(
new admin_setting_configcheckbox($componentname . '/enabletax',
get_string('enabletax', 'local_shopping_cart'),
get_string('enabletax_desc', 'local_shopping_cart'), 0));
$taxProcessingEnabled = get_config('local_shopping_cart', 'enabletax') == 1;
if ($taxProcessingEnabled) {
$taxcategoriesexample = '
<a data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
' . get_string('taxcategories_examples_button', $componentname) . '
</a>
<div class="collapse mb-5" id="collapseExample">
<div class="card card-body">
Multi country multi tax categories:
<pre class="mb-1 p-1">default A:0 B:0 C:0
At A:20 B:10 C:0
De A:19 B:10 C:0</pre><hr/>
Multi tax categories, no countries:
<pre class="mb-1 p-1">A:30 B:0</pre><hr/>
Just one default tax:
<pre class="mb-1 p-1">20</pre>
</div>
</div>
';
$taxsettings->add(
new admin_setting_taxcategories(
$componentname . '/taxcategories',
get_string('taxcategories', $componentname),
get_string('taxcategories_desc', $componentname) . $taxcategoriesexample,
'',
PARAM_TEXT
)
);
$taxsettings->add(
new admin_setting_configtext(
$componentname . '/defaulttaxcategory',
get_string('defaulttaxcategory', $componentname),
get_string('defaulttaxcategory_desc', $componentname),
"",
PARAM_TEXT
)
);
}
$ADMIN->add($componentname, $taxsettings);
}