-
Notifications
You must be signed in to change notification settings - Fork 3
/
stock-inc.php
executable file
·431 lines (379 loc) · 13.1 KB
/
stock-inc.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
<?
#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 ORDER BY listname ASC";
$listRslt = db_exec($sql);
if(pg_numrows($listRslt) < 1){
return "<li>There are no Price lists in Cubit.";
}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 ORDER BY cat ASC";
$catRslt = db_exec($sql);
if(pg_numrows($catRslt) < 1){
return "<li>There are no stock categories in Cubit.";
}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 ORDER BY classname ASC";
$clasRslt = db_exec($sql);
if(pg_numrows($clasRslt) < 1){
return "<li>There are no Classifications in Cubit.";
}else{
while($clas = pg_fetch_array($clasRslt)){
$class .= "<option value='$clas[clasid]'>$clas[classname]</option>";
}
}
$class .="</select>";
//layout
$view = "<h3>Increase Stock Items Selling Prices</h3>
<table cellpadding=5><tr><td>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<form action='".SELF."' method=post name=form>
<input type=hidden name=key value=details>
<tr><th colspan=2>Options</th></tr>
<tr class='bg-odd'><td>Pricelist</td><td>$pricelists</td></tr>
<tr class='bg-even'><td valign=top>Increase Type</td><td><input type=radio name='inctype' value=per checked=yes>Percentage <input type=text name=perc size=4 maxlength=4> % <br> <input type=radio name='inctype' value='man'>Manual</td></tr>
<tr><td><br></td></tr>
<tr><th colspan=2>By Category</th></tr>
<tr class='bg-odd'><td align=center>$cats</td><td valign=bottom><input type=submit name=cat value='Increase'></td></tr>
<tr><td><br></td></tr>
<tr><th colspan=2>By Classification</th></tr>
<tr class='bg-odd'><td align=center>$class</td><td valign=bottom><input type=submit name=class value='Increase'></td></tr>
<tr><td><br></td></tr>
</form>
</table>
</td></tr>
</table>
<p>
<table border=0 cellpadding='2' cellspacing='1' width=15%>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='toms/pricelist-view.php'>View Price Lists</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $view;
}
# details
function details($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# lets get cooking
if($inctype == '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'";
}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"];
}
$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'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.";
}else{
$list = pg_fetch_array($listRslt);
}
$enter =
"<h3>Increase Stock Items Selling Prices</h3>
<form action='".SELF."' method=post>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<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-odd'><td>Price list</td><td align=center>$list[listname]</td></tr>
<tr><td><br></td></tr>
<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.";
}
while ($stkp = pg_fetch_array ($stkpRslt)) {
db_connect();
# get stock details
$sql = "SELECT stkid, stkcod, stkdes FROM stock WHERE stkid = '$stkp[stkid]'";
$stkRslt = db_exec ($sql) or errDie ("Unable to retrieve stocks from database.");
$stk = pg_fetch_array ($stkRslt);
$enter .= "<tr class='".bg_class()."'><td><input type=hidden name=stkids[] value='$stk[stkid]'>$stk[stkcod] - ".extlib_rstr($stk['stkdes'], 30)."</td><td>".CUR." $stkp[price]</td><td align=right>".CUR." <input type=text name=prices[] size=8 value='$stkp[price]'></td></tr>";
}
$enter .= "
<tr><td><br></td></tr>
<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-odd'><td><a href='toms/pricelist-view.php'>View Price Lists</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $enter;
}
# cook up some prices
function cook($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# 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"];
}
$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.";
}
for($i = 0; $stkp = pg_fetch_array ($stkpRslt); $i++) {
$csprice = ($stkp['price'] * ($perc/100));
$csprice = round(($csprice + $stkp['price']), 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
foreach ($_POST as $key => $value) {
$$key = $value;
}
# 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.";
}
# Display errors, if any
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class=err>".$e["msg"];
}
$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'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.";
}else{
$list = pg_fetch_array($listRslt);
}
$confirm =
"<h3>Confirm Stock Selling Prices Increase</h3>
<form action='".SELF."' method=post>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<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-odd'><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]'";
$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'";
$rslt = db_exec($sql) or errDie("Unable to fetch price list items from Cubit.",SELF);
$stkp = pg_fetch_array ($rslt);
$confirm .= "<tr class='".bg_class()."'><td><input type=hidden name=stkids[] value='$stk[stkid]'>$stk[stkcod] - ".extlib_rstr($stk['stkdes'], 30)."</td><td>".CUR." $stkp[price]</td><td>".CUR." <input type=hidden name=prices[] size=8 value='$prices[$key]'>$prices[$key]</td></tr>";
}
$confirm .= "
<tr><td><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>
</table></form>
<p>
<table border=0 cellpadding='2' cellspacing='1'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='toms/pricelist-view.php'>View Price Lists</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $confirm;
}
# write new data
function write ($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# 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.";
}
# display errors, if any
if ($v->isError ()) {
$confirmCust = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirmCust .= "<li class=err>".$e["msg"];
}
$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'";
$listRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
if(pg_numrows($listRslt) < 1){
return "<li> Invalid Price List ID.";
}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'";
$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 border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width='50%'>
<tr><th>Selling Prices Increased</th></tr>
<tr class=datacell><td>Selling Prices in price list : <b>$list[listname]</b>, has been have been increased.</td></tr>
</table>
<p>
<table border=0 cellpadding='2' cellspacing='1'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='toms/pricelist-view.php'>View Price Lists</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $write;
}
?>