Skip to content

Commit 7dfd50b

Browse files
committed
#40 Adds comparison functionality. Needs more testing though.
1 parent 93a47b1 commit 7dfd50b

File tree

6 files changed

+557
-141
lines changed

6 files changed

+557
-141
lines changed

assets/css/wpcable.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ h1, h2, h3, h4, h5, h6 {
1111
.text-center {
1212
text-align: center;
1313
}
14+
.text-right {
15+
text-align: right;
16+
}
1417

1518
.spacer {
1619
padding: 10px;
@@ -20,6 +23,20 @@ img.round {
2023
border-radius: 50%;
2124
}
2225

26+
.increase { color: #46b450; }
27+
.decrease { color: #dc3232; }
28+
29+
.newline {
30+
width: 100%;
31+
float: none;
32+
display: block;
33+
overflow: auto;
34+
}
35+
36+
.maindata .value.small, .small {
37+
font-size: 12px;
38+
}
39+
2340
/**************/
2441
/* Main boxes */
2542
/**************/
@@ -188,6 +205,8 @@ img.round {
188205
display: flex;
189206
align-items: center;
190207
margin-right: 30px;
208+
flex-flow: row wrap;
209+
max-width: 29%;
191210
}
192211

193212
.date-filters label,
@@ -197,6 +216,23 @@ img.round {
197216
margin-right: 5px;
198217
}
199218

219+
.date-filters .datefield label {
220+
min-width: 120px;
221+
text-align: right;
222+
}
223+
224+
.compareto {
225+
display: none;
226+
}
227+
228+
.compareto.is_compare {
229+
display: block;
230+
}
231+
232+
.compareicon {
233+
cursor: pointer;
234+
}
235+
200236
.date-filters .set-date {
201237
margin-left: auto;
202238
height: 40px;
@@ -238,6 +274,14 @@ img.round {
238274
border-bottom: 1px solid #b5bfc6;
239275
}
240276

277+
.stats_table td.firstcol {
278+
width: 75%;
279+
}
280+
281+
.stats_table td.text-right {
282+
padding-left: 10px;
283+
}
284+
241285
.stats_table tr td:nth-child(2) {
242286
text-align: right;
243287
}

assets/images/calendar-add.svg

Lines changed: 15 additions & 0 deletions
Loading

assets/js/wpcable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
jQuery(document).ready(function () {
2+
3+
jQuery('.compareicon').click(function() {
4+
jQuery('.compareto').toggle();
5+
jQuery('#compare_date_from, #compare_date_to').val('');
6+
});
27

38
jQuery('div[data-score]').raty({
49
cancel: false,

classes/stats.php

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,16 @@ public function get_amounts_range( $from_day, $from_month, $from_year, $to_day,
281281
$cache_key = 'amounts_range_' . $first_date . '_' . $last_date;
282282
$result = $this->check_cache( $cache_key, $query );
283283

284-
$variance = array();
284+
$variance = array(
285+
'0-100' => 0,
286+
'100-300' => 0,
287+
'300-500' => 0,
288+
'500-1000' => 0,
289+
'1000-3000' => 0,
290+
'3000-5000' => 0,
291+
'5000-10000' => 0,
292+
'10000-20000' => 0
293+
);
285294
$milestones = array( 0, 100, 300, 500, 1000, 3000, 5000, 10000, 20000 );
286295

287296
foreach ( $result as $amount ) {
@@ -413,6 +422,167 @@ public function get_preferred_count( $from_day, $from_month, $from_year, $to_day
413422
return $out;
414423

415424
}
425+
426+
427+
// returns an array with all stats
428+
public function get_all_stats($from_day, $from_month, $from_year, $to_day, $to_month, $to_year, $chart_display_method = 'months') {
429+
430+
$stats = array();
431+
432+
$averages = $this->get_months_average( $from_month, $from_year, $to_month, $to_year );
433+
$preferred_count = $this->get_preferred_count( $from_day, $from_month, $from_year, $to_day, $to_month, $to_year );
434+
$get_amounts_range = $this->get_amounts_range( $from_day, $from_month, $from_year, $to_day, $to_month, $to_year );
435+
436+
$chart_amounts_range = array();
437+
$get_available_ranges = array();
438+
foreach ( $get_amounts_range as $range => $num_of_tasks ) {
439+
$chart_amounts_range[] = '["' . $range . '", ' . $num_of_tasks . ']';
440+
$get_available_ranges[] = '"'.$range.'"';
441+
}
442+
443+
$get_tasks_type = $this->get_tasks_type( $from_day, $from_month, $from_year, $to_day, $to_month, $to_year );
444+
445+
$type_categories = array();
446+
$type_contractor_fee = array();
447+
$type_revenue = array();
448+
$type_tasks_count = array();
449+
450+
foreach ($get_tasks_type as $type => $type_data) {
451+
452+
$type_categories[ $type ] = "'" . $type . "'";
453+
$type_contractor_fee[ $type ] = floatval( $type_data['fee'] );
454+
$type_revenue[ $type ] = floatval( $type_data['revenue'] );
455+
$type_tasks_count[ $type ] = intval( $type_data['count'] );
456+
}
457+
458+
$type_tasks_count_json = json_encode( $type_tasks_count );
459+
460+
if ( $chart_display_method == 'months' ) {
461+
462+
$month_totals = $this->get_month_range_totals( $from_month, $from_year, $to_month, $to_year );
463+
464+
$max_month_totals = max( $month_totals );
465+
$max_month_totals_key = array_keys( $month_totals, max( $month_totals ) );
466+
467+
$all_month_totals = array();
468+
$all_month_totals['revenue'] = $all_month_totals['total_cost'] = '';
469+
foreach ( $month_totals as $mt ) {
470+
$all_month_totals['revenue'] = $all_month_totals['revenue'] + $mt['revenue'];
471+
$all_month_totals['total_cost'] = $all_month_totals['total_cost'] + $mt['total_cost'];
472+
}
473+
474+
$chart_categories = array();
475+
$chart_dates = array();
476+
$chart_contractor_fee = array();
477+
$chart_revenue = array();
478+
$chart_revenue_avg = array();
479+
$chart_total_cost = array();
480+
$chart_tasks_count = array();
481+
$chart_tasks_count_avg = array();
482+
483+
foreach ( $month_totals as $yearmonth => $amounts ) {
484+
485+
$chart_categories[ $yearmonth ] = "'" . wordwrap( $yearmonth, 4, '-', true ) . "'";
486+
$chart_dates[] = wordwrap( $yearmonth, 4, '-', true );
487+
$chart_contractor_fee[ $yearmonth ] = floatval( $amounts['fee_amount'] );
488+
$chart_revenue[ $yearmonth ] = floatval( $amounts['revenue'] );
489+
$chart_total_cost[ $yearmonth ] = floatval( $amounts['total_cost'] );
490+
$chart_tasks_count[ $yearmonth ] = intval( $amounts['tasks'] );
491+
492+
}
493+
494+
$chart_tasks_count_json = json_encode( $chart_tasks_count );
495+
$chart_revenue_json = json_encode( $chart_revenue );
496+
497+
} else {
498+
499+
$days_totals = $this->get_days( $from_day, $from_month, $from_year, $to_day, $to_month, $to_year );
500+
501+
502+
$max_month_totals = max( $days_totals );
503+
$max_month_totals_key = array_keys( $days_totals, max( $days_totals ) );
504+
$max_month_totals_key[0] = wordwrap( $max_month_totals_key[0], 6, '-', true );
505+
506+
$all_month_totals = array();
507+
foreach ( $days_totals as $mt ) {
508+
if (!isset($all_month_totals['revenue'])) { $all_month_totals['revenue'] = 0; }
509+
if (!isset($all_month_totals['total_cost'])) { $all_month_totals['total_cost'] = 0; }
510+
511+
$all_month_totals['revenue'] = $all_month_totals['revenue'] + $mt['revenue'];
512+
$all_month_totals['total_cost'] = $all_month_totals['total_cost'] + $mt['total_cost'];
513+
}
514+
515+
$chart_categories = array();
516+
$chart_dates = array();
517+
$chart_contractor_fee = array();
518+
$chart_revenue = array();
519+
$chart_revenue_avg = array();
520+
$chart_total_cost = array();
521+
$chart_tasks_count = array();
522+
$chart_tasks_count_avg = array();
523+
524+
foreach ( $days_totals as $yearmonthday => $amounts ) {
525+
526+
$date_array = array();
527+
$date_array = date_parse_from_format( 'Ymd', $yearmonthday );
528+
529+
$chart_categories[ $yearmonthday ] = "'" . $date_array['year'] . '-' . sprintf( "%02d", $date_array['month'] ) . '-' . sprintf( "%02d", $date_array['day'] ) . "'";
530+
$chart_dates[] = $date_array['year'] . '-' . sprintf( "%02d", $date_array['month'] ) . '-' . sprintf( "%02d", $date_array['day'] );
531+
$chart_contractor_fee[ $yearmonthday ] = floatval( $amounts['fee_amount'] );
532+
$chart_revenue[ $yearmonthday ] = floatval( $amounts['revenue'] );
533+
$chart_total_cost[ $yearmonthday ] = floatval( $amounts['total_cost'] );
534+
$chart_tasks_count[ $yearmonthday ] = intval( $amounts['tasks'] );
535+
}
536+
537+
538+
$chart_tasks_count_json = json_encode( $chart_tasks_count );
539+
$chart_revenue_json = json_encode( $chart_revenue );
540+
541+
}
542+
543+
$chart_dates_json = json_encode($chart_dates);
544+
545+
$fromDT = new DateTime($from_year.'-'.$from_month.'-'.$from_day);
546+
$toDT = new DateTime($to_year.'-'.$to_month.'-'.$to_day);
547+
548+
$datediff = date_diff($fromDT, $toDT);
549+
550+
if ($chart_display_method == 'months') {
551+
$datediffcount = $datediff->format('%m') + ($datediff->format('%y') * 12) + 1;
552+
}
553+
if ($chart_display_method == 'days') {
554+
$datediffcount = $datediff->format('%a');
555+
}
556+
557+
$chart_revenue_avg = array_fill(0, count($chart_revenue), round(array_sum($chart_revenue) / $datediffcount, 2));
558+
$chart_tasks_count_avg = array_fill(0, count($chart_tasks_count), round(array_sum($chart_tasks_count) / $datediffcount, 2));
559+
560+
$stats['averages'] = $averages;
561+
$stats['preferred_count'] = $preferred_count;
562+
$stats['chart_amounts_range'] = $chart_amounts_range;
563+
$stats['get_available_ranges'] = $get_available_ranges;
564+
$stats['type_categories'] = $type_categories;
565+
$stats['type_contractor_fee'] = $type_contractor_fee;
566+
$stats['type_revenue'] = $type_revenue;
567+
$stats['type_tasks_count'] = $type_tasks_count;
568+
$stats['type_tasks_count_json'] = $type_tasks_count_json;
569+
$stats['max_month_totals'] = $max_month_totals;
570+
$stats['max_month_totals_key'] = $max_month_totals_key;
571+
$stats['all_month_totals'] = $all_month_totals;
572+
$stats['chart_categories'] = $chart_categories;
573+
$stats['chart_dates'] = $chart_dates;
574+
$stats['chart_dates_json'] = $chart_dates_json;
575+
$stats['chart_contractor_fee'] = $chart_contractor_fee;
576+
$stats['chart_revenue'] = $chart_revenue;
577+
$stats['chart_revenue_avg'] = $chart_revenue_avg;
578+
$stats['chart_total_cost'] = $chart_total_cost;
579+
$stats['chart_tasks_count'] = $chart_tasks_count;
580+
$stats['chart_tasks_count_avg'] = $chart_tasks_count_avg;
581+
$stats['chart_tasks_count_json'] = $chart_tasks_count_json;
582+
$stats['chart_revenue_json'] = $chart_revenue_json;
583+
584+
return $stats;
585+
}
416586

417587
/**
418588
* Checks and sets cached data

0 commit comments

Comments
 (0)