-
Notifications
You must be signed in to change notification settings - Fork 3
/
customers-find.php
executable file
·255 lines (210 loc) · 8.57 KB
/
customers-find.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
<?
#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
#
#
#
#
#
#
#
#
#
#
#
require ("settings.php");
require ("libs/ext.lib.php");
require_lib("validate");
if ( isset($_GET['addcontact']) ) {
$OUTPUT = AddContact($_GET);
$OUTPUT .= printCust($_GET);
} else {
# show current stock
$OUTPUT = printCust($_GET);
}
require ("template.php");
# show stock
function printCust ($_GET)
{
# get vars
foreach ($_GET as $key => $value) {
$$key = $value;
}
if(isset($filter) && !isset($all)){
$sqlfilter = " AND lower($filter) LIKE lower('%$fval%')";
$show=true;
}else{
$filter = "";
$fval = "";
$sqlfilter = "";
$show=false;
}
if(isset($all)) {
$show=true;
}
$filterarr = array("surname" => "Company/Name", "init" => "Initials", "accno" => "Account Number", "deptname" => "Department");
$filtersel = extlib_cpsel("filter", $filterarr, $filter);
# Set up table to display in
$printCust = "
<h3>Find Customer</h3>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<form action='".SELF."' method=get>
<tr><th>.: Filter :.</th><th>.: Value :.</th></tr>
<tr class='bg-odd'><td>$filtersel</td><td><input type=text size=20 name=fval value='$fval'></td></tr>
<tr class='bg-even'><td align=center><input type=submit name=all value='View All'></td><td align=center><input type=submit value='Apply Filter'></td></tr>
</form>
</table>
<p>";
if($show) {
$printCust .= "<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr><th>Acc no.</th><th>Company/Name</th><th>Type</th><th>Curr</th><th>Tel</th><th>Category</th><th>Class</th><th colspan=2>Balance</th><th>Overdue</th><th colspan=8>Options</th></tr>";
# connect to database
db_connect();
# Query server
$tot = 0;
$totoverd = 0;
$i = 0;
$sql = "SELECT * FROM customers WHERE (div = '".USER_DIV."' OR ddiv = '".USER_DIV."') $sqlfilter ORDER BY surname ASC";
$custRslt = db_exec ($sql) or errDie ("Unable to retrieve Customers from database.");
if (pg_numrows ($custRslt) < 1) {
$printCust .= "<tr class='bg-odd'><td colspan=20><li>There are no Customers in Cubit.</td></tr>";
}else{
while ($cust = pg_fetch_array ($custRslt)) {
# Check type of age analisys
if(div_isset("DEBT_AGE", "mon")){
$overd = ageage($cust['cusnum'], ($cust['overdue']/30) - 1, $cust['location']);
}else{
$overd = age($cust['cusnum'], ($cust['overdue'])- 1, $cust['location']);
}
$totoverd += $overd;
# Check if record can be removed
db_connect();
$sql = "SELECT * FROM cashbook WHERE banked = 'no' AND cusnum = '$cust[cusnum]' AND div = '".USER_DIV."'";
$rs = db_exec($sql) or errDie("Unable to get cashbook entries.",SELF);
if(pg_numrows($rs) < 1 && $cust['balance'] == 0){
$rm = "<td><a href='cust-rem.php?cusnum=$cust[cusnum]'>Remove</a></td>";
}else{
$rm = "<td></td>";
}
if(strlen(trim($cust['bustel']))<1) {
$cust['bustel']=$cust['tel'];
}
$cust['balance'] = sprint($cust['balance']);
$tot=$tot+$cust['balance'];
$inv = "";
$inv = "<td><a href='pdf/invoice-pdf-cust.php?cusnum=$cust[cusnum]' target=_blank>Print Invoices</a></td>";
# Locations drop down
$locs = array("loc"=>"Local", "int"=>"International", "" => "");
$loc = $locs[$cust['location']];
$sp4 = " ";
$fbal = "$sp4--$sp4";
$ocurr = CUR;
$trans = "<td><a href='core/cust-trans.php?cusnum=$cust[cusnum]'>Transaction</a></td>";
if($cust['location'] == 'int'){
$fbal = "$sp4 $cust[currency] $cust[fbalance]";
$ocurr = $cust['currency'];
$trans = "<td><a href='core/intcust-trans.php?cusnum=$cust[cusnum]'>Transaction</a></td>";
}
# alternate bgcolor
$printCust .= "<tr class='".bg_class()."'><td>$cust[accno]</td><td>$cust[surname]</td><td align=center>$loc</td><td align=center>$cust[currency]</td><td>$cust[bustel]</td><td>$cust[catname]</td><td>$cust[classname]</td><td align=right>".CUR." $cust[balance]</td><td align=right>$fbal</td><td align=right>$ocurr $overd</td><td><a href='cust-det.php?cusnum=$cust[cusnum]'>Details</a></td>";
$printCust .= "<td><a href='cust-edit.php?cusnum=$cust[cusnum]'>Edit</a></td><td><a href='#' onclick='openPrintWin(\"cust-stmnt.php?cusnum=$cust[cusnum]\")'>Statement</a></td>$trans $inv";
if($cust['blocked'] == 'yes'){
$printCust .= "<td><a href='cust-unblock.php?cusnum=$cust[cusnum]'>Unblock</a></td>";
}else{
$printCust .= "<td><a href='cust-block.php?cusnum=$cust[cusnum]'>Block</a></td>";
}
$printCust .= "$rm <td><a href='conper-add.php?type=cust&id=$cust[cusnum]'>Add Contact</a></td></tr>";
$i++;
}
if ($i > 1){$s = "s";} else {$s = "";}
$tot = sprint($tot);
$totoverd = sprint($totoverd);
$printCust .= "<tr class='".bg_class()."'><td colspan=7>Total Amount Outstanding, from $i client$s </td><td align=right>".CUR." $tot</td><td></td><td align=right>".CUR." $totoverd</td></tr>";
}
$printCust .= "</table>";
}
$printCust .= "
<p>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=15%>
<tr><td><br></td></tr>
<tr><th>Quick Links</th></tr>
<tr class='bg-odd'><td><a href='customers-new.php'>Add 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 $printCust;
}
// adds the customer to the contact list
function AddContact() {
global $_GET;
$v = & new Validate();
if ( ! $v->isOk($_GET["addcontact"], "num", 1, 9, "") )
return "Invalid Customer Number";
// check if supplier can be added to contact list
$rslt = db_exec("SELECT * FROM cons WHERE cust_id='$_GET[addcontact]'");
if ( pg_numrows($rslt) >= 1 ) {
return "Customer Already Added as a Contact<br>";
}
// get it from the db
$sql = "SELECT * FROM customers WHERE cusnum='$_GET[addcontact]'";
$rslt = db_exec($sql) or errDie("Unable to add customer to contact list. (RD)", SELF);
if ( pg_numrows($rslt) < 1 )
return "Unable to add customer to contact list. (RD2)";
$data = pg_fetch_array($rslt);
extract($data);
if ( isset($_GET["addcontact_as"]) && $_GET["addcontact_as"] == "Company" ) {
$company = "$surname";
$surname = "";
} else {
$company = "";
}
// put it in the db
$sql = "INSERT INTO cons (name,surname,comp,ref,tell,cell,fax,email,hadd,padd,date,cust_id,con,by,div)
VALUES ('$cusname','$surname','$company','Customer','$bustel','$cellno','$fax','$email','$addr1',
'$paddr1',CURRENT_DATE,'$cusnum','No','".USER_NAME."','".USER_DIV."')";
$rslt = db_exec($sql) or errDie("Unable to add customer to contact list", SELF);
if (pg_cmdtuples($rslt) < 1) {
return "<li class=err>Unable to add customer to contact list.";
}
}
function age($cusnum, $days, $loc){
$bal = "balance";
if($loc == 'int')
$bal = "fbalance";
# Get the current oustanding
$sql = "SELECT sum($bal) FROM invoices WHERE cusnum = '$cusnum' AND printed = 'y' AND odate < '".extlib_ago($days)."' AND div = '".USER_DIV."'";
$rs = db_exec($sql) or errDie("Unable to access database");
$sum = pg_fetch_array($rs);
# Get the current oustanding on transactions
$sql = "SELECT sum($bal) FROM custran WHERE cusnum = '$cusnum' AND odate < '".extlib_ago($days)."' AND div = '".USER_DIV."'";
$rs = db_exec($sql) or errDie("Unable to access database");
$sumb = pg_fetch_array($rs);
# Take care of nasty zero
return sprint($sum['sum'] + $sumb ['sum'] );
}
function ageage($cusnum, $age, $loc){
$bal = "balance";
if($loc == 'int')
$bal = "fbalance";
# Get the current oustanding
$sql = "SELECT sum($bal) FROM invoices WHERE cusnum = '$cusnum' AND printed = 'y' AND age > '$age' AND div = '".USER_DIV."'";
$rs = db_exec($sql) or errDie("Unable to access database");
$sum = pg_fetch_array($rs);
# Get the current oustanding on transactions
$sql = "SELECT sum($bal) FROM custran WHERE cusnum = '$cusnum' AND age > '$age' AND div = '".USER_DIV."'";
$rs = db_exec($sql) or errDie("Unable to access database");
$sumb = pg_fetch_array($rs);
# Take care of nasty zero
return sprint($sum['sum'] + $sumb ['sum']);
}
?>