Skip to content

Commit

Permalink
Merge branch 'main' into apply-wp-plugin-check-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Dec 13, 2024
2 parents 5291ae2 + dc9c8a0 commit 4ffc956
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 35 deletions.
11 changes: 11 additions & 0 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ jQuery( function( $ ) {
$( this ).closest( 'tr' ).nextAll( 'tr' ).has( 'input#next_invoice_number' ).first().show();
}
} ).trigger( 'change' );

// disable encrypted pdf option for non UBL 2.1 formats
$( "[name='wpo_wcpdf_documents_settings_invoice_ubl[ubl_format]']" ).on( 'change', function( event ) {
let $encryptedPdfCheckbox = $( this ).closest( 'form' ).find( "[name='wpo_wcpdf_documents_settings_invoice_ubl[include_encrypted_pdf]']" );

if ( $( this ).val() !== 'ubl_2_1' ) {
$encryptedPdfCheckbox.prop( 'checked', false ).prop( 'disabled', true );
} else {
$encryptedPdfCheckbox.prop( 'disabled', false );
}
} ).trigger( 'change' );

// enable settings document switch
$( '.wcpdf_document_settings_sections > h2' ).on( 'click', function() {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function backend_scripts_styles( $hook ) {
$pdfjs_version = '4.3.136';

global $wp_version;

if ( WPO_WCPDF()->admin->is_order_page() ) {

// STYLES
Expand Down Expand Up @@ -90,7 +90,7 @@ public function backend_scripts_styles( $hook ) {
if ( ! empty( $hook ) && false !== strpos( $hook, 'wpo_wcpdf_options_page' ) ) {
$tab = filter_input( INPUT_GET, 'tab', FILTER_DEFAULT );
$tab = sanitize_text_field( $tab );

wp_enqueue_style(
'wpo-wcpdf-settings-styles',
WPO_WCPDF()->plugin_url() . '/assets/css/settings-styles'.$suffix.'.css',
Expand Down Expand Up @@ -127,9 +127,13 @@ public function backend_scripts_styles( $hook ) {
wp_enqueue_style( 'wp-pointer' );
}

if ( ! wp_script_is( 'jquery-tiptip', 'enqueued' ) ) {
wp_enqueue_script( 'jquery-tiptip' );
}

wp_enqueue_script(
'wpo-wcpdf-admin',
WPO_WCPDF()->plugin_url() . '/assets/js/admin-script'.$suffix.'.js',
WPO_WCPDF()->plugin_url() . '/assets/js/admin-script' . $suffix . '.js',
array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'jquery-tiptip', 'wp-pointer' ),
WPO_WCPDF_VERSION
);
Expand Down
25 changes: 20 additions & 5 deletions includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public function get_ubl_settings_fields( $option_name ) {
$settings_fields = array(
array(
'type' => 'section',
'id' => $this->type.'_ubl',
'id' => $this->type . '_ubl',
'title' => '',
'callback' => 'section',
),
Expand All @@ -592,18 +592,32 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'enabled',
'title' => __( 'Enable', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'enabled',
)
),
array(
'type' => 'setting',
'id' => 'ubl_format',
'title' => __( 'Format', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'ubl_format',
'options' => apply_filters( 'wpo_wcpdf_document_ubl_settings_formats', array(
'ubl_2_1' => __( 'UBL 2.1' , 'woocommerce-pdf-invoices-packing-slips' ),
), $this ),
)
),
array(
'type' => 'setting',
'id' => 'attach_to_email_ids',
'title' => __( 'Attach to:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'multiple_checkboxes',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'attach_to_email_ids',
Expand All @@ -617,11 +631,11 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'include_encrypted_pdf',
'title' => __( 'Include encrypted PDF:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'include_encrypted_pdf',
'description' => __( 'Include the PDF Invoice file encrypted in the UBL file.', 'woocommerce-pdf-invoices-packing-slips' ),
'description' => __( 'Embed the encrypted PDF invoice file within the UBL document. Note that this option may not be supported by all UBL formats.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
);
Expand Down Expand Up @@ -691,6 +705,7 @@ public function get_settings_categories( string $output_format ): array {
'title' => __( 'General', 'woocommerce-pdf-invoices-packing-slips' ),
'members' => array(
'enabled',
'ubl_format',
'attach_to_email_ids',
'include_encrypted_pdf',
),
Expand Down
21 changes: 21 additions & 0 deletions includes/Documents/OrderDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ public function is_enabled( $output_format = 'pdf' ) {

return apply_filters( 'wpo_wcpdf_document_is_enabled', $is_enabled, $this->type, $output_format );
}

/**
* Get the UBL format
*
* @return string|false
*/
public function get_ubl_format() {
$ubl_format = $this->get_setting( 'ubl_format', false, 'ubl' );

return apply_filters( 'wpo_wcpdf_document_ubl_format', $ubl_format, $this );
}

public function get_hook_prefix() {
return 'wpo_wcpdf_' . $this->slug . '_get_';
Expand Down Expand Up @@ -1295,6 +1306,16 @@ public function shop_address() {
echo esc_html( $this->get_shop_address() );
}

/**
* Return/Show shop/company phone number if provided.
*/
public function get_shop_phone_number() {
return $this->get_settings_text( 'shop_phone_number', '', false );
}
public function shop_phone_number() {
echo $this->get_shop_phone_number();
}

/**
* Return/Show shop/company footer imprint, copyright etc.
*/
Expand Down
35 changes: 20 additions & 15 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,22 +511,27 @@ public function add_settings_fields( $settings_fields, $page, $option_group, $op

}

public function get_common_document_settings() {
$common_settings = array(
'paper_size' => isset( $this->general_settings['paper_size'] ) ? $this->general_settings['paper_size'] : '',
'font_subsetting' => isset( $this->general_settings['font_subsetting'] ) || ( defined("DOMPDF_ENABLE_FONTSUBSETTING") && DOMPDF_ENABLE_FONTSUBSETTING === true ) ? true : false,
'header_logo' => isset( $this->general_settings['header_logo'] ) ? $this->general_settings['header_logo'] : '',
'header_logo_height' => isset( $this->general_settings['header_logo_height'] ) ? $this->general_settings['header_logo_height'] : '',
'vat_number' => isset( $this->general_settings['vat_number'] ) ? $this->general_settings['vat_number'] : '',
'coc_number' => isset( $this->general_settings['coc_number'] ) ? $this->general_settings['coc_number'] : '',
'shop_name' => isset( $this->general_settings['shop_name'] ) ? $this->general_settings['shop_name'] : '',
'shop_address' => isset( $this->general_settings['shop_address'] ) ? $this->general_settings['shop_address'] : '',
'footer' => isset( $this->general_settings['footer'] ) ? $this->general_settings['footer'] : '',
'extra_1' => isset( $this->general_settings['extra_1'] ) ? $this->general_settings['extra_1'] : '',
'extra_2' => isset( $this->general_settings['extra_2'] ) ? $this->general_settings['extra_2'] : '',
'extra_3' => isset( $this->general_settings['extra_3'] ) ? $this->general_settings['extra_3'] : '',
/**
* Get document general settings.
*
* @return array
*/
public function get_common_document_settings(): array {
return array(
'paper_size' => $this->general_settings['paper_size'] ?? '',
'font_subsetting' => isset( $this->general_settings['font_subsetting'] ) || ( defined( "DOMPDF_ENABLE_FONTSUBSETTING" ) && DOMPDF_ENABLE_FONTSUBSETTING === true ),
'header_logo' => $this->general_settings['header_logo'] ?? '',
'header_logo_height' => $this->general_settings['header_logo_height'] ?? '',
'vat_number' => $this->general_settings['vat_number'] ?? '',
'coc_number' => $this->general_settings['coc_number'] ?? '',
'shop_name' => $this->general_settings['shop_name'] ?? '',
'shop_phone_number' => $this->general_settings['shop_phone_number'] ?? '',
'shop_address' => $this->general_settings['shop_address'] ?? '',
'footer' => $this->general_settings['footer'] ?? '',
'extra_1' => $this->general_settings['extra_1'] ?? '',
'extra_2' => $this->general_settings['extra_2'] ?? '',
'extra_3' => $this->general_settings['extra_3'] ?? '',
);
return $common_settings;
}

public function get_document_settings( $document_type, $output_format = 'pdf' ) {
Expand Down
17 changes: 15 additions & 2 deletions includes/Settings/SettingsGeneral.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function init_settings() {
'option_name' => $option_name,
'id' => 'vat_number',
'translatable' => true,
'description' => __( 'Required for UBL output format.<br>You can display this number on the invoice from the document settings.', 'woocommerce-pdf-invoices-packing-slips' ) . ' ' . $requires_pro ,
'description' => __( 'Required for UBL output format.<br>You can display this number on the invoice from the document settings.', 'woocommerce-pdf-invoices-packing-slips' ) . ' ' . $requires_pro,
)
),
array(
Expand All @@ -198,7 +198,20 @@ public function init_settings() {
'option_name' => $option_name,
'id' => 'coc_number',
'translatable' => true,
'description' => __( 'Required for UBL output format.<br>You can display this number on the invoice from the document settings.', 'woocommerce-pdf-invoices-packing-slips' ) . ' ' . $requires_pro ,
'description' => __( 'Required for UBL output format.<br>You can display this number on the invoice from the document settings.', 'woocommerce-pdf-invoices-packing-slips' ) . ' ' . $requires_pro,
)
),
array(
'type' => 'setting',
'id' => 'shop_phone_number',
'title' => __( 'Shop Phone Number', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'text_input',
'section' => 'general_settings',
'args' => array(
'option_name' => $option_name,
'id' => 'shop_phone_number',
'translatable' => true,
'description' => __( 'Mandatory for certain UBL formats.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Donate link: https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-
Tags: woocommerce, pdf, ubl, invoices, packing slips
Requires at least: 4.4
Tested up to: 6.7
Requires PHP: 7.2
Stable tag: 3.9.1-beta-2
Requires PHP: 7.4
Stable tag: 3.9.1-beta-4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
2 changes: 1 addition & 1 deletion ubl/Builders/SabreBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function build( Document $document ) {
$namespaces = array_flip( $document->get_namespaces() );
$this->service->namespaceMap = $namespaces;

return $this->service->write( 'Invoice', $document->get_data() );
return $this->service->write( $document->get_root_element(), $document->get_data() );
}

}
1 change: 1 addition & 0 deletions ubl/Documents/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function set_order_document( OrderDocument $order_document ) {
$this->order_document = $order_document;
}

abstract public function get_root_element();
abstract public function get_format();
abstract public function get_namespaces();
abstract public function get_data();
Expand Down
8 changes: 6 additions & 2 deletions ubl/Documents/UblDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
}

class UblDocument extends Document {

public function get_root_element() {
return apply_filters( 'wpo_wc_ubl_document_root_element', 'Invoice', $this );
}

public function get_format() {
$format = apply_filters( 'wpo_wc_ubl_document_format' , array(
Expand Down Expand Up @@ -82,7 +86,7 @@ public function get_format() {
'enabled' => true,
'handler' => \WPO\IPS\UBL\Handlers\Invoice\InvoiceLineHandler::class,
),
) );
), $this );

foreach ( $format as $key => $element ) {
if ( false === $element['enabled'] ) {
Expand All @@ -98,7 +102,7 @@ public function get_namespaces() {
'cac' => 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
'cbc' => 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
'' => 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
) );
), $this );
}

public function get_data() {
Expand Down
2 changes: 1 addition & 1 deletion views/advanced-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<!-- clear_released_semaphore_locks -->
<div class="tool">
<h4><?php esc_html_e( 'Remove released semaphore locks', 'woocommerce-pdf-invoices-packing-slips' ); ?></h4>
<p><?php esc_html_e( 'Clean up the released semaphore locks from the database.', 'woocommerce-pdf-invoices-packing-slips' ); ?></p>
<p><?php esc_html_e( 'Clean up the released semaphore locks from the database. These locks prevent simultaneous document generation requests, ensuring correct document numbering. Once released, they are safe to remove.', 'woocommerce-pdf-invoices-packing-slips' ); ?></p>
<form method="post" id="clear_released_semaphore_locks">
<input type="hidden" name="debug_tool" value="clear_released_semaphore_locks">
<input type="submit" class="button button-secondary submit" value="<?php esc_html_e( 'Remove released locks', 'woocommerce-pdf-invoices-packing-slips' ); ?>">
Expand Down
6 changes: 3 additions & 3 deletions woocommerce-pdf-invoices-packingslips.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* Requires Plugins: woocommerce
* Plugin URI: https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-bundle/
* Description: Create, print & email PDF or UBL Invoices & PDF Packing Slips for WooCommerce orders.
* Version: 3.9.1-beta-2
* Version: 3.9.1-beta-4
* Author: WP Overnight
* Author URI: https://www.wpovernight.com
* License: GPLv2 or later
* License URI: https://opensource.org/licenses/gpl-license.php
* Text Domain: woocommerce-pdf-invoices-packing-slips
* WC requires at least: 3.3
* WC tested up to: 9.4
* WC tested up to: 9.5
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -22,7 +22,7 @@

class WPO_WCPDF {

public $version = '3.9.1-beta-2';
public $version = '3.9.1-beta-4';
public $version_php = '7.4';
public $version_woo = '3.3';
public $version_wp = '4.4';
Expand Down

0 comments on commit 4ffc956

Please sign in to comment.