/
invoice-note-view-prd.php
executable file
·269 lines (227 loc) · 5.8 KB
/
invoice-note-view-prd.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
<?
#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 ("core-settings.php");
require_lib("docman");
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
case "view":
$OUTPUT = printNote($_POST);
break;
default:
$OUTPUT = slct();
break;
}
} else {
# Display default output
$OUTPUT = slct();
}
require ("template.php");
# Default view
function slct()
{
db_conn(YR_DB);
$sql = "SELECT * FROM info WHERE prdname !=''";
$prdRslt = db_exec($sql);
if(pg_numrows($prdRslt) < 1){
return "<li class='err'>ERROR : There are no periods set for the current year.</li>";
}
$Prds = "<select name='prd'>";
while($prd = pg_fetch_array($prdRslt)){
if($prd['prddb'] == PRD_DB){
$sel = "selected";
}else{
$sel= "";
}
$Prds .= "<option value='$prd[prddb]' $sel>$prd[prdname]</option>";
}
$Prds .= "</select>";
//layout
$slct = "
<h3>View Credit notes<h3>
<table ".TMPL_tblDflts." width='580'>
<form action='".SELF."' method='POST' name='form'>
<input type='hidden' name='key' value='view'>
<tr>
<th colspan='2'>By Date Range</th>
</tr>
<tr class='".bg_class()."'>
<td align='center' colspan='2'>
".mkDateSelect("from",date("Y"),date("m"),"01")."
TO
".mkDateSelect("to")."
</td>
</tr>
<tr>
<td colspan='2' align='right'><input type='submit' value='Search'></td>
</tr>
</form>
</table>
<p>
<table border='0' cellpadding='2' cellspacing='1'>
<tr>
<th>Quick Links</th>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $slct;
}
# show invoices
function printNote ($_POST)
{
# Get vars
extract ($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($from_day, "num", 1,2, "Invalid from Date day.");
$v->isOk ($from_month, "num", 1,2, "Invalid from Date month.");
$v->isOk ($from_year, "num", 1,4, "Invalid from Date Year.");
$v->isOk ($to_day, "num", 1,2, "Invalid to Date day.");
$v->isOk ($to_month, "num", 1,2, "Invalid to Date month.");
$v->isOk ($to_year, "num", 1,4, "Invalid to Date Year.");
# Mix dates
$fromdate = $from_year."-".$from_month."-".$from_day;
$todate = $to_year."-".$to_month."-".$to_day;
if(!checkdate($from_month, $from_day, $from_year)){
$v->isOk ($fromdate, "num", 1, 1, "Invalid from date.");
}
if(!checkdate($to_month, $to_day, $to_year)){
$v->isOk ($todate, "num", 1, 1, "Invalid to date.");
}
# display errors, if any
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>-".$e["msg"]."</li>";
}
return $confirm;
}
# Set up table to display in
$printNote = "
<h3>Credit notes</h3>
<table ".TMPL_tblDflts.">
<tr>
<th>Department</th>
<th>Sales Person</th>
<th>Credit Note No.</th>
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>Order No</th>
<th>Grand Total</th>
<th>Documents</th>
<th colspan='3'>Options</th>
</tr>";
# Connect to database
db_connect();
$month = (int)$from_month;
$yearcheck = $from_year;
$date_arr = array ();
$flag = TRUE;
while ($flag){
if($month == 13){
$month = 1;
$yearcheck++;
}
#add month to array
$date_arr[] = $month;
if ($month == $to_month && $yearcheck == $to_year)
$flag = FALSE;
$month++;
}
$date_arr = array_unique($date_arr);
$queries = array();
# this is no good ... to_month CAN be less than from_month
# for ($i = $from_month; $i <= $to_month; $i++) {
foreach ($date_arr as $i){
$schema = (int)$i;
$queries[] = "SELECT *,'$schema' AS query_schema FROM \"$schema\".inv_notes WHERE odate >= '$fromdate' AND odate <= '$todate' AND div = '".USER_DIV."'";
}
$query = implode(" UNION ", $queries);
$query .= " ORDER BY noteid DESC";
# Query server
$i = 0;
$tot1 = 0;
$sql = " ORDER BY noteid DESC";
$noteRslt = db_exec ($query) or errDie ("Unable to retrieve invoices from database.");
if (pg_numrows ($noteRslt) < 1) {
$printNote = "<li class='err'>No previous credit notes found.</li>";
}else{
while ($note = pg_fetch_array ($noteRslt)) {
$prd = $note["query_schema"];
$note['total'] = sprint($note['total']);
$tot1 = $tot1 + $note['total'];
# Format date
$note['odate'] = explode("-", $note['odate']);
$note['odate'] = $note['odate'][2]."-".$note['odate'][1]."-".$note['odate'][0];
# Get documents
$docs = doclib_getdocs("note", $note['notenum']);
$rep = "invoice-note-reprint.php";
$curr = CUR;
if($note['location'] == 'int'){
$rep = "intinvoice-note-reprint.php";
$curr = $note['currency'];
}
$printNote .= "
<tr class='".bg_class()."'>
<td>$note[deptname]</td>
<td>$note[salespn]</td>
<td>$note[notenum]</td>
<td>$note[invnum]</td>
<td align='center'>$note[odate]</td>
<td>$note[surname]</td>
<td align='right'>$note[ordno]</td>
<td align='right'>$curr $note[total]</td>
<td>$docs</td>
<td><a href='$rep?noteid=$note[noteid]&prd=$prd&reprint=yes' target='_blank'>Details</a></td>
</tr>";
$i++;
}
}
$tot1 = sprint($tot1);
// Layout
if($tot1 > 0){
$printNote .= "
<tr class='".bg_class()."'>
<td colspan='7'>Totals:$i</td>
<td align='right'>".CUR." $tot1</td>
<td colspan='2'> </td>
</tr>";
}
$printNote .= "
</table>
<p>
<table ".TMPL_tblDflts.">
<tr><td><br></td></tr>
<tr>
<th>Quick Links</th>
</tr>
<script>document.write(getQuicklinkSpecial());</script>
</table>";
return $printNote;
}
?>