@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | final class WPInv_Invoice { |
| 15 | - public $ID = 0; |
|
| 15 | + public $ID = 0; |
|
| 16 | 16 | public $title; |
| 17 | 17 | public $post_type; |
| 18 | 18 | |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | public $full_name = ''; |
| 67 | 67 | public $parent_invoice = 0; |
| 68 | 68 | |
| 69 | - public function __construct( $invoice_id = false ) { |
|
| 70 | - if( empty( $invoice_id ) ) { |
|
| 69 | + public function __construct($invoice_id = false) { |
|
| 70 | + if (empty($invoice_id)) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->setup_invoice( $invoice_id ); |
|
| 74 | + $this->setup_invoice($invoice_id); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function get( $key ) { |
|
| 78 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 79 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
| 77 | + public function get($key) { |
|
| 78 | + if (method_exists($this, 'get_' . $key)) { |
|
| 79 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
| 80 | 80 | } else { |
| 81 | 81 | $value = $this->$key; |
| 82 | 82 | } |
@@ -84,51 +84,51 @@ discard block |
||
| 84 | 84 | return $value; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function set( $key, $value ) { |
|
| 88 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
| 87 | + public function set($key, $value) { |
|
| 88 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
| 89 | 89 | |
| 90 | - if ( $key === 'status' ) { |
|
| 90 | + if ($key === 'status') { |
|
| 91 | 91 | $this->old_status = $this->status; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ( ! in_array( $key, $ignore ) ) { |
|
| 95 | - $this->pending[ $key ] = $value; |
|
| 94 | + if (!in_array($key, $ignore)) { |
|
| 95 | + $this->pending[$key] = $value; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if( '_ID' !== $key ) { |
|
| 98 | + if ('_ID' !== $key) { |
|
| 99 | 99 | $this->$key = $value; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public function _isset( $name ) { |
|
| 104 | - if ( property_exists( $this, $name) ) { |
|
| 105 | - return false === empty( $this->$name ); |
|
| 103 | + public function _isset($name) { |
|
| 104 | + if (property_exists($this, $name)) { |
|
| 105 | + return false === empty($this->$name); |
|
| 106 | 106 | } else { |
| 107 | 107 | return null; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - private function setup_invoice( $invoice_id ) { |
|
| 111 | + private function setup_invoice($invoice_id) { |
|
| 112 | 112 | $this->pending = array(); |
| 113 | 113 | |
| 114 | - if ( empty( $invoice_id ) ) { |
|
| 114 | + if (empty($invoice_id)) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $invoice = get_post( $invoice_id ); |
|
| 118 | + $invoice = get_post($invoice_id); |
|
| 119 | 119 | |
| 120 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
| 120 | + if (!$invoice || is_wp_error($invoice)) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
| 124 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
| 128 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
| 129 | 129 | |
| 130 | 130 | // Primary Identifier |
| 131 | - $this->ID = absint( $invoice_id ); |
|
| 131 | + $this->ID = absint($invoice_id); |
|
| 132 | 132 | $this->post_type = $invoice->post_type; |
| 133 | 133 | |
| 134 | 134 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | $this->completed_date = $this->setup_completed_date(); |
| 139 | 139 | $this->status = $invoice->post_status; |
| 140 | 140 | |
| 141 | - if ( 'future' == $this->status ) { |
|
| 141 | + if ('future' == $this->status) { |
|
| 142 | 142 | $this->status = 'publish'; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $this->post_status = $this->status; |
| 146 | 146 | $this->mode = $this->setup_mode(); |
| 147 | 147 | $this->parent_invoice = $invoice->post_parent; |
| 148 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
| 148 | + $this->post_name = $this->setup_post_name($invoice); |
|
| 149 | 149 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
| 150 | 150 | |
| 151 | 151 | // Items |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // User based |
| 170 | 170 | $this->ip = $this->setup_ip(); |
| 171 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
| 172 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 171 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
| 172 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 173 | 173 | |
| 174 | 174 | $this->user_info = $this->setup_user_info(); |
| 175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $this->company = $this->user_info['company']; |
| 179 | 179 | $this->vat_number = $this->user_info['vat_number']; |
| 180 | 180 | $this->vat_rate = $this->user_info['vat_rate']; |
| 181 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 181 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 182 | 182 | $this->address = $this->user_info['address']; |
| 183 | 183 | $this->city = $this->user_info['city']; |
| 184 | 184 | $this->country = $this->user_info['country']; |
@@ -193,39 +193,39 @@ discard block |
||
| 193 | 193 | // Other Identifiers |
| 194 | 194 | $this->key = $this->setup_invoice_key(); |
| 195 | 195 | $this->number = $this->setup_invoice_number(); |
| 196 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
| 196 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
| 197 | 197 | |
| 198 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
| 198 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
| 199 | 199 | |
| 200 | 200 | // Allow extensions to add items to this object via hook |
| 201 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
| 201 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
| 202 | 202 | |
| 203 | 203 | return true; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - private function setup_status_nicename( $status ) { |
|
| 207 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 206 | + private function setup_status_nicename($status) { |
|
| 207 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
| 208 | 208 | |
| 209 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 210 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 209 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
| 210 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 211 | 211 | } |
| 212 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
| 212 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
| 213 | 213 | |
| 214 | - return apply_filters( 'setup_status_nicename', $status ); |
|
| 214 | + return apply_filters('setup_status_nicename', $status); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - private function setup_post_name( $post = NULL ) { |
|
| 217 | + private function setup_post_name($post = NULL) { |
|
| 218 | 218 | global $wpdb; |
| 219 | 219 | |
| 220 | 220 | $post_name = ''; |
| 221 | 221 | |
| 222 | - if ( !empty( $post ) ) { |
|
| 223 | - if( !empty( $post->post_name ) ) { |
|
| 222 | + if (!empty($post)) { |
|
| 223 | + if (!empty($post->post_name)) { |
|
| 224 | 224 | $post_name = $post->post_name; |
| 225 | - } else if ( !empty( $post->ID ) ) { |
|
| 226 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
| 225 | + } else if (!empty($post->ID)) { |
|
| 226 | + $post_name = wpinv_generate_post_name($post->ID); |
|
| 227 | 227 | |
| 228 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
| 228 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | private function setup_due_date() { |
| 236 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
| 236 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
| 237 | 237 | |
| 238 | - if ( empty( $due_date ) ) { |
|
| 239 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
| 240 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
| 241 | - } else if ( $due_date == 'none' ) { |
|
| 238 | + if (empty($due_date)) { |
|
| 239 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
| 240 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
| 241 | + } else if ($due_date == 'none') { |
|
| 242 | 242 | $due_date = ''; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -246,67 +246,67 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | private function setup_completed_date() { |
| 249 | - $invoice = get_post( $this->ID ); |
|
| 249 | + $invoice = get_post($this->ID); |
|
| 250 | 250 | |
| 251 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
| 251 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
| 252 | 252 | return false; // This invoice was never paid |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
| 255 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
| 256 | 256 | |
| 257 | 257 | return $date; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | private function setup_cart_details() { |
| 261 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
| 261 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
| 262 | 262 | return $cart_details; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | public function array_convert() { |
| 266 | - return get_object_vars( $this ); |
|
| 266 | + return get_object_vars($this); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | private function setup_items() { |
| 270 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
| 270 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
| 271 | 271 | return $items; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | private function setup_fees() { |
| 275 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 275 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 276 | 276 | return $payment_fees; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | private function setup_currency() { |
| 280 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
| 280 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
| 281 | 281 | return $currency; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | private function setup_discount() { |
| 285 | 285 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
| 286 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
| 287 | - if ( $discount < 0 ) { |
|
| 286 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
| 287 | + if ($discount < 0) { |
|
| 288 | 288 | $discount = 0; |
| 289 | 289 | } |
| 290 | - $discount = wpinv_round_amount( $discount ); |
|
| 290 | + $discount = wpinv_round_amount($discount); |
|
| 291 | 291 | |
| 292 | 292 | return $discount; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | private function setup_discount_code() { |
| 296 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
| 296 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
| 297 | 297 | return $discount_code; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | private function setup_tax() { |
| 301 | 301 | |
| 302 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
| 302 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
| 303 | 303 | |
| 304 | 304 | // We don't have tax as it's own meta and no meta was passed |
| 305 | - if ( '' === $tax ) { |
|
| 306 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
| 305 | + if ('' === $tax) { |
|
| 306 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
| 309 | + if ($tax < 0 || !$this->is_taxable()) { |
|
| 310 | 310 | $tax = 0; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -317,16 +317,16 @@ discard block |
||
| 317 | 317 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
| 318 | 318 | */ |
| 319 | 319 | private function setup_is_taxable() { |
| 320 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
| 320 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | private function setup_subtotal() { |
| 324 | 324 | $subtotal = 0; |
| 325 | 325 | $cart_details = $this->cart_details; |
| 326 | 326 | |
| 327 | - if ( is_array( $cart_details ) ) { |
|
| 328 | - foreach ( $cart_details as $item ) { |
|
| 329 | - if ( isset( $item['subtotal'] ) ) { |
|
| 327 | + if (is_array($cart_details)) { |
|
| 328 | + foreach ($cart_details as $item) { |
|
| 329 | + if (isset($item['subtotal'])) { |
|
| 330 | 330 | $subtotal += $item['subtotal']; |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | private function setup_discounts() { |
| 343 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 343 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 344 | 344 | return $discounts; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | private function setup_total() { |
| 348 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
| 348 | + $amount = $this->get_meta('_wpinv_total', true); |
|
| 349 | 349 | |
| 350 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
| 351 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
| 352 | - $meta = maybe_unserialize( $meta ); |
|
| 350 | + if (empty($amount) && '0.00' != $amount) { |
|
| 351 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
| 352 | + $meta = maybe_unserialize($meta); |
|
| 353 | 353 | |
| 354 | - if ( isset( $meta['amount'] ) ) { |
|
| 354 | + if (isset($meta['amount'])) { |
|
| 355 | 355 | $amount = $meta['amount']; |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if($amount < 0){ |
|
| 359 | + if ($amount < 0) { |
|
| 360 | 360 | $amount = 0; |
| 361 | 361 | } |
| 362 | 362 | |
@@ -364,13 +364,13 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | private function setup_mode() { |
| 367 | - return $this->get_meta( '_wpinv_mode' ); |
|
| 367 | + return $this->get_meta('_wpinv_mode'); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | private function setup_gateway() { |
| 371 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
| 371 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
| 372 | 372 | |
| 373 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
| 373 | + if (empty($gateway) && 'publish' === $this->status) { |
|
| 374 | 374 | $gateway = 'manual'; |
| 375 | 375 | } |
| 376 | 376 | |
@@ -378,23 +378,23 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | private function setup_gateway_title() { |
| 381 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 381 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
| 382 | 382 | return $gateway_title; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | private function setup_transaction_id() { |
| 386 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
| 386 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
| 387 | 387 | |
| 388 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
| 388 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
| 389 | 389 | $gateway = $this->gateway; |
| 390 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
| 390 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | return $transaction_id; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | private function setup_ip() { |
| 397 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
| 397 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
| 398 | 398 | return $ip; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -404,62 +404,62 @@ discard block |
||
| 404 | 404 | ///} |
| 405 | 405 | |
| 406 | 406 | private function setup_first_name() { |
| 407 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
| 407 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
| 408 | 408 | return $first_name; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | private function setup_last_name() { |
| 412 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
| 412 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
| 413 | 413 | return $last_name; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | private function setup_company() { |
| 417 | - $company = $this->get_meta( '_wpinv_company' ); |
|
| 417 | + $company = $this->get_meta('_wpinv_company'); |
|
| 418 | 418 | return $company; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | private function setup_vat_number() { |
| 422 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
| 422 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
| 423 | 423 | return $vat_number; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | private function setup_vat_rate() { |
| 427 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
| 427 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
| 428 | 428 | return $vat_rate; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | private function setup_adddress_confirmed() { |
| 432 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
| 432 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
| 433 | 433 | return $adddress_confirmed; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | private function setup_phone() { |
| 437 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
| 437 | + $phone = $this->get_meta('_wpinv_phone'); |
|
| 438 | 438 | return $phone; |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | private function setup_address() { |
| 442 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
| 442 | + $address = $this->get_meta('_wpinv_address', true); |
|
| 443 | 443 | return $address; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | private function setup_city() { |
| 447 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
| 447 | + $city = $this->get_meta('_wpinv_city', true); |
|
| 448 | 448 | return $city; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | private function setup_country() { |
| 452 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
| 452 | + $country = $this->get_meta('_wpinv_country', true); |
|
| 453 | 453 | return $country; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | private function setup_state() { |
| 457 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
| 457 | + $state = $this->get_meta('_wpinv_state', true); |
|
| 458 | 458 | return $state; |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | private function setup_zip() { |
| 462 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
| 462 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
| 463 | 463 | return $zip; |
| 464 | 464 | } |
| 465 | 465 | |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | 'user_id' => $this->user_id, |
| 469 | 469 | 'first_name' => $this->first_name, |
| 470 | 470 | 'last_name' => $this->last_name, |
| 471 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
| 471 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
| 472 | 472 | 'phone' => $this->phone, |
| 473 | 473 | 'address' => $this->address, |
| 474 | 474 | 'city' => $this->city, |
@@ -483,12 +483,12 @@ discard block |
||
| 483 | 483 | ); |
| 484 | 484 | |
| 485 | 485 | $user_info = array(); |
| 486 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
| 487 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
| 486 | + if (isset($this->payment_meta['user_info'])) { |
|
| 487 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
| 488 | 488 | |
| 489 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
| 489 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
| 490 | 490 | $this->user_id = $post->post_author; |
| 491 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 491 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 492 | 492 | |
| 493 | 493 | $user_info['user_id'] = $this->user_id; |
| 494 | 494 | $user_info['email'] = $this->email; |
@@ -497,13 +497,13 @@ discard block |
||
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
| 500 | + $user_info = wp_parse_args($user_info, $defaults); |
|
| 501 | 501 | |
| 502 | 502 | // Get the user, but only if it's been created |
| 503 | - $user = get_userdata( $this->user_id ); |
|
| 503 | + $user = get_userdata($this->user_id); |
|
| 504 | 504 | |
| 505 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
| 506 | - if ( empty( $user_info ) ) { |
|
| 505 | + if (!empty($user) && $user->ID > 0) { |
|
| 506 | + if (empty($user_info)) { |
|
| 507 | 507 | $user_info = array( |
| 508 | 508 | 'user_id' => $user->ID, |
| 509 | 509 | 'first_name' => $user->first_name, |
@@ -512,23 +512,23 @@ discard block |
||
| 512 | 512 | 'discount' => '', |
| 513 | 513 | ); |
| 514 | 514 | } else { |
| 515 | - foreach ( $user_info as $key => $value ) { |
|
| 516 | - if ( ! empty( $value ) ) { |
|
| 515 | + foreach ($user_info as $key => $value) { |
|
| 516 | + if (!empty($value)) { |
|
| 517 | 517 | continue; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - switch( $key ) { |
|
| 520 | + switch ($key) { |
|
| 521 | 521 | case 'user_id': |
| 522 | - $user_info[ $key ] = $user->ID; |
|
| 522 | + $user_info[$key] = $user->ID; |
|
| 523 | 523 | break; |
| 524 | 524 | case 'first_name': |
| 525 | - $user_info[ $key ] = $user->first_name; |
|
| 525 | + $user_info[$key] = $user->first_name; |
|
| 526 | 526 | break; |
| 527 | 527 | case 'last_name': |
| 528 | - $user_info[ $key ] = $user->last_name; |
|
| 528 | + $user_info[$key] = $user->last_name; |
|
| 529 | 529 | break; |
| 530 | 530 | case 'email': |
| 531 | - $user_info[ $key ] = $user->user_email; |
|
| 531 | + $user_info[$key] = $user->user_email; |
|
| 532 | 532 | break; |
| 533 | 533 | } |
| 534 | 534 | } |
@@ -539,25 +539,25 @@ discard block |
||
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | private function setup_invoice_key() { |
| 542 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
| 542 | + $key = $this->get_meta('_wpinv_key', true); |
|
| 543 | 543 | |
| 544 | 544 | return $key; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | private function setup_invoice_number() { |
| 548 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
| 548 | + $number = $this->get_meta('_wpinv_number', true); |
|
| 549 | 549 | |
| 550 | - if ( !$number ) { |
|
| 550 | + if (!$number) { |
|
| 551 | 551 | $number = $this->ID; |
| 552 | 552 | |
| 553 | - if ( $this->status == 'auto-draft' ) { |
|
| 554 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
| 555 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
| 553 | + if ($this->status == 'auto-draft') { |
|
| 554 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
| 555 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
| 556 | 556 | $number = $next_number; |
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 560 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | return $number; |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | private function insert_invoice() { |
| 567 | 567 | global $wpdb; |
| 568 | 568 | |
| 569 | - if ( empty( $this->post_type ) ) { |
|
| 570 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
| 569 | + if (empty($this->post_type)) { |
|
| 570 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
| 571 | 571 | $this->post_type = $post_type; |
| 572 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
| 572 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
| 573 | 573 | $this->post_type = $post_type; |
| 574 | 574 | } else { |
| 575 | 575 | $this->post_type = 'wpi_invoice'; |
@@ -577,16 +577,16 @@ discard block |
||
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | $invoice_number = $this->ID; |
| 580 | - if ( $number = $this->get_meta( '_wpinv_number', true ) ) { |
|
| 580 | + if ($number = $this->get_meta('_wpinv_number', true)) { |
|
| 581 | 581 | $invoice_number = $number; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if ( empty( $this->key ) ) { |
|
| 584 | + if (empty($this->key)) { |
|
| 585 | 585 | $this->key = self::generate_key(); |
| 586 | 586 | $this->pending['key'] = $this->key; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if ( empty( $this->ip ) ) { |
|
| 589 | + if (empty($this->ip)) { |
|
| 590 | 590 | $this->ip = wpinv_get_ip(); |
| 591 | 591 | $this->pending['ip'] = $this->ip; |
| 592 | 592 | } |
@@ -623,61 +623,61 @@ discard block |
||
| 623 | 623 | 'post_status' => $this->status, |
| 624 | 624 | 'post_author' => $this->user_id, |
| 625 | 625 | 'post_type' => $this->post_type, |
| 626 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
| 627 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
| 626 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
| 627 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
| 628 | 628 | 'post_parent' => $this->parent_invoice, |
| 629 | 629 | ); |
| 630 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
| 630 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
| 631 | 631 | |
| 632 | 632 | // Create a blank invoice |
| 633 | - if ( !empty( $this->ID ) ) { |
|
| 634 | - $args['ID'] = $this->ID; |
|
| 633 | + if (!empty($this->ID)) { |
|
| 634 | + $args['ID'] = $this->ID; |
|
| 635 | 635 | |
| 636 | - $invoice_id = wp_update_post( $args, true ); |
|
| 636 | + $invoice_id = wp_update_post($args, true); |
|
| 637 | 637 | } else { |
| 638 | - $invoice_id = wp_insert_post( $args, true ); |
|
| 638 | + $invoice_id = wp_insert_post($args, true); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - if ( is_wp_error( $invoice_id ) ) { |
|
| 641 | + if (is_wp_error($invoice_id)) { |
|
| 642 | 642 | return false; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( !empty( $invoice_id ) ) { |
|
| 645 | + if (!empty($invoice_id)) { |
|
| 646 | 646 | $this->ID = $invoice_id; |
| 647 | 647 | $this->_ID = $invoice_id; |
| 648 | 648 | |
| 649 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
| 650 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
| 651 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
| 652 | - foreach( $this->fees as $fee ) { |
|
| 653 | - $this->increase_fees( $fee['amount'] ); |
|
| 649 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
| 650 | + if (!empty($this->payment_meta['fees'])) { |
|
| 651 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
| 652 | + foreach ($this->fees as $fee) { |
|
| 653 | + $this->increase_fees($fee['amount']); |
|
| 654 | 654 | } |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
| 657 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
| 658 | 658 | $this->new = true; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | return $this->ID; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - public function save( $setup = false ) { |
|
| 664 | + public function save($setup = false) { |
|
| 665 | 665 | global $wpi_session; |
| 666 | 666 | |
| 667 | 667 | $saved = false; |
| 668 | - if ( empty( $this->items ) ) { |
|
| 668 | + if (empty($this->items)) { |
|
| 669 | 669 | return $saved; // Don't save empty invoice. |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if ( empty( $this->key ) ) { |
|
| 672 | + if (empty($this->key)) { |
|
| 673 | 673 | $this->key = self::generate_key(); |
| 674 | 674 | $this->pending['key'] = $this->key; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - if ( empty( $this->ID ) ) { |
|
| 677 | + if (empty($this->ID)) { |
|
| 678 | 678 | $invoice_id = $this->insert_invoice(); |
| 679 | 679 | |
| 680 | - if ( false === $invoice_id ) { |
|
| 680 | + if (false === $invoice_id) { |
|
| 681 | 681 | $saved = false; |
| 682 | 682 | } else { |
| 683 | 683 | $this->ID = $invoice_id; |
@@ -685,27 +685,27 @@ discard block |
||
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // If we have something pending, let's save it |
| 688 | - if ( !empty( $this->pending ) ) { |
|
| 688 | + if (!empty($this->pending)) { |
|
| 689 | 689 | $total_increase = 0; |
| 690 | 690 | $total_decrease = 0; |
| 691 | 691 | |
| 692 | - foreach ( $this->pending as $key => $value ) { |
|
| 693 | - switch( $key ) { |
|
| 692 | + foreach ($this->pending as $key => $value) { |
|
| 693 | + switch ($key) { |
|
| 694 | 694 | case 'items': |
| 695 | 695 | // Update totals for pending items |
| 696 | - foreach ( $this->pending[ $key ] as $item ) { |
|
| 697 | - switch( $item['action'] ) { |
|
| 696 | + foreach ($this->pending[$key] as $item) { |
|
| 697 | + switch ($item['action']) { |
|
| 698 | 698 | case 'add': |
| 699 | 699 | $price = $item['price']; |
| 700 | 700 | $taxes = $item['tax']; |
| 701 | 701 | |
| 702 | - if ( 'publish' === $this->status ) { |
|
| 702 | + if ('publish' === $this->status) { |
|
| 703 | 703 | $total_increase += $price; |
| 704 | 704 | } |
| 705 | 705 | break; |
| 706 | 706 | |
| 707 | 707 | case 'remove': |
| 708 | - if ( 'publish' === $this->status ) { |
|
| 708 | + if ('publish' === $this->status) { |
|
| 709 | 709 | $total_decrease += $item['price']; |
| 710 | 710 | } |
| 711 | 711 | break; |
@@ -713,16 +713,16 @@ discard block |
||
| 713 | 713 | } |
| 714 | 714 | break; |
| 715 | 715 | case 'fees': |
| 716 | - if ( 'publish' !== $this->status ) { |
|
| 716 | + if ('publish' !== $this->status) { |
|
| 717 | 717 | break; |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - if ( empty( $this->pending[ $key ] ) ) { |
|
| 720 | + if (empty($this->pending[$key])) { |
|
| 721 | 721 | break; |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
| 725 | - switch( $fee['action'] ) { |
|
| 724 | + foreach ($this->pending[$key] as $fee) { |
|
| 725 | + switch ($fee['action']) { |
|
| 726 | 726 | case 'add': |
| 727 | 727 | $total_increase += $fee['amount']; |
| 728 | 728 | break; |
@@ -734,86 +734,86 @@ discard block |
||
| 734 | 734 | } |
| 735 | 735 | break; |
| 736 | 736 | case 'status': |
| 737 | - $this->update_status( $this->status ); |
|
| 737 | + $this->update_status($this->status); |
|
| 738 | 738 | break; |
| 739 | 739 | case 'gateway': |
| 740 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
| 740 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
| 741 | 741 | break; |
| 742 | 742 | case 'mode': |
| 743 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
| 743 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
| 744 | 744 | break; |
| 745 | 745 | case 'transaction_id': |
| 746 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
| 746 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
| 747 | 747 | break; |
| 748 | 748 | case 'ip': |
| 749 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
| 749 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
| 750 | 750 | break; |
| 751 | 751 | ///case 'user_id': |
| 752 | 752 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
| 753 | 753 | ///$this->user_info['user_id'] = $this->user_id; |
| 754 | 754 | ///break; |
| 755 | 755 | case 'first_name': |
| 756 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
| 756 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
| 757 | 757 | $this->user_info['first_name'] = $this->first_name; |
| 758 | 758 | break; |
| 759 | 759 | case 'last_name': |
| 760 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
| 760 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
| 761 | 761 | $this->user_info['last_name'] = $this->last_name; |
| 762 | 762 | break; |
| 763 | 763 | case 'phone': |
| 764 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
| 764 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
| 765 | 765 | $this->user_info['phone'] = $this->phone; |
| 766 | 766 | break; |
| 767 | 767 | case 'address': |
| 768 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
| 768 | + $this->update_meta('_wpinv_address', $this->address); |
|
| 769 | 769 | $this->user_info['address'] = $this->address; |
| 770 | 770 | break; |
| 771 | 771 | case 'city': |
| 772 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
| 772 | + $this->update_meta('_wpinv_city', $this->city); |
|
| 773 | 773 | $this->user_info['city'] = $this->city; |
| 774 | 774 | break; |
| 775 | 775 | case 'country': |
| 776 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
| 776 | + $this->update_meta('_wpinv_country', $this->country); |
|
| 777 | 777 | $this->user_info['country'] = $this->country; |
| 778 | 778 | break; |
| 779 | 779 | case 'state': |
| 780 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
| 780 | + $this->update_meta('_wpinv_state', $this->state); |
|
| 781 | 781 | $this->user_info['state'] = $this->state; |
| 782 | 782 | break; |
| 783 | 783 | case 'zip': |
| 784 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
| 784 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
| 785 | 785 | $this->user_info['zip'] = $this->zip; |
| 786 | 786 | break; |
| 787 | 787 | case 'company': |
| 788 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
| 788 | + $this->update_meta('_wpinv_company', $this->company); |
|
| 789 | 789 | $this->user_info['company'] = $this->company; |
| 790 | 790 | break; |
| 791 | 791 | case 'vat_number': |
| 792 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
| 792 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
| 793 | 793 | $this->user_info['vat_number'] = $this->vat_number; |
| 794 | 794 | |
| 795 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 796 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
| 797 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
| 798 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
| 799 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
| 795 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 796 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
| 797 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 798 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
| 799 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | break; |
| 803 | 803 | case 'vat_rate': |
| 804 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
| 804 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
| 805 | 805 | $this->user_info['vat_rate'] = $this->vat_rate; |
| 806 | 806 | break; |
| 807 | 807 | case 'adddress_confirmed': |
| 808 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
| 808 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
| 809 | 809 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
| 810 | 810 | break; |
| 811 | 811 | |
| 812 | 812 | case 'key': |
| 813 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
| 813 | + $this->update_meta('_wpinv_key', $this->key); |
|
| 814 | 814 | break; |
| 815 | 815 | case 'disable_taxes': |
| 816 | - $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes ); |
|
| 816 | + $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes); |
|
| 817 | 817 | break; |
| 818 | 818 | case 'date': |
| 819 | 819 | $args = array( |
@@ -822,49 +822,49 @@ discard block |
||
| 822 | 822 | 'edit_date' => true, |
| 823 | 823 | ); |
| 824 | 824 | |
| 825 | - wp_update_post( $args ); |
|
| 825 | + wp_update_post($args); |
|
| 826 | 826 | break; |
| 827 | 827 | case 'due_date': |
| 828 | - if ( empty( $this->due_date ) ) { |
|
| 828 | + if (empty($this->due_date)) { |
|
| 829 | 829 | $this->due_date = 'none'; |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
| 832 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
| 833 | 833 | break; |
| 834 | 834 | case 'completed_date': |
| 835 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
| 835 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
| 836 | 836 | break; |
| 837 | 837 | case 'discounts': |
| 838 | - if ( ! is_array( $this->discounts ) ) { |
|
| 839 | - $this->discounts = explode( ',', $this->discounts ); |
|
| 838 | + if (!is_array($this->discounts)) { |
|
| 839 | + $this->discounts = explode(',', $this->discounts); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
| 842 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
| 843 | 843 | break; |
| 844 | 844 | case 'discount': |
| 845 | - $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) ); |
|
| 845 | + $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount)); |
|
| 846 | 846 | break; |
| 847 | 847 | case 'discount_code': |
| 848 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
| 848 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
| 849 | 849 | break; |
| 850 | 850 | case 'parent_invoice': |
| 851 | 851 | $args = array( |
| 852 | 852 | 'ID' => $this->ID, |
| 853 | 853 | 'post_parent' => $this->parent_invoice, |
| 854 | 854 | ); |
| 855 | - wp_update_post( $args ); |
|
| 855 | + wp_update_post($args); |
|
| 856 | 856 | break; |
| 857 | 857 | default: |
| 858 | - do_action( 'wpinv_save', $this, $key ); |
|
| 858 | + do_action('wpinv_save', $this, $key); |
|
| 859 | 859 | break; |
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
| 864 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
| 865 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
| 863 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
| 864 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
| 865 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
| 866 | 866 | |
| 867 | - $this->items = array_values( $this->items ); |
|
| 867 | + $this->items = array_values($this->items); |
|
| 868 | 868 | |
| 869 | 869 | $new_meta = array( |
| 870 | 870 | 'items' => $this->items, |
@@ -875,12 +875,12 @@ discard block |
||
| 875 | 875 | ); |
| 876 | 876 | |
| 877 | 877 | $meta = $this->get_meta(); |
| 878 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
| 878 | + $merged_meta = array_merge($meta, $new_meta); |
|
| 879 | 879 | |
| 880 | 880 | // Only save the payment meta if it's changed |
| 881 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
| 882 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
| 883 | - if ( false !== $updated ) { |
|
| 881 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
| 882 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
| 883 | + if (false !== $updated) { |
|
| 884 | 884 | $saved = true; |
| 885 | 885 | } |
| 886 | 886 | } |
@@ -888,15 +888,15 @@ discard block |
||
| 888 | 888 | $this->pending = array(); |
| 889 | 889 | $saved = true; |
| 890 | 890 | } else { |
| 891 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
| 892 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
| 893 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
| 891 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
| 892 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
| 893 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
| 896 | + do_action('wpinv_invoice_save', $this, $saved); |
|
| 897 | 897 | |
| 898 | - if ( true === $saved || $setup ) { |
|
| 899 | - $this->setup_invoice( $this->ID ); |
|
| 898 | + if (true === $saved || $setup) { |
|
| 899 | + $this->setup_invoice($this->ID); |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | $this->refresh_item_ids(); |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | return $saved; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - public function add_fee( $args, $global = true ) { |
|
| 907 | + public function add_fee($args, $global = true) { |
|
| 908 | 908 | $default_args = array( |
| 909 | 909 | 'label' => '', |
| 910 | 910 | 'amount' => 0, |
@@ -914,75 +914,75 @@ discard block |
||
| 914 | 914 | 'item_id' => 0, |
| 915 | 915 | ); |
| 916 | 916 | |
| 917 | - $fee = wp_parse_args( $args, $default_args ); |
|
| 917 | + $fee = wp_parse_args($args, $default_args); |
|
| 918 | 918 | |
| 919 | - if ( empty( $fee['label'] ) ) { |
|
| 919 | + if (empty($fee['label'])) { |
|
| 920 | 920 | return false; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
| 923 | + $fee['id'] = sanitize_title($fee['label']); |
|
| 924 | 924 | |
| 925 | - $this->fees[] = $fee; |
|
| 925 | + $this->fees[] = $fee; |
|
| 926 | 926 | |
| 927 | 927 | $added_fee = $fee; |
| 928 | 928 | $added_fee['action'] = 'add'; |
| 929 | 929 | $this->pending['fees'][] = $added_fee; |
| 930 | - reset( $this->fees ); |
|
| 930 | + reset($this->fees); |
|
| 931 | 931 | |
| 932 | - $this->increase_fees( $fee['amount'] ); |
|
| 932 | + $this->increase_fees($fee['amount']); |
|
| 933 | 933 | return true; |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - public function remove_fee( $key ) { |
|
| 936 | + public function remove_fee($key) { |
|
| 937 | 937 | $removed = false; |
| 938 | 938 | |
| 939 | - if ( is_numeric( $key ) ) { |
|
| 940 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
| 939 | + if (is_numeric($key)) { |
|
| 940 | + $removed = $this->remove_fee_by('index', $key); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | return $removed; |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
| 947 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
| 946 | + public function remove_fee_by($key, $value, $global = false) { |
|
| 947 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
| 948 | 948 | 'index', 'label', 'amount', 'type', |
| 949 | - ) ); |
|
| 949 | + )); |
|
| 950 | 950 | |
| 951 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
| 951 | + if (!in_array($key, $allowed_fee_keys)) { |
|
| 952 | 952 | return false; |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | $removed = false; |
| 956 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
| 957 | - $removed_fee = $this->fees[ $value ]; |
|
| 956 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
| 957 | + $removed_fee = $this->fees[$value]; |
|
| 958 | 958 | $removed_fee['action'] = 'remove'; |
| 959 | 959 | $this->pending['fees'][] = $removed_fee; |
| 960 | 960 | |
| 961 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 961 | + $this->decrease_fees($removed_fee['amount']); |
|
| 962 | 962 | |
| 963 | - unset( $this->fees[ $value ] ); |
|
| 963 | + unset($this->fees[$value]); |
|
| 964 | 964 | $removed = true; |
| 965 | - } else if ( 'index' !== $key ) { |
|
| 966 | - foreach ( $this->fees as $index => $fee ) { |
|
| 967 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
| 965 | + } else if ('index' !== $key) { |
|
| 966 | + foreach ($this->fees as $index => $fee) { |
|
| 967 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
| 968 | 968 | $removed_fee = $fee; |
| 969 | 969 | $removed_fee['action'] = 'remove'; |
| 970 | 970 | $this->pending['fees'][] = $removed_fee; |
| 971 | 971 | |
| 972 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 972 | + $this->decrease_fees($removed_fee['amount']); |
|
| 973 | 973 | |
| 974 | - unset( $this->fees[ $index ] ); |
|
| 974 | + unset($this->fees[$index]); |
|
| 975 | 975 | $removed = true; |
| 976 | 976 | |
| 977 | - if ( false === $global ) { |
|
| 977 | + if (false === $global) { |
|
| 978 | 978 | break; |
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | } |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | - if ( true === $removed ) { |
|
| 985 | - $this->fees = array_values( $this->fees ); |
|
| 984 | + if (true === $removed) { |
|
| 985 | + $this->fees = array_values($this->fees); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | return $removed; |
@@ -990,35 +990,35 @@ discard block |
||
| 990 | 990 | |
| 991 | 991 | |
| 992 | 992 | |
| 993 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 993 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 994 | 994 | // Bail if no note specified |
| 995 | - if( !$note ) { |
|
| 995 | + if (!$note) { |
|
| 996 | 996 | return false; |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | - if ( empty( $this->ID ) ) |
|
| 999 | + if (empty($this->ID)) |
|
| 1000 | 1000 | return false; |
| 1001 | 1001 | |
| 1002 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
| 1003 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 1002 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
| 1003 | + $user = get_user_by('id', get_current_user_id()); |
|
| 1004 | 1004 | $comment_author = $user->display_name; |
| 1005 | 1005 | $comment_author_email = $user->user_email; |
| 1006 | 1006 | } else { |
| 1007 | 1007 | $comment_author = 'System'; |
| 1008 | 1008 | $comment_author_email = 'system@'; |
| 1009 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
| 1010 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
| 1009 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
| 1010 | + $comment_author_email = sanitize_email($comment_author_email); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
| 1013 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
| 1014 | 1014 | |
| 1015 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
| 1015 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
| 1016 | 1016 | 'comment_post_ID' => $this->ID, |
| 1017 | 1017 | 'comment_content' => $note, |
| 1018 | 1018 | 'comment_agent' => 'WPInvoicing', |
| 1019 | 1019 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
| 1020 | - 'comment_date' => current_time( 'mysql' ), |
|
| 1021 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
| 1020 | + 'comment_date' => current_time('mysql'), |
|
| 1021 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
| 1022 | 1022 | 'comment_approved' => 1, |
| 1023 | 1023 | 'comment_parent' => 0, |
| 1024 | 1024 | 'comment_author' => $comment_author, |
@@ -1026,53 +1026,53 @@ discard block |
||
| 1026 | 1026 | 'comment_author_url' => '', |
| 1027 | 1027 | 'comment_author_email' => $comment_author_email, |
| 1028 | 1028 | 'comment_type' => 'wpinv_note' |
| 1029 | - ) ) ); |
|
| 1029 | + ))); |
|
| 1030 | 1030 | |
| 1031 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
| 1031 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
| 1032 | 1032 | |
| 1033 | - if ( $customer_type ) { |
|
| 1034 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 1033 | + if ($customer_type) { |
|
| 1034 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 1035 | 1035 | |
| 1036 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
| 1036 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | return $note_id; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | - private function increase_subtotal( $amount = 0.00 ) { |
|
| 1042 | + private function increase_subtotal($amount = 0.00) { |
|
| 1043 | 1043 | $amount = (float) $amount; |
| 1044 | 1044 | $this->subtotal += $amount; |
| 1045 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1045 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1046 | 1046 | |
| 1047 | 1047 | $this->recalculate_total(); |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
| 1050 | + private function decrease_subtotal($amount = 0.00) { |
|
| 1051 | 1051 | $amount = (float) $amount; |
| 1052 | 1052 | $this->subtotal -= $amount; |
| 1053 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1053 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1054 | 1054 | |
| 1055 | - if ( $this->subtotal < 0 ) { |
|
| 1055 | + if ($this->subtotal < 0) { |
|
| 1056 | 1056 | $this->subtotal = 0; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | $this->recalculate_total(); |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - private function increase_fees( $amount = 0.00 ) { |
|
| 1063 | - $amount = (float)$amount; |
|
| 1062 | + private function increase_fees($amount = 0.00) { |
|
| 1063 | + $amount = (float) $amount; |
|
| 1064 | 1064 | $this->fees_total += $amount; |
| 1065 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1065 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1066 | 1066 | |
| 1067 | 1067 | $this->recalculate_total(); |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | - private function decrease_fees( $amount = 0.00 ) { |
|
| 1070 | + private function decrease_fees($amount = 0.00) { |
|
| 1071 | 1071 | $amount = (float) $amount; |
| 1072 | 1072 | $this->fees_total -= $amount; |
| 1073 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1073 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1074 | 1074 | |
| 1075 | - if ( $this->fees_total < 0 ) { |
|
| 1075 | + if ($this->fees_total < 0) { |
|
| 1076 | 1076 | $this->fees_total = 0; |
| 1077 | 1077 | } |
| 1078 | 1078 | |
@@ -1083,54 +1083,54 @@ discard block |
||
| 1083 | 1083 | global $wpi_nosave; |
| 1084 | 1084 | |
| 1085 | 1085 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
| 1086 | - $this->total = wpinv_round_amount( $this->total ); |
|
| 1086 | + $this->total = wpinv_round_amount($this->total); |
|
| 1087 | 1087 | |
| 1088 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
| 1088 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | - public function increase_tax( $amount = 0.00 ) { |
|
| 1091 | + public function increase_tax($amount = 0.00) { |
|
| 1092 | 1092 | $amount = (float) $amount; |
| 1093 | 1093 | $this->tax += $amount; |
| 1094 | 1094 | |
| 1095 | 1095 | $this->recalculate_total(); |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - public function decrease_tax( $amount = 0.00 ) { |
|
| 1098 | + public function decrease_tax($amount = 0.00) { |
|
| 1099 | 1099 | $amount = (float) $amount; |
| 1100 | 1100 | $this->tax -= $amount; |
| 1101 | 1101 | |
| 1102 | - if ( $this->tax < 0 ) { |
|
| 1102 | + if ($this->tax < 0) { |
|
| 1103 | 1103 | $this->tax = 0; |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | $this->recalculate_total(); |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 1110 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
| 1109 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 1110 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
| 1111 | 1111 | |
| 1112 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
| 1112 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
| 1113 | 1113 | return false; // Don't permit status changes that aren't changes |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
| 1116 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
| 1117 | 1117 | $updated = false; |
| 1118 | 1118 | |
| 1119 | - if ( $do_change ) { |
|
| 1120 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
| 1119 | + if ($do_change) { |
|
| 1120 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
| 1121 | 1121 | |
| 1122 | 1122 | $update_post_data = array(); |
| 1123 | 1123 | $update_post_data['ID'] = $this->ID; |
| 1124 | 1124 | $update_post_data['post_status'] = $new_status; |
| 1125 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
| 1126 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
| 1125 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
| 1126 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
| 1127 | 1127 | |
| 1128 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
| 1128 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
| 1129 | 1129 | |
| 1130 | - $updated = wp_update_post( $update_post_data ); |
|
| 1130 | + $updated = wp_update_post($update_post_data); |
|
| 1131 | 1131 | |
| 1132 | 1132 | // Process any specific status functions |
| 1133 | - switch( $new_status ) { |
|
| 1133 | + switch ($new_status) { |
|
| 1134 | 1134 | case 'wpi-refunded': |
| 1135 | 1135 | $this->process_refund(); |
| 1136 | 1136 | break; |
@@ -1143,9 +1143,9 @@ discard block |
||
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | // Status was changed. |
| 1146 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
| 1147 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
| 1148 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
| 1146 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
| 1147 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
| 1148 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | return $updated; |
@@ -1159,20 +1159,20 @@ discard block |
||
| 1159 | 1159 | $this->save(); |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 1163 | - if ( empty( $meta_key ) ) { |
|
| 1162 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 1163 | + if (empty($meta_key)) { |
|
| 1164 | 1164 | return false; |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
| 1167 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
| 1168 | 1168 | $current_meta = $this->get_meta(); |
| 1169 | - $current_meta[ $meta_key ] = $meta_value; |
|
| 1169 | + $current_meta[$meta_key] = $meta_value; |
|
| 1170 | 1170 | |
| 1171 | 1171 | $meta_key = '_wpinv_payment_meta'; |
| 1172 | 1172 | $meta_value = $current_meta; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 1175 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 1176 | 1176 | |
| 1177 | 1177 | // Do not update created date on invoice marked as paid. |
| 1178 | 1178 | /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
@@ -1187,45 +1187,45 @@ discard block |
||
| 1187 | 1187 | wp_update_post( $args ); |
| 1188 | 1188 | }*/ |
| 1189 | 1189 | |
| 1190 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 1190 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | private function process_refund() { |
| 1194 | 1194 | $process_refund = true; |
| 1195 | 1195 | |
| 1196 | 1196 | // If the payment was not in publish, don't decrement stats as they were never incremented |
| 1197 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
| 1197 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
| 1198 | 1198 | $process_refund = false; |
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1202 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
| 1202 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
| 1203 | 1203 | |
| 1204 | - if ( false === $process_refund ) { |
|
| 1204 | + if (false === $process_refund) { |
|
| 1205 | 1205 | return; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
| 1208 | + do_action('wpinv_pre_refund_invoice', $this); |
|
| 1209 | 1209 | |
| 1210 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
| 1211 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
| 1212 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
| 1210 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
| 1211 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
| 1212 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
| 1213 | 1213 | |
| 1214 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
| 1214 | + do_action('wpinv_post_refund_invoice', $this); |
|
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | private function process_failure() { |
| 1218 | 1218 | $discounts = $this->discounts; |
| 1219 | - if ( empty( $discounts ) ) { |
|
| 1219 | + if (empty($discounts)) { |
|
| 1220 | 1220 | return; |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | - if ( ! is_array( $discounts ) ) { |
|
| 1224 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
| 1223 | + if (!is_array($discounts)) { |
|
| 1224 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | - foreach ( $discounts as $discount ) { |
|
| 1228 | - wpinv_decrease_discount_usage( $discount ); |
|
| 1227 | + foreach ($discounts as $discount) { |
|
| 1228 | + wpinv_decrease_discount_usage($discount); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | } |
| 1231 | 1231 | |
@@ -1233,92 +1233,92 @@ discard block |
||
| 1233 | 1233 | $process_pending = true; |
| 1234 | 1234 | |
| 1235 | 1235 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
| 1236 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
| 1236 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
| 1237 | 1237 | $process_pending = false; |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1241 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
| 1241 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
| 1242 | 1242 | |
| 1243 | - if ( false === $process_pending ) { |
|
| 1243 | + if (false === $process_pending) { |
|
| 1244 | 1244 | return; |
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
| 1248 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
| 1249 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
| 1247 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
| 1248 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
| 1249 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
| 1250 | 1250 | |
| 1251 | 1251 | $this->completed_date = ''; |
| 1252 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
| 1252 | + $this->update_meta('_wpinv_completed_date', ''); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | // get data |
| 1256 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 1257 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
| 1256 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 1257 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
| 1258 | 1258 | |
| 1259 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
| 1259 | + if ($meta_key === '_wpinv_payment_meta') { |
|
| 1260 | 1260 | |
| 1261 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
| 1261 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
| 1262 | 1262 | |
| 1263 | - if ( empty( $meta['key'] ) ) { |
|
| 1263 | + if (empty($meta['key'])) { |
|
| 1264 | 1264 | $meta['key'] = $this->setup_invoice_key(); |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | - if ( empty( $meta['date'] ) ) { |
|
| 1268 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
| 1267 | + if (empty($meta['date'])) { |
|
| 1268 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
| 1272 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
| 1273 | 1273 | |
| 1274 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
| 1274 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | public function get_description() { |
| 1278 | - $post = get_post( $this->ID ); |
|
| 1278 | + $post = get_post($this->ID); |
|
| 1279 | 1279 | |
| 1280 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
| 1281 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
| 1280 | + $description = !empty($post) ? $post->post_content : ''; |
|
| 1281 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | - public function get_status( $nicename = false ) { |
|
| 1285 | - if ( !$nicename ) { |
|
| 1284 | + public function get_status($nicename = false) { |
|
| 1285 | + if (!$nicename) { |
|
| 1286 | 1286 | $status = $this->status; |
| 1287 | 1287 | } else { |
| 1288 | 1288 | $status = $this->status_nicename; |
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
| 1291 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | public function get_cart_details() { |
| 1295 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
| 1295 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | - public function get_subtotal( $currency = false ) { |
|
| 1299 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1298 | + public function get_subtotal($currency = false) { |
|
| 1299 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
| 1300 | 1300 | |
| 1301 | - if ( $currency ) { |
|
| 1302 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
| 1301 | + if ($currency) { |
|
| 1302 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
| 1305 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | - public function get_total( $currency = false ) { |
|
| 1309 | - if ( $this->is_free_trial() ) { |
|
| 1310 | - $total = wpinv_round_amount( 0 ); |
|
| 1308 | + public function get_total($currency = false) { |
|
| 1309 | + if ($this->is_free_trial()) { |
|
| 1310 | + $total = wpinv_round_amount(0); |
|
| 1311 | 1311 | } else { |
| 1312 | - $total = wpinv_round_amount( $this->total ); |
|
| 1312 | + $total = wpinv_round_amount($this->total); |
|
| 1313 | 1313 | } |
| 1314 | - if ( $currency ) { |
|
| 1315 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
| 1314 | + if ($currency) { |
|
| 1315 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
| 1318 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1321 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1322 | 1322 | $data = array(); |
| 1323 | 1323 | $data['cart_details'] = $this->cart_details; |
| 1324 | 1324 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1326,119 +1326,119 @@ discard block |
||
| 1326 | 1326 | $data['tax'] = $this->get_tax(); |
| 1327 | 1327 | $data['total'] = $this->get_total(); |
| 1328 | 1328 | |
| 1329 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
| 1329 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
| 1330 | 1330 | $is_free_trial = $this->is_free_trial(); |
| 1331 | - $discounts = $this->get_discounts( true ); |
|
| 1331 | + $discounts = $this->get_discounts(true); |
|
| 1332 | 1332 | |
| 1333 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
| 1333 | + if ($is_free_trial || !empty($discounts)) { |
|
| 1334 | 1334 | $first_use_only = false; |
| 1335 | 1335 | |
| 1336 | - if ( !empty( $discounts ) ) { |
|
| 1337 | - foreach ( $discounts as $key => $code ) { |
|
| 1338 | - if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) { |
|
| 1336 | + if (!empty($discounts)) { |
|
| 1337 | + foreach ($discounts as $key => $code) { |
|
| 1338 | + if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) { |
|
| 1339 | 1339 | $first_use_only = true; |
| 1340 | 1340 | break; |
| 1341 | 1341 | } |
| 1342 | 1342 | } |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | - if ( !$first_use_only ) { |
|
| 1346 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
| 1347 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
| 1348 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
| 1349 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
| 1345 | + if (!$first_use_only) { |
|
| 1346 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
| 1347 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
| 1348 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
| 1349 | + $data['total'] = wpinv_round_amount($this->total); |
|
| 1350 | 1350 | } else { |
| 1351 | 1351 | $cart_subtotal = 0; |
| 1352 | 1352 | $cart_discount = $this->discount; |
| 1353 | 1353 | $cart_tax = 0; |
| 1354 | 1354 | |
| 1355 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1356 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1357 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1355 | + foreach ($this->cart_details as $key => $item) { |
|
| 1356 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1357 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1358 | 1358 | $item_discount = 0; |
| 1359 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
| 1359 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0; |
|
| 1360 | 1360 | |
| 1361 | - if ( wpinv_prices_include_tax() ) { |
|
| 1362 | - $item_subtotal -= wpinv_round_amount( $item_tax ); |
|
| 1361 | + if (wpinv_prices_include_tax()) { |
|
| 1362 | + $item_subtotal -= wpinv_round_amount($item_tax); |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | $item_total = $item_subtotal - $item_discount + $item_tax; |
| 1366 | 1366 | // Do not allow totals to go negative |
| 1367 | - if ( $item_total < 0 ) { |
|
| 1367 | + if ($item_total < 0) { |
|
| 1368 | 1368 | $item_total = 0; |
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | - $cart_subtotal += (float)($item_subtotal); |
|
| 1372 | - $cart_discount += (float)($item_discount); |
|
| 1373 | - $cart_tax += (float)($item_tax); |
|
| 1371 | + $cart_subtotal += (float) ($item_subtotal); |
|
| 1372 | + $cart_discount += (float) ($item_discount); |
|
| 1373 | + $cart_tax += (float) ($item_tax); |
|
| 1374 | 1374 | |
| 1375 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount ); |
|
| 1376 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax ); |
|
| 1377 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
|
| 1375 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount); |
|
| 1376 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax); |
|
| 1377 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total); |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
| 1381 | - if ( $total < 0 ) { |
|
| 1381 | + if ($total < 0) { |
|
| 1382 | 1382 | $total = 0; |
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
|
| 1386 | - $data['discount'] = wpinv_round_amount( $cart_discount ); |
|
| 1387 | - $data['tax'] = wpinv_round_amount( $cart_tax ); |
|
| 1388 | - $data['total'] = wpinv_round_amount( $total ); |
|
| 1385 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal); |
|
| 1386 | + $data['discount'] = wpinv_round_amount($cart_discount); |
|
| 1387 | + $data['tax'] = wpinv_round_amount($cart_tax); |
|
| 1388 | + $data['total'] = wpinv_round_amount($total); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | } |
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
| 1393 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
| 1394 | 1394 | |
| 1395 | - if ( isset( $data[$field] ) ) { |
|
| 1396 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
| 1395 | + if (isset($data[$field])) { |
|
| 1396 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | return $data; |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | - public function get_final_tax( $currency = false ) { |
|
| 1403 | - $final_total = wpinv_round_amount( $this->tax ); |
|
| 1404 | - if ( $currency ) { |
|
| 1405 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
| 1402 | + public function get_final_tax($currency = false) { |
|
| 1403 | + $final_total = wpinv_round_amount($this->tax); |
|
| 1404 | + if ($currency) { |
|
| 1405 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
| 1408 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
| 1409 | 1409 | } |
| 1410 | 1410 | |
| 1411 | - public function get_discounts( $array = false ) { |
|
| 1411 | + public function get_discounts($array = false) { |
|
| 1412 | 1412 | $discounts = $this->discounts; |
| 1413 | - if ( $array && $discounts ) { |
|
| 1414 | - $discounts = explode( ',', $discounts ); |
|
| 1413 | + if ($array && $discounts) { |
|
| 1414 | + $discounts = explode(',', $discounts); |
|
| 1415 | 1415 | } |
| 1416 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
| 1416 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | - public function get_discount( $currency = false, $dash = false ) { |
|
| 1420 | - if ( !empty( $this->discounts ) ) { |
|
| 1419 | + public function get_discount($currency = false, $dash = false) { |
|
| 1420 | + if (!empty($this->discounts)) { |
|
| 1421 | 1421 | global $ajax_cart_details; |
| 1422 | 1422 | $ajax_cart_details = $this->get_cart_details(); |
| 1423 | 1423 | |
| 1424 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
| 1424 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
| 1425 | 1425 | $cart_items = $ajax_cart_details; |
| 1426 | 1426 | } else { |
| 1427 | 1427 | $cart_items = $this->items; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
| 1430 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
| 1431 | 1431 | } |
| 1432 | - $discount = wpinv_round_amount( $this->discount ); |
|
| 1432 | + $discount = wpinv_round_amount($this->discount); |
|
| 1433 | 1433 | $dash = $dash && $discount > 0 ? '–' : ''; |
| 1434 | 1434 | |
| 1435 | - if ( $currency ) { |
|
| 1436 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
| 1435 | + if ($currency) { |
|
| 1436 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | - $discount = $dash . $discount; |
|
| 1439 | + $discount = $dash . $discount; |
|
| 1440 | 1440 | |
| 1441 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
| 1441 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | public function get_discount_code() { |
@@ -1450,49 +1450,49 @@ discard block |
||
| 1450 | 1450 | return (int) $this->disable_taxes === 0; |
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | - public function get_tax( $currency = false ) { |
|
| 1454 | - $tax = wpinv_round_amount( $this->tax ); |
|
| 1453 | + public function get_tax($currency = false) { |
|
| 1454 | + $tax = wpinv_round_amount($this->tax); |
|
| 1455 | 1455 | |
| 1456 | - if ( $currency ) { |
|
| 1457 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
| 1456 | + if ($currency) { |
|
| 1457 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
| 1458 | 1458 | } |
| 1459 | 1459 | |
| 1460 | - if ( ! $this->is_taxable() ) { |
|
| 1461 | - $tax = wpinv_round_amount( 0.00 ); |
|
| 1460 | + if (!$this->is_taxable()) { |
|
| 1461 | + $tax = wpinv_round_amount(0.00); |
|
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
| 1464 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | - public function get_fees( $type = 'all' ) { |
|
| 1468 | - $fees = array(); |
|
| 1467 | + public function get_fees($type = 'all') { |
|
| 1468 | + $fees = array(); |
|
| 1469 | 1469 | |
| 1470 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
| 1471 | - foreach ( $this->fees as $fee ) { |
|
| 1472 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1470 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
| 1471 | + foreach ($this->fees as $fee) { |
|
| 1472 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
| 1473 | 1473 | continue; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
| 1477 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
| 1478 | - $fees[] = $fee; |
|
| 1476 | + $fee['label'] = stripslashes($fee['label']); |
|
| 1477 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
| 1478 | + $fees[] = $fee; |
|
| 1479 | 1479 | } |
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
| 1482 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | - public function get_fees_total( $type = 'all' ) { |
|
| 1485 | + public function get_fees_total($type = 'all') { |
|
| 1486 | 1486 | $fees_total = (float) 0.00; |
| 1487 | 1487 | |
| 1488 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 1489 | - if ( ! empty( $payment_fees ) ) { |
|
| 1490 | - foreach ( $payment_fees as $fee ) { |
|
| 1488 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 1489 | + if (!empty($payment_fees)) { |
|
| 1490 | + foreach ($payment_fees as $fee) { |
|
| 1491 | 1491 | $fees_total += (float) $fee['amount']; |
| 1492 | 1492 | } |
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
| 1495 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
| 1496 | 1496 | /* |
| 1497 | 1497 | $fees = $this->get_fees( $type ); |
| 1498 | 1498 | |
@@ -1512,116 +1512,116 @@ discard block |
||
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | public function get_user_id() { |
| 1515 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
| 1515 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | 1518 | public function get_first_name() { |
| 1519 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
| 1519 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | 1522 | public function get_last_name() { |
| 1523 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
| 1523 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | public function get_user_full_name() { |
| 1527 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
| 1527 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | 1530 | public function get_user_info() { |
| 1531 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
| 1531 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | public function get_email() { |
| 1535 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
| 1535 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | 1538 | public function get_address() { |
| 1539 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
| 1539 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | public function get_phone() { |
| 1543 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
| 1543 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | public function get_number() { |
| 1547 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
| 1547 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | public function get_items() { |
| 1551 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
| 1551 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | public function get_key() { |
| 1555 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
| 1555 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | 1558 | public function get_transaction_id() { |
| 1559 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
| 1559 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | public function get_gateway() { |
| 1563 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
| 1563 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | 1566 | public function get_gateway_title() { |
| 1567 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 1567 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
| 1568 | 1568 | |
| 1569 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
| 1569 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | public function get_currency() { |
| 1573 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
| 1573 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | 1576 | public function get_created_date() { |
| 1577 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
| 1577 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | - public function get_due_date( $display = false ) { |
|
| 1581 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
| 1580 | + public function get_due_date($display = false) { |
|
| 1581 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
| 1582 | 1582 | |
| 1583 | - if ( !$display || empty( $due_date ) ) { |
|
| 1583 | + if (!$display || empty($due_date)) { |
|
| 1584 | 1584 | return $due_date; |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
| 1587 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | public function get_completed_date() { |
| 1591 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
| 1591 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | - public function get_invoice_date( $formatted = true ) { |
|
| 1594 | + public function get_invoice_date($formatted = true) { |
|
| 1595 | 1595 | $date_completed = $this->completed_date; |
| 1596 | 1596 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 1597 | 1597 | |
| 1598 | - if ( $invoice_date == '' ) { |
|
| 1598 | + if ($invoice_date == '') { |
|
| 1599 | 1599 | $date_created = $this->date; |
| 1600 | 1600 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | - if ( $formatted && $invoice_date ) { |
|
| 1604 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
| 1603 | + if ($formatted && $invoice_date) { |
|
| 1604 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
| 1607 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | public function get_ip() { |
| 1611 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
| 1611 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | - public function has_status( $status ) { |
|
| 1615 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
| 1614 | + public function has_status($status) { |
|
| 1615 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | - public function add_item( $item_id = 0, $args = array() ) { |
|
| 1618 | + public function add_item($item_id = 0, $args = array()) { |
|
| 1619 | 1619 | global $wpi_current_id, $wpi_item_id; |
| 1620 | 1620 | |
| 1621 | - $item = new WPInv_Item( $item_id ); |
|
| 1621 | + $item = new WPInv_Item($item_id); |
|
| 1622 | 1622 | |
| 1623 | 1623 | // Bail if this post isn't a item |
| 1624 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
| 1624 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
| 1625 | 1625 | return false; |
| 1626 | 1626 | } |
| 1627 | 1627 | |
@@ -1640,8 +1640,8 @@ discard block |
||
| 1640 | 1640 | 'fees' => array() |
| 1641 | 1641 | ); |
| 1642 | 1642 | |
| 1643 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
| 1644 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
| 1643 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
| 1644 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
| 1645 | 1645 | |
| 1646 | 1646 | $wpi_current_id = $this->ID; |
| 1647 | 1647 | $wpi_item_id = $item->ID; |
@@ -1653,19 +1653,19 @@ discard block |
||
| 1653 | 1653 | $found_cart_key = false; |
| 1654 | 1654 | |
| 1655 | 1655 | if ($has_quantities) { |
| 1656 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1656 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1657 | 1657 | |
| 1658 | - foreach ( $this->items as $key => $cart_item ) { |
|
| 1659 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
| 1658 | + foreach ($this->items as $key => $cart_item) { |
|
| 1659 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
| 1660 | 1660 | continue; |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
| 1663 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
| 1664 | 1664 | break; |
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
| 1668 | - if ( $item_id != $cart_item['id'] ) { |
|
| 1667 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
| 1668 | + if ($item_id != $cart_item['id']) { |
|
| 1669 | 1669 | continue; |
| 1670 | 1670 | } |
| 1671 | 1671 | |
@@ -1677,29 +1677,29 @@ discard block |
||
| 1677 | 1677 | if ($has_quantities && $found_cart_key !== false) { |
| 1678 | 1678 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1679 | 1679 | $item_price = $cart_item['item_price']; |
| 1680 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1681 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1680 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1681 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1682 | 1682 | |
| 1683 | 1683 | $new_quantity = $quantity + $args['quantity']; |
| 1684 | 1684 | $subtotal = $item_price * $new_quantity; |
| 1685 | 1685 | |
| 1686 | 1686 | $args['quantity'] = $new_quantity; |
| 1687 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1688 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1687 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1688 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1689 | 1689 | |
| 1690 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
| 1691 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
| 1690 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
| 1691 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
| 1692 | 1692 | // The total increase equals the number removed * the item_price |
| 1693 | - $total_increased = wpinv_round_amount( $item_price ); |
|
| 1693 | + $total_increased = wpinv_round_amount($item_price); |
|
| 1694 | 1694 | |
| 1695 | - if ( wpinv_prices_include_tax() ) { |
|
| 1696 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1695 | + if (wpinv_prices_include_tax()) { |
|
| 1696 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | - $total = $subtotal - $discount + $tax; |
|
| 1699 | + $total = $subtotal - $discount + $tax; |
|
| 1700 | 1700 | |
| 1701 | 1701 | // Do not allow totals to go negative |
| 1702 | - if( $total < 0 ) { |
|
| 1702 | + if ($total < 0) { |
|
| 1703 | 1703 | $total = 0; |
| 1704 | 1704 | } |
| 1705 | 1705 | |
@@ -1715,25 +1715,25 @@ discard block |
||
| 1715 | 1715 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1716 | 1716 | } else { |
| 1717 | 1717 | // Set custom price. |
| 1718 | - if ( $args['custom_price'] !== '' ) { |
|
| 1718 | + if ($args['custom_price'] !== '') { |
|
| 1719 | 1719 | $item_price = $args['custom_price']; |
| 1720 | 1720 | } else { |
| 1721 | 1721 | // Allow overriding the price |
| 1722 | - if ( false !== $args['item_price'] ) { |
|
| 1722 | + if (false !== $args['item_price']) { |
|
| 1723 | 1723 | $item_price = $args['item_price']; |
| 1724 | 1724 | } else { |
| 1725 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
| 1725 | + $item_price = wpinv_get_item_price($item->ID); |
|
| 1726 | 1726 | } |
| 1727 | 1727 | } |
| 1728 | 1728 | |
| 1729 | 1729 | // Sanitizing the price here so we don't have a dozen calls later |
| 1730 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
| 1731 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
| 1730 | + $item_price = wpinv_sanitize_amount($item_price); |
|
| 1731 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
| 1732 | 1732 | |
| 1733 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1734 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
| 1735 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
| 1736 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1733 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1734 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
| 1735 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
| 1736 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1737 | 1737 | |
| 1738 | 1738 | // Setup the items meta item |
| 1739 | 1739 | $new_item = array( |
@@ -1741,29 +1741,29 @@ discard block |
||
| 1741 | 1741 | 'quantity' => $args['quantity'], |
| 1742 | 1742 | ); |
| 1743 | 1743 | |
| 1744 | - $this->items[] = $new_item; |
|
| 1744 | + $this->items[] = $new_item; |
|
| 1745 | 1745 | |
| 1746 | - if ( wpinv_prices_include_tax() ) { |
|
| 1747 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1746 | + if (wpinv_prices_include_tax()) { |
|
| 1747 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | - $total = $subtotal - $discount + $tax; |
|
| 1750 | + $total = $subtotal - $discount + $tax; |
|
| 1751 | 1751 | |
| 1752 | 1752 | // Do not allow totals to go negative |
| 1753 | - if( $total < 0 ) { |
|
| 1753 | + if ($total < 0) { |
|
| 1754 | 1754 | $total = 0; |
| 1755 | 1755 | } |
| 1756 | 1756 | |
| 1757 | 1757 | $this->cart_details[] = array( |
| 1758 | 1758 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
| 1759 | 1759 | 'id' => $item->ID, |
| 1760 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1761 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
| 1760 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1761 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
| 1762 | 1762 | 'quantity' => $args['quantity'], |
| 1763 | 1763 | 'discount' => $discount, |
| 1764 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1765 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1766 | - 'price' => wpinv_round_amount( $total ), |
|
| 1764 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1765 | + 'tax' => wpinv_round_amount($tax), |
|
| 1766 | + 'price' => wpinv_round_amount($total), |
|
| 1767 | 1767 | 'vat_rate' => $tax_rate, |
| 1768 | 1768 | 'vat_class' => $tax_class, |
| 1769 | 1769 | 'meta' => $args['meta'], |
@@ -1773,18 +1773,18 @@ discard block |
||
| 1773 | 1773 | $subtotal = $subtotal - $discount; |
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | - $added_item = end( $this->cart_details ); |
|
| 1777 | - $added_item['action'] = 'add'; |
|
| 1776 | + $added_item = end($this->cart_details); |
|
| 1777 | + $added_item['action'] = 'add'; |
|
| 1778 | 1778 | |
| 1779 | 1779 | $this->pending['items'][] = $added_item; |
| 1780 | 1780 | |
| 1781 | - $this->increase_subtotal( $subtotal ); |
|
| 1782 | - $this->increase_tax( $tax ); |
|
| 1781 | + $this->increase_subtotal($subtotal); |
|
| 1782 | + $this->increase_tax($tax); |
|
| 1783 | 1783 | |
| 1784 | 1784 | return true; |
| 1785 | 1785 | } |
| 1786 | 1786 | |
| 1787 | - public function remove_item( $item_id, $args = array() ) { |
|
| 1787 | + public function remove_item($item_id, $args = array()) { |
|
| 1788 | 1788 | // Set some defaults |
| 1789 | 1789 | $defaults = array( |
| 1790 | 1790 | 'quantity' => 1, |
@@ -1792,51 +1792,51 @@ discard block |
||
| 1792 | 1792 | 'custom_price' => '', |
| 1793 | 1793 | 'cart_index' => false, |
| 1794 | 1794 | ); |
| 1795 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1795 | + $args = wp_parse_args($args, $defaults); |
|
| 1796 | 1796 | |
| 1797 | 1797 | // Bail if this post isn't a item |
| 1798 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
| 1798 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
| 1799 | 1799 | return false; |
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1802 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1803 | 1803 | |
| 1804 | - foreach ( $this->items as $key => $item ) { |
|
| 1805 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
| 1804 | + foreach ($this->items as $key => $item) { |
|
| 1805 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
| 1806 | 1806 | continue; |
| 1807 | 1807 | } |
| 1808 | 1808 | |
| 1809 | - if ( false !== $args['cart_index'] ) { |
|
| 1810 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1811 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
| 1809 | + if (false !== $args['cart_index']) { |
|
| 1810 | + $cart_index = absint($args['cart_index']); |
|
| 1811 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
| 1812 | 1812 | |
| 1813 | - if ( ! empty( $cart_item ) ) { |
|
| 1813 | + if (!empty($cart_item)) { |
|
| 1814 | 1814 | // If the cart index item isn't the same item ID, don't remove it |
| 1815 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
| 1815 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
| 1816 | 1816 | continue; |
| 1817 | 1817 | } |
| 1818 | 1818 | } |
| 1819 | 1819 | } |
| 1820 | 1820 | |
| 1821 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
| 1822 | - if ( $item_quantity > $args['quantity'] ) { |
|
| 1823 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
| 1821 | + $item_quantity = $this->items[$key]['quantity']; |
|
| 1822 | + if ($item_quantity > $args['quantity']) { |
|
| 1823 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
| 1824 | 1824 | break; |
| 1825 | 1825 | } else { |
| 1826 | - unset( $this->items[ $key ] ); |
|
| 1826 | + unset($this->items[$key]); |
|
| 1827 | 1827 | break; |
| 1828 | 1828 | } |
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | 1831 | $found_cart_key = false; |
| 1832 | - if ( false === $args['cart_index'] ) { |
|
| 1833 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
| 1834 | - if ( $item_id != $item['id'] ) { |
|
| 1832 | + if (false === $args['cart_index']) { |
|
| 1833 | + foreach ($this->cart_details as $cart_key => $item) { |
|
| 1834 | + if ($item_id != $item['id']) { |
|
| 1835 | 1835 | continue; |
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | - if ( false !== $args['item_price'] ) { |
|
| 1839 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
| 1838 | + if (false !== $args['item_price']) { |
|
| 1839 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
| 1840 | 1840 | continue; |
| 1841 | 1841 | } |
| 1842 | 1842 | } |
@@ -1845,13 +1845,13 @@ discard block |
||
| 1845 | 1845 | break; |
| 1846 | 1846 | } |
| 1847 | 1847 | } else { |
| 1848 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1848 | + $cart_index = absint($args['cart_index']); |
|
| 1849 | 1849 | |
| 1850 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
| 1850 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
| 1851 | 1851 | return false; // Invalid cart index passed. |
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
| 1854 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
| 1855 | 1855 | return false; // We still need the proper Item ID to be sure. |
| 1856 | 1856 | } |
| 1857 | 1857 | |
@@ -1859,41 +1859,41 @@ discard block |
||
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1862 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1862 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1863 | 1863 | |
| 1864 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
| 1864 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
| 1865 | 1865 | //return false; // Invoice must contain at least one item. |
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | - $discounts = $this->get_discounts(); |
|
| 1868 | + $discounts = $this->get_discounts(); |
|
| 1869 | 1869 | |
| 1870 | - if ( $quantity > $args['quantity'] ) { |
|
| 1870 | + if ($quantity > $args['quantity']) { |
|
| 1871 | 1871 | $item_price = $cart_item['item_price']; |
| 1872 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1872 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1873 | 1873 | |
| 1874 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
| 1874 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
| 1875 | 1875 | $subtotal = $item_price * $new_quantity; |
| 1876 | 1876 | |
| 1877 | 1877 | $args['quantity'] = $new_quantity; |
| 1878 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1879 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1878 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1879 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1880 | 1880 | |
| 1881 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
| 1882 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
| 1883 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
| 1884 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
| 1881 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
| 1882 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
| 1883 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
| 1884 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
| 1885 | 1885 | |
| 1886 | 1886 | // The total increase equals the number removed * the item_price |
| 1887 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
| 1887 | + $total_decrease = wpinv_round_amount($item_price); |
|
| 1888 | 1888 | |
| 1889 | - if ( wpinv_prices_include_tax() ) { |
|
| 1890 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1889 | + if (wpinv_prices_include_tax()) { |
|
| 1890 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | - $total = $subtotal - $discount + $tax; |
|
| 1893 | + $total = $subtotal - $discount + $tax; |
|
| 1894 | 1894 | |
| 1895 | 1895 | // Do not allow totals to go negative |
| 1896 | - if( $total < 0 ) { |
|
| 1896 | + if ($total < 0) { |
|
| 1897 | 1897 | $total = 0; |
| 1898 | 1898 | } |
| 1899 | 1899 | |
@@ -1912,16 +1912,16 @@ discard block |
||
| 1912 | 1912 | |
| 1913 | 1913 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1914 | 1914 | |
| 1915 | - $remove_item = end( $this->cart_details ); |
|
| 1915 | + $remove_item = end($this->cart_details); |
|
| 1916 | 1916 | } else { |
| 1917 | 1917 | $item_price = $cart_item['item_price']; |
| 1918 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1919 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
| 1918 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1919 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
| 1920 | 1920 | |
| 1921 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
| 1921 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
| 1922 | 1922 | $tax_decrease = $tax; |
| 1923 | 1923 | |
| 1924 | - unset( $this->cart_details[$found_cart_key] ); |
|
| 1924 | + unset($this->cart_details[$found_cart_key]); |
|
| 1925 | 1925 | |
| 1926 | 1926 | $remove_item = $args; |
| 1927 | 1927 | $remove_item['id'] = $item_id; |
@@ -1932,8 +1932,8 @@ discard block |
||
| 1932 | 1932 | $remove_item['action'] = 'remove'; |
| 1933 | 1933 | $this->pending['items'][] = $remove_item; |
| 1934 | 1934 | |
| 1935 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
| 1936 | - $this->decrease_tax( $tax_decrease ); |
|
| 1935 | + $this->decrease_subtotal($subtotal_decrease); |
|
| 1936 | + $this->decrease_tax($tax_decrease); |
|
| 1937 | 1937 | |
| 1938 | 1938 | return true; |
| 1939 | 1939 | } |
@@ -1941,7 +1941,7 @@ discard block |
||
| 1941 | 1941 | public function update_items($temp = false) { |
| 1942 | 1942 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
| 1943 | 1943 | |
| 1944 | - if ( !empty( $this->cart_details ) ) { |
|
| 1944 | + if (!empty($this->cart_details)) { |
|
| 1945 | 1945 | $wpi_nosave = $temp; |
| 1946 | 1946 | $cart_subtotal = 0; |
| 1947 | 1947 | $cart_discount = 0; |
@@ -1951,65 +1951,65 @@ discard block |
||
| 1951 | 1951 | $_POST['wpinv_country'] = $this->country; |
| 1952 | 1952 | $_POST['wpinv_state'] = $this->state; |
| 1953 | 1953 | |
| 1954 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1954 | + foreach ($this->cart_details as $key => $item) { |
|
| 1955 | 1955 | $item_price = $item['item_price']; |
| 1956 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1957 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
| 1956 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1957 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
| 1958 | 1958 | $subtotal = $item_price * $quantity; |
| 1959 | 1959 | |
| 1960 | 1960 | $wpi_current_id = $this->ID; |
| 1961 | 1961 | $wpi_item_id = $item['id']; |
| 1962 | 1962 | |
| 1963 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
| 1963 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
| 1964 | 1964 | |
| 1965 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
| 1966 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
| 1967 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1965 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
| 1966 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
| 1967 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1968 | 1968 | |
| 1969 | - if ( ! $this->is_taxable() ) { |
|
| 1969 | + if (!$this->is_taxable()) { |
|
| 1970 | 1970 | $tax = 0; |
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | - if ( wpinv_prices_include_tax() ) { |
|
| 1974 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1973 | + if (wpinv_prices_include_tax()) { |
|
| 1974 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | - $total = $subtotal - $discount + $tax; |
|
| 1977 | + $total = $subtotal - $discount + $tax; |
|
| 1978 | 1978 | |
| 1979 | 1979 | // Do not allow totals to go negative |
| 1980 | - if( $total < 0 ) { |
|
| 1980 | + if ($total < 0) { |
|
| 1981 | 1981 | $total = 0; |
| 1982 | 1982 | } |
| 1983 | 1983 | |
| 1984 | 1984 | $cart_details[] = array( |
| 1985 | 1985 | 'id' => $item['id'], |
| 1986 | 1986 | 'name' => $item['name'], |
| 1987 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1988 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
| 1987 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1988 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
| 1989 | 1989 | 'quantity' => $quantity, |
| 1990 | 1990 | 'discount' => $discount, |
| 1991 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1992 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1993 | - 'price' => wpinv_round_amount( $total ), |
|
| 1991 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1992 | + 'tax' => wpinv_round_amount($tax), |
|
| 1993 | + 'price' => wpinv_round_amount($total), |
|
| 1994 | 1994 | 'vat_rate' => $tax_rate, |
| 1995 | 1995 | 'vat_class' => $tax_class, |
| 1996 | 1996 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
| 1997 | 1997 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
| 1998 | 1998 | ); |
| 1999 | 1999 | |
| 2000 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
| 2001 | - $cart_discount += (float)($discount); |
|
| 2002 | - $cart_tax += (float)($tax); |
|
| 2000 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
| 2001 | + $cart_discount += (float) ($discount); |
|
| 2002 | + $cart_tax += (float) ($tax); |
|
| 2003 | 2003 | } |
| 2004 | - if ( $cart_subtotal < 0 ) { |
|
| 2004 | + if ($cart_subtotal < 0) { |
|
| 2005 | 2005 | $cart_subtotal = 0; |
| 2006 | 2006 | } |
| 2007 | - if ( $cart_tax < 0 ) { |
|
| 2007 | + if ($cart_tax < 0) { |
|
| 2008 | 2008 | $cart_tax = 0; |
| 2009 | 2009 | } |
| 2010 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
| 2011 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
| 2012 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
| 2010 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
| 2011 | + $this->tax = wpinv_round_amount($cart_tax); |
|
| 2012 | + $this->discount = wpinv_round_amount($cart_discount); |
|
| 2013 | 2013 | |
| 2014 | 2014 | $this->recalculate_total(); |
| 2015 | 2015 | |
@@ -2021,177 +2021,177 @@ discard block |
||
| 2021 | 2021 | |
| 2022 | 2022 | public function recalculate_totals($temp = false) { |
| 2023 | 2023 | $this->update_items($temp); |
| 2024 | - $this->save( true ); |
|
| 2024 | + $this->save(true); |
|
| 2025 | 2025 | |
| 2026 | 2026 | return $this; |
| 2027 | 2027 | } |
| 2028 | 2028 | |
| 2029 | 2029 | public function needs_payment() { |
| 2030 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
| 2030 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
| 2031 | 2031 | |
| 2032 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
| 2032 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
| 2033 | 2033 | $needs_payment = true; |
| 2034 | 2034 | } else { |
| 2035 | 2035 | $needs_payment = false; |
| 2036 | 2036 | } |
| 2037 | 2037 | |
| 2038 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
| 2038 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
| 2041 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
| 2042 | 2042 | $pay_url = wpinv_get_checkout_uri(); |
| 2043 | 2043 | |
| 2044 | - if ( is_ssl() ) { |
|
| 2045 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 2044 | + if (is_ssl()) { |
|
| 2045 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 2046 | 2046 | } |
| 2047 | 2047 | |
| 2048 | 2048 | $key = $this->get_key(); |
| 2049 | 2049 | |
| 2050 | - if ( $with_key ) { |
|
| 2051 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
| 2050 | + if ($with_key) { |
|
| 2051 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
| 2052 | 2052 | } else { |
| 2053 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
| 2053 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
| 2054 | 2054 | } |
| 2055 | 2055 | |
| 2056 | - if ( $secret ) { |
|
| 2057 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
| 2056 | + if ($secret) { |
|
| 2057 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
| 2058 | 2058 | } |
| 2059 | 2059 | |
| 2060 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
| 2060 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
| 2061 | 2061 | } |
| 2062 | 2062 | |
| 2063 | - public function get_view_url( $with_key = false ) { |
|
| 2064 | - $invoice_url = get_permalink( $this->ID ); |
|
| 2063 | + public function get_view_url($with_key = false) { |
|
| 2064 | + $invoice_url = get_permalink($this->ID); |
|
| 2065 | 2065 | |
| 2066 | - if ( $with_key ) { |
|
| 2067 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 2066 | + if ($with_key) { |
|
| 2067 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
| 2068 | 2068 | } |
| 2069 | 2069 | |
| 2070 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
| 2070 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | - public function generate_key( $string = '' ) { |
|
| 2074 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2075 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
| 2073 | + public function generate_key($string = '') { |
|
| 2074 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2075 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
| 2076 | 2076 | } |
| 2077 | 2077 | |
| 2078 | 2078 | public function is_recurring() { |
| 2079 | - if ( empty( $this->cart_details ) ) { |
|
| 2079 | + if (empty($this->cart_details)) { |
|
| 2080 | 2080 | return false; |
| 2081 | 2081 | } |
| 2082 | 2082 | |
| 2083 | 2083 | $has_subscription = false; |
| 2084 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2085 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2084 | + foreach ($this->cart_details as $cart_item) { |
|
| 2085 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2086 | 2086 | $has_subscription = true; |
| 2087 | 2087 | break; |
| 2088 | 2088 | } |
| 2089 | 2089 | } |
| 2090 | 2090 | |
| 2091 | - if ( count( $this->cart_details ) > 1 ) { |
|
| 2091 | + if (count($this->cart_details) > 1) { |
|
| 2092 | 2092 | $has_subscription = false; |
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
| 2095 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
| 2096 | 2096 | } |
| 2097 | 2097 | |
| 2098 | 2098 | public function is_free_trial() { |
| 2099 | 2099 | $is_free_trial = false; |
| 2100 | 2100 | |
| 2101 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
| 2102 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
| 2101 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
| 2102 | + if (!empty($item) && $item->has_free_trial()) { |
|
| 2103 | 2103 | $is_free_trial = true; |
| 2104 | 2104 | } |
| 2105 | 2105 | } |
| 2106 | 2106 | |
| 2107 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
| 2107 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | public function is_initial_free() { |
| 2111 | 2111 | $is_initial_free = false; |
| 2112 | 2112 | |
| 2113 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
| 2113 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
| 2114 | 2114 | $is_initial_free = true; |
| 2115 | 2115 | } |
| 2116 | 2116 | |
| 2117 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
| 2117 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
| 2118 | 2118 | } |
| 2119 | 2119 | |
| 2120 | - public function get_recurring( $object = false ) { |
|
| 2120 | + public function get_recurring($object = false) { |
|
| 2121 | 2121 | $item = NULL; |
| 2122 | 2122 | |
| 2123 | - if ( empty( $this->cart_details ) ) { |
|
| 2123 | + if (empty($this->cart_details)) { |
|
| 2124 | 2124 | return $item; |
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2128 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2127 | + foreach ($this->cart_details as $cart_item) { |
|
| 2128 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2129 | 2129 | $item = $cart_item['id']; |
| 2130 | 2130 | break; |
| 2131 | 2131 | } |
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | - if ( $object ) { |
|
| 2135 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
| 2134 | + if ($object) { |
|
| 2135 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
| 2136 | 2136 | |
| 2137 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
| 2137 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
| 2138 | 2138 | } |
| 2139 | 2139 | |
| 2140 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
| 2140 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | public function get_subscription_name() { |
| 2144 | - $item = $this->get_recurring( true ); |
|
| 2144 | + $item = $this->get_recurring(true); |
|
| 2145 | 2145 | |
| 2146 | - if ( empty( $item ) ) { |
|
| 2146 | + if (empty($item)) { |
|
| 2147 | 2147 | return NULL; |
| 2148 | 2148 | } |
| 2149 | 2149 | |
| 2150 | - if ( !($name = $item->get_name()) ) { |
|
| 2150 | + if (!($name = $item->get_name())) { |
|
| 2151 | 2151 | $name = $item->post_name; |
| 2152 | 2152 | } |
| 2153 | 2153 | |
| 2154 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
| 2154 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | 2157 | public function get_subscription_id() { |
| 2158 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2158 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2159 | 2159 | |
| 2160 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
| 2161 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2160 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
| 2161 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
| 2162 | 2162 | |
| 2163 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2163 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | return $subscription_id; |
| 2167 | 2167 | } |
| 2168 | 2168 | |
| 2169 | 2169 | public function is_parent() { |
| 2170 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
| 2170 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
| 2171 | 2171 | |
| 2172 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
| 2172 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | 2175 | public function is_renewal() { |
| 2176 | 2176 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
| 2177 | 2177 | |
| 2178 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
| 2178 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | public function get_parent_payment() { |
| 2182 | 2182 | $parent_payment = NULL; |
| 2183 | 2183 | |
| 2184 | - if ( $this->is_renewal() ) { |
|
| 2185 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2184 | + if ($this->is_renewal()) { |
|
| 2185 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | 2188 | return $parent_payment; |
| 2189 | 2189 | } |
| 2190 | 2190 | |
| 2191 | 2191 | public function is_paid() { |
| 2192 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
| 2192 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
| 2193 | 2193 | |
| 2194 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
| 2194 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
| 2195 | 2195 | } |
| 2196 | 2196 | |
| 2197 | 2197 | /** |
@@ -2204,23 +2204,23 @@ discard block |
||
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | 2206 | public function is_refunded() { |
| 2207 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
| 2207 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
| 2208 | 2208 | |
| 2209 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
| 2209 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
| 2210 | 2210 | } |
| 2211 | 2211 | |
| 2212 | 2212 | public function is_free() { |
| 2213 | 2213 | $is_free = false; |
| 2214 | 2214 | |
| 2215 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
| 2216 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
| 2217 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
| 2215 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
| 2216 | + if ($this->is_parent() && $this->is_recurring()) { |
|
| 2217 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
| 2218 | 2218 | } else { |
| 2219 | 2219 | $is_free = true; |
| 2220 | 2220 | } |
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
| 2223 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
| 2224 | 2224 | } |
| 2225 | 2225 | |
| 2226 | 2226 | public function has_vat() { |
@@ -2228,41 +2228,41 @@ discard block |
||
| 2228 | 2228 | |
| 2229 | 2229 | $requires_vat = false; |
| 2230 | 2230 | |
| 2231 | - if ( $this->country ) { |
|
| 2231 | + if ($this->country) { |
|
| 2232 | 2232 | $wpi_country = $this->country; |
| 2233 | 2233 | |
| 2234 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
| 2234 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
| 2237 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | public function refresh_item_ids() { |
| 2241 | 2241 | $item_ids = array(); |
| 2242 | 2242 | |
| 2243 | - if ( !empty( $this->cart_details ) ) { |
|
| 2244 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 2245 | - if ( !empty( $item['id'] ) ) { |
|
| 2243 | + if (!empty($this->cart_details)) { |
|
| 2244 | + foreach ($this->cart_details as $key => $item) { |
|
| 2245 | + if (!empty($item['id'])) { |
|
| 2246 | 2246 | $item_ids[] = $item['id']; |
| 2247 | 2247 | } |
| 2248 | 2248 | } |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
| 2251 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
| 2252 | 2252 | |
| 2253 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
| 2253 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | - public function get_invoice_quote_type( $post_id ) { |
|
| 2257 | - if ( empty( $post_id ) ) { |
|
| 2256 | + public function get_invoice_quote_type($post_id) { |
|
| 2257 | + if (empty($post_id)) { |
|
| 2258 | 2258 | return ''; |
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | - $type = get_post_type( $post_id ); |
|
| 2261 | + $type = get_post_type($post_id); |
|
| 2262 | 2262 | |
| 2263 | - if ( 'wpi_invoice' === $type ) { |
|
| 2263 | + if ('wpi_invoice' === $type) { |
|
| 2264 | 2264 | $post_type = __('Invoice', 'invoicing'); |
| 2265 | - } else{ |
|
| 2265 | + } else { |
|
| 2266 | 2266 | $post_type = __('Quote', 'invoicing'); |
| 2267 | 2267 | } |
| 2268 | 2268 | |