/
invoice-stmnt.php
executable file
·320 lines (284 loc) · 10.4 KB
/
invoice-stmnt.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
<?
#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($_POST["key"])) {
switch ($_POST["key"]) {
case "slctcust":
$OUTPUT = slctCust($_POST);
break;
case "print":
$OUTPUT = printInv($_POST);
break;
default:
$OUTPUT = view();
}
} else {
$OUTPUT = view();
}
# get templete
require("template.php");
# Default view
function view()
{
# Query server for depts
db_conn("exten");
$sql = "SELECT * FROM departments ORDER BY deptname ASC";
$deptRslt = db_exec ($sql) or errDie ("Unable to view customers");
if (pg_numrows ($deptRslt) < 1) {
return "<li class=err>There are no Departments found in Cubit.";
}else{
$depts = "<select name='deptid'>";
while($dept = pg_fetch_array($deptRslt)){
$depts .= "<option value='$dept[deptid]'>$dept[deptname]</option>";
}
$depts .= "</select>";
}
//layout
$view = "<br><br><form action='".SELF."' method=post name=form>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=400>
<input type=hidden name=key value=slctcust>
<input type=hidden name=cussel value=cussel>
<tr><th colspan=2>Statement</th></tr>
<tr class='bg-odd'><td>Select Department</td><td valign=center>$depts</td></tr>
<tr class='bg-even'><td>First Letters of customer</td><td valign=center><input type=text size=5 name=letters maxlength=5></td></tr>
<tr><td><br></td></tr>
<tr><td><input type=button value='« Cancel' onClick='javascript:history.back();'></td><td valign=center><input type=submit value='Continue »'></td></tr>
</table></form>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='invoice-view.php'>View Invoices</a></td></tr>
<tr class='bg-odd'><td><a href='customers-new.php'>New Customer</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>
</table>";
return $view;
}
# Default view
function view_err($_POST, $err = "")
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# Query server for depts
db_conn("exten");
$sql = "SELECT * FROM departments ORDER BY deptname ASC";
$deptRslt = db_exec ($sql) or errDie ("Unable to view customers");
if (pg_numrows ($deptRslt) < 1) {
return "<li class=err>There are no Departments found in Cubit.";
}else{
$depts = "<select name='deptid'>";
while($dept = pg_fetch_array($deptRslt)){
if($dept['deptid'] == $deptid){
$sel = "selected";
}else{
$sel = "";
}
$depts .= "<option value='$dept[deptid]' $sel>$dept[deptname]</option>";
}
$depts .= "</select>";
}
//layout
$view = "<br><br><form action='".SELF."' method=post name=form>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=400>
<input type=hidden name=key value=slctcust>
<input type=hidden name=cussel value=cussel>
<tr><th colspan=2>Statement</th></tr>
<tr><td colspan=2>$err</td></tr>
<tr class='bg-odd'><td>Select Department</td><td valign=center>$depts</td></tr>
<tr class='bg-even'><td>First Letters of customer</td><td valign=center><input type=text size=5 name=letters value='$letters' maxlength=5></td></tr>
<tr><td><br></td></tr>
<tr><td><input type=button value='« Cancel' onClick='javascript:history.back();'></td><td valign=center><input type=submit value='Continue »'></td></tr>
</table></form>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='invoice-view.php'>View Invoices</a></td></tr>
<tr class='bg-odd'><td><a href='customers-new.php'>New Customer</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>
</table>";
return $view;
}
# Default view
function slctCust($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($deptid, "num", 1, 20, "Invalid department number.");
$v->isOk ($letters, "string", 0, 5, "Invalid First 3 Letters.");
# no done button
$done = "";
# display errors, if any
$err = "";
if ($v->isError ()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class=err>".$e["msg"];
}
return view_err($_POST, $err);
}
db_connect();
# Query server for customer info
$sql = "SELECT cusnum,cusname,surname FROM customers WHERE deptid = '$deptid' AND lower(surname) LIKE lower('$letters%') ORDER BY surname";
$custRslt = db_exec ($sql) or errDie ("Unable to view customers");
if (pg_numrows ($custRslt) < 1) {
$err = "<li class=err>No customer names starting with <b>$letters</b> in database.";
return view_err($_POST, $err);
}else{
$customers = "<select name='cusnum' onChange='javascript:document.form.submit();'>";
$customers .= "<option value='-S' disabled selected>Select Customer</option>";
while($cust = pg_fetch_array($custRslt)){
$customers .= "<option value='$cust[cusnum]'>$cust[cusname] $cust[surname]</option>";
}
$customers .= "</select>";
}
//layout
$slct = "<br><br><form action='".SELF."' method=post name=form>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=400>
<input type=hidden name=key value=print>
<tr><th colspan=2>Statement</th></tr>
<tr class='bg-odd'><td>Select Customer</td><td valign=center>$customers</td></tr>
<tr><td><br></td></tr>
<tr><td><input type=button value='« Cancel' onClick='javascript:history.back();'></td><td valign=center><input type=submit value='Continue »'></td></tr>
</table></form>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='invoice-view.php'>View Invoices</a></td></tr>
<tr class='bg-odd'><td><a href='customers-new.php'>New Customer</a></td></tr>
<script>document.write(getQuicklinkSpecial());</script>
<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>
</table>";
return $slct;
}
# show invoices
function printInv ($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($cusnum, "num", 1, 20, "Invalid Customer number.");
# display errors, if any
$err = "";
if ($v->isError ()) {
$errors = $v->getErrors();
foreach ($errors as $e) {
$err .= "<li class=err>".$e["msg"];
}
return view_err($_POST, $err);
}
# Get selected customer info
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '$cusnum'";
$custRslt = db_exec ($sql) or errDie ("Unable to view customer");
if (pg_numrows ($custRslt) < 1) {
return "<li class=err>Invalid Customer Number.";
}
$cust = pg_fetch_array($custRslt);
# connect to database
db_connect ();
$fdate = "01-".date("m")."-".date("Y");
$stmnt = "";
$totout = 0;
# Query server
$sql = "SELECT * FROM stmnt WHERE cusnum = '$cusnum' AND date >= '$fdate' ORDER BY date ASC";
$stRslt = db_exec ($sql) or errDie ("Unable to retrieve invoices statement from database.");
if (pg_numrows ($stRslt) < 1) {
$stmnt .= "<tr class='bg-even'><td colspan=4>No previous invoices.</td></tr>";
}else{
$i = 0;
while ($st = pg_fetch_array ($stRslt)) {
# Get selected customer info
db_connect();
$sql = "SELECT * FROM customers WHERE cusnum = '$st[cusnum]'";
$custRslt = db_exec ($sql) or errDie ("Unable to get customer information");
if (pg_numrows ($custRslt) < 1) {
$sql = "SELECT * FROM inv_data WHERE invid = '$st[invid]'";
$custRslt = db_exec ($sql) or errDie ("Unable to get customer information data");
$cust = pg_fetch_array($custRslt);
$cust['cusname'] = $cust['customer'];
$cust['surname'] = "";
}else{
$cust = pg_fetch_array($custRslt);
}
# Get invoice info
db_connect();
$sql = "SELECT * FROM invoices WHERE invid = '$st[invid]'";
$invRslt = db_exec ($sql) or errDie ("Unable to get invoice information");
if (pg_numrows ($invRslt) < 1) {
$stmnt .= "<tr><td colspan=4 class=err>Invoice No. <b>$st[invid]</b> note found.</td></tr>";
$i++;
continue;
}
$inv = pg_fetch_array($invRslt);
# format date
$st['date'] = explode("-", $st['date']);
$st['date'] = $st['date'][2]."-".$st['date'][1]."-".$st['date'][0];
$stmnt .= "<tr class='".bg_class()."'><td>$st[date]</td><td>$st[invid]</td><td>$st[type]</td><td>".CUR." $st[amount]</td></tr>";
# keep track of da totals
$totout += $st['amount'];
$i++;
}
}
$balbf = ($cust['balance'] - $totout);
// Layout
$printInv = "
<h3>Monthly Statement</h3>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr class='bg-odd'><th>Account No.</th><td>$cust[accno]</th></tr>
<tr class='bg-even'><td>Customer : </td><td>$cust[cusname] $cust[surname]</td></tr>
<tr class='bg-odd'><td>Balance Brought Forward</td><td>".CUR." $balbf</td>
<tr><td><br></td></tr>
<tr><th>Date</th><th>Invoice No.</th><th>Details</th><th>Amount</th></tr>
$stmnt
<tr><td><br></td></tr>
<tr class='bg-even'><td colspan=2><b>Total Outstanding</b></td><td colspan=2>".CUR." $totout</td></tr>
</table>
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><td><br></td></tr>
<tr><th>Quick Links</th></tr>
<tr class=datacell><td align=center><a href='cust-credit-stockinv.php'>New Invoice</td></tr>
<script>document.write(getQuicklinkSpecial());</script>
<tr class=datacell><td align=center><a href='main.php'>Main Menu</td></tr>
</table>";
return $printInv;
}
?>