/
sorder-view.php
executable file
·242 lines (213 loc) · 5.43 KB
/
sorder-view.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
<?
#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");
if (!isset($_REQUEST["key"])) {
$_REQUEST["key"] = "view";
}
switch ($_REQUEST["key"]) {
case "view":
default:
$OUTPUT = printSord ();
break;
}
$OUTPUT .= mkQuickLinks(
ql("sorder-new.php", "New Sales Order"),
ql("customers-new.php", "New Customer")
);
require ("template.php");
# show Sales Orders
function printSord () {
extract($_REQUEST);
if (isset($key)) {
$key = strtolower($key);
switch ($key) {
case "export to spreadsheet":
case "print":
case "save":
$pure = true;
break;
case "view":
default:
$pure = false;
}
} else {
$pure = false;
}
if (!isset($from_year)) {
explodeDate(false, $from_year, $from_month, $from_day);
explodeDate(false, $to_year, $to_month, $to_day);
}
if (!isset($type)) {
$type = "all";
}
$sel_accepted = ($type == "accepted") ? "checked='t'" : "";
$sel_notaccepted = ($type == "notaccepted") ? "checked='t'" : "";
$sel_all = ($type != "accepted" && $type != "notaccepted") ? "checked='t'" : "";
$printSord = "";
if (!$pure) {
$printSord .= "
<form method='POST' action='".SELF."'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'>View Options</th>
</tr>
<tr class='".bg_class()."'>
<td>Begin Date:</td>
<td>".mkDateSelect("from", $from_year, $from_month, $from_day)."</td>
</tr>
<tr class='".bg_class()."'>
<td>End Date:</td>
<td>".mkDateSelect("to", $to_year, $to_month, $to_day)."</td>
</tr>
<tr class='".bg_class()."'>
<td>Type:</td>
<td>
<input type='radio' name='type' $sel_accepted value='accepted' /> Accepted/Invoiced
<input type='radio' name='type' $sel_notaccepted value='notaccepted' /> Not Yet Accepted
<input type='radio' name='type' $sel_all value='all' /> All
</td>
</tr>
<tr>
<td colspan='2' align='right'><input type='submit' value='Filter' /></td>
</tr>
</table>";
}
if (!isset($key)) {
$printSord .= "</form>";
return $printSord;
}
/* build filter */
$filt = "odate>='$from_year-$from_month-$from_day' AND odate<='$to_year-$to_month-$to_day'";
switch ($type) {
case "accepted":
$filt .= " AND accepted='y'";
break;
case "notaccepted":
$filt .= " AND accepted='n'";
break;
case "all":
default:
}
$printSord .= "
<table ".TMPL_tblDflts.">
<tr>
<th>Department</th>
<th>Sales Person</th>
<th>Sales Order No.</th>
<th>Sales Order Date</th>
<th>Customer Name</th>
<th>Order No</th>
<th>Grand Total</th>
".($pure?"":"<th colspan='6'>Options</th>")."
</tr>";
$i = 0;
$sql = "
SELECT * FROM cubit.sorders
WHERE accepted != 'c' AND done = 'y' AND div = '".USER_DIV."' AND ($filt)
ORDER BY sordid DESC";
$sordRslt = db_exec ($sql) or errDie ("Unable to retrieve Sales Orders from database.");
if (pg_numrows ($sordRslt) < 1) {
$printSord .= "
<tr bgcolor='".bgcolorc(0)."'>
<td colspan='13'>No Sales Orders matching criteria.</td>
</tr>";
} else {
while ($sord = pg_fetch_array ($sordRslt)) {
# format date
$sord['odate'] = explode("-", $sord['odate']);
$sord['odate'] = $sord['odate'][2]."-".$sord['odate'][1]."-".$sord['odate'][0];
$det = "sorder-details.php";
$cancel = "sorder-cancel.php";
$accept = "sorder-accept.php";
$print = "sorder-print.php";
$edit = "sorder-new.php";
if($sord['location'] == 'int'){
$det = "intsorder-details.php";
$cancel = "intsorder-cancel.php";
$accept = "intsorder-accept.php";
$print = "intsorder-print.php";
$edit = "intsorder-new.php";
}
$sp4 = " ";
$bcurr = CUR;
if($sord['location'] == 'int'){
$bcurr = $sord['currency'];
}
$printSord .= "
<tr class='".bg_class()."'>
<td>$sord[deptname]</td>
<td>$sord[salespn]</td>
<td>$sord[sordid]</td>
<td align='center'>$sord[odate]</td>
<td>$sord[cusname] $sord[surname]</td>
<td align='right'>$sord[ordno]</td>
<td align='right'>$bcurr $sord[total]</td>";
if (!$pure) {
$printSord .= "
<td><a href='$det?sordid=$sord[sordid]'>Details</a></td>
<td><a href='javascript: printer(\"$print?invid=$sord[sordid]\");'>Print</a></td>";
if ($sord['accepted'] == 'n') {
$printSord .= "
<td><a href='$edit?sordid=$sord[sordid]&cont=1'>Edit</a></td>
<td><a href='$cancel?sordid=$sord[sordid]'>Cancel</a></td>
<td><a href='$accept?sordid=$sord[sordid]'>Invoice</a></td>
</tr>";
} else {
$printSord .="
<td colspan='3' align='center'>Accepted</td>
</tr>";
}
}
}
}
if (!$pure) {
$printSord .= "
<tr>
<td colspan='13'>
<input type='submit' name='key' value='Print'> | <input type='submit' name='key' value='Export to Spreadsheet'>
</td>
</tr>
</table>
</form>";
} else {
$printSord .= "</table>";
$OUTPUT = clean_html($printSord);
switch ($key) {
case "export to spreadsheet":
require_lib("xls");
StreamXLS("sorders", $OUTPUT);
break;
case "print":
$OUTPUT = "<h3>Sales Orders</h3>$OUTPUT";
require("tmpl-print.php");
break;
case "save":
$pure = true;
break;
}
}
return $printSord;
}
?>