Passed
Push — master ( 8cc3cf...2975b0 )
by Brian
04:06
created
includes/reports/class-getpaid-reports-report-earnings.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -12,43 +12,43 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report_Earnings extends GetPaid_Reports_Abstract_Report {
14 14
 
15
-	/**
16
-	 * Retrieves the earning graphs.
17
-	 *
18
-	 */
19
-	public function get_graphs() {
15
+    /**
16
+     * Retrieves the earning graphs.
17
+     *
18
+     */
19
+    public function get_graphs() {
20 20
 
21
-		$graphs = array(
21
+        $graphs = array(
22 22
 
23 23
             'total'      => __( 'Earnings', 'invoicing' ),
24 24
             'discount'   => __( 'Discount', 'invoicing' ),
25
-			'fees_total' => __( 'Fees', 'invoicing' ),
26
-			'tax'        => __( 'Tax', 'invoicing' ),
25
+            'fees_total' => __( 'Fees', 'invoicing' ),
26
+            'tax'        => __( 'Tax', 'invoicing' ),
27 27
 
28
-		);
28
+        );
29 29
 
30
-		return apply_filters( 'getpaid_earning_graphs', $graphs );
30
+        return apply_filters( 'getpaid_earning_graphs', $graphs );
31 31
 
32
-	}
32
+    }
33 33
 
34
-	/**
35
-	 * Retrieves the earning sql.
36
-	 *
37
-	 */
38
-	public function get_sql( $range ) {
39
-		global $wpdb;
34
+    /**
35
+     * Retrieves the earning sql.
36
+     *
37
+     */
38
+    public function get_sql( $range ) {
39
+        global $wpdb;
40 40
 
41
-		$table      = $wpdb->prefix . 'getpaid_invoices';
42
-		$clauses    = $this->get_range_sql( $range );
43
-		$graphs     = array_keys( $this->get_graphs() );
44
-		$graphs_sql = array();
41
+        $table      = $wpdb->prefix . 'getpaid_invoices';
42
+        $clauses    = $this->get_range_sql( $range );
43
+        $graphs     = array_keys( $this->get_graphs() );
44
+        $graphs_sql = array();
45 45
 
46
-		foreach ( $graphs as $graph ) {
47
-			$graphs_sql[] = "SUM( meta.$graph ) AS $graph";
48
-		}
46
+        foreach ( $graphs as $graph ) {
47
+            $graphs_sql[] = "SUM( meta.$graph ) AS $graph";
48
+        }
49 49
 
50
-		$graphs_sql = implode( ', ', $graphs_sql );
51
-		$sql        = "SELECT {$clauses[0]} AS completed_date, $graphs_sql
50
+        $graphs_sql = implode( ', ', $graphs_sql );
51
+        $sql        = "SELECT {$clauses[0]} AS completed_date, $graphs_sql
52 52
             FROM $wpdb->posts
53 53
             LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID
54 54
             WHERE meta.post_id IS NOT NULL
@@ -58,94 +58,94 @@  discard block
 block discarded – undo
58 58
             GROUP BY {$clauses[0]}
59 59
         ";
60 60
 
61
-		return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range );
62
-
63
-	}
64
-
65
-	/**
66
-	 * Prepares the report stats.
67
-	 *
68
-	 */
69
-	public function prepare_stats() {
70
-		global $wpdb;
71
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
72
-	}
73
-
74
-	/**
75
-	 * Retrieves report labels.
76
-	 *
77
-	 */
78
-	public function get_labels( $range ) {
79
-
80
-		$labels = array(
81
-			'today'     => $this->get_hours_in_a_day(),
82
-			'yesterday' => $this->get_hours_in_a_day(),
83
-			'7_days'    => $this->get_days_in_period( 7 ),
84
-			'30_days'   => $this->get_days_in_period( 30 ),
85
-			'60_days'   => $this->get_days_in_period( 60 ),
86
-			'90_days'   => $this->get_weeks_in_period( 90 ),
87
-			'180_days'  => $this->get_weeks_in_period( 180 ),
88
-			'360_days'  => $this->get_weeks_in_period( 360 ),
89
-		);
90
-
91
-		$label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ];
92
-		return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range );
93
-	}
94
-
95
-	/**
96
-	 * Retrieves report datasets.
97
-	 *
98
-	 */
99
-	public function get_datasets( $labels ) {
100
-
101
-		$datasets = array();
102
-
103
-		foreach ( $this->get_graphs() as $key => $label ) {
104
-			$datasets[ $key ] = array(
105
-				'label' => $label,
106
-				'data'  => $this->get_data( $key, $labels )
107
-			);
108
-		}
109
-
110
-		return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels );
111
-	}
112
-
113
-	/**
114
-	 * Retrieves report data.
115
-	 *
116
-	 */
117
-	public function get_data( $key, $labels ) {
118
-
119
-		$data     = wp_list_pluck( $this->stats, $key, 'completed_date' );
120
-		$prepared = array();
121
-
122
-		foreach ( $labels as $label ) {
123
-
124
-			$value = 0;
125
-			if ( isset( $data[ $label ] ) ) {
126
-				$value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) );
127
-			}
128
-
129
-			$prepared[] = $value;
130
-		}
131
-
132
-		return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels );
133
-
134
-	}
135
-
136
-	/**
137
-	 * Displays the report card.
138
-	 *
139
-	 */
140
-	public function display() {
141
-
142
-		$labels     = $this->get_labels( $this->get_range() );
143
-		$chart_data = array(
144
-			'labels'   => array_values( $labels ),
145
-			'datasets' => $this->get_datasets( array_keys( $labels ) ),
146
-		);
147
-
148
-		?>
61
+        return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range );
62
+
63
+    }
64
+
65
+    /**
66
+     * Prepares the report stats.
67
+     *
68
+     */
69
+    public function prepare_stats() {
70
+        global $wpdb;
71
+        $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
72
+    }
73
+
74
+    /**
75
+     * Retrieves report labels.
76
+     *
77
+     */
78
+    public function get_labels( $range ) {
79
+
80
+        $labels = array(
81
+            'today'     => $this->get_hours_in_a_day(),
82
+            'yesterday' => $this->get_hours_in_a_day(),
83
+            '7_days'    => $this->get_days_in_period( 7 ),
84
+            '30_days'   => $this->get_days_in_period( 30 ),
85
+            '60_days'   => $this->get_days_in_period( 60 ),
86
+            '90_days'   => $this->get_weeks_in_period( 90 ),
87
+            '180_days'  => $this->get_weeks_in_period( 180 ),
88
+            '360_days'  => $this->get_weeks_in_period( 360 ),
89
+        );
90
+
91
+        $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ];
92
+        return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range );
93
+    }
94
+
95
+    /**
96
+     * Retrieves report datasets.
97
+     *
98
+     */
99
+    public function get_datasets( $labels ) {
100
+
101
+        $datasets = array();
102
+
103
+        foreach ( $this->get_graphs() as $key => $label ) {
104
+            $datasets[ $key ] = array(
105
+                'label' => $label,
106
+                'data'  => $this->get_data( $key, $labels )
107
+            );
108
+        }
109
+
110
+        return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels );
111
+    }
112
+
113
+    /**
114
+     * Retrieves report data.
115
+     *
116
+     */
117
+    public function get_data( $key, $labels ) {
118
+
119
+        $data     = wp_list_pluck( $this->stats, $key, 'completed_date' );
120
+        $prepared = array();
121
+
122
+        foreach ( $labels as $label ) {
123
+
124
+            $value = 0;
125
+            if ( isset( $data[ $label ] ) ) {
126
+                $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) );
127
+            }
128
+
129
+            $prepared[] = $value;
130
+        }
131
+
132
+        return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels );
133
+
134
+    }
135
+
136
+    /**
137
+     * Displays the report card.
138
+     *
139
+     */
140
+    public function display() {
141
+
142
+        $labels     = $this->get_labels( $this->get_range() );
143
+        $chart_data = array(
144
+            'labels'   => array_values( $labels ),
145
+            'datasets' => $this->get_datasets( array_keys( $labels ) ),
146
+        );
147
+
148
+        ?>
149 149
 
150 150
 			<?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?>
151 151
 				<div class="row mb-4">
@@ -165,15 +165,15 @@  discard block
 block discarded – undo
165 165
 
166 166
 		<?php
167 167
 
168
-	}
168
+    }
169 169
 
170
-	/**
171
-	 * Displays the actual report.
172
-	 *
173
-	 */
174
-	public function display_graph( $key, $dataset, $labels ) {
170
+    /**
171
+     * Displays the actual report.
172
+     *
173
+     */
174
+    public function display_graph( $key, $dataset, $labels ) {
175 175
 
176
-		?>
176
+        ?>
177 177
 
178 178
 		<canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>"></canvas>
179 179
 
@@ -223,49 +223,49 @@  discard block
 block discarded – undo
223 223
 		</script>
224 224
 
225 225
 		<?php
226
-	}
226
+    }
227 227
 
228
-	/**
229
-	 * Displays the actual report.
230
-	 *
231
-	 */
232
-	public function display_stats() {}
228
+    /**
229
+     * Displays the actual report.
230
+     *
231
+     */
232
+    public function display_stats() {}
233 233
 
234
-	/**
235
-	 * Displays the range selector.
236
-	 *
237
-	 */
238
-	public function display_range_selector() {
234
+    /**
235
+     * Displays the range selector.
236
+     *
237
+     */
238
+    public function display_range_selector() {
239 239
 
240
-		?>
240
+        ?>
241 241
 
242 242
 			<form method="get" class="getpaid-filter-earnings">
243 243
 				<?php
244 244
 
245
-					getpaid_hidden_field( 'page', 'wpinv-reports' );
246
-					getpaid_hidden_field( 'tab', 'reports' );
247
-
248
-					$html = aui()->select(
249
-						array(
250
-							'name'        => 'date_range',
251
-							'id'          => 'view' . uniqid( '_' ),
252
-							'placeholder' => __( 'Select a date range', 'invoicing' ),
253
-							'label'       => __( 'Date Range', 'invoicing' ),
254
-							'options'     => $this->get_periods(),
255
-							'value'       => $this->get_range(),
256
-							'no_wrap'     => true,
257
-							'extra_attributes' => array(
258
-								'onChange'        => 'this.form.submit()',
259
-							),
260
-						)
261
-					);
262
-
263
-					echo str_replace( 'custom-select', '', $html );
264
-				?>
245
+                    getpaid_hidden_field( 'page', 'wpinv-reports' );
246
+                    getpaid_hidden_field( 'tab', 'reports' );
247
+
248
+                    $html = aui()->select(
249
+                        array(
250
+                            'name'        => 'date_range',
251
+                            'id'          => 'view' . uniqid( '_' ),
252
+                            'placeholder' => __( 'Select a date range', 'invoicing' ),
253
+                            'label'       => __( 'Date Range', 'invoicing' ),
254
+                            'options'     => $this->get_periods(),
255
+                            'value'       => $this->get_range(),
256
+                            'no_wrap'     => true,
257
+                            'extra_attributes' => array(
258
+                                'onChange'        => 'this.form.submit()',
259
+                            ),
260
+                        )
261
+                    );
262
+
263
+                    echo str_replace( 'custom-select', '', $html );
264
+                ?>
265 265
 
266 266
 			</form>
267 267
 
268 268
 		<?php
269
-	}
269
+    }
270 270
 
271 271
 }
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-maxmind-geolocation.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -16,164 +16,164 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-discounts.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -12,22 +12,22 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report {
14 14
 
15
-	/**
16
-	 * @var string
17
-	 */
18
-	public $field = 'discount_code';
19
-
20
-	/**
21
-	 * Retrieves the discounts sql.
22
-	 *
23
-	 */
24
-	public function get_sql( $range ) {
25
-		global $wpdb;
26
-
27
-		$table      = $wpdb->prefix . 'getpaid_invoices';
28
-		$clauses    = $this->get_range_sql( $range );
29
-
30
-		$sql        = "SELECT
15
+    /**
16
+     * @var string
17
+     */
18
+    public $field = 'discount_code';
19
+
20
+    /**
21
+     * Retrieves the discounts sql.
22
+     *
23
+     */
24
+    public function get_sql( $range ) {
25
+        global $wpdb;
26
+
27
+        $table      = $wpdb->prefix . 'getpaid_invoices';
28
+        $clauses    = $this->get_range_sql( $range );
29
+
30
+        $sql        = "SELECT
31 31
 				meta.discount_code AS discount_code,
32 32
 				SUM(total) as total
33 33
             FROM $wpdb->posts
@@ -41,91 +41,91 @@  discard block
 block discarded – undo
41 41
 			ORDER BY total DESC
42 42
         ";
43 43
 
44
-		return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range );
44
+        return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range );
45 45
 
46
-	}
46
+    }
47 47
 
48
-	/**
49
-	 * Prepares the report stats.
50
-	 *
51
-	 */
52
-	public function prepare_stats() {
53
-		global $wpdb;
54
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
55
-		$this->stats = $this->normalize_stats( $this->stats );
56
-	}
48
+    /**
49
+     * Prepares the report stats.
50
+     *
51
+     */
52
+    public function prepare_stats() {
53
+        global $wpdb;
54
+        $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
55
+        $this->stats = $this->normalize_stats( $this->stats );
56
+    }
57 57
 
58
-	/**
59
-	 * Normalizes the report stats.
60
-	 *
61
-	 */
62
-	public function normalize_stats( $stats ) {
63
-		$normalized = array();
64
-		$others     = 0;
65
-		$did        = 0;
58
+    /**
59
+     * Normalizes the report stats.
60
+     *
61
+     */
62
+    public function normalize_stats( $stats ) {
63
+        $normalized = array();
64
+        $others     = 0;
65
+        $did        = 0;
66 66
 
67
-		foreach ( $stats as $stat ) {
67
+        foreach ( $stats as $stat ) {
68 68
 
69
-			if ( $did > 4 ) {
69
+            if ( $did > 4 ) {
70 70
 
71
-				$others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
71
+                $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
72 72
 
73
-			} else {
73
+            } else {
74 74
 
75
-				$normalized[] = array(
76
-					'total'         => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
77
-					'discount_code' => strip_tags( $stat->discount_code ),
78
-				);
75
+                $normalized[] = array(
76
+                    'total'         => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
77
+                    'discount_code' => strip_tags( $stat->discount_code ),
78
+                );
79 79
 
80
-			}
80
+            }
81 81
 
82
-			$did++;
83
-		}
82
+            $did++;
83
+        }
84 84
 
85
-		if ( $others > 0 ) {
85
+        if ( $others > 0 ) {
86 86
 
87
-			$normalized[] = array(
88
-				'total'         => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
89
-				'discount_code' => esc_html__( 'Others', 'invoicing' ),
90
-			);
87
+            $normalized[] = array(
88
+                'total'         => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
89
+                'discount_code' => esc_html__( 'Others', 'invoicing' ),
90
+            );
91 91
 
92
-		}
92
+        }
93 93
 
94
-		return $normalized;
95
-	}
94
+        return $normalized;
95
+    }
96 96
 
97
-	/**
98
-	 * Retrieves report data.
99
-	 *
100
-	 */
101
-	public function get_data() {
97
+    /**
98
+     * Retrieves report data.
99
+     *
100
+     */
101
+    public function get_data() {
102 102
 
103
-		$data     = wp_list_pluck( $this->stats, 'total' );
104
-		$colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
103
+        $data     = wp_list_pluck( $this->stats, 'total' );
104
+        $colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
105 105
 
106
-		shuffle( $colors );
106
+        shuffle( $colors );
107 107
 
108
-		return array(
109
-			'data'            => $data,
110
-			'backgroundColor' => $colors,
111
-		);
108
+        return array(
109
+            'data'            => $data,
110
+            'backgroundColor' => $colors,
111
+        );
112 112
 
113
-	}
113
+    }
114 114
 
115
-	/**
116
-	 * Retrieves report labels.
117
-	 *
118
-	 */
119
-	public function get_labels() {
120
-		return wp_list_pluck( $this->stats, 'discount_code' );
121
-	}
115
+    /**
116
+     * Retrieves report labels.
117
+     *
118
+     */
119
+    public function get_labels() {
120
+        return wp_list_pluck( $this->stats, 'discount_code' );
121
+    }
122 122
 
123
-	/**
124
-	 * Displays the actual report.
125
-	 *
126
-	 */
127
-	public function display_stats() {
128
-		?>
123
+    /**
124
+     * Displays the actual report.
125
+     *
126
+     */
127
+    public function display_stats() {
128
+        ?>
129 129
 
130 130
 			<canvas id="getpaid-chartjs-earnings-discount_code"></canvas>
131 131
 
@@ -154,6 +154,6 @@  discard block
 block discarded – undo
154 154
 			</script>
155 155
 
156 156
 		<?php
157
-	}
157
+    }
158 158
 
159 159
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-items.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report {
14 14
 
15
-	/**
16
-	 * @var string
17
-	 */
18
-	public $field = 'item_name';
19
-
20
-	/**
21
-	 * Retrieves the earning sql.
22
-	 *
23
-	 */
24
-	public function get_sql( $range ) {
25
-		global $wpdb;
26
-
27
-		$table      = $wpdb->prefix . 'getpaid_invoices';
28
-		$table2     = $wpdb->prefix . 'getpaid_invoice_items';
29
-		$clauses    = $this->get_range_sql( $range );
30
-
31
-		$sql        = "SELECT
15
+    /**
16
+     * @var string
17
+     */
18
+    public $field = 'item_name';
19
+
20
+    /**
21
+     * Retrieves the earning sql.
22
+     *
23
+     */
24
+    public function get_sql( $range ) {
25
+        global $wpdb;
26
+
27
+        $table      = $wpdb->prefix . 'getpaid_invoices';
28
+        $table2     = $wpdb->prefix . 'getpaid_invoice_items';
29
+        $clauses    = $this->get_range_sql( $range );
30
+
31
+        $sql        = "SELECT
32 32
 				item.item_name AS item_name,
33 33
 				item.item_id AS item_id,
34 34
 				SUM(price) as total
@@ -43,91 +43,91 @@  discard block
 block discarded – undo
43 43
 			ORDER BY total DESC
44 44
         ";
45 45
 
46
-		return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range );
46
+        return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range );
47 47
 
48
-	}
48
+    }
49 49
 
50
-	/**
51
-	 * Prepares the report stats.
52
-	 *
53
-	 */
54
-	public function prepare_stats() {
55
-		global $wpdb;
56
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
57
-		$this->stats = $this->normalize_stats( $this->stats );
58
-	}
50
+    /**
51
+     * Prepares the report stats.
52
+     *
53
+     */
54
+    public function prepare_stats() {
55
+        global $wpdb;
56
+        $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
57
+        $this->stats = $this->normalize_stats( $this->stats );
58
+    }
59 59
 
60
-	/**
61
-	 * Normalizes the report stats.
62
-	 *
63
-	 */
64
-	public function normalize_stats( $stats ) {
65
-		$normalized = array();
66
-		$others     = 0;
67
-		$did        = 0;
60
+    /**
61
+     * Normalizes the report stats.
62
+     *
63
+     */
64
+    public function normalize_stats( $stats ) {
65
+        $normalized = array();
66
+        $others     = 0;
67
+        $did        = 0;
68 68
 
69
-		foreach ( $stats as $stat ) {
69
+        foreach ( $stats as $stat ) {
70 70
 
71
-			if ( $did > 4 ) {
71
+            if ( $did > 4 ) {
72 72
 
73
-				$others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
73
+                $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
74 74
 
75
-			} else {
75
+            } else {
76 76
 
77
-				$normalized[] = array(
78
-					'total'     => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
79
-					'item_name' => strip_tags( $stat->item_name ),
80
-				);
77
+                $normalized[] = array(
78
+                    'total'     => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
79
+                    'item_name' => strip_tags( $stat->item_name ),
80
+                );
81 81
 
82
-			}
82
+            }
83 83
 
84
-			$did++;
85
-		}
84
+            $did++;
85
+        }
86 86
 
87
-		if ( $others > 0 ) {
87
+        if ( $others > 0 ) {
88 88
 
89
-			$normalized[] = array(
90
-				'total'     => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
91
-				'item_name' => esc_html__( 'Others', 'invoicing' ),
92
-			);
89
+            $normalized[] = array(
90
+                'total'     => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
91
+                'item_name' => esc_html__( 'Others', 'invoicing' ),
92
+            );
93 93
 
94
-		}
94
+        }
95 95
 
96
-		return $normalized;
97
-	}
96
+        return $normalized;
97
+    }
98 98
 
99
-	/**
100
-	 * Retrieves report data.
101
-	 *
102
-	 */
103
-	public function get_data() {
99
+    /**
100
+     * Retrieves report data.
101
+     *
102
+     */
103
+    public function get_data() {
104 104
 
105
-		$data     = wp_list_pluck( $this->stats, 'total' );
106
-		$colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
105
+        $data     = wp_list_pluck( $this->stats, 'total' );
106
+        $colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
107 107
 
108
-		shuffle( $colors );
108
+        shuffle( $colors );
109 109
 
110
-		return array(
111
-			'data'            => $data,
112
-			'backgroundColor' => $colors,
113
-		);
110
+        return array(
111
+            'data'            => $data,
112
+            'backgroundColor' => $colors,
113
+        );
114 114
 
115
-	}
115
+    }
116 116
 
117
-	/**
118
-	 * Retrieves report labels.
119
-	 *
120
-	 */
121
-	public function get_labels() {
122
-		return wp_list_pluck( $this->stats, 'item_name' );
123
-	}
117
+    /**
118
+     * Retrieves report labels.
119
+     *
120
+     */
121
+    public function get_labels() {
122
+        return wp_list_pluck( $this->stats, 'item_name' );
123
+    }
124 124
 
125
-	/**
126
-	 * Displays the actual report.
127
-	 *
128
-	 */
129
-	public function display_stats() {
130
-		?>
125
+    /**
126
+     * Displays the actual report.
127
+     *
128
+     */
129
+    public function display_stats() {
130
+        ?>
131 131
 
132 132
 			<canvas id="getpaid-chartjs-earnings-items"></canvas>
133 133
 
@@ -156,6 +156,6 @@  discard block
 block discarded – undo
156 156
 			</script>
157 157
 
158 158
 		<?php
159
-	}
159
+    }
160 160
 
161 161
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-gateways.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -12,22 +12,22 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report_Gateways extends GetPaid_Reports_Abstract_Report {
14 14
 
15
-	/**
16
-	 * @var string
17
-	 */
18
-	public $field = 'gateway';
19
-
20
-	/**
21
-	 * Retrieves the earning sql.
22
-	 *
23
-	 */
24
-	public function get_sql( $range ) {
25
-		global $wpdb;
26
-
27
-		$table      = $wpdb->prefix . 'getpaid_invoices';
28
-		$clauses    = $this->get_range_sql( $range );
29
-
30
-		$sql        = "SELECT
15
+    /**
16
+     * @var string
17
+     */
18
+    public $field = 'gateway';
19
+
20
+    /**
21
+     * Retrieves the earning sql.
22
+     *
23
+     */
24
+    public function get_sql( $range ) {
25
+        global $wpdb;
26
+
27
+        $table      = $wpdb->prefix . 'getpaid_invoices';
28
+        $clauses    = $this->get_range_sql( $range );
29
+
30
+        $sql        = "SELECT
31 31
 				meta.gateway AS gateway,
32 32
 				SUM(total) as total
33 33
             FROM $wpdb->posts
@@ -40,91 +40,91 @@  discard block
 block discarded – undo
40 40
 			ORDER BY total DESC
41 41
         ";
42 42
 
43
-		return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range );
43
+        return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range );
44 44
 
45
-	}
45
+    }
46 46
 
47
-	/**
48
-	 * Prepares the report stats.
49
-	 *
50
-	 */
51
-	public function prepare_stats() {
52
-		global $wpdb;
53
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
54
-		$this->stats = $this->normalize_stats( $this->stats );
55
-	}
47
+    /**
48
+     * Prepares the report stats.
49
+     *
50
+     */
51
+    public function prepare_stats() {
52
+        global $wpdb;
53
+        $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
54
+        $this->stats = $this->normalize_stats( $this->stats );
55
+    }
56 56
 
57
-	/**
58
-	 * Normalizes the report stats.
59
-	 *
60
-	 */
61
-	public function normalize_stats( $stats ) {
62
-		$normalized = array();
63
-		$others     = 0;
64
-		$did        = 0;
57
+    /**
58
+     * Normalizes the report stats.
59
+     *
60
+     */
61
+    public function normalize_stats( $stats ) {
62
+        $normalized = array();
63
+        $others     = 0;
64
+        $did        = 0;
65 65
 
66
-		foreach ( $stats as $stat ) {
66
+        foreach ( $stats as $stat ) {
67 67
 
68
-			if ( $did > 4 ) {
68
+            if ( $did > 4 ) {
69 69
 
70
-				$others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
70
+                $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) );
71 71
 
72
-			} else {
72
+            } else {
73 73
 
74
-				$normalized[] = array(
75
-					'total'     => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
76
-					'gateway'   => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ),
77
-				);
74
+                $normalized[] = array(
75
+                    'total'     => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
76
+                    'gateway'   => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ),
77
+                );
78 78
 
79
-			}
79
+            }
80 80
 
81
-			$did++;
82
-		}
81
+            $did++;
82
+        }
83 83
 
84
-		if ( $others > 0 ) {
84
+        if ( $others > 0 ) {
85 85
 
86
-			$normalized[] = array(
87
-				'total'     => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
88
-				'gateway'   => esc_html__( 'Others', 'invoicing' ),
89
-			);
86
+            $normalized[] = array(
87
+                'total'     => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
88
+                'gateway'   => esc_html__( 'Others', 'invoicing' ),
89
+            );
90 90
 
91
-		}
91
+        }
92 92
 
93
-		return $normalized;
94
-	}
93
+        return $normalized;
94
+    }
95 95
 
96
-	/**
97
-	 * Retrieves report data.
98
-	 *
99
-	 */
100
-	public function get_data() {
96
+    /**
97
+     * Retrieves report data.
98
+     *
99
+     */
100
+    public function get_data() {
101 101
 
102
-		$data     = wp_list_pluck( $this->stats, 'total' );
103
-		$colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
102
+        $data     = wp_list_pluck( $this->stats, 'total' );
103
+        $colors   = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' );
104 104
 
105
-		shuffle( $colors );
105
+        shuffle( $colors );
106 106
 
107
-		return array(
108
-			'data'            => $data,
109
-			'backgroundColor' => $colors,
110
-		);
107
+        return array(
108
+            'data'            => $data,
109
+            'backgroundColor' => $colors,
110
+        );
111 111
 
112
-	}
112
+    }
113 113
 
114
-	/**
115
-	 * Retrieves report labels.
116
-	 *
117
-	 */
118
-	public function get_labels() {
119
-		return wp_list_pluck( $this->stats, 'gateway' );
120
-	}
114
+    /**
115
+     * Retrieves report labels.
116
+     *
117
+     */
118
+    public function get_labels() {
119
+        return wp_list_pluck( $this->stats, 'gateway' );
120
+    }
121 121
 
122
-	/**
123
-	 * Displays the actual report.
124
-	 *
125
-	 */
126
-	public function display_stats() {
127
-		?>
122
+    /**
123
+     * Displays the actual report.
124
+     *
125
+     */
126
+    public function display_stats() {
127
+        ?>
128 128
 
129 129
 			<canvas id="getpaid-chartjs-earnings-gateways"></canvas>
130 130
 
@@ -153,6 +153,6 @@  discard block
 block discarded – undo
153 153
 			</script>
154 154
 
155 155
 		<?php
156
-	}
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-graph-downloader.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -12,219 +12,219 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Reports_Report
17
-	 */
18
-	public $handler;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 */
24
-	public function __construct() {
25
-		$this->handler = new GetPaid_Reports_Report();
26
-	}
27
-
28
-	/**
29
-	 * Prepares the datastore handler.
30
-	 *
31
-	 * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32
-	 */
33
-	public function prepare_handler( $graph ) {
34
-
35
-		if ( empty( $this->handler->views[ $graph ] ) ) {
36
-			wp_die( __( 'Invalid Graph', 'invoicing' ), 400 );
37
-		}
38
-
39
-		return new $this->handler->views[ $graph ]['class']();
40
-
41
-	}
42
-
43
-	/**
44
-	 * Prepares the output stream.
45
-	 *
46
-	 * @return resource
47
-	 */
48
-	public function prepare_output() {
49
-
50
-		$output  = fopen( 'php://output', 'w' );
51
-
52
-		if ( false === $output ) {
53
-			wp_die( __( 'Unsupported server', 'invoicing' ), 500 );
54
-		}
55
-
56
-		return $output;
57
-	}
58
-
59
-	/**
60
-	 * Prepares the file type.
61
-	 *
62
-	 * @return string
63
-	 */
64
-	public function prepare_file_type( $graph ) {
65
-
66
-		$file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
-		$file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
68
-
69
-		header( "Content-Type:application/$file_type" );
70
-		header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
71
-
72
-		return $file_type;
73
-	}
74
-
75
-	/**
76
-	 * Handles the actual download.
77
-	 *
78
-	 */
79
-	public function download( $graph ) {
80
-		global $wpdb;
81
-
82
-		$handler   = $this->prepare_handler( $graph );
83
-		$stream    = $this->prepare_output();
84
-		$stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
-		$headers   = array( $handler->field, 'total', 'total_raw' );
86
-		$file_type = $this->prepare_file_type( $graph );
87
-
88
-		if ( 'csv' == $file_type ) {
89
-			$this->download_csv( $stats, $stream, $headers );
90
-		} else if( 'xml' == $file_type ) {
91
-			$this->download_xml( $stats, $stream, $headers );
92
-		} else {
93
-			$this->download_json( $stats, $stream, $headers );
94
-		}
95
-
96
-		fclose( $stream );
97
-		exit;
98
-	}
99
-
100
-	/**
101
-	 * Downloads graph as csv
102
-	 *
103
-	 * @param array $stats The stats being downloaded.
104
-	 * @param resource $stream The stream to output to.
105
-	 * @param array $headers The fields to stream.
106
-	 * @since       1.0.19
107
-	 */
108
-	public function download_csv( $stats, $stream, $headers ) {
109
-
110
-		// Output the csv column headers.
111
-		fputcsv( $stream, $headers );
112
-
113
-		// Loop through 
114
-		foreach ( $stats as $stat ) {
115
-			$row  = array_values( $this->prepare_row( $stat, $headers ) );
116
-			$row  = array_map( 'maybe_serialize', $row );
117
-			fputcsv( $stream, $row );
118
-		}
119
-
120
-	}
121
-
122
-	/**
123
-	 * Downloads graph as json
124
-	 *
125
-	 * @param array $stats The stats being downloaded.
126
-	 * @param resource $stream The stream to output to.
127
-	 * @param array $headers The fields to stream.
128
-	 * @since       1.0.19
129
-	 */
130
-	public function download_json( $stats, $stream, $headers ) {
131
-
132
-		$prepared = array();
133
-
134
-		// Loop through 
135
-		foreach ( $stats as $stat ) {
136
-			$prepared[] = $this->prepare_row( $stat, $headers );
137
-		}
138
-
139
-		fwrite( $stream, wp_json_encode( $prepared ) );
140
-
141
-	}
142
-
143
-	/**
144
-	 * Downloads graph as xml
145
-	 *
146
-	 * @param array $stats The stats being downloaded.
147
-	 * @param resource $stream The stream to output to.
148
-	 * @param array $headers The fields to stream.
149
-	 * @since       1.0.19
150
-	 */
151
-	public function download_xml( $stats, $stream, $headers ) {
152
-
153
-		$prepared = array();
154
-
155
-		// Loop through 
156
-		foreach ( $stats as $stat ) {
157
-			$prepared[] = $this->prepare_row( $stat, $headers );
158
-		}
159
-
160
-		$xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
161
-		$this->convert_array_xml( $prepared, $xml );
162
-
163
-		fwrite( $stream, $xml->asXML() );
164
-
165
-	}
166
-
167
-	/**
168
-	 * Converts stats array to xml
169
-	 *
170
-	 * @access      public
171
-	 * @since      1.0.19
172
-	 */
173
-	public function convert_array_xml( $data, $xml ) {
174
-
175
-		// Loop through 
176
-		foreach ( $data as $key => $value ) {
177
-
178
-			$key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key );
179
-
180
-			if ( is_array( $value ) ) {
181
-
182
-				if ( is_numeric( $key ) ){
183
-					$key = 'item'.$key; //dealing with <0/>..<n/> issues
184
-				}
185
-
186
-				$subnode = $xml->addChild( $key );
187
-				$this->convert_array_xml( $value, $subnode );
188
-
189
-			} else {
190
-				$xml->addChild( $key, htmlspecialchars( $value ) );
191
-			}
192
-
193
-		}
15
+    /**
16
+     * @var GetPaid_Reports_Report
17
+     */
18
+    public $handler;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     */
24
+    public function __construct() {
25
+        $this->handler = new GetPaid_Reports_Report();
26
+    }
27
+
28
+    /**
29
+     * Prepares the datastore handler.
30
+     *
31
+     * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32
+     */
33
+    public function prepare_handler( $graph ) {
34
+
35
+        if ( empty( $this->handler->views[ $graph ] ) ) {
36
+            wp_die( __( 'Invalid Graph', 'invoicing' ), 400 );
37
+        }
38
+
39
+        return new $this->handler->views[ $graph ]['class']();
40
+
41
+    }
42
+
43
+    /**
44
+     * Prepares the output stream.
45
+     *
46
+     * @return resource
47
+     */
48
+    public function prepare_output() {
49
+
50
+        $output  = fopen( 'php://output', 'w' );
51
+
52
+        if ( false === $output ) {
53
+            wp_die( __( 'Unsupported server', 'invoicing' ), 500 );
54
+        }
55
+
56
+        return $output;
57
+    }
58
+
59
+    /**
60
+     * Prepares the file type.
61
+     *
62
+     * @return string
63
+     */
64
+    public function prepare_file_type( $graph ) {
65
+
66
+        $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
+        $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
68
+
69
+        header( "Content-Type:application/$file_type" );
70
+        header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
71
+
72
+        return $file_type;
73
+    }
74
+
75
+    /**
76
+     * Handles the actual download.
77
+     *
78
+     */
79
+    public function download( $graph ) {
80
+        global $wpdb;
81
+
82
+        $handler   = $this->prepare_handler( $graph );
83
+        $stream    = $this->prepare_output();
84
+        $stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
+        $headers   = array( $handler->field, 'total', 'total_raw' );
86
+        $file_type = $this->prepare_file_type( $graph );
87
+
88
+        if ( 'csv' == $file_type ) {
89
+            $this->download_csv( $stats, $stream, $headers );
90
+        } else if( 'xml' == $file_type ) {
91
+            $this->download_xml( $stats, $stream, $headers );
92
+        } else {
93
+            $this->download_json( $stats, $stream, $headers );
94
+        }
95
+
96
+        fclose( $stream );
97
+        exit;
98
+    }
99
+
100
+    /**
101
+     * Downloads graph as csv
102
+     *
103
+     * @param array $stats The stats being downloaded.
104
+     * @param resource $stream The stream to output to.
105
+     * @param array $headers The fields to stream.
106
+     * @since       1.0.19
107
+     */
108
+    public function download_csv( $stats, $stream, $headers ) {
109
+
110
+        // Output the csv column headers.
111
+        fputcsv( $stream, $headers );
112
+
113
+        // Loop through 
114
+        foreach ( $stats as $stat ) {
115
+            $row  = array_values( $this->prepare_row( $stat, $headers ) );
116
+            $row  = array_map( 'maybe_serialize', $row );
117
+            fputcsv( $stream, $row );
118
+        }
119
+
120
+    }
121
+
122
+    /**
123
+     * Downloads graph as json
124
+     *
125
+     * @param array $stats The stats being downloaded.
126
+     * @param resource $stream The stream to output to.
127
+     * @param array $headers The fields to stream.
128
+     * @since       1.0.19
129
+     */
130
+    public function download_json( $stats, $stream, $headers ) {
131
+
132
+        $prepared = array();
133
+
134
+        // Loop through 
135
+        foreach ( $stats as $stat ) {
136
+            $prepared[] = $this->prepare_row( $stat, $headers );
137
+        }
138
+
139
+        fwrite( $stream, wp_json_encode( $prepared ) );
140
+
141
+    }
142
+
143
+    /**
144
+     * Downloads graph as xml
145
+     *
146
+     * @param array $stats The stats being downloaded.
147
+     * @param resource $stream The stream to output to.
148
+     * @param array $headers The fields to stream.
149
+     * @since       1.0.19
150
+     */
151
+    public function download_xml( $stats, $stream, $headers ) {
152
+
153
+        $prepared = array();
154
+
155
+        // Loop through 
156
+        foreach ( $stats as $stat ) {
157
+            $prepared[] = $this->prepare_row( $stat, $headers );
158
+        }
159
+
160
+        $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
161
+        $this->convert_array_xml( $prepared, $xml );
162
+
163
+        fwrite( $stream, $xml->asXML() );
164
+
165
+    }
166
+
167
+    /**
168
+     * Converts stats array to xml
169
+     *
170
+     * @access      public
171
+     * @since      1.0.19
172
+     */
173
+    public function convert_array_xml( $data, $xml ) {
174
+
175
+        // Loop through 
176
+        foreach ( $data as $key => $value ) {
177
+
178
+            $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key );
179
+
180
+            if ( is_array( $value ) ) {
181
+
182
+                if ( is_numeric( $key ) ){
183
+                    $key = 'item'.$key; //dealing with <0/>..<n/> issues
184
+                }
185
+
186
+                $subnode = $xml->addChild( $key );
187
+                $this->convert_array_xml( $value, $subnode );
188
+
189
+            } else {
190
+                $xml->addChild( $key, htmlspecialchars( $value ) );
191
+            }
192
+
193
+        }
194 194
 
195
-	}
196
-
197
-	/**
198
-	 * Prepares a single row for download.
199
-	 *
200
-	 * @param stdClass|array $row The row to prepare..
201
-	 * @param array $fields The fields to stream.
202
-	 * @since       1.0.19
203
-	 * @return array
204
-	 */
205
-	public function prepare_row( $row, $fields ) {
195
+    }
196
+
197
+    /**
198
+     * Prepares a single row for download.
199
+     *
200
+     * @param stdClass|array $row The row to prepare..
201
+     * @param array $fields The fields to stream.
202
+     * @since       1.0.19
203
+     * @return array
204
+     */
205
+    public function prepare_row( $row, $fields ) {
206 206
 
207
-		$prepared = array();
208
-		$row      = (array) $row;
207
+        $prepared = array();
208
+        $row      = (array) $row;
209 209
 
210
-		foreach ( $fields as $field ) {
210
+        foreach ( $fields as $field ) {
211 211
 
212
-			if ( $field === 'total' ) {
213
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
214
-				continue;
215
-			}
212
+            if ( $field === 'total' ) {
213
+                $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
214
+                continue;
215
+            }
216 216
 
217
-			if ( $field === 'total_raw' ) {
218
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
219
-				continue;
220
-			}
217
+            if ( $field === 'total_raw' ) {
218
+                $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
219
+                continue;
220
+            }
221 221
 
222
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
222
+            $prepared[ $field ] = strip_tags( $row[ $field ] );
223 223
 
224
-		}
224
+        }
225 225
 
226
-		return $prepared;
227
-	}
226
+        return $prepared;
227
+    }
228 228
 
229 229
 
230 230
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -12,46 +12,46 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		echo "</div>";
26
-
27
-	}
28
-
29
-	/**
30
-	 * Retrieves the download url.
31
-	 *
32
-	 */
33
-	public function get_download_url( $post_type ) {
34
-
35
-		return wp_nonce_url(
36
-			add_query_arg(
37
-				array(
38
-					'getpaid-admin-action' => 'export_invoices',
39
-					'post_type'            => urlencode( $post_type ),
40
-				)
41
-			),
42
-			'getpaid-nonce',
43
-			'getpaid-nonce'
44
-		);
45
-
46
-	}
47
-
48
-	/**
49
-	 * Displays a single post type export card.
50
-	 *
51
-	 */
52
-	public function display_post_type_export( $post_type ) {
53
-
54
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        echo "</div>";
26
+
27
+    }
28
+
29
+    /**
30
+     * Retrieves the download url.
31
+     *
32
+     */
33
+    public function get_download_url( $post_type ) {
34
+
35
+        return wp_nonce_url(
36
+            add_query_arg(
37
+                array(
38
+                    'getpaid-admin-action' => 'export_invoices',
39
+                    'post_type'            => urlencode( $post_type ),
40
+                )
41
+            ),
42
+            'getpaid-nonce',
43
+            'getpaid-nonce'
44
+        );
45
+
46
+    }
47
+
48
+    /**
49
+     * Displays a single post type export card.
50
+     *
51
+     */
52
+    public function display_post_type_export( $post_type ) {
53
+
54
+        ?>
55 55
 
56 56
 		<div class="col-12 col-md-6">
57 57
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 				<div class="card-header">
60 60
 					<strong>
61 61
 						<?php
62
-							printf(
63
-								__( 'Export %s', 'invoicing' ),
64
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
65
-							);
66
-						?>
62
+                            printf(
63
+                                __( 'Export %s', 'invoicing' ),
64
+                                sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
65
+                            );
66
+                        ?>
67 67
 					</strong>
68 68
 				</div>
69 69
 
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73 73
 
74 74
 						<?php
75
-							$this->display_markup( $this->generate_from_date( $post_type ) );
76
-							$this->display_markup( $this->generate_to_date( $post_type ) );
77
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
78
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
79
-							submit_button( __( 'Download', 'invoicing' ) );
80
-						?>
75
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
76
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
78
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
79
+                            submit_button( __( 'Download', 'invoicing' ) );
80
+                        ?>
81 81
 
82 82
 					</form>
83 83
 
@@ -88,107 +88,107 @@  discard block
 block discarded – undo
88 88
 
89 89
 		<?php
90 90
 
91
-	}
92
-
93
-	/**
94
-	 * Generates the from date input field.
95
-	 *
96
-	 */
97
-	public function generate_from_date( $post_type ) {
98
-
99
-		return aui()->input(
100
-			array(
101
-				'name'       => 'from_date',
102
-				'id'         => esc_attr( "$post_type-from_date" ),
103
-				'placeholder'=> 'yy-mm-dd',
104
-				'label'      => __( 'From Date', 'invoicing' ),
105
-				'label_type' => 'vertical',
106
-				'label_class' => 'd-block',
107
-				'type'       => 'datepicker',
108
-			)
109
-		);
110
-
111
-	}
112
-
113
-	/**
114
-	 * Generates the to date input field.
115
-	 *
116
-	 */
117
-	public function generate_to_date( $post_type ) {
118
-
119
-		return aui()->input(
120
-			array(
121
-				'name'       => 'to_date',
122
-				'id'         => esc_attr( "$post_type-to_date" ),
123
-				'placeholder'=> 'yy-mm-dd',
124
-				'label'      => __( 'To Date', 'invoicing' ),
125
-				'label_type' => 'vertical',
126
-				'label_class' => 'd-block',
127
-				'type'       => 'datepicker',
128
-			)
129
-		);
130
-
131
-	}
132
-
133
-	/**
134
-	 * Generates the to post status select field.
135
-	 *
136
-	 */
137
-	public function generate_post_status_select( $post_type ) {
138
-
139
-		return aui()->select(
140
-			array(
141
-				'name'        => 'status',
142
-				'id'          => esc_attr( "$post_type-status" ),
143
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
144
-				'label'       => __( 'Status', 'invoicing' ),
145
-				'label_type'  => 'vertical',
146
-				'label_class' => 'd-block',
147
-				'options'     => wpinv_get_invoice_statuses( true, false, $post_type ),
148
-			)
149
-		);
150
-
151
-	}
152
-
153
-	/**
154
-	 * Generates the to file type select field.
155
-	 *
156
-	 */
157
-	public function generate_file_type_select( $post_type ) {
158
-
159
-		return aui()->select(
160
-			array(
161
-				'name'        => 'file_type',
162
-				'id'          => esc_attr( "$post_type-file_type" ),
163
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
164
-				'label'       => __( 'Export File', 'invoicing' ),
165
-				'label_type'  => 'vertical',
166
-				'label_class' => 'd-block',
167
-				'options'     => array(
168
-					'csv'  => __( 'CSV', 'invoicing' ),
169
-					'xml'  => __( 'XML', 'invoicing' ),
170
-					'json' => __( 'JSON', 'invoicing' ),
171
-				),
172
-			)
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Displays a field's markup.
179
-	 *
180
-	 */
181
-	public function display_markup( $markup ) {
182
-
183
-		echo str_replace(
184
-			array(
185
-				'form-control',
186
-				'custom-select'
187
-			),
188
-			'regular-text',
189
-			$markup
190
-		);
191
-
192
-	}
91
+    }
92
+
93
+    /**
94
+     * Generates the from date input field.
95
+     *
96
+     */
97
+    public function generate_from_date( $post_type ) {
98
+
99
+        return aui()->input(
100
+            array(
101
+                'name'       => 'from_date',
102
+                'id'         => esc_attr( "$post_type-from_date" ),
103
+                'placeholder'=> 'yy-mm-dd',
104
+                'label'      => __( 'From Date', 'invoicing' ),
105
+                'label_type' => 'vertical',
106
+                'label_class' => 'd-block',
107
+                'type'       => 'datepicker',
108
+            )
109
+        );
110
+
111
+    }
112
+
113
+    /**
114
+     * Generates the to date input field.
115
+     *
116
+     */
117
+    public function generate_to_date( $post_type ) {
118
+
119
+        return aui()->input(
120
+            array(
121
+                'name'       => 'to_date',
122
+                'id'         => esc_attr( "$post_type-to_date" ),
123
+                'placeholder'=> 'yy-mm-dd',
124
+                'label'      => __( 'To Date', 'invoicing' ),
125
+                'label_type' => 'vertical',
126
+                'label_class' => 'd-block',
127
+                'type'       => 'datepicker',
128
+            )
129
+        );
130
+
131
+    }
132
+
133
+    /**
134
+     * Generates the to post status select field.
135
+     *
136
+     */
137
+    public function generate_post_status_select( $post_type ) {
138
+
139
+        return aui()->select(
140
+            array(
141
+                'name'        => 'status',
142
+                'id'          => esc_attr( "$post_type-status" ),
143
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
144
+                'label'       => __( 'Status', 'invoicing' ),
145
+                'label_type'  => 'vertical',
146
+                'label_class' => 'd-block',
147
+                'options'     => wpinv_get_invoice_statuses( true, false, $post_type ),
148
+            )
149
+        );
150
+
151
+    }
152
+
153
+    /**
154
+     * Generates the to file type select field.
155
+     *
156
+     */
157
+    public function generate_file_type_select( $post_type ) {
158
+
159
+        return aui()->select(
160
+            array(
161
+                'name'        => 'file_type',
162
+                'id'          => esc_attr( "$post_type-file_type" ),
163
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
164
+                'label'       => __( 'Export File', 'invoicing' ),
165
+                'label_type'  => 'vertical',
166
+                'label_class' => 'd-block',
167
+                'options'     => array(
168
+                    'csv'  => __( 'CSV', 'invoicing' ),
169
+                    'xml'  => __( 'XML', 'invoicing' ),
170
+                    'json' => __( 'JSON', 'invoicing' ),
171
+                ),
172
+            )
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Displays a field's markup.
179
+     *
180
+     */
181
+    public function display_markup( $markup ) {
182
+
183
+        echo str_replace(
184
+            array(
185
+                'form-control',
186
+                'custom-select'
187
+            ),
188
+            'regular-text',
189
+            $markup
190
+        );
191
+
192
+    }
193 193
 
194 194
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -12,49 +12,49 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 *
18
-	 */
19
-	public function __construct() {
20
-		add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
-		add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
-		add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
-		add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
-		add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
-
26
-	}
27
-
28
-	/**
29
-	 * Registers the reports page.
30
-	 *
31
-	 */
32
-	public function register_reports_page() {
33
-
34
-		add_submenu_page(
15
+    /**
16
+     * Class constructor.
17
+     *
18
+     */
19
+    public function __construct() {
20
+        add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
+        add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
+        add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
+        add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
+        add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
+
26
+    }
27
+
28
+    /**
29
+     * Registers the reports page.
30
+     *
31
+     */
32
+    public function register_reports_page() {
33
+
34
+        add_submenu_page(
35 35
             'wpinv',
36 36
             __( 'Reports', 'invoicing' ),
37 37
             __( 'Reports', 'invoicing' ),
38 38
             wpinv_get_capability(),
39 39
             'wpinv-reports',
40 40
             array( $this, 'display_reports_page' )
41
-		);
41
+        );
42 42
 
43
-	}
43
+    }
44 44
 
45
-	/**
46
-	 * Displays the reports page.
47
-	 *
48
-	 */
49
-	public function display_reports_page() {
45
+    /**
46
+     * Displays the reports page.
47
+     *
48
+     */
49
+    public function display_reports_page() {
50 50
 
51
-		// Prepare variables.
52
-		$tabs        = $this->get_tabs();
53
-		$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
-		$current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
51
+        // Prepare variables.
52
+        $tabs        = $this->get_tabs();
53
+        $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
+        $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
55 55
 
56
-		// Display the current tab.
57
-		?>
56
+        // Display the current tab.
57
+        ?>
58 58
 
59 59
         <div class="wrap">
60 60
 
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
 			<nav class="nav-tab-wrapper">
64 64
 
65 65
 				<?php
66
-					foreach( $tabs as $key => $label ) {
66
+                    foreach( $tabs as $key => $label ) {
67 67
 
68
-						$key   = sanitize_text_field( $key );
69
-						$label = sanitize_text_field( $label );
70
-						$class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
-						$url   = esc_url(
72
-							add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
-						);
68
+                        $key   = sanitize_text_field( $key );
69
+                        $label = sanitize_text_field( $label );
70
+                        $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
+                        $url   = esc_url(
72
+                            add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
+                        );
74 74
 
75
-						echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
75
+                        echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
76 76
 
77
-					}
78
-				?>
77
+                    }
78
+                ?>
79 79
 
80 80
 			</nav>
81 81
 
@@ -86,74 +86,74 @@  discard block
 block discarded – undo
86 86
         </div>
87 87
 		<?php
88 88
 
89
-			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
90
-			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
89
+            wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
90
+            wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves reports page tabs.
96
-	 *
97
-	 * @return array
98
-	 */
99
-	public function get_tabs() {
94
+    /**
95
+     * Retrieves reports page tabs.
96
+     *
97
+     * @return array
98
+     */
99
+    public function get_tabs() {
100 100
 
101
-		$tabs = array(
102
-			'reports' => __( 'Reports', 'invoicing' ),
103
-			'export'  => __( 'Export', 'invoicing' ),
104
-		);
101
+        $tabs = array(
102
+            'reports' => __( 'Reports', 'invoicing' ),
103
+            'export'  => __( 'Export', 'invoicing' ),
104
+        );
105 105
 
106
-		return apply_filters( 'getpaid_report_tabs', $tabs );
107
-	}
106
+        return apply_filters( 'getpaid_report_tabs', $tabs );
107
+    }
108 108
 
109
-	/**
110
-	 * Displays the reports tab.
111
-	 *
112
-	 */
113
-	public function display_reports_tab() {
109
+    /**
110
+     * Displays the reports tab.
111
+     *
112
+     */
113
+    public function display_reports_tab() {
114 114
 
115
-		$reports = new GetPaid_Reports_Report();
116
-		$reports->display();
115
+        $reports = new GetPaid_Reports_Report();
116
+        $reports->display();
117 117
 
118
-	}
118
+    }
119 119
 
120
-	/**
121
-	 * Displays the exports tab.
122
-	 *
123
-	 */
124
-	public function display_exports_tab() {
120
+    /**
121
+     * Displays the exports tab.
122
+     *
123
+     */
124
+    public function display_exports_tab() {
125 125
 
126
-		$exports = new GetPaid_Reports_Export();
127
-		$exports->display();
126
+        $exports = new GetPaid_Reports_Export();
127
+        $exports->display();
128 128
 
129
-	}
129
+    }
130 130
 
131
-	/**
132
-	 * Donwnloads a graph.
133
-	 *
134
-	 * @param array $args
135
-	 */
136
-	public function download_graph( $args ) {
131
+    /**
132
+     * Donwnloads a graph.
133
+     *
134
+     * @param array $args
135
+     */
136
+    public function download_graph( $args ) {
137 137
 
138
-		if ( ! empty( $args['graph'] ) ) {
139
-			$downloader = new GetPaid_Graph_Downloader();
140
-			$downloader->download( $args['graph'] );
141
-		}
138
+        if ( ! empty( $args['graph'] ) ) {
139
+            $downloader = new GetPaid_Graph_Downloader();
140
+            $downloader->download( $args['graph'] );
141
+        }
142 142
 
143
-	}
143
+    }
144 144
 
145
-	/**
146
-	 * Exports invoices.
147
-	 *
148
-	 * @param array $args
149
-	 */
150
-	public function export_invoices( $args ) {
145
+    /**
146
+     * Exports invoices.
147
+     *
148
+     * @param array $args
149
+     */
150
+    public function export_invoices( $args ) {
151 151
 
152
-		if ( ! empty( $args['post_type'] ) ) {
153
-			$downloader = new GetPaid_Invoice_Exporter();
154
-			$downloader->export( $args['post_type'], $args );
155
-		}
152
+        if ( ! empty( $args['post_type'] ) ) {
153
+            $downloader = new GetPaid_Invoice_Exporter();
154
+            $downloader->export( $args['post_type'], $args );
155
+        }
156 156
 
157
-	}
157
+    }
158 158
 
159 159
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -12,46 +12,46 @@  discard block
 block discarded – undo
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,44 +69,44 @@  discard block
 block discarded – undo
69 69
 
70 70
 		<?php
71 71
 
72
-	}
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
-	}
82
-
83
-	/**
84
-	 * Retrieves the download url.
85
-	 *
86
-	 */
87
-	public function get_download_url( $graph, $file_type ) {
88
-
89
-		return wp_nonce_url(
90
-			add_query_arg(
91
-				array(
92
-					'getpaid-admin-action' => 'download_graph',
93
-					'file_type'            => urlencode( $file_type ),
94
-					'graph'                => urlencode( $graph ),
95
-				)
96
-			),
97
-			'getpaid-nonce',
98
-			'getpaid-nonce'
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Displays the right side.
105
-	 *
106
-	 */
107
-	public function display_right() {
108
-
109
-		?>
72
+    }
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
+    }
82
+
83
+    /**
84
+     * Retrieves the download url.
85
+     *
86
+     */
87
+    public function get_download_url( $graph, $file_type ) {
88
+
89
+        return wp_nonce_url(
90
+            add_query_arg(
91
+                array(
92
+                    'getpaid-admin-action' => 'download_graph',
93
+                    'file_type'            => urlencode( $file_type ),
94
+                    'graph'                => urlencode( $graph ),
95
+                )
96
+            ),
97
+            'getpaid-nonce',
98
+            'getpaid-nonce'
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Displays the right side.
105
+     *
106
+     */
107
+    public function display_right() {
108
+
109
+        ?>
110 110
 
111 111
 			<?php foreach ( $this->views as $key => $view ) : ?>
112 112
 				<div class="row mb-4">
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 							</div>
136 136
 							<div class="card-body">
137 137
 								<?php
138
-									$class = $view['class'];
139
-									$class = new $class();
140
-									$class->display_stats();
141
-								?>
138
+                                    $class = $view['class'];
139
+                                    $class = new $class();
140
+                                    $class->display_stats();
141
+                                ?>
142 142
 							</div>
143 143
 						</div>
144 144
 					</div>
@@ -147,6 +147,6 @@  discard block
 block discarded – undo
147 147
 
148 148
 		<?php
149 149
 
150
-	}
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.