/
recon_balance_ct.php
executable file
·361 lines (314 loc) · 8.29 KB
/
recon_balance_ct.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
<?php
require ("settings.php");
if (isset($_REQUEST["key"])) {
switch ($_REQUEST["key"]) {
case "select":
$OUTPUT = select();
break;
case "balance":
$OUTPUT = balance();
break;
case "balance_update":
$OUTPUT = balance_update();
break;
case "reason":
$OUTPUT = reason();
break;
case "reason_update":
$OUTPUT = reason_update();
break;
case "comments":
$OUTPUT = comments();
break;
case "comments_update":
$OUTPUT = comments_update();
break;
}
} else {
$OUTPUT = select();
}
require ("template.php");
function select($message="")
{
extract ($_REQUEST);
$fields = array();
$fields["search"] = "";
extract ($fields, EXTR_SKIP);
if (empty($search)) $search = "[(EMPTY SEARCH FIELD)]";
$sql = "SELECT supid, supno, supname FROM cubit.suppliers
WHERE supno ILIKE '$search%' OR supname ILIKE '$search%'
ORDER BY supno ASC";
$suppliers_rslt = db_exec($sql) or errDie("Unable to retrieve suppliers.");
if ($search == "[(EMPTY SEARCH FIELD)]") $search = "";
$suppliers_out = "";
while (list($supid, $supno, $supname) = pg_fetch_array($suppliers_rslt)) {
$suppliers_out .= "
<tr class='".bg_class()."'>
<td>$supno</td>
<td>$supname</td>
<td><a href='".SELF."?key=balance&supid=$supid'>Select</a></td>
</tr>";
}
if (empty($suppliers_out) && empty($search)) {
$suppliers_out = "
<tr class='".bg_class()."'>
<td colspan='3'>
<li>
Please enter the first few letters of the creditors name or
supplier no.
</li>
</td>
</tr>";
} elseif (empty($suppliers_out)) {
$suppliers_out = "
<tr class='".bg_class()."'>
<td colspan='3'>
<li>No results found.</li>
</td>
</tr>";
}
$OUTPUT = "
<center>
<h3>Add balance according to creditor</h3>
<form method='post' action='".SELF."'>
<input type='hidden' name='key' value='select' />
<table ".TMPL_tblDflts.">
<tr>
<td colspan='2'>$message</td>
</tr>
<tr>
<th colspan='2'>Search</th>
</tr>
<tr class='".bg_class()."'>
<td><input type='text' name='search' value='$search' /></td>
<td><input type='submit' value='Search' /></td>
</tr>
</table>
</form>
<table ".TMPL_tblDflts.">
<tr>
<th>Supplier No.</th>
<th>Name</th>
<th>Select</th>
</tr>
$suppliers_out
</table>
</center>";
return $OUTPUT;
}
function balance()
{
extract ($_REQUEST);
$fields = array();
$fields["balance"] = "0.00";
extract ($fields, EXTR_SKIP);
$OUTPUT = "
<center>
<h3>Balance According to Creditor</h3>
<form method='post' action='".SELF."'>
<input type='hidden' name='key' value='balance_update' />
<input type='hidden' name='supid' value='$supid' />
<table ".TMPL_tblDflts.">
<tr>
<th>Balance</th>
</tr>
<tr class='".bg_class()."'>
<td>
".CUR."<input type='text' name='balance' style='text-align: right'
value='$balance' />
</td>
</tr>
<tr>
<td align='center'><input type='submit' value='Write »' /></td>
</tr>
</table>
</form>
</center>";
return $OUTPUT;
}
function balance_update()
{
extract ($_REQUEST);
$sql = "SELECT supid FROM cubit.recon_creditor_balances WHERE supid='$supid'";
$rcb_rslt = db_exec($sql) or errDie("Unable to retrieve creditor balance.");
if (pg_num_rows($rcb_rslt)) {
$sql = "UPDATE cubit.recon_creditor_balances SET balance='$balance'
WHERE supid='$supid'";
} else {
$sql = "INSERT INTO cubit.recon_creditor_balances (supid, balance)
VALUES ('$supid', '$balance')";
}
db_exec($sql) or errDie("Unable to update creditor balance.");
return select("<li class='err'>Balance updated</li>");
}
function reason()
{
extract ($_REQUEST);
if (!isset($supid) || !is_numeric($supid)) {
return select();
}
$sql = "SELECT id, date, reason_id, amount FROM cubit.recon_balance_ct
WHERE supid='$supid'
ORDER BY id DESC";
$balance_rslt = db_exec($sql) or errDie("Unable to retrieve balances.");
$sql = "SELECT id, reason FROM cubit.recon_reasons ORDER BY reason ASC";
$reason_rslt = db_exec($sql) or errDie("Unable to retrieve reasons.");
$balance_out = "";
while (list($bal_id, $date, $reason_id, $amount) = pg_fetch_array($balance_rslt)) {
$reasons_sel = "
<select name='oreason_id'>
<option value='0'>[None]</option>";
pg_result_seek($reason_rslt, 0);
while (list($id, $reason) = pg_fetch_array($reason_rslt)) {
if ($reason_id == $id) {
$sel = "selected='selected'";
} else {
$sel = "";
}
$reasons_sel .= "<option value='$id' $sel>$reason</option>";
}
$reasons_sel .= "</select>";
$balance_out .= "
<tr class='".bg_class()."'>
<td>$date</td>
<td>$reasons_sel</td>
<td>
<input type='text' name='amount[$bal_id]' value='$amount' size='8' />
</td>
<td><input type='checkbox' name='remove[$bal_id]' value='$bal_id' /></td>
</tr>";
}
pg_result_seek($reason_rslt, 0);
$reason_sel = "
<select name='nreason_id'>
<option value='0'>[None]</option>";
while (list($id, $reason) = pg_fetch_array($reason_rslt)) {
$reason_sel .= "<option value='$id'>$reason</option>";
}
$reason_sel .= "</select>";
$OUTPUT = "
<center>
<h3>Add Balance According to Creditor</h3>
<form method='post' action='".SELF."'>
<input type='hidden' name='key' value='reason_update' />
<input type='hidden' name='supid' value='$supid' />
<table ".TMPL_tblDflts.">
<tr>
<th>Date</th>
<th>Reason</th>
<th>Amount</th>
<th>Remove</th>
</tr>
<tr class='".bg_class()."'>
<td>".date("Y-m-d")."</td>
<td>$reason_sel</td>
<td><input type='text' name='namount' size='8' /></td>
<td> </td>
</tr>
$balance_out
</table>
<input type='submit' value='Update' />
</form>
<table ".TMPL_tblDflts.">
<tr class='".bg_class()."'>
<td>
<a href='recon_statement_ct.php?key=display&supid=$supid'
style='font-size: 1.3em'>
Return to Statement
</a>
</td>
</tr>
</center>";
return $OUTPUT;
}
function reason_update()
{
extract ($_REQUEST);
if (is_numeric($namount)) {
$sql = "INSERT INTO cubit.recon_balance_ct (supid, reason_id, amount)
VALUES ('$supid', '$nreason_id', '$namount')";
db_exec($sql) or errDie("Unable to add entry.");
}
if (isset($amount)) {
foreach ($amount as $bal_id=>$value) {
if (is_numeric($value)) {
$sql = "UPDATE cubit.recon_balance_ct SET reason_id='$oreason_id',
amount='$value' WHERE id='$bal_id'";
db_exec($sql) or errDie("Unable to add entry.");
}
}
}
if (isset($remove)) {
foreach ($remove as $bal_id=>$value) {
$sql = "DELETE FROM cubit.recon_balance_ct WHERE id='$bal_id'";
db_exec($sql) or errDie("Unable to remove reason.");
}
}
return reason();
}
function comments()
{
extract ($_REQUEST);
$sql = "
SELECT id, date, comment FROM cubit.recon_comments_ct
WHERE supid='$supid' ORDER BY id DESC";
$comments_rslt = db_exec($sql) or errDie("Unable to retrieve comments.");
$comments_out = "";
while ($comments_data = pg_fetch_array($comments_rslt)) {
$comments_out .= "
<tr class='".bg_class()."'>
<td>$comments_data[date]</td>
<td>".nl2br(base64_decode($comments_data["comment"]))."</td>
<td><input type='checkbox' name='remove[$comments_data[id]]' value='1' /></td>
</tr>";
}
$OUTPUT = "
<h3>Creditor Recon Statement Comments</h3>
<form method='post' action='".SELF."'>
<input type='hidden' name='key' value='comments_update' />
<input type='hidden' name='supid' value='$supid' />
<table ".TMPL_tblDflts.">
<tr>
<th>Date</th>
<th>Comment</th>
<th>Remove</th>
</tr>
<tr class='".bg_class()."'>
<td>".date("Y-m-d")."</td>
<td><textarea name='n_comment'></textarea></td>
<td> </td>
</tr>
$comments_out
<tr>
<td colspan='3' align='center'>
<input type='submit' value='Update' />
</td>
</tr>
<tr class='".bg_class()."'>
<td colspan='3' align='center'>
<a href='recon_statement_ct.php?key=display&supid=$supid'>
Return to Statement
</a>
</td>
</tr>
</table>
</form>";
return $OUTPUT;
}
function comments_update()
{
extract ($_REQUEST);
if (!empty($n_comment)) {
$sql = "
INSERT INTO cubit.recon_comments_ct (comment, supid)
VALUES ('".base64_encode($n_comment)."', '$supid')";
db_exec($sql) or errDie("Unable to update comments.");
}
if (isset($remove)) {
foreach ($remove as $id=>$value) {
$sql = "DELETE FROM cubit.recon_comments_ct WHERE id='$id'";
db_exec($sql) or errDie("Unable to remove comments.");
}
}
return comments();
}