Passed
Push — master ( 6daaec...36cd12 )
by Brian
06:16
created
includes/reports/class-getpaid-reports-export.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -12,46 +12,46 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		echo "</div>";
26
-
27
-	}
28
-
29
-	/**
30
-	 * Retrieves the download url.
31
-	 *
32
-	 */
33
-	public function get_download_url( $post_type ) {
34
-
35
-		return wp_nonce_url(
36
-			add_query_arg(
37
-				array(
38
-					'getpaid-admin-action' => 'export_invoices',
39
-					'post_type'            => urlencode( $post_type ),
40
-				)
41
-			),
42
-			'getpaid-nonce',
43
-			'getpaid-nonce'
44
-		);
45
-
46
-	}
47
-
48
-	/**
49
-	 * Displays a single post type export card.
50
-	 *
51
-	 */
52
-	public function display_post_type_export( $post_type ) {
53
-
54
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        echo "</div>";
26
+
27
+    }
28
+
29
+    /**
30
+     * Retrieves the download url.
31
+     *
32
+     */
33
+    public function get_download_url( $post_type ) {
34
+
35
+        return wp_nonce_url(
36
+            add_query_arg(
37
+                array(
38
+                    'getpaid-admin-action' => 'export_invoices',
39
+                    'post_type'            => urlencode( $post_type ),
40
+                )
41
+            ),
42
+            'getpaid-nonce',
43
+            'getpaid-nonce'
44
+        );
45
+
46
+    }
47
+
48
+    /**
49
+     * Displays a single post type export card.
50
+     *
51
+     */
52
+    public function display_post_type_export( $post_type ) {
53
+
54
+        ?>
55 55
 
56 56
 		<div class="col-12 col-md-6">
57 57
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 				<div class="card-header">
60 60
 					<strong>
61 61
 						<?php
62
-							printf(
63
-								__( 'Export %s', 'invoicing' ),
64
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
65
-							);
66
-						?>
62
+                            printf(
63
+                                __( 'Export %s', 'invoicing' ),
64
+                                sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
65
+                            );
66
+                        ?>
67 67
 					</strong>
68 68
 				</div>
69 69
 
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73 73
 
74 74
 						<?php
75
-							$this->display_markup( $this->generate_from_date( $post_type ) );
76
-							$this->display_markup( $this->generate_to_date( $post_type ) );
77
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
78
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
79
-							submit_button( __( 'Download', 'invoicing' ) );
80
-						?>
75
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
76
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
78
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
79
+                            submit_button( __( 'Download', 'invoicing' ) );
80
+                        ?>
81 81
 
82 82
 					</form>
83 83
 
@@ -88,107 +88,107 @@  discard block
 block discarded – undo
88 88
 
89 89
 		<?php
90 90
 
91
-	}
92
-
93
-	/**
94
-	 * Generates the from date input field.
95
-	 *
96
-	 */
97
-	public function generate_from_date( $post_type ) {
98
-
99
-		return aui()->input(
100
-			array(
101
-				'name'       => 'from_date',
102
-				'id'         => esc_attr( "$post_type-from_date" ),
103
-				'placeholder'=> 'yy-mm-dd',
104
-				'label'      => __( 'From Date', 'invoicing' ),
105
-				'label_type' => 'vertical',
106
-				'label_class' => 'd-block',
107
-				'type'       => 'datepicker',
108
-			)
109
-		);
110
-
111
-	}
112
-
113
-	/**
114
-	 * Generates the to date input field.
115
-	 *
116
-	 */
117
-	public function generate_to_date( $post_type ) {
118
-
119
-		return aui()->input(
120
-			array(
121
-				'name'       => 'to_date',
122
-				'id'         => esc_attr( "$post_type-to_date" ),
123
-				'placeholder'=> 'yy-mm-dd',
124
-				'label'      => __( 'To Date', 'invoicing' ),
125
-				'label_type' => 'vertical',
126
-				'label_class' => 'd-block',
127
-				'type'       => 'datepicker',
128
-			)
129
-		);
130
-
131
-	}
132
-
133
-	/**
134
-	 * Generates the to post status select field.
135
-	 *
136
-	 */
137
-	public function generate_post_status_select( $post_type ) {
138
-
139
-		return aui()->select(
140
-			array(
141
-				'name'        => 'status',
142
-				'id'          => esc_attr( "$post_type-status" ),
143
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
144
-				'label'       => __( 'Status', 'invoicing' ),
145
-				'label_type'  => 'vertical',
146
-				'label_class' => 'd-block',
147
-				'options'     => wpinv_get_invoice_statuses( true, false, $post_type ),
148
-			)
149
-		);
150
-
151
-	}
152
-
153
-	/**
154
-	 * Generates the to file type select field.
155
-	 *
156
-	 */
157
-	public function generate_file_type_select( $post_type ) {
158
-
159
-		return aui()->select(
160
-			array(
161
-				'name'        => 'file_type',
162
-				'id'          => esc_attr( "$post_type-file_type" ),
163
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
164
-				'label'       => __( 'Export File', 'invoicing' ),
165
-				'label_type'  => 'vertical',
166
-				'label_class' => 'd-block',
167
-				'options'     => array(
168
-					'csv'  => __( 'CSV', 'invoicing' ),
169
-					'xml'  => __( 'XML', 'invoicing' ),
170
-					'json' => __( 'JSON', 'invoicing' ),
171
-				),
172
-			)
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Displays a field's markup.
179
-	 *
180
-	 */
181
-	public function display_markup( $markup ) {
182
-
183
-		echo str_replace(
184
-			array(
185
-				'form-control',
186
-				'custom-select'
187
-			),
188
-			'regular-text',
189
-			$markup
190
-		);
191
-
192
-	}
91
+    }
92
+
93
+    /**
94
+     * Generates the from date input field.
95
+     *
96
+     */
97
+    public function generate_from_date( $post_type ) {
98
+
99
+        return aui()->input(
100
+            array(
101
+                'name'       => 'from_date',
102
+                'id'         => esc_attr( "$post_type-from_date" ),
103
+                'placeholder'=> 'yy-mm-dd',
104
+                'label'      => __( 'From Date', 'invoicing' ),
105
+                'label_type' => 'vertical',
106
+                'label_class' => 'd-block',
107
+                'type'       => 'datepicker',
108
+            )
109
+        );
110
+
111
+    }
112
+
113
+    /**
114
+     * Generates the to date input field.
115
+     *
116
+     */
117
+    public function generate_to_date( $post_type ) {
118
+
119
+        return aui()->input(
120
+            array(
121
+                'name'       => 'to_date',
122
+                'id'         => esc_attr( "$post_type-to_date" ),
123
+                'placeholder'=> 'yy-mm-dd',
124
+                'label'      => __( 'To Date', 'invoicing' ),
125
+                'label_type' => 'vertical',
126
+                'label_class' => 'd-block',
127
+                'type'       => 'datepicker',
128
+            )
129
+        );
130
+
131
+    }
132
+
133
+    /**
134
+     * Generates the to post status select field.
135
+     *
136
+     */
137
+    public function generate_post_status_select( $post_type ) {
138
+
139
+        return aui()->select(
140
+            array(
141
+                'name'        => 'status',
142
+                'id'          => esc_attr( "$post_type-status" ),
143
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
144
+                'label'       => __( 'Status', 'invoicing' ),
145
+                'label_type'  => 'vertical',
146
+                'label_class' => 'd-block',
147
+                'options'     => wpinv_get_invoice_statuses( true, false, $post_type ),
148
+            )
149
+        );
150
+
151
+    }
152
+
153
+    /**
154
+     * Generates the to file type select field.
155
+     *
156
+     */
157
+    public function generate_file_type_select( $post_type ) {
158
+
159
+        return aui()->select(
160
+            array(
161
+                'name'        => 'file_type',
162
+                'id'          => esc_attr( "$post_type-file_type" ),
163
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
164
+                'label'       => __( 'Export File', 'invoicing' ),
165
+                'label_type'  => 'vertical',
166
+                'label_class' => 'd-block',
167
+                'options'     => array(
168
+                    'csv'  => __( 'CSV', 'invoicing' ),
169
+                    'xml'  => __( 'XML', 'invoicing' ),
170
+                    'json' => __( 'JSON', 'invoicing' ),
171
+                ),
172
+            )
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Displays a field's markup.
179
+     *
180
+     */
181
+    public function display_markup( $markup ) {
182
+
183
+        echo str_replace(
184
+            array(
185
+                'form-control',
186
+                'custom-select'
187
+            ),
188
+            'regular-text',
189
+            $markup
190
+        );
191
+
192
+    }
193 193
 
194 194
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -12,49 +12,49 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 *
18
-	 */
19
-	public function __construct() {
20
-		add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
-		add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
-		add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
-		add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
-		add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
-
26
-	}
27
-
28
-	/**
29
-	 * Registers the reports page.
30
-	 *
31
-	 */
32
-	public function register_reports_page() {
33
-
34
-		add_submenu_page(
15
+    /**
16
+     * Class constructor.
17
+     *
18
+     */
19
+    public function __construct() {
20
+        add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
+        add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
+        add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
+        add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
+        add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
+
26
+    }
27
+
28
+    /**
29
+     * Registers the reports page.
30
+     *
31
+     */
32
+    public function register_reports_page() {
33
+
34
+        add_submenu_page(
35 35
             'wpinv',
36 36
             __( 'Reports', 'invoicing' ),
37 37
             __( 'Reports', 'invoicing' ),
38 38
             wpinv_get_capability(),
39 39
             'wpinv-reports',
40 40
             array( $this, 'display_reports_page' )
41
-		);
41
+        );
42 42
 
43
-	}
43
+    }
44 44
 
45
-	/**
46
-	 * Displays the reports page.
47
-	 *
48
-	 */
49
-	public function display_reports_page() {
45
+    /**
46
+     * Displays the reports page.
47
+     *
48
+     */
49
+    public function display_reports_page() {
50 50
 
51
-		// Prepare variables.
52
-		$tabs        = $this->get_tabs();
53
-		$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
-		$current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
51
+        // Prepare variables.
52
+        $tabs        = $this->get_tabs();
53
+        $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
+        $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
55 55
 
56
-		// Display the current tab.
57
-		?>
56
+        // Display the current tab.
57
+        ?>
58 58
 
59 59
         <div class="wrap">
60 60
 
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
 			<nav class="nav-tab-wrapper">
64 64
 
65 65
 				<?php
66
-					foreach( $tabs as $key => $label ) {
66
+                    foreach( $tabs as $key => $label ) {
67 67
 
68
-						$key   = sanitize_text_field( $key );
69
-						$label = sanitize_text_field( $label );
70
-						$class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
-						$url   = esc_url(
72
-							add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
-						);
68
+                        $key   = sanitize_text_field( $key );
69
+                        $label = sanitize_text_field( $label );
70
+                        $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
+                        $url   = esc_url(
72
+                            add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
+                        );
74 74
 
75
-						echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
75
+                        echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
76 76
 
77
-					}
78
-				?>
77
+                    }
78
+                ?>
79 79
 
80 80
 			</nav>
81 81
 
@@ -86,74 +86,74 @@  discard block
 block discarded – undo
86 86
         </div>
87 87
 		<?php
88 88
 
89
-			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
90
-			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
89
+            wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
90
+            wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves reports page tabs.
96
-	 *
97
-	 * @return array
98
-	 */
99
-	public function get_tabs() {
94
+    /**
95
+     * Retrieves reports page tabs.
96
+     *
97
+     * @return array
98
+     */
99
+    public function get_tabs() {
100 100
 
101
-		$tabs = array(
102
-			'reports' => __( 'Reports', 'invoicing' ),
103
-			'export'  => __( 'Export', 'invoicing' ),
104
-		);
101
+        $tabs = array(
102
+            'reports' => __( 'Reports', 'invoicing' ),
103
+            'export'  => __( 'Export', 'invoicing' ),
104
+        );
105 105
 
106
-		return apply_filters( 'getpaid_report_tabs', $tabs );
107
-	}
106
+        return apply_filters( 'getpaid_report_tabs', $tabs );
107
+    }
108 108
 
109
-	/**
110
-	 * Displays the reports tab.
111
-	 *
112
-	 */
113
-	public function display_reports_tab() {
109
+    /**
110
+     * Displays the reports tab.
111
+     *
112
+     */
113
+    public function display_reports_tab() {
114 114
 
115
-		$reports = new GetPaid_Reports_Report();
116
-		$reports->display();
115
+        $reports = new GetPaid_Reports_Report();
116
+        $reports->display();
117 117
 
118
-	}
118
+    }
119 119
 
120
-	/**
121
-	 * Displays the exports tab.
122
-	 *
123
-	 */
124
-	public function display_exports_tab() {
120
+    /**
121
+     * Displays the exports tab.
122
+     *
123
+     */
124
+    public function display_exports_tab() {
125 125
 
126
-		$exports = new GetPaid_Reports_Export();
127
-		$exports->display();
126
+        $exports = new GetPaid_Reports_Export();
127
+        $exports->display();
128 128
 
129
-	}
129
+    }
130 130
 
131
-	/**
132
-	 * Donwnloads a graph.
133
-	 *
134
-	 * @param array $args
135
-	 */
136
-	public function download_graph( $args ) {
131
+    /**
132
+     * Donwnloads a graph.
133
+     *
134
+     * @param array $args
135
+     */
136
+    public function download_graph( $args ) {
137 137
 
138
-		if ( ! empty( $args['graph'] ) ) {
139
-			$downloader = new GetPaid_Graph_Downloader();
140
-			$downloader->download( $args['graph'] );
141
-		}
138
+        if ( ! empty( $args['graph'] ) ) {
139
+            $downloader = new GetPaid_Graph_Downloader();
140
+            $downloader->download( $args['graph'] );
141
+        }
142 142
 
143
-	}
143
+    }
144 144
 
145
-	/**
146
-	 * Exports invoices.
147
-	 *
148
-	 * @param array $args
149
-	 */
150
-	public function export_invoices( $args ) {
145
+    /**
146
+     * Exports invoices.
147
+     *
148
+     * @param array $args
149
+     */
150
+    public function export_invoices( $args ) {
151 151
 
152
-		if ( ! empty( $args['post_type'] ) ) {
153
-			$downloader = new GetPaid_Invoice_Exporter();
154
-			$downloader->export( $args['post_type'], $args );
155
-		}
152
+        if ( ! empty( $args['post_type'] ) ) {
153
+            $downloader = new GetPaid_Invoice_Exporter();
154
+            $downloader->export( $args['post_type'], $args );
155
+        }
156 156
 
157
-	}
157
+    }
158 158
 
159 159
 }
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
99 99
 
100
-	$invoice_statuses = array(
101
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
100
+    $invoice_statuses = array(
101
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
102 102
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
103 103
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
104
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
105
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
106
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
104
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
105
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
106
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
107 107
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
108 108
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
109 109
     );
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         $invoice = $invoice->get_post_type();
121 121
     }
122 122
 
123
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
123
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
124 124
 }
125 125
 
126 126
 /**
@@ -238,25 +238,25 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function getpaid_get_price_format() {
241
-	$currency_pos = wpinv_currency_position();
242
-	$format       = '%1$s%2$s';
243
-
244
-	switch ( $currency_pos ) {
245
-		case 'left':
246
-			$format = '%1$s%2$s';
247
-			break;
248
-		case 'right':
249
-			$format = '%2$s%1$s';
250
-			break;
251
-		case 'left_space':
252
-			$format = '%1$s&nbsp;%2$s';
253
-			break;
254
-		case 'right_space':
255
-			$format = '%2$s&nbsp;%1$s';
256
-			break;
257
-	}
258
-
259
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
241
+    $currency_pos = wpinv_currency_position();
242
+    $format       = '%1$s%2$s';
243
+
244
+    switch ( $currency_pos ) {
245
+        case 'left':
246
+            $format = '%1$s%2$s';
247
+            break;
248
+        case 'right':
249
+            $format = '%2$s%1$s';
250
+            break;
251
+        case 'left_space':
252
+            $format = '%1$s&nbsp;%2$s';
253
+            break;
254
+        case 'right_space':
255
+            $format = '%2$s&nbsp;%1$s';
256
+            break;
257
+    }
258
+
259
+    return apply_filters( 'getpaid_price_format', $format, $currency_pos );
260 260
 }
261 261
 
262 262
 /**
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
  * @param mixed  $value Value.
360 360
  */
361 361
 function getpaid_maybe_define_constant( $name, $value ) {
362
-	if ( ! defined( $name ) ) {
363
-		define( $name, $value );
364
-	}
362
+    if ( ! defined( $name ) ) {
363
+        define( $name, $value );
364
+    }
365 365
 }
366 366
 
367 367
 function wpinv_get_php_arg_separator_output() {
368
-	return ini_get( 'arg_separator.output' );
368
+    return ini_get( 'arg_separator.output' );
369 369
 }
370 370
 
371 371
 function wpinv_rgb_from_hex( $color ) {
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
         $list = array();
717 717
     }
718 718
 
719
-	if ( ! is_array( $list ) ) {
720
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
721
-	}
719
+    if ( ! is_array( $list ) ) {
720
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
721
+    }
722 722
 
723
-	return $list;
723
+    return $list;
724 724
 }
725 725
 
726 726
 /**
@@ -740,9 +740,9 @@  discard block
 block discarded – undo
740 740
     }
741 741
 
742 742
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
743
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
743
+    wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
744 744
 
745
-	return $data;
745
+    return $data;
746 746
 }
747 747
 
748 748
 /**
@@ -771,17 +771,17 @@  discard block
 block discarded – undo
771 771
  */
772 772
 function wpinv_clean( $var ) {
773 773
 
774
-	if ( is_array( $var ) ) {
775
-		return array_map( 'wpinv_clean', $var );
774
+    if ( is_array( $var ) ) {
775
+        return array_map( 'wpinv_clean', $var );
776 776
     }
777 777
 
778 778
     if ( is_object( $var ) ) {
779
-		$object_vars = get_object_vars( $var );
780
-		foreach ( $object_vars as $property_name => $property_value ) {
781
-			$var->$property_name = wpinv_clean( $property_value );
779
+        $object_vars = get_object_vars( $var );
780
+        foreach ( $object_vars as $property_name => $property_value ) {
781
+            $var->$property_name = wpinv_clean( $property_value );
782 782
         }
783 783
         return $var;
784
-	}
784
+    }
785 785
     
786 786
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
787 787
 }
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  */
795 795
 function getpaid_convert_price_string_to_options( $str ) {
796 796
 
797
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
797
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
798 798
     $options     = array();
799 799
 
800 800
     foreach ( $raw_options as $option ) {
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
  * @return string
873 873
  */
874 874
 function getpaid_date_format() {
875
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
875
+    return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
876 876
 }
877 877
 
878 878
 /**
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
  * @return string
882 882
  */
883 883
 function getpaid_time_format() {
884
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
884
+    return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
885 885
 }
886 886
 
887 887
 /**
@@ -894,15 +894,15 @@  discard block
 block discarded – undo
894 894
 function getpaid_limit_length( $string, $limit ) {
895 895
     $str_limit = $limit - 3;
896 896
 
897
-	if ( function_exists( 'mb_strimwidth' ) ) {
898
-		if ( mb_strlen( $string ) > $limit ) {
899
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
900
-		}
901
-	} else {
902
-		if ( strlen( $string ) > $limit ) {
903
-			$string = substr( $string, 0, $str_limit ) . '...';
904
-		}
905
-	}
897
+    if ( function_exists( 'mb_strimwidth' ) ) {
898
+        if ( mb_strlen( $string ) > $limit ) {
899
+            $string = mb_strimwidth( $string, 0, $str_limit ) . '...';
900
+        }
901
+    } else {
902
+        if ( strlen( $string ) > $limit ) {
903
+            $string = substr( $string, 0, $str_limit ) . '...';
904
+        }
905
+    }
906 906
     return $string;
907 907
 
908 908
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -12,224 +12,224 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-
42
-	}
43
-
44
-	/**
45
-	 * Adds totals to a response for submission refresh prices.
46
-	 *
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function add_totals( $submission ) {
50
-
51
-		$this->response = array_merge(
52
-			$this->response,
53
-			array(
54
-
55
-				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
61
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
-				),
63
-
64
-				'recurring'     => array(
65
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
-				),
71
-
72
-			)
73
-		);
74
-
75
-	}
76
-
77
-	/**
78
-	 * Adds texts to a response for submission refresh prices.
79
-	 *
80
-	 * @param GetPaid_Payment_Form_Submission $submission
81
-	 */
82
-	public function add_texts( $submission ) {
83
-
84
-		$payable = $submission->format_amount( $submission->get_total() );
85
-
86
-		if ( $submission->has_recurring != 0 ) {
87
-
88
-			$recurring = new WPInv_Item( $submission->has_recurring );
89
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
-
91
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
-				$payable = "$payable / $period";
93
-			} else {
94
-				$payable = sprintf(
95
-					__( '%1$s (renews at %2$s / %3$s)'),
96
-					$submission->format_amount( $submission->get_total() ),
97
-					$submission->format_amount( $submission->get_recurring_total() ),
98
-					$period
99
-				);
100
-			}
101
-
102
-		}
103
-
104
-		$texts = array(
105
-			'.getpaid-checkout-total-payable' => $payable,
106
-		);
107
-
108
-		foreach ( $submission->get_items() as $item_id => $item ) {
109
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
-		}
112
-
113
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
114
-
115
-	}
116
-
117
-	/**
118
-	 * Adds items to a response for submission refresh prices.
119
-	 *
120
-	 * @param GetPaid_Payment_Form_Submission $submission
121
-	 */
122
-	public function add_items( $submission ) {
123
-
124
-		// Add items.
125
-		$items = array();
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+
42
+    }
43
+
44
+    /**
45
+     * Adds totals to a response for submission refresh prices.
46
+     *
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function add_totals( $submission ) {
50
+
51
+        $this->response = array_merge(
52
+            $this->response,
53
+            array(
54
+
55
+                'totals'        => array(
56
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
58
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
59
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
60
+                    'total'     => $submission->format_amount( $submission->get_total() ),
61
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
+                ),
63
+
64
+                'recurring'     => array(
65
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
+                ),
71
+
72
+            )
73
+        );
74
+
75
+    }
76
+
77
+    /**
78
+     * Adds texts to a response for submission refresh prices.
79
+     *
80
+     * @param GetPaid_Payment_Form_Submission $submission
81
+     */
82
+    public function add_texts( $submission ) {
83
+
84
+        $payable = $submission->format_amount( $submission->get_total() );
85
+
86
+        if ( $submission->has_recurring != 0 ) {
87
+
88
+            $recurring = new WPInv_Item( $submission->has_recurring );
89
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
+
91
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
+                $payable = "$payable / $period";
93
+            } else {
94
+                $payable = sprintf(
95
+                    __( '%1$s (renews at %2$s / %3$s)'),
96
+                    $submission->format_amount( $submission->get_total() ),
97
+                    $submission->format_amount( $submission->get_recurring_total() ),
98
+                    $period
99
+                );
100
+            }
101
+
102
+        }
103
+
104
+        $texts = array(
105
+            '.getpaid-checkout-total-payable' => $payable,
106
+        );
126 107
 
127 108
         foreach ( $submission->get_items() as $item_id => $item ) {
128
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
-		}
109
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
+        }
130 112
 
131
-		$this->response = array_merge(
132
-			$this->response,
133
-			array( 'items' => $items )
134
-		);
113
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
135 114
 
136
-	}
115
+    }
137 116
 
138
-	/**
139
-	 * Adds fees to a response for submission refresh prices.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 */
143
-	public function add_fees( $submission ) {
117
+    /**
118
+     * Adds items to a response for submission refresh prices.
119
+     *
120
+     * @param GetPaid_Payment_Form_Submission $submission
121
+     */
122
+    public function add_items( $submission ) {
123
+
124
+        // Add items.
125
+        $items = array();
126
+
127
+        foreach ( $submission->get_items() as $item_id => $item ) {
128
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
+        }
130
+
131
+        $this->response = array_merge(
132
+            $this->response,
133
+            array( 'items' => $items )
134
+        );
135
+
136
+    }
144 137
 
145
-		$fees = array();
138
+    /**
139
+     * Adds fees to a response for submission refresh prices.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     */
143
+    public function add_fees( $submission ) {
144
+
145
+        $fees = array();
146 146
 
147 147
         foreach ( $submission->get_fees() as $name => $data ) {
148
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
-		}
148
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
+        }
150 150
 
151
-		$this->response = array_merge(
152
-			$this->response,
153
-			array( 'fees' => $fees )
154
-		);
151
+        $this->response = array_merge(
152
+            $this->response,
153
+            array( 'fees' => $fees )
154
+        );
155 155
 
156
-	}
156
+    }
157 157
 
158
-	/**
159
-	 * Adds discounts to a response for submission refresh prices.
160
-	 *
161
-	 * @param GetPaid_Payment_Form_Submission $submission
162
-	 */
163
-	public function add_discounts( $submission ) {
158
+    /**
159
+     * Adds discounts to a response for submission refresh prices.
160
+     *
161
+     * @param GetPaid_Payment_Form_Submission $submission
162
+     */
163
+    public function add_discounts( $submission ) {
164 164
 
165
-		$discounts = array();
165
+        $discounts = array();
166 166
 
167 167
         foreach ( $submission->get_discounts() as $name => $data ) {
168
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
-		}
168
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
+        }
170 170
 
171
-		$this->response = array_merge(
172
-			$this->response,
173
-			array( 'discounts' => $discounts )
174
-		);
171
+        $this->response = array_merge(
172
+            $this->response,
173
+            array( 'discounts' => $discounts )
174
+        );
175 175
 
176
-	}
176
+    }
177 177
 
178
-	/**
179
-	 * Adds taxes to a response for submission refresh prices.
180
-	 *
181
-	 * @param GetPaid_Payment_Form_Submission $submission
182
-	 */
183
-	public function add_taxes( $submission ) {
184
-
185
-		$taxes  = array();
186
-		$markup = '';
178
+    /**
179
+     * Adds taxes to a response for submission refresh prices.
180
+     *
181
+     * @param GetPaid_Payment_Form_Submission $submission
182
+     */
183
+    public function add_taxes( $submission ) {
184
+
185
+        $taxes  = array();
186
+        $markup = '';
187 187
         foreach ( $submission->get_taxes() as $name => $data ) {
188
-			$name          = sanitize_text_field( $name );
189
-			$amount        = $submission->format_amount( $data['initial_tax'] );
190
-			$taxes[$name]  = $amount;
191
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
192
-		}
188
+            $name          = sanitize_text_field( $name );
189
+            $amount        = $submission->format_amount( $data['initial_tax'] );
190
+            $taxes[$name]  = $amount;
191
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
192
+        }
193 193
 
194
-		if ( wpinv_display_individual_tax_rates() ) {
195
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
196
-		}
194
+        if ( wpinv_display_individual_tax_rates() ) {
195
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
196
+        }
197 197
 
198
-		$this->response = array_merge(
199
-			$this->response,
200
-			array( 'taxes' => $taxes )
201
-		);
198
+        $this->response = array_merge(
199
+            $this->response,
200
+            array( 'taxes' => $taxes )
201
+        );
202 202
 
203
-	}
203
+    }
204 204
 
205
-	/**
206
-	 * Adds gateways to a response for submission refresh prices.
207
-	 *
208
-	 * @param GetPaid_Payment_Form_Submission $submission
209
-	 */
210
-	public function add_gateways( $submission ) {
205
+    /**
206
+     * Adds gateways to a response for submission refresh prices.
207
+     *
208
+     * @param GetPaid_Payment_Form_Submission $submission
209
+     */
210
+    public function add_gateways( $submission ) {
211 211
 
212
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
212
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
213 213
 
214
-		if ( $this->response['has_recurring'] ) {
214
+        if ( $this->response['has_recurring'] ) {
215 215
 
216
-			foreach ( $gateways as $i => $gateway ) {
216
+            foreach ( $gateways as $i => $gateway ) {
217 217
 
218
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
219
-					unset( $gateways[ $i ] );
220
-				}
218
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
219
+                    unset( $gateways[ $i ] );
220
+                }
221 221
 
222
-			}
222
+            }
223 223
 
224
-		}
224
+        }
225 225
 
226 226
 
227
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
228
-		$this->response = array_merge(
229
-			$this->response,
230
-			array( 'gateways' => $gateways )
231
-		);
227
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
228
+        $this->response = array_merge(
229
+            $this->response,
230
+            array( 'gateways' => $gateways )
231
+        );
232 232
 
233
-	}
233
+    }
234 234
 
235 235
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-invoice-exporter.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -12,194 +12,194 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * Retrieves invoices query args.
17
-	 * 
18
-	 * @param string $post_type post type to retrieve.
19
-	 * @param array $args Args to search for.
20
-	 * @return array
21
-	 */
22
-	public function get_invoice_query_args( $post_type, $args ) {
23
-
24
-		$query_args = array(
25
-			'post_type'              => $post_type,
26
-			'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
-			'posts_per_page'         => -1,
28
-			'no_found_rows'          => true,
29
-			'update_post_term_cache' => false,
30
-			'fields'                 => 'ids',
31
-		);
32
-
33
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
-			$query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
-		}
36
-
37
-		$date_query = array();
38
-		if ( ! empty( $args['to_date'] ) ) {
39
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
40
-		}
41
-
42
-		if ( ! empty( $args['from_date'] ) ) {
43
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
44
-		}
45
-
46
-		if ( ! empty( $date_query ) ) {
47
-			$date_query['inclusive']  = true;
48
-			$query_args['date_query'] = array( $date_query );
49
-		}
50
-
51
-		return $query_args;
52
-	}
53
-
54
-	/**
55
-	 * Retrieves invoices.
56
-	 * 
57
-	 * @param array $query_args WP_Query args.
58
-	 * @return WPInv_Invoice[]
59
-	 */
60
-	public function get_invoices( $query_args ) {
61
-
62
-		// Get invoices.
63
-		$invoices = new WP_Query( $query_args );
64
-
65
-		// Prepare the results.
66
-		return array_map( 'wpinv_get_invoice', $invoices->posts );
67
-
68
-	}
69
-
70
-	/**
71
-	 * Handles the actual download.
72
-	 *
73
-	 */
74
-	public function export( $post_type, $args ) {
75
-
76
-		$invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
-		$stream    = $this->prepare_output();
78
-		$headers   = $this->get_export_fields( $post_type );
79
-		$file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
-
81
-		if ( 'csv' == $file_type ) {
82
-			$this->download_csv( $invoices, $stream, $headers );
83
-		} else if( 'xml' == $file_type ) {
84
-			$this->download_xml( $invoices, $stream, $headers );
85
-		} else {
86
-			$this->download_json( $invoices, $stream, $headers );
87
-		}
88
-
89
-		fclose( $stream );
90
-		exit;
91
-	}
92
-
93
-	/**
94
-	 * Prepares a single invoice for download.
95
-	 *
96
-	 * @param WPInv_Invoice $invoice The invoice to prepare..
97
-	 * @param array $fields The fields to stream.
98
-	 * @since       1.0.19
99
-	 * @return array
100
-	 */
101
-	public function prepare_row( $invoice, $fields ) {
102
-
103
-		$prepared      = array();
104
-		$amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
-
106
-		foreach ( $fields as $field ) {
107
-
108
-			$value  = '';
109
-			$method = "get_$field";
110
-
111
-			if ( method_exists( $invoice, $method ) ) {
112
-				$value  = $invoice->$method();
113
-			}
114
-
115
-			if ( in_array( $field, $amount_fields ) ) {
116
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
117
-			}
118
-
119
-			$prepared[ $field ] = wpinv_clean( $value );
120
-
121
-		}
122
-
123
-		return $prepared;
124
-	}
125
-
126
-	/**
127
-	 * Retrieves export fields.
128
-	 *
129
-	 * @param string $post_type
130
-	 * @since       1.0.19
131
-	 * @return array
132
-	 */
133
-	public function get_export_fields( $post_type ) {
134
-
135
-		$fields = array(
136
-			'id',
137
-			'parent_id',
138
-			'status',
139
-			'date_created',
140
-			'date_modified',
141
-			'date_due',
142
-			'date_completed',
143
-			'number',
144
-			'key',
145
-			'description',
146
-			'post_type',
147
-			'mode',
148
-			'customer_id',
149
-			'customer_first_name',
150
-			'customer_last_name',
151
-			'customer_phone',
152
-			'customer_email',
153
-			'customer_country',
154
-			'customer_city',
155
-			'customer_state',
156
-			'customer_zip',
157
-			'customer_company',
158
-			'customer_vat_number',
159
-			'customer_address',
160
-			'subtotal',
161
-			'total_discount',
162
-			'total_tax',
163
-			'total_fees',
164
-			'fees',
165
-			'discounts',
166
-			'taxes',
167
-			'cart_details',
168
-			'item_ids',
169
-			'payment_form',
170
-			'discount_code',
171
-			'gateway',
172
-			'transaction_id',
173
-			'currency',
174
-			'disable_taxes',
175
-			'subscription_id',
176
-			'remote_subscription_id',
177
-			'is_viewed',
178
-			'email_cc',
179
-			'template',
180
-			'created_via'
181
-    	);
182
-
183
-		return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
184
-	}
185
-
186
-	/**
187
-	 * Retrieves amount fields.
188
-	 *
189
-	 * @param string $post_type
190
-	 * @since       1.0.19
191
-	 * @return array
192
-	 */
193
-	public function get_amount_fields( $post_type ) {
194
-
195
-		$fields = array(
196
-			'subtotal',
197
-			'total_discount',
198
-			'total_tax',
199
-			'total_fees'
200
-    	);
201
-
202
-		return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
203
-	}
15
+    /**
16
+     * Retrieves invoices query args.
17
+     * 
18
+     * @param string $post_type post type to retrieve.
19
+     * @param array $args Args to search for.
20
+     * @return array
21
+     */
22
+    public function get_invoice_query_args( $post_type, $args ) {
23
+
24
+        $query_args = array(
25
+            'post_type'              => $post_type,
26
+            'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
+            'posts_per_page'         => -1,
28
+            'no_found_rows'          => true,
29
+            'update_post_term_cache' => false,
30
+            'fields'                 => 'ids',
31
+        );
32
+
33
+        if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
+            $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
+        }
36
+
37
+        $date_query = array();
38
+        if ( ! empty( $args['to_date'] ) ) {
39
+            $date_query['before'] = wpinv_clean( $args['to_date'] );
40
+        }
41
+
42
+        if ( ! empty( $args['from_date'] ) ) {
43
+            $date_query['after'] = wpinv_clean( $args['from_date'] );
44
+        }
45
+
46
+        if ( ! empty( $date_query ) ) {
47
+            $date_query['inclusive']  = true;
48
+            $query_args['date_query'] = array( $date_query );
49
+        }
50
+
51
+        return $query_args;
52
+    }
53
+
54
+    /**
55
+     * Retrieves invoices.
56
+     * 
57
+     * @param array $query_args WP_Query args.
58
+     * @return WPInv_Invoice[]
59
+     */
60
+    public function get_invoices( $query_args ) {
61
+
62
+        // Get invoices.
63
+        $invoices = new WP_Query( $query_args );
64
+
65
+        // Prepare the results.
66
+        return array_map( 'wpinv_get_invoice', $invoices->posts );
67
+
68
+    }
69
+
70
+    /**
71
+     * Handles the actual download.
72
+     *
73
+     */
74
+    public function export( $post_type, $args ) {
75
+
76
+        $invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
+        $stream    = $this->prepare_output();
78
+        $headers   = $this->get_export_fields( $post_type );
79
+        $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
+
81
+        if ( 'csv' == $file_type ) {
82
+            $this->download_csv( $invoices, $stream, $headers );
83
+        } else if( 'xml' == $file_type ) {
84
+            $this->download_xml( $invoices, $stream, $headers );
85
+        } else {
86
+            $this->download_json( $invoices, $stream, $headers );
87
+        }
88
+
89
+        fclose( $stream );
90
+        exit;
91
+    }
92
+
93
+    /**
94
+     * Prepares a single invoice for download.
95
+     *
96
+     * @param WPInv_Invoice $invoice The invoice to prepare..
97
+     * @param array $fields The fields to stream.
98
+     * @since       1.0.19
99
+     * @return array
100
+     */
101
+    public function prepare_row( $invoice, $fields ) {
102
+
103
+        $prepared      = array();
104
+        $amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
+
106
+        foreach ( $fields as $field ) {
107
+
108
+            $value  = '';
109
+            $method = "get_$field";
110
+
111
+            if ( method_exists( $invoice, $method ) ) {
112
+                $value  = $invoice->$method();
113
+            }
114
+
115
+            if ( in_array( $field, $amount_fields ) ) {
116
+                $value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
117
+            }
118
+
119
+            $prepared[ $field ] = wpinv_clean( $value );
120
+
121
+        }
122
+
123
+        return $prepared;
124
+    }
125
+
126
+    /**
127
+     * Retrieves export fields.
128
+     *
129
+     * @param string $post_type
130
+     * @since       1.0.19
131
+     * @return array
132
+     */
133
+    public function get_export_fields( $post_type ) {
134
+
135
+        $fields = array(
136
+            'id',
137
+            'parent_id',
138
+            'status',
139
+            'date_created',
140
+            'date_modified',
141
+            'date_due',
142
+            'date_completed',
143
+            'number',
144
+            'key',
145
+            'description',
146
+            'post_type',
147
+            'mode',
148
+            'customer_id',
149
+            'customer_first_name',
150
+            'customer_last_name',
151
+            'customer_phone',
152
+            'customer_email',
153
+            'customer_country',
154
+            'customer_city',
155
+            'customer_state',
156
+            'customer_zip',
157
+            'customer_company',
158
+            'customer_vat_number',
159
+            'customer_address',
160
+            'subtotal',
161
+            'total_discount',
162
+            'total_tax',
163
+            'total_fees',
164
+            'fees',
165
+            'discounts',
166
+            'taxes',
167
+            'cart_details',
168
+            'item_ids',
169
+            'payment_form',
170
+            'discount_code',
171
+            'gateway',
172
+            'transaction_id',
173
+            'currency',
174
+            'disable_taxes',
175
+            'subscription_id',
176
+            'remote_subscription_id',
177
+            'is_viewed',
178
+            'email_cc',
179
+            'template',
180
+            'created_via'
181
+        );
182
+
183
+        return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
184
+    }
185
+
186
+    /**
187
+     * Retrieves amount fields.
188
+     *
189
+     * @param string $post_type
190
+     * @since       1.0.19
191
+     * @return array
192
+     */
193
+    public function get_amount_fields( $post_type ) {
194
+
195
+        $fields = array(
196
+            'subtotal',
197
+            'total_discount',
198
+            'total_tax',
199
+            'total_fees'
200
+        );
201
+
202
+        return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
203
+    }
204 204
 
205 205
 }
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,168 +13,168 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-					'country'   => wpinv_get_default_country(),
115
-					'state'     => wpinv_get_default_state(),
116
-					'global'    => true,
117
-					'rate'      => wpinv_get_default_tax_rate(),
118
-					'name'      => __( 'Base Tax', 'invoicing' ),
119
-				)
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of tax rates for a given address.
127
-	 *
128
-	 * @param string $country
129
-	 * @param string $state
130
-	 * @return array
131
-	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
133
-
134
-		$all_tax_rates  = self::get_all_tax_rates();
135
-		$matching_rates = array_merge(
136
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
-		);
139
-
140
-		foreach ( $matching_rates as $i => $rate ) {
141
-
142
-			$states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) );
143
-			if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) {
144
-				unset( $matching_rates[ $i ] );
145
-			}
146
-
147
-		}
148
-
149
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
-
151
-	}
152
-
153
-	/**
154
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
155
-	 *
156
-	 * @param  array $taxes Array of taxes.
157
-	 * @return float
158
-	 */
159
-	public static function get_tax_total( $taxes ) {
160
-		return self::round( array_sum( $taxes ) );
161
-	}
162
-
163
-	/**
164
-	 * Round to precision.
165
-	 *
166
-	 * Filter example: to return rounding to .5 cents you'd use:
167
-	 *
168
-	 * function euro_5cent_rounding( $in ) {
169
-	 *      return round( $in / 5, 2 ) * 5;
170
-	 * }
171
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
-	 *
173
-	 * @param float|int $in Value to round.
174
-	 * @return float
175
-	 */
176
-	public static function round( $in ) {
177
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
-	}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                    'country'   => wpinv_get_default_country(),
115
+                    'state'     => wpinv_get_default_state(),
116
+                    'global'    => true,
117
+                    'rate'      => wpinv_get_default_tax_rate(),
118
+                    'name'      => __( 'Base Tax', 'invoicing' ),
119
+                )
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of tax rates for a given address.
127
+     *
128
+     * @param string $country
129
+     * @param string $state
130
+     * @return array
131
+     */
132
+    public static function get_address_tax_rates( $country, $state ) {
133
+
134
+        $all_tax_rates  = self::get_all_tax_rates();
135
+        $matching_rates = array_merge(
136
+            wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
+            wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
+        );
139
+
140
+        foreach ( $matching_rates as $i => $rate ) {
141
+
142
+            $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) );
143
+            if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) {
144
+                unset( $matching_rates[ $i ] );
145
+            }
146
+
147
+        }
148
+
149
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
+
151
+    }
152
+
153
+    /**
154
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
155
+     *
156
+     * @param  array $taxes Array of taxes.
157
+     * @return float
158
+     */
159
+    public static function get_tax_total( $taxes ) {
160
+        return self::round( array_sum( $taxes ) );
161
+    }
162
+
163
+    /**
164
+     * Round to precision.
165
+     *
166
+     * Filter example: to return rounding to .5 cents you'd use:
167
+     *
168
+     * function euro_5cent_rounding( $in ) {
169
+     *      return round( $in / 5, 2 ) * 5;
170
+     * }
171
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
+     *
173
+     * @param float|int $in Value to round.
174
+     * @return float
175
+     */
176
+    public static function round( $in ) {
177
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
+    }
179 179
 
180 180
 }
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
215 215
 function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) {
216 216
 
217 217
     $initial_tax   = $tax_amount;
218
-	$recurring_tax = 0;
218
+    $recurring_tax = 0;
219 219
 
220 220
     if ( $item->is_recurring() ) {
221
-		$recurring_tax = $recurring_tax_amount;
222
-	}
221
+        $recurring_tax = $recurring_tax_amount;
222
+    }
223 223
 
224
-	return array(
225
-		'name'          => sanitize_text_field( $tax_name ),
226
-		'initial_tax'   => $initial_tax,
227
-		'recurring_tax' => $recurring_tax,
224
+    return array(
225
+        'name'          => sanitize_text_field( $tax_name ),
226
+        'initial_tax'   => $initial_tax,
227
+        'recurring_tax' => $recurring_tax,
228 228
     );
229 229
 
230 230
 }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
  */
329 329
 function wpinv_should_validate_vat_number() {
330 330
     $validate = wpinv_get_option( 'validate_vat_number' );
331
-	return ! empty( $validate );
331
+    return ! empty( $validate );
332 332
 }
333 333
 
334 334
 function wpinv_sales_tax_for_year( $year = null ) {
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-vat.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_VAT {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Output the VAT rules settings.
50
-	 *
51
-	 * @param WPInv_Item $item
52
-	 */
49
+     * Output the VAT rules settings.
50
+     *
51
+     * @param WPInv_Item $item
52
+     */
53 53
     public static function output_vat_rules( $item ) {
54 54
         ?>
55 55
 
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
     }
88 88
 
89 89
     /**
90
-	 * Output the VAT class settings.
91
-	 *
92
-	 * @param WPInv_Item $item
93
-	 */
90
+     * Output the VAT class settings.
91
+     *
92
+     * @param WPInv_Item $item
93
+     */
94 94
     public static function output_vat_classes( $item ) {
95 95
         ?>
96 96
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -12,267 +12,267 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
39 21
 
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
47 26
 
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
50 29
 
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
53 32
 
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
58 35
 
59
-	}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
60 39
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
65 44
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
68 47
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
71 50
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
74 53
 
75
-		}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
76 58
 
77
-	}
59
+    }
78 60
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
83 65
 
84
-		if ( $post_type == 'wpi_item' ) {
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
85 68
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
88 71
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
93 74
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
75
+        }
96 76
 
97
-		}
77
+    }
98 78
 
99
-	}
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
100 83
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
84
+        if ( $post_type == 'wpi_item' ) {
105 85
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
109 88
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
112 93
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
124 96
 
125
-			}
97
+        }
126 98
 
127
-			// Subscriptions.
128
-			$subscription = getpaid_get_invoice_subscription( $invoice );
129
-			if ( ! empty( $subscription ) ) {
130
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
-			}
133
-
134
-			// Invoice details.
135
-			add_meta_box(
136
-				'wpinv-details',
137
-				sprintf(
138
-					__( '%s Details', 'invoicing' ),
139
-					ucfirst( $invoice->get_invoice_quote_type() )
140
-				),
141
-				'GetPaid_Meta_Box_Invoice_Details::output',
142
-				$post_type,
143
-				'side'
144
-			);
145
-
146
-			// Payment details.
147
-			if ( ! $invoice->is_draft() ) {
148
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
-			}
99
+    }
150 100
 
151
-			// Billing details.
152
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscription = getpaid_get_invoice_subscription( $invoice );
129
+            if ( ! empty( $subscription ) ) {
130
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
+            }
133
+
134
+            // Invoice details.
135
+            add_meta_box(
136
+                'wpinv-details',
137
+                sprintf(
138
+                    __( '%s Details', 'invoicing' ),
139
+                    ucfirst( $invoice->get_invoice_quote_type() )
140
+                ),
141
+                'GetPaid_Meta_Box_Invoice_Details::output',
142
+                $post_type,
143
+                'side'
144
+            );
145
+
146
+            // Payment details.
147
+            if ( ! $invoice->is_draft() ) {
148
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
+            }
150
+
151
+            // Billing details.
152
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
153 153
 			
154
-			// Invoice items.
155
-			add_meta_box(
156
-				'wpinv-items',
157
-				sprintf(
158
-					__( '%s Items', 'invoicing' ),
159
-					ucfirst( $invoice->get_invoice_quote_type() )
160
-				),
161
-				'GetPaid_Meta_Box_Invoice_Items::output',
162
-				$post_type,
163
-				'normal',
164
-				'high'
165
-			);
154
+            // Invoice items.
155
+            add_meta_box(
156
+                'wpinv-items',
157
+                sprintf(
158
+                    __( '%s Items', 'invoicing' ),
159
+                    ucfirst( $invoice->get_invoice_quote_type() )
160
+                ),
161
+                'GetPaid_Meta_Box_Invoice_Items::output',
162
+                $post_type,
163
+                'normal',
164
+                'high'
165
+            );
166 166
 			
167
-			// Invoice notes.
168
-			add_meta_box(
169
-				'wpinv-notes',
170
-				sprintf(
171
-					__( '%s Notes', 'invoicing' ),
172
-					ucfirst( $invoice->get_invoice_quote_type() )
173
-				),
174
-				'WPInv_Meta_Box_Notes::output',
175
-				$post_type,
176
-				'side',
177
-				'low'
178
-			);
179
-
180
-			// Shipping Address.
181
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
-			}
184
-
185
-			// Payment form information.
186
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
-			}
189
-
190
-		}
191
-
192
-	}
193
-
194
-	/**
195
-	 * Remove some metaboxes.
196
-	 */
197
-	public static function remove_meta_boxes() {
198
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
-	}
200
-
201
-	/**
202
-	 * Rename other metaboxes.
203
-	 */
204
-	public static function rename_meta_boxes() {
167
+            // Invoice notes.
168
+            add_meta_box(
169
+                'wpinv-notes',
170
+                sprintf(
171
+                    __( '%s Notes', 'invoicing' ),
172
+                    ucfirst( $invoice->get_invoice_quote_type() )
173
+                ),
174
+                'WPInv_Meta_Box_Notes::output',
175
+                $post_type,
176
+                'side',
177
+                'low'
178
+            );
179
+
180
+            // Shipping Address.
181
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
+            }
184
+
185
+            // Payment form information.
186
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
+            }
189
+
190
+        }
191
+
192
+    }
193
+
194
+    /**
195
+     * Remove some metaboxes.
196
+     */
197
+    public static function remove_meta_boxes() {
198
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
+    }
200
+
201
+    /**
202
+     * Rename other metaboxes.
203
+     */
204
+    public static function rename_meta_boxes() {
205 205
 		
206
-	}
207
-
208
-	/**
209
-	 * Check if we're saving, then trigger an action based on the post type.
210
-	 *
211
-	 * @param  int    $post_id Post ID.
212
-	 * @param  object $post Post object.
213
-	 */
214
-	public static function save_meta_boxes( $post_id, $post ) {
215
-		$post_id = absint( $post_id );
216
-		$data    = wp_unslash( $_POST );
217
-
218
-		// Do not save for ajax requests.
219
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
-			return;
221
-		}
222
-
223
-		// $post_id and $post are required
224
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
-			return;
226
-		}
227
-
228
-		// Dont' save meta boxes for revisions or autosaves.
229
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
-			return;
231
-		}
232
-
233
-		// Check the nonce.
234
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
-			return;
236
-		}
237
-
238
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
-			return;
241
-		}
242
-
243
-		// Check user has permission to edit.
244
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
-			return;
246
-		}
247
-
248
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
-
250
-			// We need this save event to run once to avoid potential endless loops.
251
-			self::$saved_meta_boxes = true;
252
-
253
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
-
255
-		}
256
-
257
-		// Ensure this is our post type.
258
-		$post_types_map = array(
259
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
-		);
263
-
264
-		// Is this our post type?
265
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
-			return;
267
-		}
268
-
269
-		// We need this save event to run once to avoid potential endless loops.
270
-		self::$saved_meta_boxes = true;
206
+    }
207
+
208
+    /**
209
+     * Check if we're saving, then trigger an action based on the post type.
210
+     *
211
+     * @param  int    $post_id Post ID.
212
+     * @param  object $post Post object.
213
+     */
214
+    public static function save_meta_boxes( $post_id, $post ) {
215
+        $post_id = absint( $post_id );
216
+        $data    = wp_unslash( $_POST );
217
+
218
+        // Do not save for ajax requests.
219
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
+            return;
221
+        }
222
+
223
+        // $post_id and $post are required
224
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
+            return;
226
+        }
227
+
228
+        // Dont' save meta boxes for revisions or autosaves.
229
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
+            return;
231
+        }
232
+
233
+        // Check the nonce.
234
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
+            return;
236
+        }
237
+
238
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
+            return;
241
+        }
242
+
243
+        // Check user has permission to edit.
244
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
+            return;
246
+        }
247
+
248
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
+
250
+            // We need this save event to run once to avoid potential endless loops.
251
+            self::$saved_meta_boxes = true;
252
+
253
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
+
255
+        }
256
+
257
+        // Ensure this is our post type.
258
+        $post_types_map = array(
259
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
+        );
263
+
264
+        // Is this our post type?
265
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
+            return;
267
+        }
268
+
269
+        // We need this save event to run once to avoid potential endless loops.
270
+        self::$saved_meta_boxes = true;
271 271
 		
272
-		// Save the post.
273
-		$class = $post_types_map[ $post->post_type ];
274
-		$class::save( $post_id, $_POST, $post );
272
+        // Save the post.
273
+        $class = $post_types_map[ $post->post_type ];
274
+        $class::save( $post_id, $_POST, $post );
275 275
 
276
-	}
276
+    }
277 277
 
278 278
 }
Please login to merge, or discard this patch.