@@ -16,164 +16,164 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_MaxMind_Geolocation { |
18 | 18 | |
19 | - /** |
|
20 | - * The service responsible for interacting with the MaxMind database. |
|
21 | - * |
|
22 | - * @var GetPaid_MaxMind_Database_Service |
|
23 | - */ |
|
24 | - private $database_service; |
|
25 | - |
|
26 | - /** |
|
27 | - * Initialize the integration. |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - /** |
|
32 | - * Supports overriding the database service to be used. |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @return mixed|null The geolocation database service. |
|
36 | - */ |
|
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | - } |
|
41 | - |
|
42 | - // Bind to the scheduled updater action. |
|
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | - |
|
45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | - |
|
48 | - // Handle maxmind key updates. |
|
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get database service. |
|
55 | - * |
|
56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
57 | - */ |
|
58 | - public function get_database_service() { |
|
59 | - return $this->database_service; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Checks to make sure that the license key is valid. |
|
64 | - * |
|
65 | - * @param string $license_key The new license key. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function handle_key_updates( $license_key ) { |
|
69 | - |
|
70 | - // Trim whitespaces and strip slashes. |
|
71 | - $license_key = trim( $license_key ); |
|
72 | - |
|
73 | - // Abort if the license key is empty or unchanged. |
|
74 | - if ( empty( $license_key ) ) { |
|
75 | - return $license_key; |
|
76 | - } |
|
77 | - |
|
78 | - // Abort if a database exists and the license key is unchaged. |
|
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | - return $license_key; |
|
81 | - } |
|
82 | - |
|
83 | - // Check the license key by attempting to download the Geolocation database. |
|
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | - return $license_key; |
|
88 | - } |
|
89 | - |
|
90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | - |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Updates the database used for geolocation queries. |
|
96 | - * |
|
97 | - * @param string $tmp_database_path Temporary database path. |
|
98 | - */ |
|
99 | - public function update_database( $tmp_database_path = null ) { |
|
100 | - |
|
101 | - // Allow us to easily interact with the filesystem. |
|
102 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | - WP_Filesystem(); |
|
104 | - global $wp_filesystem; |
|
105 | - |
|
106 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | - $target_database_path = $this->database_service->get_database_path(); |
|
108 | - |
|
109 | - // If there's no database path, we can't store the database. |
|
110 | - if ( empty( $target_database_path ) ) { |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | - $wp_filesystem->delete( $target_database_path ); |
|
116 | - } |
|
117 | - |
|
118 | - // We can't download a database if there's no license key configured. |
|
119 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | - if ( empty( $license_key ) ) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - if ( empty( $tmp_database_path ) ) { |
|
125 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | - } |
|
127 | - |
|
128 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | - return; |
|
131 | - } |
|
132 | - |
|
133 | - // Move the new database into position. |
|
134 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | - * |
|
141 | - * @param array $data Geolocation data. |
|
142 | - * @param string $ip_address The IP address to geolocate. |
|
143 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | - */ |
|
145 | - public function get_geolocation( $data, $ip_address ) { |
|
146 | - |
|
147 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | - return $data; |
|
149 | - } |
|
150 | - |
|
151 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | - |
|
153 | - return array( |
|
154 | - 'country' => $country_code, |
|
155 | - 'state' => '', |
|
156 | - 'city' => '', |
|
157 | - 'postcode' => '', |
|
158 | - ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Fetches the prefix for the MaxMind database file. |
|
164 | - * |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - private function get_database_prefix() { |
|
168 | - |
|
169 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | - |
|
171 | - if ( empty( $prefix ) ) { |
|
172 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | - } |
|
175 | - |
|
176 | - return $prefix; |
|
177 | - } |
|
19 | + /** |
|
20 | + * The service responsible for interacting with the MaxMind database. |
|
21 | + * |
|
22 | + * @var GetPaid_MaxMind_Database_Service |
|
23 | + */ |
|
24 | + private $database_service; |
|
25 | + |
|
26 | + /** |
|
27 | + * Initialize the integration. |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + /** |
|
32 | + * Supports overriding the database service to be used. |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @return mixed|null The geolocation database service. |
|
36 | + */ |
|
37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | + if ( null === $this->database_service ) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | + } |
|
41 | + |
|
42 | + // Bind to the scheduled updater action. |
|
43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | + |
|
45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | + |
|
48 | + // Handle maxmind key updates. |
|
49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get database service. |
|
55 | + * |
|
56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
57 | + */ |
|
58 | + public function get_database_service() { |
|
59 | + return $this->database_service; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Checks to make sure that the license key is valid. |
|
64 | + * |
|
65 | + * @param string $license_key The new license key. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function handle_key_updates( $license_key ) { |
|
69 | + |
|
70 | + // Trim whitespaces and strip slashes. |
|
71 | + $license_key = trim( $license_key ); |
|
72 | + |
|
73 | + // Abort if the license key is empty or unchanged. |
|
74 | + if ( empty( $license_key ) ) { |
|
75 | + return $license_key; |
|
76 | + } |
|
77 | + |
|
78 | + // Abort if a database exists and the license key is unchaged. |
|
79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | + return $license_key; |
|
81 | + } |
|
82 | + |
|
83 | + // Check the license key by attempting to download the Geolocation database. |
|
84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | + return $license_key; |
|
88 | + } |
|
89 | + |
|
90 | + $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | + |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Updates the database used for geolocation queries. |
|
96 | + * |
|
97 | + * @param string $tmp_database_path Temporary database path. |
|
98 | + */ |
|
99 | + public function update_database( $tmp_database_path = null ) { |
|
100 | + |
|
101 | + // Allow us to easily interact with the filesystem. |
|
102 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | + WP_Filesystem(); |
|
104 | + global $wp_filesystem; |
|
105 | + |
|
106 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | + $target_database_path = $this->database_service->get_database_path(); |
|
108 | + |
|
109 | + // If there's no database path, we can't store the database. |
|
110 | + if ( empty( $target_database_path ) ) { |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | + $wp_filesystem->delete( $target_database_path ); |
|
116 | + } |
|
117 | + |
|
118 | + // We can't download a database if there's no license key configured. |
|
119 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | + if ( empty( $license_key ) ) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + if ( empty( $tmp_database_path ) ) { |
|
125 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | + } |
|
127 | + |
|
128 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | + return; |
|
131 | + } |
|
132 | + |
|
133 | + // Move the new database into position. |
|
134 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | + * |
|
141 | + * @param array $data Geolocation data. |
|
142 | + * @param string $ip_address The IP address to geolocate. |
|
143 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | + */ |
|
145 | + public function get_geolocation( $data, $ip_address ) { |
|
146 | + |
|
147 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | + return $data; |
|
149 | + } |
|
150 | + |
|
151 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | + |
|
153 | + return array( |
|
154 | + 'country' => $country_code, |
|
155 | + 'state' => '', |
|
156 | + 'city' => '', |
|
157 | + 'postcode' => '', |
|
158 | + ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Fetches the prefix for the MaxMind database file. |
|
164 | + * |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + private function get_database_prefix() { |
|
168 | + |
|
169 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | + |
|
171 | + if ( empty( $prefix ) ) { |
|
172 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | + } |
|
175 | + |
|
176 | + return $prefix; |
|
177 | + } |
|
178 | 178 | |
179 | 179 | } |
@@ -12,46 +12,46 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $views; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $views; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | - ), |
|
29 | + 'label' => __( 'Items', 'invoicing' ), |
|
30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | + ), |
|
32 | 32 | |
33 | - 'gateways' => array( |
|
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | - ), |
|
33 | + 'gateways' => array( |
|
34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | + ), |
|
37 | 37 | |
38 | - 'discounts' => array( |
|
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | - ), |
|
38 | + 'discounts' => array( |
|
39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | + ), |
|
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Displays the reports tab. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display() { |
|
54 | - ?> |
|
49 | + /** |
|
50 | + * Displays the reports tab. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display() { |
|
54 | + ?> |
|
55 | 55 | |
56 | 56 | <div class="mt-4" style="max-width: 1200px;"> |
57 | 57 | |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | |
70 | 70 | <?php |
71 | 71 | |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Displays the left side. |
|
76 | - * |
|
77 | - */ |
|
78 | - public function display_left() { |
|
79 | - $earnings = new GetPaid_Reports_Report_Earnings(); |
|
80 | - $earnings->display(); |
|
81 | - } |
|
74 | + /** |
|
75 | + * Displays the left side. |
|
76 | + * |
|
77 | + */ |
|
78 | + public function display_left() { |
|
79 | + $earnings = new GetPaid_Reports_Report_Earnings(); |
|
80 | + $earnings->display(); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Displays the right side. |
|
85 | - * |
|
86 | - */ |
|
87 | - public function display_right() { |
|
83 | + /** |
|
84 | + * Displays the right side. |
|
85 | + * |
|
86 | + */ |
|
87 | + public function display_right() { |
|
88 | 88 | |
89 | - ?> |
|
89 | + ?> |
|
90 | 90 | |
91 | 91 | <?php foreach ( $this->views as $view ) : ?> |
92 | 92 | <div class="row mb-4"> |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | </div> |
98 | 98 | <div class="card-body"> |
99 | 99 | <?php |
100 | - $class = $view['class']; |
|
101 | - $class = new $class(); |
|
102 | - $class->display_stats(); |
|
103 | - ?> |
|
100 | + $class = $view['class']; |
|
101 | + $class = new $class(); |
|
102 | + $class->display_stats(); |
|
103 | + ?> |
|
104 | 104 | </div> |
105 | 105 | </div> |
106 | 106 | </div> |
@@ -109,6 +109,6 @@ discard block |
||
109 | 109 | |
110 | 110 | <?php |
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
@@ -12,17 +12,17 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Gateways extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves the earning sql. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function get_sql( $range ) { |
|
20 | - global $wpdb; |
|
15 | + /** |
|
16 | + * Retrieves the earning sql. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function get_sql( $range ) { |
|
20 | + global $wpdb; |
|
21 | 21 | |
22 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | - $clauses = $this->get_range_sql( $range ); |
|
22 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | + $clauses = $this->get_range_sql( $range ); |
|
24 | 24 | |
25 | - $sql = "SELECT |
|
25 | + $sql = "SELECT |
|
26 | 26 | meta.gateway AS gateway, |
27 | 27 | SUM(total) as total |
28 | 28 | FROM $wpdb->posts |
@@ -35,91 +35,91 @@ discard block |
||
35 | 35 | ORDER BY total DESC |
36 | 36 | "; |
37 | 37 | |
38 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
38 | + return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Prepares the report stats. |
|
44 | - * |
|
45 | - */ |
|
46 | - public function prepare_stats() { |
|
47 | - global $wpdb; |
|
48 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
49 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Prepares the report stats. |
|
44 | + * |
|
45 | + */ |
|
46 | + public function prepare_stats() { |
|
47 | + global $wpdb; |
|
48 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
49 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Normalizes the report stats. |
|
54 | - * |
|
55 | - */ |
|
56 | - public function normalize_stats( $stats ) { |
|
57 | - $normalized = array(); |
|
58 | - $others = 0; |
|
59 | - $did = 0; |
|
52 | + /** |
|
53 | + * Normalizes the report stats. |
|
54 | + * |
|
55 | + */ |
|
56 | + public function normalize_stats( $stats ) { |
|
57 | + $normalized = array(); |
|
58 | + $others = 0; |
|
59 | + $did = 0; |
|
60 | 60 | |
61 | - foreach ( $stats as $stat ) { |
|
61 | + foreach ( $stats as $stat ) { |
|
62 | 62 | |
63 | - if ( $did > 4 ) { |
|
63 | + if ( $did > 4 ) { |
|
64 | 64 | |
65 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
65 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
66 | 66 | |
67 | - } else { |
|
67 | + } else { |
|
68 | 68 | |
69 | - $normalized[] = array( |
|
70 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
71 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
72 | - ); |
|
69 | + $normalized[] = array( |
|
70 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
71 | + 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
72 | + ); |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - $did++; |
|
77 | - } |
|
76 | + $did++; |
|
77 | + } |
|
78 | 78 | |
79 | - if ( $others > 0 ) { |
|
79 | + if ( $others > 0 ) { |
|
80 | 80 | |
81 | - $normalized[] = array( |
|
82 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
83 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
84 | - ); |
|
81 | + $normalized[] = array( |
|
82 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
83 | + 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
84 | + ); |
|
85 | 85 | |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - return $normalized; |
|
89 | - } |
|
88 | + return $normalized; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Retrieves report data. |
|
93 | - * |
|
94 | - */ |
|
95 | - public function get_data() { |
|
91 | + /** |
|
92 | + * Retrieves report data. |
|
93 | + * |
|
94 | + */ |
|
95 | + public function get_data() { |
|
96 | 96 | |
97 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
98 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
97 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
98 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
99 | 99 | |
100 | - shuffle( $colors ); |
|
100 | + shuffle( $colors ); |
|
101 | 101 | |
102 | - return array( |
|
103 | - 'data' => $data, |
|
104 | - 'backgroundColor' => $colors, |
|
105 | - ); |
|
102 | + return array( |
|
103 | + 'data' => $data, |
|
104 | + 'backgroundColor' => $colors, |
|
105 | + ); |
|
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Retrieves report labels. |
|
111 | - * |
|
112 | - */ |
|
113 | - public function get_labels() { |
|
114 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
115 | - } |
|
109 | + /** |
|
110 | + * Retrieves report labels. |
|
111 | + * |
|
112 | + */ |
|
113 | + public function get_labels() { |
|
114 | + return wp_list_pluck( $this->stats, 'gateway' ); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Displays the actual report. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function display_stats() { |
|
122 | - ?> |
|
117 | + /** |
|
118 | + * Displays the actual report. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function display_stats() { |
|
122 | + ?> |
|
123 | 123 | |
124 | 124 | <canvas id="getpaid-chartjs-earnings-gateways"></canvas> |
125 | 125 | |
@@ -148,6 +148,6 @@ discard block |
||
148 | 148 | </script> |
149 | 149 | |
150 | 150 | <?php |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | 153 | } |
@@ -12,17 +12,17 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves the discounts sql. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function get_sql( $range ) { |
|
20 | - global $wpdb; |
|
15 | + /** |
|
16 | + * Retrieves the discounts sql. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function get_sql( $range ) { |
|
20 | + global $wpdb; |
|
21 | 21 | |
22 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | - $clauses = $this->get_range_sql( $range ); |
|
22 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
23 | + $clauses = $this->get_range_sql( $range ); |
|
24 | 24 | |
25 | - $sql = "SELECT |
|
25 | + $sql = "SELECT |
|
26 | 26 | meta.discount_code AS discount_code, |
27 | 27 | SUM(total) as total |
28 | 28 | FROM $wpdb->posts |
@@ -36,91 +36,91 @@ discard block |
||
36 | 36 | ORDER BY total DESC |
37 | 37 | "; |
38 | 38 | |
39 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
39 | + return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Prepares the report stats. |
|
45 | - * |
|
46 | - */ |
|
47 | - public function prepare_stats() { |
|
48 | - global $wpdb; |
|
49 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
50 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
51 | - } |
|
43 | + /** |
|
44 | + * Prepares the report stats. |
|
45 | + * |
|
46 | + */ |
|
47 | + public function prepare_stats() { |
|
48 | + global $wpdb; |
|
49 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
50 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Normalizes the report stats. |
|
55 | - * |
|
56 | - */ |
|
57 | - public function normalize_stats( $stats ) { |
|
58 | - $normalized = array(); |
|
59 | - $others = 0; |
|
60 | - $did = 0; |
|
53 | + /** |
|
54 | + * Normalizes the report stats. |
|
55 | + * |
|
56 | + */ |
|
57 | + public function normalize_stats( $stats ) { |
|
58 | + $normalized = array(); |
|
59 | + $others = 0; |
|
60 | + $did = 0; |
|
61 | 61 | |
62 | - foreach ( $stats as $stat ) { |
|
62 | + foreach ( $stats as $stat ) { |
|
63 | 63 | |
64 | - if ( $did > 4 ) { |
|
64 | + if ( $did > 4 ) { |
|
65 | 65 | |
66 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
66 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
67 | 67 | |
68 | - } else { |
|
68 | + } else { |
|
69 | 69 | |
70 | - $normalized[] = array( |
|
71 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
72 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
73 | - ); |
|
70 | + $normalized[] = array( |
|
71 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
72 | + 'discount_code' => strip_tags( $stat->discount_code ), |
|
73 | + ); |
|
74 | 74 | |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - $did++; |
|
78 | - } |
|
77 | + $did++; |
|
78 | + } |
|
79 | 79 | |
80 | - if ( $others > 0 ) { |
|
80 | + if ( $others > 0 ) { |
|
81 | 81 | |
82 | - $normalized[] = array( |
|
83 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
84 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
85 | - ); |
|
82 | + $normalized[] = array( |
|
83 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
84 | + 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
85 | + ); |
|
86 | 86 | |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - return $normalized; |
|
90 | - } |
|
89 | + return $normalized; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Retrieves report data. |
|
94 | - * |
|
95 | - */ |
|
96 | - public function get_data() { |
|
92 | + /** |
|
93 | + * Retrieves report data. |
|
94 | + * |
|
95 | + */ |
|
96 | + public function get_data() { |
|
97 | 97 | |
98 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
99 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
98 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
99 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
100 | 100 | |
101 | - shuffle( $colors ); |
|
101 | + shuffle( $colors ); |
|
102 | 102 | |
103 | - return array( |
|
104 | - 'data' => $data, |
|
105 | - 'backgroundColor' => $colors, |
|
106 | - ); |
|
103 | + return array( |
|
104 | + 'data' => $data, |
|
105 | + 'backgroundColor' => $colors, |
|
106 | + ); |
|
107 | 107 | |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Retrieves report labels. |
|
112 | - * |
|
113 | - */ |
|
114 | - public function get_labels() { |
|
115 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
116 | - } |
|
110 | + /** |
|
111 | + * Retrieves report labels. |
|
112 | + * |
|
113 | + */ |
|
114 | + public function get_labels() { |
|
115 | + return wp_list_pluck( $this->stats, 'discount_code' ); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Displays the actual report. |
|
120 | - * |
|
121 | - */ |
|
122 | - public function display_stats() { |
|
123 | - ?> |
|
118 | + /** |
|
119 | + * Displays the actual report. |
|
120 | + * |
|
121 | + */ |
|
122 | + public function display_stats() { |
|
123 | + ?> |
|
124 | 124 | |
125 | 125 | <canvas id="getpaid-chartjs-earnings-discount_code"></canvas> |
126 | 126 | |
@@ -149,6 +149,6 @@ discard block |
||
149 | 149 | </script> |
150 | 150 | |
151 | 151 | <?php |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | } |
@@ -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( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
100 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
101 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
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 | } |