Skip to content

Commit

Permalink
Merge branch 'main' into 829-preview-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Jan 9, 2025
2 parents 72af162 + a73f5ab commit 817d765
Show file tree
Hide file tree
Showing 41 changed files with 1,938 additions and 916 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- name: Checkout Git repository
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Add Issues to Project

on:
issues:
types: [opened]
env:
GITHUB_API_TOKEN: ${{ secrets.PAT }}

jobs:
add_to_project:
runs-on: ubuntu-latest
steps:
- name: Assign new issues to the project
uses: tcassou/[email protected]
with:
project_url: 'https://github.com/orgs/wpovernight/projects/22'
10 changes: 10 additions & 0 deletions assets/css/settings-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ body.woocommerce_page_wpo_wcpdf_options_page {
padding-top: 0.7em;
}

#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td p.description > span.wpo-warning {
width: 100%;
box-sizing: border-box;
word-wrap: break-word;
}

#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="text"],
#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="url"],
#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > select,
Expand Down Expand Up @@ -510,6 +516,10 @@ body.woocommerce_page_wpo_wcpdf_options_page {
flex: 0 0 100%;
}

#wpo-wcpdf-preview-wrapper[data-preview-states="1"].ubl .sidebar > form {
max-width: 100%;
}

#wpo-wcpdf-preview-wrapper[data-preview-states="2"][data-preview-state="closed"] .sidebar {
flex: 0 0 95%;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/css/settings-styles.min.css

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ jQuery( function( $ ) {
}
} ).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() {
$( this ).parent().find( 'ul' ).toggleClass( 'active' );
Expand Down Expand Up @@ -373,7 +384,14 @@ jQuery( function( $ ) {
} );

// Trigger the Preview
function triggerPreview( timeoutDuration ) {
function triggerPreview( timeoutDuration = 0 ) {
$previewStates = $( '#wpo-wcpdf-preview-wrapper' ).data( 'preview-states' );

// Check if preview is disabled and return
if ( 'undefined' === $previewStates || 1 === $previewStates ) {
return;
}

timeoutDuration = typeof timeoutDuration == 'number' ? timeoutDuration : 0;

loadPreviewData();
Expand Down Expand Up @@ -430,6 +448,7 @@ jQuery( function( $ ) {

// Load the Preview with AJAX
function ajaxLoadPreview() {
console.log( 'Loading preview...' );
let worker = wpo_wcpdf_admin.pdfjs_worker;
let canvasId = 'preview-canvas';
let data = {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions assets/js/ubl-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jQuery( function ( $ ) {

$( 'select[name^="wpo_wcpdf_settings_ubl_taxes"][name$="[scheme]"], \
select[name^="wpo_wcpdf_settings_ubl_taxes"][name$="[category]"], \
select[name^="wpo_wcpdf_settings_ubl_taxes"][name$="[reason]"]'
).on( 'change', function () {
let currentValue = $( this ).data( 'current' );
let newValue = $( this ).find( 'option:selected' ).val();
let $current = $( this ).closest( 'td, th' ).find( '.current' );
let newHtml = `${wpo_wcpdf_ubl.new}: <code>${newValue}</code> <strong>(${wpo_wcpdf_ubl.unsaved})</strong>`;
let oldHtml = `${wpo_wcpdf_ubl.code}: <code>${currentValue}</code>`;

// Only update the '.current' element if the value has changed
if ( newValue !== currentValue ) {
$current.html( newHtml );
} else {
$current.html( oldHtml );
}

// Display the remark if available
if ( $( this ).attr( 'name' ).endsWith( '[reason]' ) ) {
let remark = wpo_wcpdf_ubl.remarks[ 'reason' ][ newValue ];

if ( remark ) {
$( this ).closest( 'tr' ).find( '.remark' ).html( remark );
} else {
$( this ).closest( 'tr' ).find( '.remark' ).html( '' );
}
}
} );

} );
1 change: 1 addition & 0 deletions assets/js/ubl-script.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 31 additions & 3 deletions includes/Assets.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace WPO\IPS;

use WPO\IPS\UBL\Settings\TaxesSettings;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
Expand All @@ -20,7 +22,7 @@ public static function instance() {

public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts_styles' ), 11 ); // after WC
}

/**
Expand Down Expand Up @@ -134,9 +136,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 Expand Up @@ -232,7 +238,7 @@ public function backend_scripts_styles ( $hook ) {
}

// status/debug page scripts
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpo_wcpdf_options_page' && isset( $_REQUEST['tab'] ) && $_REQUEST['tab'] == 'debug' ) {
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpo_wcpdf_options_page' && isset( $_REQUEST['tab'] ) && 'debug' === $_REQUEST['tab'] ) {
wp_enqueue_style(
'wpo-wcpdf-jquery-ui-styles',
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'
Expand Down Expand Up @@ -275,6 +281,28 @@ public function backend_scripts_styles ( $hook ) {
);

}

// ubl taxes
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpo_wcpdf_options_page' && isset( $_REQUEST['tab'] ) && 'ubl' === $_REQUEST['tab'] ) {
wp_enqueue_script(
'wpo-wcpdf-ubl',
WPO_WCPDF()->plugin_url() . '/assets/js/ubl-script' . $suffix . '.js',
array( 'jquery' ),
WPO_WCPDF_VERSION,
true
);

wp_localize_script(
'wpo-wcpdf-ubl',
'wpo_wcpdf_ubl',
array(
'code' => __( 'Code', 'woocommerce-pdf-invoices-packing-slips' ),
'new' => __( 'New', 'woocommerce-pdf-invoices-packing-slips' ),
'unsaved' => __( 'unsaved', 'woocommerce-pdf-invoices-packing-slips' ),
'remarks' => TaxesSettings::get_available_remarks(),
)
);
}
}

}
Expand Down
27 changes: 18 additions & 9 deletions includes/Compatibility/ThirdPartyPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ public function add_yith_product_bundles_classes( string $classes, ?string $docu
if ( empty( $order ) ) {
return $classes;
}

if ( ! $order instanceof \WC_Abstract_Order ) {
return $classes;
}

if ( empty( $item_id ) && ! empty( $classes ) ) {
$item_id = $this->get_item_id_from_classes( $classes );
}
Expand All @@ -226,7 +226,7 @@ public function add_yith_product_bundles_classes( string $classes, ?string $docu
} else {
return $classes;
}

$product = null;
$bundled_by = null;

Expand Down Expand Up @@ -378,7 +378,7 @@ function restore_wgm_thumbnails( $document_type, $document ) {
}

/**
* Adds invoice number filter to the search filters available in the admin order search.
* Adds "Invoice numbers" filter to the search filters available in the admin order search.
*
* @param array $options List of available filters.
*
Expand All @@ -388,24 +388,33 @@ function hpos_admin_search_filters( array $options ): array {
if ( WPO_WCPDF()->admin->invoice_number_search_enabled() ) {
$all = $options['all'];
unset( $options['all'] );
$options['invoice_number'] = __( 'Invoice number', 'woocommerce-pdf-invoices-packing-slips' );
$options['invoice_numbers'] = __( 'Invoice numbers', 'woocommerce-pdf-invoices-packing-slips' );
$options['all'] = $all;
}

return $options;
}

/**
* Modifies the arguments passed to `wc_get_orders()` to support 'invoice_number' order search filter.
* Modifies the arguments passed to `wc_get_orders()` to support 'invoice_numbers' order search filter.
*
* @param array $order_query_args Arguments to be passed to `wc_get_orders()`.
*
* @return array
*/
function invoice_number_query_args( array $order_query_args ): array {
if ( isset( $order_query_args['search_filter'] ) && 'invoice_number' === $order_query_args['search_filter'] && isset( $order_query_args['s'] ) ) {
$order_query_args['meta_key'] = '_wcpdf_invoice_number';
$order_query_args['meta_value'] = $order_query_args['s'];
if ( isset( $order_query_args['search_filter'] ) && 'invoice_numbers' === $order_query_args['search_filter'] && ! empty( $order_query_args['s'] ) ) {
$invoice_numbers = explode( ',', $order_query_args['s'] );
$invoice_numbers = array_map( function ( $number ) {
return sanitize_text_field( trim( $number ) );
}, $invoice_numbers );

$order_query_args['meta_query'] = $order_query_args['meta_query'] ?? array();
$order_query_args['meta_query'][] = [
'key' => '_wcpdf_invoice_number',
'value' => $invoice_numbers,
'compare' => 'IN',
];
$order_query_args['search_filter'] = 'all';
unset( $order_query_args['s'] );
}
Expand Down
68 changes: 62 additions & 6 deletions includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function get_pdf_settings_fields( $option_name ) {
'args' => array(
'option_name' => $option_name,
'id' => 'invoice_number_search',
'description' => __( 'The search process may be slower on non-HPOS stores. For a more efficient search, you can utilize the <a href="https://woocommerce.com/document/high-performance-order-storage/" target="_blank">HPOS</a> feature, allowing you to search orders by invoice numbers using the search type selector.', 'woocommerce-pdf-invoices-packing-slips' ),
'description' => __( 'The search process may be slower on non-HPOS stores. For a more efficient search, you can utilize the <a href="https://woocommerce.com/document/high-performance-order-storage/" target="_blank">HPOS</a> feature to search for orders by invoice numbers using the search type selector. Additionally, it allows you to search for multiple orders using a comma-separated list of invoice numbers.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
Expand Down Expand Up @@ -571,7 +571,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 @@ -580,18 +580,33 @@ 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 ),
'description' => $this->get_ubl_format_description(),
)
),
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 @@ -605,11 +620,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 @@ -679,6 +694,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 All @@ -689,6 +705,46 @@ public function get_settings_categories( string $output_format ): array {
return apply_filters( 'wpo_wcpdf_document_settings_categories', $settings_categories[ $output_format ] ?? array(), $output_format, $this );
}

/**
* Get UBL Format setting description
*
* @return string
*/
private function get_ubl_format_description(): string {
$extensions_available = array();
$ubl_format_description = '';

if ( ! class_exists( 'WPO_IPS_XRechnung' ) ) {
$extensions_available['xrechnung'] = array(
'title' => __( 'EN16931 XRechnung', 'woocommerce-pdf-invoices-packing-slips' ),
'url' => 'https://github.com/wpovernight/wpo-ips-xrechnung/releases/latest/',
);
}

if ( ! empty( $extensions_available ) ) {
$ubl_format_description = __( 'Formats available through extensions', 'woocommerce-pdf-invoices-packing-slips' ) . ':';

foreach ( $extensions_available as $extension ) {
$ubl_format_description .= ' <a href="' . esc_url( $extension['url'] ) . '" target="_blank">' . esc_html( $extension['title'] ) . '</a>';

if ( next( $extensions_available ) ) {
$ubl_format_description .= ',';
} else {
$ubl_format_description .= '<br>';
}
}
}

$ubl_format_description .= sprintf(
/* translators: %1$s: opening link tag, %2$s: closing link tag */
__( 'If the format you need isn\'t listed, please don\'t hesitate to %1$scontact us%2$s!', 'woocommerce-pdf-invoices-packing-slips' ),
'<a href="https://wpovernight.com/contact/" target="_blank">',
'</a>'
);

return $ubl_format_description;
}

}

endif; // class_exists
Loading

0 comments on commit 817d765

Please sign in to comment.