/**
  * Constructor.
  *
  * @version 2.3.0
  */
 public function __construct()
 {
     $this->id = 'pdf_invoicing';
     $this->short_desc = __('PDF Invoicing', 'woocommerce-jetpack');
     $this->section_title = __('General', 'woocommerce-jetpack');
     $this->desc = __('WooCommerce Invoices, Proforma Invoices, Credit Notes and Packing Slips.', 'woocommerce-jetpack');
     parent::__construct();
     if ($this->is_enabled()) {
         include_once 'pdf-invoices/class-wcj-pdf-invoicing-renumerate-tool.php';
         include_once 'pdf-invoices/class-wcj-pdf-invoicing-report-tool.php';
         add_action('init', array($this, 'catch_args'));
         add_action('init', array($this, 'generate_pdf_on_init'));
         //			define ( 'K_PATH_IMAGES', $_SERVER['DOCUMENT_ROOT'] );
         $invoice_types = wcj_get_enabled_invoice_types();
         foreach ($invoice_types as $invoice_type) {
             $the_hook = get_option('wcj_invoicing_' . $invoice_type['id'] . '_create_on', 'woocommerce_new_order');
             if ('disabled' != $the_hook && 'manual' != $the_hook && '' != $the_hook) {
                 add_action($the_hook, array($this, 'create_' . $invoice_type['id']));
             }
         }
         /* $this->meta_box_screen   = 'shop_order';
         			$this->meta_box_context  = 'side';
         			$this->meta_box_priority = 'default';
         			add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); */
     }
 }
 /**
  * get_settings.
  *
  * @version 2.5.2
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings = array_merge($settings, array(array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_options'), array('title' => __('Sequential', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_sequential_enabled', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('Counter', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_counter', 'default' => 1, 'type' => 'number'), array('title' => __('Counter Width', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_counter_width', 'default' => 0, 'type' => 'number'), array('title' => __('Prefix', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_prefix', 'default' => '', 'type' => 'text', 'css' => 'width:300px'), array('title' => __('Suffix', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_suffix', 'default' => '', 'type' => 'text', 'css' => 'width:300px'), array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_options')));
     }
     return $this->add_standard_settings($settings);
 }
 function wcj_get_enabled_invoice_types_ids()
 {
     $invoice_types = wcj_get_enabled_invoice_types();
     $invoice_types_ids = array();
     foreach ($invoice_types as $invoice_type) {
         $invoice_types_ids[] = $invoice_type['id'];
     }
     return $invoice_types_ids;
 }
 /**
  * get_settings.
  *
  * @version 2.4.7
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_options');
         $settings = array_merge($settings, array(array('title' => __('Enable Footer', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_enabled', 'default' => 'yes', 'type' => 'checkbox'), array('title' => __('Footer Text', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_text', 'default' => 'Page %page_number% / %total_pages%', 'type' => 'textarea', 'css' => 'width:66%;min-width:300px;height:165px;', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'desc_tip' => __('You can use HTML here, as well as any WordPress shortcodes. There is two more predefined values you can use: %page_number% and %total_pages%.', 'woocommerce-jetpack'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly')), array('title' => __('Footer Text Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_text_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Footer Line Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_line_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Footer Margin', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_footer', 'default' => 10, 'type' => 'number')));
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_options');
     }
     return $this->add_standard_settings($settings);
 }
 /**
  * get_settings.
  *
  * @version 2.4.0
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options');
         $settings = array_merge($settings, array(array('title' => __('Enable Header', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_enabled', 'default' => 'yes', 'type' => 'checkbox'), array('title' => __('Header Image', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image', 'default' => '', 'type' => 'text', 'css' => 'width:33%;min-width:300px;', 'desc' => __('Enter a URL to an image you want to show in the invoice\'s header. Upload your image using the <a href="/wp-admin/media-new.php">media uploader</a>.', 'woocommerce-jetpack'), 'desc_tip' => __('Leave blank to disable', 'woocommerce-jetpack')), array('title' => __('Header Image Width in mm', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image_width_mm', 'default' => 50, 'type' => 'number'), array('title' => __('Header Title', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_title_text', 'default' => $invoice_type['title'], 'type' => 'text'), array('title' => __('Header Text', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text', 'default' => __('Company Name', 'woocommerce-jetpack'), 'type' => 'text'), array('title' => __('Header Text Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Header Line Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_line_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Header Margin', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_header', 'default' => 10, 'type' => 'number')));
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options');
     }
     return $settings;
 }
 /**
  * get_settings.
  *
  * @version 2.4.7
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options');
         $settings = array_merge($settings, array(array('title' => __('Enable Header', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_enabled', 'default' => 'yes', 'type' => 'checkbox'), array('title' => __('Header Image', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image', 'default' => '', 'type' => 'text', 'css' => 'width:33%;min-width:300px;', 'desc' => __('Enter a URL to an image you want to show in the invoice\'s header. Upload your image using the <a href="/wp-admin/media-new.php">media uploader</a>.', 'woocommerce-jetpack'), 'desc_tip' => __('Leave blank to disable', 'woocommerce-jetpack')), array('title' => __('Header Image Width in mm', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image_width_mm', 'default' => 50, 'type' => 'number'), array('title' => __('Header Title', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_title_text', 'default' => $invoice_type['title'], 'type' => 'text'), array('title' => __('Header Text', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text', 'default' => __('Company Name', 'woocommerce-jetpack'), 'type' => 'text'), array('title' => __('Header Text Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Header Line Color', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_line_color', 'default' => '#cccccc', 'type' => 'color', 'css' => 'width:6em;'), array('title' => __('Header Margin', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_header', 'default' => 10, 'type' => 'number')));
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options');
     }
     $settings = array_merge($settings, array(array('title' => __('PDF Invoicing Header General Options', 'woocommerce-jetpack'), 'type' => 'title', 'id' => 'wcj_invoicing_general_header_options'), array('title' => __('Default Images Directory', 'woocommerce-jetpack'), 'desc' => __('Default images directory in TCPDF library (K_PATH_IMAGES).', 'woocommerce-jetpack'), 'desc_tip' => __('Try changing this if you have issues displaying image in header.', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_general_header_images_path', 'default' => 'empty', 'type' => 'select', 'options' => array('empty' => __('Empty', 'woocommerce-jetpack'), 'tcpdf_default' => __('TCPDF Default', 'woocommerce-jetpack'), 'abspath' => __('ABSPATH', 'woocommerce-jetpack'), 'document_root' => __('DOCUMENT_ROOT', 'woocommerce-jetpack'))), array('type' => 'sectionend', 'id' => 'wcj_invoicing_general_header_options')));
     return $this->add_standard_settings($settings);
 }
        /**
         * Add extra bulk action options to generate/download documents
         *
         * Using Javascript until WordPress core fixes: http://core.trac.wordpress.org/ticket/16031
         *
         * @todo    add "print" action
         * @see     https://www.skyverge.com/blog/add-custom-bulk-action/
         * @version 2.5.7
         * @since   2.5.7
         */
        function bulk_actions_pdfs_admin_footer()
        {
            global $post_type;
            if ('shop_order' == $post_type) {
                ?>
<script type="text/javascript"><?php 
                $invoice_types = wcj_get_enabled_invoice_types();
                foreach ($invoice_types as $invoice_type) {
                    $key = $invoice_type['id'];
                    $title = $invoice_type['title'];
                    ?>
jQuery(function() {
					jQuery('<option>').val('generate_<?php 
                    echo $key;
                    ?>
').text('<?php 
                    echo __('Generate', 'woocommerce-jetpack') . ' ' . $title;
                    ?>
').appendTo('select[name="action"]');
					jQuery('<option>').val('generate_<?php 
                    echo $key;
                    ?>
').text('<?php 
                    echo __('Generate', 'woocommerce-jetpack') . ' ' . $title;
                    ?>
').appendTo('select[name="action2"]');
				});<?php 
                }
                foreach ($invoice_types as $invoice_type) {
                    $key = $invoice_type['id'];
                    $title = $invoice_type['title'];
                    ?>
jQuery(function() {
					jQuery('<option>').val('download_<?php 
                    echo $key;
                    ?>
').text('<?php 
                    echo __('Download', 'woocommerce-jetpack') . ' ' . $title;
                    ?>
').appendTo('select[name="action"]');
					jQuery('<option>').val('download_<?php 
                    echo $key;
                    ?>
').text('<?php 
                    echo __('Download', 'woocommerce-jetpack') . ' ' . $title;
                    ?>
').appendTo('select[name="action2"]');
				});<?php 
                }
                ?>
</script><?php 
            }
        }
 /**
  * get_settings.
  *
  * @version 2.5.2
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         ob_start();
         include 'defaults/wcj-content-template-' . $invoice_type['id'] . '.php';
         $default_template = ob_get_clean();
         $settings = array_merge($settings, array(array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options'), array('title' => __('HTML Template', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_template', 'default' => $default_template, 'type' => 'textarea', 'css' => 'width:66%;min-width:300px;height:500px;'), array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options')));
     }
     $settings = array_merge($settings, array(array('title' => __('Available Shortcodes', 'woocommerce-jetpack'), 'type' => 'title', 'desc' => sprintf(__('For the list of available shortcodes, please visit %s.', 'woocommerce-jetpack'), '<a target="_blank" href="http://booster.io/category/shortcodes/?utm_source=shortcodes_list&utm_medium=module_button&utm_campaign=booster_documentation">http://booster.io/category/shortcodes/</a>'), 'id' => 'wcj_invoicing_templates_desc'), array('type' => 'sectionend', 'id' => 'wcj_invoicing_templates_desc')));
     return $this->add_standard_settings($settings);
 }
 /**
  * get_settings.
  *
  * @version 2.4.0
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         ob_start();
         include 'defaults/wcj-content-template-' . $invoice_type['id'] . '.php';
         $default_template = ob_get_clean();
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options');
         $settings[] = array('title' => __('HTML Template', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_template', 'default' => $default_template, 'type' => 'textarea', 'css' => 'width:66%;min-width:300px;height:500px;');
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options');
     }
     $settings[] = array('title' => __('Available Shortcodes', 'woocommerce-jetpack'), 'type' => 'title', 'desc' => wcj_get_shortcodes_list(), 'id' => 'wcj_invoicing_templates_desc');
     $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_templates_desc');
     return $settings;
 }
 /**
  * get_settings.
  *
  * @version 2.4.7
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_options');
         $settings[] = array('title' => __('Page Orientation', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_orientation', 'default' => 'P', 'type' => 'select', 'options' => array('P' => __('Portrait', 'woocommerce-jetpack'), 'L' => __('Landscape', 'woocommerce-jetpack')));
         $settings[] = array('title' => __('Page Format', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_format', 'default' => 'A4', 'type' => 'select', 'options' => $this->get_page_formats());
         $settings[] = array('title' => __('Margin Left', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_left', 'default' => 15, 'type' => 'number');
         $settings[] = array('title' => __('Margin Right', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_right', 'default' => 15, 'type' => 'number');
         $settings[] = array('title' => __('Margin Top', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_top', 'default' => 27, 'type' => 'number');
         $settings[] = array('title' => __('Margin Bottom', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_bottom', 'default' => 0, 'type' => 'number');
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_options');
     }
     return $this->add_standard_settings($settings);
 }
 /**
  * get_settings.
  *
  * @version 2.4.0
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_styling_options');
         ob_start();
         include 'defaults/wcj-' . $invoice_type['id'] . '.css';
         $default_template = ob_get_clean();
         $settings[] = array('title' => __('CSS', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_css', 'default' => $default_template, 'type' => 'textarea', 'css' => 'width:66%;min-width:300px;height:200px;');
         $settings[] = array('title' => __('Font Family', 'woocommerce-jetpack'), 'desc' => apply_filters('get_wc_jetpack_plus_message', '', 'desc'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_family', 'default' => 'dejavusans', 'type' => 'select', 'options' => array('dejavusans' => 'DejaVu Sans', 'courier' => 'Courier', 'helvetica' => 'Helvetica', 'times' => 'Times', 'droidsansfallback' => 'Droid Sans Fallback'), 'custom_attributes' => apply_filters('get_wc_jetpack_plus_message', '', 'disabled'));
         $settings[] = array('title' => __('Font Size', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_size', 'default' => 8, 'type' => 'number');
         $settings[] = array('title' => __('Make Font Shadowed', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_shadowed', 'default' => 'no', 'type' => 'checkbox');
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_styling_options');
     }
     return $settings;
 }
        /**
         * Add Invoices Report tool to WooCommerce menu (the content).
         *
         * @version 2.3.10
         */
        function create_invoices_report_tool()
        {
            $result_message = '';
            $result_message .= $this->notice;
            $the_year = !empty($_POST['report_year']) ? $_POST['report_year'] : '';
            $the_month = !empty($_POST['report_month']) ? $_POST['report_month'] : '';
            $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>';
                }
            }
            ?>
<div>
			<h3><?php 
            echo __('Booster - Invoices Report', 'woocommerce-jetpack');
            ?>
</h3>
			<p><?php 
            echo __('Invoices Monthly Reports.', 'woocommerce-jetpack');
            ?>
</p>
			<?php 
            echo $result_message;
            ?>
			<p><form method="post" action=""><?php 
            // Type
            $invoice_type_select_html = '<select 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(array(__('Year', 'woocommerce-jetpack'), '<input class="input-text" type="number" min="2000" max="2100" step="1" name="report_year" value="' . $the_year . '">'), array(__('Month', 'woocommerce-jetpack'), '<input class="input-text" type="number" min="1" max="12" step="1" name="report_month" value="' . $the_month . '">'), array(__('Document Type', 'woocommerce-jetpack'), $invoice_type_select_html), array('', '<input class="button-primary" type="submit" name="get_invoices_report" value="' . __('Display monthly invoices table', 'woocommerce-jetpack') . '">'), array('', '<input class="button-primary" type="submit" name="get_invoices_report_zip" value="' . __('Download all monthly invoices PDFs in single ZIP file', 'woocommerce-jetpack') . '">'));
            // Print all
            echo wcj_get_table_html($data, array('table_heading_type' => 'vertical'));
            ?>
</form></p>
		</div><?php 
        }
Example #13
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     if (get_option('wcj_pdf_invoicing_enabled') == 'yes') {
         include_once 'pdf-invoices/class-wcj-pdf-invoicing-renumerate-tool.php';
         add_action('init', array($this, 'catch_args'));
         add_action('init', array($this, 'generate_pdf_on_init'));
         //define ( 'K_PATH_IMAGES', $_SERVER['DOCUMENT_ROOT'] );
         $invoice_types = wcj_get_enabled_invoice_types();
         foreach ($invoice_types as $invoice_type) {
             $the_hook = get_option('wcj_invoicing_' . $invoice_type['id'] . '_create_on', 'woocommerce_new_order');
             if ('disabled' != $the_hook) {
                 add_action($the_hook, array($this, 'create_' . $invoice_type['id']));
             }
         }
     }
     // Settings hooks
     add_filter('wcj_settings_sections', array($this, 'settings_section'));
     add_filter('wcj_settings_pdf_invoicing', array($this, 'get_settings'), 100);
     add_filter('wcj_features_status', array($this, 'add_enabled_option'), 100);
 }
 /**
  * Constructor.
  *
  * @version 2.3.10
  */
 public function __construct()
 {
     $this->id = 'pdf_invoicing';
     $this->short_desc = __('PDF Invoicing', 'woocommerce-jetpack');
     $this->section_title = __('General', 'woocommerce-jetpack');
     $this->desc = __('WooCommerce Invoices, Proforma Invoices, Credit Notes and Packing Slips.', 'woocommerce-jetpack');
     parent::__construct();
     $this->add_tools(array('renumerate_invoices' => array('title' => __('Invoices Renumerate', 'woocommerce-jetpack'), 'desc' => __('Tool renumerates all invoices, proforma invoices, credit notes and packing slips.', 'woocommerce-jetpack')), 'invoices_report' => array('title' => __('Invoices Report', 'woocommerce-jetpack'), 'desc' => __('Invoices Monthly Reports.', 'woocommerce-jetpack'))));
     if ($this->is_enabled()) {
         add_action('init', array($this, 'catch_args'));
         add_action('init', array($this, 'generate_pdf_on_init'));
         $this->the_pdf_invoicing_report_tool = (include_once 'pdf-invoices/class-wcj-pdf-invoicing-report-tool.php');
         $invoice_types = wcj_get_enabled_invoice_types();
         foreach ($invoice_types as $invoice_type) {
             $the_hook = get_option('wcj_invoicing_' . $invoice_type['id'] . '_create_on', 'woocommerce_new_order');
             if ('disabled' != $the_hook && 'manual' != $the_hook && '' != $the_hook) {
                 add_action($the_hook, array($this, 'create_' . $invoice_type['id']));
             }
         }
     }
 }
        /**
         * Add Renumerate Invoices tool to WooCommerce menu (the content).
         *
         * @version 2.3.10
         */
        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']) ? true : false;
            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>';
                }
                //$result_message .= '<p>' . $renumerate_result . '</p>';
            }
            ?>
<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" 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" 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" 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 type="checkbox" name="delete_all" value="" ' . checked($the_delete_all, true, false) . '>', '<em>' . __('Clear all invoices before renumerating.', 'woocommerce-jetpack') . '</em>');
            // Type
            $invoice_type_select_html = '<select name="invoice_type">';
            //$invoice_types = wcj_get_invoice_types();
            $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 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 . '">' . $desc . '</option>';
                $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_heading_type' => 'vertical'));
            ?>
			</form></p>
			<?php 
            if ('' != $renumerate_result) {
                echo '<h3>' . __('Results', 'woocommerce-jetpack') . '</h3>';
                echo '<p>' . $renumerate_result . '</p>';
            }
            ?>
		</div><?php 
        }
 /**
  * add_pdf_invoices_action_links.
  *
  * @version 2.3.7
  */
 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($the_order->id, $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' => $the_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';
             }
             $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;
 }
 /**
  * get_settings.
  *
  * @version 2.5.6
  * @todo    "edit order" metabox;
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_display_options');
         $settings = array_merge($settings, array(array('title' => __('Admin\'s "Orders" Page', 'woocommerce-jetpack'), 'desc' => __('Add Column', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page_column', 'default' => 'yes', 'type' => 'checkbox'), array('title' => '', 'desc' => __('Column Title', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_page_column_text', 'default' => $invoice_type['title'], 'type' => 'text'), array('desc' => __('Add View Button', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_view_btn', 'default' => 'no', 'type' => 'checkbox'), array('desc' => __('Add Create Button', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_create_btn', 'default' => 'yes', 'type' => 'checkbox'), array('desc' => __('Add Delete Button', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_delete_btn', 'default' => 'yes', 'type' => 'checkbox'), array('desc' => __('Create Button Requires Confirmation', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_create_btn_confirm', 'default' => 'yes', 'type' => 'checkbox'), array('desc' => __('Delete Button Requires Confirmation', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_delete_btn_confirm', 'default' => 'yes', 'type' => 'checkbox'), array('title' => __('Customer\'s "My Account" Page', 'woocommerce-jetpack'), 'desc' => __('Add link', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers', 'default' => 'no', 'type' => 'checkbox'), array('title' => '', 'desc' => __('Link Text', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_link_text', 'default' => $invoice_type['title'], 'type' => 'text'), array('title' => __('Enable "Save as"', 'woocommerce-jetpack'), 'desc' => __('Enable', 'woocommerce-jetpack'), 'desc_tip' => __('Enable "save as" pdf instead of view pdf in browser', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('PDF File Name', 'woocommerce-jetpack'), 'desc' => __('Enter file name for PDF documents. You can use shortcodes here, e.g. [wcj_' . $invoice_type['id'] . '_number]', 'woocommerce-jetpack'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_file_name', 'default' => '[wcj_' . $invoice_type['id'] . '_number]', 'type' => 'text')));
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_display_options');
     }
     return $this->add_standard_settings($settings);
 }
 /**
  * get_settings.
  *
  * @version 2.4.0
  */
 function get_settings()
 {
     $settings = array();
     $invoice_types = 'yes' === get_option('wcj_invoicing_hide_disabled_docs_settings', 'no') ? wcj_get_enabled_invoice_types() : wcj_get_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         $settings[] = array('title' => strtoupper($invoice_type['desc']), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_emails_options');
         $available_emails = array('new_order' => __('Admin - New Order', 'woocommerce'), 'cancelled_order' => __('Admin - Cancelled Order', 'woocommerce'), 'customer_processing_order' => __('Customer - Processing Order', 'woocommerce'), 'customer_completed_order' => __('Customer - Completed Order', 'woocommerce'), 'customer_invoice' => __('Customer - Invoice', 'woocommerce'), 'customer_refunded_order' => __('Customer - Refunded Order', 'woocommerce'));
         if ('yes' === get_option('wcj_emails_enabled', 'no')) {
             for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_emails_custom_emails_total_number', 1)); $i++) {
                 $available_emails['wcj_custom' . '_' . $i] = __('Custom', 'woocommerce-jetpack') . ' #' . $i;
             }
         }
         $settings[] = array('title' => __('Attach PDF to emails', 'woocommerce'), 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_attach_to_emails', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'default' => '', 'options' => $available_emails, 'custom_attributes' => array('data-placeholder' => __('Select some emails', 'woocommerce')));
         $settings = apply_filters('wcj_pdf_invoicing_emails_settings', $settings, $invoice_type['id']);
         $settings[] = array('type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_emails_options');
     }
     return $settings;
 }
 /**
 * add_pdf_invoice_icon_css.
 *
 	function add_pdf_invoice_icon_css() {
 		$invoice_types = wcj_get_enabled_invoice_types();
 		foreach ( $invoice_types as $invoice_type ) {
 			echo '<style> a.button.tips.view.' .      $invoice_type['id'] . ':after { content: "' . $invoice_type['icon'] . '" !important; } </style>';
 		}
 	}
 
     /**
 * add_pdf_invoices_action_links.
 */
 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($the_order->id, $invoice_type['id'])) {
             continue;
         }
         //$admin_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page';
         $my_account_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers';
         /*if ( ( 'woocommerce_admin_order_actions'          === current_filter() && 'add_action_link' === get_option( $admin_option_name, 'add_column' ) ) ||
           ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) ) {*/
         //if ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) {
         if ('yes' === get_option($my_account_option_name, 'no')) {
             $the_action_id = $invoice_type['id'];
             //$the_url = basename( $_SERVER['REQUEST_URI'] ) . '&order_id=' . $the_order->id . '&invoice_type_id=' . $invoice_type['id'] . '&get_invoice=1';
             $query_args = array('order_id' => $the_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';
             }
             $the_url = add_query_arg($query_args);
             $the_name = $invoice_type['desc'];
             $the_action = 'view ' . $invoice_type['id'];
             /* if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
             				$the_url .= '&save_pdf_invoice=1';
             			} */
             $actions[$the_action_id] = array('url' => $the_url, 'name' => $the_name, 'action' => $the_action);
         }
     }
     return $actions;
 }