-
Notifications
You must be signed in to change notification settings - Fork 3
/
stock-price-dec.php
executable file
·568 lines (489 loc) · 14.9 KB
/
stock-price-dec.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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<?
#This program is copyright by Andre Coetzee email: ac@main.me
#and is licensed under the GPL v3
#
#
#
#
#Please add yourself to: http://www.accounting-123.com
#Developers, Software Vendors, Support, Accountants, Users
#
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
# get settings
require("settings.php");
require("core-settings.php");
require ("libs/ext.lib.php");
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
case "details":
$OUTPUT = details($_POST);
break;
case "confirm":
$OUTPUT = confirm($_POST);
break;
case "write":
$OUTPUT = write($_POST);
break;
default:
$OUTPUT = view();
}
} else {
$OUTPUT = view();
}
# get templete
require("template.php");
# Default view
function view()
{
# Select warehouse
db_conn("exten");
# Get pricelist
$pricelists = "<select name='listid' style='width: 120'>";
$sql = "SELECT * FROM pricelist WHERE div = '".USER_DIV."' ORDER BY listname ASC";
$listRslt = db_exec($sql);
if(pg_numrows($listRslt) < 1){
return "<li>There are no Price lists in Cubit.</li>";
}else{
while($list = pg_fetch_array($listRslt)){
$pricelists .= "<option value='$list[listid]'>$list[listname]</option>";
}
}
$pricelists .= "</select>";
# Select the stock category
db_connect();
$cats= "<select name='catid'>";
$sql = "SELECT catid,cat,catcod FROM stockcat WHERE div = '".USER_DIV."' ORDER BY cat ASC";
$catRslt = db_exec($sql);
if(pg_numrows($catRslt) < 1){
return "<li>There are no stock categories in Cubit.</li>";
}else{
while($cat = pg_fetch_array($catRslt)){
$cats .= "<option value='$cat[catid]'>($cat[catcod]) $cat[cat]</option>";
}
}
$cats .= "</select>";
# Select classification
$class = "<select name='clasid' style='width: 167'>";
$sql = "SELECT * FROM stockclass WHERE div = '".USER_DIV."' ORDER BY classname ASC";
$clasRslt = db_exec($sql);
if(pg_numrows($clasRslt) < 1){
return "<li>There are no Classifications in Cubit.</li>";
}else{
while($clas = pg_fetch_array($clasRslt)){
$class .= "<option value='$clas[clasid]'>$clas[classname]</option>";
}
}
$class .= "</select>";
//layout
$view = "
<h3>Decrease Stock Items Selling Prices</h3>
<table cellpadding='5'>
<tr>
<td>
<table ".TMPL_tblDflts.">
<form action='".SELF."' method='POST' name='form'>
<input type='hidden' name='key' value='details'>
<tr>
<th colspan='2'>Options</th>
</tr>
<tr class='".bg_class()."'>
<td>Pricelist</td>
<td>$pricelists</td>
</tr>
<tr class='".bg_class()."'>
<td valign='top'>Decrease Type</td>
<td><input type='radio' name='dectype' value='per' checked='yes'>Percentage <input type='text' name='perc' size='4' maxlength='4'> % <br> <input type='radio' name='dectype' value='man'>Manual</td>
</tr>
".TBL_BR."
<tr>
<th colspan='2'>By Category</th>
</tr>
<tr class='".bg_class()."'>
<td align='center'>$cats</td>
<td valign='bottom'><input type='submit' name='cat' value='Decrease'></td>
</tr>
".TBL_BR."
<tr>
<th colspan='2'>By Classification</th>
</tr>
<tr class='".bg_class()."'>
<td align='center'>$class</td>
<td valign='bottom'><input type='submit' name='class' value='Decrease'></td>
</tr>
".TBL_BR."
</form>
</table>
</td>
</tr>
</table>
<p>
<table border=0 cellpadding='2' cellspacing='1' width='15%'>
<tr>
<th>Quick Links</th>
</tr>
<tr class='".bg_class()."'>
<td><a href='toms/pricelist-view.php'>View Price Lists</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-inc.php'>Increase Selling Price</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-dec.php'>Decrease Selling Price</a></td>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $view;
}
# details
function details($_POST)
{
# get vars
extract ($_POST);
# lets get cooking
if($dectype == 'per'){
return cook($_POST);
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($listid, "num", 1, 50, "Invalid Warehouse.");
if(isset($cat)){
$v->isOk ($catid, "num", 1, 50, "Invalid Category.");
$searchs = "SELECT * FROM plist_prices WHERE catid = '$catid' AND listid = '$listid' AND div = '".USER_DIV."'";
}elseif(isset($class)){
$v->isOk ($clasid, "num", 1, 50, "Invalid Classification.");
$searchs = "SELECT * FROM plist_prices WHERE clasid = '$clasid' AND listid = '$listid' AND div = '".USER_DIV."'";
}
# display errors, if any
if ($v->isError ()) {
$error = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$error .= "<li class='err'>".$e["msg"]."</li>";
}
$confirm .= "$error<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# Select Stock
db_conn("exten");
$sql = "SELECT * FROM pricelist WHERE listid = '$listid' AND div = '".USER_DIV."'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.</li>";
}else{
$list = pg_fetch_array($listRslt);
}
$enter = "
<h3>Decrease Stock Items Selling Prices</h3>
<form action='".SELF."' method='POST'>
<table ".TMPL_tblDflts.">
<input type='hidden' name='key' value='confirm'>
<input type='hidden' name='listid' value='$list[listid]'>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<tr class='".bg_class()."'>
<td>Price list</td>
<td align='center'>$list[listname]</td>
</tr>
".TBL_BR."
<tr>
<td colspan='2' align='right'><input type='submit' value='Continue »'></td>
</tr>
<tr>
<td colspan='2'><h3>Prices</h3><td>
<tr>
<tr>
<th>Item</th>
<th>Old Price</th>
<th>New Price</th>
</tr>";
# Query server
$i = 0;
$stkpRslt = db_exec ($searchs) or errDie ("Unable to retrieve stock items from database.");
if (pg_numrows ($stkpRslt) < 1) {
return "<li class='err'> There are no stock item on the selected pricelist.</li>";
}
while ($stkp = pg_fetch_array ($stkpRslt)) {
db_connect();
# get stock details
$sql = "SELECT stkid, stkcod, stkdes FROM stock WHERE stkid = '$stkp[stkid]' AND div = '".USER_DIV."'";
$stkRslt = db_exec ($sql) or errDie ("Unable to retrieve stocks from database.");
$stk = pg_fetch_array ($stkRslt);
if (!isset ($stk['stkid']) OR strlen ($stk['stkid']) < 1)
continue;
$enter .= "
<tr class='".bg_class()."'>
<td><input type='hidden' name='stkids[]' value='$stk[stkid]'>$stk[stkcod] - ".extlib_rstr($stk['stkdes'], 30)."</td>
<td>".CUR." ".sprint($stkp["price"])."</td>
<td align='right'>".CUR." <input type='text' name='prices[]' size='8' value='$stkp[price]'></td>
</tr>";
}
$enter .= "
".TBL_BR."
<tr>
<td colspan='2' align='right'><input type='submit' value='Continue »'></td>
</tr>
</table>
</form>
<p>
<table border=0 cellpadding='2' cellspacing='1'>
<tr>
<th>Quick Links</th>
</tr>
<tr class='".bg_class()."'>
<td><a href='toms/pricelist-view.php'>View Price Lists</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-inc.php'>Increase Selling Price</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-dec.php'>Decrease Selling Price</a></td>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $enter;
}
# cook up some prices
function cook($_POST)
{
# get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($listid, "num", 1, 50, "Invalid Warehouse.");
if(isset($cat)){
$v->isOk ($catid, "num", 1, 50, "Invalid Category.");
$searchs = "SELECT * FROM plist_prices WHERE catid = '$catid' AND listid = '$listid'";
}elseif(isset($class)){
$v->isOk ($clasid, "num", 1, 50, "Invalid Classification.");
$searchs = "SELECT * FROM plist_prices WHERE clasid = '$clasid' AND listid = '$listid'";
}
# display errors, if any
if ($v->isError ()) {
$error = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$error .= "<li class='err'>".$e["msg"]."</li>";
}
$confirm .= "$error<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# Query server
db_conn("exten");
$i = 0;
$stkpRslt = db_exec ($searchs) or errDie ("Unable to retrieve stock items from database.");
if (pg_numrows ($stkpRslt) < 1) {
return "<li class='err'> There are no stock item on the selected pricelist.</li>";
}
for($i = 0; $stkp = pg_fetch_array ($stkpRslt); $i++) {
$csprice = ($stkp['price'] * ($perc/100));
$csprice = round(($stkp['price'] - $csprice), 2);
$stkids[$i] = $stkp['stkid'];
$prices[$i] = $csprice;
}
$_POST['stkids'] = $stkids;
$_POST['prices'] = $prices;
return confirm($_POST);
}
# Confirm new data
function confirm ($_POST)
{
# get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($listid, "num", 1, 50, "Invalid Price List id.");
if(isset($stkids)){
foreach($stkids as $key => $value){
$v->isOk ($stkids[$key], "num", 1, 20, "Invalid Stock Item number.");
$v->isOk ($prices[$key], "float", 1, 20, "Invalid Stock Item price.");
}
}else{
return "<li class='err'> there is not stock for the price list.</li>";
}
# Display errors, if any
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>".$e["msg"]."</li>";
}
$confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# Select Stock
db_conn("exten");
$sql = "SELECT * FROM pricelist WHERE listid = '$listid' AND div = '".USER_DIV."'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.</li>";
}else{
$list = pg_fetch_array($listRslt);
}
$confirm = "
<h3>Confirm Stock Selling Prices Decrease</h3>
<form action='".SELF."' method='POST'>
<table ".TMPL_tblDflts.">
<input type='hidden' name='key' value='write'>
<input type='hidden' name='listid' value='$listid'>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<tr class='".bg_class()."'>
<td>Price list</td>
<td align='center'>$list[listname]</td>
</tr>
<tr><td colspan='2'><br><td><tr>
<tr>
<td align='right'><input type='button' value='Back' onclick='javascript:history.back();'></td>
<td valign='left'><input type='submit' value='Write »'></td>
</tr>
<tr>
<td colspan='2'><h3>Prices</h3><td>
<tr>
<tr>
<th>Item</th>
<th>Old Price</th>
<th>New Price</th>
</tr>";
# Query server
foreach($stkids as $key => $value){
# format price
$prices[$key] = sprint($prices[$key]);
db_connect();
$sql = "SELECT stkid, stkcod, stkdes FROM stock WHERE stkid = '$stkids[$key]' AND div = '".USER_DIV."'";
$stkRslt = db_exec ($sql) or errDie ("Unable to retrieve stocks from database.");
$stk = pg_fetch_array ($stkRslt);
db_conn("exten");
$sql = "SELECT price FROM plist_prices WHERE stkid = '$stkids[$key]' AND listid = '$listid' AND div = '".USER_DIV."'";
$rslt = db_exec($sql) or errDie("Unable to fetch price list items from Cubit.",SELF);
$stkp = pg_fetch_array ($rslt);
if (!isset ($stk['stkid']) OR strlen ($stk['stkid']) < 1)
continue;
$confirm .= "
<tr class='".bg_class()."'>
<td><input type='hidden' name='stkids[]' value='$stk[stkid]'>$stk[stkcod] - ".extlib_rstr($stk['stkdes'], 30)."</td>
<td>".CUR." ".sprint($stkp["price"])."</td>
<td>".CUR." <input type='hidden' name='prices[]' size='8' value='$prices[$key]'>$prices[$key]</td>
</tr>";
}
$confirm .= "
".TBL_BR."
<tr>
<td align='right'><input type='button' value='Back' onclick='javascript:history.back();'></td>
<td valign='left'><input type='submit' value='Write »'></td>
</tr>
</table>
</form>
<p>
<table border=0 cellpadding='2' cellspacing='1'>
<tr>
<th>Quick Links</th>
</tr>
<tr class='".bg_class()."'>
<td><a href='toms/pricelist-view.php'>View Price Lists</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-inc.php'>Increase Selling Price</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-dec.php'>Decrease Selling Price</a></td>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $confirm;
}
# write new data
function write ($_POST)
{
# get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($listid, "num", 1, 50, "Invalid Price List id.");
if(isset($stkids)){
foreach($stkids as $key => $value){
$v->isOk ($stkids[$key], "num", 1, 20, "Invalid Stock Item number.");
$v->isOk ($prices[$key], "float", 1, 20, "Invalid Stock Item price.");
}
}else{
return "<li class='err'> There is not stock for the price list.</li>";
}
# display errors, if any
if ($v->isError ()) {
$confirmCust = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirmCust .= "<li class='err'>".$e["msg"]."</li>";
}
$confirmCust .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirmCust;
}
# connect to db
db_conn ("exten");
$sql = "SELECT * FROM pricelist WHERE listid = '$listid' AND div = '".USER_DIV."'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.</li>";
}else{
$list = pg_fetch_array($listRslt);
}
# begin updating
pglib_transaction ("BEGIN") or errDie("Unable to start a database transaction.",SELF);
# change price list item prices
foreach($stkids as $key => $value){
$sql = "UPDATE plist_prices SET price = '$prices[$key]' WHERE stkid = '$stkids[$key]' AND listid = '$listid' AND div = '".USER_DIV."'";
$rslt = db_exec($sql) or errDie("Unable to update price list items to Cubit.",SELF);
}
# commit updating
pglib_transaction ("COMMIT") or errDie("Unable to commit a database transaction.",SELF);
// Layout
$write = "
<table ".TMPL_tblDflts." width='50%'>
<tr>
<th>Selling Prices Decreased</th>
</tr>
<tr class='datacell'>
<td>Selling Prices in price list : <b>$list[listname]</b>, has been have been decreased.</td>
</tr>
</table>
<p>
<table border=0 cellpadding='2' cellspacing='1'>
<tr>
<th>Quick Links</th>
</tr>
<tr class='".bg_class()."'>
<td><a href='toms/pricelist-view.php'>View Price Lists</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-inc.php'>Increase Selling Price</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='stock-price-dec.php'>Decrease Selling Price</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='main.php'>Main Menu</a></td>
</tr>
</table>";
return $write;
}
?>