-
Notifications
You must be signed in to change notification settings - Fork 3
/
nons-purch-int-cancel.php
executable file
·353 lines (308 loc) · 9.54 KB
/
nons-purch-int-cancel.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
<?
#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");
# decide what to do
if (isset($_GET["purid"])) {
$OUTPUT = details($_GET);
}else{
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
case "update":
$OUTPUT = write($_POST);
break;
default:
$OUTPUT = "<li class='err'> Ivalid use of module.</li>";
}
} else {
$OUTPUT = "<li class='err'> Ivalid use of module.</li>";
}
}
# get templete
require("template.php");
# details
function details($_POST, $error="")
{
# Get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($purid, "num", 1, 20, "Invalid Non-Stock Order number.");
# display errors, if any
if ($v->isError ()) {
$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;
}
# Get Order info
db_connect();
$sql = "SELECT * FROM nons_purch_int WHERE purid = '$purid' AND div = '".USER_DIV."'";
$purRslt = db_exec ($sql) or errDie ("Unable to get Order information");
if (pg_numrows ($purRslt) < 1) {
return "<li class='err'>purchase Not Found</li>";
}
$pur = pg_fetch_array($purRslt);
# check if Order has been printed
if($pur['received'] == "y"){
$error = "<li class='err'> Error : Order number <b>$pur[purnum]</b> has already been received.</li>";
$error .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
/* --- Start Products Display --- */
# Products layout
$products = "
<table ".TMPL_tblDflts." width='100%'>
<tr>
<th>ITEM NUMBER</th>
<th>DESCRIPTION</th>
<th>QTY</th>
<th colspan='2'>UNIT PRICE</th>
<th colspan='2'>DUTY</th>
<th>LINE TOTAL</th>
<tr>";
# get selected stock in this Order
db_connect();
$sql = "SELECT * FROM nons_purint_items WHERE purid = '$purid' AND div = '".USER_DIV."'";
$stkdRslt = db_exec($sql);
while($stkd = pg_fetch_array($stkdRslt)){
# put in product
$products .= "
<tr class='".bg_class()."'>
<td>$stkd[cod]</td>
<td>$stkd[des]</td>
<td>$stkd[qty]</td>
<td nowrap>$pur[curr] $stkd[cunitcost] or </td>
<td nowrap>".CUR." $stkd[unitcost]</td>
<td nowrap>$pur[curr] $stkd[duty] or </td>
<td>$stkd[dutyp]%</td>
<td nowrap>$pur[curr] $stkd[amt]</td>
</tr>";
//$products .="<tr class='bg-odd'><td>$stkd[cod]</td><td>$stkd[des]</td><td>$stkd[qty]</td><td>$stkd[unitcost]</td><td>$dday-$dmon-$dyear</td><td>$pur[curr] $stkd[amt]</td></tr>";
}
$products .= "</table>";
/* --- End Products Display --- */
/* --- Start Some calculations --- */
# Get subtotal
$SUBTOT = sprint($pur['subtot']);
# Get Total
$TOTAL = sprint($pur['total']);
# Get tax
$tax = sprint($pur['tax']);
/* --- End Some calculations --- */
$currsel = ext_unddbsel("fcid", "currency", "fcid", "descrip",
"No currencies were found in cubit, please add a currency first.", null);
# format date
list($pyear, $pmon, $pday) = explode("-", $pur['pdate']);
list($dyear, $dmon, $dday) = explode("-", $pur['ddate']);
/* -- Final Layout -- */
$details = "
<center>
<h3>International Non-Stock Order Cancel</h3>
<form action='".SELF."' method='POST' name='form'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='purid' value='$purid'>
<table ".TMPL_tblDflts." width='95%'>
<tr>
<td valign='top'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'> Supplier Details </th>
</tr>
<tr class='".bg_class()."'>
<td>Supplier</td>
<td valign='center'>$pur[supplier]</td>
</tr>
<tr class='".bg_class()."'>
<td>Supplier Address</td>
<td valign='center'><pre>$pur[supaddr]</pre></td>
</tr>
</table>
</td>
<td valign='top' align='right'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'> Non-Stock Order Details </th>
</tr>
<tr class='".bg_class()."'>
<td>Non-Stock Order No.</td>
<td valign='center'>$pur[purnum]</td>
</tr>
<tr class='".bg_class()."'>
<td>Order No.</td>
<td valign='center'>$pur[ordernum]</td>
</tr>
<tr class='".bg_class()."'>
<td>Terms</td>
<td valign='center'>$pur[terms] Days</td>
</tr>
<tr class='".bg_class()."'>
<td>Date</td>
<td valign='center'>$pday-$pmon-$pyear</td>
</tr>
<tr class='".bg_class()."'>
<td>Foreign Currency</td>
<td valign='center'>$currsel Exchange rate $pur[curr] $pur[xrate]</td>
</tr>
<tr class='".bg_class()."'>
<td>Tax</td>
<td valign='center'>$pur[curr] $pur[tax]</td>
</tr>
<tr class='".bg_class()."'>
<td>Shipping Charges</td>
<td valign='center'>$pur[curr] $pur[shipchrg]</td>
</tr>
<tr class='".bg_class()."'>
<td>Delivery Date</td>
<td valign='center'>$dday-$dmon-$dyear</td>
</tr>
</table>
</td>
</tr>
<tr><td><br></td></tr>
<tr>
<td colspan='2'>$products</td>
</tr>
<tr>
<td>
<table ".TMPL_tblDflts.">
<tr>
<th width='40%'>Quick Links</th>
<th width='45%'>Remarks</th>
<td rowspan='5' valign='top' width='15%'><br></td>
</tr>
<tr>
<td class='".bg_class()."'><a href='nons-purch-int-new.php'>New International Non-Stock Order</a></td>
<td class='".bg_class()."' rowspan='4' align='center' valign='top'>".nl2br($pur['remarks'])."</td>
</tr>
<tr class='".bg_class()."'>
<td><a href='nons-purch-int-view.php'>View International Non-Stock Orders</a></td>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>
</td>
<td align='right'>
<table ".TMPL_tblDflts." width='80%'>
<tr class='".bg_class()."'>
<td>SUBTOTAL</td>
<td align='right'>$pur[curr] $pur[subtot]</td>
</tr>
<tr class='".bg_class()."'>
<td>Delivery Charges</td>
<td align='right'>$pur[curr] $pur[shipping]</td>
</tr>
<tr class='".bg_class()."'>
<td>Tax </td>
<td align='right'>$pur[curr] $pur[tax]</td>
</tr>
<tr class='".bg_class()."'>
<th>GRAND TOTAL</th>
<td align='right'>$pur[curr] $pur[total]</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align='right'><input type='button' value='« Back' onClick='javascript:history.back()'> | <input type='submit' name='upBtn' value='Write'></td>
</tr>
</table>
</form>
</center>";
return $details;
}
# details
function write($_POST)
{
#get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($purid, "num", 1, 20, "Invalid Order number.");
# display errors, if any
$err = "";
if ($v->isError ()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class='err'>".$e["msg"]."</li>";
}
return details($_POST, $err);
}
# Get Order info
db_connect();
$sql = "SELECT * FROM nons_purch_int WHERE purid = '$purid' AND div = '".USER_DIV."'";
$purRslt = db_exec ($sql) or errDie ("Unable to get Order information");
if (pg_numrows ($purRslt) < 1) {
return "<li>- Order Not Found</li>";
}
$pur = pg_fetch_array($purRslt);
# check if Order has been received
if($pur['received'] == "y"){
$error = "<li class='err'> Error : Order number <b>$pur[purnum]</b> has already been received.</li>";
$error .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
# Insert Order to DB
db_connect();
# begin updating
pglib_transaction ("BEGIN") or errDie("Unable to start a database transaction.",SELF);
# Remove items
$sql = "DELETE FROM nons_purint_items WHERE purid = '$purid' AND div = '".USER_DIV."'";
$rslt = db_exec($sql) or errDie("Unable to update Order items in Cubit.",SELF);
# Remove Order
$sql = "DELETE FROM nons_purch_int WHERE purid = '$purid' AND div = '".USER_DIV."'";
$rslt = db_exec($sql) or errDie("Unable to remove Order items in Cubit.",SELF);
# commit updating
pglib_transaction ("COMMIT") or errDie("Unable to commit a database transaction.",SELF);
// Final Layout
$write = "
<table ".TMPL_tblDflts.">
<tr>
<th>International Non-Stock Order Cancel</th>
</tr>
<tr class='".bg_class()."'>
<td>International Non-Stock Order from Supplier <b>$pur[supplier]</b> has been cancelled.</td>
</tr>
</table>
<p>
<table ".TMPL_tblDflts.">
<tr>
<th>Quick Links</th>
</tr>
<tr class='".bg_class()."'>
<td><a href='nons-purch-int-view.php'>View International Non-Stock Orders</a></td>
</tr>
<tr class='".bg_class()."'>
<td><a href='main.php'>Main Menu</a></td>
</tr>
</table>";
return $write;
}
?>