WooCommerce PDF Invoices - Version 3.0.6

Version Description

  • June 7, 2019 =

-IImproved: Sequential invoice numbering by refactoring code.

Download this release

Release Info

Developer baaaaas
Plugin Icon 128x128 WooCommerce PDF Invoices
Version 3.0.6
Comparing to
See all releases

Code changes from version 3.0.5 to 3.0.6

bootstrap.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce PDF Invoices
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
5
  * Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
6
- * Version: 3.0.5
7
  * Author: Bas Elbers
8
  * Author URI: http://wcpdfinvoices.com
9
  * License: GPL-2.0+
@@ -16,7 +16,7 @@
16
 
17
  defined( 'ABSPATH' ) || exit;
18
 
19
- define( 'WPI_VERSION', '3.0.5' );
20
 
21
  /**
22
  * Load WooCommerce PDF Invoices plugin.
3
  * Plugin Name: WooCommerce PDF Invoices
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
5
  * Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
6
+ * Version: 3.0.6
7
  * Author: Bas Elbers
8
  * Author URI: http://wcpdfinvoices.com
9
  * License: GPL-2.0+
16
 
17
  defined( 'ABSPATH' ) || exit;
18
 
19
+ define( 'WPI_VERSION', '3.0.6' );
20
 
21
  /**
22
  * Load WooCommerce PDF Invoices plugin.
includes/abstracts/abstract-invoice.php CHANGED
@@ -74,6 +74,15 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
74
  $this->filename = basename( $this->full_path );
75
  }
76
 
 
 
 
 
 
 
 
 
 
77
  /**
78
  * Invoice number.
79
  *
@@ -232,7 +241,7 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
232
  return $next_number;
233
  }
234
 
235
- $max_invoice_number = self::get_max_invoice_number();
236
  $next_number = $max_invoice_number + 1;
237
 
238
  return $next_number;
@@ -241,9 +250,11 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
241
  /**
242
  * Return highest invoice number.
243
  *
 
 
244
  * @return int
245
  */
246
- public static function get_max_invoice_number() {
247
  global $wpdb;
248
 
249
  if ( false === (bool) WPI()->get_option( 'reset_counter_yearly' ) ) {
@@ -254,7 +265,7 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
254
  INNER JOIN $wpdb->postmeta pm2 ON pm1.post_id = pm2.post_id
255
  WHERE pm1.meta_key = %s AND YEAR(pm1.meta_value) = %d AND pm2.meta_key = %s",
256
  '_bewpi_invoice_date',
257
- (int) date_i18n( 'Y', current_time( 'timestamp' ) ),
258
  '_bewpi_invoice_number'
259
  );
260
  } else {
@@ -283,17 +294,14 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
283
  parent::delete( $this->full_path );
284
  }
285
 
286
- if ( empty( $this->number ) ) {
287
- // Use WooCommerce order numbers as invoice numbers?
288
- if ( 'woocommerce_order_number' === WPI()->get_option( 'template', 'invoice_number_type' ) ) {
289
- $this->number = $this->order->get_order_number();
290
- } else {
291
- $this->number = $this->get_next_invoice_number();
292
- }
293
- }
294
 
295
- if ( empty( $this->date ) ) {
296
- $this->date = apply_filters( 'wpi_invoice_date', current_time( 'mysql' ), $this );
 
 
 
297
  }
298
 
299
  $pdf_path = $this->get_rel_pdf_path() . '/' . $this->get_formatted_number() . '.pdf';
@@ -301,7 +309,7 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
301
  $this->filename = basename( $this->full_path );
302
 
303
  // update invoice data in db.
304
- $order_id = BEWPI_WC_Order_Compatibility::get_id( $this->order );
305
  update_post_meta( $order_id, '_bewpi_invoice_date', $this->date );
306
  update_post_meta( $order_id, '_bewpi_invoice_number', $this->number );
307
  update_post_meta( $order_id, '_bewpi_invoice_pdf_path', $pdf_path );
74
  $this->filename = basename( $this->full_path );
75
  }
76
 
77
+ /**
78
+ * Get invoice yeat.
79
+ *
80
+ * @return int
81
+ */
82
+ public function get_year() {
83
+ return (int) $this->year;
84
+ }
85
+
86
  /**
87
  * Invoice number.
88
  *
241
  return $next_number;
242
  }
243
 
244
+ $max_invoice_number = self::get_max_invoice_number( $this->year );
245
  $next_number = $max_invoice_number + 1;
246
 
247
  return $next_number;
250
  /**
251
  * Return highest invoice number.
252
  *
253
+ * @param int $year invoice year.
254
+ *
255
  * @return int
256
  */
257
+ public static function get_max_invoice_number( $year ) {
258
  global $wpdb;
259
 
260
  if ( false === (bool) WPI()->get_option( 'reset_counter_yearly' ) ) {
265
  INNER JOIN $wpdb->postmeta pm2 ON pm1.post_id = pm2.post_id
266
  WHERE pm1.meta_key = %s AND YEAR(pm1.meta_value) = %d AND pm2.meta_key = %s",
267
  '_bewpi_invoice_date',
268
+ (int) $year,
269
  '_bewpi_invoice_number'
270
  );
271
  } else {
294
  parent::delete( $this->full_path );
295
  }
296
 
297
+ $this->date = apply_filters( 'wpi_invoice_date', current_time( 'mysql' ), $this );
298
+ $this->year = date_i18n( 'Y', strtotime( $this->date ) );
 
 
 
 
 
 
299
 
300
+ // Use WooCommerce order numbers as invoice numbers?
301
+ if ( 'woocommerce_order_number' === WPI()->get_option( 'template', 'invoice_number_type' ) ) {
302
+ $this->number = $this->order->get_order_number();
303
+ } else {
304
+ $this->number = $this->get_next_invoice_number();
305
  }
306
 
307
  $pdf_path = $this->get_rel_pdf_path() . '/' . $this->get_formatted_number() . '.pdf';
309
  $this->filename = basename( $this->full_path );
310
 
311
  // update invoice data in db.
312
+ $order_id = $this->order->get_id();
313
  update_post_meta( $order_id, '_bewpi_invoice_date', $this->date );
314
  update_post_meta( $order_id, '_bewpi_invoice_number', $this->number );
315
  update_post_meta( $order_id, '_bewpi_invoice_pdf_path', $pdf_path );
includes/abstracts/abstract-settings.php CHANGED
@@ -434,7 +434,7 @@ abstract class BEWPI_Abstract_Settings {
434
  <input id="<?php echo $args['id']; ?>"
435
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
436
  type="<?php echo $args['type']; ?>"
437
- value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number() + 1 ); ?>"
438
  <?php
439
  if ( isset( $args['attrs'] ) ) {
440
  foreach ( $args['attrs'] as $attr ) {
434
  <input id="<?php echo $args['id']; ?>"
435
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
436
  type="<?php echo $args['type']; ?>"
437
+ value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number( (int) date_i18n( 'Y', current_time( 'timestamp' ) ) ) + 1 ); ?>"
438
  <?php
439
  if ( isset( $args['attrs'] ) ) {
440
  foreach ( $args['attrs'] as $attr ) {
includes/compatibility/abstract-bewpi-setting.php CHANGED
@@ -141,7 +141,7 @@ if ( ! class_exists( 'BEWPI_Abstract_Setting' ) ) {
141
  <input id="<?php echo $args['id']; ?>"
142
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
143
  type="<?php echo $args['type']; ?>"
144
- value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number() + 1 ); ?>"
145
  <?php
146
  if ( isset ( $args['attrs'] ) ) {
147
  foreach ( $args['attrs'] as $attr ) {
@@ -155,9 +155,9 @@ if ( ! class_exists( 'BEWPI_Abstract_Setting' ) ) {
155
  }
156
 
157
  public function input_callback( $args ) {
158
- $options = get_option( $args['page'] );
159
- $class = ( isset( $args['class'] ) ) ? $args['class'] : "bewpi-notes";
160
- $is_checkbox = $args['type'] === 'checkbox';
161
  if ( $is_checkbox ) { ?>
162
  <input type="hidden" name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>" value="0"/>
163
  <?php } ?>
141
  <input id="<?php echo $args['id']; ?>"
142
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
143
  type="<?php echo $args['type']; ?>"
144
+ value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number( (int) date_i18n( 'Y', current_time( 'timestamp' ) ) ) + 1 ); ?>"
145
  <?php
146
  if ( isset ( $args['attrs'] ) ) {
147
  foreach ( $args['attrs'] as $attr ) {
155
  }
156
 
157
  public function input_callback( $args ) {
158
+ $options = get_option( $args['page'] );
159
+ $class = ( isset( $args['class'] ) ) ? $args['class'] : "bewpi-notes";
160
+ $is_checkbox = $args['type'] === 'checkbox';
161
  if ( $is_checkbox ) { ?>
162
  <input type="hidden" name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>" value="0"/>
163
  <?php } ?>
includes/woocommerce-pdf-invoices.php CHANGED
@@ -738,7 +738,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
738
 
739
  // Create confirm message when deleting PDF invoice.
740
  $message = __( 'Are you sure to delete the PDF invoice?', 'woocommerce-pdf-invoices' );
741
- if ( 'sequential_number' === BEWPI_Invoice::get_number_type() && $invoice->get_number() !== BEWPI_Abstract_Invoice::get_max_invoice_number() ) {
742
 
743
  /* translators: $d: invoice number */
744
  $message .= ' ' . sprintf( __( 'You will be missing a PDF invoice with invoice number %d and thus creating an accounting gap!', 'woocommerce-pdf-invoices' ), $invoice->get_number() );
738
 
739
  // Create confirm message when deleting PDF invoice.
740
  $message = __( 'Are you sure to delete the PDF invoice?', 'woocommerce-pdf-invoices' );
741
+ if ( 'sequential_number' === BEWPI_Invoice::get_number_type() && $invoice->get_number() !== BEWPI_Abstract_Invoice::get_max_invoice_number( $invoice->get_year() ) ) {
742
 
743
  /* translators: $d: invoice number */
744
  $message .= ' ' . sprintf( __( 'You will be missing a PDF invoice with invoice number %d and thus creating an accounting gap!', 'woocommerce-pdf-invoices' ), $invoice->get_number() );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: woocommerce pdf invoices, invoice, packing slips, delivery note, packing list, shipping list, generate, pdf, woocommerce, attachment, email, customer invoice, processing, vat, tax, sequential, number, dropbox, google drive, onedrive, egnyte, cloud, storage
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
- Stable tag: 3.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -344,6 +344,10 @@ Since version 2.9.4 the plugin removed the ability to update the PDF invoice whe
344
 
345
  == Changelog ==
346
 
 
 
 
 
347
  = 3.0.5 - May 31, 2019 =
348
 
349
  - Fixed: Sequential invoice numbering not incrementing.
4
  Tags: woocommerce pdf invoices, invoice, packing slips, delivery note, packing list, shipping list, generate, pdf, woocommerce, attachment, email, customer invoice, processing, vat, tax, sequential, number, dropbox, google drive, onedrive, egnyte, cloud, storage
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 3.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
344
 
345
  == Changelog ==
346
 
347
+ = 3.0.6 - June 7, 2019 =
348
+
349
+ -IImproved: Sequential invoice numbering by refactoring code.
350
+
351
  = 3.0.5 - May 31, 2019 =
352
 
353
  - Fixed: Sequential invoice numbering not incrementing.