Passed
Push — master ( 0a2cdb...97ebee )
by Brian
04:41
created
includes/reports/class-getpaid-reports-export.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  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
-		$this->display_subscription_export();
26
-		echo '</div>';
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
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
+        $this->display_subscription_export();
26
+        echo '</div>';
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								__( 'Export %s', 'invoicing' ),
65
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                __( 'Export %s', 'invoicing' ),
65
+                                sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
78
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
79
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,122 +89,122 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		return aui()->input(
101
-			array(
102
-				'name'        => 'from_date',
103
-				'id'          => esc_attr( "$post_type-from_date" ),
104
-				'placeholder' => 'yy-mm-dd',
105
-				'label'       => __( 'From Date', 'invoicing' ),
106
-				'label_type'  => 'vertical',
107
-				'label_class' => 'd-block',
108
-				'type'        => 'datepicker',
109
-			)
110
-		);
111
-
112
-	}
113
-
114
-	/**
115
-	 * Generates the to date input field.
116
-	 *
117
-	 */
118
-	public function generate_to_date( $post_type ) {
119
-
120
-		return aui()->input(
121
-			array(
122
-				'name'        => 'to_date',
123
-				'id'          => esc_attr( "$post_type-to_date" ),
124
-				'placeholder' => 'yy-mm-dd',
125
-				'label'       => __( 'To Date', 'invoicing' ),
126
-				'label_type'  => 'vertical',
127
-				'label_class' => 'd-block',
128
-				'type'        => 'datepicker',
129
-			)
130
-		);
131
-
132
-	}
133
-
134
-	/**
135
-	 * Generates the to post status select field.
136
-	 *
137
-	 */
138
-	public function generate_post_status_select( $post_type ) {
139
-
140
-		if ( 'subscriptions' === $post_type ) {
141
-			$options = getpaid_get_subscription_statuses();
142
-		} else {
143
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
144
-		}
145
-
146
-		return aui()->select(
147
-			array(
148
-				'name'        => 'status',
149
-				'id'          => esc_attr( "$post_type-status" ),
150
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
151
-				'label'       => __( 'Status', 'invoicing' ),
152
-				'label_type'  => 'vertical',
153
-				'label_class' => 'd-block',
154
-				'options'     => $options,
155
-			)
156
-		);
157
-
158
-	}
159
-
160
-	/**
161
-	 * Generates the to file type select field.
162
-	 *
163
-	 */
164
-	public function generate_file_type_select( $post_type ) {
165
-
166
-		return aui()->select(
167
-			array(
168
-				'name'        => 'file_type',
169
-				'id'          => esc_attr( "$post_type-file_type" ),
170
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
171
-				'label'       => __( 'Export File', 'invoicing' ),
172
-				'label_type'  => 'vertical',
173
-				'label_class' => 'd-block',
174
-				'options'     => array(
175
-					'csv'  => __( 'CSV', 'invoicing' ),
176
-					'xml'  => __( 'XML', 'invoicing' ),
177
-					'json' => __( 'JSON', 'invoicing' ),
178
-				),
179
-			)
180
-		);
181
-
182
-	}
183
-
184
-	/**
185
-	 * Displays a field's markup.
186
-	 *
187
-	 */
188
-	public function display_markup( $markup ) {
189
-
190
-		echo str_replace(
191
-			array(
192
-				'form-control',
193
-				'custom-select',
194
-			),
195
-			'regular-text',
196
-			$markup
197
-		);
198
-
199
-	}
200
-
201
-	/**
202
-	 * Displays a subscription export card.
203
-	 *
204
-	 */
205
-	public function display_subscription_export() {
206
-
207
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        return aui()->input(
101
+            array(
102
+                'name'        => 'from_date',
103
+                'id'          => esc_attr( "$post_type-from_date" ),
104
+                'placeholder' => 'yy-mm-dd',
105
+                'label'       => __( 'From Date', 'invoicing' ),
106
+                'label_type'  => 'vertical',
107
+                'label_class' => 'd-block',
108
+                'type'        => 'datepicker',
109
+            )
110
+        );
111
+
112
+    }
113
+
114
+    /**
115
+     * Generates the to date input field.
116
+     *
117
+     */
118
+    public function generate_to_date( $post_type ) {
119
+
120
+        return aui()->input(
121
+            array(
122
+                'name'        => 'to_date',
123
+                'id'          => esc_attr( "$post_type-to_date" ),
124
+                'placeholder' => 'yy-mm-dd',
125
+                'label'       => __( 'To Date', 'invoicing' ),
126
+                'label_type'  => 'vertical',
127
+                'label_class' => 'd-block',
128
+                'type'        => 'datepicker',
129
+            )
130
+        );
131
+
132
+    }
133
+
134
+    /**
135
+     * Generates the to post status select field.
136
+     *
137
+     */
138
+    public function generate_post_status_select( $post_type ) {
139
+
140
+        if ( 'subscriptions' === $post_type ) {
141
+            $options = getpaid_get_subscription_statuses();
142
+        } else {
143
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
144
+        }
145
+
146
+        return aui()->select(
147
+            array(
148
+                'name'        => 'status',
149
+                'id'          => esc_attr( "$post_type-status" ),
150
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
151
+                'label'       => __( 'Status', 'invoicing' ),
152
+                'label_type'  => 'vertical',
153
+                'label_class' => 'd-block',
154
+                'options'     => $options,
155
+            )
156
+        );
157
+
158
+    }
159
+
160
+    /**
161
+     * Generates the to file type select field.
162
+     *
163
+     */
164
+    public function generate_file_type_select( $post_type ) {
165
+
166
+        return aui()->select(
167
+            array(
168
+                'name'        => 'file_type',
169
+                'id'          => esc_attr( "$post_type-file_type" ),
170
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
171
+                'label'       => __( 'Export File', 'invoicing' ),
172
+                'label_type'  => 'vertical',
173
+                'label_class' => 'd-block',
174
+                'options'     => array(
175
+                    'csv'  => __( 'CSV', 'invoicing' ),
176
+                    'xml'  => __( 'XML', 'invoicing' ),
177
+                    'json' => __( 'JSON', 'invoicing' ),
178
+                ),
179
+            )
180
+        );
181
+
182
+    }
183
+
184
+    /**
185
+     * Displays a field's markup.
186
+     *
187
+     */
188
+    public function display_markup( $markup ) {
189
+
190
+        echo str_replace(
191
+            array(
192
+                'form-control',
193
+                'custom-select',
194
+            ),
195
+            'regular-text',
196
+            $markup
197
+        );
198
+
199
+    }
200
+
201
+    /**
202
+     * Displays a subscription export card.
203
+     *
204
+     */
205
+    public function display_subscription_export() {
206
+
207
+        ?>
208 208
 
209 209
 		<div class="col-12 col-md-6">
210 210
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
221 221
 
222 222
 						<?php
223
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
-							submit_button( __( 'Download', 'invoicing' ) );
228
-						?>
223
+                            $this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
+                            $this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
+                            $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
+                            $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
+                            submit_button( __( 'Download', 'invoicing' ) );
228
+                        ?>
229 229
 
230 230
 					</form>
231 231
 
@@ -236,6 +236,6 @@  discard block
 block discarded – undo
236 236
 
237 237
 		<?php
238 238
 
239
-	}
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Export Class.
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 	public function display() {
20 20
 
21 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 );
22
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
23
+			$this->display_post_type_export($post_type);
24 24
 		}
25 25
 		$this->display_subscription_export();
26 26
 		echo '</div>';
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 * Retrieves the download url.
32 32
 	 *
33 33
 	 */
34
-	public function get_download_url( $post_type ) {
34
+	public function get_download_url($post_type) {
35 35
 
36 36
 		return wp_nonce_url(
37 37
 			add_query_arg(
38 38
 				array(
39 39
 					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
40
+					'post_type'            => urlencode($post_type),
41 41
 				)
42 42
 			),
43 43
 			'getpaid-nonce',
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Displays a single post type export card.
51 51
 	 *
52 52
 	 */
53
-	public function display_post_type_export( $post_type ) {
53
+	public function display_post_type_export($post_type) {
54 54
 
55 55
 		?>
56 56
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 					<strong>
62 62
 						<?php
63 63
 							printf(
64
-								__( 'Export %s', 'invoicing' ),
65
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
64
+								__('Export %s', 'invoicing'),
65
+								sanitize_text_field(getpaid_get_post_type_label($post_type))
66 66
 							);
67 67
 						?>
68 68
 					</strong>
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 
71 71
 				<div class="card-body">
72 72
 
73
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73
+					<form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
76
+							$this->display_markup($this->generate_from_date($post_type));
77
+							$this->display_markup($this->generate_to_date($post_type));
78
+							$this->display_markup($this->generate_post_status_select($post_type));
79
+							$this->display_markup($this->generate_file_type_select($post_type));
80
+							submit_button(__('Download', 'invoicing'));
81 81
 						?>
82 82
 
83 83
 					</form>
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * Generates the from date input field.
96 96
 	 *
97 97
 	 */
98
-	public function generate_from_date( $post_type ) {
98
+	public function generate_from_date($post_type) {
99 99
 
100 100
 		return aui()->input(
101 101
 			array(
102 102
 				'name'        => 'from_date',
103
-				'id'          => esc_attr( "$post_type-from_date" ),
103
+				'id'          => esc_attr("$post_type-from_date"),
104 104
 				'placeholder' => 'yy-mm-dd',
105
-				'label'       => __( 'From Date', 'invoicing' ),
105
+				'label'       => __('From Date', 'invoicing'),
106 106
 				'label_type'  => 'vertical',
107 107
 				'label_class' => 'd-block',
108 108
 				'type'        => 'datepicker',
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 	 * Generates the to date input field.
116 116
 	 *
117 117
 	 */
118
-	public function generate_to_date( $post_type ) {
118
+	public function generate_to_date($post_type) {
119 119
 
120 120
 		return aui()->input(
121 121
 			array(
122 122
 				'name'        => 'to_date',
123
-				'id'          => esc_attr( "$post_type-to_date" ),
123
+				'id'          => esc_attr("$post_type-to_date"),
124 124
 				'placeholder' => 'yy-mm-dd',
125
-				'label'       => __( 'To Date', 'invoicing' ),
125
+				'label'       => __('To Date', 'invoicing'),
126 126
 				'label_type'  => 'vertical',
127 127
 				'label_class' => 'd-block',
128 128
 				'type'        => 'datepicker',
@@ -135,20 +135,20 @@  discard block
 block discarded – undo
135 135
 	 * Generates the to post status select field.
136 136
 	 *
137 137
 	 */
138
-	public function generate_post_status_select( $post_type ) {
138
+	public function generate_post_status_select($post_type) {
139 139
 
140
-		if ( 'subscriptions' === $post_type ) {
140
+		if ('subscriptions' === $post_type) {
141 141
 			$options = getpaid_get_subscription_statuses();
142 142
 		} else {
143
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
143
+			$options = wpinv_get_invoice_statuses(true, false, $post_type);
144 144
 		}
145 145
 
146 146
 		return aui()->select(
147 147
 			array(
148 148
 				'name'        => 'status',
149
-				'id'          => esc_attr( "$post_type-status" ),
150
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
151
-				'label'       => __( 'Status', 'invoicing' ),
149
+				'id'          => esc_attr("$post_type-status"),
150
+				'placeholder' => __('All Statuses', 'invoicing'),
151
+				'label'       => __('Status', 'invoicing'),
152 152
 				'label_type'  => 'vertical',
153 153
 				'label_class' => 'd-block',
154 154
 				'options'     => $options,
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
 	 * Generates the to file type select field.
162 162
 	 *
163 163
 	 */
164
-	public function generate_file_type_select( $post_type ) {
164
+	public function generate_file_type_select($post_type) {
165 165
 
166 166
 		return aui()->select(
167 167
 			array(
168 168
 				'name'        => 'file_type',
169
-				'id'          => esc_attr( "$post_type-file_type" ),
170
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
171
-				'label'       => __( 'Export File', 'invoicing' ),
169
+				'id'          => esc_attr("$post_type-file_type"),
170
+				'placeholder' => __('Select File Type', 'invoicing'),
171
+				'label'       => __('Export File', 'invoicing'),
172 172
 				'label_type'  => 'vertical',
173 173
 				'label_class' => 'd-block',
174 174
 				'options'     => array(
175
-					'csv'  => __( 'CSV', 'invoicing' ),
176
-					'xml'  => __( 'XML', 'invoicing' ),
177
-					'json' => __( 'JSON', 'invoicing' ),
175
+					'csv'  => __('CSV', 'invoicing'),
176
+					'xml'  => __('XML', 'invoicing'),
177
+					'json' => __('JSON', 'invoicing'),
178 178
 				),
179 179
 			)
180 180
 		);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * Displays a field's markup.
186 186
 	 *
187 187
 	 */
188
-	public function display_markup( $markup ) {
188
+	public function display_markup($markup) {
189 189
 
190 190
 		echo str_replace(
191 191
 			array(
@@ -211,20 +211,20 @@  discard block
 block discarded – undo
211 211
 
212 212
 				<div class="card-header">
213 213
 					<strong>
214
-						<?php _e( 'Export Subscriptions', 'invoicing' ); ?>
214
+						<?php _e('Export Subscriptions', 'invoicing'); ?>
215 215
 					</strong>
216 216
 				</div>
217 217
 
218 218
 				<div class="card-body">
219 219
 
220
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
220
+					<form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>">
221 221
 
222 222
 						<?php
223
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
-							submit_button( __( 'Download', 'invoicing' ) );
223
+							$this->display_markup($this->generate_from_date('subscriptions'));
224
+							$this->display_markup($this->generate_to_date('subscriptions'));
225
+							$this->display_markup($this->generate_post_status_select('subscriptions'));
226
+							$this->display_markup($this->generate_file_type_select('subscriptions'));
227
+							submit_button(__('Download', 'invoicing'));
228 228
 						?>
229 229
 
230 230
 					</form>
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-earnings.php 2 patches
Indentation   +133 added lines, -133 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 esc_attr( $key ); ?>"></canvas>
179 179
 
@@ -223,20 +223,20 @@  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
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report_Earnings Class.
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 
21 21
 		$graphs = array(
22 22
 
23
-            'total'      => __( 'Earnings', 'invoicing' ),
24
-            'discount'   => __( 'Discount', 'invoicing' ),
25
-			'fees_total' => __( 'Fees', 'invoicing' ),
26
-			'tax'        => __( 'Tax', 'invoicing' ),
23
+            'total'      => __('Earnings', 'invoicing'),
24
+            'discount'   => __('Discount', '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
 
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 	 * Retrieves the earning sql.
36 36
 	 *
37 37
 	 */
38
-	public function get_sql( $range ) {
38
+	public function get_sql($range) {
39 39
 		global $wpdb;
40 40
 
41 41
 		$table      = $wpdb->prefix . 'getpaid_invoices';
42
-		$clauses    = $this->get_range_sql( $range );
43
-		$graphs     = array_keys( $this->get_graphs() );
42
+		$clauses    = $this->get_range_sql($range);
43
+		$graphs     = array_keys($this->get_graphs());
44 44
 		$graphs_sql = array();
45 45
 
46
-		foreach ( $graphs as $graph ) {
46
+		foreach ($graphs as $graph) {
47 47
 			$graphs_sql[] = "SUM( meta.$graph ) AS $graph";
48 48
 		}
49 49
 
50
-		$graphs_sql = implode( ', ', $graphs_sql );
50
+		$graphs_sql = implode(', ', $graphs_sql);
51 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
@@ -58,7 +58,7 @@  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 );
61
+		return apply_filters('getpaid_earning_graphs_get_sql', $sql, $range);
62 62
 
63 63
 	}
64 64
 
@@ -68,68 +68,68 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function prepare_stats() {
70 70
 		global $wpdb;
71
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
71
+		$this->stats = $wpdb->get_results($this->get_sql($this->get_range()));
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Retrieves report labels.
76 76
 	 *
77 77
 	 */
78
-	public function get_labels( $range ) {
78
+	public function get_labels($range) {
79 79
 
80 80
 		$labels = array(
81 81
 			'today'     => $this->get_hours_in_a_day(),
82 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 ),
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 89
 		);
90 90
 
91
-		$label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days'];
92
-		return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range );
91
+		$label = isset($labels[$range]) ? $labels[$range] : $labels['7_days'];
92
+		return apply_filters('getpaid_earning_graphs_get_labels', $label, $range);
93 93
 	}
94 94
 
95 95
 	/**
96 96
 	 * Retrieves report datasets.
97 97
 	 *
98 98
 	 */
99
-	public function get_datasets( $labels ) {
99
+	public function get_datasets($labels) {
100 100
 
101 101
 		$datasets = array();
102 102
 
103
-		foreach ( $this->get_graphs() as $key => $label ) {
104
-			$datasets[ $key ] = array(
103
+		foreach ($this->get_graphs() as $key => $label) {
104
+			$datasets[$key] = array(
105 105
 				'label' => $label,
106
-				'data'  => $this->get_data( $key, $labels ),
106
+				'data'  => $this->get_data($key, $labels),
107 107
 			);
108 108
 		}
109 109
 
110
-		return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels );
110
+		return apply_filters('getpaid_earning_graphs_get_datasets', $datasets, $labels);
111 111
 	}
112 112
 
113 113
 	/**
114 114
 	 * Retrieves report data.
115 115
 	 *
116 116
 	 */
117
-	public function get_data( $key, $labels ) {
117
+	public function get_data($key, $labels) {
118 118
 
119
-		$data     = wp_list_pluck( $this->stats, $key, 'completed_date' );
119
+		$data     = wp_list_pluck($this->stats, $key, 'completed_date');
120 120
 		$prepared = array();
121 121
 
122
-		foreach ( $labels as $label ) {
122
+		foreach ($labels as $label) {
123 123
 
124 124
 			$value = 0;
125
-			if ( isset( $data[ $label ] ) ) {
126
-				$value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) );
125
+			if (isset($data[$label])) {
126
+				$value = wpinv_round_amount(wpinv_sanitize_amount($data[$label]));
127 127
 			}
128 128
 
129 129
 			$prepared[] = $value;
130 130
 		}
131 131
 
132
-		return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels );
132
+		return apply_filters('getpaid_earning_graphs_get_data', $prepared, $key, $labels);
133 133
 
134 134
 	}
135 135
 
@@ -139,24 +139,24 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function display() {
141 141
 
142
-		$labels     = $this->get_labels( $this->get_range() );
142
+		$labels     = $this->get_labels($this->get_range());
143 143
 		$chart_data = array(
144
-			'labels'   => array_values( $labels ),
145
-			'datasets' => $this->get_datasets( array_keys( $labels ) ),
144
+			'labels'   => array_values($labels),
145
+			'datasets' => $this->get_datasets(array_keys($labels)),
146 146
 		);
147 147
 
148 148
 		?>
149 149
 
150
-			<?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?>
150
+			<?php foreach ($chart_data['datasets'] as $key => $dataset) : ?>
151 151
 				<div class="row mb-4">
152 152
 					<div class="col-12">
153 153
 						<div class="card m-0 p-0" style="max-width:100%">
154 154
 							<div class="card-header d-flex align-items-center">
155
-								<strong class="flex-grow-1"><?php echo esc_html( $dataset['label'] ); ?></strong>
155
+								<strong class="flex-grow-1"><?php echo esc_html($dataset['label']); ?></strong>
156 156
 								<?php $this->display_range_selector(); ?>
157 157
 							</div>
158 158
 							<div class="card-body">
159
-								<?php $this->display_graph( $key, $dataset, $chart_data['labels'] ); ?>
159
+								<?php $this->display_graph($key, $dataset, $chart_data['labels']); ?>
160 160
 							</div>
161 161
 						</div>
162 162
 					</div>
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 	 * Displays the actual report.
172 172
 	 *
173 173
 	 */
174
-	public function display_graph( $key, $dataset, $labels ) {
174
+	public function display_graph($key, $dataset, $labels) {
175 175
 
176 176
 		?>
177 177
 
178
-		<canvas id="getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>"></canvas>
178
+		<canvas id="getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>"></canvas>
179 179
 
180 180
 		<script>
181 181
 			window.addEventListener( 'DOMContentLoaded', function() {
182 182
 
183
-				var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>' ).getContext('2d');
183
+				var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>' ).getContext('2d');
184 184
 				new Chart(
185 185
 					ctx,
186 186
 					{
187 187
 						type: 'line',
188 188
 						data: {
189
-							'labels': <?php echo wp_json_encode( wpinv_clean( $labels ) ); ?>,
189
+							'labels': <?php echo wp_json_encode(wpinv_clean($labels)); ?>,
190 190
 							'datasets': [
191 191
 								{
192
-									label: '<?php echo esc_attr( $dataset['label'] ); ?>',
193
-									data: <?php echo wp_json_encode( wpinv_clean( $dataset['data'] ) ); ?>,
192
+									label: '<?php echo esc_attr($dataset['label']); ?>',
193
+									data: <?php echo wp_json_encode(wpinv_clean($dataset['data'])); ?>,
194 194
 									backgroundColor: 'rgba(54, 162, 235, 0.1)',
195 195
 									borderColor: 'rgb(54, 162, 235)',
196 196
 									borderWidth: 4,
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-discounts.php 2 patches
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.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report_Discounts Class.
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	 * Retrieves the discounts sql.
22 22
 	 *
23 23
 	 */
24
-	public function get_sql( $range ) {
24
+	public function get_sql($range) {
25 25
 		global $wpdb;
26 26
 
27 27
 		$table      = $wpdb->prefix . 'getpaid_invoices';
28
-		$clauses    = $this->get_range_sql( $range );
28
+		$clauses    = $this->get_range_sql($range);
29 29
 
30 30
 		$sql        = "SELECT
31 31
 				meta.discount_code AS discount_code,
@@ -41,7 +41,7 @@  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
 
@@ -51,30 +51,30 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function prepare_stats() {
53 53
 		global $wpdb;
54
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
55
-		$this->stats = $this->normalize_stats( $this->stats );
54
+		$this->stats = $wpdb->get_results($this->get_sql($this->get_range()));
55
+		$this->stats = $this->normalize_stats($this->stats);
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * Normalizes the report stats.
60 60
 	 *
61 61
 	 */
62
-	public function normalize_stats( $stats ) {
62
+	public function normalize_stats($stats) {
63 63
 		$normalized = array();
64 64
 		$others     = 0;
65 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 73
 			} else {
74 74
 
75 75
 				$normalized[] = array(
76
-					'total'         => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
77
-					'discount_code' => strip_tags( $stat->discount_code ),
76
+					'total'         => wpinv_round_amount(wpinv_sanitize_amount($stat->total)),
77
+					'discount_code' => strip_tags($stat->discount_code),
78 78
 				);
79 79
 
80 80
 			}
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 			$did++;
83 83
 		}
84 84
 
85
-		if ( $others > 0 ) {
85
+		if ($others > 0) {
86 86
 
87 87
 			$normalized[] = array(
88
-				'total'         => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
89
-				'discount_code' => esc_html__( 'Others', 'invoicing' ),
88
+				'total'         => wpinv_round_amount(wpinv_sanitize_amount($others)),
89
+				'discount_code' => esc_html__('Others', 'invoicing'),
90 90
 			);
91 91
 
92 92
 		}
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
 	 */
101 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 108
 		return array(
109 109
 			'data'            => $data,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 */
119 119
 	public function get_labels() {
120
-		return wp_list_pluck( $this->stats, 'discount_code' );
120
+		return wp_list_pluck($this->stats, 'discount_code');
121 121
 	}
122 122
 
123 123
 	/**
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 						{
139 139
 							type: 'doughnut',
140 140
 							data: {
141
-								'labels': <?php echo wp_json_encode( wpinv_clean( $this->get_labels() ) ); ?>,
142
-								'datasets': [ <?php echo wp_json_encode( wpinv_clean( $this->get_data() ) ); ?> ]
141
+								'labels': <?php echo wp_json_encode(wpinv_clean($this->get_labels())); ?>,
142
+								'datasets': [ <?php echo wp_json_encode(wpinv_clean($this->get_data())); ?> ]
143 143
 							},
144 144
 							options: {
145 145
 								legend: {
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -12,88 +12,88 @@  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 );
46
-
47
-	}
48
-
49
-	/**
50
-	 * Retrieves the current range.
51
-	 *
52
-	 */
53
-	public function get_range() {
54
-		$valid_ranges = $this->get_periods();
55
-
56
-		if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
-			return sanitize_key( $_GET['date_range'] );
58
-		}
59
-
60
-		return '7_days';
61
-	}
62
-
63
-	/**
64
-	 * Returns an array of date ranges.
65
-	 *
66
-	 * @return array
67
-	 */
68
-	public function get_periods() {
69
-
70
-		$periods = array(
71
-			'today'        => __( 'Today', 'invoicing' ),
72
-			'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
-			'week'         => __( 'This week', 'invoicing' ),
74
-			'last_week'    => __( 'Last week', 'invoicing' ),
75
-			'7_days'       => __( 'Last 7 days', 'invoicing' ),
76
-			'month'        => __( 'This month', 'invoicing' ),
77
-			'last_month'   => __( 'Last month', 'invoicing' ),
78
-			'30_days'      => __( 'Last 30 days', 'invoicing' ),
79
-			'quarter'      => __( 'This Quarter', 'invoicing' ),
80
-			'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
-			'year'         => __( 'This year', 'invoicing' ),
82
-			'last_year'    => __( 'Last Year', 'invoicing' ),
83
-			'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
-		);
85
-
86
-		return apply_filters( 'getpaid_earning_periods', $periods );
87
-	}
88
-
89
-	/**
90
-	 * Displays the range selector.
91
-	 *
92
-	 */
93
-	public function display_range_selector() {
94
-
95
-		$range = $this->get_range();
96
-		?>
45
+        $this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
+
47
+    }
48
+
49
+    /**
50
+     * Retrieves the current range.
51
+     *
52
+     */
53
+    public function get_range() {
54
+        $valid_ranges = $this->get_periods();
55
+
56
+        if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
+            return sanitize_key( $_GET['date_range'] );
58
+        }
59
+
60
+        return '7_days';
61
+    }
62
+
63
+    /**
64
+     * Returns an array of date ranges.
65
+     *
66
+     * @return array
67
+     */
68
+    public function get_periods() {
69
+
70
+        $periods = array(
71
+            'today'        => __( 'Today', 'invoicing' ),
72
+            'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
+            'week'         => __( 'This week', 'invoicing' ),
74
+            'last_week'    => __( 'Last week', 'invoicing' ),
75
+            '7_days'       => __( 'Last 7 days', 'invoicing' ),
76
+            'month'        => __( 'This month', 'invoicing' ),
77
+            'last_month'   => __( 'Last month', 'invoicing' ),
78
+            '30_days'      => __( 'Last 30 days', 'invoicing' ),
79
+            'quarter'      => __( 'This Quarter', 'invoicing' ),
80
+            'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
+            'year'         => __( 'This year', 'invoicing' ),
82
+            'last_year'    => __( 'Last Year', 'invoicing' ),
83
+            'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
+        );
85
+
86
+        return apply_filters( 'getpaid_earning_periods', $periods );
87
+    }
88
+
89
+    /**
90
+     * Displays the range selector.
91
+     *
92
+     */
93
+    public function display_range_selector() {
94
+
95
+        $range = $this->get_range();
96
+        ?>
97 97
 
98 98
 			<form method="get" class="getpaid-filter-earnings float-right">
99 99
 				<?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?>
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 			</form>
116 116
 
117 117
 		<?php
118
-	}
118
+    }
119 119
 
120
-	/**
121
-	 * Displays the reports tab.
122
-	 *
123
-	 */
124
-	public function display() {
125
-		?>
120
+    /**
121
+     * Displays the reports tab.
122
+     *
123
+     */
124
+    public function display() {
125
+        ?>
126 126
 
127 127
 		<div class="mt-4">
128 128
 
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
 
203 203
 		<?php
204 204
 
205
-	}
205
+    }
206 206
 
207
-	/**
208
-	 * Displays the left side.
209
-	 *
210
-	 */
211
-	public function display_left() {
212
-		$graphs = wpinv_get_report_graphs();
207
+    /**
208
+     * Displays the left side.
209
+     *
210
+     */
211
+    public function display_left() {
212
+        $graphs = wpinv_get_report_graphs();
213 213
 
214
-		?>
214
+        ?>
215 215
 
216 216
 			<?php foreach ( $graphs as $key => $graph ) : ?>
217 217
 				<div class="row mb-4">
@@ -230,35 +230,35 @@  discard block
 block discarded – undo
230 230
 
231 231
 		<?php
232 232
 
233
-	}
234
-
235
-	/**
236
-	 * Retrieves the download url.
237
-	 *
238
-	 */
239
-	public function get_download_url( $graph, $file_type ) {
240
-
241
-		return wp_nonce_url(
242
-			add_query_arg(
243
-				array(
244
-					'getpaid-admin-action' => 'download_graph',
245
-					'file_type'            => urlencode( $file_type ),
246
-					'graph'                => urlencode( $graph ),
247
-				)
248
-			),
249
-			'getpaid-nonce',
250
-			'getpaid-nonce'
251
-		);
233
+    }
234
+
235
+    /**
236
+     * Retrieves the download url.
237
+     *
238
+     */
239
+    public function get_download_url( $graph, $file_type ) {
240
+
241
+        return wp_nonce_url(
242
+            add_query_arg(
243
+                array(
244
+                    'getpaid-admin-action' => 'download_graph',
245
+                    'file_type'            => urlencode( $file_type ),
246
+                    'graph'                => urlencode( $graph ),
247
+                )
248
+            ),
249
+            'getpaid-nonce',
250
+            'getpaid-nonce'
251
+        );
252 252
 
253
-	}
253
+    }
254 254
 
255
-	/**
256
-	 * Displays the right side.
257
-	 *
258
-	 */
259
-	public function display_right() {
255
+    /**
256
+     * Displays the right side.
257
+     *
258
+     */
259
+    public function display_right() {
260 260
 
261
-		?>
261
+        ?>
262 262
 
263 263
 			<?php foreach ( $this->views as $key => $view ) : ?>
264 264
 				<div class="row mb-4">
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
 							</div>
288 288
 							<div class="card-body">
289 289
 								<?php
290
-									$class = $view['class'];
291
-									$class = new $class();
292
-									$class->display_stats();
293
-								?>
290
+                                    $class = $view['class'];
291
+                                    $class = new $class();
292
+                                    $class->display_stats();
293
+                                ?>
294 294
 							</div>
295 295
 						</div>
296 296
 					</div>
@@ -299,68 +299,68 @@  discard block
 block discarded – undo
299 299
 
300 300
 		<?php
301 301
 
302
-		do_action( 'getpaid_reports_display_right', $this );
303
-	}
304
-
305
-	/**
306
-	 * Returns a list of report cards.
307
-	 *
308
-	 */
309
-	public function get_cards() {
310
-
311
-		$cards = array(
312
-			'total_sales'         => array(
313
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
315
-			),
316
-			'net_sales'           => array(
317
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
318
-				'label'       => __( 'Net Revenue', 'invoicing' ),
319
-			),
320
-			'average_sales'       => array(
321
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
323
-			),
324
-			'average_total_sales' => array(
325
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
327
-			),
328
-			'total_invoices'      => array(
329
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
331
-			),
332
-			'total_items'         => array(
333
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
334
-				'label'       => __( 'Purchased Items', 'invoicing' ),
335
-			),
336
-			'refunded_items'      => array(
337
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
338
-				'label'       => __( 'Refunded Items', 'invoicing' ),
339
-			),
340
-			'total_tax'           => array(
341
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
-				'label'       => __( 'Tax', 'invoicing' ),
343
-			),
344
-			'total_refunded_tax'  => array(
345
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
347
-			),
348
-			'total_fees'          => array(
349
-				'description' => __( 'Total fees charged.', 'invoicing' ),
350
-				'label'       => __( 'Fees', 'invoicing' ),
351
-			),
352
-			'total_refunds'       => array(
353
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
-				'label'       => __( 'Refunded', 'invoicing' ),
355
-			),
356
-			'total_discount'      => array(
357
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
358
-				'label'       => __( 'Discounted', 'invoicing' ),
359
-			),
360
-		);
361
-
362
-		return apply_filters( 'wpinv_report_cards', $cards );
363
-	}
302
+        do_action( 'getpaid_reports_display_right', $this );
303
+    }
304
+
305
+    /**
306
+     * Returns a list of report cards.
307
+     *
308
+     */
309
+    public function get_cards() {
310
+
311
+        $cards = array(
312
+            'total_sales'         => array(
313
+                'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
+                'label'       => __( 'Gross Revenue', 'invoicing' ),
315
+            ),
316
+            'net_sales'           => array(
317
+                'description' => __( 'Net sales in the period.', 'invoicing' ),
318
+                'label'       => __( 'Net Revenue', 'invoicing' ),
319
+            ),
320
+            'average_sales'       => array(
321
+                'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
+                'label'       => __( 'Avg. Net Sales', 'invoicing' ),
323
+            ),
324
+            'average_total_sales' => array(
325
+                'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
+                'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
327
+            ),
328
+            'total_invoices'      => array(
329
+                'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
+                'label'       => __( 'Paid Invoices', 'invoicing' ),
331
+            ),
332
+            'total_items'         => array(
333
+                'description' => __( 'Number of items purchased.', 'invoicing' ),
334
+                'label'       => __( 'Purchased Items', 'invoicing' ),
335
+            ),
336
+            'refunded_items'      => array(
337
+                'description' => __( 'Number of items refunded.', 'invoicing' ),
338
+                'label'       => __( 'Refunded Items', 'invoicing' ),
339
+            ),
340
+            'total_tax'           => array(
341
+                'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
+                'label'       => __( 'Tax', 'invoicing' ),
343
+            ),
344
+            'total_refunded_tax'  => array(
345
+                'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
+                'label'       => __( 'Refunded Tax', 'invoicing' ),
347
+            ),
348
+            'total_fees'          => array(
349
+                'description' => __( 'Total fees charged.', 'invoicing' ),
350
+                'label'       => __( 'Fees', 'invoicing' ),
351
+            ),
352
+            'total_refunds'       => array(
353
+                'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
+                'label'       => __( 'Refunded', 'invoicing' ),
355
+            ),
356
+            'total_discount'      => array(
357
+                'description' => __( 'Total of discounts used.', 'invoicing' ),
358
+                'label'       => __( 'Discounted', 'invoicing' ),
359
+            ),
360
+        );
361
+
362
+        return apply_filters( 'wpinv_report_cards', $cards );
363
+    }
364 364
 
365 365
 
366 366
 
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report Class.
@@ -23,26 +23,26 @@  discard block
 block discarded – undo
23 23
 	 */
24 24
 	public function __construct() {
25 25
 
26
-		$this->views        = array(
26
+		$this->views = array(
27 27
 
28 28
             'items'     => array(
29
-				'label' => __( 'Items', 'invoicing' ),
29
+				'label' => __('Items', 'invoicing'),
30 30
 				'class' => 'GetPaid_Reports_Report_Items',
31 31
 			),
32 32
 
33 33
 			'gateways'  => array(
34
-				'label' => __( 'Payment Methods', 'invoicing' ),
34
+				'label' => __('Payment Methods', 'invoicing'),
35 35
 				'class' => 'GetPaid_Reports_Report_Gateways',
36 36
 			),
37 37
 
38 38
 			'discounts' => array(
39
-				'label' => __( 'Discount Codes', 'invoicing' ),
39
+				'label' => __('Discount Codes', 'invoicing'),
40 40
 				'class' => 'GetPaid_Reports_Report_Discounts',
41 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
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	public function get_range() {
54 54
 		$valid_ranges = $this->get_periods();
55 55
 
56
-		if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
-			return sanitize_key( $_GET['date_range'] );
56
+		if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) {
57
+			return sanitize_key($_GET['date_range']);
58 58
 		}
59 59
 
60 60
 		return '7_days';
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
 	public function get_periods() {
69 69
 
70 70
 		$periods = array(
71
-			'today'        => __( 'Today', 'invoicing' ),
72
-			'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
-			'week'         => __( 'This week', 'invoicing' ),
74
-			'last_week'    => __( 'Last week', 'invoicing' ),
75
-			'7_days'       => __( 'Last 7 days', 'invoicing' ),
76
-			'month'        => __( 'This month', 'invoicing' ),
77
-			'last_month'   => __( 'Last month', 'invoicing' ),
78
-			'30_days'      => __( 'Last 30 days', 'invoicing' ),
79
-			'quarter'      => __( 'This Quarter', 'invoicing' ),
80
-			'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
-			'year'         => __( 'This year', 'invoicing' ),
82
-			'last_year'    => __( 'Last Year', 'invoicing' ),
83
-			'custom'       => __( 'Custom Date Range', 'invoicing' ),
71
+			'today'        => __('Today', 'invoicing'),
72
+			'yesterday'    => __('Yesterday', 'invoicing'),
73
+			'week'         => __('This week', 'invoicing'),
74
+			'last_week'    => __('Last week', 'invoicing'),
75
+			'7_days'       => __('Last 7 days', 'invoicing'),
76
+			'month'        => __('This month', 'invoicing'),
77
+			'last_month'   => __('Last month', 'invoicing'),
78
+			'30_days'      => __('Last 30 days', 'invoicing'),
79
+			'quarter'      => __('This Quarter', 'invoicing'),
80
+			'last_quarter' => __('Last Quarter', 'invoicing'),
81
+			'year'         => __('This year', 'invoicing'),
82
+			'last_year'    => __('Last Year', 'invoicing'),
83
+			'custom'       => __('Custom Date Range', 'invoicing'),
84 84
 		);
85 85
 
86
-		return apply_filters( 'getpaid_earning_periods', $periods );
86
+		return apply_filters('getpaid_earning_periods', $periods);
87 87
 	}
88 88
 
89 89
 	/**
@@ -96,21 +96,21 @@  discard block
 block discarded – undo
96 96
 		?>
97 97
 
98 98
 			<form method="get" class="getpaid-filter-earnings float-right">
99
-				<?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?>
100
-				<?php getpaid_hidden_field( 'tab', 'reports' ); ?>
99
+				<?php getpaid_hidden_field('page', isset($_GET['page']) ? sanitize_text_field($_GET['page']) : 'wpinv-reports'); ?>
100
+				<?php getpaid_hidden_field('tab', 'reports'); ?>
101 101
 				<select name='date_range'>
102
-					<?php foreach ( $this->get_periods() as $key => $label ) : ?>
103
-						<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo esc_html( $label ); ?></option>
102
+					<?php foreach ($this->get_periods() as $key => $label) : ?>
103
+						<option value="<?php echo esc_attr($key); ?>" <?php selected($key, $range); ?>><?php echo esc_html($label); ?></option>
104 104
 					<?php endforeach; ?>
105 105
 				</select>
106 106
 				<span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>">
107 107
 					<input type="text" name="from" class="getpaid-from align-middle" />
108
-						<?php _e( 'to', 'invoicing' ); ?>
108
+						<?php _e('to', 'invoicing'); ?>
109 109
 					<input type="text" name="to" class="getpaid-to align-middle" />
110 110
 				</span>
111 111
 				<button type="submit" class="button button-primary">
112 112
 					<i class="fa fa-chevron-right fa-lg"></i>
113
-					<span class="screen-reader-text"><?php _e( 'View Reports', 'invoicing' ); ?></span>
113
+					<span class="screen-reader-text"><?php _e('View Reports', 'invoicing'); ?></span>
114 114
 				</button>
115 115
 			</form>
116 116
 
@@ -159,17 +159,17 @@  discard block
 block discarded – undo
159 159
 
160 160
 				<div class="col-12 col-md-4">
161 161
 					<div class="row getpaid-report-cards">
162
-						<?php foreach ( $this->get_cards() as $key => $card ) : ?>
162
+						<?php foreach ($this->get_cards() as $key => $card) : ?>
163 163
 							<div class="col-12 mb-4">
164 164
 
165
-								<!-- <?php echo esc_html( $card['label'] ); ?> Card -->
166
-								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class( $key ); ?>">
165
+								<!-- <?php echo esc_html($card['label']); ?> Card -->
166
+								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class($key); ?>">
167 167
 
168 168
 									<div class="card-body">
169 169
 
170 170
 										<p class="getpaid-current text-uppercase small mb-2">
171
-											<strong><?php echo esc_html( $card['label'] ); ?></strong>
172
-											<span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
171
+											<strong><?php echo esc_html($card['label']); ?></strong>
172
+											<span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
173 173
 										</p>
174 174
 										<h5 class="font-weight-bold mb-0">
175 175
 											<span class="getpaid-report-card-value">
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 
181 181
 										<hr>
182 182
 
183
-										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e( 'Previous Period', 'invoicing' ); ?></strong></p>
183
+										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e('Previous Period', 'invoicing'); ?></strong></p>
184 184
 										<h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0">
185 185
 											<span class="spinner is-active float-none"></span>
186 186
 										</h5>
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 									</div>
189 189
 
190 190
 								</div>
191
-								<!-- <?php echo esc_html( $card['label'] ); ?> Card -->
191
+								<!-- <?php echo esc_html($card['label']); ?> Card -->
192 192
 
193 193
 							</div>
194 194
 						<?php endforeach; ?>
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
 
214 214
 		?>
215 215
 
216
-			<?php foreach ( $graphs as $key => $graph ) : ?>
216
+			<?php foreach ($graphs as $key => $graph) : ?>
217 217
 				<div class="row mb-4">
218 218
 					<div class="col-12">
219 219
 						<div class="card m-0 p-0 single-report-card" style="max-width:100%">
220 220
 							<div class="card-header">
221
-								<strong><?php echo esc_html( $graph ); ?></strong>
221
+								<strong><?php echo esc_html($graph); ?></strong>
222 222
 							</div>
223 223
 							<div class="card-body">
224
-								<canvas id="getpaid-chartjs-<?php echo esc_attr( $key ); ?>"></canvas>
224
+								<canvas id="getpaid-chartjs-<?php echo esc_attr($key); ?>"></canvas>
225 225
 							</div>
226 226
 						</div>
227 227
 					</div>
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 	 * Retrieves the download url.
237 237
 	 *
238 238
 	 */
239
-	public function get_download_url( $graph, $file_type ) {
239
+	public function get_download_url($graph, $file_type) {
240 240
 
241 241
 		return wp_nonce_url(
242 242
 			add_query_arg(
243 243
 				array(
244 244
 					'getpaid-admin-action' => 'download_graph',
245
-					'file_type'            => urlencode( $file_type ),
246
-					'graph'                => urlencode( $graph ),
245
+					'file_type'            => urlencode($file_type),
246
+					'graph'                => urlencode($graph),
247 247
 				)
248 248
 			),
249 249
 			'getpaid-nonce',
@@ -260,27 +260,27 @@  discard block
 block discarded – undo
260 260
 
261 261
 		?>
262 262
 
263
-			<?php foreach ( $this->views as $key => $view ) : ?>
263
+			<?php foreach ($this->views as $key => $view) : ?>
264 264
 				<div class="row mb-4">
265 265
 					<div class="col-12">
266 266
 						<div class="card m-0 p-0" style="max-width:100%">
267 267
 							<div class="card-header">
268 268
 								<div class="row">
269
-									<div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-9' : 'col-12'; ?>">
270
-										<strong><?php echo esc_html( $view['label'] ); ?></strong>
269
+									<div class="<?php echo empty($view['disable-downloads']) ? 'col-9' : 'col-12'; ?>">
270
+										<strong><?php echo esc_html($view['label']); ?></strong>
271 271
 									</div>
272
-									<div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-3' : 'd-none'; ?>">
273
-										<a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>">
272
+									<div class="<?php echo empty($view['disable-downloads']) ? 'col-3' : 'd-none'; ?>">
273
+										<a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>">
274 274
 											<i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i>
275
-											<span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span>
275
+											<span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span>
276 276
 										</a>
277
-										<a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>">
277
+										<a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>">
278 278
 											<i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i>
279
-											<span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span>
279
+											<span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span>
280 280
 										</a>
281
-										<a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>">
281
+										<a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>">
282 282
 											<i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i>
283
-											<span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span>
283
+											<span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span>
284 284
 										</a>
285 285
 									</div>
286 286
 								</div>
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 
300 300
 		<?php
301 301
 
302
-		do_action( 'getpaid_reports_display_right', $this );
302
+		do_action('getpaid_reports_display_right', $this);
303 303
 	}
304 304
 
305 305
 	/**
@@ -310,56 +310,56 @@  discard block
 block discarded – undo
310 310
 
311 311
 		$cards = array(
312 312
 			'total_sales'         => array(
313
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
313
+				'description' => __('Gross sales in the period.', 'invoicing'),
314
+				'label'       => __('Gross Revenue', 'invoicing'),
315 315
 			),
316 316
 			'net_sales'           => array(
317
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
318
-				'label'       => __( 'Net Revenue', 'invoicing' ),
317
+				'description' => __('Net sales in the period.', 'invoicing'),
318
+				'label'       => __('Net Revenue', 'invoicing'),
319 319
 			),
320 320
 			'average_sales'       => array(
321
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
321
+				'description' => __('Average net daily/monthly sales.', 'invoicing'),
322
+				'label'       => __('Avg. Net Sales', 'invoicing'),
323 323
 			),
324 324
 			'average_total_sales' => array(
325
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
325
+				'description' => __('Average gross daily/monthly sales.', 'invoicing'),
326
+				'label'       => __('Avg. Gross Sales', 'invoicing'),
327 327
 			),
328 328
 			'total_invoices'      => array(
329
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
329
+				'description' => __('Number of paid invoices.', 'invoicing'),
330
+				'label'       => __('Paid Invoices', 'invoicing'),
331 331
 			),
332 332
 			'total_items'         => array(
333
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
334
-				'label'       => __( 'Purchased Items', 'invoicing' ),
333
+				'description' => __('Number of items purchased.', 'invoicing'),
334
+				'label'       => __('Purchased Items', 'invoicing'),
335 335
 			),
336 336
 			'refunded_items'      => array(
337
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
338
-				'label'       => __( 'Refunded Items', 'invoicing' ),
337
+				'description' => __('Number of items refunded.', 'invoicing'),
338
+				'label'       => __('Refunded Items', 'invoicing'),
339 339
 			),
340 340
 			'total_tax'           => array(
341
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
-				'label'       => __( 'Tax', 'invoicing' ),
341
+				'description' => __('Total charged for taxes.', 'invoicing'),
342
+				'label'       => __('Tax', 'invoicing'),
343 343
 			),
344 344
 			'total_refunded_tax'  => array(
345
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
345
+				'description' => __('Total refunded for taxes.', 'invoicing'),
346
+				'label'       => __('Refunded Tax', 'invoicing'),
347 347
 			),
348 348
 			'total_fees'          => array(
349
-				'description' => __( 'Total fees charged.', 'invoicing' ),
350
-				'label'       => __( 'Fees', 'invoicing' ),
349
+				'description' => __('Total fees charged.', 'invoicing'),
350
+				'label'       => __('Fees', 'invoicing'),
351 351
 			),
352 352
 			'total_refunds'       => array(
353
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
-				'label'       => __( 'Refunded', 'invoicing' ),
353
+				'description' => __('Total of refunded invoices.', 'invoicing'),
354
+				'label'       => __('Refunded', 'invoicing'),
355 355
 			),
356 356
 			'total_discount'      => array(
357
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
358
-				'label'       => __( 'Discounted', 'invoicing' ),
357
+				'description' => __('Total of discounts used.', 'invoicing'),
358
+				'label'       => __('Discounted', 'invoicing'),
359 359
 			),
360 360
 		);
361 361
 
362
-		return apply_filters( 'wpinv_report_cards', $cards );
362
+		return apply_filters('wpinv_report_cards', $cards);
363 363
 	}
364 364
 
365 365
 
Please login to merge, or discard this patch.
includes/reports/class-getpaid-invoice-exporter.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -12,194 +12,194 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * Retrieves invoices query args.
17
-	 *
18
-	 * @param string $post_type post type to retrieve.
19
-	 * @param array $args Args to search for.
20
-	 * @return array
21
-	 */
22
-	public function get_invoice_query_args( $post_type, $args ) {
23
-
24
-		$query_args = array(
25
-			'post_type'              => $post_type,
26
-			'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
-			'posts_per_page'         => -1,
28
-			'no_found_rows'          => true,
29
-			'update_post_term_cache' => false,
30
-			'fields'                 => 'ids',
31
-		);
32
-
33
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
-			$query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
-		}
36
-
37
-		$date_query = array();
38
-		if ( ! empty( $args['to_date'] ) ) {
39
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
40
-		}
41
-
42
-		if ( ! empty( $args['from_date'] ) ) {
43
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
44
-		}
45
-
46
-		if ( ! empty( $date_query ) ) {
47
-			$date_query['inclusive']  = true;
48
-			$query_args['date_query'] = array( $date_query );
49
-		}
50
-
51
-		return $query_args;
52
-	}
53
-
54
-	/**
55
-	 * Retrieves invoices.
56
-	 *
57
-	 * @param array $query_args WP_Query args.
58
-	 * @return WPInv_Invoice[]
59
-	 */
60
-	public function get_invoices( $query_args ) {
61
-
62
-		// Get invoices.
63
-		$invoices = new WP_Query( $query_args );
64
-
65
-		// Prepare the results.
66
-		return array_map( 'wpinv_get_invoice', $invoices->posts );
67
-
68
-	}
69
-
70
-	/**
71
-	 * Handles the actual download.
72
-	 *
73
-	 */
74
-	public function export( $post_type, $args ) {
75
-
76
-		$invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
-		$stream    = $this->prepare_output();
78
-		$headers   = $this->get_export_fields( $post_type );
79
-		$file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
-
81
-		if ( 'csv' == $file_type ) {
82
-			$this->download_csv( $invoices, $stream, $headers );
83
-		} elseif ( 'xml' == $file_type ) {
84
-			$this->download_xml( $invoices, $stream, $headers );
85
-		} else {
86
-			$this->download_json( $invoices, $stream, $headers );
87
-		}
88
-
89
-		fclose( $stream );
90
-		exit;
91
-	}
92
-
93
-	/**
94
-	 * Prepares a single invoice for download.
95
-	 *
96
-	 * @param WPInv_Invoice $invoice The invoice to prepare..
97
-	 * @param array $fields The fields to stream.
98
-	 * @since       1.0.19
99
-	 * @return array
100
-	 */
101
-	public function prepare_row( $invoice, $fields ) {
102
-
103
-		$prepared      = array();
104
-		$amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
-
106
-		foreach ( $fields as $field ) {
107
-
108
-			$value  = '';
109
-			$method = "get_$field";
110
-
111
-			if ( method_exists( $invoice, $method ) ) {
112
-				$value  = $invoice->$method();
113
-			}
114
-
115
-			if ( in_array( $field, $amount_fields ) ) {
116
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
117
-			}
118
-
119
-			$prepared[ $field ] = wpinv_clean( $value );
120
-
121
-		}
122
-
123
-		return $prepared;
124
-	}
125
-
126
-	/**
127
-	 * Retrieves export fields.
128
-	 *
129
-	 * @param string $post_type
130
-	 * @since       1.0.19
131
-	 * @return array
132
-	 */
133
-	public function get_export_fields( $post_type ) {
134
-
135
-		$fields = array(
136
-			'id',
137
-			'parent_id',
138
-			'status',
139
-			'date_created',
140
-			'date_modified',
141
-			'date_due',
142
-			'date_completed',
143
-			'number',
144
-			'key',
145
-			'description',
146
-			'post_type',
147
-			'mode',
148
-			'customer_id',
149
-			'customer_first_name',
150
-			'customer_last_name',
151
-			'customer_phone',
152
-			'customer_email',
153
-			'customer_country',
154
-			'customer_city',
155
-			'customer_state',
156
-			'customer_zip',
157
-			'customer_company',
158
-			'customer_vat_number',
159
-			'customer_address',
160
-			'subtotal',
161
-			'total_discount',
162
-			'total_tax',
163
-			'total_fees',
164
-			'fees',
165
-			'discounts',
166
-			'taxes',
167
-			'cart_details',
168
-			'item_ids',
169
-			'payment_form',
170
-			'discount_code',
171
-			'gateway',
172
-			'transaction_id',
173
-			'currency',
174
-			'disable_taxes',
175
-			'subscription_id',
176
-			'remote_subscription_id',
177
-			'is_viewed',
178
-			'email_cc',
179
-			'template',
180
-			'created_via',
181
-    	);
182
-
183
-		return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
184
-	}
185
-
186
-	/**
187
-	 * Retrieves amount fields.
188
-	 *
189
-	 * @param string $post_type
190
-	 * @since       1.0.19
191
-	 * @return array
192
-	 */
193
-	public function get_amount_fields( $post_type ) {
194
-
195
-		$fields = array(
196
-			'subtotal',
197
-			'total_discount',
198
-			'total_tax',
199
-			'total_fees',
200
-    	);
201
-
202
-		return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
203
-	}
15
+    /**
16
+     * Retrieves invoices query args.
17
+     *
18
+     * @param string $post_type post type to retrieve.
19
+     * @param array $args Args to search for.
20
+     * @return array
21
+     */
22
+    public function get_invoice_query_args( $post_type, $args ) {
23
+
24
+        $query_args = array(
25
+            'post_type'              => $post_type,
26
+            'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
+            'posts_per_page'         => -1,
28
+            'no_found_rows'          => true,
29
+            'update_post_term_cache' => false,
30
+            'fields'                 => 'ids',
31
+        );
32
+
33
+        if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
+            $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
+        }
36
+
37
+        $date_query = array();
38
+        if ( ! empty( $args['to_date'] ) ) {
39
+            $date_query['before'] = wpinv_clean( $args['to_date'] );
40
+        }
41
+
42
+        if ( ! empty( $args['from_date'] ) ) {
43
+            $date_query['after'] = wpinv_clean( $args['from_date'] );
44
+        }
45
+
46
+        if ( ! empty( $date_query ) ) {
47
+            $date_query['inclusive']  = true;
48
+            $query_args['date_query'] = array( $date_query );
49
+        }
50
+
51
+        return $query_args;
52
+    }
53
+
54
+    /**
55
+     * Retrieves invoices.
56
+     *
57
+     * @param array $query_args WP_Query args.
58
+     * @return WPInv_Invoice[]
59
+     */
60
+    public function get_invoices( $query_args ) {
61
+
62
+        // Get invoices.
63
+        $invoices = new WP_Query( $query_args );
64
+
65
+        // Prepare the results.
66
+        return array_map( 'wpinv_get_invoice', $invoices->posts );
67
+
68
+    }
69
+
70
+    /**
71
+     * Handles the actual download.
72
+     *
73
+     */
74
+    public function export( $post_type, $args ) {
75
+
76
+        $invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
+        $stream    = $this->prepare_output();
78
+        $headers   = $this->get_export_fields( $post_type );
79
+        $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
+
81
+        if ( 'csv' == $file_type ) {
82
+            $this->download_csv( $invoices, $stream, $headers );
83
+        } elseif ( 'xml' == $file_type ) {
84
+            $this->download_xml( $invoices, $stream, $headers );
85
+        } else {
86
+            $this->download_json( $invoices, $stream, $headers );
87
+        }
88
+
89
+        fclose( $stream );
90
+        exit;
91
+    }
92
+
93
+    /**
94
+     * Prepares a single invoice for download.
95
+     *
96
+     * @param WPInv_Invoice $invoice The invoice to prepare..
97
+     * @param array $fields The fields to stream.
98
+     * @since       1.0.19
99
+     * @return array
100
+     */
101
+    public function prepare_row( $invoice, $fields ) {
102
+
103
+        $prepared      = array();
104
+        $amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
+
106
+        foreach ( $fields as $field ) {
107
+
108
+            $value  = '';
109
+            $method = "get_$field";
110
+
111
+            if ( method_exists( $invoice, $method ) ) {
112
+                $value  = $invoice->$method();
113
+            }
114
+
115
+            if ( in_array( $field, $amount_fields ) ) {
116
+                $value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
117
+            }
118
+
119
+            $prepared[ $field ] = wpinv_clean( $value );
120
+
121
+        }
122
+
123
+        return $prepared;
124
+    }
125
+
126
+    /**
127
+     * Retrieves export fields.
128
+     *
129
+     * @param string $post_type
130
+     * @since       1.0.19
131
+     * @return array
132
+     */
133
+    public function get_export_fields( $post_type ) {
134
+
135
+        $fields = array(
136
+            'id',
137
+            'parent_id',
138
+            'status',
139
+            'date_created',
140
+            'date_modified',
141
+            'date_due',
142
+            'date_completed',
143
+            'number',
144
+            'key',
145
+            'description',
146
+            'post_type',
147
+            'mode',
148
+            'customer_id',
149
+            'customer_first_name',
150
+            'customer_last_name',
151
+            'customer_phone',
152
+            'customer_email',
153
+            'customer_country',
154
+            'customer_city',
155
+            'customer_state',
156
+            'customer_zip',
157
+            'customer_company',
158
+            'customer_vat_number',
159
+            'customer_address',
160
+            'subtotal',
161
+            'total_discount',
162
+            'total_tax',
163
+            'total_fees',
164
+            'fees',
165
+            'discounts',
166
+            'taxes',
167
+            'cart_details',
168
+            'item_ids',
169
+            'payment_form',
170
+            'discount_code',
171
+            'gateway',
172
+            'transaction_id',
173
+            'currency',
174
+            'disable_taxes',
175
+            'subscription_id',
176
+            'remote_subscription_id',
177
+            'is_viewed',
178
+            'email_cc',
179
+            'template',
180
+            'created_via',
181
+        );
182
+
183
+        return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
184
+    }
185
+
186
+    /**
187
+     * Retrieves amount fields.
188
+     *
189
+     * @param string $post_type
190
+     * @since       1.0.19
191
+     * @return array
192
+     */
193
+    public function get_amount_fields( $post_type ) {
194
+
195
+        $fields = array(
196
+            'subtotal',
197
+            'total_discount',
198
+            'total_tax',
199
+            'total_fees',
200
+        );
201
+
202
+        return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
203
+    }
204 204
 
205 205
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Invoice_Exporter Class.
@@ -19,33 +19,33 @@  discard block
 block discarded – undo
19 19
 	 * @param array $args Args to search for.
20 20
 	 * @return array
21 21
 	 */
22
-	public function get_invoice_query_args( $post_type, $args ) {
22
+	public function get_invoice_query_args($post_type, $args) {
23 23
 
24 24
 		$query_args = array(
25 25
 			'post_type'              => $post_type,
26
-			'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
26
+			'post_status'            => array_keys(wpinv_get_invoice_statuses(true, false, $post_type)),
27 27
 			'posts_per_page'         => -1,
28 28
 			'no_found_rows'          => true,
29 29
 			'update_post_term_cache' => false,
30 30
 			'fields'                 => 'ids',
31 31
 		);
32 32
 
33
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
-			$query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
33
+		if (!empty($args['status']) && in_array($args['status'], $query_args['post_status'], true)) {
34
+			$query_args['post_status'] = wpinv_clean(wpinv_parse_list($args['status']));
35 35
 		}
36 36
 
37 37
 		$date_query = array();
38
-		if ( ! empty( $args['to_date'] ) ) {
39
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
38
+		if (!empty($args['to_date'])) {
39
+			$date_query['before'] = wpinv_clean($args['to_date']);
40 40
 		}
41 41
 
42
-		if ( ! empty( $args['from_date'] ) ) {
43
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
42
+		if (!empty($args['from_date'])) {
43
+			$date_query['after'] = wpinv_clean($args['from_date']);
44 44
 		}
45 45
 
46
-		if ( ! empty( $date_query ) ) {
46
+		if (!empty($date_query)) {
47 47
 			$date_query['inclusive']  = true;
48
-			$query_args['date_query'] = array( $date_query );
48
+			$query_args['date_query'] = array($date_query);
49 49
 		}
50 50
 
51 51
 		return $query_args;
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 	 * @param array $query_args WP_Query args.
58 58
 	 * @return WPInv_Invoice[]
59 59
 	 */
60
-	public function get_invoices( $query_args ) {
60
+	public function get_invoices($query_args) {
61 61
 
62 62
 		// Get invoices.
63
-		$invoices = new WP_Query( $query_args );
63
+		$invoices = new WP_Query($query_args);
64 64
 
65 65
 		// Prepare the results.
66
-		return array_map( 'wpinv_get_invoice', $invoices->posts );
66
+		return array_map('wpinv_get_invoice', $invoices->posts);
67 67
 
68 68
 	}
69 69
 
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
 	 * Handles the actual download.
72 72
 	 *
73 73
 	 */
74
-	public function export( $post_type, $args ) {
74
+	public function export($post_type, $args) {
75 75
 
76
-		$invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
76
+		$invoices  = $this->get_invoices($this->get_invoice_query_args($post_type, $args));
77 77
 		$stream    = $this->prepare_output();
78
-		$headers   = $this->get_export_fields( $post_type );
79
-		$file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
78
+		$headers   = $this->get_export_fields($post_type);
79
+		$file_type = $this->prepare_file_type(strtolower(getpaid_get_post_type_label($post_type)));
80 80
 
81
-		if ( 'csv' == $file_type ) {
82
-			$this->download_csv( $invoices, $stream, $headers );
83
-		} elseif ( 'xml' == $file_type ) {
84
-			$this->download_xml( $invoices, $stream, $headers );
81
+		if ('csv' == $file_type) {
82
+			$this->download_csv($invoices, $stream, $headers);
83
+		} elseif ('xml' == $file_type) {
84
+			$this->download_xml($invoices, $stream, $headers);
85 85
 		} else {
86
-			$this->download_json( $invoices, $stream, $headers );
86
+			$this->download_json($invoices, $stream, $headers);
87 87
 		}
88 88
 
89
-		fclose( $stream );
89
+		fclose($stream);
90 90
 		exit;
91 91
 	}
92 92
 
@@ -98,25 +98,25 @@  discard block
 block discarded – undo
98 98
 	 * @since       1.0.19
99 99
 	 * @return array
100 100
 	 */
101
-	public function prepare_row( $invoice, $fields ) {
101
+	public function prepare_row($invoice, $fields) {
102 102
 
103 103
 		$prepared      = array();
104
-		$amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
104
+		$amount_fields = $this->get_amount_fields($invoice->get_post_type());
105 105
 
106
-		foreach ( $fields as $field ) {
106
+		foreach ($fields as $field) {
107 107
 
108 108
 			$value  = '';
109 109
 			$method = "get_$field";
110 110
 
111
-			if ( method_exists( $invoice, $method ) ) {
112
-				$value  = $invoice->$method();
111
+			if (method_exists($invoice, $method)) {
112
+				$value = $invoice->$method();
113 113
 			}
114 114
 
115
-			if ( in_array( $field, $amount_fields ) ) {
116
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
115
+			if (in_array($field, $amount_fields)) {
116
+				$value = wpinv_round_amount(wpinv_sanitize_amount($value));
117 117
 			}
118 118
 
119
-			$prepared[ $field ] = wpinv_clean( $value );
119
+			$prepared[$field] = wpinv_clean($value);
120 120
 
121 121
 		}
122 122
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @since       1.0.19
131 131
 	 * @return array
132 132
 	 */
133
-	public function get_export_fields( $post_type ) {
133
+	public function get_export_fields($post_type) {
134 134
 
135 135
 		$fields = array(
136 136
 			'id',
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 			'created_via',
181 181
     	);
182 182
 
183
-		return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
183
+		return apply_filters('getpaid_invoice_exporter_get_fields', $fields, $post_type);
184 184
 	}
185 185
 
186 186
 	/**
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @since       1.0.19
191 191
 	 * @return array
192 192
 	 */
193
-	public function get_amount_fields( $post_type ) {
193
+	public function get_amount_fields($post_type) {
194 194
 
195 195
 		$fields = array(
196 196
 			'subtotal',
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 			'total_fees',
200 200
     	);
201 201
 
202
-		return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
202
+		return apply_filters('getpaid_invoice_exporter_get_amount_fields', $fields, $post_type);
203 203
 	}
204 204
 
205 205
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-subscription-exporter.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -12,176 +12,176 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * Retrieves subscription query args.
17
-	 *
18
-	 * @param array $args Args to search for.
19
-	 * @return array
20
-	 */
21
-	public function get_subscription_query_args( $args ) {
22
-
23
-		$query_args = array(
24
-			'status'      => 'all',
25
-			'number'      => -1,
26
-			'count_total' => false,
27
-			'fields'      => 'all',
28
-		);
29
-
30
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) {
31
-			$query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
32
-		}
33
-
34
-		$date_query = array();
35
-		if ( ! empty( $args['to_date'] ) ) {
36
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
37
-		}
38
-
39
-		if ( ! empty( $args['from_date'] ) ) {
40
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
41
-		}
42
-
43
-		if ( ! empty( $date_query ) ) {
44
-			$date_query['inclusive']          = true;
45
-			$query_args['date_created_query'] = array( $date_query );
46
-		}
47
-
48
-		return $query_args;
49
-	}
50
-
51
-	/**
52
-	 * Retrieves subscriptions.
53
-	 *
54
-	 * @param array $query_args GetPaid_Subscriptions_Query args.
55
-	 * @return WPInv_Subscription[]
56
-	 */
57
-	public function get_subscriptions( $query_args ) {
58
-
59
-		// Get subscriptions.
60
-		$subscriptions = new GetPaid_Subscriptions_Query( $query_args );
61
-
62
-		// Prepare the results.
63
-		return $subscriptions->get_results();
64
-
65
-	}
66
-
67
-	/**
68
-	 * Handles the actual download.
69
-	 *
70
-	 */
71
-	public function export( $post_type, $args ) {
72
-
73
-		$subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) );
74
-		$stream        = $this->prepare_output();
75
-		$headers       = $this->get_export_fields();
76
-		$file_type     = $this->prepare_file_type( 'subscriptions' );
77
-
78
-		if ( 'csv' == $file_type ) {
79
-			$this->download_csv( $subscriptions, $stream, $headers );
80
-		} elseif ( 'xml' == $file_type ) {
81
-			$this->download_xml( $subscriptions, $stream, $headers );
82
-		} else {
83
-			$this->download_json( $subscriptions, $stream, $headers );
84
-		}
85
-
86
-		fclose( $stream );
87
-		exit;
88
-	}
89
-
90
-	/**
91
-	 * Prepares a single subscription for download.
92
-	 *
93
-	 * @param WPInv_Subscription $subscription The subscription to prepare..
94
-	 * @param array $fields The fields to stream.
95
-	 * @since       1.0.19
96
-	 * @return array
97
-	 */
98
-	public function prepare_row( $subscription, $fields ) {
99
-
100
-		$prepared      = array();
101
-		$amount_fields = $this->get_amount_fields();
102
-		$invoice       = $subscription->get_parent_payment();
103
-
104
-		foreach ( $fields as $field ) {
105
-
106
-			$value  = '';
107
-			$method = "get_$field";
108
-
109
-			if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) {
110
-
111
-				if ( method_exists( $invoice, $method ) ) {
112
-					$value  = $invoice->$method();
113
-				}
15
+    /**
16
+     * Retrieves subscription query args.
17
+     *
18
+     * @param array $args Args to search for.
19
+     * @return array
20
+     */
21
+    public function get_subscription_query_args( $args ) {
22
+
23
+        $query_args = array(
24
+            'status'      => 'all',
25
+            'number'      => -1,
26
+            'count_total' => false,
27
+            'fields'      => 'all',
28
+        );
29
+
30
+        if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) {
31
+            $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
32
+        }
33
+
34
+        $date_query = array();
35
+        if ( ! empty( $args['to_date'] ) ) {
36
+            $date_query['before'] = wpinv_clean( $args['to_date'] );
37
+        }
38
+
39
+        if ( ! empty( $args['from_date'] ) ) {
40
+            $date_query['after'] = wpinv_clean( $args['from_date'] );
41
+        }
42
+
43
+        if ( ! empty( $date_query ) ) {
44
+            $date_query['inclusive']          = true;
45
+            $query_args['date_created_query'] = array( $date_query );
46
+        }
47
+
48
+        return $query_args;
49
+    }
50
+
51
+    /**
52
+     * Retrieves subscriptions.
53
+     *
54
+     * @param array $query_args GetPaid_Subscriptions_Query args.
55
+     * @return WPInv_Subscription[]
56
+     */
57
+    public function get_subscriptions( $query_args ) {
58
+
59
+        // Get subscriptions.
60
+        $subscriptions = new GetPaid_Subscriptions_Query( $query_args );
61
+
62
+        // Prepare the results.
63
+        return $subscriptions->get_results();
64
+
65
+    }
66
+
67
+    /**
68
+     * Handles the actual download.
69
+     *
70
+     */
71
+    public function export( $post_type, $args ) {
72
+
73
+        $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) );
74
+        $stream        = $this->prepare_output();
75
+        $headers       = $this->get_export_fields();
76
+        $file_type     = $this->prepare_file_type( 'subscriptions' );
77
+
78
+        if ( 'csv' == $file_type ) {
79
+            $this->download_csv( $subscriptions, $stream, $headers );
80
+        } elseif ( 'xml' == $file_type ) {
81
+            $this->download_xml( $subscriptions, $stream, $headers );
82
+        } else {
83
+            $this->download_json( $subscriptions, $stream, $headers );
84
+        }
85
+
86
+        fclose( $stream );
87
+        exit;
88
+    }
89
+
90
+    /**
91
+     * Prepares a single subscription for download.
92
+     *
93
+     * @param WPInv_Subscription $subscription The subscription to prepare..
94
+     * @param array $fields The fields to stream.
95
+     * @since       1.0.19
96
+     * @return array
97
+     */
98
+    public function prepare_row( $subscription, $fields ) {
99
+
100
+        $prepared      = array();
101
+        $amount_fields = $this->get_amount_fields();
102
+        $invoice       = $subscription->get_parent_payment();
103
+
104
+        foreach ( $fields as $field ) {
105
+
106
+            $value  = '';
107
+            $method = "get_$field";
108
+
109
+            if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) {
110
+
111
+                if ( method_exists( $invoice, $method ) ) {
112
+                    $value  = $invoice->$method();
113
+                }
114 114
 } elseif ( method_exists( $subscription, $method ) ) {
115
-				$value  = $subscription->$method();
116
-			}
117
-
118
-			if ( in_array( $field, $amount_fields ) ) {
119
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
120
-			}
121
-
122
-			$prepared[ $field ] = wpinv_clean( $value );
123
-
124
-		}
125
-
126
-		return $prepared;
127
-	}
128
-
129
-	/**
130
-	 * Retrieves export fields.
131
-	 *
132
-	 * @since       1.0.19
133
-	 * @return array
134
-	 */
135
-	public function get_export_fields() {
136
-
137
-		$fields = array(
138
-			'id',
139
-			'currency',
140
-			'initial_amount',
141
-			'recurring_amount',
142
-			'trial_period',
143
-			'frequency',
144
-			'period',
145
-			'bill_times',
146
-			'parent_payment_id',
147
-			'profile_id',
148
-			'product_id',
149
-			'status',
150
-			'date_created',
151
-			'date_expires',
152
-
153
-			'customer_id',
154
-			'customer_first_name',
155
-			'customer_last_name',
156
-			'customer_phone',
157
-			'customer_email',
158
-			'customer_country',
159
-			'customer_city',
160
-			'customer_state',
161
-			'customer_zip',
162
-			'customer_company',
163
-			'customer_vat_number',
164
-			'customer_address',
165
-
166
-    	);
167
-
168
-		return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields );
169
-	}
170
-
171
-	/**
172
-	 * Retrieves amount fields.
173
-	 *
174
-	 * @since       1.0.19
175
-	 * @return array
176
-	 */
177
-	public function get_amount_fields() {
178
-
179
-		$fields = array(
180
-			'initial_amount',
181
-			'recurring_amount',
182
-    	);
183
-
184
-		return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields );
185
-	}
115
+                $value  = $subscription->$method();
116
+            }
117
+
118
+            if ( in_array( $field, $amount_fields ) ) {
119
+                $value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
120
+            }
121
+
122
+            $prepared[ $field ] = wpinv_clean( $value );
123
+
124
+        }
125
+
126
+        return $prepared;
127
+    }
128
+
129
+    /**
130
+     * Retrieves export fields.
131
+     *
132
+     * @since       1.0.19
133
+     * @return array
134
+     */
135
+    public function get_export_fields() {
136
+
137
+        $fields = array(
138
+            'id',
139
+            'currency',
140
+            'initial_amount',
141
+            'recurring_amount',
142
+            'trial_period',
143
+            'frequency',
144
+            'period',
145
+            'bill_times',
146
+            'parent_payment_id',
147
+            'profile_id',
148
+            'product_id',
149
+            'status',
150
+            'date_created',
151
+            'date_expires',
152
+
153
+            'customer_id',
154
+            'customer_first_name',
155
+            'customer_last_name',
156
+            'customer_phone',
157
+            'customer_email',
158
+            'customer_country',
159
+            'customer_city',
160
+            'customer_state',
161
+            'customer_zip',
162
+            'customer_company',
163
+            'customer_vat_number',
164
+            'customer_address',
165
+
166
+        );
167
+
168
+        return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields );
169
+    }
170
+
171
+    /**
172
+     * Retrieves amount fields.
173
+     *
174
+     * @since       1.0.19
175
+     * @return array
176
+     */
177
+    public function get_amount_fields() {
178
+
179
+        $fields = array(
180
+            'initial_amount',
181
+            'recurring_amount',
182
+        );
183
+
184
+        return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields );
185
+    }
186 186
 
187 187
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Subscription_Exporter Class.
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 * @param array $args Args to search for.
19 19
 	 * @return array
20 20
 	 */
21
-	public function get_subscription_query_args( $args ) {
21
+	public function get_subscription_query_args($args) {
22 22
 
23 23
 		$query_args = array(
24 24
 			'status'      => 'all',
@@ -27,22 +27,22 @@  discard block
 block discarded – undo
27 27
 			'fields'      => 'all',
28 28
 		);
29 29
 
30
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) {
31
-			$query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
30
+		if (!empty($args['status']) && in_array($args['status'], array_keys(getpaid_get_subscription_statuses()), true)) {
31
+			$query_args['status'] = wpinv_clean(wpinv_parse_list($args['status']));
32 32
 		}
33 33
 
34 34
 		$date_query = array();
35
-		if ( ! empty( $args['to_date'] ) ) {
36
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
35
+		if (!empty($args['to_date'])) {
36
+			$date_query['before'] = wpinv_clean($args['to_date']);
37 37
 		}
38 38
 
39
-		if ( ! empty( $args['from_date'] ) ) {
40
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
39
+		if (!empty($args['from_date'])) {
40
+			$date_query['after'] = wpinv_clean($args['from_date']);
41 41
 		}
42 42
 
43
-		if ( ! empty( $date_query ) ) {
43
+		if (!empty($date_query)) {
44 44
 			$date_query['inclusive']          = true;
45
-			$query_args['date_created_query'] = array( $date_query );
45
+			$query_args['date_created_query'] = array($date_query);
46 46
 		}
47 47
 
48 48
 		return $query_args;
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 	 * @param array $query_args GetPaid_Subscriptions_Query args.
55 55
 	 * @return WPInv_Subscription[]
56 56
 	 */
57
-	public function get_subscriptions( $query_args ) {
57
+	public function get_subscriptions($query_args) {
58 58
 
59 59
 		// Get subscriptions.
60
-		$subscriptions = new GetPaid_Subscriptions_Query( $query_args );
60
+		$subscriptions = new GetPaid_Subscriptions_Query($query_args);
61 61
 
62 62
 		// Prepare the results.
63 63
 		return $subscriptions->get_results();
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
 	 * Handles the actual download.
69 69
 	 *
70 70
 	 */
71
-	public function export( $post_type, $args ) {
71
+	public function export($post_type, $args) {
72 72
 
73
-		$subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) );
73
+		$subscriptions = $this->get_subscriptions($this->get_subscription_query_args($args));
74 74
 		$stream        = $this->prepare_output();
75 75
 		$headers       = $this->get_export_fields();
76
-		$file_type     = $this->prepare_file_type( 'subscriptions' );
76
+		$file_type     = $this->prepare_file_type('subscriptions');
77 77
 
78
-		if ( 'csv' == $file_type ) {
79
-			$this->download_csv( $subscriptions, $stream, $headers );
80
-		} elseif ( 'xml' == $file_type ) {
81
-			$this->download_xml( $subscriptions, $stream, $headers );
78
+		if ('csv' == $file_type) {
79
+			$this->download_csv($subscriptions, $stream, $headers);
80
+		} elseif ('xml' == $file_type) {
81
+			$this->download_xml($subscriptions, $stream, $headers);
82 82
 		} else {
83
-			$this->download_json( $subscriptions, $stream, $headers );
83
+			$this->download_json($subscriptions, $stream, $headers);
84 84
 		}
85 85
 
86
-		fclose( $stream );
86
+		fclose($stream);
87 87
 		exit;
88 88
 	}
89 89
 
@@ -95,31 +95,31 @@  discard block
 block discarded – undo
95 95
 	 * @since       1.0.19
96 96
 	 * @return array
97 97
 	 */
98
-	public function prepare_row( $subscription, $fields ) {
98
+	public function prepare_row($subscription, $fields) {
99 99
 
100 100
 		$prepared      = array();
101 101
 		$amount_fields = $this->get_amount_fields();
102 102
 		$invoice       = $subscription->get_parent_payment();
103 103
 
104
-		foreach ( $fields as $field ) {
104
+		foreach ($fields as $field) {
105 105
 
106 106
 			$value  = '';
107 107
 			$method = "get_$field";
108 108
 
109
-			if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) {
109
+			if (0 === stripos($field, 'customer') || 'currency' === $field) {
110 110
 
111
-				if ( method_exists( $invoice, $method ) ) {
112
-					$value  = $invoice->$method();
111
+				if (method_exists($invoice, $method)) {
112
+					$value = $invoice->$method();
113 113
 				}
114
-} elseif ( method_exists( $subscription, $method ) ) {
115
-				$value  = $subscription->$method();
114
+} elseif (method_exists($subscription, $method)) {
115
+				$value = $subscription->$method();
116 116
 			}
117 117
 
118
-			if ( in_array( $field, $amount_fields ) ) {
119
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
118
+			if (in_array($field, $amount_fields)) {
119
+				$value = wpinv_round_amount(wpinv_sanitize_amount($value));
120 120
 			}
121 121
 
122
-			$prepared[ $field ] = wpinv_clean( $value );
122
+			$prepared[$field] = wpinv_clean($value);
123 123
 
124 124
 		}
125 125
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
     	);
167 167
 
168
-		return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields );
168
+		return apply_filters('getpaid_subscription_exporter_get_fields', $fields);
169 169
 	}
170 170
 
171 171
 	/**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			'recurring_amount',
182 182
     	);
183 183
 
184
-		return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields );
184
+		return apply_filters('getpaid_subscription_exporter_get_amount_fields', $fields);
185 185
 	}
186 186
 
187 187
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-gateways.php 2 patches
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.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report_Items Class.
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	 * Retrieves the earning sql.
22 22
 	 *
23 23
 	 */
24
-	public function get_sql( $range ) {
24
+	public function get_sql($range) {
25 25
 		global $wpdb;
26 26
 
27 27
 		$table      = $wpdb->prefix . 'getpaid_invoices';
28
-		$clauses    = $this->get_range_sql( $range );
28
+		$clauses    = $this->get_range_sql($range);
29 29
 
30 30
 		$sql        = "SELECT
31 31
 				meta.gateway AS gateway,
@@ -40,7 +40,7 @@  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
 
@@ -50,30 +50,30 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function prepare_stats() {
52 52
 		global $wpdb;
53
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
54
-		$this->stats = $this->normalize_stats( $this->stats );
53
+		$this->stats = $wpdb->get_results($this->get_sql($this->get_range()));
54
+		$this->stats = $this->normalize_stats($this->stats);
55 55
 	}
56 56
 
57 57
 	/**
58 58
 	 * Normalizes the report stats.
59 59
 	 *
60 60
 	 */
61
-	public function normalize_stats( $stats ) {
61
+	public function normalize_stats($stats) {
62 62
 		$normalized = array();
63 63
 		$others     = 0;
64 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 72
 			} else {
73 73
 
74 74
 				$normalized[] = array(
75
-					'total'   => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ),
76
-					'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ),
75
+					'total'   => wpinv_round_amount(wpinv_sanitize_amount($stat->total)),
76
+					'gateway' => strip_tags(wpinv_get_gateway_admin_label($stat->gateway)),
77 77
 				);
78 78
 
79 79
 			}
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 			$did++;
82 82
 		}
83 83
 
84
-		if ( $others > 0 ) {
84
+		if ($others > 0) {
85 85
 
86 86
 			$normalized[] = array(
87
-				'total'   => wpinv_round_amount( wpinv_sanitize_amount( $others ) ),
88
-				'gateway' => esc_html__( 'Others', 'invoicing' ),
87
+				'total'   => wpinv_round_amount(wpinv_sanitize_amount($others)),
88
+				'gateway' => esc_html__('Others', 'invoicing'),
89 89
 			);
90 90
 
91 91
 		}
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
 	 */
100 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 107
 		return array(
108 108
 			'data'            => $data,
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 *
117 117
 	 */
118 118
 	public function get_labels() {
119
-		return wp_list_pluck( $this->stats, 'gateway' );
119
+		return wp_list_pluck($this->stats, 'gateway');
120 120
 	}
121 121
 
122 122
 	/**
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 						{
138 138
 							type: 'doughnut',
139 139
 							data: {
140
-								'labels': <?php echo wp_json_encode( wp_kses_post_deep( $this->get_labels() ) ); ?>,
141
-								'datasets': [ <?php echo wp_json_encode( wp_kses_post_deep( $this->get_data() ) ); ?> ]
140
+								'labels': <?php echo wp_json_encode(wp_kses_post_deep($this->get_labels())); ?>,
141
+								'datasets': [ <?php echo wp_json_encode(wp_kses_post_deep($this->get_data())); ?> ]
142 142
 							},
143 143
 							options: {
144 144
 								legend: {
Please login to merge, or discard this patch.
includes/reports/class-getpaid-graph-downloader.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -12,218 +12,218 @@
 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
-		} elseif ( '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
-			}
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
+        } elseif ( '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 192
 }
193 193
 
194
-	}
194
+    }
195 195
 
196
-	/**
197
-	 * Prepares a single row for download.
198
-	 *
199
-	 * @param stdClass|array $row The row to prepare..
200
-	 * @param array $fields The fields to stream.
201
-	 * @since       1.0.19
202
-	 * @return array
203
-	 */
204
-	public function prepare_row( $row, $fields ) {
196
+    /**
197
+     * Prepares a single row for download.
198
+     *
199
+     * @param stdClass|array $row The row to prepare..
200
+     * @param array $fields The fields to stream.
201
+     * @since       1.0.19
202
+     * @return array
203
+     */
204
+    public function prepare_row( $row, $fields ) {
205 205
 
206
-		$prepared = array();
207
-		$row      = (array) $row;
206
+        $prepared = array();
207
+        $row      = (array) $row;
208 208
 
209
-		foreach ( $fields as $field ) {
209
+        foreach ( $fields as $field ) {
210 210
 
211
-			if ( $field === 'total' ) {
212
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
213
-				continue;
214
-			}
211
+            if ( $field === 'total' ) {
212
+                $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
213
+                continue;
214
+            }
215 215
 
216
-			if ( $field === 'total_raw' ) {
217
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
218
-				continue;
219
-			}
216
+            if ( $field === 'total_raw' ) {
217
+                $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
218
+                continue;
219
+            }
220 220
 
221
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
221
+            $prepared[ $field ] = strip_tags( $row[ $field ] );
222 222
 
223
-		}
223
+        }
224 224
 
225
-		return $prepared;
226
-	}
225
+        return $prepared;
226
+    }
227 227
 
228 228
 
229 229
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Graph_Downloader Class.
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32 32
 	 */
33
-	public function prepare_handler( $graph ) {
33
+	public function prepare_handler($graph) {
34 34
 
35
-		if ( empty( $this->handler->views[ $graph ] ) ) {
36
-			wp_die( __( 'Invalid Graph', 'invoicing' ), 400 );
35
+		if (empty($this->handler->views[$graph])) {
36
+			wp_die(__('Invalid Graph', 'invoicing'), 400);
37 37
 		}
38 38
 
39
-		return new $this->handler->views[ $graph ]['class']();
39
+		return new $this->handler->views[$graph]['class']();
40 40
 
41 41
 	}
42 42
 
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function prepare_output() {
49 49
 
50
-		$output  = fopen( 'php://output', 'w' );
50
+		$output = fopen('php://output', 'w');
51 51
 
52
-		if ( false === $output ) {
53
-			wp_die( __( 'Unsupported server', 'invoicing' ), 500 );
52
+		if (false === $output) {
53
+			wp_die(__('Unsupported server', 'invoicing'), 500);
54 54
 		}
55 55
 
56 56
 		return $output;
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return string
63 63
 	 */
64
-	public function prepare_file_type( $graph ) {
64
+	public function prepare_file_type($graph) {
65 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' ) );
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 68
 
69
-		header( "Content-Type:application/$file_type" );
70
-		header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
69
+		header("Content-Type:application/$file_type");
70
+		header("Content-Disposition:attachment;filename=$file_name.$file_type");
71 71
 
72 72
 		return $file_type;
73 73
 	}
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
 	 * Handles the actual download.
77 77
 	 *
78 78
 	 */
79
-	public function download( $graph ) {
79
+	public function download($graph) {
80 80
 		global $wpdb;
81 81
 
82
-		$handler   = $this->prepare_handler( $graph );
82
+		$handler   = $this->prepare_handler($graph);
83 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
-		} elseif ( 'xml' == $file_type ) {
91
-			$this->download_xml( $stats, $stream, $headers );
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
+		} elseif ('xml' == $file_type) {
91
+			$this->download_xml($stats, $stream, $headers);
92 92
 		} else {
93
-			$this->download_json( $stats, $stream, $headers );
93
+			$this->download_json($stats, $stream, $headers);
94 94
 		}
95 95
 
96
-		fclose( $stream );
96
+		fclose($stream);
97 97
 		exit;
98 98
 	}
99 99
 
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
 	 * @param array $headers The fields to stream.
106 106
 	 * @since       1.0.19
107 107
 	 */
108
-	public function download_csv( $stats, $stream, $headers ) {
108
+	public function download_csv($stats, $stream, $headers) {
109 109
 
110 110
 		// Output the csv column headers.
111
-		fputcsv( $stream, $headers );
111
+		fputcsv($stream, $headers);
112 112
 
113 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 );
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 118
 		}
119 119
 
120 120
 	}
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 	 * @param array $headers The fields to stream.
128 128
 	 * @since       1.0.19
129 129
 	 */
130
-	public function download_json( $stats, $stream, $headers ) {
130
+	public function download_json($stats, $stream, $headers) {
131 131
 
132 132
 		$prepared = array();
133 133
 
134 134
 		// Loop through
135
-		foreach ( $stats as $stat ) {
136
-			$prepared[] = $this->prepare_row( $stat, $headers );
135
+		foreach ($stats as $stat) {
136
+			$prepared[] = $this->prepare_row($stat, $headers);
137 137
 		}
138 138
 
139
-		fwrite( $stream, wp_json_encode( $prepared ) );
139
+		fwrite($stream, wp_json_encode($prepared));
140 140
 
141 141
 	}
142 142
 
@@ -148,19 +148,19 @@  discard block
 block discarded – undo
148 148
 	 * @param array $headers The fields to stream.
149 149
 	 * @since       1.0.19
150 150
 	 */
151
-	public function download_xml( $stats, $stream, $headers ) {
151
+	public function download_xml($stats, $stream, $headers) {
152 152
 
153 153
 		$prepared = array();
154 154
 
155 155
 		// Loop through
156
-		foreach ( $stats as $stat ) {
157
-			$prepared[] = $this->prepare_row( $stat, $headers );
156
+		foreach ($stats as $stat) {
157
+			$prepared[] = $this->prepare_row($stat, $headers);
158 158
 		}
159 159
 
160
-		$xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
161
-		$this->convert_array_xml( $prepared, $xml );
160
+		$xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
161
+		$this->convert_array_xml($prepared, $xml);
162 162
 
163
-		fwrite( $stream, $xml->asXML() );
163
+		fwrite($stream, $xml->asXML());
164 164
 
165 165
 	}
166 166
 
@@ -170,24 +170,24 @@  discard block
 block discarded – undo
170 170
 	 * @access      public
171 171
 	 * @since      1.0.19
172 172
 	 */
173
-	public function convert_array_xml( $data, $xml ) {
173
+	public function convert_array_xml($data, $xml) {
174 174
 
175 175
 		// Loop through
176
-		foreach ( $data as $key => $value ) {
176
+		foreach ($data as $key => $value) {
177 177
 
178
-			$key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key );
178
+			$key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key);
179 179
 
180
-			if ( is_array( $value ) ) {
180
+			if (is_array($value)) {
181 181
 
182
-				if ( is_numeric( $key ) ) {
182
+				if (is_numeric($key)) {
183 183
 					$key = 'item' . $key; //dealing with <0/>..<n/> issues
184 184
 				}
185 185
 
186
-				$subnode = $xml->addChild( $key );
187
-				$this->convert_array_xml( $value, $subnode );
186
+				$subnode = $xml->addChild($key);
187
+				$this->convert_array_xml($value, $subnode);
188 188
 
189 189
 			} else {
190
-				$xml->addChild( $key, htmlspecialchars( $value ) );
190
+				$xml->addChild($key, htmlspecialchars($value));
191 191
 			}
192 192
 }
193 193
 
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 	 * @since       1.0.19
202 202
 	 * @return array
203 203
 	 */
204
-	public function prepare_row( $row, $fields ) {
204
+	public function prepare_row($row, $fields) {
205 205
 
206 206
 		$prepared = array();
207 207
 		$row      = (array) $row;
208 208
 
209
-		foreach ( $fields as $field ) {
209
+		foreach ($fields as $field) {
210 210
 
211
-			if ( $field === 'total' ) {
212
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
211
+			if ($field === 'total') {
212
+				$prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES);
213 213
 				continue;
214 214
 			}
215 215
 
216
-			if ( $field === 'total_raw' ) {
217
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
216
+			if ($field === 'total_raw') {
217
+				$prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total']));
218 218
 				continue;
219 219
 			}
220 220
 
221
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
221
+			$prepared[$field] = strip_tags($row[$field]);
222 222
 
223 223
 		}
224 224
 
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Returns an array of eu states.
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @return array
13 13
  */
14 14
 function getpaid_get_eu_states() {
15
-    return wpinv_get_data( 'eu-states' );
15
+    return wpinv_get_data('eu-states');
16 16
 }
17 17
 
18 18
 /**
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
  *
21 21
  * @return bool
22 22
  */
23
-function getpaid_is_eu_state( $country ) {
24
-    return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states() ) ? true : false;
23
+function getpaid_is_eu_state($country) {
24
+    return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states()) ? true : false;
25 25
 }
26 26
 
27 27
 /**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @return array
31 31
  */
32 32
 function getpaid_get_gst_states() {
33
-    return array( 'AU', 'NZ', 'CA', 'CN' );
33
+    return array('AU', 'NZ', 'CA', 'CN');
34 34
 }
35 35
 
36 36
 /**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
  *
39 39
  * @return bool
40 40
  */
41
-function getpaid_is_gst_country( $country ) {
42
-    return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states() ) ? true : false;
41
+function getpaid_is_gst_country($country) {
42
+    return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states()) ? true : false;
43 43
 }
44 44
 
45 45
 /**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function wpinv_use_taxes() {
51 51
 
52
-    $ret = wpinv_get_option( 'enable_taxes', false );
53
-    return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) );
52
+    $ret = wpinv_get_option('enable_taxes', false);
53
+    return (bool) apply_filters('wpinv_use_taxes', !empty($ret));
54 54
 
55 55
 }
56 56
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @param WPInv_Invoice $invoice
61 61
  * @return bool
62 62
  */
63
-function wpinv_is_invoice_taxable( $invoice ) {
63
+function wpinv_is_invoice_taxable($invoice) {
64 64
     return $invoice->is_taxable();
65 65
 }
66 66
 
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
  * @param string $country
71 71
  * @return bool
72 72
  */
73
-function wpinv_is_country_taxable( $country ) {
74
-    $is_eu     = getpaid_is_eu_state( $country );
75
-    $is_exempt = ! $is_eu && wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat();
73
+function wpinv_is_country_taxable($country) {
74
+    $is_eu     = getpaid_is_eu_state($country);
75
+    $is_exempt = !$is_eu && wpinv_is_base_country($country) && wpinv_same_country_exempt_vat();
76 76
 
77
-    return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country );
77
+    return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country);
78 78
 
79 79
 }
80 80
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
  * @param WPInv_Item|GetPaid_Form_Item $item
85 85
  * @return bool
86 86
  */
87
-function wpinv_is_item_taxable( $item ) {
87
+function wpinv_is_item_taxable($item) {
88 88
     return '_exempt' != $item->get_vat_rule();
89 89
 }
90 90
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
  * @return bool
95 95
  */
96 96
 function wpinv_use_store_address_as_tax_base() {
97
-    $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base';
98
-    return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base );
97
+    $use_base = wpinv_get_option('tax_base', 'billing') == 'base';
98
+    return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base);
99 99
 }
100 100
 
101 101
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  * @return bool
105 105
  */
106 106
 function wpinv_prices_include_tax() {
107
-    $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes';
108
-    return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive );
107
+    $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes';
108
+    return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive);
109 109
 }
110 110
 
111 111
 /**
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
  * @return bool
115 115
  */
116 116
 function wpinv_round_tax_per_tax_rate() {
117
-    $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 );
118
-    return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) );
117
+    $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1);
118
+    return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding));
119 119
 }
120 120
 
121 121
 /**
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
  * @return bool
125 125
  */
126 126
 function wpinv_display_individual_tax_rates() {
127
-    $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual';
128
-    return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual );
127
+    $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual';
128
+    return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual);
129 129
 }
130 130
 
131 131
 /**
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
  * @return float
135 135
  */
136 136
 function wpinv_get_default_tax_rate() {
137
-    $rate = wpinv_get_option( 'tax_rate', 0 );
138
-    return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) );
137
+    $rate = wpinv_get_option('tax_rate', 0);
138
+    return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate));
139 139
 }
140 140
 
141 141
 /**
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
  * @return bool
145 145
  */
146 146
 function wpinv_same_country_exempt_vat() {
147
-    return 'no' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' );
147
+    return 'no' == wpinv_get_option('vat_same_country_rule', 'vat_too');
148 148
 }
149 149
 
150 150
 /**
@@ -164,28 +164,28 @@  discard block
 block discarded – undo
164 164
  * @param string $state
165 165
  * @return array
166 166
  */
167
-function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) {
167
+function getpaid_get_item_tax_rates($item, $country = '', $state = '') {
168 168
 
169 169
     // Abort if the item is not taxable.
170
-    if ( ! wpinv_is_item_taxable( $item ) ) {
170
+    if (!wpinv_is_item_taxable($item)) {
171 171
         return array();
172 172
     }
173 173
 
174 174
     // Maybe use the store address.
175
-    if ( wpinv_use_store_address_as_tax_base() ) {
175
+    if (wpinv_use_store_address_as_tax_base()) {
176 176
         $country = wpinv_get_default_country();
177 177
         $state   = wpinv_get_default_state();
178 178
     }
179 179
 
180 180
     // Retrieve tax rates.
181
-    $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state );
181
+    $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state);
182 182
 
183 183
     // Fallback to the default tax rates if non were found.
184
-    if ( empty( $tax_rates ) ) {
184
+    if (empty($tax_rates)) {
185 185
         $tax_rates = GetPaid_Tax::get_default_tax_rates();
186 186
     }
187 187
 
188
-    return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state );
188
+    return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state);
189 189
 }
190 190
 
191 191
 /**
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
  * @param array $rates
196 196
  * @return array
197 197
  */
198
-function getpaid_filter_item_tax_rates( $item, $rates ) {
198
+function getpaid_filter_item_tax_rates($item, $rates) {
199 199
 
200 200
     $tax_class = $item->get_vat_class();
201 201
 
202
-    foreach ( $rates as $i => $rate ) {
202
+    foreach ($rates as $i => $rate) {
203 203
 
204
-        if ( $tax_class == '_reduced' ) {
205
-            $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate'];
204
+        if ($tax_class == '_reduced') {
205
+            $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate'];
206 206
         }
207 207
 
208
-        if ( $tax_class == '_exempt' ) {
209
-            $rates[ $i ]['rate'] = 0;
208
+        if ($tax_class == '_exempt') {
209
+            $rates[$i]['rate'] = 0;
210 210
         }
211 211
 }
212 212
 
213
-    return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item );
213
+    return apply_filters('getpaid_filter_item_tax_rates', $rates, $item);
214 214
 }
215 215
 
216 216
 /**
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
  * @param array $rates
221 221
  * @return array
222 222
  */
223
-function getpaid_calculate_item_taxes( $amount, $rates ) {
223
+function getpaid_calculate_item_taxes($amount, $rates) {
224 224
 
225 225
     $is_inclusive = wpinv_prices_include_tax();
226
-    $taxes        = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive );
226
+    $taxes        = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive);
227 227
 
228
-    return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates );
228
+    return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates);
229 229
 }
230 230
 
231 231
 /**
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
  * @param float $recurring_tax_amount
238 238
  * @return array
239 239
  */
240
-function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) {
240
+function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) {
241 241
 
242
-    $initial_tax   = $tax_amount;
242
+    $initial_tax = $tax_amount;
243 243
 	$recurring_tax = 0;
244 244
 
245
-    if ( $item->is_recurring() ) {
245
+    if ($item->is_recurring()) {
246 246
 		$recurring_tax = $recurring_tax_amount;
247 247
 	}
248 248
 
249 249
 	return array(
250
-		'name'          => sanitize_text_field( $tax_name ),
250
+		'name'          => sanitize_text_field($tax_name),
251 251
 		'initial_tax'   => $initial_tax,
252 252
 		'recurring_tax' => $recurring_tax,
253 253
     );
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
  * @param string $vat_number
261 261
  * @return string
262 262
  */
263
-function wpinv_sanitize_vat_number( $vat_number ) {
264
-    return str_replace( array( ' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
263
+function wpinv_sanitize_vat_number($vat_number) {
264
+    return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
265 265
 }
266 266
 
267 267
 /**
@@ -270,22 +270,22 @@  discard block
 block discarded – undo
270 270
  * @param string $vat_number
271 271
  * @return bool
272 272
  */
273
-function wpinv_regex_validate_vat_number( $vat_number ) {
273
+function wpinv_regex_validate_vat_number($vat_number) {
274 274
 
275
-    $country    = substr( $vat_number, 0, 2 );
276
-    $vatin      = substr( $vat_number, 2 );
277
-    $regexes    = wpinv_get_data( 'vat-number-regexes' );
275
+    $country    = substr($vat_number, 0, 2);
276
+    $vatin      = substr($vat_number, 2);
277
+    $regexes    = wpinv_get_data('vat-number-regexes');
278 278
 
279
-    if ( isset( $regexes[ $country ] ) ) {
279
+    if (isset($regexes[$country])) {
280 280
 
281
-        $regex = $regexes[ $country ];
281
+        $regex = $regexes[$country];
282 282
         $regex = '/^(?:' . $regex . ')$/';
283
-        return 1 === preg_match( $regex, $vatin );
283
+        return 1 === preg_match($regex, $vatin);
284 284
 
285 285
     }
286 286
 
287 287
     // Not an EU state, use filters to validate the number.
288
-    return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number );
288
+    return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number);
289 289
 }
290 290
 
291 291
 /**
@@ -294,29 +294,29 @@  discard block
 block discarded – undo
294 294
  * @param string $vat_number
295 295
  * @return bool
296 296
  */
297
-function wpinv_vies_validate_vat_number( $vat_number ) {
297
+function wpinv_vies_validate_vat_number($vat_number) {
298 298
 
299
-    $country    = substr( $vat_number, 0, 2 );
300
-    $vatin      = substr( $vat_number, 2 );
299
+    $country    = substr($vat_number, 0, 2);
300
+    $vatin      = substr($vat_number, 2);
301 301
 
302 302
     $url        = add_query_arg(
303 303
         array(
304
-            'ms'  => urlencode( $country ),
305
-            'iso' => urlencode( $country ),
306
-            'vat' => urlencode( $vatin ),
304
+            'ms'  => urlencode($country),
305
+            'iso' => urlencode($country),
306
+            'vat' => urlencode($vatin),
307 307
         ),
308 308
         'http://ec.europa.eu/taxation_customs/vies/viesquer.do'
309 309
     );
310 310
 
311
-    $response   = wp_remote_get( $url );
312
-    $response   = wp_remote_retrieve_body( $response );
311
+    $response   = wp_remote_get($url);
312
+    $response   = wp_remote_retrieve_body($response);
313 313
 
314 314
     // Fallback gracefully if the VIES website is down.
315
-    if ( empty( $response ) ) {
315
+    if (empty($response)) {
316 316
         return true;
317 317
     }
318 318
 
319
-    return 1 !== preg_match( '/invalid VAT number/i', $response );
319
+    return 1 !== preg_match('/invalid VAT number/i', $response);
320 320
 
321 321
 }
322 322
 
@@ -327,18 +327,18 @@  discard block
 block discarded – undo
327 327
  * @param string $country
328 328
  * @return bool
329 329
  */
330
-function wpinv_validate_vat_number( $vat_number, $country ) {
330
+function wpinv_validate_vat_number($vat_number, $country) {
331 331
 
332 332
     // In case the vat number does not have a country code...
333
-    $vat_number = wpinv_sanitize_vat_number( $vat_number );
334
-    $_country   = substr( $vat_number, 0, 2 );
335
-    $_country   = $_country == wpinv_country_name( $_country );
333
+    $vat_number = wpinv_sanitize_vat_number($vat_number);
334
+    $_country   = substr($vat_number, 0, 2);
335
+    $_country   = $_country == wpinv_country_name($_country);
336 336
 
337
-    if ( $_country ) {
338
-        $vat_number = strtoupper( $country ) . $vat_number;
337
+    if ($_country) {
338
+        $vat_number = strtoupper($country) . $vat_number;
339 339
     }
340 340
 
341
-    return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number );
341
+    return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number);
342 342
 }
343 343
 
344 344
 /**
@@ -347,39 +347,39 @@  discard block
 block discarded – undo
347 347
  * @return bool
348 348
  */
349 349
 function wpinv_should_validate_vat_number() {
350
-    $validate = wpinv_get_option( 'validate_vat_number' );
351
-	return ! empty( $validate );
350
+    $validate = wpinv_get_option('validate_vat_number');
351
+	return !empty($validate);
352 352
 }
353 353
 
354
-function wpinv_sales_tax_for_year( $year = null ) {
355
-    return wpinv_price( wpinv_get_sales_tax_for_year( $year ) );
354
+function wpinv_sales_tax_for_year($year = null) {
355
+    return wpinv_price(wpinv_get_sales_tax_for_year($year));
356 356
 }
357 357
 
358
-function wpinv_get_sales_tax_for_year( $year = null ) {
358
+function wpinv_get_sales_tax_for_year($year = null) {
359 359
     global $wpdb;
360 360
 
361 361
     // Start at zero
362 362
     $tax = 0;
363 363
 
364
-    if ( ! empty( $year ) ) {
364
+    if (!empty($year)) {
365 365
         $args = array(
366 366
             'post_type'      => 'wpi_invoice',
367
-            'post_status'    => array( 'publish' ),
367
+            'post_status'    => array('publish'),
368 368
             'posts_per_page' => -1,
369 369
             'year'           => $year,
370 370
             'fields'         => 'ids',
371 371
         );
372 372
 
373
-        $payments    = get_posts( $args );
374
-        $payment_ids = implode( ',', $payments );
373
+        $payments    = get_posts($args);
374
+        $payment_ids = implode(',', $payments);
375 375
 
376
-        if ( count( $payments ) > 0 ) {
376
+        if (count($payments) > 0) {
377 377
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
378
-            $tax = $wpdb->get_var( $sql );
378
+            $tax = $wpdb->get_var($sql);
379 379
         }
380 380
 }
381 381
 
382
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
382
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
383 383
 }
384 384
 
385 385
 function wpinv_is_cart_taxed() {
@@ -388,34 +388,34 @@  discard block
 block discarded – undo
388 388
 
389 389
 function wpinv_prices_show_tax_on_checkout() {
390 390
     return false; // TODO
391
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
391
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
392 392
 
393
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
393
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
394 394
 }
395 395
 
396 396
 function wpinv_display_tax_rate() {
397
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
397
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
398 398
 
399
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
399
+    return apply_filters('wpinv_display_tax_rate', $ret);
400 400
 }
401 401
 
402 402
 function wpinv_cart_needs_tax_address_fields() {
403
-    if ( ! wpinv_is_cart_taxed() ) {
403
+    if (!wpinv_is_cart_taxed()) {
404 404
         return false;
405 405
     }
406 406
 
407
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
407
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
408 408
 }
409 409
 
410
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
411
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
412
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
410
+function wpinv_item_is_tax_exclusive($item_id = 0) {
411
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
412
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
413 413
 }
414 414
 
415
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
415
+function wpinv_currency_decimal_filter($decimals = 2) {
416 416
     $currency = wpinv_get_currency();
417 417
 
418
-    switch ( $currency ) {
418
+    switch ($currency) {
419 419
         case 'RIAL':
420 420
         case 'JPY':
421 421
         case 'TWD':
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
             break;
425 425
     }
426 426
 
427
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
427
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
428 428
 }
429 429
 
430 430
 function wpinv_tax_amount() {
431 431
     $output = 0.00;
432 432
 
433
-    return apply_filters( 'wpinv_tax_amount', $output );
433
+    return apply_filters('wpinv_tax_amount', $output);
434 434
 }
435 435
 
436 436
 /**
@@ -438,25 +438,25 @@  discard block
 block discarded – undo
438 438
  *
439 439
  * @param string|bool|null $vat_rule
440 440
  */
441
-function getpaid_filter_vat_rule( $vat_rule ) {
441
+function getpaid_filter_vat_rule($vat_rule) {
442 442
 
443
-    if ( empty( $vat_rule ) ) {
443
+    if (empty($vat_rule)) {
444 444
         return 'digital';
445 445
     }
446 446
 
447 447
     return $vat_rule;
448 448
 }
449
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
449
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
450 450
 
451 451
 /**
452 452
  * Filters the VAT class to ensure that each item has a VAT class.
453 453
  *
454 454
  * @param string|bool|null $vat_rule
455 455
  */
456
-function getpaid_filter_vat_class( $vat_class ) {
457
-    return empty( $vat_class ) ? '_standard' : $vat_class;
456
+function getpaid_filter_vat_class($vat_class) {
457
+    return empty($vat_class) ? '_standard' : $vat_class;
458 458
 }
459
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
459
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
460 460
 
461 461
 /**
462 462
  * Returns a list of all tax classes.
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
     return apply_filters(
469 469
         'getpaid_tax_classes',
470 470
         array(
471
-            '_standard' => __( 'Standard Tax Rate', 'invoicing' ),
472
-            '_reduced'  => __( 'Reduced Tax Rate', 'invoicing' ),
473
-            '_exempt'   => __( 'Tax Exempt', 'invoicing' ),
471
+            '_standard' => __('Standard Tax Rate', 'invoicing'),
472
+            '_reduced'  => __('Reduced Tax Rate', 'invoicing'),
473
+            '_exempt'   => __('Tax Exempt', 'invoicing'),
474 474
         )
475 475
     );
476 476
 
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
     return apply_filters(
487 487
         'getpaid_tax_rules',
488 488
         array(
489
-            'physical' => __( 'Physical Item', 'invoicing' ),
490
-            'digital'  => __( 'Digital Item', 'invoicing' ),
489
+            'physical' => __('Physical Item', 'invoicing'),
490
+            'digital'  => __('Digital Item', 'invoicing'),
491 491
         )
492 492
     );
493 493
 
@@ -499,15 +499,15 @@  discard block
 block discarded – undo
499 499
  * @param string $tax_class
500 500
  * @return string
501 501
  */
502
-function getpaid_get_tax_class_label( $tax_class ) {
502
+function getpaid_get_tax_class_label($tax_class) {
503 503
 
504 504
     $classes = getpaid_get_tax_classes();
505 505
 
506
-    if ( isset( $classes[ $tax_class ] ) ) {
507
-        return sanitize_text_field( $classes[ $tax_class ] );
506
+    if (isset($classes[$tax_class])) {
507
+        return sanitize_text_field($classes[$tax_class]);
508 508
     }
509 509
 
510
-    return sanitize_text_field( $tax_class );
510
+    return sanitize_text_field($tax_class);
511 511
 
512 512
 }
513 513
 
@@ -517,15 +517,15 @@  discard block
 block discarded – undo
517 517
  * @param string $tax_rule
518 518
  * @return string
519 519
  */
520
-function getpaid_get_tax_rule_label( $tax_rule ) {
520
+function getpaid_get_tax_rule_label($tax_rule) {
521 521
 
522 522
     $rules = getpaid_get_tax_rules();
523 523
 
524
-    if ( isset( $rules[ $tax_rule ] ) ) {
525
-        return sanitize_text_field( $rules[ $tax_rule ] );
524
+    if (isset($rules[$tax_rule])) {
525
+        return sanitize_text_field($rules[$tax_rule]);
526 526
     }
527 527
 
528
-    return sanitize_text_field( $tax_rule );
528
+    return sanitize_text_field($tax_rule);
529 529
 
530 530
 }
531 531
 
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
  * @param string $recurring
537 537
  * @return string
538 538
  */
539
-function getpaid_get_taxable_amount( $item, $recurring = false ) {
539
+function getpaid_get_taxable_amount($item, $recurring = false) {
540 540
 
541 541
     $taxable_amount  = $recurring ? $item->get_recurring_sub_total() : $item->get_sub_total();
542 542
     $taxable_amount -= $recurring ? $item->recurring_item_discount : $item->item_discount;
543
-    $taxable_amount  = max( 0, $taxable_amount );
544
-    return apply_filters( 'getpaid_taxable_amount', $taxable_amount, $item, $recurring );
543
+    $taxable_amount  = max(0, $taxable_amount);
544
+    return apply_filters('getpaid_taxable_amount', $taxable_amount, $item, $recurring);
545 545
 
546 546
 }
Please login to merge, or discard this patch.