@@ -12,18 +12,18 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves the earning sql. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function get_sql( $range ) { |
|
20 | - global $wpdb; |
|
21 | - |
|
22 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
24 | - $clauses = $this->get_range_sql( $range ); |
|
25 | - |
|
26 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * Retrieves the earning sql. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function get_sql( $range ) { |
|
20 | + global $wpdb; |
|
21 | + |
|
22 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
24 | + $clauses = $this->get_range_sql( $range ); |
|
25 | + |
|
26 | + $sql = "SELECT |
|
27 | 27 | item.item_name AS item_name, |
28 | 28 | item.item_id AS item_id, |
29 | 29 | SUM(price) as total |
@@ -38,91 +38,91 @@ discard block |
||
38 | 38 | ORDER BY total DESC |
39 | 39 | "; |
40 | 40 | |
41 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
41 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Prepares the report stats. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function prepare_stats() { |
|
50 | - global $wpdb; |
|
51 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
52 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Prepares the report stats. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function prepare_stats() { |
|
50 | + global $wpdb; |
|
51 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
52 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Normalizes the report stats. |
|
57 | - * |
|
58 | - */ |
|
59 | - public function normalize_stats( $stats ) { |
|
60 | - $normalized = array(); |
|
61 | - $others = 0; |
|
62 | - $did = 0; |
|
55 | + /** |
|
56 | + * Normalizes the report stats. |
|
57 | + * |
|
58 | + */ |
|
59 | + public function normalize_stats( $stats ) { |
|
60 | + $normalized = array(); |
|
61 | + $others = 0; |
|
62 | + $did = 0; |
|
63 | 63 | |
64 | - foreach ( $stats as $stat ) { |
|
64 | + foreach ( $stats as $stat ) { |
|
65 | 65 | |
66 | - if ( $did > 4 ) { |
|
66 | + if ( $did > 4 ) { |
|
67 | 67 | |
68 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
68 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
69 | 69 | |
70 | - } else { |
|
70 | + } else { |
|
71 | 71 | |
72 | - $normalized[] = array( |
|
73 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
74 | - 'item_name' => strip_tags( $stat->item_name ), |
|
75 | - ); |
|
72 | + $normalized[] = array( |
|
73 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
74 | + 'item_name' => strip_tags( $stat->item_name ), |
|
75 | + ); |
|
76 | 76 | |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - $did++; |
|
80 | - } |
|
79 | + $did++; |
|
80 | + } |
|
81 | 81 | |
82 | - if ( $others > 0 ) { |
|
82 | + if ( $others > 0 ) { |
|
83 | 83 | |
84 | - $normalized[] = array( |
|
85 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
86 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
87 | - ); |
|
84 | + $normalized[] = array( |
|
85 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
86 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
87 | + ); |
|
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - return $normalized; |
|
92 | - } |
|
91 | + return $normalized; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves report data. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function get_data() { |
|
94 | + /** |
|
95 | + * Retrieves report data. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function get_data() { |
|
99 | 99 | |
100 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
101 | - $colors = array( '#007bff','#28a745','#333333','#c3e6cb','#dc3545','#6c757d', '#00bcd4', '#00695C', '#03a9f4', '#2196f3', '#3f51b5', '#673ab7', '#9c27b0', '#e91e63', '#f44336', '#8bc34a', '#4caf50' ); |
|
100 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
101 | + $colors = array( '#007bff','#28a745','#333333','#c3e6cb','#dc3545','#6c757d', '#00bcd4', '#00695C', '#03a9f4', '#2196f3', '#3f51b5', '#673ab7', '#9c27b0', '#e91e63', '#f44336', '#8bc34a', '#4caf50' ); |
|
102 | 102 | |
103 | - shuffle( $colors ); |
|
103 | + shuffle( $colors ); |
|
104 | 104 | |
105 | - return array( |
|
106 | - 'data' => $data, |
|
107 | - 'backgroundColor' => $colors, |
|
108 | - ); |
|
105 | + return array( |
|
106 | + 'data' => $data, |
|
107 | + 'backgroundColor' => $colors, |
|
108 | + ); |
|
109 | 109 | |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Retrieves report labels. |
|
114 | - * |
|
115 | - */ |
|
116 | - public function get_labels() { |
|
117 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
118 | - } |
|
112 | + /** |
|
113 | + * Retrieves report labels. |
|
114 | + * |
|
115 | + */ |
|
116 | + public function get_labels() { |
|
117 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Displays the actual report. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function display_stats() { |
|
125 | - ?> |
|
120 | + /** |
|
121 | + * Displays the actual report. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function display_stats() { |
|
125 | + ?> |
|
126 | 126 | |
127 | 127 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
128 | 128 | |
@@ -151,6 +151,6 @@ discard block |
||
151 | 151 | </script> |
152 | 152 | |
153 | 153 | <?php |
154 | - } |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | * Retrieves the earning sql. |
17 | 17 | * |
18 | 18 | */ |
19 | - public function get_sql( $range ) { |
|
19 | + public function get_sql($range) { |
|
20 | 20 | global $wpdb; |
21 | 21 | |
22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
23 | 23 | $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
24 | - $clauses = $this->get_range_sql( $range ); |
|
24 | + $clauses = $this->get_range_sql($range); |
|
25 | 25 | |
26 | 26 | $sql = "SELECT |
27 | 27 | item.item_name AS item_name, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ORDER BY total DESC |
39 | 39 | "; |
40 | 40 | |
41 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
41 | + return apply_filters('getpaid_items_graphs_get_sql', $sql, $range); |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | |
@@ -48,30 +48,30 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function prepare_stats() { |
50 | 50 | global $wpdb; |
51 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
52 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
51 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
52 | + $this->stats = $this->normalize_stats($this->stats); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Normalizes the report stats. |
57 | 57 | * |
58 | 58 | */ |
59 | - public function normalize_stats( $stats ) { |
|
59 | + public function normalize_stats($stats) { |
|
60 | 60 | $normalized = array(); |
61 | 61 | $others = 0; |
62 | 62 | $did = 0; |
63 | 63 | |
64 | - foreach ( $stats as $stat ) { |
|
64 | + foreach ($stats as $stat) { |
|
65 | 65 | |
66 | - if ( $did > 4 ) { |
|
66 | + if ($did > 4) { |
|
67 | 67 | |
68 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
68 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
69 | 69 | |
70 | 70 | } else { |
71 | 71 | |
72 | 72 | $normalized[] = array( |
73 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
74 | - 'item_name' => strip_tags( $stat->item_name ), |
|
73 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
74 | + 'item_name' => strip_tags($stat->item_name), |
|
75 | 75 | ); |
76 | 76 | |
77 | 77 | } |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | $did++; |
80 | 80 | } |
81 | 81 | |
82 | - if ( $others > 0 ) { |
|
82 | + if ($others > 0) { |
|
83 | 83 | |
84 | 84 | $normalized[] = array( |
85 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
86 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
85 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
86 | + 'item_name' => esc_html__('Others', 'invoicing'), |
|
87 | 87 | ); |
88 | 88 | |
89 | 89 | } |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function get_data() { |
99 | 99 | |
100 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
101 | - $colors = array( '#007bff','#28a745','#333333','#c3e6cb','#dc3545','#6c757d', '#00bcd4', '#00695C', '#03a9f4', '#2196f3', '#3f51b5', '#673ab7', '#9c27b0', '#e91e63', '#f44336', '#8bc34a', '#4caf50' ); |
|
100 | + $data = wp_list_pluck($this->stats, 'total'); |
|
101 | + $colors = array('#007bff', '#28a745', '#333333', '#c3e6cb', '#dc3545', '#6c757d', '#00bcd4', '#00695C', '#03a9f4', '#2196f3', '#3f51b5', '#673ab7', '#9c27b0', '#e91e63', '#f44336', '#8bc34a', '#4caf50'); |
|
102 | 102 | |
103 | - shuffle( $colors ); |
|
103 | + shuffle($colors); |
|
104 | 104 | |
105 | 105 | return array( |
106 | 106 | 'data' => $data, |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | */ |
116 | 116 | public function get_labels() { |
117 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
117 | + return wp_list_pluck($this->stats, 'item_name'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | { |
136 | 136 | type: 'doughnut', |
137 | 137 | data: { |
138 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
139 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
138 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
139 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
140 | 140 | }, |
141 | 141 | options: { |
142 | 142 | legend: { |