-
Notifications
You must be signed in to change notification settings - Fork 12
/
e_dashboard.php
369 lines (269 loc) · 10.6 KB
/
e_dashboard.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
364
365
366
367
368
369
<?php
if (!defined('e107_INIT')) { exit; }
class vstore_dashboard // include plugin-folder in the name.
{
private $title; // dynamic title.
function chart()
{
$config = array(
0 => array(
'text' => $this->renderChart(),
'caption' => e107::getParser()->toGlyph('fa-shopping-cart').' Vstore Open/Payed orders',
),
);
return $config;
}
/**
* Render a chart displaying open and payed orders of the last week
*
* @return bool|string
*/
function renderChart()
{
$sql = e107::getDb();
$week_start = strtotime('1 week ago');
$week_end = time()+7200;
$fields = 'SUM(IF(order_status="C", order_pay_amount, 0)) AS A, SUM(IF(order_status!="C", order_pay_amount, 0)) AS B, DATE(FROM_UNIXTIME(order_date)) AS `COL`';
$where = 'order_date >= '.$week_start .' AND order_date <= '.$week_end;
$groupby = 'GROUP BY DATE(FROM_UNIXTIME(order_date))';
if(!$sql->select('vstore_orders', $fields, $where.' '.$groupby))
{
return 'No orders available for the last week.';
}
$dbdata = array();
while($row = $sql->fetch())
{
$dbdata['COL'][] = $row['COL'];
$dbdata['A'][] = floatval($row['A']);
$dbdata['B'][] = floatval($row['B']);
}
$this->title = 'Payed & Open orders';
$data = array();
$data['labels'] = $dbdata['COL'];
$data['datasets'][] = array(
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor ' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => $dbdata['A'],
'title' => 'Open'
);
$data['datasets'][] = array(
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor ' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => $dbdata['B'],
'title' => 'Payed'
);
$cht = e107::getChart();
$cht->setType('line');
$cht->setOptions(array(
'annotateDisplay' => true,
'annotateFontSize' => 8
));
$cht->setData($data);
$text = $cht->render('vstore_canvas', '100%', '200px');
$text .= "<div class='center'><small>
<span style='color:rgba(220,220,220,1);' class='fa fa-shopping-cart'></span> Open
<span style='color:rgba(151,187,205,1);' class='fa fa-shopping-cart'></span> Payed
</small></div>";
return $text;
}
/*
function status() // Status Panel in the admin area
{
$var[0]['icon'] = "<img src='".e_PLUGIN."vstore/images/vstore_16.png' alt='' />";
$var[0]['title'] = "My Title";
$var[0]['url'] = e_PLUGIN_ABS."vstore/vstore.php";
$var[0]['total'] = 10;
return $var;
}
*/
function latest() // Latest panel in the admin area.
{
$count = e107::getDb()->count('vstore_orders', '(*)', 'FIND_IN_SET(order_status, "N,P,H")');
$var[0]['icon'] = "<img src='".e_PLUGIN."vstore/images/vstore_16.png' alt='' />";
$var[0]['title'] = "Open orders";
$var[0]['url'] = e_PLUGIN_ABS."vstore/admin_config.php?searchquery=&filter_options=order_status__open&mode=orders&action=list";
$var[0]['total'] = $count;
return $var;
}
public function revenue()
{
$cht = e107::getChart()->setProvider('google');
$sql = e107::getDb();
$id = 'vstore'.ucfirst(__FUNCTION__);
$width='100%';
$height = 400;
$amt = array();
$month_start = strtotime('first day of -12 months');
$month_end = strtotime("last day of this month"); // strtotime('+9 months');
if(!$sql->gen("SELECT * FROM #vstore_orders WHERE order_pay_status = 'complete' AND order_date BETWEEN ".$month_start." AND ".$month_end." "))
{
return "<div class='alert alert-block alert-info'>No Transactions Found</div>";
}
$total = 0;
while($row = $sql->fetch())
{
$month = date('Y-n', $row['order_date']); // 'Y-n' for monthly, 'Y-n-j' for daily.
// $num = (int) 1; // $row['invoice_total'];
$value = $row['order_pay_amount']; // ($num - $tax);
$type = $row['order_pay_status'];
if(!isset($amt[$month][$type]))
{
$amt[$month][$type] = 0;
$amt[$month]['total'] = 0;
}
$amt[$month][$type] += $value; // increment 'complete' or other type.
if($type === 'complete')
{
$amt[$month]['total'] += $value;
}
$total += $value;
}
$sum = $total;
$data = array();
$data[0] = array('Day', "Complete", /*'Tentative', 'To Reschedule', 'Discounts Given'*/);
$data[0][] = array('type'=>'string', 'label'=>'Total', 'role'=>'annotation', 'p'=> array('html'=>true));
// $this->title = 'Revenue ('.$sum.')';
$range = $this->dateRange($month_start, $month_end, 'first day of next month', 'Y-n');
// e107::getDebug()->log($range);
// e107::getDebug()->log($amt);
$c = 0;
// foreach($amt as $k=>$v)
foreach($range as $unix => $k)
{
$diz = date("M 'y", $unix);
$total = (float) varset($amt[$k]['total']);
$data[] = array(
(string) $diz,
(int) varset($amt[$k]['complete']),
/* (int) $amt[$k]['pending'],
(int) $amt[$k]['reschedule'],
(int) $amt[$k]['discount'],*/
(string) round($total), // annotation
);
$ticks[] = $k;
$c++;
}
// e107::getDebug()->log($data);
$label = "Monthly Revenue ";
$label .= date('M Y', $month_start)." - ".date('M Y', $month_end)." (".number_format($sum).")";
$options = array(
'chartArea' =>array('left'=>80, 'right'=>40, 'width'=>'100%', 'top'=>60, 'bottom'=>130),
'legend' => array('position'=> 'top', 'alignment'=>'center', 'textStyle' => array('fontSize' => 11, 'color' => '#ccc')),
'vAxis' => array('title'=>null, /*'minValue'=>0, 'maxValue'=>10,*/ 'titleFontSize'=>16, 'titleTextStyle'=>array('color' => '#ccc'), 'gridlines'=>array('color'=>'#696969', 'count'=>5), 'minorGridlines'=>array('color'=>'transparent', 'count'=>0), 'format'=>'short', 'textStyle'=>array('color' => '#ccc') ),
'hAxis' => array('title'=>$label, 'slantedText'=>true, 'slantedTextAngle'=>60, 'ticks'=>$ticks, 'titleFontSize'=>14, 'titleTextStyle'=>array('color' => '#ccc'), 'gridlines' => array('color'=>'transparent'), 'textStyle'=>array('color' => '#ccc') ),
'colors' => array('#5CB85C', '#f89406', '#5bc0de', '#ee5f5b', '#ffffff'),
'animation' => array('duration'=>1000, 'easing' => 'out'),
'areaOpacity' => 0.8,
'isStacked' => true,
'annotations' => array('textStyle'=> array('color'=>'white', 'fontSize' => 11), 'format'=>'short', 'alwaysOutside' => true, 'stem' => array('color' => 'transparent')),
'backgroundColor' => array('fill' => 'transparent' )
);
$cht->setType('column');
$cht->setOptions($options);
$cht->setData($data);
return "<div>".$cht->render($id, $width, $height)."</div>";
}
public function orders()
{
$cht = e107::getChart()->setProvider('google');
$sql = e107::getDb();
$id = 'vstore'.ucfirst(__FUNCTION__);
$width='100%';
$height = 400;
$amt = array();
$month_start = strtotime('first day of this month');
$month_end = strtotime("last day of this month"); // strtotime('+9 months');
if(!$sql->gen("SELECT * FROM #vstore_orders WHERE order_date BETWEEN ".$month_start." AND ".$month_end." "))
{
return "<div class='alert alert-block alert-info'>No Transactions Found</div>";
}
$total = 0;
while($row = $sql->fetch())
{
$month = date('Y-n-j', $row['order_date']); // 'Y-n' for monthly, 'Y-n-j' for daily.
$num = (int) 1; // $row['invoice_total'];
$value = $row['order_pay_amount']; // ($num - $tax);
$type = $row['order_status'];
if(!isset($amt[$month][$type]))
{
$amt[$month][$type] = 0;
$amt[$month]['total'] = 0;
}
$amt[$month][$type] += $num; // increment 'complete' or other type.
$amt[$month]['total'] += $num;
/* if($type === 'complete')
{
$amt[$month]['total'] += $num;
}*/
$total += $num;
}
$sum = $total;
$data = array();
$data[0] = array('Day', "New", "Processing", "Completed", "On Hold", "Cancelled", "Refunded");
// $data[0][] = array('type'=>'string', 'label'=>'Total', 'role'=>'annotation', 'p'=> array('html'=>true));
// Create items for each day of the month.
$range = $this->dateRange($month_start, $month_end, '+1 day', 'Y-n-j');
$c = 0;
foreach($range as $unix=>$k)
{
$diz = date("jS", $unix);
$data[] = array(
(string) $diz,
(int) varset($amt[$k]['N']),
(int) varset($amt[$k]['P']),
(int) varset($amt[$k]['C']),
(int) varset($amt[$k]['H']),
(int) varset($amt[$k]['X']),
(int) varset($amt[$k]['R']),
/*
(int) $amt[$k]['reschedule'],
(int) $amt[$k]['discount'],*/
// (string) round($amt[$k]['total']), // annotation
);
$ticks[] = $k;
$c++;
}
// e107::getDebug()->log($data);
$label = "Number of Sales ";
// $label .= date('M Y', $month_start)." - ".date('M Y', $month_end)." (".number_format($sum).")";
$options = array(
'chartArea' =>array('left'=>80, 'right'=>40, 'width'=>'100%', 'top'=>60, 'bottom'=>130),
'legend' => array('position'=> 'top', 'alignment'=>'center', 'textStyle' => array('fontSize' => 11, 'color' => '#ccc')),
'vAxis' => array('title'=>null, /*'minValue'=>0, 'maxValue'=>10,*/ 'titleFontSize'=>16, 'titleTextStyle'=>array('color' => '#ccc'), 'gridlines'=>array('color'=>'#696969', 'count'=>5), 'minorGridlines'=>array('color'=>'transparent', 'count'=>0), 'format'=>'short', 'textStyle'=>array('color' => '#ccc') ),
'hAxis' => array('title'=>$label, 'slantedText'=>true, 'slantedTextAngle'=>60, 'ticks'=>$ticks, 'titleFontSize'=>14, 'titleTextStyle'=>array('color' => '#ccc'), 'gridlines' => array('color'=>'transparent'), 'textStyle'=>array('color' => '#ccc') ),
'colors' => array(
'#337ab7', // New
'#5bc0de', // Processing
'#5CB85C', // Completed
'#f89406', // On Hold
'#ee5f5b', // Cancelled
'#555555' // Refunded
),
'animation' => array('duration'=>1000, 'easing' => 'out'),
'areaOpacity' => 0.8,
'isStacked' => true,
'annotations' => array('textStyle'=> array('color'=>'white', 'fontSize' => 11), 'format'=>'short', 'alwaysOutside' => true, 'stem' => array('color' => 'transparent')),
'backgroundColor' => array('fill' => 'transparent' )
);
$cht->setType('column');
$cht->setOptions($options);
$cht->setData($data);
return "<div>".$cht->render($id, $width, $height)."</div>";
}
private function dateRange( $first, $last, $step = '+1 day', $format = 'Y-n-j' )
{
$dates = array();
$current = $first;
//$last = strtotime( $last );
while( $current <= $last )
{
$dates[$current] = date( $format, $current );
$current = strtotime( $step, $current );
}
return $dates;
}
}