@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -13,217 +13,217 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | /** Check if billing class does not exist before creating the class */ |
| 15 | 15 | if (!class_exists("wpshop_modules_billing")) { |
| 16 | - /** |
|
| 17 | - * Billing module utilities definition |
|
| 18 | - * |
|
| 19 | - * @author Alexandre Techer - Eoxia dev team <[email protected]> |
|
| 20 | - * @version 0.1 |
|
| 21 | - * @package includes |
|
| 22 | - * @subpackage modules |
|
| 23 | - */ |
|
| 24 | - class wpshop_modules_billing |
|
| 25 | - { |
|
| 26 | - /** |
|
| 27 | - * Create a new instance for the current module - Billing |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - /** Add custom template for current module */ |
|
| 32 | - add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 33 | - |
|
| 34 | - /** In case wpshop is set on sale mode and not on view catalog only, Ad billign options */ |
|
| 35 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 36 | - $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 37 | - $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 38 | - |
|
| 39 | - if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 40 | - && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 41 | - /** Add module option to wpshop general options */ |
|
| 42 | - add_filter('wpshop_options', array(&$this, 'add_options'), 9); |
|
| 43 | - add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Filter |
|
| 48 | - add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Load module/addon automatically to existing template list |
|
| 53 | - * |
|
| 54 | - * @param array $templates The current template definition |
|
| 55 | - * |
|
| 56 | - * @return array The template with new elements |
|
| 57 | - */ |
|
| 58 | - public function custom_template_load($templates) |
|
| 59 | - { |
|
| 60 | - include 'templates/common/main_elements.tpl.php'; |
|
| 61 | - $wpshop_template = $tpl_element; |
|
| 62 | - /* Get custom frontend template */ |
|
| 63 | - if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) { |
|
| 64 | - require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php'; |
|
| 65 | - if (!empty($tpl_element)) { |
|
| 66 | - $wpshop_template['common']['custom'] = ($tpl_element); |
|
| 67 | - } |
|
| 68 | - unset($tpl_element); |
|
| 69 | - } |
|
| 70 | - $wpshop_display = new wpshop_display(); |
|
| 71 | - $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates); |
|
| 72 | - |
|
| 73 | - unset($tpl_element); |
|
| 74 | - |
|
| 75 | - return $templates; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Declare option groups for the module |
|
| 80 | - */ |
|
| 81 | - public function add_options($option_group) |
|
| 82 | - { |
|
| 83 | - $option_group['wpshop_billing_info'] = |
|
| 84 | - array('label' => __('Billing', 'wpshop'), |
|
| 85 | - 'subgroups' => array( |
|
| 86 | - 'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'), |
|
| 87 | - ), |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - return $option_group; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Declare the different options in groups for the module |
|
| 95 | - */ |
|
| 96 | - public function declare_options() |
|
| 97 | - { |
|
| 98 | - add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 99 | - |
|
| 100 | - register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures')); |
|
| 101 | - add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 102 | - |
|
| 103 | - register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator')); |
|
| 104 | - add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 105 | - add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 106 | - |
|
| 107 | - $quotation_option = get_option('wpshop_addons'); |
|
| 108 | - if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) { |
|
| 109 | - add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 110 | - |
|
| 111 | - register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time')); |
|
| 112 | - add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 113 | - $payment_option = get_option('wps_payment_mode'); |
|
| 114 | - if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) { |
|
| 115 | - register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation')); |
|
| 116 | - add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 117 | - } |
|
| 118 | - register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation')); |
|
| 119 | - add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function wpshop_options_validate_wpshop_bic_to_quotation($input) |
|
| 125 | - { |
|
| 126 | - return $input; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function wpshop_bic_to_quotation_field() |
|
| 130 | - { |
|
| 131 | - $add_quotation_option = get_option('wpshop_paymentMethod_options'); |
|
| 132 | - $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />'; |
|
| 133 | - echo $output; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function billing_options_main_explanation() |
|
| 137 | - { |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - public function quotation_options_main_explanation() |
|
| 141 | - { |
|
| 142 | - |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function wpshop_options_validate_quotation_validate_time($input) |
|
| 146 | - { |
|
| 147 | - return $input; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function wpshop_billing_number_figures_field() |
|
| 151 | - { |
|
| 152 | - $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures'); |
|
| 153 | - $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null; |
|
| 154 | - if (empty($wpshop_billing_number_figures)) { |
|
| 155 | - $wpshop_billing_number_figures = 5; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' /> |
|
| 16 | + /** |
|
| 17 | + * Billing module utilities definition |
|
| 18 | + * |
|
| 19 | + * @author Alexandre Techer - Eoxia dev team <[email protected]> |
|
| 20 | + * @version 0.1 |
|
| 21 | + * @package includes |
|
| 22 | + * @subpackage modules |
|
| 23 | + */ |
|
| 24 | + class wpshop_modules_billing |
|
| 25 | + { |
|
| 26 | + /** |
|
| 27 | + * Create a new instance for the current module - Billing |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + /** Add custom template for current module */ |
|
| 32 | + add_filter('wpshop_custom_template', array(&$this, 'custom_template_load')); |
|
| 33 | + |
|
| 34 | + /** In case wpshop is set on sale mode and not on view catalog only, Ad billign options */ |
|
| 35 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 36 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 37 | + $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : ''; |
|
| 38 | + |
|
| 39 | + if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation') |
|
| 40 | + && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) { |
|
| 41 | + /** Add module option to wpshop general options */ |
|
| 42 | + add_filter('wpshop_options', array(&$this, 'add_options'), 9); |
|
| 43 | + add_action('wsphop_options', array(&$this, 'declare_options'), 8); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Filter |
|
| 48 | + add_filter('wps_order_saving_admin_extra_action', array($this, 'force_invoice_generation_on_order'), 50, 2); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Load module/addon automatically to existing template list |
|
| 53 | + * |
|
| 54 | + * @param array $templates The current template definition |
|
| 55 | + * |
|
| 56 | + * @return array The template with new elements |
|
| 57 | + */ |
|
| 58 | + public function custom_template_load($templates) |
|
| 59 | + { |
|
| 60 | + include 'templates/common/main_elements.tpl.php'; |
|
| 61 | + $wpshop_template = $tpl_element; |
|
| 62 | + /* Get custom frontend template */ |
|
| 63 | + if (is_file(get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php')) { |
|
| 64 | + require_once get_stylesheet_directory() . '/wpshop/common/main_elements.tpl.php'; |
|
| 65 | + if (!empty($tpl_element)) { |
|
| 66 | + $wpshop_template['common']['custom'] = ($tpl_element); |
|
| 67 | + } |
|
| 68 | + unset($tpl_element); |
|
| 69 | + } |
|
| 70 | + $wpshop_display = new wpshop_display(); |
|
| 71 | + $templates = $wpshop_display->add_modules_template_to_internal($wpshop_template, $templates); |
|
| 72 | + |
|
| 73 | + unset($tpl_element); |
|
| 74 | + |
|
| 75 | + return $templates; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Declare option groups for the module |
|
| 80 | + */ |
|
| 81 | + public function add_options($option_group) |
|
| 82 | + { |
|
| 83 | + $option_group['wpshop_billing_info'] = |
|
| 84 | + array('label' => __('Billing', 'wpshop'), |
|
| 85 | + 'subgroups' => array( |
|
| 86 | + 'wpshop_billing_info' => array('class' => ' wpshop_admin_box_options_billing'), |
|
| 87 | + ), |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + return $option_group; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Declare the different options in groups for the module |
|
| 95 | + */ |
|
| 96 | + public function declare_options() |
|
| 97 | + { |
|
| 98 | + add_settings_section('wpshop_billing_info', '<span class="dashicons dashicons-admin-generic"></span>' . __('Billing settings', 'wpshop'), array(&$this, 'billing_options_main_explanation'), 'wpshop_billing_info'); |
|
| 99 | + |
|
| 100 | + register_setting('wpshop_options', 'wpshop_billing_number_figures', array(&$this, 'wpshop_options_validate_billing_number_figures')); |
|
| 101 | + add_settings_field('wpshop_billing_number_figures', __('Number of figures', 'wpshop'), array(&$this, 'wpshop_billing_number_figures_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 102 | + |
|
| 103 | + register_setting('wpshop_options', 'wpshop_billing_address', array(&$this, 'wpshop_billing_address_validator')); |
|
| 104 | + add_settings_field('wpshop_billing_address_choice', __('Billing address choice', 'wpshop'), array(&$this, 'wpshop_billing_address_choice_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 105 | + add_settings_field('wpshop_billing_address_include_into_register', '', array(&$this, 'wpshop_billing_address_include_into_register_field'), 'wpshop_billing_info', 'wpshop_billing_info'); |
|
| 106 | + |
|
| 107 | + $quotation_option = get_option('wpshop_addons'); |
|
| 108 | + if (!empty($quotation_option) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']) && !empty($quotation_option['WPSHOP_ADDONS_QUOTATION']['activate'])) { |
|
| 109 | + add_settings_section('wpshop_quotation_info', '<span class="dashicons dashicons-clipboard"></span>' . __('Quotation settings', 'wpshop'), array(&$this, 'quotation_options_main_explanation'), 'wpshop_billing_info'); |
|
| 110 | + |
|
| 111 | + register_setting('wpshop_options', 'wpshop_quotation_validate_time', array(&$this, 'wpshop_options_validate_quotation_validate_time')); |
|
| 112 | + add_settings_field('wpshop_quotation_validate_time', __('Quotation validate time', 'wpshop'), array(&$this, 'wpshop_quotation_validate_time_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 113 | + $payment_option = get_option('wps_payment_mode'); |
|
| 114 | + if (!empty($payment_option) && !empty($payment_option['mode']) && !empty($payment_option['mode']['banktransfer']) && !empty($payment_option['mode']['banktransfer']['active'])) { |
|
| 115 | + register_setting('wpshop_options', 'wpshop_paymentMethod_options[banktransfer][add_in_quotation]', array(&$this, 'wpshop_options_validate_wpshop_bic_to_quotation')); |
|
| 116 | + add_settings_field('wpshop_paymentMethod_options[banktransfer][add_in_quotation]', __('Add your BIC to your quotations', 'wpshop'), array(&$this, 'wpshop_bic_to_quotation_field'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 117 | + } |
|
| 118 | + register_setting('wpshop_options', 'wpshop_payment_partial', array(&$this, 'wpshop_quotation_payment_partial_validation')); |
|
| 119 | + add_settings_field('wpshop_payment_partial', __('Quotation partial payment'), array(&$this, 'wpshop_quotation_payment_partial'), 'wpshop_billing_info', 'wpshop_quotation_info'); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function wpshop_options_validate_wpshop_bic_to_quotation($input) |
|
| 125 | + { |
|
| 126 | + return $input; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function wpshop_bic_to_quotation_field() |
|
| 130 | + { |
|
| 131 | + $add_quotation_option = get_option('wpshop_paymentMethod_options'); |
|
| 132 | + $output = '<input type="checkbox" name="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" id="wpshop_paymentMethod_options[banktransfer][add_in_quotation]" ' . ((!empty($add_quotation_option) && !empty($add_quotation_option['banktransfer']) && !empty($add_quotation_option['banktransfer']['add_in_quotation'])) ? 'checked="checked"' : '') . ' />'; |
|
| 133 | + echo $output; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function billing_options_main_explanation() |
|
| 137 | + { |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + public function quotation_options_main_explanation() |
|
| 141 | + { |
|
| 142 | + |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function wpshop_options_validate_quotation_validate_time($input) |
|
| 146 | + { |
|
| 147 | + return $input; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function wpshop_billing_number_figures_field() |
|
| 151 | + { |
|
| 152 | + $wpshop_billing_number_figures = get_option('wpshop_billing_number_figures'); |
|
| 153 | + $readonly = !empty($wpshop_billing_number_figures) ? 'readonly="readonly"' : null; |
|
| 154 | + if (empty($wpshop_billing_number_figures)) { |
|
| 155 | + $wpshop_billing_number_figures = 5; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + echo '<input name="wpshop_billing_number_figures" type="text" value="' . $wpshop_billing_number_figures . '" ' . $readonly . ' /> |
|
| 159 | 159 | <a href="#" title="' . __('Number of figures to make appear on invoices', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>'; |
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function wpshop_options_validate_billing_number_figures($input) |
|
| 163 | - { |
|
| 164 | - return $input; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - public function wpshop_billing_address_validator($input) |
|
| 168 | - { |
|
| 169 | - global $wpdb; |
|
| 170 | - $t = wps_address::get_addresss_form_fields_by_type($input['choice']); |
|
| 171 | - |
|
| 172 | - $the_code = ''; |
|
| 173 | - foreach ($t[$input['choice']] as $group_id => $group_def) { |
|
| 174 | - if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { |
|
| 175 | - $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; |
|
| 176 | - continue; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $the_code; |
|
| 180 | - |
|
| 181 | - if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { |
|
| 182 | - if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 183 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $billing_option = get_option('wpshop_billing_address'); |
|
| 188 | - if (!empty($billing_option) && !empty($billing_option['display_model'])) { |
|
| 189 | - $input['display_model'] = $billing_option['display_model']; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $input; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - public function wpshop_billing_address_choice_field() |
|
| 196 | - { |
|
| 197 | - global $wpdb; |
|
| 198 | - $output = ''; |
|
| 199 | - |
|
| 200 | - $wpshop_billing_address = get_option('wpshop_billing_address'); |
|
| 201 | - |
|
| 202 | - $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 203 | - $entity_id = $wpdb->get_var($query); |
|
| 204 | - |
|
| 205 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 206 | - $content = $wpdb->get_results($query); |
|
| 207 | - |
|
| 208 | - /* Field for billing address type choice */ |
|
| 209 | - $input_def['name'] = 'wpshop_billing_address[choice]'; |
|
| 210 | - $input_def['id'] = 'wpshop_billing_address_choice'; |
|
| 211 | - $input_def['possible_value'] = $content; |
|
| 212 | - $input_def['type'] = 'select'; |
|
| 213 | - $input_def['value'] = $wpshop_billing_address['choice']; |
|
| 214 | - $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>'; |
|
| 215 | - |
|
| 216 | - /* Field for integrate billign form into register form */ |
|
| 217 | - $input_def = array(); |
|
| 218 | - $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]'; |
|
| 219 | - $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form'; |
|
| 220 | - $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop')); |
|
| 221 | - $input_def['valueToPut'] = 'index'; |
|
| 222 | - $input_def['options_label']['original'] = true; |
|
| 223 | - $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" '; |
|
| 224 | - $input_def['type'] = 'checkbox'; |
|
| 225 | - $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : ''); |
|
| 226 | - $output .= ' |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function wpshop_options_validate_billing_number_figures($input) |
|
| 163 | + { |
|
| 164 | + return $input; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + public function wpshop_billing_address_validator($input) |
|
| 168 | + { |
|
| 169 | + global $wpdb; |
|
| 170 | + $t = wps_address::get_addresss_form_fields_by_type($input['choice']); |
|
| 171 | + |
|
| 172 | + $the_code = ''; |
|
| 173 | + foreach ($t[$input['choice']] as $group_id => $group_def) { |
|
| 174 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && array_key_exists($input['integrate_into_register_form_matching_field']['user_email'], $group_def['content'])) { |
|
| 175 | + $the_code = $group_def['content'][$input['integrate_into_register_form_matching_field']['user_email']]['name']; |
|
| 176 | + continue; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $the_code; |
|
| 180 | + |
|
| 181 | + if (!empty($input['integrate_into_register_form']) && $input['integrate_into_register_form'] == 'yes') { |
|
| 182 | + if (!empty($input['integrate_into_register_form_matching_field']) && !empty($input['integrate_into_register_form_matching_field']['user_email']) && $the_code == 'address_user_email') { |
|
| 183 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('_need_verification' => 'no'), array('code' => $the_code)); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 188 | + if (!empty($billing_option) && !empty($billing_option['display_model'])) { |
|
| 189 | + $input['display_model'] = $billing_option['display_model']; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $input; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + public function wpshop_billing_address_choice_field() |
|
| 196 | + { |
|
| 197 | + global $wpdb; |
|
| 198 | + $output = ''; |
|
| 199 | + |
|
| 200 | + $wpshop_billing_address = get_option('wpshop_billing_address'); |
|
| 201 | + |
|
| 202 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = "%s" AND post_type = "%s"', WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 203 | + $entity_id = $wpdb->get_var($query); |
|
| 204 | + |
|
| 205 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 206 | + $content = $wpdb->get_results($query); |
|
| 207 | + |
|
| 208 | + /* Field for billing address type choice */ |
|
| 209 | + $input_def['name'] = 'wpshop_billing_address[choice]'; |
|
| 210 | + $input_def['id'] = 'wpshop_billing_address_choice'; |
|
| 211 | + $input_def['possible_value'] = $content; |
|
| 212 | + $input_def['type'] = 'select'; |
|
| 213 | + $input_def['value'] = $wpshop_billing_address['choice']; |
|
| 214 | + $output .= '<div>' . wpshop_form::check_input_type($input_def) . '</div>'; |
|
| 215 | + |
|
| 216 | + /* Field for integrate billign form into register form */ |
|
| 217 | + $input_def = array(); |
|
| 218 | + $input_def['name'] = 'wpshop_billing_address[integrate_into_register_form]'; |
|
| 219 | + $input_def['id'] = 'wpshop_billing_address_integrate_into_register_form'; |
|
| 220 | + $input_def['possible_value'] = array('yes' => __('Integrate billing form into register form', 'wpshop')); |
|
| 221 | + $input_def['valueToPut'] = 'index'; |
|
| 222 | + $input_def['options_label']['original'] = true; |
|
| 223 | + $input_def['option'] = ' class="wpshop_billing_address_integrate_into_register_form" '; |
|
| 224 | + $input_def['type'] = 'checkbox'; |
|
| 225 | + $input_def['value'] = array(!empty($wpshop_billing_address['integrate_into_register_form']) ? $wpshop_billing_address['integrate_into_register_form'] : ''); |
|
| 226 | + $output .= ' |
|
| 227 | 227 | <div class="wpshop_include_billing_form_into_register_container" > |
| 228 | 228 | ' . wpshop_form::check_input_type($input_def) . ' |
| 229 | 229 | <input type="hidden" name="wpshop_ajax_integrate_billin_into_register" id="wpshop_ajax_integrate_billin_into_register" value="' . wp_create_nonce('wpshop_ajax_integrate_billin_into_register') . '" /> |
@@ -231,892 +231,892 @@ discard block |
||
| 231 | 231 | <div class="wpshop_include_billing_form_into_register_where" ></div> |
| 232 | 232 | </div>'; |
| 233 | 233 | |
| 234 | - echo $output; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - public function wpshop_billing_address_include_into_register_field() |
|
| 238 | - { |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - public function wpshop_quotation_validate_time_field() |
|
| 243 | - { |
|
| 244 | - $quotation_option = get_option('wpshop_quotation_validate_time'); |
|
| 245 | - $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />'; |
|
| 246 | - $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">'; |
|
| 247 | - $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>'; |
|
| 248 | - $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>'; |
|
| 249 | - $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>'; |
|
| 250 | - $output .= '</select>'; |
|
| 251 | - |
|
| 252 | - echo $output; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Generate a new invoice number |
|
| 257 | - * |
|
| 258 | - * @param integer $order_id The order identifier we want to generate the new invoice number for |
|
| 259 | - * |
|
| 260 | - * @return string The new invoice number |
|
| 261 | - */ |
|
| 262 | - public static function generate_invoice_number($order_id) |
|
| 263 | - { |
|
| 264 | - /** Get configuration about the number of figure dor invoice number */ |
|
| 265 | - |
|
| 266 | - $number_figures = get_option('wpshop_billing_number_figures', false); |
|
| 267 | - |
|
| 268 | - /** If the number doesn't exist, we create a default one */ |
|
| 269 | - if (!$number_figures) { |
|
| 270 | - update_option('wpshop_billing_number_figures', 5); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** sleep my script, SLEEP I SAY ! **/ |
|
| 274 | - $rand_time = rand(1000, 200000); |
|
| 275 | - usleep($rand_time); |
|
| 276 | - /** GET UP !! **/ |
|
| 277 | - |
|
| 278 | - /** Get last invoice number */ |
|
| 279 | - $billing_current_number = get_option('wpshop_billing_current_number', false); |
|
| 280 | - |
|
| 281 | - /** If the counter doesn't exist, we initiate it */ |
|
| 282 | - if (!$billing_current_number) { |
|
| 283 | - $billing_current_number = 1; |
|
| 284 | - } else { |
|
| 285 | - $billing_current_number++; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** Check if number exists **/ |
|
| 289 | - $billing_current_number_checking = get_option('wpshop_billing_current_number', false); |
|
| 290 | - if ($billing_current_number_checking == $billing_current_number) { |
|
| 291 | - $billing_current_number++; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - update_option('wpshop_billing_current_number', $billing_current_number); |
|
| 295 | - |
|
| 296 | - /** Create the new invoice number with all parameters viewed above */ |
|
| 297 | - $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 298 | - |
|
| 299 | - return $invoice_ref; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Generate output for an invoice |
|
| 304 | - * |
|
| 305 | - * @param integer $order_id |
|
| 306 | - * @param string $invoice_ref |
|
| 307 | - * |
|
| 308 | - * @return string The invoice output in case no error is found. The error in other case |
|
| 309 | - */ |
|
| 310 | - public static function generate_html_invoice($order_id, $invoice_ref) |
|
| 311 | - { |
|
| 312 | - global $wpdb; |
|
| 313 | - |
|
| 314 | - $date_output_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 315 | - $count_products = 0; |
|
| 316 | - |
|
| 317 | - if (!empty($order_id)) { |
|
| 318 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 319 | - |
|
| 320 | - $discounts_exists = false; |
|
| 321 | - |
|
| 322 | - $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false; |
|
| 323 | - /** Check if it's a partial payment bill **/ |
|
| 324 | - $is_partial_payment = false; |
|
| 325 | - if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 326 | - foreach ($order_postmeta['order_payment']['received'] as $key => $payment) { |
|
| 327 | - if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) { |
|
| 328 | - $is_partial_payment = true; |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) { |
|
| 333 | - $is_partial_payment = true; |
|
| 334 | - } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 335 | - $is_partial_payment = true; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** Check it is a shipping slip **/ |
|
| 339 | - $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false; |
|
| 340 | - if ($bon_colisage) { |
|
| 341 | - $bon_colisage = true; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if (!empty($order_postmeta)) { |
|
| 345 | - $tpl_component = array(); |
|
| 346 | - |
|
| 347 | - /** Billing Header **/ |
|
| 348 | - //Logo |
|
| 349 | - $logo_options = get_option('wpshop_logo'); |
|
| 350 | - $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : ''; |
|
| 351 | - |
|
| 352 | - // Title |
|
| 353 | - $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop')); |
|
| 234 | + echo $output; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + public function wpshop_billing_address_include_into_register_field() |
|
| 238 | + { |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + public function wpshop_quotation_validate_time_field() |
|
| 243 | + { |
|
| 244 | + $quotation_option = get_option('wpshop_quotation_validate_time'); |
|
| 245 | + $output = '<input type="text" name="wpshop_quotation_validate_time[number]" id="wpshop_quotation_validate_time[number]" style="width:50px;" value="' . ((!empty($quotation_option) && !empty($quotation_option['number'])) ? $quotation_option['number'] : null) . '" />'; |
|
| 246 | + $output .= '<select name="wpshop_quotation_validate_time[time_type]" id="wpshop_quotation_validate_time[time_type]">'; |
|
| 247 | + $output .= '<option value="day" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'day') ? 'selected="selected"' : '') . '>' . __('Days', 'wpshop') . '</option>'; |
|
| 248 | + $output .= '<option value="month" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'month') ? 'selected="selected"' : '') . '>' . __('Months', 'wpshop') . '</option>'; |
|
| 249 | + $output .= '<option value="year" ' . ((!empty($quotation_option) && !empty($quotation_option['time_type']) && $quotation_option['time_type'] == 'year') ? 'selected="selected"' : '') . '>' . __('Years', 'wpshop') . '</option>'; |
|
| 250 | + $output .= '</select>'; |
|
| 251 | + |
|
| 252 | + echo $output; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Generate a new invoice number |
|
| 257 | + * |
|
| 258 | + * @param integer $order_id The order identifier we want to generate the new invoice number for |
|
| 259 | + * |
|
| 260 | + * @return string The new invoice number |
|
| 261 | + */ |
|
| 262 | + public static function generate_invoice_number($order_id) |
|
| 263 | + { |
|
| 264 | + /** Get configuration about the number of figure dor invoice number */ |
|
| 265 | + |
|
| 266 | + $number_figures = get_option('wpshop_billing_number_figures', false); |
|
| 267 | + |
|
| 268 | + /** If the number doesn't exist, we create a default one */ |
|
| 269 | + if (!$number_figures) { |
|
| 270 | + update_option('wpshop_billing_number_figures', 5); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** sleep my script, SLEEP I SAY ! **/ |
|
| 274 | + $rand_time = rand(1000, 200000); |
|
| 275 | + usleep($rand_time); |
|
| 276 | + /** GET UP !! **/ |
|
| 277 | + |
|
| 278 | + /** Get last invoice number */ |
|
| 279 | + $billing_current_number = get_option('wpshop_billing_current_number', false); |
|
| 280 | + |
|
| 281 | + /** If the counter doesn't exist, we initiate it */ |
|
| 282 | + if (!$billing_current_number) { |
|
| 283 | + $billing_current_number = 1; |
|
| 284 | + } else { |
|
| 285 | + $billing_current_number++; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** Check if number exists **/ |
|
| 289 | + $billing_current_number_checking = get_option('wpshop_billing_current_number', false); |
|
| 290 | + if ($billing_current_number_checking == $billing_current_number) { |
|
| 291 | + $billing_current_number++; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + update_option('wpshop_billing_current_number', $billing_current_number); |
|
| 295 | + |
|
| 296 | + /** Create the new invoice number with all parameters viewed above */ |
|
| 297 | + $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 298 | + |
|
| 299 | + return $invoice_ref; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Generate output for an invoice |
|
| 304 | + * |
|
| 305 | + * @param integer $order_id |
|
| 306 | + * @param string $invoice_ref |
|
| 307 | + * |
|
| 308 | + * @return string The invoice output in case no error is found. The error in other case |
|
| 309 | + */ |
|
| 310 | + public static function generate_html_invoice($order_id, $invoice_ref) |
|
| 311 | + { |
|
| 312 | + global $wpdb; |
|
| 313 | + |
|
| 314 | + $date_output_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 315 | + $count_products = 0; |
|
| 316 | + |
|
| 317 | + if (!empty($order_id)) { |
|
| 318 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 319 | + |
|
| 320 | + $discounts_exists = false; |
|
| 321 | + |
|
| 322 | + $is_quotation = (empty($order_postmeta['order_key']) && !empty($order_postmeta['order_temporary_key']) && $invoice_ref == null) ? true : false; |
|
| 323 | + /** Check if it's a partial payment bill **/ |
|
| 324 | + $is_partial_payment = false; |
|
| 325 | + if (isset($order_postmeta['order_payment']['received']) && !empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 326 | + foreach ($order_postmeta['order_payment']['received'] as $key => $payment) { |
|
| 327 | + if (isset($payment['invoice_ref']) && $payment['invoice_ref'] == $invoice_ref) { |
|
| 328 | + $is_partial_payment = true; |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } elseif (!empty($invoice_ref) && !empty($order_postmeta['order_invoice_ref']) && $order_postmeta['order_invoice_ref'] != $invoice_ref) { |
|
| 333 | + $is_partial_payment = true; |
|
| 334 | + } elseif (empty($invoice_ref) && $order_postmeta['order_status'] == 'partially_paid') { |
|
| 335 | + $is_partial_payment = true; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** Check it is a shipping slip **/ |
|
| 339 | + $bon_colisage = !empty($_GET['bon_colisage']) ? sanitize_key($_GET['bon_colisage']) : false; |
|
| 340 | + if ($bon_colisage) { |
|
| 341 | + $bon_colisage = true; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if (!empty($order_postmeta)) { |
|
| 345 | + $tpl_component = array(); |
|
| 346 | + |
|
| 347 | + /** Billing Header **/ |
|
| 348 | + //Logo |
|
| 349 | + $logo_options = get_option('wpshop_logo'); |
|
| 350 | + $tpl_component['INVOICE_LOGO'] = (!empty($logo_options)) ? '<img src="' . str_replace('https', 'http', $logo_options) . '" alt="" />' : ''; |
|
| 351 | + |
|
| 352 | + // Title |
|
| 353 | + $tpl_component['INVOICE_TITLE'] = ($is_partial_payment) ? __('Bill payment', 'wpshop') : (($is_quotation) ? __('Quotation', 'wpshop') : __('Invoice', 'wpshop')); |
|
| 354 | 354 | |
| 355 | 355 | // if ( empty($order_postmeta['order_invoice_ref']) ) { |
| 356 | - // $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop'); |
|
| 357 | - // $is_partial_payment = true; |
|
| 358 | - // } |
|
| 359 | - |
|
| 360 | - if ($bon_colisage) { |
|
| 361 | - $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 365 | - if ($bon_colisage) { |
|
| 366 | - $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ''; |
|
| 367 | - } |
|
| 368 | - $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']); |
|
| 369 | - $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)); |
|
| 370 | - |
|
| 371 | - /** Validate period for Quotation **/ |
|
| 372 | - if ($is_quotation) { |
|
| 373 | - $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']); |
|
| 374 | - } else { |
|
| 375 | - $tpl_component['INVOICE_VALIDATE_TIME'] = ''; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME']; |
|
| 379 | - |
|
| 380 | - $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : ''; |
|
| 381 | - |
|
| 382 | - // Sender & receiver addresses |
|
| 383 | - $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part(); |
|
| 384 | - $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage); |
|
| 385 | - |
|
| 386 | - $tpl_component['INVOICE_TRACKING'] = ''; |
|
| 387 | - $first = false; |
|
| 388 | - if (!empty($order_postmeta['order_trackingNumber'])) { |
|
| 389 | - $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber']; |
|
| 390 | - $first = true; |
|
| 391 | - } |
|
| 392 | - if (!empty($order_postmeta['order_trackingLink'])) { |
|
| 393 | - if (!$first) { |
|
| 394 | - $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink']; |
|
| 395 | - } else { |
|
| 396 | - $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink']; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** Items Tab **/ |
|
| 401 | - $order_tva = array(); |
|
| 402 | - if ($bon_colisage) { |
|
| 403 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common'); |
|
| 404 | - } else { |
|
| 405 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common'); |
|
| 406 | - //if ( !$is_quotation ) { |
|
| 407 | - /** Check if products have discounts **/ |
|
| 408 | - if (!empty($order_postmeta['order_items']) && !$is_partial_payment) { |
|
| 409 | - foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 410 | - if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) { |
|
| 411 | - $discounts_exists = true; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if ($discounts_exists) { |
|
| 417 | - $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common'); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - //} |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $total_discounted = 0; |
|
| 424 | - $tpl_component['INVOICE_ROWS'] = ''; |
|
| 425 | - |
|
| 426 | - if (!$is_partial_payment) { |
|
| 427 | - if (!empty($order_postmeta['order_items'])) { |
|
| 428 | - foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 429 | - $sub_tpl_component = array(); |
|
| 430 | - $count_products += $item['item_qty']; |
|
| 431 | - $barcode = get_post_meta($item['item_id'], '_barcode', true); |
|
| 432 | - if (empty($barcode)) { |
|
| 433 | - $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); |
|
| 434 | - $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : ''; |
|
| 435 | - |
|
| 436 | - if (empty($barcode)) { |
|
| 437 | - $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 438 | - $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code'); |
|
| 439 | - $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']); |
|
| 440 | - $barcode = $wpdb->get_var($query); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-'; |
|
| 444 | - |
|
| 445 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref']; |
|
| 446 | - |
|
| 447 | - /** Item name **/ |
|
| 448 | - $is_variation = false; |
|
| 449 | - if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 450 | - $is_variation = true; |
|
| 451 | - $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 452 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 453 | - $parent_post = $parent_def['parent_post']; |
|
| 454 | - $item_parent_id = $parent_post->ID; |
|
| 455 | - $item_title = $parent_post->post_title; |
|
| 456 | - } |
|
| 457 | - } else { |
|
| 458 | - $item_title = $item['item_name']; |
|
| 459 | - } |
|
| 460 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title; |
|
| 461 | - /** Get attribute order for current product */ |
|
| 462 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 463 | - $output_order = array(); |
|
| 464 | - if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 465 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 466 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 467 | - if (!empty($attribute_def->code)) { |
|
| 468 | - $output_order[$attribute_def->code] = $position; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 475 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 476 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = ''; |
|
| 477 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 478 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output; |
|
| 479 | - } |
|
| 480 | - $post_content = get_post_field('post_content', $item['item_id']); |
|
| 481 | - if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) { |
|
| 482 | - if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) { |
|
| 483 | - //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>'; |
|
| 484 | - } |
|
| 485 | - $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>'; |
|
| 486 | - } |
|
| 487 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : ''; |
|
| 488 | - unset($detail_tpl_component); |
|
| 489 | - |
|
| 490 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty']; |
|
| 491 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', '')); |
|
| 492 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '')); |
|
| 493 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', ''); |
|
| 494 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', ''); |
|
| 495 | - /** TVA **/ |
|
| 496 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', ''); |
|
| 497 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate']; |
|
| 498 | - |
|
| 499 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', ''); |
|
| 500 | - |
|
| 501 | - /** Checking Rate amount **/ |
|
| 502 | - if (!$bon_colisage) { |
|
| 503 | - $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id); |
|
| 504 | - if (!$checking) { |
|
| 505 | - return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop'); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - if ($bon_colisage) { |
|
| 510 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common'); |
|
| 511 | - } else { |
|
| 512 | - if ($discounts_exists) { |
|
| 513 | - $discounted_total_per_item = $item['item_total_ht']; |
|
| 514 | - /** Unit Discount **/ |
|
| 515 | - if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) { |
|
| 516 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', ''); |
|
| 517 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', ''); |
|
| 518 | - $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount']; |
|
| 519 | - } else { |
|
| 520 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 521 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** Global Discount **/ |
|
| 525 | - if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) { |
|
| 526 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', ''); |
|
| 527 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', ''); |
|
| 528 | - $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount']; |
|
| 529 | - } else { |
|
| 530 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 531 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $total_discounted += $discounted_total_per_item; |
|
| 535 | - /** Total HT Discounted **/ |
|
| 536 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', ''); |
|
| 537 | - |
|
| 538 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 539 | - } else { |
|
| 540 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - unset($sub_tpl_component); |
|
| 544 | - |
|
| 545 | - /** Check TVA **/ |
|
| 546 | - if (empty($order_tva[$item['item_tva_rate']])) { |
|
| 547 | - $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 548 | - } else { |
|
| 549 | - $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** Display Partials payments **/ |
|
| 556 | - $total_partial_payment = 0; |
|
| 557 | - $last_payment = 0; |
|
| 558 | - $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 559 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 560 | - foreach ($order_postmeta['order_payment']['received'] as $received_payment) { |
|
| 561 | - if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) { |
|
| 562 | - if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) { |
|
| 563 | - $sub_tpl_component = array(); |
|
| 564 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 565 | - |
|
| 566 | - /** Item name **/ |
|
| 567 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 568 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 569 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 570 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 571 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 572 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 573 | - |
|
| 574 | - /** TVA **/ |
|
| 575 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 576 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 577 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 578 | - |
|
| 579 | - if ($discounts_exists) { |
|
| 580 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 581 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 582 | - $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 583 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 584 | - $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 585 | - |
|
| 586 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 587 | - } else { |
|
| 588 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - unset($sub_tpl_component); |
|
| 593 | - $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 594 | - } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) { |
|
| 595 | - $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - } else { |
|
| 601 | - /** Display Partials payments **/ |
|
| 602 | - $total_partial_payment = 0; |
|
| 603 | - $last_payment = 0; |
|
| 604 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 605 | - foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) { |
|
| 606 | - if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) { |
|
| 607 | - $sub_tpl_component = array(); |
|
| 608 | - $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 609 | - /** Item name **/ |
|
| 610 | - $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1); |
|
| 611 | - $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 612 | - $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 613 | - $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 614 | - $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 615 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 616 | - /** TVA **/ |
|
| 617 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 618 | - $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 619 | - $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 620 | - $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 621 | - unset($sub_tpl_component); |
|
| 622 | - $total_partial_payment += $received_payment['received_amount']; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** Summary of order **/ |
|
| 629 | - $summary_tpl_component = array(); |
|
| 630 | - $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = ''; |
|
| 631 | - if (!$bon_colisage) { |
|
| 632 | - if (!empty($order_tva)) { |
|
| 633 | - foreach ($order_tva as $tax_rate => $tax_amount) { |
|
| 634 | - if ($tax_amount > 0) { |
|
| 635 | - $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 636 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 637 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 638 | - $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 639 | - unset($sub_tpl_component); |
|
| 640 | - } elseif ($is_partial_payment) { |
|
| 641 | - $tax_rate = 0; |
|
| 642 | - $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 643 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 644 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 645 | - $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 646 | - unset($sub_tpl_component); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** If Discount Exist **/ |
|
| 652 | - // Checking Discounts on order |
|
| 653 | - if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) { |
|
| 654 | - $discounts_exists = true; |
|
| 655 | - // Calcul discount on Order |
|
| 656 | - switch ($order_postmeta['order_discount_type']) { |
|
| 657 | - case 'amount': |
|
| 658 | - $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', ''); |
|
| 659 | - break; |
|
| 660 | - case 'percent': |
|
| 661 | - $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - if (!empty($total_discounted) && $discounts_exists) { |
|
| 666 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop'); |
|
| 667 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 668 | - $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 669 | - unset($sub_tpl_component); |
|
| 670 | - } else { |
|
| 671 | - $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = ''; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - $shipping_cost = 0; |
|
| 675 | - if (!$is_partial_payment) { |
|
| 676 | - if (!empty($order_postmeta['order_shipping_cost'])) { |
|
| 677 | - $shipping_cost = $order_postmeta['order_shipping_cost']; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 681 | - $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100)); |
|
| 682 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', ''); |
|
| 683 | - $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', ''); |
|
| 684 | - //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' ); |
|
| 685 | - |
|
| 686 | - $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 687 | - $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', ''); |
|
| 688 | - |
|
| 689 | - $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 690 | - |
|
| 691 | - $total_payment = 0; |
|
| 692 | - |
|
| 693 | - /** Amount paid **/ |
|
| 694 | - if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 695 | - foreach ($order_postmeta['order_payment']['received'] as $key => $value) { |
|
| 696 | - if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) { |
|
| 697 | - $total_payment = number_format($value['received_amount'], 2, ',', ''); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - } else { |
|
| 701 | - $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop'); |
|
| 705 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 706 | - //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ? number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 707 | - $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 708 | - unset($sub_tpl_component); |
|
| 709 | - |
|
| 710 | - $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop'); |
|
| 711 | - $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products; |
|
| 712 | - $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 713 | - unset($sub_tpl_component); |
|
| 714 | - |
|
| 715 | - /** If Discount Exist **/ |
|
| 716 | - if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) { |
|
| 717 | - $tpl_discount_component = array(); |
|
| 718 | - $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', ''); |
|
| 719 | - |
|
| 720 | - $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 721 | - $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common'); |
|
| 722 | - unset($tpl_discount_component); |
|
| 723 | - } else { |
|
| 724 | - $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = ''; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop'); |
|
| 728 | - |
|
| 729 | - $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common'); |
|
| 730 | - unset($summary_tpl_component); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** IBAN Include on quotation **/ |
|
| 734 | - if ($is_quotation) { |
|
| 735 | - /** If admin want to include his IBAN to quotation */ |
|
| 736 | - $iban_options = get_option('wpshop_paymentMethod_options'); |
|
| 737 | - $payment_options = get_option('wps_payment_mode'); |
|
| 738 | - if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') { |
|
| 739 | - if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) { |
|
| 740 | - $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>'; |
|
| 741 | - $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>'; |
|
| 742 | - $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>'; |
|
| 743 | - $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>'; |
|
| 744 | - $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>'; |
|
| 745 | - } |
|
| 746 | - } else { |
|
| 747 | - $tpl_component['IBAN_INFOS'] = ''; |
|
| 748 | - } |
|
| 749 | - } else { |
|
| 750 | - $tpl_component['IBAN_INFOS'] = ''; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - /** Received payements **/ |
|
| 754 | - if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) { |
|
| 755 | - $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id); |
|
| 756 | - } else { |
|
| 757 | - $tpl_component['RECEIVED_PAYMENT'] = ''; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** Invoice footer **/ |
|
| 761 | - $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice(); |
|
| 762 | - |
|
| 763 | - $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); |
|
| 764 | - } else { |
|
| 765 | - $output = __('No order information has been found', 'wpshop'); |
|
| 766 | - } |
|
| 767 | - } else { |
|
| 768 | - $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 769 | - } |
|
| 770 | - return $output; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Return the payment list part |
|
| 775 | - * @param integer $order_id |
|
| 776 | - * @return string |
|
| 777 | - */ |
|
| 778 | - public static function generate_received_payment_part($order_id) |
|
| 779 | - { |
|
| 780 | - $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 781 | - $output = ''; |
|
| 782 | - $tpl_component = array(); |
|
| 783 | - $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = ''; |
|
| 784 | - if (!empty($order_id)) { |
|
| 785 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 786 | - if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 787 | - $wps_payment_option = get_option('wps_payment_mode'); |
|
| 788 | - foreach ($order_postmeta['order_payment']['received'] as $payment) { |
|
| 789 | - if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) { |
|
| 790 | - $sub_tpl_component = array(); |
|
| 791 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0; |
|
| 792 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 793 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : '')); |
|
| 794 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : ''; |
|
| 795 | - $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : ''; |
|
| 796 | - $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 801 | - unset($tpl_component); |
|
| 802 | - } |
|
| 803 | - return $output; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** Return the validity period of a quotation **/ |
|
| 807 | - public static function quotation_validate_period($quotation_date) |
|
| 808 | - { |
|
| 809 | - $quotation_options = get_option('wpshop_quotation_validate_time'); |
|
| 810 | - if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) { |
|
| 811 | - $timestamp_quotation = strtotime($quotation_date); |
|
| 812 | - $timestamp_validity_date_quotation = 0; |
|
| 813 | - $query = ''; |
|
| 814 | - $date = ''; |
|
| 815 | - global $wpdb; |
|
| 816 | - switch ($quotation_options['time_type']) { |
|
| 817 | - case 'day': |
|
| 818 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " DAY) "); |
|
| 819 | - break; |
|
| 820 | - case 'month': |
|
| 821 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " MONTH) "); |
|
| 822 | - break; |
|
| 823 | - case 'year': |
|
| 824 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " YEAR) "); |
|
| 825 | - break; |
|
| 826 | - default: |
|
| 827 | - $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL 15 DAY) "); |
|
| 828 | - break; |
|
| 829 | - } |
|
| 830 | - if ($query != null) { |
|
| 831 | - $date = mysql2date('d F Y', $wpdb->get_var($query), true); |
|
| 832 | - } |
|
| 833 | - return sprintf(__('Quotation validity date %s', 'wpshop'), $date); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Generate HTML invoice to be sended by email |
|
| 839 | - * @param integer $order_id |
|
| 840 | - * @param string $invoice_ref |
|
| 841 | - * @return string |
|
| 842 | - */ |
|
| 843 | - public static function generate_invoice_for_email($order_id, $invoice_ref = '') |
|
| 844 | - { |
|
| 845 | - /** Generate the PDF file for the invoice **/ |
|
| 846 | - $is_ok = false; |
|
| 847 | - if (!empty($invoice_ref)) { |
|
| 848 | - require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'; |
|
| 849 | - try { |
|
| 850 | - $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 851 | - $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
|
| 852 | - $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
|
| 853 | - |
|
| 854 | - $html2pdf->setDefaultFont('Arial'); |
|
| 855 | - $html2pdf->writeHTML($html_content); |
|
| 856 | - $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F'); |
|
| 857 | - $is_ok = true; |
|
| 858 | - } catch (HTML2PDF_exception $e) { |
|
| 859 | - echo $e; |
|
| 860 | - exit; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : ''; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * Generate Sender part invoice template |
|
| 868 | - * @return Ambigous <string, string> |
|
| 869 | - */ |
|
| 870 | - public static function generate_invoice_sender_part() |
|
| 871 | - { |
|
| 872 | - $output = ''; |
|
| 873 | - $company = get_option('wpshop_company_info', array()); |
|
| 874 | - $emails = get_option('wpshop_emails', array()); |
|
| 875 | - if (!empty($company)) { |
|
| 876 | - $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 877 | - $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl'); |
|
| 878 | - foreach ($company as $company_info_key => $company_info_value) { |
|
| 879 | - switch ($company_info_key) { |
|
| 880 | - case 'company_rcs': |
|
| 881 | - $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 882 | - break; |
|
| 883 | - case 'company_capital': |
|
| 884 | - $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 885 | - break; |
|
| 886 | - case 'company_siren': |
|
| 887 | - $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 888 | - break; |
|
| 889 | - case 'company_siret': |
|
| 890 | - $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 891 | - break; |
|
| 892 | - case 'company_tva_intra': |
|
| 893 | - $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 894 | - break; |
|
| 895 | - case 'company_legal_statut': |
|
| 896 | - $array_state_compagny = wpshop_company_options::get_legal_status(); |
|
| 897 | - $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop'); |
|
| 898 | - break; |
|
| 899 | - default: |
|
| 900 | - $data = $company_info_value; |
|
| 901 | - break; |
|
| 902 | - } |
|
| 903 | - $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 904 | - } |
|
| 905 | - $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common'); |
|
| 906 | - } |
|
| 907 | - return $output; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Generate Receiver part template |
|
| 912 | - * @param unknown_type $order_id |
|
| 913 | - * @param unknown_type $bon_colisage |
|
| 914 | - * @return Ambigous <string, string> |
|
| 915 | - */ |
|
| 916 | - public static function generate_receiver_part($order_id, $bon_colisage = false) |
|
| 917 | - { |
|
| 918 | - $output = ''; |
|
| 919 | - $order_customer_postmeta = get_post_meta($order_id, '_order_info', true); |
|
| 920 | - $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 921 | - |
|
| 922 | - if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) { |
|
| 923 | - $address_info = $order_customer_postmeta['shipping']['address']; |
|
| 924 | - } else { |
|
| 925 | - if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) { |
|
| 926 | - $address_info = $order_customer_postmeta['billing']['address']; |
|
| 927 | - } else { |
|
| 928 | - $address_info = array(); |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - if (!empty($order_customer_postmeta) && !empty($address_info)) { |
|
| 933 | - $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY'); |
|
| 934 | - foreach ($default_address_attributes as $default_address_attribute) { |
|
| 935 | - $tpl_component[$default_address_attribute] = ''; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - foreach ($address_info as $order_customer_info_key => $order_customer_info_value) { |
|
| 939 | - $tpl_component[strtoupper($order_customer_info_key)] = ''; |
|
| 940 | - if ($order_customer_info_key == 'civility') { |
|
| 941 | - global $wpdb; |
|
| 942 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value); |
|
| 943 | - $civility = $wpdb->get_row($query); |
|
| 944 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 945 | - } else if ($order_customer_info_key == 'country') { |
|
| 946 | - foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { |
|
| 947 | - if ($order_customer_info_value == $key) { |
|
| 948 | - $tpl_component[strtoupper($order_customer_info_key)] = $value; |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - } elseif ($order_customer_info_key == 'phone') { |
|
| 952 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : ''; |
|
| 953 | - } else { |
|
| 954 | - $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : ''; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - if (empty($tpl_component['PHONE'])) { |
|
| 959 | - $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) { |
|
| 963 | - $user_info = get_userdata($order_postmeta['customer_id']); |
|
| 964 | - $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : ''; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - $output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common'); |
|
| 968 | - } |
|
| 969 | - return $output; |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * Genrate Footer invoice |
|
| 974 | - * @return Ambigous <string, string> |
|
| 975 | - */ |
|
| 976 | - public static function generate_footer_invoice() |
|
| 977 | - { |
|
| 978 | - $output = ''; |
|
| 979 | - $company = get_option('wpshop_company_info', array()); |
|
| 980 | - $emails = get_option('wpshop_emails', array()); |
|
| 981 | - if (!empty($company)) { |
|
| 982 | - $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 983 | - $tpl_component['COMPANY_WEBSITE'] = site_url(); |
|
| 984 | - foreach ($company as $company_info_key => $company_info_value) { |
|
| 985 | - |
|
| 986 | - switch ($company_info_key) { |
|
| 987 | - case 'company_rcs': |
|
| 988 | - $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 989 | - break; |
|
| 990 | - case 'company_capital': |
|
| 991 | - $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 992 | - break; |
|
| 993 | - case 'company_siren': |
|
| 994 | - $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 995 | - break; |
|
| 996 | - case 'company_siret': |
|
| 997 | - $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 998 | - break; |
|
| 999 | - case 'company_tva_intra': |
|
| 1000 | - $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1001 | - break; |
|
| 1002 | - default: |
|
| 1003 | - $data = $company_info_value; |
|
| 1004 | - break; |
|
| 1005 | - } |
|
| 1006 | - $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 1007 | - } |
|
| 1008 | - $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); |
|
| 1009 | - } |
|
| 1010 | - return $output; |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * Check product price |
|
| 1015 | - * @param float $price_ht |
|
| 1016 | - * @param float $price_ati |
|
| 1017 | - * @param float $tva_amount |
|
| 1018 | - * @param float $tva_rate |
|
| 1019 | - * @param id $product_id |
|
| 1020 | - * @param string $invoice_ref |
|
| 1021 | - */ |
|
| 1022 | - public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id) |
|
| 1023 | - { |
|
| 1024 | - $checking = true; |
|
| 1025 | - $error_percent = 1; |
|
| 1026 | - |
|
| 1027 | - /** Check VAT Amount **/ |
|
| 1028 | - $formatted_tva_amount = number_format($tva_amount, 2, '.', ''); |
|
| 1029 | - $formatted_price_ht = number_format($price_ht, 2, '.', ''); |
|
| 1030 | - $formatted_price_ati = number_format($price_ati, 2, '.', ''); |
|
| 1031 | - $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100)); |
|
| 1032 | - $unformatted = $formatted_price_ati - $calculated_price_excluding_tax; |
|
| 1033 | - $checked_tva_amount = number_format($unformatted, 2, '.', ''); |
|
| 1034 | - |
|
| 1035 | - if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) { |
|
| 1036 | - $error_infos = array(); |
|
| 1037 | - $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1038 | - $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1039 | - $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1040 | - |
|
| 1041 | - $error_infos['corrected_data'] = $checked_tva_amount; |
|
| 1042 | - self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos); |
|
| 1043 | - $checking = false; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** Check price ati **/ |
|
| 1047 | - $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100)); |
|
| 1048 | - if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) { |
|
| 1049 | - self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id); |
|
| 1050 | - $checking = false; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - return $checking; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Alert administrator when have invoice error |
|
| 1058 | - * @param string $invoice_ref |
|
| 1059 | - * @param string $object |
|
| 1060 | - * @param unknown_type $product_id |
|
| 1061 | - */ |
|
| 1062 | - public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array()) |
|
| 1063 | - { |
|
| 1064 | - $wpshop_email_option = get_option('wpshop_emails'); |
|
| 1065 | - if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) { |
|
| 1066 | - $headers = "MIME-Version: 1.0\r\n"; |
|
| 1067 | - $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
|
| 1068 | - $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n"; |
|
| 1069 | - $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>'; |
|
| 1070 | - $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>'; |
|
| 1071 | - $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>'; |
|
| 1072 | - $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>'; |
|
| 1073 | - |
|
| 1074 | - if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) { |
|
| 1075 | - $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>'; |
|
| 1076 | - foreach ($errors_infos['real_datas'] as $k => $errors_info) { |
|
| 1077 | - $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>'; |
|
| 1078 | - } |
|
| 1079 | - $message .= '</ul>'; |
|
| 1080 | - if (!empty($errors_infos['corrected_data'])) { |
|
| 1081 | - $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers); |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * Force Invoice Generation. Function called on save order custom informations action |
|
| 1091 | - * @param array $order_metadata |
|
| 1092 | - * @param array $posted_datas |
|
| 1093 | - * @return string |
|
| 1094 | - */ |
|
| 1095 | - public function force_invoice_generation_on_order($order_metadata, $posted_datas) |
|
| 1096 | - { |
|
| 1097 | - if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1098 | - $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']); |
|
| 1099 | - } |
|
| 1100 | - return $order_metadata; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - public function wpshop_quotation_payment_partial_validation($input) |
|
| 1104 | - { |
|
| 1105 | - return $input; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - public function wpshop_quotation_payment_partial() |
|
| 1109 | - { |
|
| 1110 | - $output = ''; |
|
| 1111 | - |
|
| 1112 | - $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
| 1113 | - |
|
| 1114 | - $partial_for_quotation_is_activate = false; |
|
| 1115 | - if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) { |
|
| 1116 | - $partial_for_quotation_is_activate = true; |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - $output .= ' |
|
| 356 | + // $tpl_component['INVOICE_TITLE'] = __('Bill payment', 'wpshop'); |
|
| 357 | + // $is_partial_payment = true; |
|
| 358 | + // } |
|
| 359 | + |
|
| 360 | + if ($bon_colisage) { |
|
| 361 | + $tpl_component['INVOICE_TITLE'] = __('Products List', 'wpshop'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $tpl_component['INVOICE_ORDER_INVOICE_REF'] = (!empty($invoice_ref)) ? $invoice_ref : (!empty($order_postmeta['order_invoice_ref']) ? $order_postmeta['order_invoice_ref'] : null); |
|
| 365 | + if ($bon_colisage) { |
|
| 366 | + $tpl_component['INVOICE_ORDER_INVOICE_REF'] = ''; |
|
| 367 | + } |
|
| 368 | + $tpl_component['INVOICE_ORDER_KEY_INDICATION'] = ($is_quotation) ? sprintf(__('Ref. %s', 'wpshop'), $order_postmeta['order_temporary_key']) : sprintf(__('Order n. %s', 'wpshop'), $order_postmeta['order_key']); |
|
| 369 | + $tpl_component['INVOICE_ORDER_DATE_INDICATION'] = ($is_quotation) ? sprintf(__('Quotation date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)) : sprintf(__('Order date %s', 'wpshop'), mysql2date($date_output_format, $order_postmeta['order_date'], true)); |
|
| 370 | + |
|
| 371 | + /** Validate period for Quotation **/ |
|
| 372 | + if ($is_quotation) { |
|
| 373 | + $quotation_validate_period = self::quotation_validate_period($order_postmeta['order_date']); |
|
| 374 | + } else { |
|
| 375 | + $tpl_component['INVOICE_VALIDATE_TIME'] = ''; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $tpl_component['INVOICE_VALIDATE_TIME'] = empty($tpl_component['INVOICE_VALIDATE_TIME']) ? '' : $tpl_component['INVOICE_VALIDATE_TIME']; |
|
| 379 | + |
|
| 380 | + $tpl_component['AMOUNT_INFORMATION'] = (!$bon_colisage) ? sprintf(__('Amount are shown in %s', 'wpshop'), wpshop_tools::wpshop_get_currency(true)) : ''; |
|
| 381 | + |
|
| 382 | + // Sender & receiver addresses |
|
| 383 | + $tpl_component['INVOICE_SENDER'] = self::generate_invoice_sender_part(); |
|
| 384 | + $tpl_component['INVOICE_RECEIVER'] = self::generate_receiver_part($order_id, $bon_colisage); |
|
| 385 | + |
|
| 386 | + $tpl_component['INVOICE_TRACKING'] = ''; |
|
| 387 | + $first = false; |
|
| 388 | + if (!empty($order_postmeta['order_trackingNumber'])) { |
|
| 389 | + $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingNumber']; |
|
| 390 | + $first = true; |
|
| 391 | + } |
|
| 392 | + if (!empty($order_postmeta['order_trackingLink'])) { |
|
| 393 | + if (!$first) { |
|
| 394 | + $tpl_component['INVOICE_TRACKING'] = __('Tracking : ', 'wpshop') . $order_postmeta['order_trackingLink']; |
|
| 395 | + } else { |
|
| 396 | + $tpl_component['INVOICE_TRACKING'] .= ' - ' . $order_postmeta['order_trackingLink']; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** Items Tab **/ |
|
| 401 | + $order_tva = array(); |
|
| 402 | + if ($bon_colisage) { |
|
| 403 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('bon_colisage_row_header', array(), array(), 'common'); |
|
| 404 | + } else { |
|
| 405 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header', array(), array(), 'common'); |
|
| 406 | + //if ( !$is_quotation ) { |
|
| 407 | + /** Check if products have discounts **/ |
|
| 408 | + if (!empty($order_postmeta['order_items']) && !$is_partial_payment) { |
|
| 409 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 410 | + if (!empty($item['item_global_discount_value']) || !empty($item['item_unit_discount_value'])) { |
|
| 411 | + $discounts_exists = true; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if ($discounts_exists) { |
|
| 417 | + $tpl_component['INVOICE_HEADER'] = wpshop_display::display_template_element('invoice_row_header_with_discount', array(), array(), 'common'); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + //} |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $total_discounted = 0; |
|
| 424 | + $tpl_component['INVOICE_ROWS'] = ''; |
|
| 425 | + |
|
| 426 | + if (!$is_partial_payment) { |
|
| 427 | + if (!empty($order_postmeta['order_items'])) { |
|
| 428 | + foreach ($order_postmeta['order_items'] as $item_id => $item) { |
|
| 429 | + $sub_tpl_component = array(); |
|
| 430 | + $count_products += $item['item_qty']; |
|
| 431 | + $barcode = get_post_meta($item['item_id'], '_barcode', true); |
|
| 432 | + if (empty($barcode)) { |
|
| 433 | + $product_metadata = get_post_meta($item['item_id'], '_wpshop_product_metadata', true); |
|
| 434 | + $barcode = (!empty($product_metadata) && !empty($product_metadata['barcode'])) ? $product_metadata['barcode'] : ''; |
|
| 435 | + |
|
| 436 | + if (empty($barcode)) { |
|
| 437 | + $product_entity = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 438 | + $att_def = wpshop_attributes::getElement('barcode', '"valid"', 'code'); |
|
| 439 | + $query = $wpdb->prepare('SELECT value FROM ' . $wpdb->prefix . 'wpshop__attribute_value_' . $att_def->data_type . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d AND value != ""', $product_entity, $att_def->id, $item['item_id']); |
|
| 440 | + $barcode = $wpdb->get_var($query); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + $sub_tpl_component['INVOICE_ROW_ITEM_BARCODE'] = (!empty($barcode)) ? $barcode : '-'; |
|
| 444 | + |
|
| 445 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = (!empty($barcode)) ? $barcode : $item['item_ref']; |
|
| 446 | + |
|
| 447 | + /** Item name **/ |
|
| 448 | + $is_variation = false; |
|
| 449 | + if (get_post_type($item['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 450 | + $is_variation = true; |
|
| 451 | + $parent_def = wpshop_products::get_parent_variation($item['item_id']); |
|
| 452 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 453 | + $parent_post = $parent_def['parent_post']; |
|
| 454 | + $item_parent_id = $parent_post->ID; |
|
| 455 | + $item_title = $parent_post->post_title; |
|
| 456 | + } |
|
| 457 | + } else { |
|
| 458 | + $item_title = $item['item_name']; |
|
| 459 | + } |
|
| 460 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = $item_title; |
|
| 461 | + /** Get attribute order for current product */ |
|
| 462 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($item['item_id'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 463 | + $output_order = array(); |
|
| 464 | + if (count($product_attribute_order_detail) > 0 && is_array($product_attribute_order_detail)) { |
|
| 465 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 466 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 467 | + if (!empty($attribute_def->code)) { |
|
| 468 | + $output_order[$attribute_def->code] = $position; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($item['item_meta'], $output_order, 'invoice_print', 'common'); |
|
| 475 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 476 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] = ''; |
|
| 477 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 478 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= $attribute_variation_to_output; |
|
| 479 | + } |
|
| 480 | + $post_content = get_post_field('post_content', $item['item_id']); |
|
| 481 | + if ( /*get_post_status( $item['item_id'] ) == 'free_product' &&*/!empty($post_content) && false) { |
|
| 482 | + if (!empty($detail_tpl_component['CART_PRODUCT_MORE_INFO'])) { |
|
| 483 | + //$detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<br>'; |
|
| 484 | + } |
|
| 485 | + $detail_tpl_component['CART_PRODUCT_MORE_INFO'] .= '<span id="wpshop_cart_description_line">' . nl2br(get_post_field('post_content', $item['item_id'])) . '</span>'; |
|
| 486 | + } |
|
| 487 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = !empty($detail_tpl_component['CART_PRODUCT_MORE_INFO']) ? wpshop_display::display_template_element('invoice_row_item_detail', $detail_tpl_component, array(), 'common') : ''; |
|
| 488 | + unset($detail_tpl_component); |
|
| 489 | + |
|
| 490 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = $item['item_qty']; |
|
| 491 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_TTC'] = ((!empty($item['item_pu_ttc_before_discount'])) ? number_format($item['item_pu_ttc_before_discount'], 2, '.', '') : number_format($item['item_pu_ttc'], 2, '.', '')); |
|
| 492 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = ((!empty($item['item_pu_ht_before_discount'])) ? number_format($item['item_pu_ht_before_discount'], 2, '.', '') : number_format($item['item_pu_ht'], 2, '.', '')); |
|
| 493 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = (!empty($item['item_discount_value'])) ? number_format($item['item_discount_value'], 2, '.', '') : number_format(0, 2, '.', ''); |
|
| 494 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format(($item['item_pu_ht'] * $item['item_qty']), 2, '.', ''); |
|
| 495 | + /** TVA **/ |
|
| 496 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format($item['item_tva_total_amount'], 2, '.', ''); |
|
| 497 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = $item['item_tva_rate']; |
|
| 498 | + |
|
| 499 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($item['item_total_ttc'], 2, '.', ''); |
|
| 500 | + |
|
| 501 | + /** Checking Rate amount **/ |
|
| 502 | + if (!$bon_colisage) { |
|
| 503 | + $checking = self::check_product_price($item['item_total_ht'], $item['item_total_ttc'], $item['item_tva_total_amount'], $item['item_tva_rate'], $item['item_id'], $invoice_ref, $order_id); |
|
| 504 | + if (!$checking) { |
|
| 505 | + return __('Invoice cannot be generate because an error was found. The website administrator has been warned.', 'wpshop'); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($bon_colisage) { |
|
| 510 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('bon_colisage_row', $sub_tpl_component, array(), 'common'); |
|
| 511 | + } else { |
|
| 512 | + if ($discounts_exists) { |
|
| 513 | + $discounted_total_per_item = $item['item_total_ht']; |
|
| 514 | + /** Unit Discount **/ |
|
| 515 | + if (!empty($item['item_unit_discount_amount']) && !empty($item['item_unit_discount_value'])) { |
|
| 516 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format($item['item_unit_discount_amount'], 2, '.', ''); |
|
| 517 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format($item['item_unit_discount_value'], 2, '.', ''); |
|
| 518 | + $discounted_total_per_item = $discounted_total_per_item - $item['item_unit_discount_amount']; |
|
| 519 | + } else { |
|
| 520 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 521 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** Global Discount **/ |
|
| 525 | + if (!empty($item['item_global_discount_amount']) && !empty($item['item_global_discount_value'])) { |
|
| 526 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format($item['item_global_discount_amount'], 2, '.', ''); |
|
| 527 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format($item['item_global_discount_value'], 2, '.', ''); |
|
| 528 | + $discounted_total_per_item = $discounted_total_per_item - $item['item_global_discount_amount']; |
|
| 529 | + } else { |
|
| 530 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 531 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $total_discounted += $discounted_total_per_item; |
|
| 535 | + /** Total HT Discounted **/ |
|
| 536 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = number_format($discounted_total_per_item, 2, '.', ''); |
|
| 537 | + |
|
| 538 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 539 | + } else { |
|
| 540 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + unset($sub_tpl_component); |
|
| 544 | + |
|
| 545 | + /** Check TVA **/ |
|
| 546 | + if (empty($order_tva[$item['item_tva_rate']])) { |
|
| 547 | + $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; |
|
| 548 | + } else { |
|
| 549 | + $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** Display Partials payments **/ |
|
| 556 | + $total_partial_payment = 0; |
|
| 557 | + $last_payment = 0; |
|
| 558 | + $order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : ''; |
|
| 559 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 560 | + foreach ($order_postmeta['order_payment']['received'] as $received_payment) { |
|
| 561 | + if (!empty($received_payment['invoice_ref']) && $received_payment['invoice_ref'] != $order_invoice_ref) { |
|
| 562 | + if (intval(substr($received_payment['invoice_ref'], 2)) == intval(substr($tpl_component['INVOICE_ORDER_INVOICE_REF'], 2))) { |
|
| 563 | + $sub_tpl_component = array(); |
|
| 564 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 565 | + |
|
| 566 | + /** Item name **/ |
|
| 567 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference']); |
|
| 568 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 569 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 570 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 571 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 572 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 573 | + |
|
| 574 | + /** TVA **/ |
|
| 575 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 576 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 577 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 578 | + |
|
| 579 | + if ($discounts_exists) { |
|
| 580 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNTED_HT_TOTAL'] = '-' . number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 581 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 582 | + $sub_tpl_component['INVOICE_ROW_ITEM_UNIT_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 583 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 584 | + $sub_tpl_component['INVOICE_ROW_ITEM_GLOBAL_DISCOUNT_VALUE'] = number_format(0, 2, '.', ''); |
|
| 585 | + |
|
| 586 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row_with_discount', $sub_tpl_component, array(), 'common'); |
|
| 587 | + } else { |
|
| 588 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + unset($sub_tpl_component); |
|
| 593 | + $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 594 | + } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) { |
|
| 595 | + $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + } else { |
|
| 601 | + /** Display Partials payments **/ |
|
| 602 | + $total_partial_payment = 0; |
|
| 603 | + $last_payment = 0; |
|
| 604 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received']) && !$bon_colisage) { |
|
| 605 | + foreach ($order_postmeta['order_payment']['received'] as $key => $received_payment) { |
|
| 606 | + if (!empty($received_payment['invoice_ref']) && !empty($invoice_ref) && $received_payment['invoice_ref'] == $invoice_ref) { |
|
| 607 | + $sub_tpl_component = array(); |
|
| 608 | + $sub_tpl_component['INVOICE_ROW_ITEM_REF'] = $received_payment['invoice_ref']; |
|
| 609 | + /** Item name **/ |
|
| 610 | + $sub_tpl_component['INVOICE_ROW_ITEM_NAME'] = sprintf(__('Partial payment %4$d on order %1$s', 'wpshop'), $order_postmeta['order_key'], __($received_payment['method'], 'wpshop'), $received_payment['payment_reference'], $key + 1); |
|
| 611 | + $sub_tpl_component['INVOICE_ROW_ITEM_DETAIL'] = ''; |
|
| 612 | + $sub_tpl_component['INVOICE_ROW_ITEM_QTY'] = 1; |
|
| 613 | + $sub_tpl_component['INVOICE_ROW_ITEM_PU_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 614 | + $sub_tpl_component['INVOICE_ROW_ITEM_DISCOUNT_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 615 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_HT'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 616 | + /** TVA **/ |
|
| 617 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_TOTAL_AMOUNT'] = number_format(0, 2, '.', ''); |
|
| 618 | + $sub_tpl_component['INVOICE_ROW_ITEM_TVA_RATE'] = 0; |
|
| 619 | + $sub_tpl_component['INVOICE_ROW_ITEM_TOTAL_TTC'] = number_format($received_payment['received_amount'], 2, '.', ''); |
|
| 620 | + $tpl_component['INVOICE_ROWS'] .= wpshop_display::display_template_element('invoice_row', $sub_tpl_component, array(), 'common'); |
|
| 621 | + unset($sub_tpl_component); |
|
| 622 | + $total_partial_payment += $received_payment['received_amount']; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** Summary of order **/ |
|
| 629 | + $summary_tpl_component = array(); |
|
| 630 | + $tpl_component['INVOICE_SUMMARY_PART'] = $summary_tpl_component['INVOICE_SUMMARY_TAXES'] = ''; |
|
| 631 | + if (!$bon_colisage) { |
|
| 632 | + if (!empty($order_tva)) { |
|
| 633 | + foreach ($order_tva as $tax_rate => $tax_amount) { |
|
| 634 | + if ($tax_amount > 0) { |
|
| 635 | + $tax_rate = (!empty($tax_rate) && $tax_rate == 'VAT_shipping_cost') ? __('on Shipping cost', 'wpshop') . ' ' . WPSHOP_VAT_ON_SHIPPING_COST : $tax_rate; |
|
| 636 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 637 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 638 | + $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 639 | + unset($sub_tpl_component); |
|
| 640 | + } elseif ($is_partial_payment) { |
|
| 641 | + $tax_rate = 0; |
|
| 642 | + $tax_amount = number_format(0, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 643 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = sprintf(__('Total taxes amount %1$s', 'wpshop'), $tax_rate . '%'); |
|
| 644 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = wpshop_display::format_field_output('wpshop_product_price', $tax_amount) . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 645 | + $summary_tpl_component['INVOICE_SUMMARY_TAXES'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 646 | + unset($sub_tpl_component); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** If Discount Exist **/ |
|
| 652 | + // Checking Discounts on order |
|
| 653 | + if (!empty($order_postmeta['order_discount_type']) && $order_postmeta['order_discount_value']) { |
|
| 654 | + $discounts_exists = true; |
|
| 655 | + // Calcul discount on Order |
|
| 656 | + switch ($order_postmeta['order_discount_type']) { |
|
| 657 | + case 'amount': |
|
| 658 | + $total_discounted += number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', ''); |
|
| 659 | + break; |
|
| 660 | + case 'percent': |
|
| 661 | + $total_discounted += number_format($order_postmeta['order_grand_total_before_discount'], 2, '.', '') * (number_format(str_replace(',', '.', $order_postmeta['order_discount_value']), 2, '.', '') / 100); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + if (!empty($total_discounted) && $discounts_exists) { |
|
| 666 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Discounted Total', 'wpshop'); |
|
| 667 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = number_format($total_discounted, 2, '.', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 668 | + $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 669 | + unset($sub_tpl_component); |
|
| 670 | + } else { |
|
| 671 | + $summary_tpl_component['INVOICE_SUMMARY_TOTAL_DISCOUNTED'] = ''; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + $shipping_cost = 0; |
|
| 675 | + if (!$is_partial_payment) { |
|
| 676 | + if (!empty($order_postmeta['order_shipping_cost'])) { |
|
| 677 | + $shipping_cost = $order_postmeta['order_shipping_cost']; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + $price_piloting = get_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 681 | + $shipping_taxes = 'HT' == $price_piloting ? (WPSHOP_VAT_ON_SHIPPING_COST / 100) * $shipping_cost : $shipping_cost - ($shipping_cost / (1 + WPSHOP_VAT_ON_SHIPPING_COST / 100)); |
|
| 682 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = number_format($shipping_cost, 2, ',', ''); |
|
| 683 | + $summary_tpl_component['INVOICE_ORDER_SHIPPING_COST_TAXES'] = number_format($shipping_taxes, 2, ',', ''); |
|
| 684 | + //$summary_tpl_component['INVOICE_ORDER_SHIPPING_COST'] = ( $is_partial_payment ) ? number_format( 0, 2, ',', '') : number_format( ( (!empty($order_postmeta['order_shipping_cost']) ) ? $order_postmeta['order_shipping_cost'] : 0 ), 2, ',', '' ); |
|
| 685 | + |
|
| 686 | + $summary_tpl_component['INVOICE_ORDER_GRAND_TOTAL'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_grand_total'], 2, ',', ''); // - $total_partial_payment , 2, ',', '' ); |
|
| 687 | + $summary_tpl_component['INVOICE_ORDER_TOTAL_HT'] = ($is_partial_payment) ? number_format(0, 2, ',', '') : number_format($order_postmeta['order_total_ht'], 2, ',', ''); |
|
| 688 | + |
|
| 689 | + $summary_tpl_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 690 | + |
|
| 691 | + $total_payment = 0; |
|
| 692 | + |
|
| 693 | + /** Amount paid **/ |
|
| 694 | + if (empty($order_postmeta['order_invoice_ref'])) { |
|
| 695 | + foreach ($order_postmeta['order_payment']['received'] as $key => $value) { |
|
| 696 | + if (!empty($value['invoice_ref']) && $value['invoice_ref'] === $tpl_component['INVOICE_ORDER_INVOICE_REF']) { |
|
| 697 | + $total_payment = number_format($value['received_amount'], 2, ',', ''); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + } else { |
|
| 701 | + $total_payment = (($total_partial_payment + $last_payment) !== $order_postmeta['order_grand_total']) ? number_format($total_partial_payment + $last_payment, 2, ',', '') : $order_postmeta['order_grand_total']; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Amount already paid', 'wpshop'); |
|
| 705 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = (!$is_partial_payment) ? number_format($last_payment, 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : $total_payment . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 706 | + //$sub_tpl_component['SUMMARY_ROW_VALUE'] = ( $is_partial_payment ) ? number_format($total_partial_payment, 2, ',', '' ). ' ' . wpshop_tools::wpshop_get_currency() : number_format($order_postmeta['order_grand_total'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency(); |
|
| 707 | + $summary_tpl_component['INVOICE_SUMMARY_MORE'] = wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 708 | + unset($sub_tpl_component); |
|
| 709 | + |
|
| 710 | + $sub_tpl_component['SUMMARY_ROW_TITLE'] = __('Number of products', 'wpshop'); |
|
| 711 | + $sub_tpl_component['SUMMARY_ROW_VALUE'] = $count_products; |
|
| 712 | + $summary_tpl_component['INVOICE_SUMMARY_MORE'] .= wpshop_display::display_template_element('invoice_summary_row', $sub_tpl_component, array(), 'common'); |
|
| 713 | + unset($sub_tpl_component); |
|
| 714 | + |
|
| 715 | + /** If Discount Exist **/ |
|
| 716 | + if (!empty($order_postmeta['coupon_id']) && !empty($order_postmeta['order_discount_value'])) { |
|
| 717 | + $tpl_discount_component = array(); |
|
| 718 | + $tpl_discount_component['DISCOUNT_VALUE'] = ($order_postmeta['order_discount_type'] == 'percent') ? number_format($order_postmeta['order_discount_amount_total_cart'], 2, ',', '') : number_format($order_postmeta['order_discount_value'], 2, ',', ''); |
|
| 719 | + |
|
| 720 | + $tpl_discount_component['TOTAL_BEFORE_DISCOUNT'] = number_format($order_postmeta['order_grand_total_before_discount'], 2, ',', ''); |
|
| 721 | + $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = wpshop_display::display_template_element('invoice_discount_part', $tpl_discount_component, array(), 'common'); |
|
| 722 | + unset($tpl_discount_component); |
|
| 723 | + } else { |
|
| 724 | + $summary_tpl_component['INVOICE_ORDER_DISCOUNT'] = ''; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + $summary_tpl_component['PRICE_PILOTING'] = 'HT' == $price_piloting ? __('ET', 'wpshop') : __('ATI', 'wpshop'); |
|
| 728 | + |
|
| 729 | + $tpl_component['INVOICE_SUMMARY_PART'] = wpshop_display::display_template_element('invoice_summary_part', $summary_tpl_component, array(), 'common'); |
|
| 730 | + unset($summary_tpl_component); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** IBAN Include on quotation **/ |
|
| 734 | + if ($is_quotation) { |
|
| 735 | + /** If admin want to include his IBAN to quotation */ |
|
| 736 | + $iban_options = get_option('wpshop_paymentMethod_options'); |
|
| 737 | + $payment_options = get_option('wps_payment_mode'); |
|
| 738 | + if (!empty($payment_options) && !empty($payment_options['mode']) && !empty($payment_options['mode']['banktransfer']) && !empty($payment_options['mode']['banktransfer']['active']) && $payment_options['mode']['banktransfer']['active'] == 'on') { |
|
| 739 | + if (!empty($iban_options) && !empty($iban_options['banktransfer']) /*&& !empty($iban_options['banktransfer']['add_in_quotation'])*/) { |
|
| 740 | + $tpl_component['IBAN_INFOS'] = __('Payment by Bank Transfer on this bank account', 'wpshop') . ' : <br/>'; |
|
| 741 | + $tpl_component['IBAN_INFOS'] .= __('Bank name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bank_name'])) ? $iban_options['banktransfer']['bank_name'] : '') . '<br/>'; |
|
| 742 | + $tpl_component['IBAN_INFOS'] .= __('IBAN', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['iban'])) ? $iban_options['banktransfer']['iban'] : '') . '<br/>'; |
|
| 743 | + $tpl_component['IBAN_INFOS'] .= __('BIC/SWIFT', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['bic'])) ? $iban_options['banktransfer']['bic'] : '') . '<br/>'; |
|
| 744 | + $tpl_component['IBAN_INFOS'] .= __('Account owner name', 'wpshop') . ' : ' . ((!empty($iban_options['banktransfer']['accountowner'])) ? $iban_options['banktransfer']['accountowner'] : '') . '<br/>'; |
|
| 745 | + } |
|
| 746 | + } else { |
|
| 747 | + $tpl_component['IBAN_INFOS'] = ''; |
|
| 748 | + } |
|
| 749 | + } else { |
|
| 750 | + $tpl_component['IBAN_INFOS'] = ''; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + /** Received payements **/ |
|
| 754 | + if (!$is_partial_payment && !$bon_colisage && !empty($order_postmeta['order_invoice_ref'])) { |
|
| 755 | + $tpl_component['RECEIVED_PAYMENT'] = self::generate_received_payment_part($order_id); |
|
| 756 | + } else { |
|
| 757 | + $tpl_component['RECEIVED_PAYMENT'] = ''; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** Invoice footer **/ |
|
| 761 | + $tpl_component['INVOICE_FOOTER'] = self::generate_footer_invoice(); |
|
| 762 | + |
|
| 763 | + $output = wpshop_display::display_template_element('invoice_page_content', $tpl_component, array(), 'common'); |
|
| 764 | + } else { |
|
| 765 | + $output = __('No order information has been found', 'wpshop'); |
|
| 766 | + } |
|
| 767 | + } else { |
|
| 768 | + $output = __('You requested a page that does not exist anymore. Please verify your request or ask the site administrator', 'wpshop'); |
|
| 769 | + } |
|
| 770 | + return $output; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Return the payment list part |
|
| 775 | + * @param integer $order_id |
|
| 776 | + * @return string |
|
| 777 | + */ |
|
| 778 | + public static function generate_received_payment_part($order_id) |
|
| 779 | + { |
|
| 780 | + $date_ouput_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 781 | + $output = ''; |
|
| 782 | + $tpl_component = array(); |
|
| 783 | + $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] = ''; |
|
| 784 | + if (!empty($order_id)) { |
|
| 785 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 786 | + if (!empty($order_postmeta['order_payment']) && !empty($order_postmeta['order_payment']['received'])) { |
|
| 787 | + $wps_payment_option = get_option('wps_payment_mode'); |
|
| 788 | + foreach ($order_postmeta['order_payment']['received'] as $payment) { |
|
| 789 | + if (!empty($payment) && !in_array($payment['method'], array('quotation'), true) && !empty($payment['received_amount'])) { |
|
| 790 | + $sub_tpl_component = array(); |
|
| 791 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_RECEIVED_AMOUNT'] = (!empty($payment['received_amount'])) ? number_format($payment['received_amount'], 2, ',', '') . ' ' . wpshop_tools::wpshop_get_currency() : 0; |
|
| 792 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_DATE'] = (!empty($payment['date'])) ? mysql2date($date_ouput_format, $payment['date'], true) : ''; |
|
| 793 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_METHOD'] = ((!empty($payment['method']) && is_array($wps_payment_option) && array_key_exists(strtolower($payment['method']), $wps_payment_option['mode']) && !empty($wps_payment_option['mode'][strtolower($payment['method'])]['name'])) ? $wps_payment_option['mode'][strtolower($payment['method'])]['name'] : (!empty($payment['method']) ? __($payment['method'], 'wpshop') : '')); |
|
| 794 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_PAYMENT_REFERENCE'] = (!empty($payment['payment_reference'])) ? $payment['payment_reference'] : ''; |
|
| 795 | + $sub_tpl_component['INVOICE_RECEIVED_PAYMENT_INVOICE_REF'] = (!empty($payment['invoice_ref'])) ? $payment['invoice_ref'] : ''; |
|
| 796 | + $tpl_component['ORDER_RECEIVED_PAYMENT_ROWS'] .= wpshop_display::display_template_element('received_payment_row', $sub_tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $output = wpshop_display::display_template_element('received_payment', $tpl_component, array('type' => 'invoice_line', 'id' => 'partial_payment'), 'common'); |
|
| 801 | + unset($tpl_component); |
|
| 802 | + } |
|
| 803 | + return $output; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** Return the validity period of a quotation **/ |
|
| 807 | + public static function quotation_validate_period($quotation_date) |
|
| 808 | + { |
|
| 809 | + $quotation_options = get_option('wpshop_quotation_validate_time'); |
|
| 810 | + if (!empty($quotation_options) && !empty($quotation_options['number']) && !empty($quotation_options['time_type'])) { |
|
| 811 | + $timestamp_quotation = strtotime($quotation_date); |
|
| 812 | + $timestamp_validity_date_quotation = 0; |
|
| 813 | + $query = ''; |
|
| 814 | + $date = ''; |
|
| 815 | + global $wpdb; |
|
| 816 | + switch ($quotation_options['time_type']) { |
|
| 817 | + case 'day': |
|
| 818 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " DAY) "); |
|
| 819 | + break; |
|
| 820 | + case 'month': |
|
| 821 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " MONTH) "); |
|
| 822 | + break; |
|
| 823 | + case 'year': |
|
| 824 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL " . $quotation_options['number'] . " YEAR) "); |
|
| 825 | + break; |
|
| 826 | + default: |
|
| 827 | + $query = $wpdb->prepare("SELECT DATE_ADD('" . $quotation_date . "', INTERVAL 15 DAY) "); |
|
| 828 | + break; |
|
| 829 | + } |
|
| 830 | + if ($query != null) { |
|
| 831 | + $date = mysql2date('d F Y', $wpdb->get_var($query), true); |
|
| 832 | + } |
|
| 833 | + return sprintf(__('Quotation validity date %s', 'wpshop'), $date); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Generate HTML invoice to be sended by email |
|
| 839 | + * @param integer $order_id |
|
| 840 | + * @param string $invoice_ref |
|
| 841 | + * @return string |
|
| 842 | + */ |
|
| 843 | + public static function generate_invoice_for_email($order_id, $invoice_ref = '') |
|
| 844 | + { |
|
| 845 | + /** Generate the PDF file for the invoice **/ |
|
| 846 | + $is_ok = false; |
|
| 847 | + if (!empty($invoice_ref)) { |
|
| 848 | + require_once WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'; |
|
| 849 | + try { |
|
| 850 | + $html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref); |
|
| 851 | + $html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>'; |
|
| 852 | + $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
|
| 853 | + |
|
| 854 | + $html2pdf->setDefaultFont('Arial'); |
|
| 855 | + $html2pdf->writeHTML($html_content); |
|
| 856 | + $html2pdf->Output(WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf', 'F'); |
|
| 857 | + $is_ok = true; |
|
| 858 | + } catch (HTML2PDF_exception $e) { |
|
| 859 | + echo $e; |
|
| 860 | + exit; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + return ($is_ok) ? WPSHOP_UPLOAD_DIR . $invoice_ref . '.pdf' : ''; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * Generate Sender part invoice template |
|
| 868 | + * @return Ambigous <string, string> |
|
| 869 | + */ |
|
| 870 | + public static function generate_invoice_sender_part() |
|
| 871 | + { |
|
| 872 | + $output = ''; |
|
| 873 | + $company = get_option('wpshop_company_info', array()); |
|
| 874 | + $emails = get_option('wpshop_emails', array()); |
|
| 875 | + if (!empty($company)) { |
|
| 876 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 877 | + $tpl_component['COMPANY_WEBSITE'] = get_option('siteurl'); |
|
| 878 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 879 | + switch ($company_info_key) { |
|
| 880 | + case 'company_rcs': |
|
| 881 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 882 | + break; |
|
| 883 | + case 'company_capital': |
|
| 884 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 885 | + break; |
|
| 886 | + case 'company_siren': |
|
| 887 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 888 | + break; |
|
| 889 | + case 'company_siret': |
|
| 890 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 891 | + break; |
|
| 892 | + case 'company_tva_intra': |
|
| 893 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 894 | + break; |
|
| 895 | + case 'company_legal_statut': |
|
| 896 | + $array_state_compagny = wpshop_company_options::get_legal_status(); |
|
| 897 | + $data = (!empty($array_state_compagny) && !empty($array_state_compagny[$company_info_value])) ? $array_state_compagny[$company_info_value] : __('Auto-Entrepreneur', 'wpshop'); |
|
| 898 | + break; |
|
| 899 | + default: |
|
| 900 | + $data = $company_info_value; |
|
| 901 | + break; |
|
| 902 | + } |
|
| 903 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 904 | + } |
|
| 905 | + $output = wpshop_display::display_template_element('invoice_sender_formatted_address', $tpl_component, array(), 'common'); |
|
| 906 | + } |
|
| 907 | + return $output; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Generate Receiver part template |
|
| 912 | + * @param unknown_type $order_id |
|
| 913 | + * @param unknown_type $bon_colisage |
|
| 914 | + * @return Ambigous <string, string> |
|
| 915 | + */ |
|
| 916 | + public static function generate_receiver_part($order_id, $bon_colisage = false) |
|
| 917 | + { |
|
| 918 | + $output = ''; |
|
| 919 | + $order_customer_postmeta = get_post_meta($order_id, '_order_info', true); |
|
| 920 | + $order_postmeta = get_post_meta($order_id, '_order_postmeta', true); |
|
| 921 | + |
|
| 922 | + if ($bon_colisage && !empty($order_customer_postmeta['shipping']) && !empty($order_customer_postmeta['shipping']['address']) && is_array($order_customer_postmeta['shipping']['address'])) { |
|
| 923 | + $address_info = $order_customer_postmeta['shipping']['address']; |
|
| 924 | + } else { |
|
| 925 | + if (!empty($order_customer_postmeta['billing']) && !empty($order_customer_postmeta['billing']['address']) && is_array($order_customer_postmeta['billing']['address'])) { |
|
| 926 | + $address_info = $order_customer_postmeta['billing']['address']; |
|
| 927 | + } else { |
|
| 928 | + $address_info = array(); |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + if (!empty($order_customer_postmeta) && !empty($address_info)) { |
|
| 933 | + $default_address_attributes = array('CIVILITY', 'ADDRESS_LAST_NAME', 'ADDRESS_FIRST_NAME', 'ADDRESS', 'POSTCODE', 'CITY', 'STATE', 'COUNTRY', 'PHONE', 'ADDRESS_USER_EMAIL', 'COMPANY'); |
|
| 934 | + foreach ($default_address_attributes as $default_address_attribute) { |
|
| 935 | + $tpl_component[$default_address_attribute] = ''; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + foreach ($address_info as $order_customer_info_key => $order_customer_info_value) { |
|
| 939 | + $tpl_component[strtoupper($order_customer_info_key)] = ''; |
|
| 940 | + if ($order_customer_info_key == 'civility') { |
|
| 941 | + global $wpdb; |
|
| 942 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id= %d', $order_customer_info_value); |
|
| 943 | + $civility = $wpdb->get_row($query); |
|
| 944 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($civility)) ? (!empty($civility->label)) ? $civility->label : __($civility->value, 'wpshop') : ''; |
|
| 945 | + } else if ($order_customer_info_key == 'country') { |
|
| 946 | + foreach (unserialize(WPSHOP_COUNTRY_LIST) as $key => $value) { |
|
| 947 | + if ($order_customer_info_value == $key) { |
|
| 948 | + $tpl_component[strtoupper($order_customer_info_key)] = $value; |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + } elseif ($order_customer_info_key == 'phone') { |
|
| 952 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? __('Phone', 'wpshop') . ' : ' . $order_customer_info_value : ''; |
|
| 953 | + } else { |
|
| 954 | + $tpl_component[strtoupper($order_customer_info_key)] = (!empty($order_customer_info_value)) ? $order_customer_info_value : ''; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + if (empty($tpl_component['PHONE'])) { |
|
| 959 | + $tpl_component['PHONE'] = (!empty($order_customer_postmeta['billing']['address']['phone'])) ? __('Phone', 'wpshop') . ' : ' . $order_customer_postmeta['billing']['address']['phone'] : ''; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + if (empty($tpl_component['ADDRESS_USER_EMAIL']) || (empty($tpl_component['ADDRESS_USER_EMAIL']) && $bon_colisage)) { |
|
| 963 | + $user_info = get_userdata($order_postmeta['customer_id']); |
|
| 964 | + $tpl_component['ADDRESS_USER_EMAIL'] = (!empty($user_info) && !empty($user_info->user_email)) ? $user_info->user_email : ''; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + $output = wpshop_display::display_template_element('invoice_receiver_formatted_address', $tpl_component, array(), 'common'); |
|
| 968 | + } |
|
| 969 | + return $output; |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * Genrate Footer invoice |
|
| 974 | + * @return Ambigous <string, string> |
|
| 975 | + */ |
|
| 976 | + public static function generate_footer_invoice() |
|
| 977 | + { |
|
| 978 | + $output = ''; |
|
| 979 | + $company = get_option('wpshop_company_info', array()); |
|
| 980 | + $emails = get_option('wpshop_emails', array()); |
|
| 981 | + if (!empty($company)) { |
|
| 982 | + $tpl_component['COMPANY_EMAIL'] = (!empty($emails) && !empty($emails['contact_email'])) ? $emails['contact_email'] : ''; |
|
| 983 | + $tpl_component['COMPANY_WEBSITE'] = site_url(); |
|
| 984 | + foreach ($company as $company_info_key => $company_info_value) { |
|
| 985 | + |
|
| 986 | + switch ($company_info_key) { |
|
| 987 | + case 'company_rcs': |
|
| 988 | + $data = (!empty($company_info_value)) ? __('RCS', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 989 | + break; |
|
| 990 | + case 'company_capital': |
|
| 991 | + $data = (!empty($company_info_value)) ? __('Capital', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 992 | + break; |
|
| 993 | + case 'company_siren': |
|
| 994 | + $data = (!empty($company_info_value)) ? __('SIREN', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 995 | + break; |
|
| 996 | + case 'company_siret': |
|
| 997 | + $data = (!empty($company_info_value)) ? __('SIRET', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 998 | + break; |
|
| 999 | + case 'company_tva_intra': |
|
| 1000 | + $data = (!empty($company_info_value)) ? __('TVA Intracommunautaire', 'wpshop') . ' : ' . $company_info_value : ''; |
|
| 1001 | + break; |
|
| 1002 | + default: |
|
| 1003 | + $data = $company_info_value; |
|
| 1004 | + break; |
|
| 1005 | + } |
|
| 1006 | + $tpl_component[strtoupper($company_info_key)] = $data; |
|
| 1007 | + } |
|
| 1008 | + $output = wpshop_display::display_template_element('invoice_footer', $tpl_component, array(), 'common'); |
|
| 1009 | + } |
|
| 1010 | + return $output; |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * Check product price |
|
| 1015 | + * @param float $price_ht |
|
| 1016 | + * @param float $price_ati |
|
| 1017 | + * @param float $tva_amount |
|
| 1018 | + * @param float $tva_rate |
|
| 1019 | + * @param id $product_id |
|
| 1020 | + * @param string $invoice_ref |
|
| 1021 | + */ |
|
| 1022 | + public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id) |
|
| 1023 | + { |
|
| 1024 | + $checking = true; |
|
| 1025 | + $error_percent = 1; |
|
| 1026 | + |
|
| 1027 | + /** Check VAT Amount **/ |
|
| 1028 | + $formatted_tva_amount = number_format($tva_amount, 2, '.', ''); |
|
| 1029 | + $formatted_price_ht = number_format($price_ht, 2, '.', ''); |
|
| 1030 | + $formatted_price_ati = number_format($price_ati, 2, '.', ''); |
|
| 1031 | + $calculated_price_excluding_tax = $price_ati / (1 + ($tva_rate / 100)); |
|
| 1032 | + $unformatted = $formatted_price_ati - $calculated_price_excluding_tax; |
|
| 1033 | + $checked_tva_amount = number_format($unformatted, 2, '.', ''); |
|
| 1034 | + |
|
| 1035 | + if (($checked_tva_amount < ($formatted_tva_amount / (1 + ($error_percent / 100)))) || ($checked_tva_amount > ($formatted_tva_amount * (1 + ($error_percent / 100))))) { |
|
| 1036 | + $error_infos = array(); |
|
| 1037 | + $error_infos['real_datas']['price_ati'] = $formatted_price_ati; |
|
| 1038 | + $error_infos['real_datas']['price_ht'] = $formatted_price_ht; |
|
| 1039 | + $error_infos['real_datas']['tva_amount'] = $formatted_tva_amount; |
|
| 1040 | + |
|
| 1041 | + $error_infos['corrected_data'] = $checked_tva_amount; |
|
| 1042 | + self::invoice_error_check_administrator($invoice_ref, __('VAT error', 'wpshop'), $product_id, $order_id, $error_infos); |
|
| 1043 | + $checking = false; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** Check price ati **/ |
|
| 1047 | + $checked_price_ati = $formatted_price_ht * (1 + ($tva_rate / 100)); |
|
| 1048 | + if (($checked_price_ati < ($formatted_price_ati / (1 + ($error_percent / 100)))) || ($checked_price_ati > ($formatted_price_ati * (1 + ($error_percent / 100))))) { |
|
| 1049 | + self::invoice_error_check_administrator($invoice_ref, __('ATI Price error', 'wpshop'), $product_id, $order_id); |
|
| 1050 | + $checking = false; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + return $checking; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Alert administrator when have invoice error |
|
| 1058 | + * @param string $invoice_ref |
|
| 1059 | + * @param string $object |
|
| 1060 | + * @param unknown_type $product_id |
|
| 1061 | + */ |
|
| 1062 | + public function invoice_error_check_administrator($invoice_ref, $object, $product_id, $order_id, $errors_infos = array()) |
|
| 1063 | + { |
|
| 1064 | + $wpshop_email_option = get_option('wpshop_emails'); |
|
| 1065 | + if (!empty($wpshop_email_option) && !empty($wpshop_email_option['contact_email'])) { |
|
| 1066 | + $headers = "MIME-Version: 1.0\r\n"; |
|
| 1067 | + $headers .= "Content-type: text/html; charset=UTF-8\r\n"; |
|
| 1068 | + $headers .= 'From: ' . get_bloginfo('name') . ' <' . $wpshop_email_option['noreply_email'] . '>' . "\r\n"; |
|
| 1069 | + $message = '<b>' . __('Error type', 'wpshop') . ' : </b>' . $object . '<br/>'; |
|
| 1070 | + $message .= '<b>' . __('Product', 'wpshop') . ' : </b>' . get_the_title($product_id) . '<br/>'; |
|
| 1071 | + $message .= '<b>' . __('Invoice ref', 'wpshop') . ' : </b>' . $invoice_ref . '<br/>'; |
|
| 1072 | + $message .= '<b>' . __('Order ID', 'wpshop') . ' : </b>' . $order_id . '<br/>'; |
|
| 1073 | + |
|
| 1074 | + if (!empty($errors_infos) && !empty($errors_infos['real_datas'])) { |
|
| 1075 | + $message .= '<b>' . __('Bad datas', 'wpshop') . ' :</b> <ul>'; |
|
| 1076 | + foreach ($errors_infos['real_datas'] as $k => $errors_info) { |
|
| 1077 | + $message .= '<li><b>' . $k . ' : </b>' . $errors_info . '</li>'; |
|
| 1078 | + } |
|
| 1079 | + $message .= '</ul>'; |
|
| 1080 | + if (!empty($errors_infos['corrected_data'])) { |
|
| 1081 | + $message .= '<b>' . __('Good value', 'wpshop') . ' : </b>' . $errors_infos['corrected_data']; |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + wp_mail($wpshop_email_option['contact_email'], __('Error on invoice generation', 'wpshop'), $message, $headers); |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * Force Invoice Generation. Function called on save order custom informations action |
|
| 1091 | + * @param array $order_metadata |
|
| 1092 | + * @param array $posted_datas |
|
| 1093 | + * @return string |
|
| 1094 | + */ |
|
| 1095 | + public function force_invoice_generation_on_order($order_metadata, $posted_datas) |
|
| 1096 | + { |
|
| 1097 | + if (!empty($posted_datas['action_triggered_from']) && $posted_datas['action_triggered_from'] == 'generate_invoice') { |
|
| 1098 | + $order_metadata['order_invoice_ref'] = $this->generate_invoice_number($posted_datas['post_ID']); |
|
| 1099 | + } |
|
| 1100 | + return $order_metadata; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + public function wpshop_quotation_payment_partial_validation($input) |
|
| 1104 | + { |
|
| 1105 | + return $input; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + public function wpshop_quotation_payment_partial() |
|
| 1109 | + { |
|
| 1110 | + $output = ''; |
|
| 1111 | + |
|
| 1112 | + $partial_payment_current_config = get_option('wpshop_payment_partial', array('for_quotation' => array())); |
|
| 1113 | + |
|
| 1114 | + $partial_for_quotation_is_activate = false; |
|
| 1115 | + if (!empty($partial_payment_current_config) && !empty($partial_payment_current_config['for_quotation']) && !empty($partial_payment_current_config['for_quotation']['activate'])) { |
|
| 1116 | + $partial_for_quotation_is_activate = true; |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + $output .= ' |
|
| 1120 | 1120 | <input type="checkbox" name="wpshop_payment_partial[for_quotation][activate]"' . ($partial_for_quotation_is_activate ? ' checked="checked"' : '') . ' id="wpshop_payment_partial_on_quotation_activation_state" /> <label for="wpshop_payment_partial_on_quotation_activation_state" >' . __('Activate partial command for quotations', 'wpshop') . '</label><a href="#" title="' . __('If you want that customer pay a part o f total amount of there order, check this box then fill fields below', 'wpshop') . '" class="wpshop_infobulle_marker">?</a> |
| 1121 | 1121 | <div class="wpshop_partial_payment_quotation_config_container' . ($partial_for_quotation_is_activate ? '' : ' wpshopHide') . '" id="wpshop_partial_payment_quotation_config_container" > |
| 1122 | 1122 | <div class="alignleft" > |
@@ -1132,13 +1132,13 @@ discard block |
||
| 1132 | 1132 | </div> |
| 1133 | 1133 | </div>'; |
| 1134 | 1134 | |
| 1135 | - echo $output; |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1135 | + echo $output; |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | 1138 | |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** Instanciate the module utilities if not */ |
| 1142 | 1142 | if (class_exists("wpshop_modules_billing")) { |
| 1143 | - $wpshop_modules_billing = new wpshop_modules_billing(); |
|
| 1143 | + $wpshop_modules_billing = new wpshop_modules_billing(); |
|
| 1144 | 1144 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | update_option('wpshop_billing_current_number', $billing_current_number); |
| 295 | 295 | |
| 296 | 296 | /** Create the new invoice number with all parameters viewed above */ |
| 297 | - $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string) sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 297 | + $invoice_ref = WPSHOP_BILLING_REFERENCE_PREFIX . ((string)sprintf('%0' . $number_figures . 'd', $billing_current_number)); |
|
| 298 | 298 | |
| 299 | 299 | return $invoice_ref; |
| 300 | 300 | } |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | unset($sub_tpl_component); |
| 593 | 593 | $total_partial_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
| 594 | - } else if ( !empty( $received_payment['status'] ) && 'payment_received' == $received_payment['status'] ) { |
|
| 594 | + } else if (!empty($received_payment['status']) && 'payment_received' == $received_payment['status']) { |
|
| 595 | 595 | $last_payment += (!empty($received_payment['received_amount'])) ? $received_payment['received_amount'] : 0; |
| 596 | 596 | } |
| 597 | 597 | |