Passed
Push — master ( 43660e...962628 )
by Brian
10:35
created
includes/admin/class-getpaid-admin.php 1 patch
Spacing   +129 added lines, -129 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
  * The main admin class.
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * Class constructor.
39 39
 	 */
40
-	public function __construct(){
40
+	public function __construct() {
41 41
 
42
-        $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
42
+        $this->admin_path = plugin_dir_path(__FILE__);
43
+		$this->admin_url   = plugins_url('/', __FILE__);
44 44
 		$this->reports     = new GetPaid_Reports();
45 45
 
46
-        if ( is_admin() ) {
46
+        if (is_admin()) {
47 47
 			$this->init_admin_hooks();
48 48
         }
49 49
 
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	private function init_admin_hooks() {
57
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
61
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
65
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
66
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
58
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
59
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
60
+        add_action('admin_init', array($this, 'activation_redirect'));
61
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
62
+		add_action('admin_notices', array($this, 'show_notices'));
63
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
64
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
65
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
66
+		do_action('getpaid_init_admin_hooks', $this);
67 67
 
68 68
     }
69 69
 
@@ -74,39 +74,39 @@  discard block
 block discarded – undo
74 74
 	public function enqeue_scripts() {
75 75
         global $current_screen, $pagenow;
76 76
 
77
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
77
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
78 78
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
79 79
 
80
-        if ( ! empty( $current_screen->post_type ) ) {
80
+        if (!empty($current_screen->post_type)) {
81 81
 			$page = $current_screen->post_type;
82 82
         }
83 83
 
84 84
         // General styles.
85
-        if ( false !== stripos( $page, 'wpi' ) ) {
85
+        if (false !== stripos($page, 'wpi')) {
86 86
 
87 87
             // Styles.
88
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
89
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
90
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
91
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
88
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
89
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
90
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
91
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
92 92
 
93 93
             // Scripts.
94
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
95
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
94
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
95
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
96 96
 
97
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
98
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
99
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
97
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
98
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
99
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
100 100
 
101 101
         }
102 102
 
103 103
         // Payment form scripts.
104
-		if ( 'wpi_payment_form' == $page && $editing ) {
104
+		if ('wpi_payment_form' == $page && $editing) {
105 105
             $this->load_payment_form_scripts();
106 106
         }
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
108
+		if ($page == 'wpinv-subscriptions') {
109
+			wp_enqueue_script('postbox');
110 110
 		}
111 111
 
112 112
     }
@@ -119,16 +119,16 @@  discard block
 block discarded – undo
119 119
         global $post;
120 120
 
121 121
         $i18n = array(
122
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
123
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
124
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
125
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
126
-			'rest_root'                 => esc_url_raw( rest_url() ),
127
-			'date_range'                => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
128
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
129
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
130
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
131
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
122
+            'ajax_url'                  => admin_url('admin-ajax.php'),
123
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
124
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
125
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
126
+			'rest_root'                 => esc_url_raw(rest_url()),
127
+			'date_range'                => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days',
128
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
129
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
130
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
131
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
132 132
             'tax'                       => wpinv_tax_amount(),
133 133
             'discount'                  => 0,
134 134
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -137,35 +137,35 @@  discard block
 block discarded – undo
137 137
             'thousand_sep'              => wpinv_thousands_separator(),
138 138
             'decimal_sep'               => wpinv_decimal_separator(),
139 139
             'decimals'                  => wpinv_decimals(),
140
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
141
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
142
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
143
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
144
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
145
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
146
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
147
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
148
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
149
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
150
-            'action_edit'               => __( 'Edit', 'invoicing' ),
151
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
152
-            'item_description'          => __( 'Item Description', 'invoicing' ),
153
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
154
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
155
-            'searching'                 => __( 'Searching', 'invoicing' ),
140
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
141
+            'status_publish'            => wpinv_status_nicename('publish'),
142
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
143
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
144
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
145
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
146
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
147
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
148
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
149
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
150
+            'action_edit'               => __('Edit', 'invoicing'),
151
+            'action_cancel'             => __('Cancel', 'invoicing'),
152
+            'item_description'          => __('Item Description', 'invoicing'),
153
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
154
+            'discount_description'      => __('Discount Description', 'invoicing'),
155
+            'searching'                 => __('Searching', 'invoicing'),
156 156
         );
157 157
 
158
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
158
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
159 159
 
160
-			$invoice              = new WPInv_Invoice( $post );
160
+			$invoice              = new WPInv_Invoice($post);
161 161
 			$i18n['save_invoice'] = sprintf(
162
-				__( 'Save %s', 'invoicing' ),
163
-				ucfirst( $invoice->get_type() )
162
+				__('Save %s', 'invoicing'),
163
+				ucfirst($invoice->get_type())
164 164
 			);
165 165
 
166 166
 			$i18n['invoice_description'] = sprintf(
167
-				__( '%s Description', 'invoicing' ),
168
-				ucfirst( $invoice->get_type() )
167
+				__('%s Description', 'invoicing'),
168
+				ucfirst($invoice->get_type())
169 169
 			);
170 170
 
171 171
 		}
@@ -179,30 +179,30 @@  discard block
 block discarded – undo
179 179
 	protected function load_payment_form_scripts() {
180 180
         global $post;
181 181
 
182
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
183
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
184
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
182
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
183
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
184
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
185 185
 
186
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
187
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
186
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
187
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
188 188
 
189 189
 		wp_localize_script(
190 190
             'wpinv-admin-payment-form-script',
191 191
             'wpinvPaymentFormAdmin',
192 192
             array(
193
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
194
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
193
+				'elements'      => wpinv_get_data('payment-form-elements'),
194
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
195 195
 				'currency'      => wpinv_currency_symbol(),
196 196
 				'position'      => wpinv_currency_position(),
197 197
 				'decimals'      => (int) wpinv_decimals(),
198 198
 				'thousands_sep' => wpinv_thousands_separator(),
199 199
 				'decimals_sep'  => wpinv_decimal_separator(),
200
-				'form_items'    => gepaid_get_form_items( $post->ID ),
200
+				'form_items'    => gepaid_get_form_items($post->ID),
201 201
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
202 202
             )
203 203
         );
204 204
 
205
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
205
+        wp_enqueue_script('wpinv-admin-payment-form-script');
206 206
 
207 207
     }
208 208
 
@@ -213,25 +213,25 @@  discard block
 block discarded – undo
213 213
      * @return string
214 214
 	 *
215 215
 	 */
216
-    public function admin_body_class( $classes ) {
216
+    public function admin_body_class($classes) {
217 217
 		global $pagenow, $post, $current_screen;
218 218
 
219 219
 
220
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
220
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
221 221
 
222
-        if ( ! empty( $current_screen->post_type ) ) {
222
+        if (!empty($current_screen->post_type)) {
223 223
 			$page = $current_screen->post_type;
224 224
         }
225 225
 
226
-        if ( false !== stripos( $page, 'wpi' ) ) {
227
-            $classes .= ' wpi-' . sanitize_key( $page );
226
+        if (false !== stripos($page, 'wpi')) {
227
+            $classes .= ' wpi-' . sanitize_key($page);
228 228
         }
229 229
 
230
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
230
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
231 231
             $classes .= ' wpinv-cpt wpinv';
232 232
 		}
233 233
 		
234
-		if ( getpaid_is_invoice_post_type( $page ) ) {
234
+		if (getpaid_is_invoice_post_type($page)) {
235 235
             $classes .= ' getpaid-is-invoice-cpt';
236 236
         }
237 237
 
@@ -241,19 +241,19 @@  discard block
 block discarded – undo
241 241
     /**
242 242
 	 * Maybe show the AyeCode Connect Notice.
243 243
 	 */
244
-	public function init_ayecode_connect_helper(){
244
+	public function init_ayecode_connect_helper() {
245 245
 
246 246
         new AyeCode_Connect_Helper(
247 247
             array(
248
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
249
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
250
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
251
-				'connect_button'    => __("Connect Site","invoicing"),
252
-				'connecting_button'    => __("Connecting...","invoicing"),
253
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
254
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
248
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
249
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
250
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
251
+				'connect_button'    => __("Connect Site", "invoicing"),
252
+				'connecting_button'    => __("Connecting...", "invoicing"),
253
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
254
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
255 255
             ),
256
-            array( 'wpi-addons' )
256
+            array('wpi-addons')
257 257
         );
258 258
 
259 259
     }
@@ -264,19 +264,19 @@  discard block
 block discarded – undo
264 264
     public function activation_redirect() {
265 265
 
266 266
 		// Bail if no activation redirect.
267
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
267
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
268 268
 			return;
269 269
 		}
270 270
 
271 271
 		// Delete the redirect transient.
272
-		delete_transient( '_wpinv_activation_redirect' );
272
+		delete_transient('_wpinv_activation_redirect');
273 273
 
274 274
 		// Bail if activating from network, or bulk
275
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
275
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
276 276
 			return;
277 277
 		}
278 278
 
279
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
279
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
280 280
 		exit;
281 281
     }
282 282
 
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
      */
286 286
     public function maybe_do_admin_action() {
287 287
 
288
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
289
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
290
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
288
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
289
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
290
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
291 291
         }
292 292
 
293 293
     }
@@ -297,16 +297,16 @@  discard block
 block discarded – undo
297 297
 	 * 
298 298
 	 * @param array $args
299 299
      */
300
-    public function send_customer_invoice( $args ) {
301
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
300
+    public function send_customer_invoice($args) {
301
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
302 302
 
303
-		if ( $sent ) {
304
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
303
+		if ($sent) {
304
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
305 305
 		} else {
306
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
306
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
307 307
 		}
308 308
 
309
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
309
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
310 310
 		exit;
311 311
 	}
312 312
 
@@ -315,16 +315,16 @@  discard block
 block discarded – undo
315 315
 	 * 
316 316
 	 * @param array $args
317 317
      */
318
-    public function send_customer_payment_reminder( $args ) {
319
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
318
+    public function send_customer_payment_reminder($args) {
319
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
320 320
 
321
-		if ( $sent ) {
322
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
321
+		if ($sent) {
322
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
323 323
 		} else {
324
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
324
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
325 325
 		}
326 326
 
327
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
327
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
328 328
 		exit;
329 329
 	}
330 330
 
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
      */
335 335
     public function admin_reset_tax_rates() {
336 336
 
337
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
338
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
337
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
338
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
339 339
 		exit;
340 340
 
341 341
 	}
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
      * @return array
348 348
 	 */
349 349
 	public function get_notices() {
350
-		$notices = get_option( 'wpinv_admin_notices' );
351
-        return is_array( $notices ) ? $notices : array();
350
+		$notices = get_option('wpinv_admin_notices');
351
+        return is_array($notices) ? $notices : array();
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 * @since       1.0.19
359 359
 	 */
360 360
 	public function clear_notices() {
361
-		delete_option( 'wpinv_admin_notices' );
361
+		delete_option('wpinv_admin_notices');
362 362
 	}
363 363
 
364 364
 	/**
@@ -367,16 +367,16 @@  discard block
 block discarded – undo
367 367
 	 * @access      public
368 368
 	 * @since       1.0.19
369 369
 	 */
370
-	public function save_notice( $type, $message ) {
370
+	public function save_notice($type, $message) {
371 371
 		$notices = $this->get_notices();
372 372
 
373
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
374
-			$notices[ $type ] = array();
373
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
374
+			$notices[$type] = array();
375 375
 		}
376 376
 
377
-		$notices[ $type ][] = $message;
377
+		$notices[$type][] = $message;
378 378
 
379
-		update_option( 'wpinv_admin_notices', $notices );
379
+		update_option('wpinv_admin_notices', $notices);
380 380
 	}
381 381
 
382 382
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @access      public
387 387
 	 * @since       1.0.19
388 388
 	 */
389
-	public function show_success( $msg ) {
390
-		$this->save_notice( 'success', $msg );
389
+	public function show_success($msg) {
390
+		$this->save_notice('success', $msg);
391 391
 	}
392 392
 
393 393
 	/**
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
 	 * @param       string $msg The message to qeue.
398 398
 	 * @since       1.0.19
399 399
 	 */
400
-	public function show_error( $msg ) {
401
-		$this->save_notice( 'error', $msg );
400
+	public function show_error($msg) {
401
+		$this->save_notice('error', $msg);
402 402
 	}
403 403
 
404 404
 	/**
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param       string $msg The message to qeue.
409 409
 	 * @since       1.0.19
410 410
 	 */
411
-	public function show_warning( $msg ) {
412
-		$this->save_notice( 'warning', $msg );
411
+	public function show_warning($msg) {
412
+		$this->save_notice('warning', $msg);
413 413
 	}
414 414
 
415 415
 	/**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 	 * @param       string $msg The message to qeue.
420 420
 	 * @since       1.0.19
421 421
 	 */
422
-	public function show_info( $msg ) {
423
-		$this->save_notice( 'info', $msg );
422
+	public function show_info($msg) {
423
+		$this->save_notice('info', $msg);
424 424
 	}
425 425
 
426 426
 	/**
@@ -434,15 +434,15 @@  discard block
 block discarded – undo
434 434
         $notices = $this->get_notices();
435 435
         $this->clear_notices();
436 436
 
437
-		foreach ( $notices as $type => $messages ) {
437
+		foreach ($notices as $type => $messages) {
438 438
 
439
-			if ( ! is_array( $messages ) ) {
439
+			if (!is_array($messages)) {
440 440
 				continue;
441 441
 			}
442 442
 
443
-            $type  = sanitize_key( $type );
444
-			foreach ( $messages as $message ) {
445
-                $message = wp_kses_post( $message );
443
+            $type = sanitize_key($type);
444
+			foreach ($messages as $message) {
445
+                $message = wp_kses_post($message);
446 446
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
447 447
             }
448 448
 
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-report-sales-controller.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since   2.0.0
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * GetPaid REST reports controller class.
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @see register_rest_route()
48 48
 	 */
49
-	public function register_namespace_routes( $namespace ) {
49
+	public function register_namespace_routes($namespace) {
50 50
 
51 51
 		// Get sales report.
52 52
 		register_rest_route(
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 			array(
56 56
 				array(
57 57
 					'methods'             => WP_REST_Server::READABLE,
58
-					'callback'            => array( $this, 'get_items' ),
59
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
58
+					'callback'            => array($this, 'get_items'),
59
+					'permission_callback' => array($this, 'get_items_permissions_check'),
60 60
 					'args'                => $this->get_collection_params(),
61 61
 				),
62
-				'schema' => array( $this, 'get_public_item_schema' ),
62
+				'schema' => array($this, 'get_public_item_schema'),
63 63
 			)
64 64
 		);
65 65
 
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	 * @param WP_REST_Request $request Full data about the request.
73 73
 	 * @return WP_Error|boolean
74 74
 	 */
75
-	public function get_items_permissions_check( $request ) {
75
+	public function get_items_permissions_check($request) {
76 76
 
77
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
78
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
77
+		if (!wpinv_current_user_can_manage_invoicing()) {
78
+			return new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code()));
79 79
 		}
80 80
 
81 81
 		return true;
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	 * @param WP_REST_Request $request
88 88
 	 * @return array|WP_Error
89 89
 	 */
90
-	public function get_items( $request ) {
90
+	public function get_items($request) {
91 91
 		$data   = array();
92
-		$item   = $this->prepare_item_for_response( null, $request );
93
-		$data[] = $this->prepare_response_for_collection( $item );
92
+		$item   = $this->prepare_item_for_response(null, $request);
93
+		$data[] = $this->prepare_response_for_collection($item);
94 94
 
95
-		return rest_ensure_response( $data );
95
+		return rest_ensure_response($data);
96 96
 	}
97 97
 
98 98
 	/**
@@ -102,139 +102,139 @@  discard block
 block discarded – undo
102 102
 	 * @param WP_REST_Request $request Request object.
103 103
 	 * @return WP_REST_Response $response Response data.
104 104
 	 */
105
-	public function prepare_item_for_response( $_, $request ) {
105
+	public function prepare_item_for_response($_, $request) {
106 106
 
107 107
 		// Set report range.
108
-		$this->report_range = $this->get_date_range( $request );
108
+		$this->report_range = $this->get_date_range($request);
109 109
 
110 110
 		$report_data     = $this->get_report_data();
111 111
 		$period_totals   = array();
112 112
 
113 113
 		// Setup period totals by ensuring each period in the interval has data.
114
-		$start_date      = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS;
114
+		$start_date      = strtotime($this->report_range['after']) + DAY_IN_SECONDS;
115 115
 
116
-		if ( 'month' === $this->groupby ) {
117
-			$start_date      = strtotime( date( 'Y-m-01', $start_date ) );
116
+		if ('month' === $this->groupby) {
117
+			$start_date = strtotime(date('Y-m-01', $start_date));
118 118
 		}
119 119
 
120
-		for ( $i = 0; $i < $this->interval; $i++ ) {
120
+		for ($i = 0; $i < $this->interval; $i++) {
121 121
 
122
-			switch ( $this->groupby ) {
122
+			switch ($this->groupby) {
123 123
 				case 'day' :
124
-					$time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) );
124
+					$time = date('Y-m-d', strtotime("+{$i} DAY", $start_date));
125 125
 					break;
126 126
 				default :
127
-					$time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) );
127
+					$time = date('Y-m', strtotime("+{$i} MONTH", $start_date));
128 128
 					break;
129 129
 			}
130 130
 
131 131
 			// Set the defaults for each period.
132
-			$period_totals[ $time ] = array(
133
-				'sales'             => wpinv_round_amount( 0.00 ),
132
+			$period_totals[$time] = array(
133
+				'sales'             => wpinv_round_amount(0.00),
134 134
 				'invoices'          => 0,
135
-				'refunds'           => wpinv_round_amount( 0.00 ),
135
+				'refunds'           => wpinv_round_amount(0.00),
136 136
 				'items'             => 0,
137 137
 				'refunded_items'    => 0,
138
-				'tax'               => wpinv_round_amount( 0.00 ),
139
-				'refunded_tax'      => wpinv_round_amount( 0.00 ),
140
-				'subtotal'          => wpinv_round_amount( 0.00 ),
141
-				'refunded_subtotal' => wpinv_round_amount( 0.00 ),
142
-				'fees'              => wpinv_round_amount( 0.00 ),
143
-				'refunded_fees'     => wpinv_round_amount( 0.00 ),
144
-				'discount'          => wpinv_round_amount( 0.00 ),
138
+				'tax'               => wpinv_round_amount(0.00),
139
+				'refunded_tax'      => wpinv_round_amount(0.00),
140
+				'subtotal'          => wpinv_round_amount(0.00),
141
+				'refunded_subtotal' => wpinv_round_amount(0.00),
142
+				'fees'              => wpinv_round_amount(0.00),
143
+				'refunded_fees'     => wpinv_round_amount(0.00),
144
+				'discount'          => wpinv_round_amount(0.00),
145 145
 			);
146 146
 
147 147
 		}
148 148
 
149 149
 		// add total sales, total invoice count, total tax for each period
150
-		$date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m';
151
-		foreach ( $report_data->invoices as $invoice ) {
152
-			$time = date( $date_format, strtotime( $invoice->post_date ) );
150
+		$date_format = ('day' === $this->groupby) ? 'Y-m-d' : 'Y-m';
151
+		foreach ($report_data->invoices as $invoice) {
152
+			$time = date($date_format, strtotime($invoice->post_date));
153 153
 
154
-			if ( ! isset( $period_totals[ $time ] ) ) {
154
+			if (!isset($period_totals[$time])) {
155 155
 				continue;
156 156
 			}
157 157
 
158
-			$period_totals[ $time ]['sales']    = wpinv_round_amount( $invoice->total_sales );
159
-			$period_totals[ $time ]['tax']      = wpinv_round_amount( $invoice->total_tax );
160
-			$period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal );
161
-			$period_totals[ $time ]['fees']     = wpinv_round_amount( $invoice->total_fees );
158
+			$period_totals[$time]['sales']    = wpinv_round_amount($invoice->total_sales);
159
+			$period_totals[$time]['tax']      = wpinv_round_amount($invoice->total_tax);
160
+			$period_totals[$time]['subtotal'] = wpinv_round_amount($invoice->subtotal);
161
+			$period_totals[$time]['fees']     = wpinv_round_amount($invoice->total_fees);
162 162
 
163 163
 		}
164 164
 
165
-		foreach ( $report_data->refunds as $invoice ) {
166
-			$time = date( $date_format, strtotime( $invoice->post_date ) );
165
+		foreach ($report_data->refunds as $invoice) {
166
+			$time = date($date_format, strtotime($invoice->post_date));
167 167
 
168
-			if ( ! isset( $period_totals[ $time ] ) ) {
168
+			if (!isset($period_totals[$time])) {
169 169
 				continue;
170 170
 			}
171 171
 
172
-			$period_totals[ $time ]['refunds']           = wpinv_round_amount( $invoice->total_sales );
173
-			$period_totals[ $time ]['refunded_tax']      = wpinv_round_amount( $invoice->total_tax );
174
-			$period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal );
175
-			$period_totals[ $time ]['refunded_fees']     = wpinv_round_amount( $invoice->total_fees );
172
+			$period_totals[$time]['refunds']           = wpinv_round_amount($invoice->total_sales);
173
+			$period_totals[$time]['refunded_tax']      = wpinv_round_amount($invoice->total_tax);
174
+			$period_totals[$time]['refunded_subtotal'] = wpinv_round_amount($invoice->subtotal);
175
+			$period_totals[$time]['refunded_fees']     = wpinv_round_amount($invoice->total_fees);
176 176
 
177 177
 		}
178 178
 
179
-		foreach ( $report_data->invoice_counts as $invoice ) {
180
-			$time = date( $date_format, strtotime( $invoice->post_date ) );
179
+		foreach ($report_data->invoice_counts as $invoice) {
180
+			$time = date($date_format, strtotime($invoice->post_date));
181 181
 
182
-			if ( isset( $period_totals[ $time ] ) ) {
183
-				$period_totals[ $time ]['invoices']   = (int) $invoice->count;
182
+			if (isset($period_totals[$time])) {
183
+				$period_totals[$time]['invoices'] = (int) $invoice->count;
184 184
 			}
185 185
 
186 186
 		}
187 187
 
188 188
 		// Add total invoice items for each period.
189
-		foreach ( $report_data->invoice_items as $invoice_item ) {
190
-			$time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) );
189
+		foreach ($report_data->invoice_items as $invoice_item) {
190
+			$time = ('day' === $this->groupby) ? date('Y-m-d', strtotime($invoice_item->post_date)) : date('Y-m', strtotime($invoice_item->post_date));
191 191
 
192
-			if ( isset( $period_totals[ $time ] ) ) {
193
-				$period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count;
192
+			if (isset($period_totals[$time])) {
193
+				$period_totals[$time]['items'] = (int) $invoice_item->invoice_item_count;
194 194
 			}
195 195
 
196 196
 		}
197 197
 
198 198
 		// Add total discount for each period.
199
-		foreach ( $report_data->coupons as $discount ) {
200
-			$time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) );
199
+		foreach ($report_data->coupons as $discount) {
200
+			$time = ('day' === $this->groupby) ? date('Y-m-d', strtotime($discount->post_date)) : date('Y-m', strtotime($discount->post_date));
201 201
 
202
-			if ( isset( $period_totals[ $time ] ) ) {
203
-				$period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount );
202
+			if (isset($period_totals[$time])) {
203
+				$period_totals[$time]['discount'] = wpinv_round_amount($discount->discount_amount);
204 204
 			}
205 205
 
206 206
 		}
207 207
 
208 208
 		$report_data->totals            = $period_totals;
209 209
 		$report_data->grouped_by        = $this->groupby;
210
-		$report_data->interval          = max( $this->interval, 1 );
210
+		$report_data->interval          = max($this->interval, 1);
211 211
 		$report_data->currency          = wpinv_get_currency();
212 212
 		$report_data->currency_symbol   = wpinv_currency_symbol();
213 213
 		$report_data->currency_position = wpinv_currency_position();
214 214
 		$report_data->decimal_places    = wpinv_decimals();
215 215
 		$report_data->thousands_sep     = wpinv_thousands_separator();
216 216
 		$report_data->decimals_sep      = wpinv_decimal_separator();
217
-		$report_data->start_date        = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS );
218
-		$report_data->end_date          = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS );
219
-		$report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) );
220
-		$report_data->end_date_locale   = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) );
217
+		$report_data->start_date        = date('Y-m-d', strtotime($this->report_range['after']) + DAY_IN_SECONDS);
218
+		$report_data->end_date          = date('Y-m-d', strtotime($this->report_range['before']) - DAY_IN_SECONDS);
219
+		$report_data->start_date_locale = getpaid_format_date(date('Y-m-d', strtotime($this->report_range['after']) + DAY_IN_SECONDS));
220
+		$report_data->end_date_locale   = getpaid_format_date(date('Y-m-d', strtotime($this->report_range['before']) - DAY_IN_SECONDS));
221 221
 		$report_data->decimals_sep      = wpinv_decimal_separator();
222 222
 
223
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
223
+		$context = !empty($request['context']) ? $request['context'] : 'view';
224 224
 		$data    = $report_data;
225
-		unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items );
226
-		$data    = $this->add_additional_fields_to_object( (array) $data, $request );
227
-		$data    = $this->filter_response_by_context( $data, $context );
225
+		unset($data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items);
226
+		$data    = $this->add_additional_fields_to_object((array) $data, $request);
227
+		$data    = $this->filter_response_by_context($data, $context);
228 228
 
229 229
 		// Wrap the data in a response object.
230
-		$response = rest_ensure_response( $data );
231
-		$response->add_links( array(
230
+		$response = rest_ensure_response($data);
231
+		$response->add_links(array(
232 232
 			'about' => array(
233
-				'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
233
+				'href' => rest_url(sprintf('%s/reports', $this->namespace)),
234 234
 			),
235
-		) );
235
+		));
236 236
 
237
-		return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request );
237
+		return apply_filters('getpaid_rest_prepare_report_sales', $response, $report_data, $request);
238 238
 	}
239 239
 
240 240
 	/**
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * @return stdClass
244 244
 	 */
245 245
 	public function get_report_data() {
246
-		if ( empty( $this->report_data ) ) {
246
+		if (empty($this->report_data)) {
247 247
 			$this->query_report_data();
248 248
 		}
249 249
 		return $this->report_data;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
 		// Prepare reports.
258 258
 		$this->report_data = (object) array(
259
-			'invoice_counts' => $this->query_invoice_counts(),//count, post_date
259
+			'invoice_counts' => $this->query_invoice_counts(), //count, post_date
260 260
 			'coupons'        => $this->query_coupon_counts(), // discount_amount, post_date
261 261
 			'invoice_items'  => $this->query_item_counts(), // invoice_item_count, post_date
262 262
 			'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date
@@ -266,32 +266,32 @@  discard block
 block discarded – undo
266 266
 		);
267 267
 
268 268
 		// Calculated totals.
269
-		$this->report_data->total_tax          = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) );
270
-		$this->report_data->total_sales        = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) );
271
-		$this->report_data->total_discount     = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) );
272
-		$this->report_data->total_fees         = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) );
273
-		$this->report_data->subtotal           = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) );
274
-		$this->report_data->net_sales          = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) );
275
-		$this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) );
276
-		$this->report_data->total_refunds      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) );
277
-		$this->report_data->refunded_discount  = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) );
278
-		$this->report_data->refunded_fees      = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) );
279
-		$this->report_data->subtotal           = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) );
280
-		$this->report_data->net_refunds        = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) );
269
+		$this->report_data->total_tax          = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_tax')));
270
+		$this->report_data->total_sales        = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_sales')));
271
+		$this->report_data->total_discount     = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_discount')));
272
+		$this->report_data->total_fees         = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_fees')));
273
+		$this->report_data->subtotal           = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'subtotal')));
274
+		$this->report_data->net_sales          = wpinv_round_amount($this->report_data->total_sales - max(0, $this->report_data->total_tax));
275
+		$this->report_data->total_refunded_tax = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_tax')));
276
+		$this->report_data->total_refunds      = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_sales')));
277
+		$this->report_data->refunded_discount  = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_discount')));
278
+		$this->report_data->refunded_fees      = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_fees')));
279
+		$this->report_data->subtotal           = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'subtotal')));
280
+		$this->report_data->net_refunds        = wpinv_round_amount($this->report_data->total_refunds + max(0, $this->report_data->total_refunded_tax));
281 281
 
282 282
 
283 283
 		// Calculate average based on net.
284
-		$this->report_data->average_sales       = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 );
285
-		$this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 );
284
+		$this->report_data->average_sales       = wpinv_round_amount($this->report_data->net_sales / max($this->interval, 1), 2);
285
+		$this->report_data->average_total_sales = wpinv_round_amount($this->report_data->total_sales / max($this->interval, 1), 2);
286 286
 
287 287
 		// Total invoices in this period, even if refunded.
288
-		$this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) );
288
+		$this->report_data->total_invoices = absint(array_sum(wp_list_pluck($this->report_data->invoice_counts, 'count')));
289 289
 
290 290
 		// Items invoiced in this period, even if refunded.
291
-		$this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) );
291
+		$this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->invoice_items, 'invoice_item_count')));
292 292
 
293 293
 		// 3rd party filtering of report data
294
-		$this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data );
294
+		$this->report_data = apply_filters('getpaid_rest_api_filter_report_data', $this->report_data);
295 295
 	}
296 296
 
297 297
 	/**
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
 						'name'     => 'post_date',
317 317
 					),
318 318
 				),
319
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
319
+				'group_by'       => $this->get_group_by_sql('posts.post_date'),
320 320
 				'order_by'       => 'post_date ASC',
321 321
 				'query_type'     => 'get_results',
322 322
 				'filter_range'   => $this->report_range,
323
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded' ),
323
+				'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded'),
324 324
 			)
325 325
 		);
326 326
 
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
 						'name'     => 'post_date',
348 348
 					),
349 349
 				),
350
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
350
+				'group_by'       => $this->get_group_by_sql('posts.post_date'),
351 351
 				'order_by'       => 'post_date ASC',
352 352
 				'query_type'     => 'get_results',
353 353
 				'filter_range'   => $this->report_range,
354
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded' ),
354
+				'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded'),
355 355
 			)
356 356
 		);
357 357
 
@@ -378,11 +378,11 @@  discard block
 block discarded – undo
378 378
 						'name'     => 'post_date',
379 379
 					),
380 380
 				),
381
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
381
+				'group_by'       => $this->get_group_by_sql('posts.post_date'),
382 382
 				'order_by'       => 'post_date ASC',
383 383
 				'query_type'     => 'get_results',
384 384
 				'filter_range'   => $this->report_range,
385
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded' ),
385
+				'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded'),
386 386
 			)
387 387
 		);
388 388
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 				),
407 407
 				'query_type'     => 'get_var',
408 408
 				'filter_range'   => $this->report_range,
409
-				'invoice_status' => array( 'wpi-refunded' ),
409
+				'invoice_status' => array('wpi-refunded'),
410 410
 			)
411 411
 		);
412 412
 
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
 						'name'     => 'post_date',
454 454
 					),
455 455
 				),
456
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
456
+				'group_by'       => $this->get_group_by_sql('posts.post_date'),
457 457
 				'order_by'       => 'post_date ASC',
458 458
 				'query_type'     => 'get_results',
459 459
 				'filter_range'   => $this->report_range,
460
-				'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
460
+				'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'),
461 461
 			)
462 462
 		);
463 463
 
@@ -504,11 +504,11 @@  discard block
 block discarded – undo
504 504
 						'name'     => 'post_date',
505 505
 					),
506 506
 				),
507
-				'group_by'       => $this->get_group_by_sql( 'posts.post_date' ),
507
+				'group_by'       => $this->get_group_by_sql('posts.post_date'),
508 508
 				'order_by'       => 'post_date ASC',
509 509
 				'query_type'     => 'get_results',
510 510
 				'filter_range'   => $this->report_range,
511
-				'invoice_status' => array( 'wpi-refunded' ),
511
+				'invoice_status' => array('wpi-refunded'),
512 512
 			)
513 513
 		);
514 514
 
@@ -527,154 +527,154 @@  discard block
 block discarded – undo
527 527
 			'type'       => 'object',
528 528
 			'properties' => array(
529 529
 				'total_sales' => array(
530
-					'description' => __( 'Gross sales in the period.', 'invoicing' ),
530
+					'description' => __('Gross sales in the period.', 'invoicing'),
531 531
 					'type'        => 'string',
532
-					'context'     => array( 'view' ),
532
+					'context'     => array('view'),
533 533
 					'readonly'    => true,
534 534
 				),
535 535
 				'net_sales' => array(
536
-					'description' => __( 'Net sales in the period.', 'invoicing' ),
536
+					'description' => __('Net sales in the period.', 'invoicing'),
537 537
 					'type'        => 'string',
538
-					'context'     => array( 'view' ),
538
+					'context'     => array('view'),
539 539
 					'readonly'    => true,
540 540
 				),
541 541
 				'average_sales' => array(
542
-					'description' => __( 'Average net daily sales.', 'invoicing' ),
542
+					'description' => __('Average net daily sales.', 'invoicing'),
543 543
 					'type'        => 'string',
544
-					'context'     => array( 'view' ),
544
+					'context'     => array('view'),
545 545
 					'readonly'    => true,
546 546
 				),
547 547
 				'average_total_sales' => array(
548
-					'description' => __( 'Average gross daily sales.', 'invoicing' ),
548
+					'description' => __('Average gross daily sales.', 'invoicing'),
549 549
 					'type'        => 'string',
550
-					'context'     => array( 'view' ),
550
+					'context'     => array('view'),
551 551
 					'readonly'    => true,
552 552
 				),
553 553
 				'total_invoices'  => array(
554
-					'description' => __( 'Number of paid invoices.', 'invoicing' ),
554
+					'description' => __('Number of paid invoices.', 'invoicing'),
555 555
 					'type'        => 'integer',
556
-					'context'     => array( 'view' ),
556
+					'context'     => array('view'),
557 557
 					'readonly'    => true,
558 558
 				),
559 559
 				'total_items' => array(
560
-					'description' => __( 'Number of items purchased.', 'invoicing' ),
560
+					'description' => __('Number of items purchased.', 'invoicing'),
561 561
 					'type'        => 'integer',
562
-					'context'     => array( 'view' ),
562
+					'context'     => array('view'),
563 563
 					'readonly'    => true,
564 564
 				),
565 565
 				'refunded_items' => array(
566
-					'description' => __( 'Number of items refunded.', 'invoicing' ),
566
+					'description' => __('Number of items refunded.', 'invoicing'),
567 567
 					'type'        => 'integer',
568
-					'context'     => array( 'view' ),
568
+					'context'     => array('view'),
569 569
 					'readonly'    => true,
570 570
 				),
571 571
 				'total_tax' => array(
572
-					'description' => __( 'Total charged for taxes.', 'invoicing' ),
572
+					'description' => __('Total charged for taxes.', 'invoicing'),
573 573
 					'type'        => 'string',
574
-					'context'     => array( 'view' ),
574
+					'context'     => array('view'),
575 575
 					'readonly'    => true,
576 576
 				),
577 577
 				'total_refunded_tax' => array(
578
-					'description' => __( 'Total refunded for taxes.', 'invoicing' ),
578
+					'description' => __('Total refunded for taxes.', 'invoicing'),
579 579
 					'type'        => 'string',
580
-					'context'     => array( 'view' ),
580
+					'context'     => array('view'),
581 581
 					'readonly'    => true,
582 582
 				),
583 583
 				'total_fees' => array(
584
-					'description' => __( 'Total fees charged.', 'invoicing' ),
584
+					'description' => __('Total fees charged.', 'invoicing'),
585 585
 					'type'        => 'string',
586
-					'context'     => array( 'view' ),
586
+					'context'     => array('view'),
587 587
 					'readonly'    => true,
588 588
 				),
589 589
 				'total_refunds' => array(
590
-					'description' => __( 'Total of refunded invoices.', 'invoicing' ),
590
+					'description' => __('Total of refunded invoices.', 'invoicing'),
591 591
 					'type'        => 'integer',
592
-					'context'     => array( 'view' ),
592
+					'context'     => array('view'),
593 593
 					'readonly'    => true,
594 594
 				),
595 595
 				'net_refunds' => array(
596
-					'description' => __( 'Net of refunded invoices.', 'invoicing' ),
596
+					'description' => __('Net of refunded invoices.', 'invoicing'),
597 597
 					'type'        => 'integer',
598
-					'context'     => array( 'view' ),
598
+					'context'     => array('view'),
599 599
 					'readonly'    => true,
600 600
 				),
601 601
 				'total_discount' => array(
602
-					'description' => __( 'Total of discounts used.', 'invoicing' ),
602
+					'description' => __('Total of discounts used.', 'invoicing'),
603 603
 					'type'        => 'integer',
604
-					'context'     => array( 'view' ),
604
+					'context'     => array('view'),
605 605
 					'readonly'    => true,
606 606
 				),
607 607
 				'totals' => array(
608
-					'description' => __( 'Totals.', 'invoicing' ),
608
+					'description' => __('Totals.', 'invoicing'),
609 609
 					'type'        => 'array',
610 610
 					'items'       => array(
611 611
 						'type'    => 'array',
612 612
 					),
613
-					'context'     => array( 'view' ),
613
+					'context'     => array('view'),
614 614
 					'readonly'    => true,
615 615
 				),
616 616
 				'interval' => array(
617
-					'description' => __( 'Number of months/days in the report period.', 'invoicing' ),
617
+					'description' => __('Number of months/days in the report period.', 'invoicing'),
618 618
 					'type'        => 'integer',
619
-					'context'     => array( 'view' ),
619
+					'context'     => array('view'),
620 620
 					'readonly'    => true,
621 621
 				),
622 622
 				'previous_range'  => array(
623
-					'description' => __( 'The previous report period.', 'invoicing' ),
623
+					'description' => __('The previous report period.', 'invoicing'),
624 624
 					'type'        => 'array',
625 625
 					'items'       => array(
626 626
 						'type'    => 'string',
627 627
 					),
628
-					'context'     => array( 'view' ),
628
+					'context'     => array('view'),
629 629
 					'readonly'    => true,
630 630
 				),
631 631
 				'grouped_by' => array(
632
-					'description' => __( 'The period used to group the totals.', 'invoicing' ),
632
+					'description' => __('The period used to group the totals.', 'invoicing'),
633 633
 					'type'        => 'string',
634
-					'context'     => array( 'view' ),
635
-					'enum'        => array( 'day', 'month' ),
634
+					'context'     => array('view'),
635
+					'enum'        => array('day', 'month'),
636 636
 					'readonly'    => true,
637 637
 				),
638 638
 				'currency' => array(
639
-					'description' => __( 'The default store currency.', 'invoicing' ),
639
+					'description' => __('The default store currency.', 'invoicing'),
640 640
 					'type'        => 'string',
641
-					'context'     => array( 'view' ),
641
+					'context'     => array('view'),
642 642
 					'readonly'    => true,
643 643
 				),
644 644
 				'currency_symbol' => array(
645
-					'description' => __( 'The default store currency symbol.', 'invoicing' ),
645
+					'description' => __('The default store currency symbol.', 'invoicing'),
646 646
 					'type'        => 'string',
647
-					'context'     => array( 'view' ),
647
+					'context'     => array('view'),
648 648
 					'readonly'    => true,
649 649
 				),
650 650
 				'currency_position' => array(
651
-					'description' => __( 'The default store currency position.', 'invoicing' ),
651
+					'description' => __('The default store currency position.', 'invoicing'),
652 652
 					'type'        => 'string',
653
-					'context'     => array( 'view' ),
653
+					'context'     => array('view'),
654 654
 					'readonly'    => true,
655 655
 				),
656 656
 				'decimal_places' => array(
657
-					'description' => __( 'The default store decimal places.', 'invoicing' ),
657
+					'description' => __('The default store decimal places.', 'invoicing'),
658 658
 					'type'        => 'string',
659
-					'context'     => array( 'view' ),
659
+					'context'     => array('view'),
660 660
 					'readonly'    => true,
661 661
 				),
662 662
 				'thousands_sep' => array(
663
-					'description' => __( 'The default store thousands separator.', 'invoicing' ),
663
+					'description' => __('The default store thousands separator.', 'invoicing'),
664 664
 					'type'        => 'string',
665
-					'context'     => array( 'view' ),
665
+					'context'     => array('view'),
666 666
 					'readonly'    => true,
667 667
 				),
668 668
 				'decimals_sep' => array(
669
-					'description' => __( 'The default store decimals separator.', 'invoicing' ),
669
+					'description' => __('The default store decimals separator.', 'invoicing'),
670 670
 					'type'        => 'string',
671
-					'context'     => array( 'view' ),
671
+					'context'     => array('view'),
672 672
 					'readonly'    => true,
673 673
 				),
674 674
 			),
675 675
 		);
676 676
 
677
-		return $this->add_additional_fields_schema( $schema );
677
+		return $this->add_additional_fields_schema($schema);
678 678
 
679 679
 	}
680 680
 
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-date-based-controller.php 1 patch
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since   2.0.0
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * GetPaid REST date based controller class.
@@ -43,15 +43,15 @@  discard block
 block discarded – undo
43 43
 	 * @param WP_REST_Request $request Request object.
44 44
 	 * @return array The appropriate date range.
45 45
 	 */
46
-	public function get_date_range( $request ) {
46
+	public function get_date_range($request) {
47 47
 
48 48
 		// If not supported, assume all time.
49
-		if ( ! in_array( $request['period'], array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'year', 'last_year' ) ) ) {
49
+		if (!in_array($request['period'], array('custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'year', 'last_year'))) {
50 50
 			$request['period'] = '7_days';
51 51
 		}
52 52
 
53
-		$date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request );
54
-		$this->prepare_interval( $date_range );
53
+		$date_range = call_user_func(array($this, 'get_' . $request['period'] . '_date_range'), $request);
54
+		$this->prepare_interval($date_range);
55 55
 
56 56
 		return $date_range;
57 57
 
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
 	 * @param array $range Date range.
64 64
 	 * @return array The appropriate date range.
65 65
 	 */
66
-	public function prepare_interval( $range ) {
66
+	public function prepare_interval($range) {
67 67
 
68
-		$before = strtotime( $range['before'] ) - DAY_IN_SECONDS;
69
-		$after  = strtotime( $range['after'] ) + DAY_IN_SECONDS;
70
-		if ( 'day' === $this->groupby ) {
71
-			$difference     = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0;
72
-			$this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) );
68
+		$before = strtotime($range['before']) - DAY_IN_SECONDS;
69
+		$after  = strtotime($range['after']) + DAY_IN_SECONDS;
70
+		if ('day' === $this->groupby) {
71
+			$difference     = max(DAY_IN_SECONDS, (DAY_IN_SECONDS + $before - $after)); // Prevent division by 0;
72
+			$this->interval = absint(ceil(max(1, $difference / DAY_IN_SECONDS)));
73 73
 			return;
74 74
 		}
75 75
 
76 76
 		$this->interval = 0;
77
-		$min_date       = strtotime( date( 'Y-m-01', $after ) );
77
+		$min_date       = strtotime(date('Y-m-01', $after));
78 78
 
79
-		while ( $min_date <= $before ) {
80
-			$this->interval ++;
81
-			$min_date = strtotime( '+1 MONTH', $min_date );
79
+		while ($min_date <= $before) {
80
+			$this->interval++;
81
+			$min_date = strtotime('+1 MONTH', $min_date);
82 82
 		}
83 83
 
84
-		$this->interval = max( 1, $this->interval );
84
+		$this->interval = max(1, $this->interval);
85 85
 
86 86
 	}
87 87
 
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
 	 * @param WP_REST_Request $request Request object.
92 92
 	 * @return array The appropriate date range.
93 93
 	 */
94
-	public function get_custom_date_range( $request ) {
94
+	public function get_custom_date_range($request) {
95 95
 
96
-		$after  = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) );
97
-		$before = strtotime( '+1 day', current_time( 'timestamp' ) );
96
+		$after  = max(strtotime('-20 years'), strtotime(sanitize_text_field($request['after'])));
97
+		$before = strtotime('+1 day', current_time('timestamp'));
98 98
 
99
-		if ( ! empty( $request['before'] ) ) {
100
-			$before  = min( $before, strtotime( sanitize_text_field( $request['before'] ) ) );
99
+		if (!empty($request['before'])) {
100
+			$before = min($before, strtotime(sanitize_text_field($request['before'])));
101 101
 		}
102 102
 
103 103
 		// 3 months max for day view
104
-		if ( ( $before - $after ) / MONTH_IN_SECONDS > 3 ) {
104
+		if (($before - $after) / MONTH_IN_SECONDS > 3) {
105 105
 			$this->groupby = 'month';
106 106
 		}
107 107
 
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
 		$difference           = $before - $after;
110 110
 		$this->previous_range = array(
111 111
 			'period' => 'custom',
112
-			'before' => date( 'Y-m-d', $before - $difference ),
113
-			'after'  => date( 'Y-m-d', $after - $difference ),
112
+			'before' => date('Y-m-d', $before - $difference),
113
+			'after'  => date('Y-m-d', $after - $difference),
114 114
 		);
115 115
 
116 116
 		// Generate the report.
117 117
 		return array(
118
-			'before' => date( 'Y-m-d', $before ),
119
-			'after' => date( 'Y-m-d', $after ),
118
+			'before' => date('Y-m-d', $before),
119
+			'after' => date('Y-m-d', $after),
120 120
 		);
121 121
 
122 122
 	}
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 
136 136
 		// Generate the report.
137 137
 		return array(
138
-			'before' => date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ),
139
-			'after'  => date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ),
138
+			'before' => date('Y-m-d', strtotime('+1 day', current_time('timestamp'))),
139
+			'after'  => date('Y-m-d', strtotime('-1 day', current_time('timestamp'))),
140 140
 		);
141 141
 
142 142
 	}
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 		// Set the previous date range.
152 152
 		$this->previous_range = array(
153 153
 			'period' => 'custom',
154
-			'before' => date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ),
155
-			'after'  => date( 'Y-m-d', strtotime( '-3 days', current_time( 'timestamp' ) ) ),
154
+			'before' => date('Y-m-d', strtotime('-1 day', current_time('timestamp'))),
155
+			'after'  => date('Y-m-d', strtotime('-3 days', current_time('timestamp'))),
156 156
 		);
157 157
 
158 158
 		// Generate the report.
159 159
 		return array(
160
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
161
-			'after'  => date( 'Y-m-d', strtotime( '-2 days', current_time( 'timestamp' ) ) ),
160
+			'before' => date('Y-m-d', current_time('timestamp')),
161
+			'after'  => date('Y-m-d', strtotime('-2 days', current_time('timestamp'))),
162 162
 		);
163 163
 
164 164
 	}
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 
178 178
 		// Generate the report.
179 179
 		return array(
180
-			'before' => date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ),
181
-			'after'  => date( 'Y-m-d', strtotime( 'sunday last week'  ) ),
180
+			'before' => date('Y-m-d', strtotime('+1 day', current_time('timestamp'))),
181
+			'after'  => date('Y-m-d', strtotime('sunday last week')),
182 182
 		);
183 183
 
184 184
 	}
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
 		// Set the previous date range.
194 194
 		$this->previous_range = array(
195 195
 			'period' => 'custom',
196
-			'before' => date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' )  ) ),
197
-			'after'  => date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' )  ) - 8 * DAY_IN_SECONDS ),
196
+			'before' => date('Y-m-d', strtotime('monday last week', current_time('timestamp'))),
197
+			'after'  => date('Y-m-d', strtotime('monday last week', current_time('timestamp')) - 8 * DAY_IN_SECONDS),
198 198
 		);
199 199
 
200 200
 		// Generate the report.
201 201
 		return array(
202
-			'before' => date( 'Y-m-d', strtotime( 'monday this week', current_time( 'timestamp' )  ) ),
203
-			'after'  => date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' )  ) - DAY_IN_SECONDS ),
202
+			'before' => date('Y-m-d', strtotime('monday this week', current_time('timestamp'))),
203
+			'after'  => date('Y-m-d', strtotime('monday last week', current_time('timestamp')) - DAY_IN_SECONDS),
204 204
 		);
205 205
 
206 206
 	}
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 		// Set the previous date range.
216 216
 		$this->previous_range = array(
217 217
 			'period' => 'custom',
218
-			'before' => date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ),
219
-			'after'  => date( 'Y-m-d', strtotime( '-15 days', current_time( 'timestamp' ) ) ),
218
+			'before' => date('Y-m-d', strtotime('-7 days', current_time('timestamp'))),
219
+			'after'  => date('Y-m-d', strtotime('-15 days', current_time('timestamp'))),
220 220
 		);
221 221
 
222 222
 		// Generate the report.
223 223
 		return array(
224
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
225
-			'after'  => date( 'Y-m-d', strtotime( '-8 days', current_time( 'timestamp' ) ) ),
224
+			'before' => date('Y-m-d', current_time('timestamp')),
225
+			'after'  => date('Y-m-d', strtotime('-8 days', current_time('timestamp'))),
226 226
 		);
227 227
 
228 228
 	}
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 		// Set the previous date range.
238 238
 		$this->previous_range = array(
239 239
 			'period' => 'custom',
240
-			'before' => date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ),
241
-			'after'  => date( 'Y-m-d', strtotime( '-61 days', current_time( 'timestamp' ) ) ),
240
+			'before' => date('Y-m-d', strtotime('-30 days', current_time('timestamp'))),
241
+			'after'  => date('Y-m-d', strtotime('-61 days', current_time('timestamp'))),
242 242
 		);
243 243
 
244 244
 		// Generate the report.
245 245
 		return array(
246
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
247
-			'after'  => date( 'Y-m-d', strtotime( '-31 days', current_time( 'timestamp' ) ) ),
246
+			'before' => date('Y-m-d', current_time('timestamp')),
247
+			'after'  => date('Y-m-d', strtotime('-31 days', current_time('timestamp'))),
248 248
 		);
249 249
 
250 250
 	}
@@ -261,14 +261,14 @@  discard block
 block discarded – undo
261 261
 		// Set the previous date range.
262 262
 		$this->previous_range = array(
263 263
 			'period' => 'custom',
264
-			'before' => date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ),
265
-			'after'  => date( 'Y-m-d', strtotime( '-181 days', current_time( 'timestamp' ) ) ),
264
+			'before' => date('Y-m-d', strtotime('-90 days', current_time('timestamp'))),
265
+			'after'  => date('Y-m-d', strtotime('-181 days', current_time('timestamp'))),
266 266
 		);
267 267
 
268 268
 		// Generate the report.
269 269
 		return array(
270
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
271
-			'after'  => date( 'Y-m-d', strtotime( '-91 days', current_time( 'timestamp' ) ) ),
270
+			'before' => date('Y-m-d', current_time('timestamp')),
271
+			'after'  => date('Y-m-d', strtotime('-91 days', current_time('timestamp'))),
272 272
 		);
273 273
 
274 274
 	}
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
 		// Set the previous date range.
286 286
 		$this->previous_range = array(
287 287
 			'period' => 'custom',
288
-			'before' => date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ),
289
-			'after'  => date( 'Y-m-d', strtotime( '-361 days', current_time( 'timestamp' ) ) ),
288
+			'before' => date('Y-m-d', strtotime('-180 days', current_time('timestamp'))),
289
+			'after'  => date('Y-m-d', strtotime('-361 days', current_time('timestamp'))),
290 290
 		);
291 291
 
292 292
 		// Generate the report.
293 293
 		return array(
294
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
295
-			'after'  => date( 'Y-m-d', strtotime( '-181 days', current_time( 'timestamp' ) ) ),
294
+			'before' => date('Y-m-d', current_time('timestamp')),
295
+			'after'  => date('Y-m-d', strtotime('-181 days', current_time('timestamp'))),
296 296
 		);
297 297
 
298 298
 	}
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
 		// Set the previous date range.
308 308
 		$this->previous_range = array(
309 309
 			'period' => 'custom',
310
-			'before' => date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ),
311
-			'after'  => date( 'Y-m-d', strtotime( '-121 days', current_time( 'timestamp' ) ) ),
310
+			'before' => date('Y-m-d', strtotime('-60 days', current_time('timestamp'))),
311
+			'after'  => date('Y-m-d', strtotime('-121 days', current_time('timestamp'))),
312 312
 		);
313 313
 
314 314
 		// Generate the report.
315 315
 		return array(
316
-			'before' => date( 'Y-m-d', current_time( 'timestamp' ) ),
317
-			'after'  => date( 'Y-m-d', strtotime( '-61 days', current_time( 'timestamp' ) ) ),
316
+			'before' => date('Y-m-d', current_time('timestamp')),
317
+			'after'  => date('Y-m-d', strtotime('-61 days', current_time('timestamp'))),
318 318
 		);
319 319
 
320 320
 	}
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 
334 334
 		// Generate the report.
335 335
 		return array(
336
-			'before' => date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ),
337
-			'after'  => date( 'Y-m-t', strtotime( 'last month', current_time( 'timestamp' ) ) ),
336
+			'before' => date('Y-m-d', strtotime('+1 day', current_time('timestamp'))),
337
+			'after'  => date('Y-m-t', strtotime('last month', current_time('timestamp'))),
338 338
 		);
339 339
 
340 340
 	}
@@ -349,14 +349,14 @@  discard block
 block discarded – undo
349 349
 		// Set the previous date range.
350 350
 		$this->previous_range = array(
351 351
 			'period' => 'custom',
352
-			'before' => date( 'Y-m-1', strtotime( 'last month', current_time( 'timestamp' ) ) ),
353
-			'after'  => date( 'Y-m-t', strtotime( "-3 months", current_time( 'timestamp' ) ) ),
352
+			'before' => date('Y-m-1', strtotime('last month', current_time('timestamp'))),
353
+			'after'  => date('Y-m-t', strtotime("-3 months", current_time('timestamp'))),
354 354
 		);
355 355
 
356 356
 		// Generate the report.
357 357
 		return array(
358
-			'before' => date( 'Y-m-1', current_time( 'timestamp' ) ),
359
-			'after'  => date( 'Y-m-t', strtotime( "-2 months", current_time( 'timestamp' ) ) ),
358
+			'before' => date('Y-m-1', current_time('timestamp')),
359
+			'after'  => date('Y-m-t', strtotime("-2 months", current_time('timestamp'))),
360 360
 		);
361 361
 
362 362
 	}
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 
378 378
 		// Generate the report.
379 379
 		return array(
380
-			'before' => date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ),
381
-			'after'  => date( 'Y-m-d', strtotime( 'last year December 31st', current_time( 'timestamp' ) ) ),
380
+			'before' => date('Y-m-d', strtotime('+1 day', current_time('timestamp'))),
381
+			'after'  => date('Y-m-d', strtotime('last year December 31st', current_time('timestamp'))),
382 382
 		);
383 383
 
384 384
 	}
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 		$year          = (int) date('Y') - 3;
397 397
 		$this->previous_range = array(
398 398
 			'period' => 'custom',
399
-			'before' => date( 'Y-m-d', strtotime( 'first day of january last year', current_time( 'timestamp' ) ) ),
399
+			'before' => date('Y-m-d', strtotime('first day of january last year', current_time('timestamp'))),
400 400
 			'after'  => "$year-12-31",
401 401
 		);
402 402
 
403 403
 		// Generate the report.
404
-		$year          = (int) date('Y') - 2;
404
+		$year = (int) date('Y') - 2;
405 405
 		return array(
406 406
 			'after'  => "$year-12-31",
407
-			'before' => date( 'Y-m-d', strtotime( 'first day of january this year', current_time( 'timestamp' ) ) ),
407
+			'before' => date('Y-m-d', strtotime('first day of january this year', current_time('timestamp'))),
408 408
 		);
409 409
 
410 410
 	}
@@ -416,21 +416,21 @@  discard block
 block discarded – undo
416 416
 	 * @param string $date_field The date field.
417 417
 	 * @return string The appropriate SQL.
418 418
 	 */
419
-	public function get_date_range_sql( $request, $date_field ) {
419
+	public function get_date_range_sql($request, $date_field) {
420 420
 		global $wpdb;
421 421
 
422 422
 		$sql = '1=1';
423
-		$range = $this->get_date_range( $request );
423
+		$range = $this->get_date_range($request);
424 424
 
425
-		if ( ! empty( $range['after'] ) ) {
426
-			$sql .= ' AND ' .  $wpdb->prepare(
425
+		if (!empty($range['after'])) {
426
+			$sql .= ' AND ' . $wpdb->prepare(
427 427
 				"$date_field > %s",
428 428
 				$range['after']
429 429
 			);
430 430
 		}
431 431
 
432
-		if ( ! empty( $range['before'] ) ) {
433
-			$sql .= ' AND ' .  $wpdb->prepare(
432
+		if (!empty($range['before'])) {
433
+			$sql .= ' AND ' . $wpdb->prepare(
434 434
 				"$date_field < %s",
435 435
 				$range['before']
436 436
 			);
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
 	 * @param string $date_field The date field.
447 447
 	 * @return string The appropriate SQL.
448 448
 	 */
449
-	public function get_group_by_sql( $date_field ) {
449
+	public function get_group_by_sql($date_field) {
450 450
 
451
-		if ( 'day' === $this->groupby ) {
451
+		if ('day' === $this->groupby) {
452 452
 			return "YEAR($date_field), MONTH($date_field), DAY($date_field)";
453 453
 		}
454 454
 
@@ -462,32 +462,32 @@  discard block
 block discarded – undo
462 462
 	 */
463 463
 	public function get_collection_params() {
464 464
 		return array(
465
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
465
+			'context' => $this->get_context_param(array('default' => 'view')),
466 466
 			'period' => array(
467
-				'description'       => __( 'Limit to results of a specific period.', 'invoicing' ),
467
+				'description'       => __('Limit to results of a specific period.', 'invoicing'),
468 468
 				'type'              => 'string',
469
-				'enum'              => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days' , '90_days', '180_days', 'month', 'last_month', 'year', 'last_year', 'quarter', 'last_quarter' ),
469
+				'enum'              => array('custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'year', 'last_year', 'quarter', 'last_quarter'),
470 470
 				'validate_callback' => 'rest_validate_request_arg',
471 471
 				'sanitize_callback' => 'sanitize_text_field',
472 472
 				'default'           => '7_days',
473 473
 			),
474 474
 			'after' => array(
475 475
 				/* translators: %s: date format */
476
-				'description'       => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
476
+				'description'       => sprintf(__('Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing'), 'YYYY-MM-DD'),
477 477
 				'type'              => 'string',
478 478
 				'format'            => 'date',
479 479
 				'validate_callback' => 'rest_validate_request_arg',
480 480
 				'sanitize_callback' => 'sanitize_text_field',
481
-				'default'           => date( 'Y-m-d', strtotime( '-8 days', current_time( 'timestamp' ) ) ),
481
+				'default'           => date('Y-m-d', strtotime('-8 days', current_time('timestamp'))),
482 482
 			),
483 483
 			'before' => array(
484 484
 				/* translators: %s: date format */
485
-				'description'       => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ),
485
+				'description'       => sprintf(__('Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing'), 'YYYY-MM-DD'),
486 486
 				'type'              => 'string',
487 487
 				'format'            => 'date',
488 488
 				'validate_callback' => 'rest_validate_request_arg',
489 489
 				'sanitize_callback' => 'sanitize_text_field',
490
-				'default'           => date( 'Y-m-d', current_time( 'timestamp' ) ),
490
+				'default'           => date('Y-m-d', current_time('timestamp')),
491 491
 			),
492 492
 		);
493 493
 	}
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-earnings.php 1 patch
Spacing   +44 added lines, -44 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,15 +139,15 @@  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%">
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
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 sanitize_key( $key ); ?>"></canvas>
178
+		<canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key($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 sanitize_key( $key ); ?>' ).getContext('2d');
183
+				var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo sanitize_key($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( $labels ); ?>,
189
+							'labels': <?php echo wp_json_encode($labels); ?>,
190 190
 							'datasets': [
191 191
 								{
192
-									label: '<?php echo esc_attr( $dataset['label'] ); ?>',
193
-									data: <?php echo wp_json_encode( $dataset['data'] ); ?>,
192
+									label: '<?php echo esc_attr($dataset['label']); ?>',
193
+									data: <?php echo wp_json_encode($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.php 1 patch
Spacing   +79 added lines, -79 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,20 +68,20 @@  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
-			'year'      => __( 'This year', 'invoicing' ),
80
-			'last_year' => __( 'Last Year', 'invoicing' ),
81
-			'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
+			'year'      => __('This year', 'invoicing'),
80
+			'last_year' => __('Last Year', 'invoicing'),
81
+			'custom'    => __('Custom Date Range', 'invoicing'),
82 82
 		);
83 83
 
84
-		return apply_filters( 'getpaid_earning_periods', $periods );
84
+		return apply_filters('getpaid_earning_periods', $periods);
85 85
 	}
86 86
 
87 87
 	/**
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
 		?>
95 95
 
96 96
 			<form method="get" class="getpaid-filter-earnings float-right">
97
-				<?php getpaid_hidden_field( 'page', 'wpinv-reports' );  ?>
98
-				<?php getpaid_hidden_field( 'tab', 'reports' );  ?>
97
+				<?php getpaid_hidden_field('page', 'wpinv-reports'); ?>
98
+				<?php getpaid_hidden_field('tab', 'reports'); ?>
99 99
 				<select name='date_range'>
100
-					<?php foreach( $this->get_periods() as $key => $label ) :?>
101
-						<option value="<?php echo sanitize_key( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo sanitize_text_field( $label ); ?></option>
102
-					<?php endforeach;?>
100
+					<?php foreach ($this->get_periods() as $key => $label) :?>
101
+						<option value="<?php echo sanitize_key($key); ?>" <?php selected($key, $range); ?>><?php echo sanitize_text_field($label); ?></option>
102
+					<?php endforeach; ?>
103 103
 				</select>
104 104
 				<span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>">
105 105
 					<input type="text" name="from" class="getpaid-from align-middle" />
106
-						<?php _e( 'to', 'invoicing' ); ?>
106
+						<?php _e('to', 'invoicing'); ?>
107 107
 					<input type="text" name="to" class="getpaid-to align-middle" />
108 108
 				</span>
109 109
 				<button type="submit" class="button button-primary">
110 110
 					<i class="fa fa-chevron-right fa-lg"></i>
111
-					<span class="screen-reader-text"><?php _e( 'Next', 'invoicing' ); ?></span>
111
+					<span class="screen-reader-text"><?php _e('Next', 'invoicing'); ?></span>
112 112
 				</button>
113 113
 			</form>
114 114
 
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 
158 158
 				<div class="col-12 col-md-4">
159 159
 					<div class="row getpaid-report-cards">
160
-						<?php foreach( $this->get_cards() as $key => $card ) : ?>
160
+						<?php foreach ($this->get_cards() as $key => $card) : ?>
161 161
 							<div class="col-12 mb-4">
162 162
 
163
-								<!-- <?php echo sanitize_text_field(  $card['label']  ); ?> Card -->
164
-								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class( $key ); ?>">
163
+								<!-- <?php echo sanitize_text_field($card['label']); ?> Card -->
164
+								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class($key); ?>">
165 165
 
166 166
 									<div class="card-body">
167 167
 
168 168
 										<p class="getpaid-current text-uppercase small mb-2">
169
-											<strong><?php echo sanitize_text_field( $card['label']  ); ?></strong>
170
-											<span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
169
+											<strong><?php echo sanitize_text_field($card['label']); ?></strong>
170
+											<span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
171 171
 										</p>
172 172
 										<h5 class="font-weight-bold mb-0">
173 173
 											<span class="getpaid-report-card-value">
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 
179 179
 										<hr>
180 180
 
181
-										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e( 'Previous Period', 'invoicing' ); ?></strong></p>
181
+										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e('Previous Period', 'invoicing'); ?></strong></p>
182 182
 										<h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0">
183 183
 											<span class="spinner is-active float-none"></span>
184 184
 										</h5>
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 									</div>
187 187
 
188 188
 								</div>
189
-								<!-- <?php echo sanitize_text_field( $card['label'] ); ?> Card -->
189
+								<!-- <?php echo sanitize_text_field($card['label']); ?> Card -->
190 190
 
191 191
 							</div>
192 192
 						<?php endforeach; ?>
@@ -208,26 +208,26 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	public function display_left() {
210 210
 		$graphs = array(
211
-			'sales'    => __( 'Earnings', 'invoicing' ),
212
-			'refunds'  => __( 'Refunds', 'invoicing' ),
213
-			'tax'      => __( 'Taxes', 'invoicing' ),
214
-			'fees'     => __( 'Fees', 'invoicing' ),
215
-			'discount' => __( 'Discounts', 'invoicing' ),
216
-			'invoices' => __( 'Invoices', 'invoicing' ),
217
-			'items'    => __( 'Purchased Items', 'invoicing' ),
211
+			'sales'    => __('Earnings', 'invoicing'),
212
+			'refunds'  => __('Refunds', 'invoicing'),
213
+			'tax'      => __('Taxes', 'invoicing'),
214
+			'fees'     => __('Fees', 'invoicing'),
215
+			'discount' => __('Discounts', 'invoicing'),
216
+			'invoices' => __('Invoices', 'invoicing'),
217
+			'items'    => __('Purchased Items', 'invoicing'),
218 218
 		);
219 219
 
220 220
 		?>
221 221
 
222
-			<?php foreach ( $graphs as $key => $graph ) : ?>
222
+			<?php foreach ($graphs as $key => $graph) : ?>
223 223
 				<div class="row mb-4">
224 224
 					<div class="col-12">
225 225
 						<div class="card m-0 p-0" style="max-width:100%">
226 226
 							<div class="card-header">
227
-								<strong><?php echo wpinv_clean( $graph ); ?></strong>
227
+								<strong><?php echo wpinv_clean($graph); ?></strong>
228 228
 							</div>
229 229
 							<div class="card-body">
230
-								<canvas id="getpaid-chartjs-<?php echo sanitize_key( $key ); ?>"></canvas>
230
+								<canvas id="getpaid-chartjs-<?php echo sanitize_key($key); ?>"></canvas>
231 231
 							</div>
232 232
 						</div>
233 233
 					</div>
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
 	 * Retrieves the download url.
243 243
 	 *
244 244
 	 */
245
-	public function get_download_url( $graph, $file_type ) {
245
+	public function get_download_url($graph, $file_type) {
246 246
 
247 247
 		return wp_nonce_url(
248 248
 			add_query_arg(
249 249
 				array(
250 250
 					'getpaid-admin-action' => 'download_graph',
251
-					'file_type'            => urlencode( $file_type ),
252
-					'graph'                => urlencode( $graph ),
251
+					'file_type'            => urlencode($file_type),
252
+					'graph'                => urlencode($graph),
253 253
 				)
254 254
 			),
255 255
 			'getpaid-nonce',
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 
267 267
 		?>
268 268
 
269
-			<?php foreach ( $this->views as $key => $view ) : ?>
269
+			<?php foreach ($this->views as $key => $view) : ?>
270 270
 				<div class="row mb-4">
271 271
 					<div class="col-12">
272 272
 						<div class="card m-0 p-0" style="max-width:100%">
@@ -276,17 +276,17 @@  discard block
 block discarded – undo
276 276
 										<strong><?php echo $view['label']; ?></strong>
277 277
 									</div>
278 278
 									<div class="col-3">
279
-										<a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>">
279
+										<a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>">
280 280
 											<i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i>
281
-											<span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span>
281
+											<span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span>
282 282
 										</a>
283
-										<a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>">
283
+										<a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>">
284 284
 											<i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i>
285
-											<span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span>
285
+											<span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span>
286 286
 										</a>
287
-										<a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>">
287
+										<a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>">
288 288
 											<i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i>
289
-											<span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span>
289
+											<span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span>
290 290
 										</a>
291 291
 									</div>
292 292
 								</div>
@@ -315,56 +315,56 @@  discard block
 block discarded – undo
315 315
 
316 316
 		$cards = array(
317 317
 			'total_sales' => array(
318
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
319
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
318
+				'description' => __('Gross sales in the period.', 'invoicing'),
319
+				'label'       => __('Gross Revenue', 'invoicing'),
320 320
 			),
321 321
 			'net_sales' => array(
322
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
323
-				'label'       => __( 'Net Revenue', 'invoicing' ),
322
+				'description' => __('Net sales in the period.', 'invoicing'),
323
+				'label'       => __('Net Revenue', 'invoicing'),
324 324
 			),
325 325
 			'average_sales' => array(
326
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
327
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
326
+				'description' => __('Average net daily/monthly sales.', 'invoicing'),
327
+				'label'       => __('Avg. Net Sales', 'invoicing'),
328 328
 			),
329 329
 			'average_total_sales' => array(
330
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
331
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
330
+				'description' => __('Average gross daily/monthly sales.', 'invoicing'),
331
+				'label'       => __('Avg. Gross Sales', 'invoicing'),
332 332
 			),
333 333
 			'total_invoices'  => array(
334
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
335
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
334
+				'description' => __('Number of paid invoices.', 'invoicing'),
335
+				'label'       => __('Paid Invoices', 'invoicing'),
336 336
 			),
337 337
 			'total_items' => array(
338
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
339
-				'label'       => __( 'Purchased Items', 'invoicing' ),
338
+				'description' => __('Number of items purchased.', 'invoicing'),
339
+				'label'       => __('Purchased Items', 'invoicing'),
340 340
 			),
341 341
 			'refunded_items' => array(
342
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
343
-				'label'       => __( 'Refunded Items', 'invoicing' ),
342
+				'description' => __('Number of items refunded.', 'invoicing'),
343
+				'label'       => __('Refunded Items', 'invoicing'),
344 344
 			),
345 345
 			'total_tax' => array(
346
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
347
-				'label'       => __( 'Tax', 'invoicing' ),
346
+				'description' => __('Total charged for taxes.', 'invoicing'),
347
+				'label'       => __('Tax', 'invoicing'),
348 348
 			),
349 349
 			'total_refunded_tax' => array(
350
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
351
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
350
+				'description' => __('Total refunded for taxes.', 'invoicing'),
351
+				'label'       => __('Refunded Tax', 'invoicing'),
352 352
 			),
353 353
 			'total_fees' => array(
354
-				'description' => __( 'Total fees charged.', 'invoicing' ),
355
-				'label'       => __( 'Fees', 'invoicing' ),
354
+				'description' => __('Total fees charged.', 'invoicing'),
355
+				'label'       => __('Fees', 'invoicing'),
356 356
 			),
357 357
 			'total_refunds' => array(
358
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
359
-				'label'       => __( 'Refunded', 'invoicing' ),
358
+				'description' => __('Total of refunded invoices.', 'invoicing'),
359
+				'label'       => __('Refunded', 'invoicing'),
360 360
 			),
361 361
 			'total_discount'  => array(
362
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
363
-				'label'       => __( 'Discounted', 'invoicing' ),
362
+				'description' => __('Total of discounts used.', 'invoicing'),
363
+				'label'       => __('Discounted', 'invoicing'),
364 364
 			),
365 365
 		);
366 366
 
367
-		return apply_filters( 'wpinv_report_cards', $cards );
367
+		return apply_filters('wpinv_report_cards', $cards);
368 368
 	}
369 369
 
370 370
 	
Please login to merge, or discard this patch.