/
StaffWidget.php
395 lines (327 loc) · 9.54 KB
/
StaffWidget.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/**
* Staff Widget interface and individual Widget classes
*
* @since 8.6
*
* @package RosarioSIS
* @subpackage classes/core
*/
namespace RosarioSIS;
// StaffWidget interface.
// Implement this interface when creating a new StaffWidget.
interface StaffWidget
{
/**
* Check whether StaffWidget can be built:
* Usually check if the corresponding Module is active
* Maybe check if User is admin
* Maybe check if AllowUse() for corresponding modname
*
* @param array $modules $RosarioModules global.
*
* @return bool True if can build StaffWidget, else false.
*/
public function canBuild( $modules );
/**
* Build extra SQL, and search terms
*
* @param array $extra Extra array, see definition in Widgets class.
*
* @return array $extra array with StaffWidget extra added.
*/
public function extra( $extra );
/**
* Build HTML form
*
* @return string HTML form.
*/
public function html();
}
// Permissions Widget.
class StaffWidget_permissions implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Users'];
}
function extra( $extra )
{
if ( empty( $_REQUEST['permissions'] ) )
{
return $extra;
}
$extra['WHERE'] .= " AND s.PROFILE_ID IS " . ( $_REQUEST['permissions'] == 'Y' ? 'NOT' : '' ) . " NULL
AND s.PROFILE!='none'";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Permissions' ) . ': </b>' .
( $_REQUEST['permissions'] == 'Y' ? _( 'Profile' ) : _( 'Custom' ) ) . '<br />';
}
return $extra;
}
function html( $value = '' )
{
return '<tr class="st"><td>' . _( 'Permissions' ) . '</td><td>
<label><input type="radio" name="permissions" value=""' . ( empty( $value ) ? ' checked' : '' ) . '> ' .
_( 'All' ) . '</label>
<label><input type="radio" name="permissions" value="Y"' . ( $value == 'Y' ? ' checked' : '' ) . '> ' .
_( 'Profile' ) . '</label>
<label><input type="radio" name="permissions" value="N"' . ( $value == 'N' ? ' checked' : '' ) . '> ' .
_( 'Custom' ) . '</label>
</td></tr>';
}
}
// Permissions Yes Widget.
class StaffWidget_permissions_Y extends StaffWidget_permissions
{
function html( $value = 'Y' )
{
return parent::html( $value );
}
}
// Permissions No Widget.
class StaffWidget_permissions_N extends StaffWidget_permissions
{
function html( $value = 'N' )
{
return parent::html( $value );
}
}
// Food Service Balance Widget
class StaffWidget_fsa_balance implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Food_Service'];
}
function extra( $extra )
{
if ( ! isset( $_REQUEST['fsa_balance'] )
|| ! is_numeric( $_REQUEST['fsa_balance'] ) )
{
return $extra;
}
if ( ! mb_strpos( $extra['FROM'], 'fssa' ) )
{
$extra['FROM'] .= ',FOOD_SERVICE_STAFF_ACCOUNTS fssa';
$extra['WHERE'] .= ' AND fssa.STAFF_ID=s.STAFF_ID';
}
$extra['WHERE'] .= " AND fssa.BALANCE" . ( ! empty( $_REQUEST['fsa_bal_ge'] ) ? '>=' : '<' ) .
"'" . round( $_REQUEST['fsa_balance'], 2 ) . "'";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Food Service Balance' ) . ' </b>
<span class="sizep2">' . ( ! empty( $_REQUEST['fsa_bal_ge'] ) ? '≥' : '<' ) . '</span>' .
number_format( $_REQUEST['fsa_balance'], 2, '.', '' ) . '<br />';
}
return $extra;
}
function html( $value = '' )
{
return '<tr class="st"><td><label for="fsa_balance">' . _( 'Balance' ) . '</label></td><td>
<label class="sizep2">
<input type="radio" name="fsa_bal_ge" value="" checked /> <</label>
<label class="sizep2">
<input type="radio" name="fsa_bal_ge" value="Y" /> ≥</label>
<input name="fsa_balance" id="fsa_balance" type="number" step="0.01"' .
( $value ? ' value="' . AttrEscape( $value ) . '"' : '') . ' min="-999999999999999" max="999999999999999" />
</td></tr>';
}
}
// Food Service Balance Warning Widget
class StaffWidget_fsa_balance_warning extends StaffWidget_fsa_balance
{
function html( $value = '' )
{
$value = $GLOBALS['warning'];
return parent::html( $value );
}
}
// Food Service Account Status Widget
class StaffWidget_fsa_status implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Food_Service'];
}
function extra( $extra )
{
if ( empty( $_REQUEST['fsa_status'] ) )
{
return $extra;
}
if ( ! mb_strpos( $extra['FROM'], 'fssa' ) )
{
$extra['FROM'] .= ',FOOD_SERVICE_STAFF_ACCOUNTS fssa';
$extra['WHERE'] .= ' AND fssa.STAFF_ID=s.STAFF_ID';
}
if ( $_REQUEST['fsa_status'] == 'Active' )
{
$extra['WHERE'] .= ' AND fssa.STATUS IS NULL';
}
else
$extra['WHERE'] .= " AND fssa.STATUS='" . $_REQUEST['fsa_status'] . "'";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Food Service Status' ) . ': </b>' .
$_REQUEST['fsa_status'] . '<br />';
}
return $extra;
}
function html( $value = '' )
{
return '<tr class="st"><td><label for="fsa_status">' . _( 'Account Status' ) . '</label></td><td>
<select name="fsa_status" id="fsa_status">
<option value="">' . _( 'Not Specified' ) . '</option>
<option value="Active"' . ( $value == 'active' ? ' selected' : '' ) . '>' . _( 'Active' ) . '</option>
<option value="Inactive">' . _( 'Inactive' ) . '</option>
<option value="Disabled">' . _( 'Disabled' ) . '</option>
<option value="Closed">' . _( 'Closed' ) . '</option>
</select>
</td></tr>';
}
}
// Food Service Active Account Status Widget
class StaffWidget_fsa_status_active extends StaffWidget_fsa_status
{
function html( $value = 'active' )
{
return parent::html( $value );
}
}
// Food Service Barcode Widget
class StaffWidget_fsa_barcode implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Food_Service'];
}
function extra( $extra )
{
if ( empty( $_REQUEST['fsa_barcode'] ) )
{
return $extra;
}
if ( ! mb_strpos( $extra['FROM'], 'fssa' ) )
{
$extra['FROM'] .= ',FOOD_SERVICE_STAFF_ACCOUNTS fssa';
$extra['WHERE'] .= ' AND fssa.STAFF_ID=s.STAFF_ID';
}
$extra['WHERE'] .= " AND fssa.BARCODE='" . $_REQUEST['fsa_barcode'] . "'";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Food Service Barcode' ) . ': </b>' .
$_REQUEST['fsa_barcode'] . '<br />';
}
return $extra;
}
function html()
{
return '<tr class="st"><td><label for="fsa_barcode">' . _( 'Barcode' ) .
'</label></td><td>
<input type="text" name="fsa_barcode" id="fsa_barcode" size="15" maxlength="50" />
</td></tr>';
}
}
// Food Service Account Exists Widget
class StaffWidget_fsa_exists implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Food_Service'];
}
function extra( $extra )
{
if ( empty( $_REQUEST['fsa_exists'] ) )
{
return $extra;
}
$extra['WHERE'] .= ' AND ' . ( $_REQUEST['fsa_exists'] == 'N' ? 'NOT ' : '' ) . "EXISTS
(SELECT 'exists'
FROM FOOD_SERVICE_STAFF_ACCOUNTS
WHERE STAFF_ID=s.STAFF_ID)";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Food Service Account Exists' ) . ': </b>' .
( $_REQUEST['fsa_exists'] == 'Y' ? _( 'Yes' ) : _( 'No' ) ) . '<br />';
}
return $extra;
}
function html( $value = '' )
{
return '<tr class="st"><td>' . _( 'Has Account' ) . '</td><td>
<label><input type="radio" name="fsa_exists" value=""' . ( empty( $value ) ? ' checked' : '' ) . ' /> ' .
_( 'All') . '</label>
<label><input type="radio" name="fsa_exists" value="Y"' . ( $value == 'Y' ? ' checked' : '' ).' /> '.
_( 'Yes' ) . '</label>
<label><input type="radio" name="fsa_exists" value="N"' . ( $value == 'N' ? ' checked' : '' ) . ' /> '.
_( 'No' ) . '</label>
</td></tr>';
}
}
// Food Service Account Exists No Widget
class StaffWidget_fsa_exists_N extends StaffWidget_fsa_exists
{
function html( $value = 'N' )
{
return parent::html( $value );
}
}
// Food Service Account Exists Yes Widget
class StaffWidget_fsa_exists_Y extends StaffWidget_fsa_exists
{
function html( $value = 'Y' )
{
return parent::html( $value );
}
}
// Staff Payroll Balance Widget
class StaffWidget_staff_balance implements StaffWidget
{
function canBuild( $modules )
{
return $modules['Accounting'] && AllowUse( 'Accounting/StaffBalances.php' );
}
function extra( $extra )
{
if ( ! isset( $_REQUEST['balance_low'] )
|| ! is_numeric( $_REQUEST['balance_low'] )
|| ! isset( $_REQUEST['balance_high'] )
|| ! is_numeric( $_REQUEST['balance_high'] ) )
{
return $extra;
}
if ( $_REQUEST['balance_low'] > $_REQUEST['balance_high'] )
{
$temp = $_REQUEST['balance_high'];
$_REQUEST['balance_high'] = $_REQUEST['balance_low'];
$_REQUEST['balance_low'] = $temp;
}
$extra['WHERE'] .= " AND (coalesce((SELECT sum(p.AMOUNT)
FROM ACCOUNTING_PAYMENTS p
WHERE p.STAFF_ID=s.STAFF_ID
AND p.SYEAR=s.SYEAR),0)
-coalesce((SELECT sum(f.AMOUNT)
FROM ACCOUNTING_SALARIES f
WHERE f.STAFF_ID=s.STAFF_ID
AND f.SYEAR=s.SYEAR),0))
BETWEEN '" . $_REQUEST['balance_low'] . "'
AND '" . $_REQUEST['balance_high'] . "' ";
if ( ! $extra['NoSearchTerms'] )
{
$extra['SearchTerms'] .= '<b>' . _( 'Staff Payroll Balance' ) . ': </b>' .
_( 'Between' ) . ' ' . $_REQUEST['balance_low'] .
' & ' . $_REQUEST['balance_high'] . '<br />';
}
return $extra;
}
function html()
{
return '<tr class="st"><td>' . _( 'Staff Payroll Balance' ) . '</td><td><label>' .
_( 'Between' ) .
' <input type="number" name="balance_low" step="0.01" min="-999999999999999" max="999999999999999" /></label> <label>&
<input type="number" name="balance_high" step="0.01" min="-999999999999999" max="999999999999999" /></label>
</td></tr>';
}
}