-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmonthly_report.php
159 lines (129 loc) · 5.21 KB
/
monthly_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
<?php
include_once('lock.php');
include_once('plugins/gChart.php');
include_once('dbplugin.php');
include_once('date_handler.php');
include_once('plugins/html_table.class.php');
$crntYear = getYear();
$crntMonth = getMonth();
// for monthly report
$monthlyArray = generateMonthlyReportData($db, $crntYear, $crntMonth);
if (count($monthlyArray) >= 1) {
$monthlyCatArray = array();
$monthlySumArray = array();
foreach ($monthlyArray as $val) {
list($cat, $amt) = explode("|", $val);
$monthlyCatArray[] = $cat;
$monthlySumArray[] = $amt;
$piChartM = new gPieChart();
$piChartM->addDataSet(array($monthlySumArray[0], $monthlySumArray[1], $monthlySumArray[2], $monthlySumArray[3], $monthlySumArray[4], $monthlySumArray[5], $monthlySumArray[6], $monthlySumArray[7], $monthlySumArray[8], $monthlySumArray[9], $monthlySumArray[10], $monthlySumArray[11], $monthlySumArray[12], $monthlySumArray[13], $monthlySumArray[14], $monthlySumArray[15]));
$piChartM->setLabels(array($monthlyCatArray[0], $monthlyCatArray[1], $monthlyCatArray[2], $monthlyCatArray[3], $monthlyCatArray[4], $monthlyCatArray[5], $monthlyCatArray[6], $monthlyCatArray[7], $monthlyCatArray[8], $monthlyCatArray[9], $monthlyCatArray[10], $monthlyCatArray[11], $monthlyCatArray[12], $monthlyCatArray[13], $monthlyCatArray[14], $monthlyCatArray[15]));
$piChartM->setColors(array("C50000", "1000C5", "14C500", "C5AE00", "AB00C5", "04B7B1", "B75504", "FF00EF", "00FFE6", "9EFF00", "FF5100", "0000FF", "CCOOOO", "C50000", "1000C5", "14C500", "C5AE00", "AB00C5", "04B7B1", "B75504", "FF00EF", "00FFE6", "9EFF00", "FF5100", "0000FF", "CCOOOO"));
}
}
?>
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<link type="text/css" href="scripts/jquery/css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/jquery/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="scripts/jquery/js/jquery-ui-1.10.3.custom.js"></script>
<style type="text/css">
table.demoTbl {
border-collapse: collapse;
border-spacing: 0;
}
#tblCap {
font-weight: bold;
font-size: 15px;
margin: 1em auto .4em;
}
table.demoTbl .percentage {
width: 150px;
}
table.demoTbl .category {
width: 250px;
}
table.demoTbl .amount {
width: 150px;
}
table.demoTbl td, table.demoTbl th {
padding: 1px;
}
table.demoTbl th.first {
text-align: center;
padding: 3px;
background-color: #CCCCCC;
border: 2px solid #FFFFFF;
}
table.demoTbl td.per {
text-align: center;
}
table.demoTbl td.cat {
text-align: center;
}
table.demoTbl td.amt {
text-align: right;
padding-right: 10px;
}
table.demoTbl td.foot {
text-align: center;
}
</style>
</head>
<body>
<h3>Monthly Expenses Report ( <?php echo $crntMonth . "-" . $crntYear ?> )</h3>
<img src="<?php
if (count($monthlyArray) >= 1) {
print $piChartM->getUrl();
} ?>"/>
<br>
<?php
$getCatssql = "select c.category,sum(amount) as sums from expences e, category c where e.year='" . $crntYear . "' and e.month='" . $crntMonth . "' and e.category_id = c.id group by e.category_id order by sums desc";
$cat_result = mysqli_query($db, $getCatssql);
$rowcount = mysqli_num_rows($cat_result);
if ($rowcount >= 1) {
// arguments: id, class, border,
// can include associative array of optional additional attributes
$tbl = new HTML_Table('', 'demoTbl', 0);
$tbl->addCaption('Category Breakdown', 'cap', array('id' => 'tblCap'));
$tbl->addColgroup();
// span, class
$tbl->addCol(0, 'percentage');
$tbl->addCol(1, 'category');
$tbl->addCol(2, 'amount');
// thead
$tbl->addTSection('thead');
$tbl->addRow();
// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
// can include associative array of optional additional attributes
$tbl->addCell('Percentage', 'first', 'header');
$tbl->addCell('Category', 'first', 'header');
$tbl->addCell('Expences (Rs)', 'first', 'header');
// tfoot
$tbl->addTSection('tfoot');
$tbl->addRow();
// span all 3 columns
$tbl->addCell('', 'foot', 'data', array('colspan' => 4));
// tbody
$tbl->addTSection('tbody');
$getTotSum = "select total from summary_month where year='" . $crntYear . "' and month='" . $crntMonth . "'";
$totalSum = mysqli_query($db, $getTotSum);
$totRow = mysqli_fetch_array($totalSum);
$total = $totRow['total'];
while ($row = mysqli_fetch_array($cat_result)) {
$category = $row['category'];
$sum = number_format($row['sums'], 2);
$percentage = number_format((str_replace(",", "", $sum) / $total) * 100, 2);
$tbl->addRow();
$tbl->addCell($percentage . '%', 'per');
$tbl->addCell($category, 'cat');
$tbl->addCell($sum, 'amt');
}
echo $tbl->display();
} else {
echo "<b>No Data to Display</b>";
}
?>
</body>
</html>