Passed
Push — master ( eadd35...968588 )
by Brian
04:42
created
includes/reports/class-getpaid-reports-export.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo "</div>";
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo "</div>";
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								__( 'Export %s', 'invoicing' ),
65
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                __( 'Export %s', 'invoicing' ),
65
+                                sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
78
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
79
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,122 +89,122 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		return aui()->input(
101
-			array(
102
-				'name'       => 'from_date',
103
-				'id'         => esc_attr( "$post_type-from_date" ),
104
-				'placeholder'=> 'yy-mm-dd',
105
-				'label'      => __( 'From Date', 'invoicing' ),
106
-				'label_type' => 'vertical',
107
-				'label_class' => 'd-block',
108
-				'type'       => 'datepicker',
109
-			)
110
-		);
111
-
112
-	}
113
-
114
-	/**
115
-	 * Generates the to date input field.
116
-	 *
117
-	 */
118
-	public function generate_to_date( $post_type ) {
119
-
120
-		return aui()->input(
121
-			array(
122
-				'name'       => 'to_date',
123
-				'id'         => esc_attr( "$post_type-to_date" ),
124
-				'placeholder'=> 'yy-mm-dd',
125
-				'label'      => __( 'To Date', 'invoicing' ),
126
-				'label_type' => 'vertical',
127
-				'label_class' => 'd-block',
128
-				'type'       => 'datepicker',
129
-			)
130
-		);
131
-
132
-	}
133
-
134
-	/**
135
-	 * Generates the to post status select field.
136
-	 *
137
-	 */
138
-	public function generate_post_status_select( $post_type ) {
139
-
140
-		if ( 'subscriptions' === $post_type ) {
141
-			$options = getpaid_get_subscription_statuses();
142
-		} else {
143
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
144
-		}
145
-
146
-		return aui()->select(
147
-			array(
148
-				'name'        => 'status',
149
-				'id'          => esc_attr( "$post_type-status" ),
150
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
151
-				'label'       => __( 'Status', 'invoicing' ),
152
-				'label_type'  => 'vertical',
153
-				'label_class' => 'd-block',
154
-				'options'     => $options,
155
-			)
156
-		);
157
-
158
-	}
159
-
160
-	/**
161
-	 * Generates the to file type select field.
162
-	 *
163
-	 */
164
-	public function generate_file_type_select( $post_type ) {
165
-
166
-		return aui()->select(
167
-			array(
168
-				'name'        => 'file_type',
169
-				'id'          => esc_attr( "$post_type-file_type" ),
170
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
171
-				'label'       => __( 'Export File', 'invoicing' ),
172
-				'label_type'  => 'vertical',
173
-				'label_class' => 'd-block',
174
-				'options'     => array(
175
-					'csv'  => __( 'CSV', 'invoicing' ),
176
-					'xml'  => __( 'XML', 'invoicing' ),
177
-					'json' => __( 'JSON', 'invoicing' ),
178
-				),
179
-			)
180
-		);
181
-
182
-	}
183
-
184
-	/**
185
-	 * Displays a field's markup.
186
-	 *
187
-	 */
188
-	public function display_markup( $markup ) {
189
-
190
-		echo str_replace(
191
-			array(
192
-				'form-control',
193
-				'custom-select'
194
-			),
195
-			'regular-text',
196
-			$markup
197
-		);
198
-
199
-	}
200
-
201
-	/**
202
-	 * Displays a subscription export card.
203
-	 *
204
-	 */
205
-	public function display_subscription_export() {
206
-
207
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        return aui()->input(
101
+            array(
102
+                'name'       => 'from_date',
103
+                'id'         => esc_attr( "$post_type-from_date" ),
104
+                'placeholder'=> 'yy-mm-dd',
105
+                'label'      => __( 'From Date', 'invoicing' ),
106
+                'label_type' => 'vertical',
107
+                'label_class' => 'd-block',
108
+                'type'       => 'datepicker',
109
+            )
110
+        );
111
+
112
+    }
113
+
114
+    /**
115
+     * Generates the to date input field.
116
+     *
117
+     */
118
+    public function generate_to_date( $post_type ) {
119
+
120
+        return aui()->input(
121
+            array(
122
+                'name'       => 'to_date',
123
+                'id'         => esc_attr( "$post_type-to_date" ),
124
+                'placeholder'=> 'yy-mm-dd',
125
+                'label'      => __( 'To Date', 'invoicing' ),
126
+                'label_type' => 'vertical',
127
+                'label_class' => 'd-block',
128
+                'type'       => 'datepicker',
129
+            )
130
+        );
131
+
132
+    }
133
+
134
+    /**
135
+     * Generates the to post status select field.
136
+     *
137
+     */
138
+    public function generate_post_status_select( $post_type ) {
139
+
140
+        if ( 'subscriptions' === $post_type ) {
141
+            $options = getpaid_get_subscription_statuses();
142
+        } else {
143
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
144
+        }
145
+
146
+        return aui()->select(
147
+            array(
148
+                'name'        => 'status',
149
+                'id'          => esc_attr( "$post_type-status" ),
150
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
151
+                'label'       => __( 'Status', 'invoicing' ),
152
+                'label_type'  => 'vertical',
153
+                'label_class' => 'd-block',
154
+                'options'     => $options,
155
+            )
156
+        );
157
+
158
+    }
159
+
160
+    /**
161
+     * Generates the to file type select field.
162
+     *
163
+     */
164
+    public function generate_file_type_select( $post_type ) {
165
+
166
+        return aui()->select(
167
+            array(
168
+                'name'        => 'file_type',
169
+                'id'          => esc_attr( "$post_type-file_type" ),
170
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
171
+                'label'       => __( 'Export File', 'invoicing' ),
172
+                'label_type'  => 'vertical',
173
+                'label_class' => 'd-block',
174
+                'options'     => array(
175
+                    'csv'  => __( 'CSV', 'invoicing' ),
176
+                    'xml'  => __( 'XML', 'invoicing' ),
177
+                    'json' => __( 'JSON', 'invoicing' ),
178
+                ),
179
+            )
180
+        );
181
+
182
+    }
183
+
184
+    /**
185
+     * Displays a field's markup.
186
+     *
187
+     */
188
+    public function display_markup( $markup ) {
189
+
190
+        echo str_replace(
191
+            array(
192
+                'form-control',
193
+                'custom-select'
194
+            ),
195
+            'regular-text',
196
+            $markup
197
+        );
198
+
199
+    }
200
+
201
+    /**
202
+     * Displays a subscription export card.
203
+     *
204
+     */
205
+    public function display_subscription_export() {
206
+
207
+        ?>
208 208
 
209 209
 		<div class="col-12 col-md-6">
210 210
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
221 221
 
222 222
 						<?php
223
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
-							submit_button( __( 'Download', 'invoicing' ) );
228
-						?>
223
+                            $this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
+                            $this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
+                            $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
+                            $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
+                            submit_button( __( 'Download', 'invoicing' ) );
228
+                        ?>
229 229
 
230 230
 					</form>
231 231
 
@@ -236,6 +236,6 @@  discard block
 block discarded – undo
236 236
 
237 237
 		<?php
238 238
 
239
-	}
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-subscription-exporter.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -12,177 +12,177 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * Retrieves subscription query args.
17
-	 * 
18
-	 * @param array $args Args to search for.
19
-	 * @return array
20
-	 */
21
-	public function get_subscription_query_args( $args ) {
22
-
23
-		$query_args = array(
24
-			'status'      => 'all',
25
-			'number'      => -1,
26
-			'count_total' => false,
27
-			'fields'      => 'all',
28
-		);
29
-
30
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) {
31
-			$query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
32
-		}
33
-
34
-		$date_query = array();
35
-		if ( ! empty( $args['to_date'] ) ) {
36
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
37
-		}
38
-
39
-		if ( ! empty( $args['from_date'] ) ) {
40
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
41
-		}
42
-
43
-		if ( ! empty( $date_query ) ) {
44
-			$date_query['inclusive']          = true;
45
-			$query_args['date_created_query'] = array( $date_query );
46
-		}
47
-
48
-		return $query_args;
49
-	}
50
-
51
-	/**
52
-	 * Retrieves subscriptions.
53
-	 * 
54
-	 * @param array $query_args GetPaid_Subscriptions_Query args.
55
-	 * @return WPInv_Subscription[]
56
-	 */
57
-	public function get_subscriptions( $query_args ) {
58
-
59
-		// Get subscriptions.
60
-		$subscriptions = new GetPaid_Subscriptions_Query( $query_args );
61
-
62
-		// Prepare the results.
63
-		return $subscriptions->get_results();
64
-
65
-	}
66
-
67
-	/**
68
-	 * Handles the actual download.
69
-	 *
70
-	 */
71
-	public function export( $post_type, $args ) {
72
-
73
-		$subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) );
74
-		$stream        = $this->prepare_output();
75
-		$headers       = $this->get_export_fields();
76
-		$file_type     = $this->prepare_file_type( 'subscriptions' );
77
-
78
-		if ( 'csv' == $file_type ) {
79
-			$this->download_csv( $subscriptions, $stream, $headers );
80
-		} else if( 'xml' == $file_type ) {
81
-			$this->download_xml( $subscriptions, $stream, $headers );
82
-		} else {
83
-			$this->download_json( $subscriptions, $stream, $headers );
84
-		}
85
-
86
-		fclose( $stream );
87
-		exit;
88
-	}
89
-
90
-	/**
91
-	 * Prepares a single subscription for download.
92
-	 *
93
-	 * @param WPInv_Subscription $subscription The subscription to prepare..
94
-	 * @param array $fields The fields to stream.
95
-	 * @since       1.0.19
96
-	 * @return array
97
-	 */
98
-	public function prepare_row( $subscription, $fields ) {
99
-
100
-		$prepared      = array();
101
-		$amount_fields = $this->get_amount_fields();
102
-		$invoice       = $subscription->get_parent_payment();
103
-
104
-		foreach ( $fields as $field ) {
105
-
106
-			$value  = '';
107
-			$method = "get_$field";
108
-
109
-			if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) {
110
-
111
-				if ( method_exists( $invoice, $method ) ) {
112
-					$value  = $invoice->$method();
113
-				}
114
-
115
-			} else if ( method_exists( $subscription, $method ) ) {
116
-				$value  = $subscription->$method();
117
-			}
118
-
119
-			if ( in_array( $field, $amount_fields ) ) {
120
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
121
-			}
122
-
123
-			$prepared[ $field ] = wpinv_clean( $value );
124
-
125
-		}
126
-
127
-		return $prepared;
128
-	}
129
-
130
-	/**
131
-	 * Retrieves export fields.
132
-	 *
133
-	 * @since       1.0.19
134
-	 * @return array
135
-	 */
136
-	public function get_export_fields() {
137
-
138
-		$fields = array(
139
-			'id',
140
-			'currency',
141
-			'initial_amount',
142
-			'recurring_amount',
143
-			'trial_period',
144
-			'frequency',
145
-			'period',
146
-			'bill_times',
147
-			'parent_payment_id',
148
-			'profile_id',
149
-			'product_id',
150
-			'status',
151
-			'date_created',
152
-			'date_expires',
153
-
154
-			'customer_id',
155
-			'customer_first_name',
156
-			'customer_last_name',
157
-			'customer_phone',
158
-			'customer_email',
159
-			'customer_country',
160
-			'customer_city',
161
-			'customer_state',
162
-			'customer_zip',
163
-			'customer_company',
164
-			'customer_vat_number',
165
-			'customer_address',
166
-
167
-    	);
168
-
169
-		return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields );
170
-	}
171
-
172
-	/**
173
-	 * Retrieves amount fields.
174
-	 *
175
-	 * @since       1.0.19
176
-	 * @return array
177
-	 */
178
-	public function get_amount_fields() {
179
-
180
-		$fields = array(
181
-			'initial_amount',
182
-			'recurring_amount'
183
-    	);
184
-
185
-		return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields );
186
-	}
15
+    /**
16
+     * Retrieves subscription query args.
17
+     * 
18
+     * @param array $args Args to search for.
19
+     * @return array
20
+     */
21
+    public function get_subscription_query_args( $args ) {
22
+
23
+        $query_args = array(
24
+            'status'      => 'all',
25
+            'number'      => -1,
26
+            'count_total' => false,
27
+            'fields'      => 'all',
28
+        );
29
+
30
+        if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) {
31
+            $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
32
+        }
33
+
34
+        $date_query = array();
35
+        if ( ! empty( $args['to_date'] ) ) {
36
+            $date_query['before'] = wpinv_clean( $args['to_date'] );
37
+        }
38
+
39
+        if ( ! empty( $args['from_date'] ) ) {
40
+            $date_query['after'] = wpinv_clean( $args['from_date'] );
41
+        }
42
+
43
+        if ( ! empty( $date_query ) ) {
44
+            $date_query['inclusive']          = true;
45
+            $query_args['date_created_query'] = array( $date_query );
46
+        }
47
+
48
+        return $query_args;
49
+    }
50
+
51
+    /**
52
+     * Retrieves subscriptions.
53
+     * 
54
+     * @param array $query_args GetPaid_Subscriptions_Query args.
55
+     * @return WPInv_Subscription[]
56
+     */
57
+    public function get_subscriptions( $query_args ) {
58
+
59
+        // Get subscriptions.
60
+        $subscriptions = new GetPaid_Subscriptions_Query( $query_args );
61
+
62
+        // Prepare the results.
63
+        return $subscriptions->get_results();
64
+
65
+    }
66
+
67
+    /**
68
+     * Handles the actual download.
69
+     *
70
+     */
71
+    public function export( $post_type, $args ) {
72
+
73
+        $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) );
74
+        $stream        = $this->prepare_output();
75
+        $headers       = $this->get_export_fields();
76
+        $file_type     = $this->prepare_file_type( 'subscriptions' );
77
+
78
+        if ( 'csv' == $file_type ) {
79
+            $this->download_csv( $subscriptions, $stream, $headers );
80
+        } else if( 'xml' == $file_type ) {
81
+            $this->download_xml( $subscriptions, $stream, $headers );
82
+        } else {
83
+            $this->download_json( $subscriptions, $stream, $headers );
84
+        }
85
+
86
+        fclose( $stream );
87
+        exit;
88
+    }
89
+
90
+    /**
91
+     * Prepares a single subscription for download.
92
+     *
93
+     * @param WPInv_Subscription $subscription The subscription to prepare..
94
+     * @param array $fields The fields to stream.
95
+     * @since       1.0.19
96
+     * @return array
97
+     */
98
+    public function prepare_row( $subscription, $fields ) {
99
+
100
+        $prepared      = array();
101
+        $amount_fields = $this->get_amount_fields();
102
+        $invoice       = $subscription->get_parent_payment();
103
+
104
+        foreach ( $fields as $field ) {
105
+
106
+            $value  = '';
107
+            $method = "get_$field";
108
+
109
+            if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) {
110
+
111
+                if ( method_exists( $invoice, $method ) ) {
112
+                    $value  = $invoice->$method();
113
+                }
114
+
115
+            } else if ( method_exists( $subscription, $method ) ) {
116
+                $value  = $subscription->$method();
117
+            }
118
+
119
+            if ( in_array( $field, $amount_fields ) ) {
120
+                $value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
121
+            }
122
+
123
+            $prepared[ $field ] = wpinv_clean( $value );
124
+
125
+        }
126
+
127
+        return $prepared;
128
+    }
129
+
130
+    /**
131
+     * Retrieves export fields.
132
+     *
133
+     * @since       1.0.19
134
+     * @return array
135
+     */
136
+    public function get_export_fields() {
137
+
138
+        $fields = array(
139
+            'id',
140
+            'currency',
141
+            'initial_amount',
142
+            'recurring_amount',
143
+            'trial_period',
144
+            'frequency',
145
+            'period',
146
+            'bill_times',
147
+            'parent_payment_id',
148
+            'profile_id',
149
+            'product_id',
150
+            'status',
151
+            'date_created',
152
+            'date_expires',
153
+
154
+            'customer_id',
155
+            'customer_first_name',
156
+            'customer_last_name',
157
+            'customer_phone',
158
+            'customer_email',
159
+            'customer_country',
160
+            'customer_city',
161
+            'customer_state',
162
+            'customer_zip',
163
+            'customer_company',
164
+            'customer_vat_number',
165
+            'customer_address',
166
+
167
+        );
168
+
169
+        return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields );
170
+    }
171
+
172
+    /**
173
+     * Retrieves amount fields.
174
+     *
175
+     * @since       1.0.19
176
+     * @return array
177
+     */
178
+    public function get_amount_fields() {
179
+
180
+        $fields = array(
181
+            'initial_amount',
182
+            'recurring_amount'
183
+        );
184
+
185
+        return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields );
186
+    }
187 187
 
188 188
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports.php 1 patch
Indentation   +103 added lines, -103 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,83 +86,83 @@  discard block
 block discarded – undo
86 86
         </div>
87 87
 		<?php
88 88
 
89
-			// Wordfence loads an unsupported version of chart js on our page.
90
-			wp_deregister_style( 'chart-js' );
91
-			wp_deregister_script( 'chart-js' );
92
-			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
93
-			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
89
+            // Wordfence loads an unsupported version of chart js on our page.
90
+            wp_deregister_style( 'chart-js' );
91
+            wp_deregister_script( 'chart-js' );
92
+            wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
93
+            wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
94 94
 
95
-	}
95
+    }
96 96
 
97
-	/**
98
-	 * Retrieves reports page tabs.
99
-	 *
100
-	 * @return array
101
-	 */
102
-	public function get_tabs() {
97
+    /**
98
+     * Retrieves reports page tabs.
99
+     *
100
+     * @return array
101
+     */
102
+    public function get_tabs() {
103 103
 
104
-		$tabs = array(
105
-			'reports' => __( 'Reports', 'invoicing' ),
106
-			'export'  => __( 'Export', 'invoicing' ),
107
-		);
104
+        $tabs = array(
105
+            'reports' => __( 'Reports', 'invoicing' ),
106
+            'export'  => __( 'Export', 'invoicing' ),
107
+        );
108 108
 
109
-		return apply_filters( 'getpaid_report_tabs', $tabs );
110
-	}
109
+        return apply_filters( 'getpaid_report_tabs', $tabs );
110
+    }
111 111
 
112
-	/**
113
-	 * Displays the reports tab.
114
-	 *
115
-	 */
116
-	public function display_reports_tab() {
112
+    /**
113
+     * Displays the reports tab.
114
+     *
115
+     */
116
+    public function display_reports_tab() {
117 117
 
118
-		$reports = new GetPaid_Reports_Report();
119
-		$reports->display();
118
+        $reports = new GetPaid_Reports_Report();
119
+        $reports->display();
120 120
 
121
-	}
121
+    }
122 122
 
123
-	/**
124
-	 * Displays the exports tab.
125
-	 *
126
-	 */
127
-	public function display_exports_tab() {
123
+    /**
124
+     * Displays the exports tab.
125
+     *
126
+     */
127
+    public function display_exports_tab() {
128 128
 
129
-		$exports = new GetPaid_Reports_Export();
130
-		$exports->display();
129
+        $exports = new GetPaid_Reports_Export();
130
+        $exports->display();
131 131
 
132
-	}
132
+    }
133 133
 
134
-	/**
135
-	 * Donwnloads a graph.
136
-	 *
137
-	 * @param array $args
138
-	 */
139
-	public function download_graph( $args ) {
134
+    /**
135
+     * Donwnloads a graph.
136
+     *
137
+     * @param array $args
138
+     */
139
+    public function download_graph( $args ) {
140 140
 
141
-		if ( ! empty( $args['graph'] ) ) {
142
-			$downloader = new GetPaid_Graph_Downloader();
143
-			$downloader->download( $args['graph'] );
144
-		}
141
+        if ( ! empty( $args['graph'] ) ) {
142
+            $downloader = new GetPaid_Graph_Downloader();
143
+            $downloader->download( $args['graph'] );
144
+        }
145 145
 
146
-	}
146
+    }
147 147
 
148
-	/**
149
-	 * Exports invoices.
150
-	 *
151
-	 * @param array $args
152
-	 */
153
-	public function export_invoices( $args ) {
148
+    /**
149
+     * Exports invoices.
150
+     *
151
+     * @param array $args
152
+     */
153
+    public function export_invoices( $args ) {
154 154
 
155
-		if ( ! empty( $args['post_type'] ) ) {
155
+        if ( ! empty( $args['post_type'] ) ) {
156 156
 
157
-			if ( 'subscriptions' === $args['post_type'] ) {
158
-				$downloader = new GetPaid_Subscription_Exporter();
159
-			} else {
160
-				$downloader = new GetPaid_Invoice_Exporter();
161
-			}
157
+            if ( 'subscriptions' === $args['post_type'] ) {
158
+                $downloader = new GetPaid_Subscription_Exporter();
159
+            } else {
160
+                $downloader = new GetPaid_Invoice_Exporter();
161
+            }
162 162
 
163
-			$downloader->export( $args['post_type'], $args );
164
-		}
163
+            $downloader->export( $args['post_type'], $args );
164
+        }
165 165
 
166
-	}
166
+    }
167 167
 
168 168
 }
Please login to merge, or discard this patch.
includes/data/tax-rates.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -12,265 +12,265 @@
 block discarded – undo
12 12
 
13 13
 return array(
14 14
 
15
-	array(
16
-		'country'      => 'AT', // Austria
17
-		'state'        => '',
18
-		'global'       => true,
19
-		'rate'         => 20,
20
-		'reduced_rate' => 13,
21
-		'name'         => __( 'VAT', 'invoicing' ),
22
-	),
23
-
24
-	array(
25
-		'country'      => 'BE', // Belgium
26
-		'state'        => '',
27
-		'global'       => true,
28
-		'rate'         => 21,
29
-		'reduced_rate' => 12,
30
-		'name'         => __( 'VAT', 'invoicing' ),
31
-	),
32
-
33
-	array(
34
-		'country'      => 'BG', // Bulgaria
35
-		'state'        => '',
36
-		'global'       => true,
37
-		'rate'         => 20,
38
-		'reduced_rate' => 9,
39
-		'name'         => __( 'VAT', 'invoicing' ),
40
-	),
41
-
42
-	array(
43
-		'country'      => 'HR', // Croatia
44
-		'state'        => '',
45
-		'global'       => true,
46
-		'rate'         => 25,
47
-		'reduced_rate' => 13,
48
-		'name'         => __( 'VAT', 'invoicing' ),
49
-	),
50
-
51
-	array(
52
-		'country'      => 'CY', // Cyprus
53
-		'state'        => '',
54
-		'global'       => true,
55
-		'rate'         => 19,
56
-		'reduced_rate' => 9,
57
-		'name'         => __( 'VAT', 'invoicing' ),
58
-	),
59
-
60
-	array(
61
-		'country'      => 'CZ', // Czech Republic
62
-		'state'        => '',
63
-		'global'       => true,
64
-		'rate'         => 21,
65
-		'reduced_rate' => 15,
66
-		'name'         => __( 'VAT', 'invoicing' ),
67
-	),
68
-
69
-	array(
70
-		'country'      => 'DK', // Denmark
71
-		'state'        => '',
72
-		'global'       => true,
73
-		'rate'         => 25,
74
-		'reduced_rate' => 0,
75
-		'name'         => __( 'VAT', 'invoicing' ),
76
-	),
77
-
78
-	array(
79
-		'country'      => 'EE', // Estonia
80
-		'state'        => '',
81
-		'global'       => true,
82
-		'rate'         => 20,
83
-		'reduced_rate' => 9,
84
-		'name'         => __( 'VAT', 'invoicing' ),
85
-	),
86
-
87
-	array(
88
-		'country'      => 'FI', // Finland
89
-		'state'        => '',
90
-		'global'       => true,
91
-		'rate'         => 24,
92
-		'reduced_rate' => 14,
93
-		'name'         => __( 'VAT', 'invoicing' ),
94
-	),
95
-
96
-	array(
97
-		'country'      => 'FR', // France
98
-		'state'        => '',
99
-		'global'       => true,
100
-		'rate'         => 20,
101
-		'reduced_rate' => 5.5,
102
-		'name'         => __( 'VAT', 'invoicing' ),
103
-	),
104
-
105
-	array(
106
-		'country'      => 'DE', // Germany
107
-		'state'        => '',
108
-		'global'       => true,
109
-		'rate'         => 19,
110
-		'reduced_rate' => 7,
111
-		'name'         => __( 'VAT', 'invoicing' ),
112
-	),
113
-
114
-	array(
115
-		'country'      => 'GR', // Greece
116
-		'state'        => '',
117
-		'global'       => true,
118
-		'rate'         => 24,
119
-		'reduced_rate' => 13,
120
-		'name'         => __( 'VAT', 'invoicing' ),
121
-	),
122
-
123
-	array(
124
-		'country'      => 'HU', // Hungary
125
-		'state'        => '',
126
-		'global'       => true,
127
-		'rate'         => 27,
128
-		'reduced_rate' => 18,
129
-		'name'         => __( 'VAT', 'invoicing' ),
130
-	),
131
-
132
-	array(
133
-		'country'      => 'IE', // Ireland
134
-		'state'        => '',
135
-		'global'       => true,
136
-		'rate'         => 23,
137
-		'reduced_rate' => 13.5,
138
-		'name'         => __( 'VAT', 'invoicing' ),
139
-	),
140
-
141
-	array(
142
-		'country'      => 'IT', // Italy
143
-		'state'        => '',
144
-		'global'       => true,
145
-		'rate'         => 22,
146
-		'reduced_rate' => 10,
147
-		'name'         => __( 'VAT', 'invoicing' ),
148
-	),
149
-
150
-	array(
151
-		'country'      => 'LV', // Latvia
152
-		'state'        => '',
153
-		'global'       => true,
154
-		'rate'         => 21,
155
-		'reduced_rate' => 12,
156
-		'name'         => __( 'VAT', 'invoicing' ),
157
-	),
158
-
159
-	array(
160
-		'country'      => 'LT', // Lithuania
161
-		'state'        => '',
162
-		'global'       => true,
163
-		'rate'         => 21,
164
-		'reduced_rate' => 9,
165
-		'name'         => __( 'VAT', 'invoicing' ),
166
-	),
167
-
168
-	array(
169
-		'country'      => 'LU', // Luxembourg
170
-		'state'        => '',
171
-		'global'       => true,
172
-		'rate'         => 17,
173
-		'reduced_rate' => 14,
174
-		'name'         => __( 'VAT', 'invoicing' ),
175
-	),
176
-
177
-	array(
178
-		'country'      => 'MT', // Malta
179
-		'state'        => '',
180
-		'global'       => true,
181
-		'rate'         => 18,
182
-		'reduced_rate' => 7,
183
-		'name'         => __( 'VAT', 'invoicing' ),
184
-	),
185
-
186
-	array(
187
-		'country'      => 'MC', // Monaco
188
-		'state'        => '',
189
-		'global'       => true,
190
-		'rate'         => 20,
191
-		'reduced_rate' => 10,
192
-		'name'         => __( 'VAT', 'invoicing' ),
193
-	),
194
-
195
-	array(
196
-		'country'      => 'NL', // Netherlands
197
-		'state'        => '',
198
-		'global'       => true,
199
-		'rate'         => 21,
200
-		'reduced_rate' => 9,
201
-		'name'         => __( 'VAT', 'invoicing' ),
202
-	),
203
-
204
-	array(
205
-		'country'      => 'PL', // Poland
206
-		'state'        => '',
207
-		'global'       => true,
208
-		'rate'         => 23,
209
-		'reduced_rate' => 8,
210
-		'name'         => __( 'VAT', 'invoicing' ),
211
-	),
212
-
213
-	array(
214
-		'country'      => 'PT', // Portugal
215
-		'state'        => '',
216
-		'global'       => true,
217
-		'rate'         => 23,
218
-		'reduced_rate' => 13,
219
-		'name'         => __( 'VAT', 'invoicing' ),
220
-	),
221
-
222
-	array(
223
-		'country'      => 'RO', // Romania
224
-		'state'        => '',
225
-		'global'       => true,
226
-		'rate'         => 19,
227
-		'reduced_rate' => 9,
228
-		'name'         => __( 'VAT', 'invoicing' ),
229
-	),
230
-
231
-	array(
232
-		'country'      => 'SK', // Slovakia
233
-		'state'        => '',
234
-		'global'       => true,
235
-		'rate'         => 20,
236
-		'reduced_rate' => 10,
237
-		'name'         => __( 'VAT', 'invoicing' ),
238
-	),
239
-
240
-	array(
241
-		'country'      => 'SI', // Slovenia
242
-		'state'        => '',
243
-		'global'       => true,
244
-		'rate'         => 22,
245
-		'reduced_rate' => 9.5,
246
-		'name'         => __( 'VAT', 'invoicing' ),
247
-	),
248
-
249
-	array(
250
-		'country'      => 'ES', // Spain
251
-		'state'        => '',
252
-		'global'       => true,
253
-		'rate'         => 21,
254
-		'reduced_rate' => 10,
255
-		'name'         => __( 'VAT', 'invoicing' ),
256
-	),
257
-
258
-	array(
259
-		'country'      => 'SE', // Sweden
260
-		'state'        => '',
261
-		'global'       => true,
262
-		'rate'         => 25,
263
-		'reduced_rate' => 12,
264
-		'name'         => __( 'VAT', 'invoicing' ),
265
-	),
266
-
267
-	array(
268
-		'country'      => 'GB', // UK
269
-		'state'        => '',
270
-		'global'       => true,
271
-		'rate'         => 20,
272
-		'reduced_rate' => 5,
273
-		'name'         => __( 'VAT', 'invoicing' ),
274
-	)
15
+    array(
16
+        'country'      => 'AT', // Austria
17
+        'state'        => '',
18
+        'global'       => true,
19
+        'rate'         => 20,
20
+        'reduced_rate' => 13,
21
+        'name'         => __( 'VAT', 'invoicing' ),
22
+    ),
23
+
24
+    array(
25
+        'country'      => 'BE', // Belgium
26
+        'state'        => '',
27
+        'global'       => true,
28
+        'rate'         => 21,
29
+        'reduced_rate' => 12,
30
+        'name'         => __( 'VAT', 'invoicing' ),
31
+    ),
32
+
33
+    array(
34
+        'country'      => 'BG', // Bulgaria
35
+        'state'        => '',
36
+        'global'       => true,
37
+        'rate'         => 20,
38
+        'reduced_rate' => 9,
39
+        'name'         => __( 'VAT', 'invoicing' ),
40
+    ),
41
+
42
+    array(
43
+        'country'      => 'HR', // Croatia
44
+        'state'        => '',
45
+        'global'       => true,
46
+        'rate'         => 25,
47
+        'reduced_rate' => 13,
48
+        'name'         => __( 'VAT', 'invoicing' ),
49
+    ),
50
+
51
+    array(
52
+        'country'      => 'CY', // Cyprus
53
+        'state'        => '',
54
+        'global'       => true,
55
+        'rate'         => 19,
56
+        'reduced_rate' => 9,
57
+        'name'         => __( 'VAT', 'invoicing' ),
58
+    ),
59
+
60
+    array(
61
+        'country'      => 'CZ', // Czech Republic
62
+        'state'        => '',
63
+        'global'       => true,
64
+        'rate'         => 21,
65
+        'reduced_rate' => 15,
66
+        'name'         => __( 'VAT', 'invoicing' ),
67
+    ),
68
+
69
+    array(
70
+        'country'      => 'DK', // Denmark
71
+        'state'        => '',
72
+        'global'       => true,
73
+        'rate'         => 25,
74
+        'reduced_rate' => 0,
75
+        'name'         => __( 'VAT', 'invoicing' ),
76
+    ),
77
+
78
+    array(
79
+        'country'      => 'EE', // Estonia
80
+        'state'        => '',
81
+        'global'       => true,
82
+        'rate'         => 20,
83
+        'reduced_rate' => 9,
84
+        'name'         => __( 'VAT', 'invoicing' ),
85
+    ),
86
+
87
+    array(
88
+        'country'      => 'FI', // Finland
89
+        'state'        => '',
90
+        'global'       => true,
91
+        'rate'         => 24,
92
+        'reduced_rate' => 14,
93
+        'name'         => __( 'VAT', 'invoicing' ),
94
+    ),
95
+
96
+    array(
97
+        'country'      => 'FR', // France
98
+        'state'        => '',
99
+        'global'       => true,
100
+        'rate'         => 20,
101
+        'reduced_rate' => 5.5,
102
+        'name'         => __( 'VAT', 'invoicing' ),
103
+    ),
104
+
105
+    array(
106
+        'country'      => 'DE', // Germany
107
+        'state'        => '',
108
+        'global'       => true,
109
+        'rate'         => 19,
110
+        'reduced_rate' => 7,
111
+        'name'         => __( 'VAT', 'invoicing' ),
112
+    ),
113
+
114
+    array(
115
+        'country'      => 'GR', // Greece
116
+        'state'        => '',
117
+        'global'       => true,
118
+        'rate'         => 24,
119
+        'reduced_rate' => 13,
120
+        'name'         => __( 'VAT', 'invoicing' ),
121
+    ),
122
+
123
+    array(
124
+        'country'      => 'HU', // Hungary
125
+        'state'        => '',
126
+        'global'       => true,
127
+        'rate'         => 27,
128
+        'reduced_rate' => 18,
129
+        'name'         => __( 'VAT', 'invoicing' ),
130
+    ),
131
+
132
+    array(
133
+        'country'      => 'IE', // Ireland
134
+        'state'        => '',
135
+        'global'       => true,
136
+        'rate'         => 23,
137
+        'reduced_rate' => 13.5,
138
+        'name'         => __( 'VAT', 'invoicing' ),
139
+    ),
140
+
141
+    array(
142
+        'country'      => 'IT', // Italy
143
+        'state'        => '',
144
+        'global'       => true,
145
+        'rate'         => 22,
146
+        'reduced_rate' => 10,
147
+        'name'         => __( 'VAT', 'invoicing' ),
148
+    ),
149
+
150
+    array(
151
+        'country'      => 'LV', // Latvia
152
+        'state'        => '',
153
+        'global'       => true,
154
+        'rate'         => 21,
155
+        'reduced_rate' => 12,
156
+        'name'         => __( 'VAT', 'invoicing' ),
157
+    ),
158
+
159
+    array(
160
+        'country'      => 'LT', // Lithuania
161
+        'state'        => '',
162
+        'global'       => true,
163
+        'rate'         => 21,
164
+        'reduced_rate' => 9,
165
+        'name'         => __( 'VAT', 'invoicing' ),
166
+    ),
167
+
168
+    array(
169
+        'country'      => 'LU', // Luxembourg
170
+        'state'        => '',
171
+        'global'       => true,
172
+        'rate'         => 17,
173
+        'reduced_rate' => 14,
174
+        'name'         => __( 'VAT', 'invoicing' ),
175
+    ),
176
+
177
+    array(
178
+        'country'      => 'MT', // Malta
179
+        'state'        => '',
180
+        'global'       => true,
181
+        'rate'         => 18,
182
+        'reduced_rate' => 7,
183
+        'name'         => __( 'VAT', 'invoicing' ),
184
+    ),
185
+
186
+    array(
187
+        'country'      => 'MC', // Monaco
188
+        'state'        => '',
189
+        'global'       => true,
190
+        'rate'         => 20,
191
+        'reduced_rate' => 10,
192
+        'name'         => __( 'VAT', 'invoicing' ),
193
+    ),
194
+
195
+    array(
196
+        'country'      => 'NL', // Netherlands
197
+        'state'        => '',
198
+        'global'       => true,
199
+        'rate'         => 21,
200
+        'reduced_rate' => 9,
201
+        'name'         => __( 'VAT', 'invoicing' ),
202
+    ),
203
+
204
+    array(
205
+        'country'      => 'PL', // Poland
206
+        'state'        => '',
207
+        'global'       => true,
208
+        'rate'         => 23,
209
+        'reduced_rate' => 8,
210
+        'name'         => __( 'VAT', 'invoicing' ),
211
+    ),
212
+
213
+    array(
214
+        'country'      => 'PT', // Portugal
215
+        'state'        => '',
216
+        'global'       => true,
217
+        'rate'         => 23,
218
+        'reduced_rate' => 13,
219
+        'name'         => __( 'VAT', 'invoicing' ),
220
+    ),
221
+
222
+    array(
223
+        'country'      => 'RO', // Romania
224
+        'state'        => '',
225
+        'global'       => true,
226
+        'rate'         => 19,
227
+        'reduced_rate' => 9,
228
+        'name'         => __( 'VAT', 'invoicing' ),
229
+    ),
230
+
231
+    array(
232
+        'country'      => 'SK', // Slovakia
233
+        'state'        => '',
234
+        'global'       => true,
235
+        'rate'         => 20,
236
+        'reduced_rate' => 10,
237
+        'name'         => __( 'VAT', 'invoicing' ),
238
+    ),
239
+
240
+    array(
241
+        'country'      => 'SI', // Slovenia
242
+        'state'        => '',
243
+        'global'       => true,
244
+        'rate'         => 22,
245
+        'reduced_rate' => 9.5,
246
+        'name'         => __( 'VAT', 'invoicing' ),
247
+    ),
248
+
249
+    array(
250
+        'country'      => 'ES', // Spain
251
+        'state'        => '',
252
+        'global'       => true,
253
+        'rate'         => 21,
254
+        'reduced_rate' => 10,
255
+        'name'         => __( 'VAT', 'invoicing' ),
256
+    ),
257
+
258
+    array(
259
+        'country'      => 'SE', // Sweden
260
+        'state'        => '',
261
+        'global'       => true,
262
+        'rate'         => 25,
263
+        'reduced_rate' => 12,
264
+        'name'         => __( 'VAT', 'invoicing' ),
265
+    ),
266
+
267
+    array(
268
+        'country'      => 'GB', // UK
269
+        'state'        => '',
270
+        'global'       => true,
271
+        'rate'         => 20,
272
+        'reduced_rate' => 5,
273
+        'name'         => __( 'VAT', 'invoicing' ),
274
+    )
275 275
 
276 276
 );
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( $this->get_price() );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( $this->get_initial_price() );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( $this->get_recurring_price() );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,58 +527,58 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
+        return max( 1, $interval );
539 539
     }
540 540
 
541 541
     /**
542
-	 * Get the recurring limit.
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  string $context View or edit context.
546
-	 * @return int
547
-	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
542
+     * Get the recurring limit.
543
+     *
544
+     * @since 1.0.19
545
+     * @param  string $context View or edit context.
546
+     * @return int
547
+     */
548
+    public function get_recurring_limit( $context = 'view' ) {
549 549
         return (int) $this->get_prop( 'recurring_limit', $context );
550 550
     }
551 551
 
552 552
     /**
553
-	 * Checks if we have a free trial.
554
-	 *
555
-	 * @since 1.0.19
556
-	 * @param  string $context View or edit context.
557
-	 * @return int
558
-	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
553
+     * Checks if we have a free trial.
554
+     *
555
+     * @since 1.0.19
556
+     * @param  string $context View or edit context.
557
+     * @return int
558
+     */
559
+    public function get_is_free_trial( $context = 'view' ) {
560 560
         return (int) $this->get_prop( 'is_free_trial', $context );
561 561
     }
562 562
 
563 563
     /**
564
-	 * Alias for self::get_is_free_trial().
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param  string $context View or edit context.
568
-	 * @return int
569
-	 */
570
-	public function get_free_trial( $context = 'view' ) {
564
+     * Alias for self::get_is_free_trial().
565
+     *
566
+     * @since 1.0.19
567
+     * @param  string $context View or edit context.
568
+     * @return int
569
+     */
570
+    public function get_free_trial( $context = 'view' ) {
571 571
         return $this->get_is_free_trial( $context );
572 572
     }
573 573
 
574 574
     /**
575
-	 * Get the trial period.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  bool $full Return abbreviation or in full.
579
-	 * @return string
580
-	 */
581
-	public function get_trial_period( $full = false ) {
575
+     * Get the trial period.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  bool $full Return abbreviation or in full.
579
+     * @return string
580
+     */
581
+    public function get_trial_period( $full = false ) {
582 582
         $period = $this->get_prop( 'trial_period', 'view' );
583 583
 
584 584
         if ( $full && ! is_bool( $full ) ) {
@@ -589,104 +589,104 @@  discard block
 block discarded – undo
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the trial interval.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  string $context View or edit context.
596
-	 * @return int
597
-	 */
598
-	public function get_trial_interval( $context = 'view' ) {
592
+     * Get the trial interval.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  string $context View or edit context.
596
+     * @return int
597
+     */
598
+    public function get_trial_interval( $context = 'view' ) {
599 599
         return (int) $this->get_prop( 'trial_interval', $context );
600
-	}
600
+    }
601 601
 	
602
-	/**
603
-	 * Get the item's edit url.
604
-	 *
605
-	 * @since 1.0.19
606
-	 * @return string
607
-	 */
608
-	public function get_edit_url() {
602
+    /**
603
+     * Get the item's edit url.
604
+     *
605
+     * @since 1.0.19
606
+     * @return string
607
+     */
608
+    public function get_edit_url() {
609 609
         return get_edit_post_link( $this->get_id(), 'edit' );
610
-	}
611
-
612
-	/**
613
-	 * Given an item's name/custom id, it returns its id.
614
-	 *
615
-	 *
616
-	 * @static
617
-	 * @param string $value The item name or custom id.
618
-	 * @param string $field Either name or custom_id.
619
-	 * @param string $type in case you need to search for a given type.
620
-	 * @since 1.0.15
621
-	 * @return int
622
-	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
-
625
-		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
628
-			return 0;
629
-		}
610
+    }
611
+
612
+    /**
613
+     * Given an item's name/custom id, it returns its id.
614
+     *
615
+     *
616
+     * @static
617
+     * @param string $value The item name or custom id.
618
+     * @param string $field Either name or custom_id.
619
+     * @param string $type in case you need to search for a given type.
620
+     * @since 1.0.15
621
+     * @return int
622
+     */
623
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
+
625
+        // Trim the value.
626
+        $value = sanitize_text_field( $value );
627
+        if ( empty( $value ) ) {
628
+            return 0;
629
+        }
630 630
 
631 631
         // Valid fields.
632 632
         $fields = array( 'custom_id', 'name', 'slug' );
633 633
 
634
-		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
-			return 0;
637
-		}
638
-
639
-		if ( $field == 'name' ) {
640
-			$field = 'slug';
641
-		}
642
-
643
-		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
646
-			return $item_id;
647
-		}
648
-
649
-		// Fetch from the db.
650
-		$items = array();
651
-		if ( $field == 'slug' ) {
652
-			$items = get_posts(
653
-				array(
654
-					'post_type'      => 'wpi_item',
655
-					'name'           => $value,
656
-					'posts_per_page' => 1,
657
-					'post_status'    => 'any',
658
-				)
659
-			);
660
-		}
661
-
662
-		if ( $field =='custom_id' ) {
663
-			$items = get_posts(
664
-				array(
665
-					'post_type'      => 'wpi_item',
666
-					'posts_per_page' => 1,
667
-					'post_status'    => 'any',
668
-					'meta_query'     => array(
669
-						array(
670
-							'key'   => '_wpinv_type',
671
-                			'value' => $type,
672
-						),
673
-						array(
674
-							'key'   => '_wpinv_custom_id',
675
-                			'value' => $value,
676
-						)
677
-					)
678
-				)
679
-			);
680
-		}
681
-
682
-		if ( empty( $items ) ) {
683
-			return 0;
684
-		}
685
-
686
-		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
-
689
-		return $items[0]->ID;
634
+        // Ensure a field has been passed.
635
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
+            return 0;
637
+        }
638
+
639
+        if ( $field == 'name' ) {
640
+            $field = 'slug';
641
+        }
642
+
643
+        // Maybe retrieve from the cache.
644
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
+        if ( ! empty( $item_id ) ) {
646
+            return $item_id;
647
+        }
648
+
649
+        // Fetch from the db.
650
+        $items = array();
651
+        if ( $field == 'slug' ) {
652
+            $items = get_posts(
653
+                array(
654
+                    'post_type'      => 'wpi_item',
655
+                    'name'           => $value,
656
+                    'posts_per_page' => 1,
657
+                    'post_status'    => 'any',
658
+                )
659
+            );
660
+        }
661
+
662
+        if ( $field =='custom_id' ) {
663
+            $items = get_posts(
664
+                array(
665
+                    'post_type'      => 'wpi_item',
666
+                    'posts_per_page' => 1,
667
+                    'post_status'    => 'any',
668
+                    'meta_query'     => array(
669
+                        array(
670
+                            'key'   => '_wpinv_type',
671
+                            'value' => $type,
672
+                        ),
673
+                        array(
674
+                            'key'   => '_wpinv_custom_id',
675
+                            'value' => $value,
676
+                        )
677
+                    )
678
+                )
679
+            );
680
+        }
681
+
682
+        if ( empty( $items ) ) {
683
+            return 0;
684
+        }
685
+
686
+        // Update the cache with our data
687
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
+
689
+        return $items[0]->ID;
690 690
     }
691 691
 
692 692
     /**
@@ -719,52 +719,52 @@  discard block
 block discarded – undo
719 719
     */
720 720
 
721 721
     /**
722
-	 * Set parent order ID.
723
-	 *
724
-	 * @since 1.0.19
725
-	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
-			return;
729
-		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
731
-	}
732
-
733
-    /**
734
-	 * Sets item status.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $status New status.
738
-	 * @return array details of change.
739
-	 */
740
-	public function set_status( $status ) {
722
+     * Set parent order ID.
723
+     *
724
+     * @since 1.0.19
725
+     */
726
+    public function set_parent_id( $value ) {
727
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
+            return;
729
+        }
730
+        $this->set_prop( 'parent_id', absint( $value ) );
731
+    }
732
+
733
+    /**
734
+     * Sets item status.
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $status New status.
738
+     * @return array details of change.
739
+     */
740
+    public function set_status( $status ) {
741 741
         $old_status = $this->get_status();
742 742
 
743 743
         $this->set_prop( 'status', $status );
744 744
 
745
-		return array(
746
-			'from' => $old_status,
747
-			'to'   => $status,
748
-		);
745
+        return array(
746
+            'from' => $old_status,
747
+            'to'   => $status,
748
+        );
749 749
     }
750 750
 
751 751
     /**
752
-	 * Set plugin version when the item was created.
753
-	 *
754
-	 * @since 1.0.19
755
-	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
752
+     * Set plugin version when the item was created.
753
+     *
754
+     * @since 1.0.19
755
+     */
756
+    public function set_version( $value ) {
757
+        $this->set_prop( 'version', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set date when the item was created.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param string $value Value to set.
761
+     * Set date when the item was created.
762
+     *
763
+     * @since 1.0.19
764
+     * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766
-	 */
767
-	public function set_date_created( $value ) {
766
+     */
767
+    public function set_date_created( $value ) {
768 768
         $date = strtotime( $value );
769 769
 
770 770
         if ( $date ) {
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
     }
778 778
 
779 779
     /**
780
-	 * Set date when the item was last modified.
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param string $value Value to set.
780
+     * Set date when the item was last modified.
781
+     *
782
+     * @since 1.0.19
783
+     * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785
-	 */
786
-	public function set_date_modified( $value ) {
785
+     */
786
+    public function set_date_modified( $value ) {
787 787
         $date = strtotime( $value );
788 788
 
789 789
         if ( $date ) {
@@ -796,115 +796,115 @@  discard block
 block discarded – undo
796 796
     }
797 797
 
798 798
     /**
799
-	 * Set the item name.
800
-	 *
801
-	 * @since 1.0.19
802
-	 * @param  string $value New name.
803
-	 */
804
-	public function set_name( $value ) {
799
+     * Set the item name.
800
+     *
801
+     * @since 1.0.19
802
+     * @param  string $value New name.
803
+     */
804
+    public function set_name( $value ) {
805 805
         $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
806
+        $this->set_prop( 'name', $name );
807 807
     }
808 808
 
809 809
     /**
810
-	 * Alias of self::set_name().
811
-	 *
812
-	 * @since 1.0.19
813
-	 * @param  string $value New name.
814
-	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
810
+     * Alias of self::set_name().
811
+     *
812
+     * @since 1.0.19
813
+     * @param  string $value New name.
814
+     */
815
+    public function set_title( $value ) {
816
+        $this->set_name( $value );
817 817
     }
818 818
 
819 819
     /**
820
-	 * Set the item description.
821
-	 *
822
-	 * @since 1.0.19
823
-	 * @param  string $value New description.
824
-	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( wp_unslash( $value ) );
827
-		return $this->set_prop( 'description', $description );
820
+     * Set the item description.
821
+     *
822
+     * @since 1.0.19
823
+     * @param  string $value New description.
824
+     */
825
+    public function set_description( $value ) {
826
+        $description = wp_kses_post( wp_unslash( $value ) );
827
+        return $this->set_prop( 'description', $description );
828 828
     }
829 829
 
830 830
     /**
831
-	 * Alias of self::set_description().
832
-	 *
833
-	 * @since 1.0.19
834
-	 * @param  string $value New description.
835
-	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
831
+     * Alias of self::set_description().
832
+     *
833
+     * @since 1.0.19
834
+     * @param  string $value New description.
835
+     */
836
+    public function set_excerpt( $value ) {
837
+        $this->set_description( $value );
838 838
     }
839 839
 
840 840
     /**
841
-	 * Alias of self::set_description().
842
-	 *
843
-	 * @since 1.0.19
844
-	 * @param  string $value New description.
845
-	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
841
+     * Alias of self::set_description().
842
+     *
843
+     * @since 1.0.19
844
+     * @param  string $value New description.
845
+     */
846
+    public function set_summary( $value ) {
847
+        $this->set_description( $value );
848 848
     }
849 849
 
850 850
     /**
851
-	 * Set the owner of the item.
852
-	 *
853
-	 * @since 1.0.19
854
-	 * @param  int $value New author.
855
-	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
858
-	}
851
+     * Set the owner of the item.
852
+     *
853
+     * @since 1.0.19
854
+     * @param  int $value New author.
855
+     */
856
+    public function set_author( $value ) {
857
+        $this->set_prop( 'author', (int) $value );
858
+    }
859 859
 	
860
-	/**
861
-	 * Alias of self::set_author().
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param  int $value New author.
865
-	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
868
-    }
869
-
870
-    /**
871
-	 * Set the price of the item.
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  float $value New price.
875
-	 */
876
-	public function set_price( $value ) {
860
+    /**
861
+     * Alias of self::set_author().
862
+     *
863
+     * @since 1.0.19
864
+     * @param  int $value New author.
865
+     */
866
+    public function set_owner( $value ) {
867
+        $this->set_author( $value );
868
+    }
869
+
870
+    /**
871
+     * Set the price of the item.
872
+     *
873
+     * @since 1.0.19
874
+     * @param  float $value New price.
875
+     */
876
+    public function set_price( $value ) {
877 877
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
878 878
     }
879 879
 
880 880
     /**
881
-	 * Set the VAT rule of the item.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param  string $value new rule.
885
-	 */
886
-	public function set_vat_rule( $value ) {
881
+     * Set the VAT rule of the item.
882
+     *
883
+     * @since 1.0.19
884
+     * @param  string $value new rule.
885
+     */
886
+    public function set_vat_rule( $value ) {
887 887
         $this->set_prop( 'vat_rule', $value );
888 888
     }
889 889
 
890 890
     /**
891
-	 * Set the VAT class of the item.
892
-	 *
893
-	 * @since 1.0.19
894
-	 * @param  string $value new class.
895
-	 */
896
-	public function set_vat_class( $value ) {
891
+     * Set the VAT class of the item.
892
+     *
893
+     * @since 1.0.19
894
+     * @param  string $value new class.
895
+     */
896
+    public function set_vat_class( $value ) {
897 897
         $this->set_prop( 'vat_class', $value );
898 898
     }
899 899
 
900 900
     /**
901
-	 * Set the type of the item.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @param  string $value new item type.
905
-	 * @return string
906
-	 */
907
-	public function set_type( $value ) {
901
+     * Set the type of the item.
902
+     *
903
+     * @since 1.0.19
904
+     * @param  string $value new item type.
905
+     * @return string
906
+     */
907
+    public function set_type( $value ) {
908 908
 
909 909
         if ( empty( $value ) ) {
910 910
             $value = 'custom';
@@ -914,132 +914,132 @@  discard block
 block discarded – undo
914 914
     }
915 915
 
916 916
     /**
917
-	 * Set the custom id of the item.
918
-	 *
919
-	 * @since 1.0.19
920
-	 * @param  string $value new custom id.
921
-	 */
922
-	public function set_custom_id( $value ) {
917
+     * Set the custom id of the item.
918
+     *
919
+     * @since 1.0.19
920
+     * @param  string $value new custom id.
921
+     */
922
+    public function set_custom_id( $value ) {
923 923
         $this->set_prop( 'custom_id', $value );
924 924
     }
925 925
 
926 926
     /**
927
-	 * Set the custom name of the item.
928
-	 *
929
-	 * @since 1.0.19
930
-	 * @param  string $value new custom name.
931
-	 */
932
-	public function set_custom_name( $value ) {
927
+     * Set the custom name of the item.
928
+     *
929
+     * @since 1.0.19
930
+     * @param  string $value new custom name.
931
+     */
932
+    public function set_custom_name( $value ) {
933 933
         $this->set_prop( 'custom_name', $value );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Set the custom singular name of the item.
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $value new custom singular name.
941
-	 */
942
-	public function set_custom_singular_name( $value ) {
937
+     * Set the custom singular name of the item.
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $value new custom singular name.
941
+     */
942
+    public function set_custom_singular_name( $value ) {
943 943
         $this->set_prop( 'custom_singular_name', $value );
944 944
     }
945 945
 
946 946
     /**
947
-	 * Sets if an item is editable..
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param  int|bool $value whether or not the item is editable.
951
-	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
947
+     * Sets if an item is editable..
948
+     *
949
+     * @since 1.0.19
950
+     * @param  int|bool $value whether or not the item is editable.
951
+     */
952
+    public function set_is_editable( $value ) {
953
+        $this->set_prop( 'is_editable', (int) $value );
954 954
     }
955 955
 
956 956
     /**
957
-	 * Sets if dynamic pricing is enabled.
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961
-	 */
962
-	public function set_is_dynamic_pricing( $value ) {
957
+     * Sets if dynamic pricing is enabled.
958
+     *
959
+     * @since 1.0.19
960
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
961
+     */
962
+    public function set_is_dynamic_pricing( $value ) {
963 963
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
964 964
     }
965 965
 
966 966
     /**
967
-	 * Sets the minimum price if dynamic pricing is enabled.
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param  float $value minimum price.
971
-	 */
972
-	public function set_minimum_price( $value ) {
967
+     * Sets the minimum price if dynamic pricing is enabled.
968
+     *
969
+     * @since 1.0.19
970
+     * @param  float $value minimum price.
971
+     */
972
+    public function set_minimum_price( $value ) {
973 973
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
974 974
     }
975 975
 
976 976
     /**
977
-	 * Sets if this is a recurring item.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981
-	 */
982
-	public function set_is_recurring( $value ) {
977
+     * Sets if this is a recurring item.
978
+     *
979
+     * @since 1.0.19
980
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
981
+     */
982
+    public function set_is_recurring( $value ) {
983 983
         $this->set_prop( 'is_recurring', (int) $value );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Set the recurring period.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @param  string $value new period.
991
-	 */
992
-	public function set_recurring_period( $value ) {
987
+     * Set the recurring period.
988
+     *
989
+     * @since 1.0.19
990
+     * @param  string $value new period.
991
+     */
992
+    public function set_recurring_period( $value ) {
993 993
         $this->set_prop( 'recurring_period', $value );
994 994
     }
995 995
 
996 996
     /**
997
-	 * Set the recurring interval.
998
-	 *
999
-	 * @since 1.0.19
1000
-	 * @param  int $value recurring interval.
1001
-	 */
1002
-	public function set_recurring_interval( $value ) {
997
+     * Set the recurring interval.
998
+     *
999
+     * @since 1.0.19
1000
+     * @param  int $value recurring interval.
1001
+     */
1002
+    public function set_recurring_interval( $value ) {
1003 1003
         return $this->set_prop( 'recurring_interval', (int) $value );
1004 1004
     }
1005 1005
 
1006 1006
     /**
1007
-	 * Get the recurring limit.
1008
-	 * @since 1.0.19
1009
-	 * @param  int $value The recurring limit.
1010
-	 * @return int
1011
-	 */
1012
-	public function set_recurring_limit( $value ) {
1007
+     * Get the recurring limit.
1008
+     * @since 1.0.19
1009
+     * @param  int $value The recurring limit.
1010
+     * @return int
1011
+     */
1012
+    public function set_recurring_limit( $value ) {
1013 1013
         $this->set_prop( 'recurring_limit', (int) $value );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Checks if we have a free trial.
1018
-	 *
1019
-	 * @since 1.0.19
1020
-	 * @param  int|bool $value whether or not it has a free trial.
1021
-	 */
1022
-	public function set_is_free_trial( $value ) {
1017
+     * Checks if we have a free trial.
1018
+     *
1019
+     * @since 1.0.19
1020
+     * @param  int|bool $value whether or not it has a free trial.
1021
+     */
1022
+    public function set_is_free_trial( $value ) {
1023 1023
         $this->set_prop( 'is_free_trial', (int) $value );
1024 1024
     }
1025 1025
 
1026 1026
     /**
1027
-	 * Set the trial period.
1028
-	 *
1029
-	 * @since 1.0.19
1030
-	 * @param  string $value trial period.
1031
-	 */
1032
-	public function set_trial_period( $value ) {
1027
+     * Set the trial period.
1028
+     *
1029
+     * @since 1.0.19
1030
+     * @param  string $value trial period.
1031
+     */
1032
+    public function set_trial_period( $value ) {
1033 1033
         $this->set_prop( 'trial_period', $value );
1034 1034
     }
1035 1035
 
1036 1036
     /**
1037
-	 * Set the trial interval.
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  int $value trial interval.
1041
-	 */
1042
-	public function set_trial_interval( $value ) {
1037
+     * Set the trial interval.
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  int $value trial interval.
1041
+     */
1042
+    public function set_trial_interval( $value ) {
1043 1043
         $this->set_prop( 'trial_interval', $value );
1044 1044
     }
1045 1045
 
@@ -1047,17 +1047,17 @@  discard block
 block discarded – undo
1047 1047
      * Create an item. For backwards compatibilty.
1048 1048
      * 
1049 1049
      * @deprecated
1050
-	 * @return int item id
1050
+     * @return int item id
1051 1051
      */
1052 1052
     public function create( $data = array() ) {
1053 1053
 
1054
-		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1057
-		}
1054
+        // Set the properties.
1055
+        if ( is_array( $data ) ) {
1056
+            $this->set_props( $data );
1057
+        }
1058 1058
 
1059
-		// Save the item.
1060
-		return $this->save();
1059
+        // Save the item.
1060
+        return $this->save();
1061 1061
 
1062 1062
     }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
      * Updates an item. For backwards compatibilty.
1066 1066
      * 
1067 1067
      * @deprecated
1068
-	 * @return int item id
1068
+     * @return int item id
1069 1069
      */
1070 1070
     public function update( $data = array() ) {
1071 1071
         return $this->create( $data );
@@ -1081,93 +1081,93 @@  discard block
 block discarded – undo
1081 1081
 	*/
1082 1082
 
1083 1083
     /**
1084
-	 * Checks whether the item has enabled dynamic pricing.
1085
-	 *
1086
-	 * @since 1.0.19
1087
-	 * @return bool
1088
-	 */
1089
-	public function user_can_set_their_price() {
1084
+     * Checks whether the item has enabled dynamic pricing.
1085
+     *
1086
+     * @since 1.0.19
1087
+     * @return bool
1088
+     */
1089
+    public function user_can_set_their_price() {
1090 1090
         return (bool) $this->get_is_dynamic_pricing();
1091
-	}
1091
+    }
1092 1092
 	
1093
-	/**
1094
-	 * Checks whether the item is recurring.
1095
-	 *
1096
-	 * @since 1.0.19
1097
-	 * @return bool
1098
-	 */
1099
-	public function is_recurring() {
1093
+    /**
1094
+     * Checks whether the item is recurring.
1095
+     *
1096
+     * @since 1.0.19
1097
+     * @return bool
1098
+     */
1099
+    public function is_recurring() {
1100 1100
         return (bool) $this->get_is_recurring();
1101 1101
     }
1102 1102
 
1103 1103
     /**
1104
-	 * Checks whether the item has a free trial.
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @return bool
1108
-	 */
1104
+     * Checks whether the item has a free trial.
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @return bool
1108
+     */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111 1111
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1112 1112
     }
1113 1113
 
1114 1114
     /**
1115
-	 * Checks whether the item is free.
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @return bool
1119
-	 */
1115
+     * Checks whether the item is free.
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @return bool
1119
+     */
1120 1120
     public function is_free() {
1121 1121
         $is_free   = $this->get_price() == 0;
1122 1122
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1123 1123
     }
1124 1124
 
1125 1125
     /**
1126
-	 * Checks the item status against a passed in status.
1127
-	 *
1128
-	 * @param array|string $status Status to check.
1129
-	 * @return bool
1130
-	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1126
+     * Checks the item status against a passed in status.
1127
+     *
1128
+     * @param array|string $status Status to check.
1129
+     * @return bool
1130
+     */
1131
+    public function has_status( $status ) {
1132
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1134 1134
     }
1135 1135
 
1136 1136
     /**
1137
-	 * Checks the item type against a passed in types.
1138
-	 *
1139
-	 * @param array|string $type Type to check.
1140
-	 * @return bool
1141
-	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
-	}
1137
+     * Checks the item type against a passed in types.
1138
+     *
1139
+     * @param array|string $type Type to check.
1140
+     * @return bool
1141
+     */
1142
+    public function is_type( $type ) {
1143
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
+    }
1146 1146
 
1147 1147
     /**
1148
-	 * Checks whether the item is editable.
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @return bool
1152
-	 */
1148
+     * Checks whether the item is editable.
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @return bool
1152
+     */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155 1155
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1156
-	}
1156
+    }
1157 1157
 
1158
-	/**
1159
-	 * Returns an array of cart fees.
1160
-	 */
1161
-	public function get_fees() {
1158
+    /**
1159
+     * Returns an array of cart fees.
1160
+     */
1161
+    public function get_fees() {
1162 1162
         return array();
1163 1163
     }
1164 1164
 
1165 1165
     /**
1166
-	 * Checks whether the item is purchasable.
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @return bool
1170
-	 */
1166
+     * Checks whether the item is purchasable.
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @return bool
1170
+     */
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
     }
1180 1180
 
1181 1181
     /**
1182
-	 * Checks whether the item supports dynamic pricing.
1183
-	 *
1184
-	 * @since 1.0.19
1185
-	 * @return bool
1186
-	 */
1182
+     * Checks whether the item supports dynamic pricing.
1183
+     *
1184
+     * @since 1.0.19
1185
+     * @return bool
1186
+     */
1187 1187
     public function supports_dynamic_pricing() {
1188 1188
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1189 1189
     }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<?php $subscribers_table->views(); ?>
67 67
 	<form id="subscribers-filter" class="bsui" method="get">
68 68
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
@@ -81,41 +81,41 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function wpinv_recurring_subscription_details() {
83 83
 
84
-	// Fetch the subscription.
85
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
86
-	if ( ! $sub->exists() ) {
84
+    // Fetch the subscription.
85
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
86
+    if ( ! $sub->exists() ) {
87 87
 
88
-		echo aui()->alert(
89
-			array(
90
-				'type'    => 'danger',
91
-				'content' => __( 'Subscription not found.', 'invoicing' ),
92
-			)
93
-		);
88
+        echo aui()->alert(
89
+            array(
90
+                'type'    => 'danger',
91
+                'content' => __( 'Subscription not found.', 'invoicing' ),
92
+            )
93
+        );
94 94
 
95
-		return;
96
-	}
95
+        return;
96
+    }
97 97
 
98
-	// Use metaboxes to display the subscription details.
99
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
100
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
98
+    // Use metaboxes to display the subscription details.
99
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
100
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
101 101
 
102
-	$subscription_id     = $sub->get_id();
103
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
104
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
102
+    $subscription_id     = $sub->get_id();
103
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
104
+    $subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
105 105
 
106
-	if ( 1 < count( $subscription_groups ) ) {
107
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
108
-	}
106
+    if ( 1 < count( $subscription_groups ) ) {
107
+        add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
108
+    }
109 109
 
110
-	if ( ! empty( $subscription_group ) ) {
111
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
112
-	}
110
+    if ( ! empty( $subscription_group ) ) {
111
+        add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
112
+    }
113 113
 
114
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
114
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
115 115
 
116
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
116
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
117 117
 
118
-	?>
118
+    ?>
119 119
 
120 120
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
121 121
 
@@ -155,45 +155,45 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function getpaid_admin_subscription_details_metabox( $sub ) {
157 157
 
158
-	// Subscription items.
159
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
160
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
161
-
162
-	// Prepare subscription detail columns.
163
-	$fields = apply_filters(
164
-		'getpaid_subscription_admin_page_fields',
165
-		array(
166
-			'subscription'   => __( 'Subscription', 'invoicing' ),
167
-			'customer'       => __( 'Customer', 'invoicing' ),
168
-			'amount'         => __( 'Amount', 'invoicing' ),
169
-			'start_date'     => __( 'Start Date', 'invoicing' ),
170
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
171
-			'renewals'       => __( 'Payments', 'invoicing' ),
172
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
173
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
174
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
175
-			'status'         => __( 'Status', 'invoicing' ),
176
-		)
177
-	);
178
-
179
-	if ( ! $sub->is_active() ) {
180
-
181
-		if ( isset( $fields['renews_on'] ) ) {
182
-			unset( $fields['renews_on'] );
183
-		}
184
-
185
-		if ( isset( $fields['gateway'] ) ) {
186
-			unset( $fields['gateway'] );
187
-		}
188
-
189
-	}
190
-
191
-	$profile_id = $sub->get_profile_id();
192
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
193
-		unset( $fields['profile_id'] );
194
-	}
195
-
196
-	?>
158
+    // Subscription items.
159
+    $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
160
+    $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
161
+
162
+    // Prepare subscription detail columns.
163
+    $fields = apply_filters(
164
+        'getpaid_subscription_admin_page_fields',
165
+        array(
166
+            'subscription'   => __( 'Subscription', 'invoicing' ),
167
+            'customer'       => __( 'Customer', 'invoicing' ),
168
+            'amount'         => __( 'Amount', 'invoicing' ),
169
+            'start_date'     => __( 'Start Date', 'invoicing' ),
170
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
171
+            'renewals'       => __( 'Payments', 'invoicing' ),
172
+            'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
173
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
174
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
175
+            'status'         => __( 'Status', 'invoicing' ),
176
+        )
177
+    );
178
+
179
+    if ( ! $sub->is_active() ) {
180
+
181
+        if ( isset( $fields['renews_on'] ) ) {
182
+            unset( $fields['renews_on'] );
183
+        }
184
+
185
+        if ( isset( $fields['gateway'] ) ) {
186
+            unset( $fields['gateway'] );
187
+        }
188
+
189
+    }
190
+
191
+    $profile_id = $sub->get_profile_id();
192
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
193
+        unset( $fields['profile_id'] );
194
+    }
195
+
196
+    ?>
197 197
 
198 198
 		<table class="table table-borderless" style="font-size: 14px;">
199 199
 			<tbody>
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
  */
228 228
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
229 229
 
230
-	$username = __( '(Missing User)', 'invoicing' );
230
+    $username = __( '(Missing User)', 'invoicing' );
231 231
 
232
-	$user = get_userdata( $subscription->get_customer_id() );
233
-	if ( $user ) {
232
+    $user = get_userdata( $subscription->get_customer_id() );
233
+    if ( $user ) {
234 234
 
235
-		$username = sprintf(
236
-			'<a href="user-edit.php?user_id=%s">%s</a>',
237
-			absint( $user->ID ),
238
-			! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
239
-		);
235
+        $username = sprintf(
236
+            '<a href="user-edit.php?user_id=%s">%s</a>',
237
+            absint( $user->ID ),
238
+            ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
239
+        );
240 240
 
241
-	}
241
+    }
242 242
 
243
-	echo  $username;
243
+    echo  $username;
244 244
 }
245 245
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
246 246
 
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
  * @param WPInv_Subscription $subscription
251 251
  */
252 252
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
253
-	$amount    = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) );
254
-	echo "<span>$amount</span>";
253
+    $amount    = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) );
254
+    echo "<span>$amount</span>";
255 255
 }
256 256
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
257 257
 
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
264 264
 
265
-	printf(
266
-		'<a href="%s">#%s</a>',
267
-		esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ),
268
-		absint( $subscription->get_id() )
269
-	);
265
+    printf(
266
+        '<a href="%s">#%s</a>',
267
+        esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ),
268
+        absint( $subscription->get_id() )
269
+    );
270 270
 
271 271
 }
272 272
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
  * @param WPInv_Subscription $subscription
278 278
  */
279 279
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
280
-	echo getpaid_format_date_value( $subscription->get_date_created() );
280
+    echo getpaid_format_date_value( $subscription->get_date_created() );
281 281
 }
282 282
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
283 283
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
  * @param WPInv_Subscription $subscription
288 288
  */
289 289
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
290
-	echo getpaid_format_date_value( $subscription->get_expiration() );
290
+    echo getpaid_format_date_value( $subscription->get_expiration() );
291 291
 }
292 292
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
293 293
 
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
  * @param WPInv_Subscription $subscription
298 298
  */
299 299
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
300
-	$max_bills = $subscription->get_bill_times();
301
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
300
+    $max_bills = $subscription->get_bill_times();
301
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
302 302
 }
303 303
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
304 304
 /**
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
  */
310 310
 function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
311 311
 
312
-	if ( empty( $subscription_group ) ) {
313
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
314
-		return;
315
-	}
312
+    if ( empty( $subscription_group ) ) {
313
+        echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
314
+        return;
315
+    }
316 316
 
317
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
318
-	echo implode( ' | ', $markup );
317
+    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
318
+    echo implode( ' | ', $markup );
319 319
 
320 320
 }
321 321
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
  */
328 328
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
329 329
 
330
-	$gateway = $subscription->get_gateway();
330
+    $gateway = $subscription->get_gateway();
331 331
 
332
-	if ( ! empty( $gateway ) ) {
333
-		echo esc_html( wpinv_get_gateway_admin_label( $gateway ) );
334
-	} else {
335
-		echo "&mdash;";
336
-	}
332
+    if ( ! empty( $gateway ) ) {
333
+        echo esc_html( wpinv_get_gateway_admin_label( $gateway ) );
334
+    } else {
335
+        echo "&mdash;";
336
+    }
337 337
 
338 338
 }
339 339
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
  * @param WPInv_Subscription $subscription
345 345
  */
346 346
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
347
-	echo $subscription->get_status_label_html();
347
+    echo $subscription->get_status_label_html();
348 348
 }
349 349
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
350 350
 
@@ -355,29 +355,29 @@  discard block
 block discarded – undo
355 355
  */
356 356
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
357 357
 
358
-	$profile_id = $subscription->get_profile_id();
359
-
360
-	$input = aui()->input(
361
-		array(
362
-			'type'        => 'text',
363
-			'id'          => 'wpinv_subscription_profile_id',
364
-			'name'        => 'wpinv_subscription_profile_id',
365
-			'label'       => __( 'Profile Id', 'invoicing' ),
366
-			'label_type'  => 'hidden',
367
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
368
-			'value'       => esc_attr( $profile_id ),
369
-			'input_group_right' => '',
370
-			'no_wrap'     => true,
371
-		)
372
-	);
373
-
374
-	echo str_ireplace( 'form-control', 'regular-text', $input );
375
-
376
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
377
-	if ( ! empty( $url ) ) {
378
-		$url = esc_url_raw( $url );
379
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
380
-	}
358
+    $profile_id = $subscription->get_profile_id();
359
+
360
+    $input = aui()->input(
361
+        array(
362
+            'type'        => 'text',
363
+            'id'          => 'wpinv_subscription_profile_id',
364
+            'name'        => 'wpinv_subscription_profile_id',
365
+            'label'       => __( 'Profile Id', 'invoicing' ),
366
+            'label_type'  => 'hidden',
367
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
368
+            'value'       => esc_attr( $profile_id ),
369
+            'input_group_right' => '',
370
+            'no_wrap'     => true,
371
+        )
372
+    );
373
+
374
+    echo str_ireplace( 'form-control', 'regular-text', $input );
375
+
376
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
377
+    if ( ! empty( $url ) ) {
378
+        $url = esc_url_raw( $url );
379
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
380
+    }
381 381
 
382 382
 }
383 383
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -389,39 +389,39 @@  discard block
 block discarded – undo
389 389
  */
390 390
 function getpaid_admin_subscription_update_metabox( $subscription ) {
391 391
 
392
-	?>
392
+    ?>
393 393
 	<div class="mt-3">
394 394
 
395 395
 		<?php
396
-			echo aui()->select(
397
-				array(
398
-					'options'          => getpaid_get_subscription_statuses(),
399
-					'name'             => 'subscription_status',
400
-					'id'               => 'subscription_status_update_select',
401
-					'required'         => true,
402
-					'no_wrap'          => false,
403
-					'label'            => __( 'Subscription Status', 'invoicing' ),
404
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
405
-					'select2'          => true,
406
-					'value'            => $subscription->get_status( 'edit' ),
407
-				)
408
-			);
409
-		?>
396
+            echo aui()->select(
397
+                array(
398
+                    'options'          => getpaid_get_subscription_statuses(),
399
+                    'name'             => 'subscription_status',
400
+                    'id'               => 'subscription_status_update_select',
401
+                    'required'         => true,
402
+                    'no_wrap'          => false,
403
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
404
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
405
+                    'select2'          => true,
406
+                    'value'            => $subscription->get_status( 'edit' ),
407
+                )
408
+            );
409
+        ?>
410 410
 
411 411
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
412 412
 
413 413
 		<?php
414
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
414
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
415 415
 
416
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
417
-			$anchor = __( 'Renew Subscription', 'invoicing' );
418
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
416
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
417
+            $anchor = __( 'Renew Subscription', 'invoicing' );
418
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
419 419
 
420
-			if ( $subscription->is_active() ) {
421
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
422
-			}
420
+            if ( $subscription->is_active() ) {
421
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
422
+            }
423 423
 
424
-	echo '</div></div>';
424
+    echo '</div></div>';
425 425
 }
426 426
 
427 427
 /**
@@ -432,33 +432,33 @@  discard block
 block discarded – undo
432 432
  */
433 433
 function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
434 434
 
435
-	$columns = apply_filters(
436
-		'getpaid_subscription_related_invoices_columns',
437
-		array(
438
-			'invoice'      => __( 'Invoice', 'invoicing' ),
439
-			'relationship' => __( 'Relationship', 'invoicing' ),
440
-			'date'         => __( 'Date', 'invoicing' ),
441
-			'status'       => __( 'Status', 'invoicing' ),
442
-			'total'        => __( 'Total', 'invoicing' ),
443
-		),
444
-		$subscription
445
-	);
446
-
447
-	// Prepare the invoices.
448
-	$payments = $subscription->get_child_payments( ! is_admin() );
449
-	$parent   = $subscription->get_parent_invoice();
450
-
451
-	if ( $parent->exists() ) {
452
-		$payments = array_merge( array( $parent ), $payments );
453
-	}
454
-
455
-	$table_class = 'w-100 bg-white';
456
-
457
-	if ( ! is_admin() ) {
458
-		$table_class = 'table table-bordered';
459
-	}
460
-
461
-	?>
435
+    $columns = apply_filters(
436
+        'getpaid_subscription_related_invoices_columns',
437
+        array(
438
+            'invoice'      => __( 'Invoice', 'invoicing' ),
439
+            'relationship' => __( 'Relationship', 'invoicing' ),
440
+            'date'         => __( 'Date', 'invoicing' ),
441
+            'status'       => __( 'Status', 'invoicing' ),
442
+            'total'        => __( 'Total', 'invoicing' ),
443
+        ),
444
+        $subscription
445
+    );
446
+
447
+    // Prepare the invoices.
448
+    $payments = $subscription->get_child_payments( ! is_admin() );
449
+    $parent   = $subscription->get_parent_invoice();
450
+
451
+    if ( $parent->exists() ) {
452
+        $payments = array_merge( array( $parent ), $payments );
453
+    }
454
+
455
+    $table_class = 'w-100 bg-white';
456
+
457
+    if ( ! is_admin() ) {
458
+        $table_class = 'table table-bordered';
459
+    }
460
+
461
+    ?>
462 462
 		<div class="m-0" style="overflow: auto;">
463 463
 
464 464
 			<table class="<?php echo $table_class; ?>">
@@ -466,14 +466,14 @@  discard block
 block discarded – undo
466 466
 				<thead>
467 467
 					<tr>
468 468
 						<?php
469
-							foreach ( $columns as $key => $label ) {
470
-								$key   = esc_attr( $key );
471
-								$label = esc_html( $label );
472
-								$class = 'text-left';
473
-
474
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
475
-							}
476
-						?>
469
+                            foreach ( $columns as $key => $label ) {
470
+                                $key   = esc_attr( $key );
471
+                                $label = esc_html( $label );
472
+                                $class = 'text-left';
473
+
474
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
475
+                            }
476
+                        ?>
477 477
 					</tr>
478 478
 				</thead>
479 479
 
@@ -489,73 +489,73 @@  discard block
 block discarded – undo
489 489
 
490 490
 					<?php
491 491
 
492
-						foreach( $payments as $payment ) :
492
+                        foreach( $payments as $payment ) :
493 493
 
494
-							// Ensure that we have an invoice.
495
-							$payment = new WPInv_Invoice( $payment );
494
+                            // Ensure that we have an invoice.
495
+                            $payment = new WPInv_Invoice( $payment );
496 496
 
497
-							// Abort if the invoice is invalid...
498
-							if ( ! $payment->exists() ) {
499
-								continue;
500
-							}
497
+                            // Abort if the invoice is invalid...
498
+                            if ( ! $payment->exists() ) {
499
+                                continue;
500
+                            }
501 501
 
502
-							// ... or belongs to a different subscription.
503
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
504
-								continue;
505
-							}
502
+                            // ... or belongs to a different subscription.
503
+                            if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
504
+                                continue;
505
+                            }
506 506
 
507
-							echo '<tr>';
507
+                            echo '<tr>';
508 508
 
509
-								foreach ( array_keys( $columns ) as $key ) {
509
+                                foreach ( array_keys( $columns ) as $key ) {
510 510
 
511
-									$class = 'text-left';
511
+                                    $class = 'text-left';
512 512
 
513
-									echo "<td class='p-2 $class'>";
513
+                                    echo "<td class='p-2 $class'>";
514 514
 
515
-										switch( $key ) {
515
+                                        switch( $key ) {
516 516
 
517
-											case 'total':
518
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
519
-												break;
517
+                                            case 'total':
518
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
519
+                                                break;
520 520
 
521
-											case 'relationship':
522
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
523
-												break;
521
+                                            case 'relationship':
522
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
523
+                                                break;
524 524
 
525
-											case 'date':
526
-												echo getpaid_format_date_value( $payment->get_date_created() );
527
-												break;
525
+                                            case 'date':
526
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
527
+                                                break;
528 528
 
529
-											case 'status':
529
+                                            case 'status':
530 530
 
531
-												$status = $payment->get_status_nicename();
532
-												if ( is_admin() ) {
533
-													$status = $payment->get_status_label_html();
534
-												}
531
+                                                $status = $payment->get_status_nicename();
532
+                                                if ( is_admin() ) {
533
+                                                    $status = $payment->get_status_label_html();
534
+                                                }
535 535
 
536
-												echo $status;
537
-												break;
536
+                                                echo $status;
537
+                                                break;
538 538
 
539
-											case 'invoice':
540
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
539
+                                            case 'invoice':
540
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
541 541
 
542
-												if ( ! is_admin() ) {
543
-													$link = esc_url( $payment->get_view_url() );
544
-												}
542
+                                                if ( ! is_admin() ) {
543
+                                                    $link = esc_url( $payment->get_view_url() );
544
+                                                }
545 545
 
546
-												$invoice = esc_html( $payment->get_number() );
547
-												echo "<a href='$link'>$invoice</a>";
548
-												break;
549
-										}
546
+                                                $invoice = esc_html( $payment->get_number() );
547
+                                                echo "<a href='$link'>$invoice</a>";
548
+                                                break;
549
+                                        }
550 550
 
551
-									echo '</td>';
551
+                                    echo '</td>';
552 552
 
553
-								}
553
+                                }
554 554
 
555
-							echo '</tr>';
555
+                            echo '</tr>';
556 556
 
557
-						endforeach;
558
-					?>
557
+                        endforeach;
558
+                    ?>
559 559
 
560 560
 				</tbody>
561 561
 
@@ -573,42 +573,42 @@  discard block
 block discarded – undo
573 573
  */
574 574
 function getpaid_admin_subscription_item_details_metabox( $subscription ) {
575 575
 
576
-	// Fetch the subscription group.
577
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
576
+    // Fetch the subscription group.
577
+    $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
578 578
 
579
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
580
-		return;
581
-	}
579
+    if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
580
+        return;
581
+    }
582 582
 
583
-	// Prepare table columns.
584
-	$columns = apply_filters(
585
-		'getpaid_subscription_item_details_columns',
586
-		array(
587
-			'item_name'    => __( 'Item', 'invoicing' ),
588
-			'price'        => __( 'Price', 'invoicing' ),
589
-			'tax'          => __( 'Tax', 'invoicing' ),
590
-			'discount'     => __( 'Discount', 'invoicing' ),
591
-			//'initial'      => __( 'Initial Amount', 'invoicing' ),
592
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
593
-		),
594
-		$subscription
595
-	);
583
+    // Prepare table columns.
584
+    $columns = apply_filters(
585
+        'getpaid_subscription_item_details_columns',
586
+        array(
587
+            'item_name'    => __( 'Item', 'invoicing' ),
588
+            'price'        => __( 'Price', 'invoicing' ),
589
+            'tax'          => __( 'Tax', 'invoicing' ),
590
+            'discount'     => __( 'Discount', 'invoicing' ),
591
+            //'initial'      => __( 'Initial Amount', 'invoicing' ),
592
+            'recurring'    => __( 'Subtotal', 'invoicing' ),
593
+        ),
594
+        $subscription
595
+    );
596 596
 
597
-	// Prepare the invoices.
597
+    // Prepare the invoices.
598 598
 
599
-	$invoice = $subscription->get_parent_invoice();
599
+    $invoice = $subscription->get_parent_invoice();
600 600
 
601
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
602
-		unset( $columns['tax'] );
603
-	}
601
+    if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
602
+        unset( $columns['tax'] );
603
+    }
604 604
 
605
-	$table_class = 'w-100 bg-white';
605
+    $table_class = 'w-100 bg-white';
606 606
 
607
-	if ( ! is_admin() ) {
608
-		$table_class = 'table table-bordered';
609
-	}
607
+    if ( ! is_admin() ) {
608
+        $table_class = 'table table-bordered';
609
+    }
610 610
 
611
-	?>
611
+    ?>
612 612
 		<div class="m-0" style="overflow: auto;">
613 613
 
614 614
 			<table class="<?php echo $table_class; ?>">
@@ -617,14 +617,14 @@  discard block
 block discarded – undo
617 617
 					<tr>
618 618
 						<?php
619 619
 
620
-							foreach ( $columns as $key => $label ) {
621
-								$key   = esc_attr( $key );
622
-								$label = esc_html( $label );
623
-								$class = 'text-left';
620
+                            foreach ( $columns as $key => $label ) {
621
+                                $key   = esc_attr( $key );
622
+                                $label = esc_html( $label );
623
+                                $class = 'text-left';
624 624
 
625
-								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
626
-							}
627
-						?>
625
+                                echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
626
+                            }
627
+                        ?>
628 628
 					</tr>
629 629
 				</thead>
630 630
 
@@ -632,106 +632,106 @@  discard block
 block discarded – undo
632 632
 
633 633
 					<?php
634 634
 
635
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
635
+                        foreach( $subscription_group['items'] as $subscription_group_item ) :
636 636
 
637
-							echo '<tr>';
637
+                            echo '<tr>';
638 638
 
639
-								foreach ( array_keys( $columns ) as $key ) {
639
+                                foreach ( array_keys( $columns ) as $key ) {
640 640
 
641
-									$class = 'text-left';
641
+                                    $class = 'text-left';
642 642
 
643
-									echo "<td class='p-2 $class'>";
643
+                                    echo "<td class='p-2 $class'>";
644 644
 
645
-										switch( $key ) {
645
+                                        switch( $key ) {
646 646
 
647
-											case 'item_name':
648
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
649
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
647
+                                            case 'item_name':
648
+                                                $item_name = get_the_title( $subscription_group_item['item_id'] );
649
+                                                $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
650 650
 
651
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
652
-													echo esc_html( $item_name );
653
-												} else {
654
-													printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] );
655
-												}
651
+                                                if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
652
+                                                    echo esc_html( $item_name );
653
+                                                } else {
654
+                                                    printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] );
655
+                                                }
656 656
 
657
-												break;
657
+                                                break;
658 658
 
659
-											case 'price':
660
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
661
-												break;
659
+                                            case 'price':
660
+                                                echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
661
+                                                break;
662 662
 
663
-											case 'tax':
664
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
665
-												break;
663
+                                            case 'tax':
664
+                                                echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
665
+                                                break;
666 666
 
667
-											case 'discount':
668
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
669
-												break;
667
+                                            case 'discount':
668
+                                                echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
669
+                                                break;
670 670
 
671
-											case 'initial':
672
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
673
-												break;
671
+                                            case 'initial':
672
+                                                echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
673
+                                                break;
674 674
 
675
-											case 'recurring':
676
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
677
-												break;
675
+                                            case 'recurring':
676
+                                                echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
677
+                                                break;
678 678
 
679
-										}
679
+                                        }
680 680
 
681
-									echo '</td>';
681
+                                    echo '</td>';
682 682
 
683
-								}
683
+                                }
684 684
 
685
-							echo '</tr>';
685
+                            echo '</tr>';
686 686
 
687
-						endforeach;
687
+                        endforeach;
688 688
 
689
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
689
+                        foreach( $subscription_group['fees'] as $subscription_group_fee ) :
690 690
 
691
-							echo '<tr>';
691
+                            echo '<tr>';
692 692
 
693
-								foreach ( array_keys( $columns ) as $key ) {
693
+                                foreach ( array_keys( $columns ) as $key ) {
694 694
 
695
-									$class = 'text-left';
695
+                                    $class = 'text-left';
696 696
 
697
-									echo "<td class='p-2 $class'>";
697
+                                    echo "<td class='p-2 $class'>";
698 698
 
699
-										switch( $key ) {
699
+                                        switch( $key ) {
700 700
 
701
-											case 'item_name':
702
-												echo esc_html( $subscription_group_fee['name'] );
703
-												break;
701
+                                            case 'item_name':
702
+                                                echo esc_html( $subscription_group_fee['name'] );
703
+                                                break;
704 704
 
705
-											case 'price':
706
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
707
-												break;
705
+                                            case 'price':
706
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
707
+                                                break;
708 708
 
709
-											case 'tax':
710
-												echo "&mdash;";
711
-												break;
709
+                                            case 'tax':
710
+                                                echo "&mdash;";
711
+                                                break;
712 712
 
713
-											case 'discount':
714
-												echo "&mdash;";
715
-												break;
713
+                                            case 'discount':
714
+                                                echo "&mdash;";
715
+                                                break;
716 716
 
717
-											case 'initial':
718
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
719
-												break;
717
+                                            case 'initial':
718
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
719
+                                                break;
720 720
 
721
-											case 'recurring':
722
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
723
-												break;
721
+                                            case 'recurring':
722
+                                                echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
723
+                                                break;
724 724
 
725
-										}
725
+                                        }
726 726
 
727
-									echo '</td>';
727
+                                    echo '</td>';
728 728
 
729
-								}
729
+                                }
730 730
 
731
-							echo '</tr>';
731
+                            echo '</tr>';
732 732
 
733
-						endforeach;
734
-					?>
733
+                        endforeach;
734
+                    ?>
735 735
 
736 736
 				</tbody>
737 737
 
@@ -750,38 +750,38 @@  discard block
 block discarded – undo
750 750
  */
751 751
 function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
752 752
 
753
-	// Fetch the subscription groups.
754
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
755
-
756
-	if ( empty( $subscription_groups ) ) {
757
-		return;
758
-	}
759
-
760
-	// Prepare table columns.
761
-	$columns = apply_filters(
762
-		'getpaid_subscription_related_subscriptions_columns',
763
-		array(
764
-			'subscription'      => __( 'Subscription', 'invoicing' ),
765
-			'start_date'        => __( 'Start Date', 'invoicing' ),
766
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
767
-			'renewals'          => __( 'Payments', 'invoicing' ),
768
-			'item'              => __( 'Items', 'invoicing' ),
769
-			'status'            => __( 'Status', 'invoicing' ),
770
-		),
771
-		$subscription
772
-	);
773
-
774
-	if ( $subscription->get_status() == 'pending' ) {
775
-		unset( $columns['start_date'], $columns['renewal_date'] );
776
-	}
777
-
778
-	$table_class = 'w-100 bg-white';
779
-
780
-	if ( ! is_admin() ) {
781
-		$table_class = 'table table-bordered';
782
-	}
783
-
784
-	?>
753
+    // Fetch the subscription groups.
754
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
755
+
756
+    if ( empty( $subscription_groups ) ) {
757
+        return;
758
+    }
759
+
760
+    // Prepare table columns.
761
+    $columns = apply_filters(
762
+        'getpaid_subscription_related_subscriptions_columns',
763
+        array(
764
+            'subscription'      => __( 'Subscription', 'invoicing' ),
765
+            'start_date'        => __( 'Start Date', 'invoicing' ),
766
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
767
+            'renewals'          => __( 'Payments', 'invoicing' ),
768
+            'item'              => __( 'Items', 'invoicing' ),
769
+            'status'            => __( 'Status', 'invoicing' ),
770
+        ),
771
+        $subscription
772
+    );
773
+
774
+    if ( $subscription->get_status() == 'pending' ) {
775
+        unset( $columns['start_date'], $columns['renewal_date'] );
776
+    }
777
+
778
+    $table_class = 'w-100 bg-white';
779
+
780
+    if ( ! is_admin() ) {
781
+        $table_class = 'table table-bordered';
782
+    }
783
+
784
+    ?>
785 785
 		<div class="m-0" style="overflow: auto;">
786 786
 
787 787
 			<table class="<?php echo $table_class; ?>">
@@ -790,14 +790,14 @@  discard block
 block discarded – undo
790 790
 					<tr>
791 791
 						<?php
792 792
 
793
-							foreach ( $columns as $key => $label ) {
794
-								$key   = esc_attr( $key );
795
-								$label = esc_html( $label );
796
-								$class = 'text-left';
793
+                            foreach ( $columns as $key => $label ) {
794
+                                $key   = esc_attr( $key );
795
+                                $label = esc_html( $label );
796
+                                $class = 'text-left';
797 797
 
798
-								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
799
-							}
800
-						?>
798
+                                echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
799
+                            }
800
+                        ?>
801 801
 					</tr>
802 802
 				</thead>
803 803
 
@@ -805,74 +805,74 @@  discard block
 block discarded – undo
805 805
 
806 806
 					<?php
807 807
 
808
-						foreach( $subscription_groups as $subscription_group ) :
808
+                        foreach( $subscription_groups as $subscription_group ) :
809 809
 
810
-							// Do not list current subscription.
811
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
812
-								continue;
813
-							}
810
+                            // Do not list current subscription.
811
+                            if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
812
+                                continue;
813
+                            }
814 814
 
815
-							// Ensure the subscription exists.
816
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
815
+                            // Ensure the subscription exists.
816
+                            $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
817 817
 
818
-							if ( ! $_suscription->exists() ) {
819
-								continue;
820
-							}
818
+                            if ( ! $_suscription->exists() ) {
819
+                                continue;
820
+                            }
821 821
 
822
-							echo '<tr>';
822
+                            echo '<tr>';
823 823
 
824
-								foreach ( array_keys( $columns ) as $key ) {
824
+                                foreach ( array_keys( $columns ) as $key ) {
825 825
 
826
-									$class = 'text-left';
826
+                                    $class = 'text-left';
827 827
 
828
-									echo "<td class='p-2 $class'>";
828
+                                    echo "<td class='p-2 $class'>";
829 829
 
830
-										switch( $key ) {
830
+                                        switch( $key ) {
831 831
 
832
-											case 'status':
833
-												echo $_suscription->get_status_label_html();
834
-												break;
832
+                                            case 'status':
833
+                                                echo $_suscription->get_status_label_html();
834
+                                                break;
835 835
 
836
-											case 'item':
837
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
838
-												echo implode( ' | ', $markup );
839
-												break;
836
+                                            case 'item':
837
+                                                $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
838
+                                                echo implode( ' | ', $markup );
839
+                                                break;
840 840
 
841
-											case 'renewals':
842
-												$max_bills = $_suscription->get_bill_times();
843
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
844
-												break;
841
+                                            case 'renewals':
842
+                                                $max_bills = $_suscription->get_bill_times();
843
+                                                echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
844
+                                                break;
845 845
 
846
-											case 'renewal_date':
847
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
848
-												break;
846
+                                            case 'renewal_date':
847
+                                                echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
848
+                                                break;
849 849
 
850
-											case 'start_date':
851
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
852
-												break;
850
+                                            case 'start_date':
851
+                                                echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
852
+                                                break;
853 853
 
854
-											case 'subscription':
855
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
856
-												printf(
857
-													'%1$s#%2$s%3$s',
858
-													'<a href="' . esc_url( $url ) . '">',
859
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
860
-													'</a>'
861
-												);
854
+                                            case 'subscription':
855
+                                                $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
856
+                                                printf(
857
+                                                    '%1$s#%2$s%3$s',
858
+                                                    '<a href="' . esc_url( $url ) . '">',
859
+                                                    '<strong>' . intval( $_suscription->get_id() ) . '</strong>',
860
+                                                    '</a>'
861
+                                                );
862 862
 
863
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
864
-												break;
863
+                                                echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
864
+                                                break;
865 865
 
866
-										}
866
+                                        }
867 867
 
868
-									echo '</td>';
868
+                                    echo '</td>';
869 869
 
870
-								}
870
+                                }
871 871
 
872
-							echo '</tr>';
872
+                            echo '</tr>';
873 873
 
874
-						endforeach;
875
-					?>
874
+                        endforeach;
875
+                    ?>
876 876
 
877 877
 				</tbody>
878 878
 
Please login to merge, or discard this patch.
includes/class-bp-getpaid-component.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class BP_GetPaid_Component extends BP_Component {
19 19
 
20
-	/**
21
-	 * Start the component setup process.
22
-	 *
23
-	 * @since 2.1.5
24
-	 */
25
-	public function __construct() {
26
-		parent::start(
27
-			'getpaid',
28
-			'GetPaid',
29
-			buddypress()->plugin_dir,
30
-			array(
31
-				'adminbar_myaccount_order' => 30,
32
-			)
33
-		);
34
-	}
20
+    /**
21
+     * Start the component setup process.
22
+     *
23
+     * @since 2.1.5
24
+     */
25
+    public function __construct() {
26
+        parent::start(
27
+            'getpaid',
28
+            'GetPaid',
29
+            buddypress()->plugin_dir,
30
+            array(
31
+                'adminbar_myaccount_order' => 30,
32
+            )
33
+        );
34
+    }
35 35
 
36 36
     /**
37
-	 * Set up component global variables.
38
-	 *
39
-	 * @since 2.1.5
40
-	 *
41
-	 *
42
-	 * @param array $args {
43
-	 *     All values are optional.
44
-	 *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
-	 *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
-	 *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
-	 *                                           component has a root directory (the slug will be overridden by the
48
-	 *                                           post_name of the directory page). Default: the slug of the directory page
49
-	 *                                           if one is found, otherwise an empty string.
50
-	 *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
-	 *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
-	 *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
-	 *                                           'Search Groups...'.
54
-	 *     @type array    $global_tables         Optional. An array of database table names.
55
-	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56
-	 * }
57
-	 */
58
-	public function setup_globals( $args = array() ) {
37
+     * Set up component global variables.
38
+     *
39
+     * @since 2.1.5
40
+     *
41
+     *
42
+     * @param array $args {
43
+     *     All values are optional.
44
+     *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
+     *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
+     *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
+     *                                           component has a root directory (the slug will be overridden by the
48
+     *                                           post_name of the directory page). Default: the slug of the directory page
49
+     *                                           if one is found, otherwise an empty string.
50
+     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
+     *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
+     *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
+     *                                           'Search Groups...'.
54
+     *     @type array    $global_tables         Optional. An array of database table names.
55
+     *     @type array    $meta_tables           Optional. An array of metadata table names.
56
+     * }
57
+     */
58
+    public function setup_globals( $args = array() ) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
                 'has_directory' => false
65 65
             )
66 66
         );
67
-	}
68
-
69
-	/**
70
-	 * Set up component navigation.
71
-	 *
72
-	 * @since 2.1.5
73
-	 *
74
-	 * @see BP_Component::setup_nav() for a description of arguments.
75
-	 *
76
-	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
-	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
-	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
-
81
-		// Abort if the integration is inactive.
67
+    }
68
+
69
+    /**
70
+     * Set up component navigation.
71
+     *
72
+     * @since 2.1.5
73
+     *
74
+     * @see BP_Component::setup_nav() for a description of arguments.
75
+     *
76
+     * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
+     * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
+     */
79
+    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
+
81
+        // Abort if the integration is inactive.
82 82
         if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
83 83
             return;
84 84
         }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
             return;
89 89
         }
90 90
 
91
-		// Determine user to use.
92
-		$user_domain   = bp_loggedin_user_domain();
93
-		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
95
-
96
-		// Add 'Payments' to the main navigation.
97
-		$main_nav = array(
98
-			'name'                => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
-			'slug'                => $slug,
100
-			'position'            => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'     => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
91
+        // Determine user to use.
92
+        $user_domain   = bp_loggedin_user_domain();
93
+        $slug          = 'getpaid';
94
+        $payments_link = trailingslashit( $user_domain . $slug );
95
+
96
+        // Add 'Payments' to the main navigation.
97
+        $main_nav = array(
98
+            'name'                => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
+            'slug'                => $slug,
100
+            'position'            => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
+            'screen_function'     => array( $this, 'display_current_tab' ),
102
+            'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
103 103
             'show_for_displayed_user' => false,
104
-			'item_css_id'         => $this->id,
105
-			'parent_url'          => $user_domain,
106
-			'parent_slug'         => buddypress()->slug,
107
-		);
104
+            'item_css_id'         => $this->id,
105
+            'parent_url'          => $user_domain,
106
+            'parent_slug'         => buddypress()->slug,
107
+        );
108 108
 
109
-		// Add the subnav items to the payments nav item if we are using a theme that supports this.
109
+        // Add the subnav items to the payments nav item if we are using a theme that supports this.
110 110
         foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
111 111
 
112 112
             $sub_nav[] = array(
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
                 'parent_slug'     => $slug,
117 117
                 'position' => 10,
118 118
                 'screen_function'        => function() use ( $tab ) {
119
-					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120
-					$this->display_current_tab();
119
+                    $GLOBALS['getpaid_bp_current_tab'] = $tab;
120
+                    $this->display_current_tab();
121 121
                 },
122 122
                 'show_for_displayed_user' => false,
123 123
                 'item_css_id'             => "getpaid-bp-$_slug",
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
129
-	}
130
-
131
-	/**
132
-	 * Set up the component entries in the WordPress Admin Bar.
133
-	 *
134
-	 * @since 2.1.5
135
-	 *
136
-	 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
-	 *      parameter array.
138
-	 *
139
-	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
-	 *                            description.
141
-	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
143
-
144
-		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
128
+        parent::setup_nav( $main_nav, $sub_nav );
129
+    }
146 130
 
147
-			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
131
+    /**
132
+     * Set up the component entries in the WordPress Admin Bar.
133
+     *
134
+     * @since 2.1.5
135
+     *
136
+     * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
+     *      parameter array.
138
+     *
139
+     * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
+     *                            description.
141
+     */
142
+    public function setup_admin_bar( $wp_admin_nav = array() ) {
143
+
144
+        // Menus for logged in user.
145
+        if ( is_user_logged_in() ) {
146
+
147
+            // Setup the logged in user variables.
148
+            $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
@@ -167,50 +167,50 @@  discard block
 block discarded – undo
167 167
 
168 168
             }
169 169
 
170
-		}
171
-
172
-		parent::setup_admin_bar( $wp_admin_nav );
173
-	}
170
+        }
174 171
 
175
-	/**
176
-	 * Retrieves the current tab.
177
-	 *
178
-	 * @since 2.1.5
179
-	 */
180
-	public function get_current_tab() {
181
-		global $getpaid_bp_current_tab;
172
+        parent::setup_admin_bar( $wp_admin_nav );
173
+    }
182 174
 
183
-		if ( empty( $getpaid_bp_current_tab ) ) {
184
-			return array(
185
-				'label'     => __( 'Invoices', 'invoicing' ),
186
-				'content'   => '[wpinv_history]',
187
-				'icon'      => 'fas fa-file-invoice',
188
-			);
189
-		}
175
+    /**
176
+     * Retrieves the current tab.
177
+     *
178
+     * @since 2.1.5
179
+     */
180
+    public function get_current_tab() {
181
+        global $getpaid_bp_current_tab;
182
+
183
+        if ( empty( $getpaid_bp_current_tab ) ) {
184
+            return array(
185
+                'label'     => __( 'Invoices', 'invoicing' ),
186
+                'content'   => '[wpinv_history]',
187
+                'icon'      => 'fas fa-file-invoice',
188
+            );
189
+        }
190 190
 
191
-		return $getpaid_bp_current_tab;
192
-	}
191
+        return $getpaid_bp_current_tab;
192
+    }
193 193
 
194
-	/**
195
-	 * Displays the current tab.
196
-	 *
197
-	 * @since 2.1.5
198
-	 */
199
-	public function display_current_tab() {
194
+    /**
195
+     * Displays the current tab.
196
+     *
197
+     * @since 2.1.5
198
+     */
199
+    public function display_current_tab() {
200 200
 
201
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
202
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
201
+        add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
202
+        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
203 203
 
204 204
         bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
205
-	}
206
-
207
-	/**
208
-	 * Handles the actual display of the current tab.
209
-	 *
210
-	 * @since 2.1.5
211
-	 */
212
-	public function handle_display_current_tab() {
213
-		echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
214
-	}
205
+    }
206
+
207
+    /**
208
+     * Handles the actual display of the current tab.
209
+     *
210
+     * @since 2.1.5
211
+     */
212
+    public function handle_display_current_tab() {
213
+        echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
214
+    }
215 215
 
216 216
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -12,167 +12,167 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Discount {
14 14
 
15
-	/**
16
-	 * Submission discounts.
17
-	 * @var array
18
-	 */
19
-	public $discounts = array();
15
+    /**
16
+     * Submission discounts.
17
+     * @var array
18
+     */
19
+    public $discounts = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     * @param float                           $initial_total
26
+     * @param float                           $recurring_total
27
+     */
28
+    public function __construct( $submission, $initial_total, $recurring_total ) {
29
+
30
+        // Process any existing invoice discounts.
31
+        if ( $submission->has_invoice() ) {
32
+            $this->discounts = $submission->get_invoice()->get_discounts();
33
+        }
34
+
35
+        // Do we have a discount?
36
+        $discount = $submission->get_field( 'discount' );
37
+
38
+        if ( empty( $discount ) ) {
39
+
40
+            if ( isset( $this->discounts['discount_code'] ) ) {
41
+                unset( $this->discounts['discount_code'] );
42
+            }
43
+
44
+            return;
45
+        }
46
+
47
+        // Processes the discount code.
48
+        $amount = max( $initial_total, $recurring_total );
49
+        $this->process_discount( $submission, $discount, $amount );
50
+
51
+    }
20 52
 
21 53
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 * @param float                           $initial_total
26
-	 * @param float                           $recurring_total
27
-	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
29
-
30
-		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
32
-			$this->discounts = $submission->get_invoice()->get_discounts();
33
-		}
34
-
35
-		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
37
-
38
-		if ( empty( $discount ) ) {
39
-
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
42
-			}
43
-
44
-			return;
45
-		}
46
-
47
-		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Processes a submission discount.
55
-	 *
56
-	 * @param GetPaid_Payment_Form_Submission $submission
57
-	 * @param string                          $discount
58
-	 * @param float                           $amount
59
-	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
61
-
62
-		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
64
-
65
-		// Ensure it is active.
54
+     * Processes a submission discount.
55
+     *
56
+     * @param GetPaid_Payment_Form_Submission $submission
57
+     * @param string                          $discount
58
+     * @param float                           $amount
59
+     */
60
+    public function process_discount( $submission, $discount, $amount ) {
61
+
62
+        // Fetch the discount.
63
+        $discount = new WPInv_Discount( $discount );
64
+
65
+        // Ensure it is active.
66 66
         if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
-		}
69
-
70
-		// Required items.
71
-		if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) {
72
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) );
73
-		}
74
-
75
-		// Exceeded limit.
76
-		if ( $discount->has_exceeded_limit() ) {
77
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
78
-		}
79
-
80
-		// Validate usages.
81
-		$this->validate_single_use_discount( $submission, $discount );
82
-
83
-		// Validate amount.
84
-		$this->validate_discount_amount( $submission, $discount, $amount );
85
-
86
-		// Save the discount.
87
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
88
-	}
89
-
90
-	/**
91
-	 * Validates a single use discount.
92
-	 *
93
-	 * @param WPInv_Discount                  $discount
94
-	 * @return bool
95
-	 */
96
-	public function is_discount_active(  $discount ) {
97
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
98
-	}
99
-
100
-	/**
101
-	 * Returns a user's id or email.
102
-	 *
103
-	 * @param string $email
104
-	 * @return int|string|false
105
-	 */
106
-	public function get_user_id_or_email( $email ) {
107
-
108
-		if ( is_user_logged_in() ) {
109
-			return get_current_user_id();
110
-		}
111
-
112
-		return empty( $email ) ? false : sanitize_email( $email );
113
-	}
114
-
115
-	/**
116
-	 * Validates a single use discount.
117
-	 *
118
-	 * @param GetPaid_Payment_Form_Submission $submission
119
-	 * @param WPInv_Discount                  $discount
120
-	 */
121
-	public function validate_single_use_discount( $submission, $discount ) {
122
-
123
-		// Abort if it is not a single use discount.
124
-		if ( ! $discount->is_single_use() ) {
125
-			return;
126
-		}
127
-
128
-		// Ensure there is a valid billing email.
129
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
130
-
131
-		if ( empty( $user ) ) {
132
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
133
-		}
134
-
135
-		// Has the user used this discount code before?
136
-		if ( ! $discount->is_valid_for_user( $user ) ) {
137
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
138
-		}
139
-
140
-	}
141
-
142
-	/**
143
-	 * Validates the discount's amount.
144
-	 *
145
-	 * @param GetPaid_Payment_Form_Submission $submission
146
-	 * @param WPInv_Discount         $discount
147
-	 * @param float                  $amount
148
-	 */
149
-	public function validate_discount_amount( $submission, $discount, $amount ) {
150
-
151
-		// Validate minimum amount.
152
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
153
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
154
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
155
-		}
156
-
157
-		// Validate the maximum amount.
158
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
159
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
160
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
161
-		}
162
-
163
-	}
164
-
165
-	/**
166
-	 * Calculates the discount code's amount.
167
-	 *
168
-	 * Ensure that the discount exists and has been validated before calling this method.
169
-	 *
170
-	 * @param GetPaid_Payment_Form_Submission $submission
171
-	 * @param WPInv_Discount                  $discount
172
-	 * @return array
173
-	 */
174
-	public function calculate_discount( $submission, $discount ) {
175
-		return getpaid_calculate_invoice_discount( $submission, $discount );
176
-	}
67
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Required items.
71
+        if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) {
72
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) );
73
+        }
74
+
75
+        // Exceeded limit.
76
+        if ( $discount->has_exceeded_limit() ) {
77
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
78
+        }
79
+
80
+        // Validate usages.
81
+        $this->validate_single_use_discount( $submission, $discount );
82
+
83
+        // Validate amount.
84
+        $this->validate_discount_amount( $submission, $discount, $amount );
85
+
86
+        // Save the discount.
87
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
88
+    }
89
+
90
+    /**
91
+     * Validates a single use discount.
92
+     *
93
+     * @param WPInv_Discount                  $discount
94
+     * @return bool
95
+     */
96
+    public function is_discount_active(  $discount ) {
97
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
98
+    }
99
+
100
+    /**
101
+     * Returns a user's id or email.
102
+     *
103
+     * @param string $email
104
+     * @return int|string|false
105
+     */
106
+    public function get_user_id_or_email( $email ) {
107
+
108
+        if ( is_user_logged_in() ) {
109
+            return get_current_user_id();
110
+        }
111
+
112
+        return empty( $email ) ? false : sanitize_email( $email );
113
+    }
114
+
115
+    /**
116
+     * Validates a single use discount.
117
+     *
118
+     * @param GetPaid_Payment_Form_Submission $submission
119
+     * @param WPInv_Discount                  $discount
120
+     */
121
+    public function validate_single_use_discount( $submission, $discount ) {
122
+
123
+        // Abort if it is not a single use discount.
124
+        if ( ! $discount->is_single_use() ) {
125
+            return;
126
+        }
127
+
128
+        // Ensure there is a valid billing email.
129
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
130
+
131
+        if ( empty( $user ) ) {
132
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
133
+        }
134
+
135
+        // Has the user used this discount code before?
136
+        if ( ! $discount->is_valid_for_user( $user ) ) {
137
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
138
+        }
139
+
140
+    }
141
+
142
+    /**
143
+     * Validates the discount's amount.
144
+     *
145
+     * @param GetPaid_Payment_Form_Submission $submission
146
+     * @param WPInv_Discount         $discount
147
+     * @param float                  $amount
148
+     */
149
+    public function validate_discount_amount( $submission, $discount, $amount ) {
150
+
151
+        // Validate minimum amount.
152
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
153
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
154
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
155
+        }
156
+
157
+        // Validate the maximum amount.
158
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
159
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
160
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
161
+        }
162
+
163
+    }
164
+
165
+    /**
166
+     * Calculates the discount code's amount.
167
+     *
168
+     * Ensure that the discount exists and has been validated before calling this method.
169
+     *
170
+     * @param GetPaid_Payment_Form_Submission $submission
171
+     * @param WPInv_Discount                  $discount
172
+     * @return array
173
+     */
174
+    public function calculate_discount( $submission, $discount ) {
175
+        return getpaid_calculate_invoice_discount( $submission, $discount );
176
+    }
177 177
 
178 178
 }
Please login to merge, or discard this patch.
includes/data/discount-schema.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -13,177 +13,177 @@
 block discarded – undo
13 13
 
14 14
 return array(
15 15
 
16
-	'id'              => array(
17
-		'description' => __( 'Unique identifier for the discount.', 'invoicing' ),
18
-		'type'        => 'integer',
19
-		'context'     => array( 'view', 'edit', 'embed' ),
20
-		'readonly'    => true,
21
-	),
22
-
23
-	'status'          => array(
24
-		'description' => __( 'A named status for the discount.', 'invoicing' ),
25
-		'type'        => 'string',
26
-		'enum'        => array( 'publish', 'pending', 'draft', 'expired' ),
27
-		'default'     => 'draft',
28
-		'context'     => array( 'view', 'edit', 'embed' ),
29
-	),
30
-
31
-	'version'         => array(
32
-		'description' => __( 'Plugin version when the discount was created.', 'invoicing' ),
33
-		'type'        => 'string',
34
-		'context'     => array( 'view', 'edit', 'embed' ),
35
-		'readonly'    => true,
36
-	),
37
-
38
-	'date_created'    => array(
39
-		'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ),
40
-		'type'        => 'string',
41
-		'context'     => array( 'view', 'edit', 'embed' ),
42
-	),
43
-
44
-	'date_created_gmt'    => array(
45
-		'description' => __( 'The GMT date the discount was created.', 'invoicing' ),
46
-		'type'        => 'string',
47
-		'context'     => array( 'view', 'edit', 'embed' ),
48
-		'readonly'    => true,
49
-	),
50
-
51
-	'date_modified'   => array(
52
-		'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ),
53
-		'type'        => 'string',
54
-		'context'     => array( 'view', 'edit', 'embed' ),
55
-		'readonly'    => true,
56
-	),
57
-
58
-	'date_modified_gmt'    => array(
59
-		'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ),
60
-		'type'        => 'string',
61
-		'context'     => array( 'view', 'edit', 'embed' ),
62
-		'readonly'    => true,
63
-	),
64
-
65
-	'name'			  => array(
66
-		'description' => __( 'The discount name.', 'invoicing' ),
67
-		'type'        => 'string',
68
-		'context'     => array( 'view', 'edit', 'embed' ),
69
-	),
70
-
71
-	'description'     => array(
72
-		'description' => __( 'A description of what the discount is all about.', 'invoicing' ),
73
-		'type'        => 'string',
74
-		'context'     => array( 'view', 'edit', 'embed' ),
75
-	),
76
-
77
-	'code'            => array(
78
-		'description' => __( 'The discount code.', 'invoicing' ),
79
-		'type'        => 'string',
80
-		'context'     => array( 'view', 'edit', 'embed' ),
81
-		'required'	  => true,
82
-	),
83
-
84
-	'type'            => array(
85
-		'description' => __( 'The type of discount.', 'invoicing' ),
86
-		'type'        => 'string',
87
-		'enum'        => array_keys( wpinv_get_discount_types() ),
88
-		'context'     => array( 'view', 'edit', 'embed' ),
89
-		'default'	  => 'percent',
90
-	),
91
-
92
-	'amount'        => array(
93
-		'description' => __( 'The discount value.', 'invoicing' ),
94
-		'type'        => 'number',
95
-		'context'     => array( 'view', 'edit', 'embed' ),
96
-		'required'	  => true,
97
-	),
98
-
99
-	'formatted_amount'        => array(
100
-		'description' => __( 'The formatted discount value.', 'invoicing' ),
101
-		'type'        => 'string',
102
-		'context'     => array( 'view', 'edit', 'embed' ),
103
-		'readonly'    => true,
104
-	),
105
-
106
-	'uses'            => array(
107
-		'description' => __( 'The number of times the discount has been used.', 'invoicing' ),
108
-		'type'        => 'integer',
109
-		'context'     => array( 'view', 'embed' ),
110
-		'readonly'    => true,
111
-	),
112
-
113
-	'max_uses'        => array(
114
-		'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ),
115
-		'type'        => 'integer',
116
-		'context'     => array( 'view', 'edit' ),
117
-	),
118
-
119
-	'usage'           => array(
120
-		'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ),
121
-		'type'        => 'string',
122
-		'context'     => array( 'view', 'embed' ),
123
-		'readonly'    => true,
124
-	),
125
-
126
-	'is_single_use'   => array(
127
-		'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ),
128
-		'type'        => 'boolean',
129
-		'context'     => array( 'view', 'edit' ),
130
-	),
131
-
132
-	'is_recurring'   => array(
133
-		'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ),
134
-		'type'        => 'boolean',
135
-		'context'     => array( 'view', 'edit' ),
136
-	),
137
-
138
-	'start_date'      => array(
139
-		'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ),
140
-		'type'        => 'string',
141
-		'context'     => array( 'view', 'edit' ),
142
-	),
143
-
144
-	'end_date'        => array(
145
-		'description' => __( 'The expiration date for the discount.', 'invoicing' ),
146
-		'type'        => 'string',
147
-		'context'     => array( 'view', 'edit' ),
148
-	),
149
-
150
-	'allowed_items'   => array(
151
-		'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ),
152
-		'type'        => 'array',
153
-		'context'     => array( 'view', 'edit' ),
154
-		'items'       => array(
155
-			'type'    => 'integer'
156
-		)
157
-	),
158
-
159
-	'excluded_items'  => array(
160
-		'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ),
161
-		'type'        => 'array',
162
-		'context'     => array( 'view', 'edit' ),
163
-		'items'       => array(
164
-			'type'    => 'integer'
165
-		)
166
-	),
167
-
168
-	'required_items'  => array(
169
-		'description' => __( 'Items which are required to be in the cart before using this discount.', 'invoicing' ),
170
-		'type'        => 'array',
171
-		'context'     => array( 'view', 'edit' ),
172
-		'items'       => array(
173
-			'type'    => 'integer'
174
-		)
175
-	),
176
-
177
-	'minimum_total'   => array(
178
-		'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ),
179
-		'type'        => 'number',
180
-		'context'     => array( 'view', 'edit' ),
181
-	),
182
-
183
-	'maximum_total'   => array(
184
-		'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ),
185
-		'type'        => 'number',
186
-		'context'     => array( 'view', 'edit' ),
187
-	),
16
+    'id'              => array(
17
+        'description' => __( 'Unique identifier for the discount.', 'invoicing' ),
18
+        'type'        => 'integer',
19
+        'context'     => array( 'view', 'edit', 'embed' ),
20
+        'readonly'    => true,
21
+    ),
22
+
23
+    'status'          => array(
24
+        'description' => __( 'A named status for the discount.', 'invoicing' ),
25
+        'type'        => 'string',
26
+        'enum'        => array( 'publish', 'pending', 'draft', 'expired' ),
27
+        'default'     => 'draft',
28
+        'context'     => array( 'view', 'edit', 'embed' ),
29
+    ),
30
+
31
+    'version'         => array(
32
+        'description' => __( 'Plugin version when the discount was created.', 'invoicing' ),
33
+        'type'        => 'string',
34
+        'context'     => array( 'view', 'edit', 'embed' ),
35
+        'readonly'    => true,
36
+    ),
37
+
38
+    'date_created'    => array(
39
+        'description' => __( "The date the discount was created, in the site's timezone.", 'invoicing' ),
40
+        'type'        => 'string',
41
+        'context'     => array( 'view', 'edit', 'embed' ),
42
+    ),
43
+
44
+    'date_created_gmt'    => array(
45
+        'description' => __( 'The GMT date the discount was created.', 'invoicing' ),
46
+        'type'        => 'string',
47
+        'context'     => array( 'view', 'edit', 'embed' ),
48
+        'readonly'    => true,
49
+    ),
50
+
51
+    'date_modified'   => array(
52
+        'description' => __( "The date the discount was last modified, in the site's timezone.", 'invoicing' ),
53
+        'type'        => 'string',
54
+        'context'     => array( 'view', 'edit', 'embed' ),
55
+        'readonly'    => true,
56
+    ),
57
+
58
+    'date_modified_gmt'    => array(
59
+        'description' => __( 'The GMT date the discount was last modified.', 'invoicing' ),
60
+        'type'        => 'string',
61
+        'context'     => array( 'view', 'edit', 'embed' ),
62
+        'readonly'    => true,
63
+    ),
64
+
65
+    'name'			  => array(
66
+        'description' => __( 'The discount name.', 'invoicing' ),
67
+        'type'        => 'string',
68
+        'context'     => array( 'view', 'edit', 'embed' ),
69
+    ),
70
+
71
+    'description'     => array(
72
+        'description' => __( 'A description of what the discount is all about.', 'invoicing' ),
73
+        'type'        => 'string',
74
+        'context'     => array( 'view', 'edit', 'embed' ),
75
+    ),
76
+
77
+    'code'            => array(
78
+        'description' => __( 'The discount code.', 'invoicing' ),
79
+        'type'        => 'string',
80
+        'context'     => array( 'view', 'edit', 'embed' ),
81
+        'required'	  => true,
82
+    ),
83
+
84
+    'type'            => array(
85
+        'description' => __( 'The type of discount.', 'invoicing' ),
86
+        'type'        => 'string',
87
+        'enum'        => array_keys( wpinv_get_discount_types() ),
88
+        'context'     => array( 'view', 'edit', 'embed' ),
89
+        'default'	  => 'percent',
90
+    ),
91
+
92
+    'amount'        => array(
93
+        'description' => __( 'The discount value.', 'invoicing' ),
94
+        'type'        => 'number',
95
+        'context'     => array( 'view', 'edit', 'embed' ),
96
+        'required'	  => true,
97
+    ),
98
+
99
+    'formatted_amount'        => array(
100
+        'description' => __( 'The formatted discount value.', 'invoicing' ),
101
+        'type'        => 'string',
102
+        'context'     => array( 'view', 'edit', 'embed' ),
103
+        'readonly'    => true,
104
+    ),
105
+
106
+    'uses'            => array(
107
+        'description' => __( 'The number of times the discount has been used.', 'invoicing' ),
108
+        'type'        => 'integer',
109
+        'context'     => array( 'view', 'embed' ),
110
+        'readonly'    => true,
111
+    ),
112
+
113
+    'max_uses'        => array(
114
+        'description' => __( 'The maximum number of times the discount can be used.', 'invoicing' ),
115
+        'type'        => 'integer',
116
+        'context'     => array( 'view', 'edit' ),
117
+    ),
118
+
119
+    'usage'           => array(
120
+        'description' => __( "The discount's usage, i.e uses / max uses.", 'invoicing' ),
121
+        'type'        => 'string',
122
+        'context'     => array( 'view', 'embed' ),
123
+        'readonly'    => true,
124
+    ),
125
+
126
+    'is_single_use'   => array(
127
+        'description' => __( 'Whether or not the discount can only be used once per user.', 'invoicing' ),
128
+        'type'        => 'boolean',
129
+        'context'     => array( 'view', 'edit' ),
130
+    ),
131
+
132
+    'is_recurring'   => array(
133
+        'description' => __( 'Whether or not the discount applies to the initial payment only or all recurring payments.', 'invoicing' ),
134
+        'type'        => 'boolean',
135
+        'context'     => array( 'view', 'edit' ),
136
+    ),
137
+
138
+    'start_date'      => array(
139
+        'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss. If provided, the discount can only be used after or on this date.', 'invoicing' ),
140
+        'type'        => 'string',
141
+        'context'     => array( 'view', 'edit' ),
142
+    ),
143
+
144
+    'end_date'        => array(
145
+        'description' => __( 'The expiration date for the discount.', 'invoicing' ),
146
+        'type'        => 'string',
147
+        'context'     => array( 'view', 'edit' ),
148
+    ),
149
+
150
+    'allowed_items'   => array(
151
+        'description' => __( 'Items which are allowed to use this discount. Leave blank to enable for all items.', 'invoicing' ),
152
+        'type'        => 'array',
153
+        'context'     => array( 'view', 'edit' ),
154
+        'items'       => array(
155
+            'type'    => 'integer'
156
+        )
157
+    ),
158
+
159
+    'excluded_items'  => array(
160
+        'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ),
161
+        'type'        => 'array',
162
+        'context'     => array( 'view', 'edit' ),
163
+        'items'       => array(
164
+            'type'    => 'integer'
165
+        )
166
+    ),
167
+
168
+    'required_items'  => array(
169
+        'description' => __( 'Items which are required to be in the cart before using this discount.', 'invoicing' ),
170
+        'type'        => 'array',
171
+        'context'     => array( 'view', 'edit' ),
172
+        'items'       => array(
173
+            'type'    => 'integer'
174
+        )
175
+    ),
176
+
177
+    'minimum_total'   => array(
178
+        'description' => __( 'The minimum total needed to use this invoice.', 'invoicing' ),
179
+        'type'        => 'number',
180
+        'context'     => array( 'view', 'edit' ),
181
+    ),
182
+
183
+    'maximum_total'   => array(
184
+        'description' => __( 'The maximum total needed to use this invoice.', 'invoicing' ),
185
+        'type'        => 'number',
186
+        'context'     => array( 'view', 'edit' ),
187
+    ),
188 188
 
189 189
 );
Please login to merge, or discard this patch.