Skip to content

Commit

Permalink
Merge branch 'main' into 636-due_date
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Nov 3, 2023
2 parents 6e056e0 + 83e3451 commit 464e02f
Show file tree
Hide file tree
Showing 26 changed files with 1,489 additions and 584 deletions.
17 changes: 16 additions & 1 deletion assets/css/debug-tools.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
form#wpo-wcpdf-settings {
margin-left: 0 !important;
min-height: 600px;
}
#debug-tools {
width: 50%;
width: 100%;
margin-top: 2em;
}

#debug-tools .wrapper {
Expand Down Expand Up @@ -34,6 +36,19 @@ form#wpo-wcpdf-settings {
max-width: 25rem;
}

#debug-tools #danger_zone {
margin-top: 20px;
background-color: #fcf9e8;
}

#debug-tools #danger_zone .notice {
margin: 0;
}

#debug-tools .add-info {
margin-left: 6px;
}

#document_custom_redirect_page,
#document_custom_redirect_page + .description {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/debug-tools.min.css

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

12 changes: 10 additions & 2 deletions assets/css/settings-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ table.wcpdf_documents_settings_list td.title {
color: #222;
}

.wcpdf_advanced_numbers_choose_table {
margin-top: 20px;
}

.wcpdf_document_settings_document_output_formats {
margin-bottom: 30px;
}
Expand Down Expand Up @@ -263,7 +267,7 @@ body.woocommerce_page_wpo_wcpdf_options_page {
margin: 15px 0 0;
}

.nav-tab-wrapper a.nav-tab {
.nav-tab-wrapper:not( .wcpdf_debug_settings_sections > .nav-tab-wrapper) a.nav-tab {
background: transparent;
border: none;
border-bottom: 3px solid transparent;
Expand All @@ -272,7 +276,7 @@ body.woocommerce_page_wpo_wcpdf_options_page {
font-size: 15px;
}

.nav-tab-wrapper a.nav-tab.nav-tab-active {
.nav-tab-wrapper:not( .wcpdf_debug_settings_sections > .nav-tab-wrapper) a.nav-tab.nav-tab-active {
border-bottom: 3px solid #51266b;
}

Expand Down Expand Up @@ -435,6 +439,10 @@ body.woocommerce_page_wpo_wcpdf_options_page {
font-size: 12px;
}

#wpo-wcpdf-settings .system-status-table {
margin-top: 2em;
}

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

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions assets/js/debug-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,103 @@ jQuery( function( $ ) {
}
} ).trigger( 'change' );

// danger zone enabled notice
if ( true === wpo_wcpdf_debug.danger_zone['enabled'] ) {
let notice = '<div class="notice notice-warning inline"><p>' + wpo_wcpdf_debug.danger_zone['message'] + '</p></div>';
$( "input#enable_danger_zone_tools" ).closest( 'td' ).find( '.description' ).append( notice );
}

// number search
$( document.body ).on( 'click', '#wpo-wcpdf-settings a.number-search-button', function( e ) {
e.preventDefault();

let search_val = $( this ).closest( 'div' ).find( ':input[name="number_search_input"]' ).val();
window.location.href = window.location.href + '&s=' + search_val;
} );

// datepicker
$( '#renumber-date-from, #renumber-date-to, #delete-date-from, #delete-date-to' ).datepicker( { dateFormat: 'yy-mm-dd' } );

// danger zone tools
$( '#wpo-wcpdf-settings .number-tools-btn' ).click( function( event ) {
event.preventDefault();

let documentType = '';
let dateFrom = '';
let dateTo = '';
let deleteOrRenumber = '';
let pageCount = 1;
let documentCount = 0;

if ( 'renumber-documents-btn' === this.id ) {
documentType = $( '#renumber-document-type' ).val();
dateFrom = $( '#renumber-date-from' ).val();
dateTo = $( '#renumber-date-to' ).val();
deleteOrRenumber = 'renumber';

} else if ( 'delete-documents-btn' === this.id ) {
documentType = $( '#delete-document-type' ).val();
dateFrom = $( '#delete-date-from' ).val();
dateTo = $( '#delete-date-to' ).val();
deleteOrRenumber = 'delete';
}

if ( '' === documentType || 'undefined' === documentType ) {
alert( wpo_wcpdf_debug.select_document_type );
return;
}

if ( 'renumber' === deleteOrRenumber ) {
$( '.renumber-spinner' ).css( 'visibility', 'visible' );
} else if ( 'delete' === deleteOrRenumber ) {
$( '.delete-spinner' ).css( 'visibility', 'visible' );
}

$( '#renumber-documents-btn, #delete-documents-btn' ).attr( 'disabled', true );
$( '#renumber-document-type, #renumber-date-from, #renumber-date-to, #delete-document-type, #delete-date-from, #delete-date-to' ).prop( 'disabled', true );

// first call
renumberOrDeleteDocuments( documentType, dateFrom, dateTo, pageCount, documentCount, deleteOrRenumber );
} );

function renumberOrDeleteDocuments( documentType, dateFrom, dateTo, pageCount, documentCount, deleteOrRenumber ) {
let data = {
'action': 'wpo_wcpdf_danger_zone_tools',
'delete_or_renumber': deleteOrRenumber,
'document_type': documentType,
'date_from': dateFrom,
'date_to': dateTo,
'page_count': pageCount,
'document_count': documentCount,
'nonce': wpo_wcpdf_debug.nonce,
};

$.ajax( {
type: 'POST',
url: wpo_wcpdf_debug.ajaxurl,
data: data,
dataType: 'json',
success: function( response ) {
if ( false === response.data.finished ) {
// update page count and document count
pageCount = response.data.pageCount;
documentCount = response.data.documentCount;

// recall function
renumberOrDeleteDocuments( documentType, dateFrom, dateTo, pageCount, documentCount, deleteOrRenumber );

} else {
$( '.renumber-spinner, .delete-spinner' ).css( 'visibility', 'hidden' );
$( '#renumber-documents-btn, #delete-documents-btn' ).removeAttr( 'disabled' );
$( '#renumber-document-type, #renumber-date-from, #renumber-date-to, #delete-document-type, #delete-date-from, #delete-date-to' ).prop( 'disabled', false );
let message = response.data.message;
alert( documentCount + message );
}
},
error: function( xhr, ajaxOptions, thrownError ) {
alert( xhr.status + ':'+ thrownError );
}
} );
}

} );
2 changes: 1 addition & 1 deletion assets/js/debug-script.min.js

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

32 changes: 25 additions & 7 deletions includes/class-wcpdf-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,45 @@ 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' ) {
wp_enqueue_style(
'wpo-wcpdf-jquery-ui-styles',
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'
);

wp_enqueue_script( 'jquery-ui-datepicker' );

wp_enqueue_style(
'wpo-wcpdf-debug-tools-styles',
WPO_WCPDF()->plugin_url() . '/assets/css/debug-tools'.$suffix.'.css',
WPO_WCPDF_VERSION
);

wp_enqueue_script(
'wpo-wcpdf-debug',
WPO_WCPDF()->plugin_url() . '/assets/js/debug-script'.$suffix.'.js',
[ 'jquery', 'jquery-blockui' ],
array( 'jquery', 'jquery-blockui', 'jquery-ui-datepicker' ),
WPO_WCPDF_VERSION
);

wp_localize_script(
'wpo-wcpdf-debug',
'wpo_wcpdf_debug',
[
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wpo_wcpdf_debug_nonce' ),
'download_label' => __( 'Download', 'woocommerce-pdf-invoices-packing-slips' ),
'confirm_reset' => __( 'Are you sure you want to reset this settings? This cannot be undone.', 'woocommerce-pdf-invoices-packing-slips' ),
]
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wpo_wcpdf_debug_nonce' ),
'download_label' => __( 'Download', 'woocommerce-pdf-invoices-packing-slips' ),
'confirm_reset' => __( 'Are you sure you want to reset this settings? This cannot be undone.', 'woocommerce-pdf-invoices-packing-slips' ),
'select_document_type' => __( 'Please select a document type', 'woocommerce-pdf-invoices-packing-slips' ),
'danger_zone' => array(
'enabled' => isset( WPO_WCPDF()->settings->debug_settings['enable_danger_zone_tools'] ) ? true : false,
'message' => sprintf(
/* translators: <a> tags */
__( '<strong>Enabled</strong>: %sclick here%s to start using the tools.', 'woocommerce-pdf-invoices-packing-slips' ),
'<a href="' . esc_url( add_query_arg( 'section', 'tools' ) ) . '#danger_zone">',
'</a>'
),
),
)
);

}
Expand Down
11 changes: 11 additions & 0 deletions includes/class-wcpdf-documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public function get_document( $document_type, $order ) {

return false;
}

public function get_document_titles() {
$documents = $this->get_documents();
$document_titles = array();

foreach ( $documents as $document ) {
$document_titles[ $document->get_type() ] = $document->get_title();
}

return $document_titles;
}

}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wcpdf-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function do_install() {
update_option( $version_setting, WPO_WCPDF_VERSION );
}

// deactivate ubl addon
add_action( 'admin_init', array( WPO_WCPDF(), 'deactivate_ubl_addon') );
// deactivate legacy addons
add_action( 'admin_init', array( WPO_WCPDF(), 'deactivate_legacy_addons') );
}


Expand Down
2 changes: 1 addition & 1 deletion includes/class-wcpdf-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct() {
add_filter( 'wpo_wcpdf_pdf_filters', array( $this, 'pdf_currency_filters' ) );
add_filter( 'wpo_wcpdf_html_filters', array( $this, 'html_currency_filters' ) );

// scheduled attachments cleanup (following settings on Status tab)
// scheduled attachments cleanup (following settings on Advanced tab)
add_action( 'wp_scheduled_delete', array( $this, 'schedule_temporary_files_cleanup' ) );

// remove private data
Expand Down
6 changes: 3 additions & 3 deletions includes/class-wcpdf-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function check_auto_increment_increment() {
$row = $wpdb->get_row( "SHOW VARIABLES LIKE 'auto_increment_increment'" );
if ( ! empty( $row ) && ! empty( $row->Value ) && $row->Value != 1 ) {
/* translators: database row value */
$error = wp_kses_post( sprintf( __( "<strong>Warning!</strong> Your database has an AUTO_INCREMENT step size of %d, your invoice numbers may not be sequential. Enable the 'Calculate document numbers (slow)' setting in the Status tab to use an alternate method." , 'woocommerce-pdf-invoices-packing-slips' ), intval( $row->Value ) ) );
$error = wp_kses_post( sprintf( __( "<strong>Warning!</strong> Your database has an AUTO_INCREMENT step size of %d, your invoice numbers may not be sequential. Enable the 'Calculate document numbers (slow)' setting in the Advanced tab to use an alternate method." , 'woocommerce-pdf-invoices-packing-slips' ), intval( $row->Value ) ) );
printf( '<div class="error"><p>%s</p></div>', $error );
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ public function settings_page() {

// add status and upgrade tabs last in row
$settings_tabs['debug'] = array(
'title' => __( 'Status', 'woocommerce-pdf-invoices-packing-slips' ),
'title' => __( 'Advanced', 'woocommerce-pdf-invoices-packing-slips' ),
'preview_states' => 1,
);

Expand All @@ -204,7 +204,7 @@ public function settings_page() {
$active_tab = isset( $_GET[ 'tab' ] ) ? sanitize_text_field( $_GET[ 'tab' ] ) : $default_tab;
$active_section = isset( $_GET[ 'section' ] ) ? sanitize_text_field( $_GET[ 'section' ] ) : '';

include( 'views/wcpdf-settings-page.php' );
include( 'views/settings-page.php' );
}

public function maybe_disable_preview_on_settings_tabs( $settings_tabs ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public function get_thumbnail ( $product ) {
* which turns the function 'imagecreatefromwebp()' inexistent,
* leading to display an error in DOMPDF.
*
* Check 'System configuration' in the Status tab for 'webp' support.
* Check 'System configuration' in the Advanced tab for 'webp' support.
*/
if ( 'webp' === wp_check_filetype( $thumbnail_path )['ext'] && ! function_exists( 'imagecreatefromwebp' ) ) {
$thumbnail = '';
Expand Down
11 changes: 8 additions & 3 deletions includes/documents/abstract-wcpdf-order-document.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ public function output_html() {
}

public function preview_ubl() {
// get last settings
$this->settings = ! empty( $this->latest_settings ) ? $this->latest_settings : $this->get_settings( true );

return $this->output_ubl( true );
}

Expand All @@ -967,8 +970,10 @@ public function output_ubl( $contents_only = false ) {

$ubl_document->set_order( $this->order );

if ( $order_document = wcpdf_get_document( $this->get_type(), $this->order, true ) ) {
$ubl_document->set_order_document( $order_document );
$document = $contents_only ? $this : wcpdf_get_document( $this->get_type(), $this->order, true );

if ( $document ) {
$ubl_document->set_order_document( $document );
} else {
wcpdf_log_error( 'Error generating order document for UBL!', 'error' );
exit();
Expand All @@ -981,7 +986,7 @@ public function output_ubl( $contents_only = false ) {
return $contents;
}

$filename = $order_document->get_filename( 'download', array( 'output' => 'ubl' ) );
$filename = $document->get_filename( 'download', array( 'output' => 'ubl' ) );
$full_filename = $ubl_maker->write( $filename, $contents );
$quoted = sprintf( '"%s"', addcslashes( basename( $full_filename ), '"\\' ) );
$size = filesize( $full_filename );
Expand Down
Loading

0 comments on commit 464e02f

Please sign in to comment.