forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PcTabs.php
473 lines (471 loc) · 18.5 KB
/
PcTabs.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
include('includes/session.php');
$Title = _('Maintenance Of Petty Cash Tabs');
/* webERP manual links before header.php */
$ViewTopic = 'PettyCash';
$BookMark = 'PCTabSetup';
include('includes/header.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/money_add.png" title="', _('Payment Entry'), '" alt="" />', ' ', $Title, '
</p>';
if (isset($_POST['SelectedTab'])) {
$SelectedTab = mb_strtoupper($_POST['SelectedTab']);
} elseif (isset($_GET['SelectedTab'])) {
$SelectedTab = mb_strtoupper($_GET['SelectedTab']);
}
if (isset($_POST['Cancel'])) {
unset($SelectedTab);
unset($_POST['TabCode']);
unset($_POST['SelectUser']);
unset($_POST['SelectTabs']);
unset($_POST['SelectCurrency']);
unset($_POST['TabLimit']);
unset($_POST['SelectAssigner']);
unset($_POST['SelectAuthoriserCash']);
unset($_POST['SelectAuthoriserExpenses']);
unset($_POST['GLAccountCash']);
unset($_POST['GLAccountPcashTab']);
}
if (isset($_POST['Submit'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
//first off validate inputs sensible
if ($_POST['TabCode'] == '' or $_POST['TabCode'] == ' ' or $_POST['TabCode'] == ' ') {
$InputError = 1;
prnMsg('<br />' . _('The Tab code cannot be an empty string or spaces'), 'error');
} elseif (mb_strlen($_POST['TabCode']) > 20) {
$InputError = 1;
echo prnMsg(_('The Tab code must be twenty characters or less long'), 'error');
} elseif (($_POST['SelectUser']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a User for this tab'), 'error');
} elseif (($_POST['SelectTabs']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a type of tab from the list'), 'error');
} elseif (($_POST['SelectAssigner']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a User to assign cash to this tab'), 'error');
} elseif (($_POST['SelectAuthoriserCash']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a User to authorise this tab'), 'error');
} elseif (($_POST['GLAccountCash']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a General ledger code for the cash to be assigned from'), 'error');
} elseif (($_POST['GLAccountPcashTab']) == '') {
$InputError = 1;
echo prnMsg(_('You must select a General ledger code for this petty cash tab'), 'error');
} elseif (($_POST['TaxGroup']) === '0') {
$InputError = 1;
echo prnMsg(_('You must select a tax group'), 'error');
}
if (isset($SelectedTab) and $InputError != 1) {
$SQL = "UPDATE pctabs SET usercode = '" . $_POST['SelectUser'] . "',
typetabcode = '" . $_POST['SelectTabs'] . "',
currency = '" . $_POST['SelectCurrency'] . "',
tablimit = '" . filter_number_format($_POST['TabLimit']) . "',
assigner = '" . $_POST['SelectAssigner'] . "',
authorizer = '" . $_POST['SelectAuthoriserCash'] . "',
authorizerexpenses = '" . $_POST['SelectAuthoriserExpenses'] . "',
glaccountassignment = '" . $_POST['GLAccountCash'] . "',
glaccountpcash = '" . $_POST['GLAccountPcashTab'] . "',
defaulttag = '" . $_POST['DefaultTag'] . "',
taxgroupid='" . $_POST['TaxGroup'] . "'
WHERE tabcode = '" . $SelectedTab . "'";
$Msg = _('The Petty Cash Tab') . ' ' . $SelectedTab . ' ' . _('has been updated');
} elseif ($InputError != 1) {
// First check the type is not being duplicated
$CheckSQL = "SELECT count(*)
FROM pctabs
WHERE tabcode = '" . $_POST['TabCode'] . "'";
$CheckResult = DB_query($CheckSQL);
$CheckRow = DB_fetch_row($CheckResult);
if ($CheckRow[0] > 0) {
$InputError = 1;
prnMsg(_('The Tab ') . ' ' . $_POST['TabCode'] . ' ' . _(' already exists'), 'error');
} else {
// Add new record on submit
$SQL = "INSERT INTO pctabs (tabcode,
usercode,
typetabcode,
currency,
tablimit,
assigner,
authorizer,
authorizerexpenses,
glaccountassignment,
glaccountpcash,
defaulttag,
taxgroupid)
VALUES ('" . $_POST['TabCode'] . "',
'" . $_POST['SelectUser'] . "',
'" . $_POST['SelectTabs'] . "',
'" . $_POST['SelectCurrency'] . "',
'" . filter_number_format($_POST['TabLimit']) . "',
'" . $_POST['SelectAssigner'] . "',
'" . $_POST['SelectAuthoriserCash'] . "',
'" . $_POST['SelectAuthoriserExpenses'] . "',
'" . $_POST['GLAccountCash'] . "',
'" . $_POST['GLAccountPcashTab'] . "',
'" . $_POST['DefaultTag'] . "',
'" . $_POST['TaxGroup'] . "'
)";
$Msg = _('The Petty Cash Tab') . ' ' . $_POST['TabCode'] . ' ' . _('has been created');
}
}
if ($InputError != 1) {
//run the SQL from either of the above possibilites
$Result = DB_query($SQL);
prnMsg($Msg, 'success');
unset($SelectedTab);
unset($_POST['SelectUser']);
unset($_POST['TabCode']);
unset($_POST['SelectTabs']);
unset($_POST['SelectCurrency']);
unset($_POST['TabLimit']);
unset($_POST['SelectAssigner']);
unset($_POST['SelectAuthoriserCash']);
unset($_POST['GLAccountCash']);
unset($_POST['GLAccountPcashTab']);
unset($_POST['TaxGroup']);
}
} elseif (isset($_GET['delete'])) {
$SQL = "DELETE FROM pctabs WHERE tabcode='" . $SelectedTab . "'";
$ErrMsg = _('The Tab record could not be deleted because');
$Result = DB_query($SQL, $ErrMsg);
prnMsg(_('The Petty Cash Tab') . ' ' . $SelectedTab . ' ' . _('has been deleted'), 'success');
unset($SelectedTab);
unset($_GET['delete']);
}
if (!isset($SelectedTab)) {
/* It could still be the second time the page has been run and a record has been selected for modification - SelectedTab will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters
then none of the above are true and the list of sales types will be displayed with
links to delete or edit each. These will call the same page again and allow update/input
or deletion of the records*/
$SQL = "SELECT tabcode,
usercode,
typetabdescription,
currabrev,
tablimit,
assigner,
authorizer,
authorizerexpenses,
glaccountassignment,
glaccountpcash,
defaulttag,
currencies.decimalplaces,
chartmaster1.accountname AS glactassigntname,
chartmaster2.accountname AS glactpcashname,
taxgroupdescription
FROM pctabs
INNER JOIN currencies
ON pctabs.currency=currencies.currabrev
INNER JOIN pctypetabs
ON pctabs.typetabcode=pctypetabs.typetabcode
INNER JOIN chartmaster AS chartmaster1 ON
pctabs.glaccountassignment = chartmaster1.accountcode
INNER JOIN chartmaster AS chartmaster2 ON
pctabs.glaccountpcash = chartmaster2.accountcode
INNER JOIN taxgroups
ON pctabs.taxgroupid=taxgroups.taxgroupid
ORDER BY tabcode";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<table class="selection">
<tr>
<th>', _('Tab Code'), '</th>
<th>', _('User Name'), '</th>
<th>', _('Type Of Tab'), '</th>
<th>', _('Currency'), '</th>
<th>', _('Limit'), '</th>
<th>', _('Cash Assigner'), '</th>
<th>', _('Authoriser - Cash'), '</th>
<th>', _('Authoriser - Expenses'), '</th>
<th>', _('GL Account For Cash Assignment'), '</th>
<th>', _('GL Account Petty Cash Tab'), '</th>
<th>', _('Default Tag'), '</th>
<th>', _('Tax Group'), '</th>
</tr>';
while ($MyRow = DB_fetch_array($Result)) {
$TagSQL = "SELECT tagdescription FROM tags WHERE tagref='" . $MyRow['defaulttag'] . "'";
$TagResult = DB_query($TagSQL);
$TagRow = DB_fetch_array($TagResult);
echo '<tr class="striped_row">
<td>', $MyRow['tabcode'], '</td>
<td>', $MyRow['usercode'], '</td>
<td>', $MyRow['typetabdescription'], '</td>
<td>', $MyRow['currabrev'], '</td>
<td class="number">', locale_number_format($MyRow['tablimit'], $MyRow['decimalplaces']), '</td>
<td>', $MyRow['assigner'], '</td>
<td>', $MyRow['authorizer'], '</td>
<td>', $MyRow['authorizerexpenses'], '</td>
<td>', $MyRow['glaccountassignment'] . ' - ' . $MyRow['glactassigntname'], '</td>
<td>', $MyRow['glaccountpcash'] . ' - ' . $MyRow['glactpcashname'], '</td>
<td>', $TagRow['tagdescription'], '</td>
<td>', $MyRow['taxgroupdescription'], '</td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?SelectedTab=', $MyRow['tabcode'], '">' . _('Edit') . '</a></td>
<td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?SelectedTab=', $MyRow['tabcode'], '&delete=yes" onclick=\' return confirm("' . _('Are you sure you wish to delete this tab code?') . '", \'Confirm Delete\', this);\'>' . _('Delete') . '</a></td>
</tr>';
}
//END WHILE LIST LOOP
echo '</table>';
} //if there are tabs to show
}
//end of ifs and buts!
if (isset($SelectedTab)) {
echo '<div class="centre">
<a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">', _('Show All Tabs Defined'), '</a>
</div>';
}
if (!isset($_GET['delete'])) {
echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
if (isset($SelectedTab) and $SelectedTab != '') {
$SQL = "SELECT tabcode,
usercode,
typetabcode,
currency,
tablimit,
assigner,
authorizer,
authorizerexpenses,
glaccountassignment,
glaccountpcash,
defaulttag,
taxgroupid
FROM pctabs
WHERE tabcode='" . $SelectedTab . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['TabCode'] = $MyRow['tabcode'];
$_POST['SelectUser'] = $MyRow['usercode'];
$_POST['SelectTabs'] = $MyRow['typetabcode'];
$_POST['SelectCurrency'] = $MyRow['currency'];
$_POST['TabLimit'] = locale_number_format($MyRow['tablimit']);
$_POST['SelectAssigner'] = $MyRow['assigner'];
$_POST['SelectAuthoriserCash'] = $MyRow['authorizer'];
$_POST['SelectAuthoriserExpenses'] = $MyRow['authorizerexpenses'];
$_POST['GLAccountCash'] = $MyRow['glaccountassignment'];
$_POST['GLAccountPcashTab'] = $MyRow['glaccountpcash'];
$_POST['DefaultTag'] = $MyRow['defaulttag'];
$_POST['TaxGroup'] = $MyRow['taxgroupid'];
echo '<input type="hidden" name="SelectedTab" value="', $SelectedTab, '" />';
echo '<input type="hidden" name="TabCode" value="', $_POST['TabCode'], '" />';
echo '<table class="selection">
<tr>
<td>', _('Tab Code'), ':</td>
<td>', $_POST['TabCode'], '</td>
</tr>';
} else {
// This is a new type so the user may volunteer a type code
echo '<table class="selection">
<tr>
<td>', _('Tab Code'), ':</td>
<td><input type="text" required="required" maxlength="20" name="TabCode" /></td>
</tr>';
}
if (!isset($_POST['typetabdescription'])) {
$_POST['typetabdescription'] = '';
}
echo '<tr>
<td>', _('User Name'), ':</td>
<td><select required="required" name="SelectUser">';
$SQL = "SELECT userid,
realname
FROM www_users ORDER BY userid";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectUser']) and $MyRow['userid'] == $_POST['SelectUser']) {
echo '<option selected="selected" value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
} else {
echo '<option value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
}
} //end while loop get user
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('Type Of Tab'), ':</td>
<td><select required="required" name="SelectTabs">';
$SQL = "SELECT typetabcode,
typetabdescription
FROM pctypetabs
ORDER BY typetabcode";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectTabs']) and $MyRow['typetabcode'] == $_POST['SelectTabs']) {
echo '<option selected="selected" value="', $MyRow['typetabcode'], '">', $MyRow['typetabcode'], ' - ', $MyRow['typetabdescription'], '</option>';
} else {
echo '<option value="', $MyRow['typetabcode'], '">', $MyRow['typetabcode'], ' - ', $MyRow['typetabdescription'], '</option>';
}
} //end while loop get type of tab
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('Currency'), ':</td>
<td><select required="required" name="SelectCurrency">';
$SQL = "SELECT currency, currabrev FROM currencies";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectCurrency']) and $MyRow['currabrev'] == $_POST['SelectCurrency']) {
echo '<option selected="selected" value="', $MyRow['currabrev'], '">', $MyRow['currency'], '</option>';
} else {
echo '<option value="', $MyRow['currabrev'], '">', $MyRow['currency'], '</option>';
}
} //end while loop get type of tab
echo '</select>
</td>
</tr>';
if (!isset($_POST['TabLimit'])) {
$_POST['TabLimit'] = 0;
}
echo '<tr>
<td>', _('Limit Of Tab'), ':</td>
<td>
<input type="text" class="number" name="TabLimit" size="12" required="required" maxlength="11" value="', $_POST['TabLimit'], '" />
</td>
</tr>';
echo '<tr>
<td>', _('Cash Assigner'), ':</td>
<td><select required="required" name="SelectAssigner">';
$SQL = "SELECT userid,
realname
FROM www_users
ORDER BY userid";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectAssigner']) and $MyRow['userid'] == $_POST['SelectAssigner']) {
echo '<option selected="selected" value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
} else {
echo '<option value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
}
} //end while loop get assigner
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('Authoriser - Cash'), ':</td>
<td><select required="required" name="SelectAuthoriserCash">';
$SQL = "SELECT userid,
realname
FROM www_users
ORDER BY userid";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectAuthoriserCash']) and $MyRow['userid'] == $_POST['SelectAuthoriserCash']) {
echo '<option selected="selected" value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
} else {
echo '<option value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
}
} //end while loop get authoriser
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('Authoriser - Expenses'), ':</td>
<td><select required="required" name="SelectAuthoriserExpenses">';
$SQL = "SELECT userid,
realname
FROM www_users
ORDER BY userid";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectAuthoriserExpenses']) and $MyRow['userid'] == $_POST['SelectAuthoriserExpenses']) {
echo '<option selected="selected" value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
} else {
echo '<option value="', $MyRow['userid'], '">', $MyRow['userid'], ' - ', $MyRow['realname'], '</option>';
}
} //end while loop get authoriser
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('GL Account Cash Assignment'), ':</td>
<td><select required="required" name="GLAccountCash">';
$SQL = "SELECT chartmaster.accountcode,
chartmaster.accountname
FROM chartmaster
INNER JOIN bankaccounts
ON chartmaster.accountcode = bankaccounts.accountcode
ORDER BY chartmaster.accountcode";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['GLAccountCash']) and $MyRow['accountcode'] == $_POST['GLAccountCash']) {
echo '<option selected="selected" value="', $MyRow['accountcode'], '">', $MyRow['accountcode'], ' - ', htmlspecialchars($MyRow['accountname'], ENT_QUOTES, 'UTF-8', false), '</option>';
} else {
echo '<option value="', $MyRow['accountcode'], '">', $MyRow['accountcode'], ' - ', htmlspecialchars($MyRow['accountname'], ENT_QUOTES, 'UTF-8', false), '</option>';
}
} //end while loop
echo '</select>
</td>
</tr>';
echo '<tr>
<td>', _('GL Account Petty Cash Tab'), ':</td>
<td><select required="required" name="GLAccountPcashTab">';
$SQL = "SELECT accountcode,
accountname
FROM chartmaster
ORDER BY accountcode";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['GLAccountPcashTab']) and $MyRow['accountcode'] == $_POST['GLAccountPcashTab']) {
echo '<option selected="selected" value="', $MyRow['accountcode'], '">', $MyRow['accountcode'], ' - ', htmlspecialchars($MyRow['accountname'], ENT_QUOTES, 'UTF-8', false), '</option>';
} else {
echo '<option value="', $MyRow['accountcode'], '">', $MyRow['accountcode'], ' - ', htmlspecialchars($MyRow['accountname'], ENT_QUOTES, 'UTF-8', false), '</option>';
}
} //end while loop
echo '</select>
</td>
</tr>';
//Select the tag
$SQL = "SELECT tagref,
tagdescription
FROM tags
ORDER BY tagref";
$Result = DB_query($SQL);
echo '<tr>
<td>', _('Default Tag'), ':</td>
<td><select name="DefaultTag">';
echo '<option value="0">0 - ', _('None'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['DefaultTag']) and $_POST['DefaultTag'] == $MyRow['tagref']) {
echo '<option selected="selected" value="', $MyRow['tagref'], '">', $MyRow['tagref'], ' - ', $MyRow['tagdescription'], '</option>';
} else {
echo '<option value="', $MyRow['tagref'], '">', $MyRow['tagref'], ' - ', $MyRow['tagdescription'], '</option>';
}
}
echo '</select>
</td>
</tr>';
// End select tag
$SQL = "SELECT taxgroupid,
taxgroupdescription
FROM taxgroups
ORDER BY taxgroupdescription";
$Result = DB_query($SQL);
echo '<tr>
<td>', _('Tax Group'), ':</td>
<td><select name="TaxGroup">';
echo '<option value="0">0 - ', _('None'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['TaxGroup']) and $_POST['TaxGroup'] == $MyRow['taxgroupid']) {
echo '<option selected="selected" value="', $MyRow['taxgroupid'], '">', $MyRow['taxgroupid'], ' - ', $MyRow['taxgroupdescription'], '</option>';
} else {
echo '<option value="', $MyRow['taxgroupid'], '">', $MyRow['taxgroupid'], ' - ', $MyRow['taxgroupdescription'], '</option>';
}
}
echo '</select>
</td>
</tr>';
// End select tag
echo '</table>'; // close main table
echo '<div class="centre">
<input type="submit" name="Submit" value="', _('Accept'), '" />
<input type="submit" name="Cancel" value="', _('Cancel'), '" />
</div>';
echo '</form>';
} // end if user wish to delete
include('includes/footer.php');
?>