-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_report.php
executable file
·363 lines (346 loc) · 12.9 KB
/
show_report.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
<?php
require('session.php');
$error = '';
$sql_main = "select t1.tran_id, t1.tran_create_date, t2.transaction_price, t3.supp_name, t4.user_name, t7.status from";
$sql_main .= " (select tran_id, tran_supp_id, tran_create_user, tran_create_date from";
$sql_main .= " can_transaction_mast";
$sql_main .= " where 1 = 1";
if(strcmp($_POST['supplier'], '0') != 0)
$sql_main .= " and tran_supp_id = '".$_POST['supplier']."'"; # Only from this supplier
if(strcmp($_POST['create_by'], '0') != 0)
$sql_main .= " and tran_create_user = '".$_POST['create_by']."'";
$sql_main .= " and tran_create_date >= to_date('".$_POST['from_date']."', 'yyyy-mm-dd')";
$sql_main .= " and tran_create_date <= to_date('".$_POST['to_date']."', 'yyyy-mm-dd') + 1";
$sql_main .= " ) t1";
$sql_main .= " inner join";
$sql_main .= " (select tran_id, sum(rate*quantity) transaction_price from";
$sql_main .= " (select * from";
$sql_main .= " can_transaction_dtl";
if(strcmp($_POST['item'], '0') != 0)
$sql_main .= " where item_id = '".$_POST['item']."'";
$sql_main .= " )";
$sql_main .= " group by tran_id";
$sql_main .= " ) t2";
$sql_main .= " on t1.tran_id = t2.tran_id";
$sql_main .= " inner join";
$sql_main .= " (select supp_id, supp_name";
$sql_main .= " from can_supplier_mast";
$sql_main .= " ) t3";
$sql_main .= " on t1.tran_supp_id = t3.supp_id";
$sql_main .= " inner join";
$sql_main .= " (select user_id, user_name";
$sql_main .= " from can_user_mast";
$sql_main .= " ) t4";
$sql_main .= " on t1.tran_create_user = t4.user_id";
$sql_main .= " inner join";
$sql_main .= " (select t5.tran_id, t6.status from";
$sql_main .= " (select tran_id, max(aprv_id) aid from";
$sql_main .= " can_transaction_aprv";
$sql_main .= " group by tran_id";
$sql_main .= " ) t5";
$sql_main .= " inner join";
$sql_main .= " (select aprv_id, status from";
$sql_main .= " can_transaction_aprv";
$sql_main .= " ) t6";
$sql_main .= " on t5.aid = t6.aprv_id";
$sql_main .= " ) t7";
$sql_main .= " on t1.tran_id = t7.tran_id";
$sql_main .= " where t7.status <> 'Cancelled'";
if(isset($_POST['approved_only']))
$sql_main .= " and t7.status = 'Approved'";
$sql_main .= " order by t1.tran_create_date desc";
$result_main = odbc_exec($conn, $sql_main);
$report['total_price'] = 0;
$report['tran_id'] = array();
$report['date'] = array();
$report['price'] = array();
$report['supp_name'] = array();
$report['user_name'] = array();
$report['status'] = array();
while(odbc_fetch_row($result_main)) {
array_push($report['tran_id'], odbc_result($result_main, 1));
array_push($report['date'], odbc_result($result_main, 2));
$price = floatval(odbc_result($result_main, 3));
array_push($report['price'], number_format($price, 2));
array_push($report['supp_name'], odbc_result($result_main, 4));
array_push($report['user_name'], odbc_result($result_main, 5));
array_push($report['status'], odbc_result($result_main, 6));
$report['total_price'] += $price;
}
$report['total_price'] = number_format($report['total_price'], 2);
if(isset($_POST['show_item'])) {
$sql_items = "select t1.tran_id, t6.item_name, t2.quantity, t2.unit, t2.rate, t2.description from";
$sql_items .= " (select tran_id from";
$sql_items .= " can_transaction_mast";
$sql_items .= " where 1 = 1";
if(strcmp($_POST['supplier'], '0') != 0)
$sql_items .= " and tran_supp_id = '".$_POST['supplier']."'"; # Only from this supplier
if(strcmp($_POST['create_by'], '0') != 0)
$sql_items .= " and tran_create_user = '".$_POST['create_by']."'";
$sql_items .= " and tran_create_date >= to_date('".$_POST['from_date']."', 'yyyy-mm-dd')";
$sql_items .= " and tran_create_date <= to_date('".$_POST['to_date']."', 'yyyy-mm-dd')";
$sql_items .= " ) t1";
$sql_items .= " inner join";
$sql_items .= " (select * from";
$sql_items .= " can_transaction_dtl";
if(strcmp($_POST['item'], '0') != 0)
$sql_items .= " where item_id = '".$_POST['item']."'";
$sql_items .= " ) t2";
$sql_items .= " on t1.tran_id = t2.tran_id";
$sql_items .= " inner join";
$sql_items .= " (select t3.tran_id, t4.status from";
$sql_items .= " (select tran_id, max(aprv_id) aid from";
$sql_items .= " can_transaction_aprv";
$sql_items .= " group by tran_id";
$sql_items .= " ) t3";
$sql_items .= " inner join";
$sql_items .= " (select aprv_id, status from";
$sql_items .= " can_transaction_aprv";
$sql_items .= " ) t4";
$sql_items .= " on t3.aid = t4.aprv_id";
$sql_items .= " ) t5";
$sql_items .= " on t1.tran_id = t5.tran_id";
$sql_items .= " inner join";
$sql_items .= " can_item_mast t6";
$sql_items .= " on t2.item_id = t6.item_id";
$sql_items .= " where status <> 'Cancelled'";
if(isset($_POST['approved_only']))
$sql_items .= " and t5.status = 'Approved'";
$sql_items .= " order by t1.tran_id";
$result_items = odbc_exec($conn, $sql_items);
$item['tran_id'] = array();
$item['item_name'] = array();
$item['quantity'] = array();
$item['rate'] = array();
$item['desc'] = array();
$item['total'] = array();
while(odbc_fetch_row($result_items)) {
array_push($item['tran_id'], odbc_result($result_items, 1));
array_push($item['item_name'], odbc_result($result_items, 2));
$quantity = odbc_result($result_items, 3);
array_push($item['quantity'], number_format($quantity).' '.odbc_result($result_items, 4));
$rate = floatval(odbc_result($result_items, 5));
array_push($item['rate'], number_format($rate, 2));
array_push($item['desc'], odbc_result($result_items, 6));
$total = $quantity * $rate;
array_push($item['total'], number_format($total, 2));
}
} else {
$sql_items = " select t7.item_name, t6.qty, t6.rte, t6.prc from";
$sql_items .= " (select item_id, sum(quantity) qty, avg(rate) rte, sum(quantity*rate) prc from";
$sql_items .= " (select tran_id from";
$sql_items .= " can_transaction_mast";
$sql_items .= " where 1 = 1";
if(strcmp($_POST['supplier'], '0') != 0)
$sql_items .= " and tran_supp_id = '".$_POST['supplier']."'"; # Only from this supplier
if(strcmp($_POST['create_by'], '0') != 0)
$sql_items .= " and tran_create_user = '".$_POST['create_by']."'";
$sql_items .= " and tran_create_date >= to_date('".$_POST['from_date']."', 'yyyy-mm-dd')";
$sql_items .= " and tran_create_date <= to_date('".$_POST['to_date']."', 'yyyy-mm-dd')";
$sql_items .= " ) t1";
$sql_items .= " inner join";
$sql_items .= " (select tran_id, item_id, quantity, rate from";
$sql_items .= " can_transaction_dtl";
if(strcmp($_POST['item'], '0') != 0)
$sql_items .= " where item_id = '".$_POST['item']."'";
$sql_items .= " ) t2";
$sql_items .= " on t1.tran_id = t2.tran_id";
$sql_items .= " inner join";
$sql_items .= " (select t3.tran_id, t4.status from";
$sql_items .= " (Select tran_id, max(aprv_id) aid";
$sql_items .= " from can_transaction_aprv";
$sql_items .= " group by tran_id";
$sql_items .= " ) t3";
$sql_items .= " inner join";
$sql_items .= " can_transaction_aprv t4";
$sql_items .= " on t3.aid = t4.aprv_id";
$sql_items .= " where t4.status <> 'Cancelled'";
if(isset($_POST['approved_only']))
$sql_items .= " and t4.status = 'Approved'";
$sql_items .= " ) t5";
$sql_items .= " on t1.tran_id = t5.tran_id";
$sql_items .= " group by item_id";
$sql_items .= " ) t6";
$sql_items .= " inner join";
$sql_items .= " can_item_mast t7";
$sql_items .= " on t6.item_id = t7.item_id";
$sql_items .= " order by t7.item_name";
$result_items = odbc_exec($conn, $sql_items);
$item['name'] = array();
$item['qty'] = array();
$item['rate'] = array();
$item['price'] = array();
while(odbc_fetch_row($result_items)) {
array_push($item['name'], odbc_result($result_items, 1));
array_push($item['qty'], number_format(odbc_result($result_items, 2)));
array_push($item['rate'], number_format(odbc_result($result_items, 3), 2));
array_push($item['price'], number_format(odbc_result($result_items, 4), 2));
}
}
?>
<!DOCTYPE html>
<HTML lang="en">
<HEAD>
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</HEAD>
<BODY>
<div class="container" style="margin-bottom: 30px;">
<div class="container-fluid">
<div class="text-center">
<u><h4> Canteen Inventory Import Summary </h4></u>
<br/>
</div>
<b> Basic Details </b>
<div class="table-responsive" style="border-top: 1px solid black;">
<table class="table table-hover">
<tr>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> From Date : </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php print date('d-M-Y', strtotime($_POST['from_date'])) ?>
</div>
</td>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> To Date : </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php print date('d-M-Y', strtotime($_POST['to_date'])) ?>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> Supplier : </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php
if(strcmp($_POST['supplier'], '0') == 0)
print 'All';
else
{
print $report['supp_name'][0];
}
?>
</div>
</td>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> Created By : </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php
if(strcmp($_POST['create_by'], '0') == 0)
print 'All';
else
print $report['user_name'][0];
?>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> Transactions Found : </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php print number_format(count($report['tran_id'])); ?>
</div>
</td>
<td>
<div class="col-sm-6 col-md-4 col-lg-4">
<b> Total Price </b>
</div>
<div class="col-sm-6 col-md-8 col-lg-8">
<?php print $report['total_price']; ?>
</div>
</td>
</tr>
</table>
</div>
<b> Transaction Overview </b>
<div class="table-responsive" style="border-top: 1px solid black;">
<table class="table table-hover table-bordered">
<thead>
<th> # </th>
<th> Transaction ID </th>
<th> Supplier </th>
<th> Creation Date </th>
<th> Creating User </th>
<th> Status </th>
<th> Price </th>
</thead>
<?php
for($i = 0 ; $i < count($report['tran_id']) ; $i ++ ) {
print '<tr>';
print '<td>'.($i + 1).'</td>';
print '<td>'.$report['tran_id'][$i].'</td>';
print '<td>'.$report['supp_name'][$i].'</td>';
print '<td>'.$report['date'][$i].'</td>';
print '<td>'.$report['user_name'][$i].'</td>';
print '<td>'.$report['status'][$i].'</td>';
print '<td>'.$report['price'][$i].'</td>';
}
?>
</table>
</div>
<b> Item Details </b>
<div class="table-responsive" style="border-top: 1px solid black;">
<table class="table table-hover table-bordered">
<thead>
<th> # </th>
<?php if(isset($_POST['show_item'])) { ?>
<th> Transaction ID </th>
<th> Item </th>
<th> Description </th>
<th> Quantity </th>
<th> Rate </th>
<th> Total </th>
<?php } else { ?>
<th> Name </th>
<th> Quantity </th>
<th> Avg. Rate </th>
<th> Total Price </th>
<?php } ?>
</thead>
<?php
if(isset($_POST['show_item'])) {
for($i = 0 ; $i < count($item['tran_id']) ; $i ++) {
print '<tr>';
print '<td>'.($i + 1).'</td>';
print '<td>'.$item['tran_id'][$i].'</td>';
print '<td>'.$item['item_name'][$i].'</td>';
print '<td>'.$item['desc'][$i].'</td>';
print '<td>'.$item['quantity'][$i].'</td>';
print '<td>'.$item['rate'][$i].'</td>';
print '<td>'.$item['total'][$i].'</td>';
print '</tr>';
}
} else {
for($i = 0 ; $i < count($item['name']) ; $i ++) {
print '<tr>';
print '<td>'.($i + 1).'</td>';
print '<td>'.$item['name'][$i].'</td>';
print '<td>'.$item['qty'][$i].'</td>';
print '<td>'.$item['rate'][$i].'</td>';
print '<td>'.$item['price'][$i].'</td>';
print '</tr>';
}
}
?>
</table>
</div>
<div class="no-print text-center">
<button onclick="window.print();" class="btn btn-primary input-sm">Print Page</button>
</div>
</div>
</div>
</BODY>
</HTML>