/
callout-invoiced.php
executable file
·366 lines (304 loc) · 10.9 KB
/
callout-invoiced.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
<?
#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["calloutid"])) {
$OUTPUT = details($_GET);
}else{
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
case "update":
$OUTPUT = write($_POST);
break;
default:
$OUTPUT = details($_POST);
break;
}
} else {
$OUTPUT = details($_POST);
}
}
# get templete
require("template.php");
# details
function details($_POST, $error="") {
extract($_POST);
# validate input
include("libs/validate.lib.php");
$v = new validate ();
if (isset($calloutid)) {
$v->isOk($calloutid, "num", 1, 20, "Invalid callout document number.");
}
if (isset($deptid)) {
$v->isOk($deptid, "num", 1, 20, "Invalid department number.");
}
if (isset($letters)) {
$v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters.");
}
# 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;
}
if (!isset($deptid)) {
$deptid = 0;
} else if (isset($calloutid)) {
db_conn("cubit");
$sql = "UPDATE callout_docs SET deptid='$deptid' WHERE calloutid='$calloutid' AND deptid<>'$deptid'";
db_exec($sql) or errDie("Error updating invoice department.");
}
if (!isset($stkerr)) {
$stkerr = "0,0";
}
if(!isset($done)){
$done = "";
}
# Get callout document info
db_connect();
$sql = "SELECT * FROM callout_docs WHERE calloutid = '$calloutid' AND div = '".USER_DIV."'";
$docRslt = db_exec ($sql) or errDie ("Unable to get callout document information");
if (pg_numrows ($docRslt) < 1) {
return "<li class=err>Callout Document Not Found</li>";
}
$doc = pg_fetch_array($docRslt);
$cusnum = $doc['cusnum'];
# check if callout document has been printed
if($doc['accepted'] == "y"){
$error = "<li class=err> Error : Callout Document number <b>$calloutid</b> has already been printed.</li>";
$error .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $error;
}
# get department
db_conn("exten");
$sql = "SELECT * FROM departments WHERE deptid = '$doc[deptid]' AND div = '".USER_DIV."'";
$deptRslt = db_exec($sql);
if(pg_numrows($deptRslt) < 1){
$dept['deptname'] = "<li class=err>Department not Found.</li>";
}else{
$dept = pg_fetch_array($deptRslt);
}
# Get selected customer info
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '$doc[cusnum]' AND div = '".USER_DIV."'";
$custRslt = db_exec ($sql) or errDie ("Unable to view customer");
if (pg_numrows ($custRslt) < 1) {
db_connect();
# Query server for customer info
$sql = "SELECT cusnum,cusname,surname FROM customers WHERE deptid = '$doc[deptid]' AND location != 'int' AND lower(surname) LIKE lower('$letters%') AND div = '".USER_DIV."' ORDER BY surname";
$custRslt = db_exec ($sql) or errDie ("Unable to view customers");
if (pg_numrows ($custRslt) < 1) {
$ajax_err = "<li class=err>No customer names starting with <b>$letters</b> in database.</li>";
//return view_err($_POST, $err);
}else{
$customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>";
$customers .= "<option value='-S' selected>Select Customer</option>";
while($cust = pg_fetch_array($custRslt)){
$customers .= "<option value='$cust[cusnum]'>$cust[cusname] $cust[surname]</option>";
}
$customers .= "</select>";
}
# take care of the unset vars
$cust['addr1'] = "";
$cust['cusnum'] = "";
$cust['accno'] = "";
}else{
$cust = pg_fetch_array($custRslt);
# moarn if customer account has been blocked
if($cust['blocked'] == 'yes'){
return "<li class=err>Error : Selected customer account has been blocked.</li>";
}
$customers = "<input type=hidden name=cusnum value='$cust[cusnum]'>$cust[cusname] $cust[surname]";
$cusnum = $cust['cusnum'];
}
/* --- Start Drop Downs --- */
# Select warehouse
db_conn("exten");
$whs = "<select name='whidss[]' onChange='javascript:document.form.submit();'>";
$sql = "SELECT * FROM warehouses WHERE div = '".USER_DIV."' ORDER BY whname ASC";
$whRslt = db_exec($sql);
if(pg_numrows($whRslt) < 1){
return "<li class=err> There are no Stores found in Cubit.</li>";
}else{
$whs .= "<option value='-S' disabled selected>Select Store</option>";
while($wh = pg_fetch_array($whRslt)){
$whs .= "<option value='$wh[whid]'>($wh[whno]) $wh[whname]</option>";
}
}
$whs .="</select>";
# days drop downs
$days = array("0"=>"0","7"=>"7","14"=>"14","30"=>"30","60"=>"60","90"=>"90","120"=>"120");
# format date
list($oyear, $omon, $oday) = explode("-", $doc['odate']);
/* --- End Drop Downs --- */
// get the ID of the first warehouse
db_conn("exten");
$sql = "SELECT whid FROM warehouses ORDER BY whid ASC LIMIT 1";
$rslt = db_exec($sql) or errDie("Error reading warehouses (FWH).");
if ( pg_num_rows($rslt) > 0 ) {
$FIRST_WH = pg_fetch_result($rslt, 0, 0);
} else {
$FIRST_WH = "-S";
}
/* --- Start Products Display --- */
# select all products
$products = "
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' border=0 width=100%>
<tr><th>STORE</th><th>ITEM NUMBER</th><th>DESCRIPTION</th><th>QTY</th><th>ITEM PRICE</th><tr>";
# get selected stock in this callout document
db_connect();
$sql = "SELECT * FROM callout_docs_items WHERE calloutid = '$calloutid' AND div = '".USER_DIV."'";
$stkdRslt = db_exec($sql);
$i = 0;
$key = 0;
while($stkd = pg_fetch_array($stkdRslt)){
$stkd['account']+=0;
$stkd['unitcost'] = sprint ($stkd['unitcost']);
# keep track of selected stock amounts
$amts[$i] = $stkd['amt'];
$i++;
# get warehouse name
db_conn("exten");
$sql = "SELECT whname FROM warehouses WHERE whid = '$stkd[whid]' AND div = '".USER_DIV."'";
$whRslt = db_exec($sql);
$wh = pg_fetch_array($whRslt);
# get selected stock in this warehouse
db_connect();
$sql = "SELECT * FROM stock WHERE stkid = '$stkd[stkid]' AND div = '".USER_DIV."'";
$stkRslt = db_exec($sql);
$stk = pg_fetch_array($stkRslt);
# put in product
$products .="<input type=hidden name=accounts[] value=0>
<input type=hidden name=descriptions[] value=''>
<tr class='bg-odd'><td><input type=hidden name=whids[] value='$stkd[whid]'>$wh[whname]</td><td><input type=hidden name=stkids[] value='$stkd[stkid]'><a href='#' onclick='openwindow(\"stock-amt-det.php?stkid=$stk[stkid]\")'>$stk[stkcod]</a></td><td>".extlib_rstr($stk['stkdes'], 30)."</td><td>$stkd[qty]</td><td>$stkd[unitcost]</td></tr>";
$key++;
}
# Look above(remprod keys)
$keyy = $key;
# look above(if i = 0 then there are no products)
if($i == 0){
$done = "";
}
# check if stock warehouse was selected
/* -- start Listeners -- */
/* -- End Listeners -- */
$products .= "</table>";
/* --- End Products Display --- */
/* --- Start Some calculations --- */
# Calculate subtotal
$SUBTOT = sprint($doc['subtot']);
# Calculate subtotal
$SUBTOT = sprint($doc['subtot']);
/* --- End Some calculations --- */
/*--- Start checks --- */
$details_begin = "
<center><h3>Confirm Call Out Document Has Been Invoiced</h3>
<form action='".SELF."' method='post' name='form'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='calloutid' value='$calloutid'>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' border='0' width=95%>
<tr><td valign=top>
<div id='cust_selection'>";
$ajaxOut = "
<input type=hidden name=stkerr value='$stkerr'>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' border=0>
<tr>
<th colspan=2> Customer Details </th>
</tr>
<tr class='bg-odd'>
<td>Department</td>
<td valign=center>$dept[deptname]</td>
</tr>
<tr class='bg-even'>
<td>Customer</td>
<td valign=center>$customers</td>
</tr>
<tr class='bg-odd'>
<td valign=top>Customer Address</td>
<td valign=center>".nl2br($cust['addr1'])."</td>
</tr>
<tr class='bg-even'>
<td>Customer VAT Number</td>
<td>11</td>
</tr>
</table>";
$details_end = "
</div>
</td><td valign=top align=right>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' border=0>
<tr><th colspan=2> Callout Document Details </th></tr>
<tr class='bg-even'><td>Job Number</td><td valign=center>$doc[calloutid]</td></tr>
<tr class='bg-even'><td>Call Out Person</td><td valign=center>$doc[calloutp]</td></tr>
<tr class='bg-odd'><td>Date Service Required</td><td valign=center>$oday-$omon-$oyear</td></tr>
<tr class='bg-even'><td>Default Travel or Call Out</td><td valign=center>$doc[def_travel]</td></tr>
<tr class='bg-odd'><td>Default Labour</td><td valign=center>$doc[def_labour]</td></tr>
</table>
</td></tr>
<tr><td><br></td></tr>
<tr><td colspan=2>$products</td></tr>
<tr>
<td colspan='4'>".nl2br($doc['sign'])."</td>
</tr>
<tr><td>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th width=25%>Quick Links</th><th width=25%>Description Of Callout</th><th width=25%>Comments</th><td rowspan=5 valign=top width=50%>$error</td></tr>
<tr><td class='bg-odd'><a href='callout-new.php'>New Callout Document</a></td><td class='bg-odd' rowspan=4 align=center valign=top>".nl2br($doc['calloutdescrip'])."</td><td class='bg-odd' rowspan=4 align=center valign=top>".nl2br($doc['comm'])."</td></tr>
<tr class='bg-odd'><td><a href='callout-view.php'>View Callout Documents</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>
</td><td align=right>
</td></tr>
<tr><td align='right'><input type='submit' value='Next'></td></tr>
</table>
</form>
</center>";
return "$details_begin$ajaxOut$details_end";
}
function write ($_POST)
{
extract ($_POST);
if(!isset($calloutid))
return "Invalid use of module";
db_connect ();
$update_sql = "UPDATE callout_docs SET invoiced = 'yes' WHERE calloutid = '$calloutid'";
$run_update = db_exec($update_sql) or errDie("Unable to update call out document information");
return "
<h2>Document Stored As Invoice.</h2>
<p>
<table ".TMPL_tblDflts.">
<tr><th width='50'>Quick Links</th></tr>
<tr class='".bg_class()."'><td><a href='callout-new.php'>New Callout Document</a></td></tr>
<tr class='".bg_class()."'><td><a href='callout-view.php'>View Callout Documents</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
}
?>