Enabled product bundles

This commit is contained in:
Nedim Uka
2018-06-29 14:40:28 +02:00
parent e0514f7f57
commit b5475ff2f1
12004 changed files with 1694047 additions and 1610 deletions

View File

@@ -0,0 +1,225 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Renumerate Tool
*
* @version 3.2.2
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Renumerate_Tool' ) ) :
class WCJ_PDF_Invoicing_Renumerate_Tool {
/**
* Constructor.
*
* @version 3.2.2
*/
function __construct() {
return true;
}
/**
* wcj_multi_selected.
*/
function wcj_multi_selected( $selected, $current_multi ) {
if ( ! is_array( $current_multi ) ) {
return selected( $selected, $current_multi, false );
}
foreach( $current_multi as $current ) {
$selected_single = selected( $selected, $current, false );
if ( '' != $selected_single ) {
return $selected_single;
}
}
return '';
}
/**
* Add Renumerate Invoices tool to WooCommerce menu (the content).
*
* @version 3.2.2
*/
function create_renumerate_invoices_tool() {
$result_message = '';
$renumerate_result = '';
$the_invoice_type = ( ! empty( $_POST['invoice_type'] ) ) ? $_POST['invoice_type'] : 'invoice';
$the_start_number = ( ! empty( $_POST['start_number'] ) ) ? $_POST['start_number'] : 0;
$the_start_date = ( ! empty( $_POST['start_date'] ) ) ? $_POST['start_date'] : '';
$the_end_date = ( ! empty( $_POST['end_date'] ) ) ? $_POST['end_date'] : '';
$the_order_statuses = ( ! empty( $_POST['order_statuses'] ) ) ? $_POST['order_statuses'] : array();
$the_delete_all = ( isset( $_POST['delete_all'] ) );
if ( isset( $_POST['renumerate_invoices'] ) ) {
if ( ! empty( $the_order_statuses ) ) {
$renumerate_result = $this->renumerate_invoices( $the_invoice_type, $the_start_number, $the_start_date, $the_end_date, $the_order_statuses, $the_delete_all );
$result_message = '<div class="updated"><p><strong>' . __( 'Invoices successfully renumerated!', 'woocommerce-jetpack' ) . '</strong></p></div>';
} else {
$result_message = '<div class="error"><p><strong>' . __( 'Please select at least one order status.', 'woocommerce-jetpack' ) . '</strong></p></div>';
}
}
?><div>
<h2><?php echo __( 'Booster - Renumerate Invoices', 'woocommerce-jetpack' ); ?></h2>
<p><?php echo __( 'The tool renumerates invoices from choosen date. Invoice number format is set in WooCommerce > Settings > Booster > PDF Invoicing & Packing Slips > Numbering.', 'woocommerce-jetpack' ); ?></p>
<?php echo $result_message; ?>
<p><form method="post" action="">
<?php
// Start Date
$data[] = array(
__( 'Start Date', 'woocommerce-jetpack' ),
'<input class="input-text widefat" display="date" type="text" name="start_date" value="' . $the_start_date . '">',
'<em>' . __( 'Date to start renumerating. Leave blank to renumerate all invoices.', 'woocommerce-jetpack' ) . '</em>',
);
// End Date
$data[] = array(
__( 'End Date', 'woocommerce-jetpack' ),
'<input class="input-text widefat" display="date" type="text" name="end_date" value="' . $the_end_date . '">',
'<em>' . __( 'Date to end renumerating. Leave blank to renumerate all invoices.', 'woocommerce-jetpack' ) . '</em>',
);
// Number
$data[] = array(
__( 'Start Number', 'woocommerce-jetpack' ),
'<input class="input-text widefat" type="text" name="start_number" value="' . $the_start_number . '">',
'<em>' . __( 'Counter to start renumerating. Leave 0 to continue from current counter.', 'woocommerce-jetpack' ) . '</em>',
);
// Delete All
$data[] = array(
__( 'Delete All', 'woocommerce-jetpack' ),
'<input id="wcj_renumerate_invoices_delete_all" type="checkbox" name="delete_all" value="" ' . checked( $the_delete_all, true, false ) . '>' . ' ' .
'<label for="wcj_renumerate_invoices_delete_all">' . __( 'Clear all invoices before renumerating', 'woocommerce-jetpack' ) . '</label>',
'',
);
// Type
$invoice_type_select_html = '<select class="widefat" name="invoice_type">';
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
$invoice_type_select_html .= '<option value="' . $invoice_type['id'] . '" ' . selected( $invoice_type['id'], $the_invoice_type, false ) . '>' .
$invoice_type['title'] . '</option>';
}
$invoice_type_select_html .= '</select>';
$data[] = array( __( 'Document Type', 'woocommerce-jetpack' ), $invoice_type_select_html, '', );
// Statuses
$order_statuses_select_html = '<select class="widefat" id="order_statuses" name="order_statuses[]" multiple size="5">';
$order_statuses = wcj_get_order_statuses( false );
foreach ( $order_statuses as $status => $desc ) {
$order_statuses_select_html .= '<option value="' . $status . '" ' . $this->wcj_multi_selected( $status, $the_order_statuses ) . '>' . $desc . '</option>';
}
$order_statuses_select_html .= '</select>';
$data[] = array( __( 'Order Statuses', 'woocommerce-jetpack' ), $order_statuses_select_html, '', );
// Button
$data[] = array(
'<input class="button-primary" type="submit" name="renumerate_invoices" value="' . __( 'Renumerate invoices', 'woocommerce-jetpack' ) . '">',
'',
''
);
// Print all
echo wcj_get_table_html( $data, array( 'table_class' => 'widefat striped', 'table_heading_type' => 'vertical', ) );
?>
</form></p>
<?php
if ( '' != $renumerate_result ) {
echo '<h3>' . __( 'Results', 'woocommerce-jetpack' ) . '</h3>';
echo '<p>' . $renumerate_result . '</p>';
}
?>
</div><?php
}
/**
* Renumerate invoices function.
*
* @version 2.3.10
*/
function renumerate_invoices( $invoice_type, $start_number, $start_date, $end_date, $order_statuses, $the_delete_all ) {
$output = '';
if ( 0 != $start_number ) {
update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', $start_number );
}
$date_query_array = array(
array(
'after' => $start_date,
'inclusive' => true,
),
);
if ( '' != $end_date ) {
$date_query_array[0]['before'] = $end_date;
}
$deleted_invoices_counter = 0;
$created_invoices_counter = 0;
$offset = 0;
$block_size = 96;
while( true ) {
$args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'posts_per_page' => $block_size,
'offset' => $offset,
'orderby' => 'date',
'order' => 'ASC',
'date_query' => $date_query_array,
);
$loop = new WP_Query( $args );
if ( ! $loop->have_posts() ) {
break;
}
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
if (
in_array( $loop->post->post_status, $order_statuses ) &&
strtotime( $loop->post->post_date ) >= strtotime( $start_date ) &&
( strtotime( $loop->post->post_date ) <= strtotime( $end_date ) || '' == $end_date )
) {
$the_order = wc_get_order( $order_id );
if ( 0 != $the_order->get_total() ) {
wcj_create_invoice( $order_id, $invoice_type, strtotime( $loop->post->post_date ) );
$created_invoices_counter++;
}
} else {
if ( $the_delete_all && wcj_is_invoice_created( $order_id, $invoice_type ) ) {
wcj_delete_invoice( $order_id, $invoice_type );
$deleted_invoices_counter++;
}
}
endwhile;
$offset += $block_size;
}
$output .= '<p>' . sprintf( __( 'Total documents created: %d', 'woocommerce-jetpack' ), $created_invoices_counter ) . '</p>';
$output .= '<p>' . sprintf( __( 'Total documents deleted: %d', 'woocommerce-jetpack' ), $deleted_invoices_counter ) . '</p>';
return $output;
}
}
endif;
return new WCJ_PDF_Invoicing_Renumerate_Tool();

View File

@@ -0,0 +1,481 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Report Tool
*
* @version 3.6.0
* @since 2.2.1
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Report_Tool' ) ) :
class WCJ_PDF_Invoicing_Report_Tool {
/**
* Constructor.
*
* @version 2.5.7
*/
function __construct() {
$this->notice = '';
add_action( 'init', array( $this, 'generate_report_zip' ) );
add_action( 'init', array( $this, 'export_csv' ) );
}
/**
* get_report_file_name.
*
* @version 3.1.0
* @since 3.1.0
*/
function get_report_file_name( $year, $month, $invoice_type, $extension ) {
$replaced_values = array(
'%year%' => $year,
'%month%' => sprintf( '%02d', $month ),
'%invoice_type%' => $invoice_type,
'%site%' => sanitize_title( str_replace( array( 'http://', 'https://' ), '', site_url() ) ),
);
return str_replace( array_keys( $replaced_values ), array_values( $replaced_values ),
get_option( 'wcj_pdf_invoicing_report_tool_filename', '%site%-%invoice_type%-%year%_%month%' ) ) . '.' . $extension;
}
/**
* check_user_roles.
*
* @version 3.4.0
* @since 3.4.0
* @todo this function is similar to `WCJ_PDF_Invoicing::check_user_roles()` - maybe it should be just one function for both classes..
*/
function check_user_roles( $invoice_type_id ) {
$allowed_user_roles = get_option( 'wcj_invoicing_' . $invoice_type_id . '_roles', array( 'administrator', 'shop_manager' ) );
if ( empty( $allowed_user_roles ) ) {
$allowed_user_roles = array( 'administrator' );
}
return wcj_is_user_role( $allowed_user_roles );
}
/**
* generate_report_zip.
*
* @version 3.5.0
* @since 2.3.10
*/
function generate_report_zip() {
if ( isset( $_POST['get_invoices_report_zip'] ) ) {
if ( wcj_is_module_enabled( 'general' ) && 'yes' === get_option( 'wcj_general_advanced_disable_save_sys_temp_dir', 'no' ) ) {
$this->notice = '<div class="error"><p><strong>' . sprintf(
__( 'This option is disabled with "Disable Saving PDFs in PHP directory for temporary files" checkbox in <a href="%s" target="_blank">WooCommerce > Settings > Booster > Emails & Misc. > General > Advanced Options</a>.', 'woocommerce-jetpack' ),
admin_url( 'admin.php?page=wc-settings&tab=jetpack&wcj-cat=emails_and_misc&section=general' ) ) .
'</strong></p></div>';
} else {
$_year = ( ! empty( $_POST['report_year'] ) ) ? $_POST['report_year'] : date( 'Y' );
$_month = ( ! empty( $_POST['report_month'] ) ) ? $_POST['report_month'] : date( 'n' );
$_invoice_type = ( ! empty( $_POST['invoice_type'] ) ) ? $_POST['invoice_type'] : 'invoice';
if ( ! empty( $_year ) && ! empty( $_month ) && ! empty( $_invoice_type ) ) {
if ( $this->check_user_roles( $_invoice_type ) ) {
$result = $this->get_invoices_report_zip( $_year, $_month, $_invoice_type );
if ( false === $result ) {
$this->notice = '<div class="error"><p><strong>' . __( 'Sorry, but something went wrong...', 'woocommerce-jetpack' ) . '</strong></p></div>';
} elseif ( true !== $result ) {
$this->notice = '<div class="error"><p><strong>' . $result . '</strong></p></div>';
}
}
} else {
$this->notice = '<div class="error"><p><strong>' . __( 'Please fill year and month values.', 'woocommerce-jetpack' ) . '</strong></p></div>';
}
}
}
}
/**
* Add Invoices Report tool to WooCommerce menu (the content).
*
* @version 3.6.0
*/
function create_invoices_report_tool() {
$result_message = '';
$result_message .= $this->notice;
$the_year = ( ! empty( $_POST['report_year'] ) ) ? $_POST['report_year'] : date( 'Y' );
$the_month = ( ! empty( $_POST['report_month'] ) ) ? $_POST['report_month'] : date( 'n' );
$the_invoice_type = ( ! empty( $_POST['invoice_type'] ) ) ? $_POST['invoice_type'] : 'invoice';
if ( isset( $_POST['get_invoices_report'] ) ) {
if ( ! empty( $the_year ) && ! empty( $the_month ) && ! empty( $the_invoice_type ) ) {
$result_message = $this->get_invoices_report( $the_year, $the_month, $the_invoice_type );
} else {
$result_message = '<div class="error"><p><strong>' . __( 'Please fill year and month values.', 'woocommerce-jetpack' ) . '</strong></p></div>';
}
}
$html = '';
$html .= '<div class="wrap">';
$html .= WCJ()->modules['pdf_invoicing']->get_tool_header_html( 'invoices_report' );
$html .= '<p><form method="post" action="">';
// Type
$invoice_type_select_html = '<select name="invoice_type" class="widefat">';
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
$invoice_type_select_html .= '<option value="' . $invoice_type['id'] . '" ' . selected( $invoice_type['id'], $the_invoice_type, false ) . '>' .
$invoice_type['title'] . '</option>';
}
$invoice_type_select_html .= '</select>';
$data = array(
// Year
array(
__( 'Year', 'woocommerce-jetpack' ),
'<input class="input-text widefat" type="number" min="2000" max="2100" step="1" name="report_year" value="' . $the_year . '">',
),
// Month
array(
__( 'Month', 'woocommerce-jetpack' ),
'<input class="input-text widefat" type="number" min="1" max="12" step="1" name="report_month" value="' . $the_month . '">',
),
// Type
array(
__( 'Document Type', 'woocommerce-jetpack' ),
$invoice_type_select_html,
),
// Get Report Button
array(
'',
'<input class="button-primary" style="background-color:#006799;" type="submit" name="get_invoices_report" value="' .
__( 'Display monthly documents table', 'woocommerce-jetpack' ) . '">',
),
// Get Report Zip Button
array(
'',
'<input class="button-primary" type="submit" name="get_invoices_report_zip" value="' .
__( 'Download all monthly documents PDFs in single ZIP file', 'woocommerce-jetpack' ) . '">',
),
// Get Report CSV Button
array(
'',
'<input class="button-primary" type="submit" name="get_invoices_report_csv" value="' .
__( 'Download monthly documents CSV', 'woocommerce-jetpack' ) . '">',
),
);
$html .= wcj_get_table_html( $data, array( 'table_class' => 'widefat striped', 'table_heading_type' => 'vertical' ) );
$html .= '</form></p>';
$html .= $result_message;
$html .= '</div>';
echo $html;
}
/**
* get_invoices_report_zip.
*
* @version 3.5.0
* @since 2.3.10
*/
function get_invoices_report_zip( $year, $month, $invoice_type_id ) {
if ( ! class_exists( 'ZipArchive' ) ) {
return sprintf( __( 'Booster: %s class is not accessible on your server. Please contact your hosting provider.', 'woocommerce-jetpack' ),
'<a target="_blank" href="http://php.net/manual/en/class.ziparchive.php">PHP ZipArchive</a>' );
}
$zip = new ZipArchive();
$zip_file_name = $this->get_report_file_name( $year, $month, $invoice_type_id, 'zip' );
$zip_file_path = wcj_get_invoicing_temp_dir() . '/' . $zip_file_name;
if ( file_exists( $zip_file_path ) ) {
unlink ( $zip_file_path );
}
if ( $zip->open( $zip_file_path, ZipArchive::CREATE ) !== TRUE ) {
return false;
}
$first_minute = mktime( 0, 0, 0, $month, 1, $year );
$last_minute = mktime( 23, 59, 59, $month, date( 't', $first_minute ), $year );
$archive_is_empty = true;
$offset = 0;
$block_size = 512;
while( true ) {
$args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'posts_per_page' => $block_size,
'orderby' => 'meta_value_num',
'meta_key' => '_wcj_invoicing_' . $invoice_type_id . '_date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_wcj_invoicing_' . $invoice_type_id . '_date',
'value' => array( $first_minute , $last_minute ),
'type' => 'numeric',
'compare' => 'BETWEEN',
),
),
'offset' => $offset,
'fields' => 'ids',
);
$loop = new WP_Query( $args );
if ( ! $loop->have_posts() ) {
break;
}
foreach ( $loop->posts as $order_id ) {
if ( wcj_is_invoice_created( $order_id, $invoice_type_id ) ) {
$the_invoice = wcj_get_pdf_invoice( $order_id, $invoice_type_id );
$file_name = $the_invoice->get_pdf( 'F' );
$zip->addFile( $file_name, $the_invoice->get_file_name() );
$archive_is_empty = false;
}
}
$offset += $block_size;
}
$zip->close();
if ( $archive_is_empty ) {
return $this->get_no_documents_found_message( $year, $month, $invoice_type_id );
}
header( "Content-Disposition: attachment; filename=" . urlencode( $zip_file_name ) );
header( "Content-Type: application/download" );
header( "Content-Description: File Transfer" );
header( "Content-Length: " . filesize( $zip_file_path ) );
flush(); // this doesn't really matter.
if ( false !== ( $fp = fopen( $zip_file_path, "r" ) ) ) {
while ( ! feof( $fp ) ) {
echo fread( $fp, 65536 );
flush(); // this is essential for large downloads
}
fclose( $fp );
exit();
} else {
die( __( 'Unexpected error', 'woocommerce-jetpack' ) );
}
return true;
}
/**
* get_no_documents_found_message.
*
* @version 3.1.0
* @since 3.1.0
*/
function get_no_documents_found_message( $year, $month, $invoice_type_id ) {
return sprintf( __( 'No documents (%s) found for %d-%02d.', 'woocommerce-jetpack' ), $invoice_type_id, $year, $month );
}
/**
* export_csv.
*
* @version 3.1.0
* @since 2.5.7
*/
function export_csv() {
$_year = ( ! empty( $_POST['report_year'] ) ) ? $_POST['report_year'] : date( 'Y' );
$_month = ( ! empty( $_POST['report_month'] ) ) ? $_POST['report_month'] : date( 'm' );
$_invoice_type = ( ! empty( $_POST['invoice_type'] ) ) ? $_POST['invoice_type'] : 'invoice';
if ( isset( $_POST['get_invoices_report_csv'] ) ) {
$data = $this->get_invoices_report_data( $_year, $_month, $_invoice_type );
if ( empty( $data ) ) {
$this->notice = '<div class="error"><p><strong>' . $this->get_no_documents_found_message( $_year, $_month, $_invoice_type ) . '</strong></p></div>';
return false;
}
$csv = '';
$sep = get_option( 'wcj_pdf_invoicing_report_tool_csv_separator', ';' );
$replace_periods_with_commas = ( 'yes' === get_option( 'wcj_pdf_invoicing_report_tool_csv_replace_periods_w_commas', 'yes' ) );
foreach ( $data as $row ) {
if ( $replace_periods_with_commas ) {
$row = str_replace( '.', ',', $row );
}
$csv .= implode( $sep, $row ) . PHP_EOL;
}
if ( 'yes' === get_option( 'wcj_pdf_invoicing_report_tool_csv_add_utf_8_bom', 'yes' ) ) {
$csv = "\xEF\xBB\xBF" . $csv; // UTF-8 BOM
}
$filename = $this->get_report_file_name( $_year, $_month, $_invoice_type, 'csv' );
header( "Content-Disposition: attachment; filename=" . $filename );
header( "Content-Type: Content-Type: text/html; charset=utf-8" );
header( "Content-Description: File Transfer" );
header( "Content-Length: " . strlen( $csv ) );
echo $csv;
die();
}
}
/**
* Invoices Report function.
*
* @version 3.1.0
*/
function get_invoices_report( $year, $month, $invoice_type_id ) {
$data = $this->get_invoices_report_data( $year, $month, $invoice_type_id );
return ( ! empty( $data ) ?
wcj_get_table_html( $data, array( 'table_class' => 'widefat' ) ) :
'<div class="error"><p><strong>' . $this->get_no_documents_found_message( $year, $month, $invoice_type_id ) . '</strong></p></div>' );
}
/**
* Invoices Report Data function.
*
* @version 3.6.0
* @since 2.5.7
*/
function get_invoices_report_data( $year, $month, $invoice_type_id ) {
$columns = get_option( 'wcj_pdf_invoicing_report_tool_columns', '' );
if ( empty( $columns ) ) {
$columns = array_keys( WCJ()->modules['pdf_invoicing_advanced']->get_report_columns() );
}
$total_sum = 0;
$total_sum_excl_tax = 0;
$total_tax = 0;
$first_minute = mktime( 0, 0, 0, $month, 1, $year );
$last_minute = mktime( 23, 59, 59, $month, date( 't', $first_minute ), $year );
$tax_percent_format = '%.' . get_option( 'wcj_pdf_invoicing_report_tool_tax_percent_precision', 0 ) . 'f %%';
$data = array();
$offset = 0;
$block_size = 512;
while( true ) {
$args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'posts_per_page' => $block_size,
'orderby' => 'meta_value_num',
'meta_key' => '_wcj_invoicing_' . $invoice_type_id . '_date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_wcj_invoicing_' . $invoice_type_id . '_date',
'value' => array( $first_minute , $last_minute ),
'type' => 'numeric',
'compare' => 'BETWEEN',
),
),
'offset' => $offset,
'fields' => 'ids',
);
$loop = new WP_Query( $args );
if ( ! $loop->have_posts() ) {
break;
}
foreach ( $loop->posts as $order_id ) {
if ( wcj_is_invoice_created( $order_id, $invoice_type_id ) ) {
$the_order = wc_get_order( $order_id );
$user_meta = get_user_meta( $the_order->get_user_id() );
$billing_country = isset( $user_meta['billing_country'][0] ) ? $user_meta['billing_country'][0] : '';
$shipping_country = isset( $user_meta['shipping_country'][0] ) ? $user_meta['shipping_country'][0] : '';
$customer_country = ( '' == $billing_country ) ? $shipping_country : $billing_country;
$customer_vat_id = get_post_meta( $order_id, '_billing_eu_vat_number', true );
$order_total = $the_order->get_total();
$order_tax = apply_filters( 'wcj_order_total_tax', $the_order->get_total_tax(), $the_order );
$order_total_exlc_tax = $order_total - $order_tax;
$order_total_tax_not_rounded = $the_order->get_cart_tax() + $the_order->get_shipping_tax();
$order_tax_percent = ( 0 == $order_total_exlc_tax ? 0 : $order_total_tax_not_rounded / $order_total_exlc_tax );
$total_sum += $order_total;
$total_sum_excl_tax += $order_total_exlc_tax;
$total_tax += $order_tax;
$order_cart_tax = $the_order->get_cart_tax();
$order_shipping_tax = $the_order->get_shipping_tax();
$order_cart_total_excl_tax = 0;
foreach ( $the_order->get_items() as $item ) {
$order_cart_total_excl_tax += $item->get_total();
}
$order_shipping_total_excl_tax = $the_order->get_shipping_total();
$order_cart_tax_percent = ( 0 == $order_cart_total_excl_tax ? 0 : $order_cart_tax / $order_cart_total_excl_tax );
$order_shipping_tax_percent = ( 0 == $order_shipping_total_excl_tax ? 0 : $order_shipping_tax / $order_shipping_total_excl_tax );
$row = array();
foreach ( $columns as $column ) {
switch ( $column ) {
case 'document_number':
$row[] = wcj_get_invoice_number( $order_id, $invoice_type_id );
break;
case 'document_date':
$row[] = wcj_get_invoice_date( $order_id, $invoice_type_id, 0, get_option( 'date_format' ) );
break;
case 'order_id':
$row[] = $order_id;
break;
case 'customer_country':
$row[] = $customer_country;
break;
case 'customer_vat_id':
$row[] = $customer_vat_id;
break;
case 'tax_percent':
$row[] = sprintf( $tax_percent_format, $order_tax_percent * 100 );
break;
case 'order_total_tax_excluding':
$row[] = sprintf( '%.2f', $order_total_exlc_tax );
break;
case 'order_taxes':
$row[] = sprintf( '%.2f', $order_tax );
break;
case 'order_cart_total_excl_tax':
$row[] = sprintf( '%.2f', $order_cart_total_excl_tax );
break;
case 'order_cart_tax':
$row[] = sprintf( '%.2f', $order_cart_tax );
break;
case 'order_cart_tax_percent':
$row[] = sprintf( $tax_percent_format, $order_cart_tax_percent * 100 );
break;
case 'order_shipping_total_excl_tax':
$row[] = sprintf( '%.2f', $order_shipping_total_excl_tax );
break;
case 'order_shipping_tax':
$row[] = sprintf( '%.2f', $order_shipping_tax );
break;
case 'order_shipping_tax_percent':
$row[] = sprintf( $tax_percent_format, $order_shipping_tax_percent * 100 );
break;
case 'order_total':
$row[] = sprintf( '%.2f', $order_total );
break;
case 'order_currency':
$row[] = wcj_get_order_currency( $the_order );
break;
case 'payment_gateway':
$row[] = get_post_meta( $order_id, '_payment_method_title', true );
break;
case 'refunds':
$row[] = $the_order->get_total_refunded();
break;
}
}
$data[] = $row;
}
}
$offset += $block_size;
}
$headers = $this->get_data_headers( $columns );
return ( ! empty( $data ) ? array_merge( array( $headers ), $data ) : array() );
}
/**
* get_data_headers.
*
* @version 3.6.0
* @since 3.3.0
*/
function get_data_headers( $columns ) {
$headers = array();
$all_headers = WCJ()->modules['pdf_invoicing_advanced']->get_report_columns();
foreach ( $columns as $column ) {
$headers[] = $all_headers[ $column ];
}
return $headers;
}
}
endif;
return new WCJ_PDF_Invoicing_Report_Tool();

View File

@@ -0,0 +1,87 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Advanced
*
* @version 3.3.0
* @since 3.3.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Advanced' ) ) :
class WCJ_PDF_Invoicing_Advanced extends WCJ_Module {
/**
* Constructor.
*
* @version 3.3.0
* @since 3.3.0
*/
function __construct() {
$this->id = 'pdf_invoicing_advanced';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Advanced', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
}
/**
* get_report_default_columns.
*
* @version 3.3.0
* @since 3.3.0
*/
function get_report_default_columns() {
return array_keys( array(
'document_number' => __( 'Document Number', 'woocommerce-jetpack' ),
'document_date' => __( 'Document Date', 'woocommerce-jetpack' ),
'order_id' => __( 'Order ID', 'woocommerce-jetpack' ),
'customer_country' => __( 'Customer Country', 'woocommerce-jetpack' ),
'customer_vat_id' => __( 'Customer VAT ID', 'woocommerce-jetpack' ),
'tax_percent' => __( 'Tax %', 'woocommerce-jetpack' ),
'order_total_tax_excluding' => __( 'Order Total Excl. Tax', 'woocommerce-jetpack' ),
'order_taxes' => __( 'Order Taxes', 'woocommerce-jetpack' ),
'order_total' => __( 'Order Total', 'woocommerce-jetpack' ),
'order_currency' => __( 'Order Currency', 'woocommerce-jetpack' ),
'payment_gateway' => __( 'Payment Gateway', 'woocommerce-jetpack' ),
'refunds' => __( 'Refunds', 'woocommerce-jetpack' ),
) );
}
/**
* get_report_columns.
*
* @version 3.3.0
* @since 3.3.0
* @todo (maybe) `order_discount_tax`
*/
function get_report_columns() {
return array(
'document_number' => __( 'Document Number', 'woocommerce-jetpack' ),
'document_date' => __( 'Document Date', 'woocommerce-jetpack' ),
'order_id' => __( 'Order ID', 'woocommerce-jetpack' ),
'customer_country' => __( 'Customer Country', 'woocommerce-jetpack' ),
'customer_vat_id' => __( 'Customer VAT ID', 'woocommerce-jetpack' ),
'tax_percent' => __( 'Tax %', 'woocommerce-jetpack' ),
'order_total_tax_excluding' => __( 'Order Total Excl. Tax', 'woocommerce-jetpack' ),
'order_taxes' => __( 'Order Taxes', 'woocommerce-jetpack' ),
'order_cart_total_excl_tax' => __( 'Cart Total Excl. Tax', 'woocommerce-jetpack' ),
'order_cart_tax' => __( 'Cart Tax', 'woocommerce-jetpack' ),
'order_cart_tax_percent' => __( 'Cart Tax %', 'woocommerce-jetpack' ),
'order_shipping_total_excl_tax' => __( 'Shipping Total Excl. Tax', 'woocommerce-jetpack' ),
'order_shipping_tax' => __( 'Shipping Tax', 'woocommerce-jetpack' ),
'order_shipping_tax_percent' => __( 'Shipping Tax %', 'woocommerce-jetpack' ),
'order_total' => __( 'Order Total', 'woocommerce-jetpack' ),
'order_currency' => __( 'Order Currency', 'woocommerce-jetpack' ),
'payment_gateway' => __( 'Payment Gateway', 'woocommerce-jetpack' ),
'refunds' => __( 'Refunds', 'woocommerce-jetpack' ),
);
}
}
endif;
return new WCJ_PDF_Invoicing_Advanced();

View File

@@ -0,0 +1,350 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Display
*
* @version 3.6.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Display' ) ) :
class WCJ_PDF_Invoicing_Display extends WCJ_Module {
/**
* Constructor.
*
* @version 3.6.0
*/
function __construct() {
$this->id = 'pdf_invoicing_display';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Display & Misc.', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
if ( $this->is_enabled() ) {
// Columns on Admin's Orders page
add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_order_column' ), PHP_INT_MAX - 3 );
add_action( 'manage_shop_order_posts_custom_column', array( $this, 'render_order_columns' ), 2 );
// Action Links on Customer's My Account page
add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'add_pdf_invoices_action_links' ), PHP_INT_MAX, 2 );
// Action Links on Customer's Thank You page
add_action( 'woocommerce_thankyou', array( $this, 'add_pdf_invoices_links_to_thankyou_page' ), 10, 1 );
// Action Buttons to Admin's Orders list
add_filter( 'woocommerce_admin_order_actions', array( $this, 'add_pdf_invoices_admin_actions' ), PHP_INT_MAX, 2 );
add_filter( 'admin_head', array( $this, 'add_pdf_invoices_admin_actions_buttons_css' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// Make Sortable Columns
add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'shop_order_sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'shop_order_pre_get_posts_order_by_column' ) );
// Meta box on admin order page
add_action( 'add_meta_boxes', array( $this, 'add_invoices_meta_box' ) );
}
}
/**
* shop_order_pre_get_posts_order_by_column.
*
* @version 2.9.0
* @since 2.5.8
*/
function shop_order_pre_get_posts_order_by_column( $query ) {
if (
$query->is_main_query() &&
( $orderby = $query->get( 'orderby' ) ) &&
isset( $query->query['post_type'] ) && 'shop_order' === $query->query['post_type'] &&
isset( $query->is_admin ) && 1 == $query->is_admin
) {
if ( 'wcj_invoicing_' === substr( $orderby, 0, 14 ) ) {
$query->set( 'meta_key', '_' . $orderby );
$query->set( 'orderby', 'meta_value_num' );
}
}
}
/**
* Make columns sortable.
*
* @version 2.9.0
* @since 2.5.8
* @param array $columns
* @return array
*/
function shop_order_sortable_columns( $columns ) {
$custom = array();
foreach ( wcj_get_enabled_invoice_types_ids() as $invoice_type_id ) {
$custom[ $invoice_type_id ] = 'wcj_invoicing_' . $invoice_type_id . '_number_id';
}
return wp_parse_args( $custom, $columns );
}
/**
* enqueue_scripts.
*
* @version 2.5.2
* @since 2.5.2
*/
function enqueue_scripts() {
wp_enqueue_script( 'wcj-pdf-invoicing', wcj_plugin_url() . '/includes/js/wcj-pdf-invoicing.js', array(), false, true );
}
/**
* add_pdf_invoices_admin_actions_buttons_css.
*
* @version 3.1.0
* @since 2.4.7
*/
function add_pdf_invoices_admin_actions_buttons_css() {
echo '<style>' . PHP_EOL;
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
echo '.view.' . $invoice_type['id'] . '{ color: ' . $invoice_type['color'] . ' !important; }' . PHP_EOL;
echo '.view.' . $invoice_type['id'] . '_' . 'create' . '{ color: ' . $invoice_type['color'] . ' !important; }' . PHP_EOL;
echo '.view.' . $invoice_type['id'] . '_' . 'delete' . '{ color: ' . $invoice_type['color'] . ' !important; }' . PHP_EOL;
echo '.view.' . $invoice_type['id'] . '::after { content: "\f498" !important; }' . PHP_EOL;
echo '.view.' . $invoice_type['id'] . '_' . 'create' . '::after { content: "\f119" !important; }' . PHP_EOL;
echo '.view.' . $invoice_type['id'] . '_' . 'delete' . '::after { content: "\f153" !important; }' . PHP_EOL;
}
echo '</style>' . PHP_EOL;
}
/**
* add_pdf_invoices_admin_actions.
*
* @version 2.7.0
* @since 2.4.7
*/
function add_pdf_invoices_admin_actions( $actions, $the_order ) {
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
if ( wcj_is_invoice_created( wcj_get_order_id( $the_order ), $invoice_type['id'] ) ) {
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_view_btn', 'no' ) ) {
// Document (View) button
$query_args = array( 'order_id' => wcj_get_order_id( $the_order ), 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1', );
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
$query_args['save_pdf_invoice'] = '1';
}
$the_url = add_query_arg( $query_args, remove_query_arg( array ( 'create_invoice_for_order_id', 'delete_invoice_for_order_id' ) ) );
$the_name = __( 'View', 'woocommerce-jetpack' ) . ' ' . $invoice_type['title'];
$the_action = 'view ' . $invoice_type['id'];
$the_action_id = $invoice_type['id'];
$actions[ $the_action_id ] = array( 'url' => $the_url, 'name' => $the_name, 'action' => $the_action );
}
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_delete_btn', 'yes' ) ) {
// Delete button
$query_args = array( 'delete_invoice_for_order_id' => wcj_get_order_id( $the_order ), 'invoice_type_id' => $invoice_type['id'] );
$the_url = add_query_arg( $query_args, remove_query_arg( 'create_invoice_for_order_id' ) );
$the_name = __( 'Delete', 'woocommerce-jetpack' ) . ' ' . $invoice_type['title'];
$the_action = 'view ' . $invoice_type['id'] . '_' . 'delete' . ( ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_delete_btn_confirm', 'yes' ) ) ? ' wcj_need_confirmation' : '' );
$the_action_id = $invoice_type['id'] . '_' . 'delete';
$actions[ $the_action_id ] = array( 'url' => $the_url, 'name' => $the_name, 'action' => $the_action );
}
} else {
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_create_btn', 'yes' ) ) {
// Create button
$query_args = array( 'create_invoice_for_order_id' => wcj_get_order_id( $the_order ), 'invoice_type_id' => $invoice_type['id'] );
$the_url = add_query_arg( $query_args, remove_query_arg( 'delete_invoice_for_order_id' ) );
$the_name = __( 'Create', 'woocommerce-jetpack' ) . ' ' . $invoice_type['title'];
$the_action = 'view ' . $invoice_type['id'] . '_' . 'create' . ( ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_create_btn_confirm', 'yes' ) ) ? ' wcj_need_confirmation' : '' );
$the_action_id = $invoice_type['id'] . '_' . 'create';
$actions[ $the_action_id ] = array( 'url' => $the_url, 'name' => $the_name, 'action' => $the_action );
}
}
}
return $actions;
}
/**
* add_order_column.
*
* @version 3.1.0
*/
function add_order_column( $columns ) {
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page_column', 'yes' ) ) {
$columns[ $invoice_type['id'] ] = get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_page_column_text', $invoice_type['title'] );
}
}
return $columns;
}
/**
* Output custom columns for products
*
* @version 2.4.7
* @param string $column
*/
function render_order_columns( $column ) {
$invoice_types_ids = wcj_get_enabled_invoice_types_ids();
if ( ! in_array( $column, $invoice_types_ids ) ) {
return;
}
$order_id = get_the_ID();
$invoice_type_id = $column;
$html = '';
if ( wcj_is_invoice_created( $order_id, $invoice_type_id ) ) {
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
$the_number = $the_invoice->get_invoice_number();
// Document Link
$query_args = array( 'order_id' => $order_id, 'invoice_type_id' => $invoice_type_id, 'get_invoice' => '1', );
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type_id . '_save_as_enabled', 'no' ) ) {
$query_args['save_pdf_invoice'] = '1';
}
$html .= '<a href="' . add_query_arg( $query_args, remove_query_arg( array( 'create_invoice_for_order_id', 'delete_invoice_for_order_id' ) ) ) . '">' .
$the_number . '</a>';
}
echo $html;
}
/**
* add_pdf_invoices_links_to_thankyou_page.
*
* @version 3.6.0
* @since 3.6.0
* @todo option to change priority for the hook (probably for all docs at once)
*/
function add_pdf_invoices_links_to_thankyou_page( $order_id ) {
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
if ( ! wcj_is_invoice_created( $order_id, $invoice_type['id'] ) ) {
continue;
}
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_on_thankyou_page', 'no' ) ) {
$query_args = array( 'order_id' => $order_id, 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1', );
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
$query_args['save_pdf_invoice'] = '1';
}
if ( '' == ( $title = get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_thankyou_page_link_text', $invoice_type['title'] ) ) ) {
$title = $invoice_type['title'];
}
echo str_replace( '%link%', '<a target="_blank" href="' . add_query_arg( $query_args ) . '">' . $title . '</a>',
get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_thankyou_page_template',
'<p><strong>' . sprintf( __( 'Your %s:', 'woocommerce-jetpack' ), $invoice_type['title'] ) . ' </strong> %link%</p>' ) );
}
}
}
/**
* add_pdf_invoices_action_links.
*
* @version 2.7.0
*/
function add_pdf_invoices_action_links( $actions, $the_order ) {
$invoice_types = wcj_get_enabled_invoice_types();
foreach ( $invoice_types as $invoice_type ) {
if ( ! wcj_is_invoice_created( wcj_get_order_id( $the_order ), $invoice_type['id'] ) ) {
continue;
}
$my_account_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers';
if ( 'yes' === get_option( $my_account_option_name, 'no' ) ) {
$the_action_id = $invoice_type['id'];
$query_args = array( 'order_id' => wcj_get_order_id( $the_order ), 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1', );
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
$query_args['save_pdf_invoice'] = '1';
}
$the_url = add_query_arg( $query_args );
$the_name = get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_link_text' );
if ( '' == $the_name ) {
$the_name = $invoice_type['title'];
}
$the_action = 'view ' . $invoice_type['id'];
$actions[ $the_action_id ] = array( 'url' => $the_url, 'name' => $the_name, 'action' => $the_action );
}
}
return $actions;
}
/**
* add_invoices_meta_box.
*
* @version 3.1.0
* @since 2.8.0
*/
function add_invoices_meta_box() {
if ( 'yes' === get_option( 'wcj_invoicing_add_order_meta_box', 'yes' ) ) {
add_meta_box(
'wc-booster-pdf-invoicing',
'<span class="dashicons dashicons-media-default" style="color:#23282d;"></span>' . ' ' . __( 'Booster: PDF Invoices', 'woocommerce-jetpack' ),
array( $this, 'create_invoices_meta_box' ),
'shop_order',
'side',
'default'
);
}
}
/**
* create_invoices_meta_box.
*
* @version 3.6.0
* @since 2.8.0
*/
function create_invoices_meta_box() {
$_order = wc_get_order();
$order_id = wcj_get_order_id( $_order );
$invoice_types = wcj_get_enabled_invoice_types();
if ( empty( $invoice_types ) ) {
echo '<p style="font-style:italic;">' . __( 'You have no document types enabled.', 'woocommerce-jetpack' ) . '</p>';
} else {
foreach ( $invoice_types as $invoice_type ) {
$table_data = array();
$the_number = '';
if ( wcj_is_invoice_created( $order_id, $invoice_type['id'] ) ) {
// "Document (View)" link
$query_args = array( 'order_id' => $order_id, 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1', );
$target = ( 'yes' === get_option( 'wcj_invoicing_order_meta_box_open_in_new_window', 'yes' ) ? ' target="_blank"' : '' );
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
$query_args['save_pdf_invoice'] = '1';
$target = '';
}
$the_url = add_query_arg( $query_args, remove_query_arg( array ( 'create_invoice_for_order_id', 'delete_invoice_for_order_id' ) ) );
$the_name = __( 'View', 'woocommerce-jetpack' );
$the_invoice = wcj_get_invoice( $order_id, $invoice_type['id'] );
$the_number = ' [#' . $the_invoice->get_invoice_number() . ']';
$view_link = '<a' . $target . ' href="' . $the_url . '">' . $the_name . '</a>';
// "Delete" link
$query_args = array( 'delete_invoice_for_order_id' => $order_id, 'invoice_type_id' => $invoice_type['id'] );
$the_url = add_query_arg( $query_args, remove_query_arg( 'create_invoice_for_order_id' ) );
$the_name = __( 'Delete', 'woocommerce-jetpack' );
$delete_link = '<a class="wcj_need_confirmation" href="' . $the_url . '">' . $the_name . '</a>';
// Numbering
if ( 'yes' === get_option( 'wcj_invoicing_add_order_meta_box_numbering', 'yes' ) ) {
$number_option = 'wcj_invoicing_' . $invoice_type['id'] . '_number_id';
$number_input = '<input style="width:100%;" type="number"' .
' id="' . $number_option . '" name="' . $number_option . '" value="' . get_post_meta( $order_id, '_' . $number_option, true ) . '">' .
'<input type="hidden" name="woojetpack_pdf_invoicing_save_post" value="woojetpack_pdf_invoicing_save_post">';
} else {
$number_input = '';
}
// Actions
$actions = array( $view_link . ' | ' . $delete_link . '<br>' . $number_input );
} else {
// "Create" link
$query_args = array( 'create_invoice_for_order_id' => $order_id, 'invoice_type_id' => $invoice_type['id'] );
$the_url = add_query_arg( $query_args, remove_query_arg( 'delete_invoice_for_order_id' ) );
$the_name = __( 'Create', 'woocommerce-jetpack' );
$actions = array( '<a class="wcj_need_confirmation" href="' . $the_url . '">' . $the_name . '</a>' );
}
$maybe_toolptip = '';
$_hooks = wcj_get_invoice_create_on( $invoice_type['id'] );
if ( in_array( 'woocommerce_order_partially_refunded_notification', $_hooks ) ) {
$maybe_toolptip = wc_help_tip( __( 'In case of partial refund, you need to reload the page to see created document in this meta box.', 'woocommerce-jetpack' ), true );
}
$table_data[] = array( '<span class="dashicons dashicons-media-default" style="color:' . $invoice_type['color'] . ';"></span>' . ' ' .
$invoice_type['title'] . $the_number . $maybe_toolptip );
$table_data[] = $actions;
echo '<p>' . wcj_get_table_html( $table_data, array( 'table_class' => 'widefat striped' ) ) . '</p>';
}
}
}
}
endif;
return new WCJ_PDF_Invoicing_Display();

View File

@@ -0,0 +1,85 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Email Options
*
* @version 3.7.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Emails' ) ) :
class WCJ_PDF_Invoicing_Emails extends WCJ_Module {
/**
* Constructor.
*
* @version 2.8.0
*/
function __construct() {
$this->id = 'pdf_invoicing_emails';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Email Options', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
if ( $this->is_enabled() ) {
if ( ! wcj_is_module_enabled( 'general' ) || 'no' === get_option( 'wcj_general_advanced_disable_save_sys_temp_dir', 'no' ) ) {
add_filter( 'woocommerce_email_attachments', array( $this, 'add_pdf_invoice_email_attachment' ), PHP_INT_MAX, 3 );
}
}
}
/**
* do_attach_for_payment_method.
*
* @version 2.8.0
*/
function do_attach_for_payment_method( $invoice_type_id, $payment_method ) {
$included_gateways = get_option( 'wcj_invoicing_' . $invoice_type_id . '_payment_gateways', array() );
if ( empty ( $included_gateways ) ) {
return true; // include all
}
return ( in_array( $payment_method, $included_gateways ) );
}
/**
* add_pdf_invoice_email_attachment.
*
* @version 3.7.0
*/
function add_pdf_invoice_email_attachment( $attachments, $status, $order ) {
if ( ! $order || ! is_object( $order ) || 'WC_Order' != get_class( $order ) ) {
return $attachments;
}
$invoice_types_ids = wcj_get_enabled_invoice_types_ids();
$order_id = wcj_get_order_id( $order );
foreach ( $invoice_types_ids as $invoice_type_id ) {
if ( false === $this->do_attach_for_payment_method( $invoice_type_id, wcj_order_get_payment_method( $order ) ) ) {
continue;
}
if ( ! wcj_is_invoice_created( $order_id, $invoice_type_id ) ) {
continue;
}
$send_on_statuses = get_option( 'wcj_invoicing_' . $invoice_type_id . '_attach_to_emails', array() );
if ( '' == $send_on_statuses ) {
$send_on_statuses = array();
}
if ( in_array( $status, $send_on_statuses ) ) {
$the_invoice = wcj_get_pdf_invoice( $order_id, $invoice_type_id );
$file_name = $the_invoice->get_pdf( 'F' );
if ( '' != $file_name ) {
$attachments[] = $file_name;
}
}
}
return $attachments;
}
}
endif;
return new WCJ_PDF_Invoicing_Emails();

View File

@@ -0,0 +1,30 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Footer
*
* @version 2.8.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Footer' ) ) :
class WCJ_PDF_Invoicing_Footer extends WCJ_Module {
/**
* Constructor.
*/
function __construct() {
$this->id = 'pdf_invoicing_footer';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Footer', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
}
}
endif;
return new WCJ_PDF_Invoicing_Footer();

View File

@@ -0,0 +1,32 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Header
*
* @version 2.8.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Header' ) ) :
class WCJ_PDF_Invoicing_Header extends WCJ_Module {
/**
* Constructor.
*
* @version 2.3.0
*/
function __construct() {
$this->id = 'pdf_invoicing_header';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Header', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
}
}
endif;
return new WCJ_PDF_Invoicing_Header();

View File

@@ -0,0 +1,60 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Numbering
*
* @version 3.2.3
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Numbering' ) ) :
class WCJ_PDF_Invoicing_Numbering extends WCJ_Module {
/**
* Constructor.
*
* @version 3.2.3
*/
function __construct() {
$this->id = 'pdf_invoicing_numbering';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Numbering', 'woocommerce-jetpack' );
parent::__construct( 'submodule' );
if ( 'yes' === get_option( 'wcj_invoicing_admin_search_by_invoice', 'no' ) ) {
add_action( 'pre_get_posts', array( $this, 'search_orders_by_invoice_number' ) );
}
}
/**
* search_orders_by_invoice_number.
*
* @version 3.2.3
* @since 3.2.3
*/
function search_orders_by_invoice_number( $query ) {
if (
! is_admin() ||
! isset( $query->query ) ||
! isset( $query->query['s'] ) ||
false === is_numeric( $query->query['s'] ) ||
0 == $query->query['s'] ||
'shop_order' !== $query->query['post_type'] ||
! $query->query_vars['shop_order_search']
) {
return;
}
$invoice_number = $query->query['s'];
$query->query_vars['post__in'] = array();
$query->query['s'] = '';
$query->set( 'meta_key', '_wcj_invoicing_invoice_number_id' );
$query->set( 'meta_value', $invoice_number );
}
}
endif;
return new WCJ_PDF_Invoicing_Numbering();

View File

@@ -0,0 +1,394 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Page Settings
*
* @version 2.8.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Page' ) ) :
class WCJ_PDF_Invoicing_Page extends WCJ_Module {
/**
* Constructor.
*
* @version 2.4.0
*/
function __construct() {
$this->id = 'pdf_invoicing_page';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Page Settings', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
}
/**
* get_page_formats.
*
* @version 2.4.7
* @since 2.4.7
*/
function get_page_formats() {
$page_formats = array(
// ISO 216 A Series + 2 SIS 014711 extensions
'A0',
'A1',
'A2',
'A3',
'A4',
'A5',
'A6',
'A7',
'A8',
'A9',
'A10',
'A11',
'A12',
// ISO 216 B Series + 2 SIS 014711 extensions
'B0',
'B1',
'B2',
'B3',
'B4',
'B5',
'B6',
'B7',
'B8',
'B9',
'B10',
'B11',
'B12',
// ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
'C0',
'C1',
'C2',
'C3',
'C4',
'C5',
'C6',
'C7',
'C8',
'C9',
'C10',
'C11',
'C12',
'C76',
'DL',
// SIS 014711 E Series
'E0',
'E1',
'E2',
'E3',
'E4',
'E5',
'E6',
'E7',
'E8',
'E9',
'E10',
'E11',
'E12',
// SIS 014711 G Series
'G0',
'G1',
'G2',
'G3',
'G4',
'G5',
'G6',
'G7',
'G8',
'G9',
'G10',
'G11',
'G12',
// ISO Press
'RA0',
'RA1',
'RA2',
'RA3',
'RA4',
'SRA0',
'SRA1',
'SRA2',
'SRA3',
'SRA4',
// German DIN 476
'4A0',
'2A0',
// Variations on the ISO Standard
'A2_EXTRA',
'A3+',
'A3_EXTRA',
'A3_SUPER',
'SUPER_A3',
'A4_EXTRA',
'A4_SUPER',
'SUPER_A4',
'A4_LONG',
'F4',
'SO_B5_EXTRA',
'A5_EXTRA',
// ANSI Series
'ANSI_E',
'ANSI_D',
'ANSI_C',
'ANSI_B',
'ANSI_A',
// Traditional 'Loose' North American Paper Sizes
'USLEDGER',
'LEDGER',
'ORGANIZERK',
'BIBLE',
'USTABLOID',
'TABLOID',
'ORGANIZERM',
'USLETTER',
'LETTER',
'USLEGAL',
'LEGAL',
'GOVERNMENTLETTER',
'GLETTER',
'JUNIORLEGAL',
'JLEGAL',
// Other North American Paper Sizes
'QUADDEMY',
'SUPER_B',
'QUARTO',
'GOVERNMENTLEGAL',
'FOLIO',
'MONARCH',
'EXECUTIVE',
'ORGANIZERL',
'STATEMENT',
'MEMO',
'FOOLSCAP',
'COMPACT',
'ORGANIZERJ',
// Canadian standard CAN 2-9.60M
'P1',
'P2',
'P3',
'P4',
'P5',
'P6',
// North American Architectural Sizes
'ARCH_E',
'ARCH_E1',
'ARCH_D',
'BROADSHEET',
'ARCH_C',
'ARCH_B',
'ARCH_A',
// --- North American Envelope Sizes ---
// - Announcement Envelopes
'ANNENV_A2',
'ANNENV_A6',
'ANNENV_A7',
'ANNENV_A8',
'ANNENV_A10',
'ANNENV_SLIM',
// - Commercial Envelopes
'COMMENV_N6_1/4',
'COMMENV_N6_3/4',
'COMMENV_N8',
'COMMENV_N9',
'COMMENV_N10',
'COMMENV_N11',
'COMMENV_N12',
'COMMENV_N14',
// - Catalogue Envelopes
'CATENV_N1',
'CATENV_N1_3/4',
'CATENV_N2',
'CATENV_N3',
'CATENV_N6',
'CATENV_N7',
'CATENV_N8',
'CATENV_N9_1/2',
'CATENV_N9_3/4',
'CATENV_N10_1/2',
'CATENV_N12_1/2',
'CATENV_N13_1/2',
'CATENV_N14_1/4',
'CATENV_N14_1/2',
// Japanese (JIS P 0138-61) Standard B-Series
'JIS_B0',
'JIS_B1',
'JIS_B2',
'JIS_B3',
'JIS_B4',
'JIS_B5',
'JIS_B6',
'JIS_B7',
'JIS_B8',
'JIS_B9',
'JIS_B10',
'JIS_B11',
'JIS_B12',
// PA Series
'PA0',
'PA1',
'PA2',
'PA3',
'PA4',
'PA5',
'PA6',
'PA7',
'PA8',
'PA9',
'PA10',
// Standard Photographic Print Sizes
/* 'PASSPORT_PHOTO',
'E',
'L',
'3R',
'KG',
'4R',
'4D',
'2L',
'5R',
'8P',
'6R',
'6P',
'8R',
'6PW',
'S8R',
'4P',
'10R',
'4PW',
'S10R',
'11R',
'S11R',
'12R',
'S12R',
// Common Newspaper Sizes
'NEWSPAPER_BROADSHEET',
'NEWSPAPER_BERLINER',
'NEWSPAPER_TABLOID',
'NEWSPAPER_COMPACT',
// Business Cards
'CREDIT_CARD',
'BUSINESS_CARD',
'BUSINESS_CARD_ISO7810',
'BUSINESS_CARD_ISO216',
'BUSINESS_CARD_IT',
'BUSINESS_CARD_UK',
'BUSINESS_CARD_FR',
'BUSINESS_CARD_DE',
'BUSINESS_CARD_ES',
'BUSINESS_CARD_CA',
'BUSINESS_CARD_US',
'BUSINESS_CARD_JP',
'BUSINESS_CARD_HK',
'BUSINESS_CARD_AU',
'BUSINESS_CARD_DK',
'BUSINESS_CARD_SE',
'BUSINESS_CARD_RU',
'BUSINESS_CARD_CZ',
'BUSINESS_CARD_FI',
'BUSINESS_CARD_HU',
'BUSINESS_CARD_IL',
// Billboards
'4SHEET',
'6SHEET',
'12SHEET',
'16SHEET',
'32SHEET',
'48SHEET',
'64SHEET',
'96SHEET',
// Old European Sizes
// - Old Imperial English Sizes
'EN_EMPEROR',
'EN_ANTIQUARIAN',
'EN_GRAND_EAGLE',
'EN_DOUBLE_ELEPHANT',
'EN_ATLAS',
'EN_COLOMBIER',
'EN_ELEPHANT',
'EN_DOUBLE_DEMY',
'EN_IMPERIAL',
'EN_PRINCESS',
'EN_CARTRIDGE',
'EN_DOUBLE_LARGE_POST',
'EN_ROYAL',
'EN_SHEET',
'EN_HALF_POST',
'EN_SUPER_ROYAL',
'EN_DOUBLE_POST',
'EN_MEDIUM',
'EN_DEMY',
'EN_LARGE_POST',
'EN_COPY_DRAUGHT',
'EN_POST',
'EN_CROWN',
'EN_PINCHED_POST',
'EN_BRIEF',
'EN_FOOLSCAP',
'EN_SMALL_FOOLSCAP',
'EN_POTT',
// - Old Imperial Belgian Sizes
'BE_GRAND_AIGLE',
'BE_COLOMBIER',
'BE_DOUBLE_CARRE',
'BE_ELEPHANT',
'BE_PETIT_AIGLE',
'BE_GRAND_JESUS',
'BE_JESUS',
'BE_RAISIN',
'BE_GRAND_MEDIAN',
'BE_DOUBLE_POSTE',
'BE_COQUILLE',
'BE_PETIT_MEDIAN',
'BE_RUCHE',
'BE_PROPATRIA',
'BE_LYS',
'BE_POT',
'BE_ROSETTE',
// - Old Imperial French Sizes
'FR_UNIVERS',
'FR_DOUBLE_COLOMBIER',
'FR_GRANDE_MONDE',
'FR_DOUBLE_SOLEIL',
'FR_DOUBLE_JESUS',
'FR_GRAND_AIGLE',
'FR_PETIT_AIGLE',
'FR_DOUBLE_RAISIN',
'FR_JOURNAL',
'FR_COLOMBIER_AFFICHE',
'FR_DOUBLE_CAVALIER',
'FR_CLOCHE',
'FR_SOLEIL',
'FR_DOUBLE_CARRE',
'FR_DOUBLE_COQUILLE',
'FR_JESUS',
'FR_RAISIN',
'FR_CAVALIER',
'FR_DOUBLE_COURONNE',
'FR_CARRE',
'FR_COQUILLE',
'FR_DOUBLE_TELLIERE',
'FR_DOUBLE_CLOCHE',
'FR_DOUBLE_POT',
'FR_ECU',
'FR_COURONNE',
'FR_TELLIERE',
'FR_POT', */
);
$page_formats_options = array();
foreach ( $page_formats as $page_format ) {
$page_formats_options[ $page_format ] = $page_format;
}
return $page_formats_options;
}
}
endif;
return new WCJ_PDF_Invoicing_Page();

View File

@@ -0,0 +1,101 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Styling
*
* @version 3.1.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Styling' ) ) :
class WCJ_PDF_Invoicing_Styling extends WCJ_Module {
/**
* Constructor.
*
* @version 2.9.0
*/
function __construct() {
$this->id = 'pdf_invoicing_styling';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Styling', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
add_action( 'init', array( $this, 'manually_download_fonts' ) );
add_action( 'init', array( $this, 'schedule_download_fonts_event' ) );
add_action( 'admin_init', array( $this, 'schedule_download_fonts_event' ) );
add_action( 'wcj_download_tcpdf_fonts_hook', array( $this, 'download_fonts' ) );
}
/**
* get_default_css_template.
*
* @version 3.1.0
* @version 3.1.0
*/
function get_default_css_template( $invoice_type_id ) {
if ( ! isset( $this->default_css_template[ $invoice_type_id ] ) ) {
$default_template_filename = ( false === strpos( $invoice_type_id, 'custom_doc_' ) ? $invoice_type_id : 'custom_doc' );
$default_template_filename = wcj_plugin_path() . '/includes/settings/pdf-invoicing/wcj-' . $default_template_filename . '.css';
if ( file_exists( $default_template_filename ) ) {
ob_start();
include( $default_template_filename );
$this->default_css_template[ $invoice_type_id ] = ob_get_clean();
} else {
$this->default_css_template[ $invoice_type_id ] = '';
}
}
return $this->default_css_template[ $invoice_type_id ];
}
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*
* @version 2.9.0
* @version 2.9.0
* @todo save `$event_timestamp` info (i.e. hook next scheduled time)
*/
function schedule_download_fonts_event() {
$interval = 'hourly';
$event_hook = 'wcj_download_tcpdf_fonts_hook';
$event_timestamp = wp_next_scheduled( $event_hook, array( $interval ) );
if ( ! $event_timestamp ) {
wp_schedule_event( time(), $interval, $event_hook, array( $interval ) );
}
}
/**
* download_fonts.
*
* @version 2.9.0
* @version 2.9.0
*/
function download_fonts( $interval ) {
update_option( 'wcj_download_tcpdf_fonts_hook_timestamp', (int) current_time( 'timestamp' ) );
wcj_check_and_maybe_download_tcpdf_fonts( true );
}
/**
* manually_download_fonts.
*
* @version 2.9.0
* @version 2.9.0
* @todo add success/error message
*/
function manually_download_fonts() {
if ( isset( $_GET['wcj_download_fonts'] ) ) {
delete_option( 'wcj_invoicing_fonts_version' );
delete_option( 'wcj_invoicing_fonts_version_timestamp' );
wcj_check_and_maybe_download_tcpdf_fonts();
wp_safe_redirect( remove_query_arg( 'wcj_download_fonts' ) );
exit;
}
}
}
endif;
return new WCJ_PDF_Invoicing_Styling();

View File

@@ -0,0 +1,60 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - Templates
*
* @version 3.1.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_PDF_Invoicing_Templates' ) ) :
class WCJ_PDF_Invoicing_Templates extends WCJ_Module {
/**
* Constructor.
*
* @version 2.3.7
*/
function __construct() {
$this->id = 'pdf_invoicing_templates';
$this->parent_id = 'pdf_invoicing';
$this->short_desc = __( 'Templates', 'woocommerce-jetpack' );
$this->desc = '';
parent::__construct( 'submodule' );
}
/**
* get_default_template.
*
* @version 3.1.0
* @since 3.1.0
*/
function get_default_template( $invoice_type_id ) {
if ( ! isset( $this->default_template[ $invoice_type_id ] ) ) {
$default_template_filename = ( false === strpos( $invoice_type_id, 'custom_doc_' ) ? $invoice_type_id : 'custom_doc' );
$default_template_filename = wcj_plugin_path() . '/includes/settings/pdf-invoicing/wcj-content-template-' . $default_template_filename . '.php';
if ( file_exists( $default_template_filename ) ) {
ob_start();
include( $default_template_filename );
$this->default_template[ $invoice_type_id ] = ob_get_clean();
if ( false !== strpos( $invoice_type_id, 'custom_doc' ) ) {
$custom_doc_nr = ( 'custom_doc' === $invoice_type_id ) ? '1' : str_replace( 'custom_doc_', '', $invoice_type_id );
$this->default_template[ $invoice_type_id ] = str_replace( '[wcj_custom_doc_number]', '[wcj_custom_doc_number doc_nr="' . $custom_doc_nr . '"]',
$this->default_template[ $invoice_type_id ] );
$this->default_template[ $invoice_type_id ] = str_replace( '[wcj_custom_doc_date]', '[wcj_custom_doc_date doc_nr="' . $custom_doc_nr . '"]',
$this->default_template[ $invoice_type_id ] );
}
} else {
$this->default_template[ $invoice_type_id ] = '';
}
}
return $this->default_template[ $invoice_type_id ];
}
}
endif;
return new WCJ_PDF_Invoicing_Templates();

View File

@@ -0,0 +1,14 @@
<?php
/**
* Booster for WooCommerce - PDF Invoicing - TcpdfFpdi
*
* This is needed to get round namespaces parse error in PHP < 5.3.0.
*
* @version 3.5.2
* @since 3.5.2
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
return new \setasign\Fpdi\TcpdfFpdi();