Completed
Push — master ( 55b084...f77a5b )
by
unknown
11:30
created
includes/modules/billing/billing.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
         /**
867 867
          * Generate Sender part invoice template
868
-         * @return Ambigous <string, string>
868
+         * @return string <string, string>
869 869
          */
870 870
         public static function generate_invoice_sender_part()
871 871
         {
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
          * Generate Receiver part template
912 912
          * @param unknown_type $order_id
913 913
          * @param unknown_type $bon_colisage
914
-         * @return Ambigous <string, string>
914
+         * @return string <string, string>
915 915
          */
916 916
         public static function generate_receiver_part($order_id, $bon_colisage = false)
917 917
         {
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
 
972 972
         /**
973 973
          * Genrate Footer invoice
974
-         * @return Ambigous <string, string>
974
+         * @return string <string, string>
975 975
          */
976 976
         public static function generate_footer_invoice()
977 977
         {
@@ -1018,6 +1018,7 @@  discard block
 block discarded – undo
1018 1018
          * @param float $tva_rate
1019 1019
          * @param id $product_id
1020 1020
          * @param string $invoice_ref
1021
+         * @param integer $order_id
1021 1022
          */
1022 1023
         public static function check_product_price($price_ht, $price_ati, $tva_amount, $tva_rate, $product_id, $invoice_ref, $order_id)
1023 1024
         {
Please login to merge, or discard this patch.
Indentation   +1099 added lines, -1099 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('ABSPATH')) {
2
-    exit;
2
+	exit;
3 3
 }
4 4
 
5 5
 /**
@@ -13,217 +13,217 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 ('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 ('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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -294,7 +294,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
includes/modules/wps_customer/controller/wps_customer_ctr.php 4 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -310,7 +310,6 @@
 block discarded – undo
310 310
     /**
311 311
      * Add metas in user when customer is modified
312 312
      *
313
-     * @param integer $post_id
314 313
      * @param WP_Post $post
315 314
      */
316 315
     public static function save_entity_customer($customer_post_ID, $post)
Please login to merge, or discard this patch.
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('ABSPATH')) {
2
-    exit;
2
+	exit;
3 3
 }
4 4
 
5 5
 /**
@@ -10,543 +10,543 @@  discard block
 block discarded – undo
10 10
 class wps_customer_ctr
11 11
 {
12 12
 
13
-    public function __construct()
14
-    {
15
-        /**    Create customer entity type on wordpress initilisation*/
16
-        add_action('init', array($this, 'create_customer_entity'));
17
-
18
-        /**    Call style for administration    */
19
-        add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
20
-
21
-        add_action('admin_init', array($this, 'customer_action_on_plugin_init'));
22
-        add_action('admin_init', array($this, 'redirect_new_user'));
23
-        add_action('admin_menu', array($this, 'customer_action_on_menu'));
24
-
25
-        /**    When a wordpress user is created, create a customer (post type)    */
26
-        add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
27
-        add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
28
-
29
-        /** When save customer update */
30
-        add_action('save_post', array($this, 'save_entity_customer'), 10, 2);
31
-        //add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) );
32
-
33
-        /**    Add filters for customer list    */
34
-        add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
35
-        add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
36
-        add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
37
-        add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
38
-        add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
39
-
40
-        /**    Filter search for customers    */
41
-        //add_filter( 'pre_get_posts', array( $this, 'customer_search' ) );
42
-
43
-        /** Customer options for the shop */
44
-        add_action('wsphop_options', array(&$this, 'declare_options'), 8);
45
-    }
46
-
47
-    /**
48
-     * Customer options for the shop
49
-     */
50
-    public static function declare_options()
51
-    {
52
-        if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
53
-            $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
54
-            $old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
55
-
56
-            if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
57
-                && ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
58
-                /**    Add module option to wpshop general options    */
59
-                register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
60
-                add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
61
-
62
-            }
63
-        }
64
-    }
65
-
66
-    /**
67
-     * Validate Options Customer
68
-     * @param unknown_type $input
69
-     * @return unknown
70
-     */
71
-    public static function wpshop_options_validate_customers_newsleters($input)
72
-    {
73
-        return $input;
74
-    }
75
-
76
-    public static function display_newsletters_subscriptions()
77
-    {
78
-        $cart_option = get_option('wpshop_cart_option', array());
79
-        $output = '';
80
-
81
-        $input_def = array();
82
-        $input_def['name'] = '';
83
-        $input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription';
84
-        $input_def['type'] = 'checkbox';
85
-        $input_def['valueToPut'] = 'index';
86
-        $input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
87
-        $input_def['possible_value'] = 'yes';
88
-        $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
89
-
90
-        $input_def = array();
91
-        $input_def['name'] = '';
92
-        $input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription';
93
-        $input_def['type'] = 'checkbox';
94
-        $input_def['valueToPut'] = 'index';
95
-        $input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
96
-        $input_def['possible_value'] = 'yes';
97
-        $output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
98
-
99
-        echo $output;
100
-    }
101
-
102
-    /**
103
-     * Include stylesheets
104
-     */
105
-    public function admin_css()
106
-    {
107
-        wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION);
108
-        wp_enqueue_style('wpshop-modules-customer-backend-styles');
109
-    }
110
-
111
-    /**
112
-     * Return a list  of users
113
-     * @param array $customer_list_params
114
-     * @param integer $selected_user
115
-     * @param boolean $multiple
116
-     * @param boolean $disabled
117
-     * @return string
118
-     */
119
-    public function custom_user_list($customer_list_params = array('name' => 'user[customer_id]', 'id' => 'user_customer_id'), $selected_user = "", $multiple = false, $disabled = false)
120
-    {
121
-        global $wpdb;
122
-        $content_output = '';
123
-
124
-        // USERS
125
-        $wps_customer_mdl = new wps_customer_mdl();
126
-        $users = $wps_customer_mdl->getUserList();
127
-        $select_users = '';
128
-        if (!empty($users)) {
129
-            foreach ($users as $user) {
130
-                if ($user->ID != 1) {
131
-                    $lastname = get_user_meta($user->ID, 'last_name', true);
132
-                    $firstname = get_user_meta($user->ID, 'first_name', true);
133
-                    $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
134
-                    if (!empty($customer_entity_id)) {
135
-                        $company_attr = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid'));
136
-                        if (!empty($company_attr)) {
137
-                            $query = $wpdb->prepare('SELECT value  FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($company_attr->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id($user->ID));
138
-                            $company_value = $wpdb->get_var($query);
139
-                        }
140
-                    }
141
-                    ob_start();?>
13
+	public function __construct()
14
+	{
15
+		/**    Create customer entity type on wordpress initilisation*/
16
+		add_action('init', array($this, 'create_customer_entity'));
17
+
18
+		/**    Call style for administration    */
19
+		add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
20
+
21
+		add_action('admin_init', array($this, 'customer_action_on_plugin_init'));
22
+		add_action('admin_init', array($this, 'redirect_new_user'));
23
+		add_action('admin_menu', array($this, 'customer_action_on_menu'));
24
+
25
+		/**    When a wordpress user is created, create a customer (post type)    */
26
+		add_action('user_register', array($this, 'create_entity_customer_when_user_is_created'));
27
+		add_action('edit_user_profile_update', array($this, 'update_entity_customer_when_profile_user_is_update'));
28
+
29
+		/** When save customer update */
30
+		add_action('save_post', array($this, 'save_entity_customer'), 10, 2);
31
+		//add_action( 'admin_notices', array( $this, 'notice_save_post_customer_informations' ) );
32
+
33
+		/**    Add filters for customer list    */
34
+		add_filter('bulk_actions-edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, array($this, 'customer_list_table_bulk_actions'));
35
+		add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_columns', array($this, 'list_table_header'));
36
+		add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '_posts_custom_column', array($this, 'list_table_column_content'), 10, 2);
37
+		add_action('restrict_manage_posts', array(&$this, 'list_table_filters'));
38
+		add_filter('parse_query', array(&$this, 'list_table_filter_parse_query'));
39
+
40
+		/**    Filter search for customers    */
41
+		//add_filter( 'pre_get_posts', array( $this, 'customer_search' ) );
42
+
43
+		/** Customer options for the shop */
44
+		add_action('wsphop_options', array(&$this, 'declare_options'), 8);
45
+	}
46
+
47
+	/**
48
+	 * Customer options for the shop
49
+	 */
50
+	public static function declare_options()
51
+	{
52
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
53
+			$wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : '';
54
+			$old_wpshop_shop_type = !empty($_POST['old_wpshop_shop_type']) ? sanitize_text_field($_POST['old_wpshop_shop_type']) : '';
55
+
56
+			if (($wpshop_shop_type == '' || $wpshop_shop_type != 'presentation')
57
+				&& ($old_wpshop_shop_type == '' || $old_wpshop_shop_type != 'presentation')) {
58
+				/**    Add module option to wpshop general options    */
59
+				register_setting('wpshop_options', 'wpshop_cart_option', array('wps_customer_ctr', 'wpshop_options_validate_customers_newsleters'));
60
+				add_settings_field('display_newsletters_subscriptions', __('Display newsletters subscriptions', 'wpshop'), array('wps_customer_ctr', 'display_newsletters_subscriptions'), 'wpshop_cart_info', 'wpshop_cart_info');
61
+
62
+			}
63
+		}
64
+	}
65
+
66
+	/**
67
+	 * Validate Options Customer
68
+	 * @param unknown_type $input
69
+	 * @return unknown
70
+	 */
71
+	public static function wpshop_options_validate_customers_newsleters($input)
72
+	{
73
+		return $input;
74
+	}
75
+
76
+	public static function display_newsletters_subscriptions()
77
+	{
78
+		$cart_option = get_option('wpshop_cart_option', array());
79
+		$output = '';
80
+
81
+		$input_def = array();
82
+		$input_def['name'] = '';
83
+		$input_def['id'] = 'wpshop_cart_option_display_newsletter_site_subscription';
84
+		$input_def['type'] = 'checkbox';
85
+		$input_def['valueToPut'] = 'index';
86
+		$input_def['value'] = !empty($cart_option['display_newsletter']['site_subscription']) ? $cart_option['display_newsletter']['site_subscription'][0] : 'no';
87
+		$input_def['possible_value'] = 'yes';
88
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][site_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the site', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter site subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
89
+
90
+		$input_def = array();
91
+		$input_def['name'] = '';
92
+		$input_def['id'] = 'wpshop_cart_option_display_newsletter_partner_subscription';
93
+		$input_def['type'] = 'checkbox';
94
+		$input_def['valueToPut'] = 'index';
95
+		$input_def['value'] = !empty($cart_option['display_newsletter']['partner_subscription']) ? $cart_option['display_newsletter']['partner_subscription'][0] : 'no';
96
+		$input_def['possible_value'] = 'yes';
97
+		$output .= wpshop_form::check_input_type($input_def, 'wpshop_cart_option[display_newsletter][partner_subscription]') . '<label for="' . $input_def['id'] . '">' . __('Newsletters of the partners', 'wpshop') . '</label>' . '<a href="#" title="' . __('Check this box if you want display newsletter partners subscription', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>' . '<br>';
98
+
99
+		echo $output;
100
+	}
101
+
102
+	/**
103
+	 * Include stylesheets
104
+	 */
105
+	public function admin_css()
106
+	{
107
+		wp_register_style('wpshop-modules-customer-backend-styles', WPS_ACCOUNT_URL . '/' . WPS_ACCOUNT_DIR . '/assets/backend/css/backend.css', '', WPSHOP_VERSION);
108
+		wp_enqueue_style('wpshop-modules-customer-backend-styles');
109
+	}
110
+
111
+	/**
112
+	 * Return a list  of users
113
+	 * @param array $customer_list_params
114
+	 * @param integer $selected_user
115
+	 * @param boolean $multiple
116
+	 * @param boolean $disabled
117
+	 * @return string
118
+	 */
119
+	public function custom_user_list($customer_list_params = array('name' => 'user[customer_id]', 'id' => 'user_customer_id'), $selected_user = "", $multiple = false, $disabled = false)
120
+	{
121
+		global $wpdb;
122
+		$content_output = '';
123
+
124
+		// USERS
125
+		$wps_customer_mdl = new wps_customer_mdl();
126
+		$users = $wps_customer_mdl->getUserList();
127
+		$select_users = '';
128
+		if (!empty($users)) {
129
+			foreach ($users as $user) {
130
+				if ($user->ID != 1) {
131
+					$lastname = get_user_meta($user->ID, 'last_name', true);
132
+					$firstname = get_user_meta($user->ID, 'first_name', true);
133
+					$customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
134
+					if (!empty($customer_entity_id)) {
135
+						$company_attr = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE entity_id = %s AND code = %s AND status = %s', $customer_entity_id, 'company_customer', 'valid'));
136
+						if (!empty($company_attr)) {
137
+							$query = $wpdb->prepare('SELECT value  FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($company_attr->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $company_attr->id, wps_customer_ctr::get_customer_id_by_author_id($user->ID));
138
+							$company_value = $wpdb->get_var($query);
139
+						}
140
+					}
141
+					ob_start();?>
142 142
 					<option value="<?php echo $user->ID; ?>" <?php echo ((!$multiple) && ($selected_user == $user->ID)) ? ' selected="selected"' : ''; ?>>
143 143
 						<?php echo $lastname; ?> <?php echo $firstname; ?> (<?php echo $user->user_email; ?>)<?php echo isset($company_value) ? ' : ' . $company_value : ''; ?>
144 144
 					</option>
145 145
 					<?php
146 146
 $select_users .= ob_get_clean();
147
-                }
148
-            }
149
-            $content_output = '
147
+				}
148
+			}
149
+			$content_output = '
150 150
 			<select name="' . $customer_list_params['name'] . '" id="' . $customer_list_params['id'] . '" data-placeholder="' . __('Choose a customer', 'wpshop') . '" class="chosen_select"' . ($multiple ? ' multiple="multiple" ' : '') . '' . ($disabled ? ' disabled="disabled" ' : '') . '>
151 151
 				<option value="0" ></option>
152 152
 				' . $select_users . '
153 153
 			</select>';
154
-        }
155
-        return $content_output;
156
-    }
157
-
158
-    /**
159
-     * Action on plug-on action
160
-     */
161
-    public static function customer_action_on_plugin_init()
162
-    {
163
-        return;
164
-    }
165
-
166
-    /**
167
-     * Create the customer entity
168
-     */
169
-    public function create_customer_entity()
170
-    {
171
-        global $wpdb;
172
-        $query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params');
173
-        $customer_entity_definition = $wpdb->get_row($query);
174
-        $current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null;
175
-
176
-        $post_type_params = array(
177
-            'labels' => array(
178
-                'name' => __('Customers', 'wpshop'),
179
-                'singular_name' => __('Customer', 'wpshop'),
180
-                'add_new_item' => __('New customer', 'wpshop'),
181
-                'add_new' => __('New customer', 'wpshop'),
182
-                'edit_item' => __('Edit customer', 'wpshop'),
183
-                'new_item' => __('New customer', 'wpshop'),
184
-                'view_item' => __('View customer', 'wpshop'),
185
-                'search_items' => __('Search in customers', 'wpshop'),
186
-                'not_found' => __('No customer found', 'wpshop'),
187
-                'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
188
-                'parent_item_colon' => '',
189
-            ),
190
-            'description' => '',
191
-            'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
192
-            'hierarchical' => false,
193
-            'public' => false,
194
-            'show_ui' => true,
195
-            'show_in_menu' => true, //'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
196
-            'show_in_nav_menus' => false,
197
-            'show_in_admin_bar' => false,
198
-            'can_export' => false,
199
-            'has_archive' => false,
200
-            'exclude_from_search' => true,
201
-            'publicly_queryable' => false,
202
-            'rewrite' => false,
203
-            'menu_icon' => 'dashicons-id-alt',
204
-            'capabilities' => array(
205
-                'create_posts' => 'wpshop_view_dashboard',
206
-                'edit_post' => 'wpshop_view_dashboard',
207
-                'edit_posts' => 'wpshop_view_dashboard',
208
-                'edit_others_posts' => 'wpshop_view_dashboard',
209
-                'publish_posts' => 'wpshop_view_dashboard',
210
-                'read_post' => 'wpshop_view_dashboard',
211
-                'read_private_posts' => 'wpshop_view_dashboard',
212
-                'delete_posts' => 'delete_product',
213
-            ),
214
-        );
215
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params);
216
-    }
217
-
218
-    /**
219
-     * Link for redirect new customer to new user
220
-     */
221
-    public static function customer_action_on_menu()
222
-    {
223
-        global $submenu;
224
-        //$submenu['edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS][10] = array( __( 'New customer', 'wpshop' ), 'create_users', admin_url( 'user-new.php?redirect_to=edit.php%3Fpost_type%3D' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) );
225
-    }
226
-
227
-    /**
228
-     * Redirect when create new customer in admin
229
-     */
230
-    public function redirect_new_user()
231
-    {
232
-        global $pagenow;
233
-
234
-        /* Check current admin page. */
235
-        if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
236
-            $redirect = $_SESSION['redirect_to_customer'];
237
-            unset($_SESSION['redirect_to_customer']);
238
-            if ($pagenow == 'users.php') {
239
-                wp_redirect(admin_url($redirect, 'http'));
240
-                exit;
241
-            }
242
-        }
243
-
244
-        /* Redirect to new user */
245
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
246
-        if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
247
-            $_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
248
-            wp_redirect(admin_url('user-new.php', 'http'), 301);
249
-            exit;
250
-        }
251
-
252
-        /* Include JS on new user customer */
253
-        if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
254
-            add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20);
255
-        }
256
-    }
257
-    /* JS to select customer in place of suscriber */
258
-    public function admin_user_customer_js()
259
-    {
260
-        echo "<script type='text/javascript'>\n";
261
-        echo "jQuery(document).ready(function($) {";
262
-        echo "\n$('#role').val('customer').change();";
263
-        echo "\n});\n</script>";
264
-    }
265
-
266
-    /**
267
-     * Create an entity of customer type when a new user is created
268
-     *
269
-     * @param integer $user_id
270
-     */
271
-    public static function create_entity_customer_when_user_is_created($user_id)
272
-    {
273
-        $user_data = get_userdata($user_id);
274
-        $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
275
-        $customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
276
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
277
-
278
-        /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
279
-        $usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true);
280
-        if (!empty($usermeta) && is_array($usermeta)) {
281
-            $data_to_delete = array_search('add-wpshop_product_category', $usermeta);
282
-            if ($data_to_delete !== false) {
283
-                unset($usermeta[$data_to_delete]);
284
-                update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta);
285
-            }
286
-        }
287
-    }
288
-    private static function array_map_create_entity_customer_when_user_is_created($a)
289
-    {
290
-        return $a[0];
291
-    }
292
-
293
-    /**
294
-     * Update an entity of customer type when a user profile is update
295
-     *
296
-     * @param integer $user_id
297
-     */
298
-    public static function update_entity_customer_when_profile_user_is_update($user_id)
299
-    {
300
-        $user_data = get_userdata($user_id);
301
-        $user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
302
-        $customer_post_ID = self::get_customer_id_by_author_id($user_id);
303
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
304
-    }
305
-    private static function array_map_update_entity_customer_when_profile_user_is_update($a)
306
-    {
307
-        return $a[0];
308
-    }
309
-
310
-    /**
311
-     * Add metas in user when customer is modified
312
-     *
313
-     * @param integer $post_id
314
-     * @param WP_Post $post
315
-     */
316
-    public static function save_entity_customer($customer_post_ID, $post)
317
-    {
318
-        if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) {
319
-            return;
320
-        }
321
-        $user_id = $post->post_author;
322
-        $user_info = array();
323
-        $attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
324
-        if (!empty($attribute)) {
325
-            foreach ($attribute as $type => $attributes) {
326
-                foreach ($attributes as $meta => $attribute) {
327
-                    $user_info[$meta] = sanitize_text_field($attribute);
328
-                }
329
-            }
330
-        }
331
-        self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
332
-        /** Update newsletter user preferences **/
333
-        $newsletter_preferences = array();
334
-        $newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : '';
335
-        if (!empty($newsletter_site)) {
336
-            $newsletter_preferences['newsletters_site'] = 1;
337
-        }
338
-        $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : '';
339
-        if (!empty($newsletters_site_partners)) {
340
-            $newsletter_preferences['newsletters_site_partners'] = 1;
341
-        }
342
-        update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
343
-        return;
344
-    }
345
-
346
-    public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info)
347
-    {
348
-        global $wpdb;
349
-        global $wpshop;
350
-        $exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
351
-        $wps_entities = new wpshop_entities();
352
-        $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
353
-        $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
354
-        $attribute_set_id = $wpdb->get_var($query);
355
-        $attributes_default = array();
356
-        if (!empty($attribute_set_id)) {
357
-            $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
358
-            foreach ($group as $attribute_sets) {
359
-                foreach ($attribute_sets as $attribute_set_field) {
360
-                    foreach ($attribute_set_field['content'] as $attribute) {
361
-                        if (isset($attribute['value'])) {
362
-                            if (is_serialized($attribute['value'])) {
363
-                                $unserialized_value = unserialize($attribute['value']);
364
-                                if (isset($unserialized_value['default_value'])) {
365
-                                    $attributes_default[$attribute['name']] = $unserialized_value['default_value'];
366
-                                }
367
-                            } else {
368
-                                $attributes_default[$attribute['name']] = $attribute['value'];
369
-                            }
370
-                        }
371
-                    }
372
-                }
373
-            }
374
-        }
375
-        $user_info = array_merge($attributes_default, $user_info);
376
-        foreach ($user_info as $user_meta => $user_meta_value) {
377
-            $attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
378
-            if (!empty($attribute_def)) {
379
-                //Save data in user meta
380
-                if (in_array($user_meta, $exclude_user_meta)) {
381
-                    if ($user_meta == 'user_pass') {
382
-                        $new_password = wpshop_tools::varSanitizer($user_meta_value);
383
-                        if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) {
384
-                            continue;
385
-                        }
386
-                    }
387
-                    wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value)));
388
-                } else {
389
-                    update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value));
390
-                }
391
-                //Save data in attribute tables, ckeck first if exist to know if Insert or Update
392
-                $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
393
-                $checking_attribute_exist = $wpdb->get_results($query);
394
-                if (!empty($checking_attribute_exist)) {
395
-                    $wpdb->update(
396
-                        WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
397
-                        array(
398
-                            'value' => wpshop_tools::varSanitizer($user_meta_value)),
399
-                        array(
400
-                            'entity_type_id' => $element_id,
401
-                            'entity_id' => $customer_post_ID,
402
-                            'attribute_id' => $attribute_def->id,
403
-                        )
404
-                    );
405
-                } else {
406
-                    $wpdb->insert(
407
-                        WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
408
-                        array(
409
-                            'entity_type_id' => $element_id,
410
-                            'attribute_id' => $attribute_def->id,
411
-                            'entity_id' => $customer_post_ID,
412
-                            'user_id' => $user_id,
413
-                            'creation_date_value' => current_time('mysql', 0),
414
-                            'language' => 'fr_FR',
415
-                            'value' => wpshop_tools::varSanitizer($user_meta_value),
416
-                        )
417
-                    );
418
-                }
419
-            }
420
-        }
421
-    }
422
-
423
-    /**
424
-     * Notice for errors on admin
425
-     */
426
-    public function notice_save_post_customer_informations()
427
-    {
428
-        $errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : '';
429
-        if (!empty($errors)) {
430
-            foreach ($errors as $error) {
431
-                $class = "error";
432
-                $message = $error;
433
-                echo "<div class=\"$class\"> <p>$message</p></div>";
434
-            }
435
-            unset($_SESSION['save_post_customer_informations_errors']);
436
-        }
437
-    }
438
-
439
-    /**
440
-     * Change the customer list table header to display custom informations
441
-     *
442
-     * @param array $current_header The current header list displayed to filter and modify for new output
443
-     *
444
-     * @return array The new header to display
445
-     */
446
-    public function list_table_header($current_header)
447
-    {
448
-        unset($current_header['title']);
449
-        unset($current_header['date']);
450
-
451
-        $current_header['customer_identifier'] = __('Customer ID', 'wpshop');
452
-        $current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
453
-        $current_header['customer_email'] = __('E-mail', 'wpshop');
454
-        $current_header['customer_orders'] = __('Customer\'s orders', 'wpshop');
455
-        $current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
456
-        $current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop');
457
-
458
-        return $current_header;
459
-    }
460
-
461
-    /**
462
-     * Display the content into list table column
463
-     *
464
-     * @param string $column THe column identifier to modify output for
465
-     * @param integer $post_id The current post identifier
466
-     */
467
-    public function list_table_column_content($column, $post_id)
468
-    {
469
-        global $wpdb;
470
-        /**    Get wp_users idenfifier from customer id    */
471
-        $current_user_id_in_list = self::get_author_id_by_customer_id($post_id);
472
-
473
-        /**    Get current post informations    */
474
-        $customer_post = get_post($post_id);
475
-
476
-        /**    Get user data    */
477
-        $current_user_datas = get_userdata($current_user_id_in_list);
478
-
479
-        /**    Switch current column for custom case    */
480
-        $use_template = true;
481
-        switch ($column) {
482
-            case 'customer_identifier':
483
-                echo $post_id;
484
-                $use_template = false;
485
-                break;
486
-            case 'customer_date_subscription':
487
-                echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true);
488
-                $use_template = false;
489
-                break;
490
-            case 'customer_date_lastlogin':
491
-                $last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true);
492
-                if (!empty($last_login)):
493
-                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
494
-                else:
495
-                    _e('Never logged in', 'wpshop');
496
-                endif;
497
-                $use_template = false;
498
-                break;
499
-        }
500
-
501
-        /**    Require the template for displaying the current column    */
502
-        if ($use_template) {
503
-            $template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column);
504
-            if (is_file($template)) {
505
-                require $template;
506
-            }
507
-        }
508
-    }
509
-
510
-    /**
511
-     * Filter bulk actions into customer list table
512
-     *
513
-     * @param array $actions Current available actions list
514
-     *
515
-     * @return array The new action list to use into customer list table
516
-     */
517
-    public function customer_list_table_bulk_actions($actions)
518
-    {
519
-        unset($actions['edit']);
520
-        unset($actions['trash']);
521
-
522
-        return $actions;
523
-    }
524
-
525
-    public function list_table_filters()
526
-    {
527
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
528
-        if (isset($post_type)) {
529
-            if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
530
-                $filter_possibilities = array();
531
-                $filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
532
-                $filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
533
-                $filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
534
-                echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
535
-            }
536
-        }
537
-    }
538
-
539
-    public function list_table_filter_parse_query($query)
540
-    {
541
-        global $pagenow, $wpdb;
542
-        $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
543
-        $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
544
-        if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
545
-            $check = null;
546
-            switch ($entity_filter) {
547
-                case 'orders':
548
-                    $sql_query = $wpdb->prepare(
549
-                        "SELECT ID
154
+		}
155
+		return $content_output;
156
+	}
157
+
158
+	/**
159
+	 * Action on plug-on action
160
+	 */
161
+	public static function customer_action_on_plugin_init()
162
+	{
163
+		return;
164
+	}
165
+
166
+	/**
167
+	 * Create the customer entity
168
+	 */
169
+	public function create_customer_entity()
170
+	{
171
+		global $wpdb;
172
+		$query = $wpdb->prepare("SELECT P.post_title, PM.meta_value FROM {$wpdb->posts} AS P INNER JOIN {$wpdb->postmeta} AS PM ON (PM.post_id = P.ID) WHERE P.post_name = %s AND PM.meta_key = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, '_wpshop_entity_params');
173
+		$customer_entity_definition = $wpdb->get_row($query);
174
+		$current_entity_params = !empty($customer_entity_definition) && !empty($customer_entity_definition->meta_value) ? unserialize($customer_entity_definition->meta_value) : null;
175
+
176
+		$post_type_params = array(
177
+			'labels' => array(
178
+				'name' => __('Customers', 'wpshop'),
179
+				'singular_name' => __('Customer', 'wpshop'),
180
+				'add_new_item' => __('New customer', 'wpshop'),
181
+				'add_new' => __('New customer', 'wpshop'),
182
+				'edit_item' => __('Edit customer', 'wpshop'),
183
+				'new_item' => __('New customer', 'wpshop'),
184
+				'view_item' => __('View customer', 'wpshop'),
185
+				'search_items' => __('Search in customers', 'wpshop'),
186
+				'not_found' => __('No customer found', 'wpshop'),
187
+				'not_found_in_trash' => __('No customer founded in trash', 'wpshop'),
188
+				'parent_item_colon' => '',
189
+			),
190
+			'description' => '',
191
+			'supports' => !empty($current_entity_params['support']) ? $current_entity_params['support'] : array('title'),
192
+			'hierarchical' => false,
193
+			'public' => false,
194
+			'show_ui' => true,
195
+			'show_in_menu' => true, //'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
196
+			'show_in_nav_menus' => false,
197
+			'show_in_admin_bar' => false,
198
+			'can_export' => false,
199
+			'has_archive' => false,
200
+			'exclude_from_search' => true,
201
+			'publicly_queryable' => false,
202
+			'rewrite' => false,
203
+			'menu_icon' => 'dashicons-id-alt',
204
+			'capabilities' => array(
205
+				'create_posts' => 'wpshop_view_dashboard',
206
+				'edit_post' => 'wpshop_view_dashboard',
207
+				'edit_posts' => 'wpshop_view_dashboard',
208
+				'edit_others_posts' => 'wpshop_view_dashboard',
209
+				'publish_posts' => 'wpshop_view_dashboard',
210
+				'read_post' => 'wpshop_view_dashboard',
211
+				'read_private_posts' => 'wpshop_view_dashboard',
212
+				'delete_posts' => 'delete_product',
213
+			),
214
+		);
215
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_type_params);
216
+	}
217
+
218
+	/**
219
+	 * Link for redirect new customer to new user
220
+	 */
221
+	public static function customer_action_on_menu()
222
+	{
223
+		global $submenu;
224
+		//$submenu['edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS][10] = array( __( 'New customer', 'wpshop' ), 'create_users', admin_url( 'user-new.php?redirect_to=edit.php%3Fpost_type%3D' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) );
225
+	}
226
+
227
+	/**
228
+	 * Redirect when create new customer in admin
229
+	 */
230
+	public function redirect_new_user()
231
+	{
232
+		global $pagenow;
233
+
234
+		/* Check current admin page. */
235
+		if ($pagenow != 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
236
+			$redirect = $_SESSION['redirect_to_customer'];
237
+			unset($_SESSION['redirect_to_customer']);
238
+			if ($pagenow == 'users.php') {
239
+				wp_redirect(admin_url($redirect, 'http'));
240
+				exit;
241
+			}
242
+		}
243
+
244
+		/* Redirect to new user */
245
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
246
+		if ($pagenow == 'post-new.php' && isset($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) {
247
+			$_SESSION['redirect_to_customer'] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
248
+			wp_redirect(admin_url('user-new.php', 'http'), 301);
249
+			exit;
250
+		}
251
+
252
+		/* Include JS on new user customer */
253
+		if ($pagenow == 'user-new.php' && isset($_SESSION['redirect_to_customer'])) {
254
+			add_action('admin_print_scripts', array($this, 'admin_user_customer_js'), 20);
255
+		}
256
+	}
257
+	/* JS to select customer in place of suscriber */
258
+	public function admin_user_customer_js()
259
+	{
260
+		echo "<script type='text/javascript'>\n";
261
+		echo "jQuery(document).ready(function($) {";
262
+		echo "\n$('#role').val('customer').change();";
263
+		echo "\n});\n</script>";
264
+	}
265
+
266
+	/**
267
+	 * Create an entity of customer type when a new user is created
268
+	 *
269
+	 * @param integer $user_id
270
+	 */
271
+	public static function create_entity_customer_when_user_is_created($user_id)
272
+	{
273
+		$user_data = get_userdata($user_id);
274
+		$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
275
+		$customer_post_ID = wp_insert_post(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, 'post_author' => $user_id, 'post_title' => $user_data->user_nicename));
276
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
277
+
278
+		/** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
279
+		$usermeta = get_post_meta($user_id, 'metaboxhidden_nav-menus', true);
280
+		if (!empty($usermeta) && is_array($usermeta)) {
281
+			$data_to_delete = array_search('add-wpshop_product_category', $usermeta);
282
+			if ($data_to_delete !== false) {
283
+				unset($usermeta[$data_to_delete]);
284
+				update_user_meta($user_id, 'metaboxhidden_nav-menus', $usermeta);
285
+			}
286
+		}
287
+	}
288
+	private static function array_map_create_entity_customer_when_user_is_created($a)
289
+	{
290
+		return $a[0];
291
+	}
292
+
293
+	/**
294
+	 * Update an entity of customer type when a user profile is update
295
+	 *
296
+	 * @param integer $user_id
297
+	 */
298
+	public static function update_entity_customer_when_profile_user_is_update($user_id)
299
+	{
300
+		$user_data = get_userdata($user_id);
301
+		$user_info = array_merge(get_object_vars($user_data->data), array_map('self::array_map_create_entity_customer_when_user_is_created', get_user_meta($user_id)));
302
+		$customer_post_ID = self::get_customer_id_by_author_id($user_id);
303
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
304
+	}
305
+	private static function array_map_update_entity_customer_when_profile_user_is_update($a)
306
+	{
307
+		return $a[0];
308
+	}
309
+
310
+	/**
311
+	 * Add metas in user when customer is modified
312
+	 *
313
+	 * @param integer $post_id
314
+	 * @param WP_Post $post
315
+	 */
316
+	public static function save_entity_customer($customer_post_ID, $post)
317
+	{
318
+		if (WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS != $post->post_type || $post->post_status == 'auto-draft' || wp_is_post_revision($customer_post_ID)) {
319
+			return;
320
+		}
321
+		$user_id = $post->post_author;
322
+		$user_info = array();
323
+		$attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
324
+		if (!empty($attribute)) {
325
+			foreach ($attribute as $type => $attributes) {
326
+				foreach ($attributes as $meta => $attribute) {
327
+					$user_info[$meta] = sanitize_text_field($attribute);
328
+				}
329
+			}
330
+		}
331
+		self::save_customer_synchronize($customer_post_ID, $user_id, $user_info);
332
+		/** Update newsletter user preferences **/
333
+		$newsletter_preferences = array();
334
+		$newsletter_site = !empty($_POST['newsletters_site']) ? sanitize_text_field($_POST['newsletters_site']) : '';
335
+		if (!empty($newsletter_site)) {
336
+			$newsletter_preferences['newsletters_site'] = 1;
337
+		}
338
+		$newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? sanitize_text_field($_POST['newsletters_site_partners']) : '';
339
+		if (!empty($newsletters_site_partners)) {
340
+			$newsletter_preferences['newsletters_site_partners'] = 1;
341
+		}
342
+		update_user_meta($user_id, 'user_preferences', $newsletter_preferences);
343
+		return;
344
+	}
345
+
346
+	public static function save_customer_synchronize($customer_post_ID, $user_id, $user_info)
347
+	{
348
+		global $wpdb;
349
+		global $wpshop;
350
+		$exclude_user_meta = array('user_login', 'user_nicename', 'user_email', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status', 'display_name');
351
+		$wps_entities = new wpshop_entities();
352
+		$element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
353
+		$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id);
354
+		$attribute_set_id = $wpdb->get_var($query);
355
+		$attributes_default = array();
356
+		if (!empty($attribute_set_id)) {
357
+			$group = wps_address::get_addresss_form_fields_by_type($attribute_set_id);
358
+			foreach ($group as $attribute_sets) {
359
+				foreach ($attribute_sets as $attribute_set_field) {
360
+					foreach ($attribute_set_field['content'] as $attribute) {
361
+						if (isset($attribute['value'])) {
362
+							if (is_serialized($attribute['value'])) {
363
+								$unserialized_value = unserialize($attribute['value']);
364
+								if (isset($unserialized_value['default_value'])) {
365
+									$attributes_default[$attribute['name']] = $unserialized_value['default_value'];
366
+								}
367
+							} else {
368
+								$attributes_default[$attribute['name']] = $attribute['value'];
369
+							}
370
+						}
371
+					}
372
+				}
373
+			}
374
+		}
375
+		$user_info = array_merge($attributes_default, $user_info);
376
+		foreach ($user_info as $user_meta => $user_meta_value) {
377
+			$attribute_def = wpshop_attributes::getElement($user_meta, "'valid'", 'code');
378
+			if (!empty($attribute_def)) {
379
+				//Save data in user meta
380
+				if (in_array($user_meta, $exclude_user_meta)) {
381
+					if ($user_meta == 'user_pass') {
382
+						$new_password = wpshop_tools::varSanitizer($user_meta_value);
383
+						if (wp_hash_password($new_password) == get_user_meta($user_id, $user_meta, true)) {
384
+							continue;
385
+						}
386
+					}
387
+					wp_update_user(array('ID' => $user_id, $user_meta => wpshop_tools::varSanitizer($user_meta_value)));
388
+				} else {
389
+					update_user_meta($user_id, $user_meta, wpshop_tools::varSanitizer($user_meta_value));
390
+				}
391
+				//Save data in attribute tables, ckeck first if exist to know if Insert or Update
392
+				$query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND entity_id = %d AND attribute_id = %d', $element_id, $customer_post_ID, $attribute_def->id);
393
+				$checking_attribute_exist = $wpdb->get_results($query);
394
+				if (!empty($checking_attribute_exist)) {
395
+					$wpdb->update(
396
+						WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
397
+						array(
398
+							'value' => wpshop_tools::varSanitizer($user_meta_value)),
399
+						array(
400
+							'entity_type_id' => $element_id,
401
+							'entity_id' => $customer_post_ID,
402
+							'attribute_id' => $attribute_def->id,
403
+						)
404
+					);
405
+				} else {
406
+					$wpdb->insert(
407
+						WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type),
408
+						array(
409
+							'entity_type_id' => $element_id,
410
+							'attribute_id' => $attribute_def->id,
411
+							'entity_id' => $customer_post_ID,
412
+							'user_id' => $user_id,
413
+							'creation_date_value' => current_time('mysql', 0),
414
+							'language' => 'fr_FR',
415
+							'value' => wpshop_tools::varSanitizer($user_meta_value),
416
+						)
417
+					);
418
+				}
419
+			}
420
+		}
421
+	}
422
+
423
+	/**
424
+	 * Notice for errors on admin
425
+	 */
426
+	public function notice_save_post_customer_informations()
427
+	{
428
+		$errors = isset($_SESSION['save_post_customer_informations_errors']) ? $_SESSION['save_post_customer_informations_errors'] : '';
429
+		if (!empty($errors)) {
430
+			foreach ($errors as $error) {
431
+				$class = "error";
432
+				$message = $error;
433
+				echo "<div class=\"$class\"> <p>$message</p></div>";
434
+			}
435
+			unset($_SESSION['save_post_customer_informations_errors']);
436
+		}
437
+	}
438
+
439
+	/**
440
+	 * Change the customer list table header to display custom informations
441
+	 *
442
+	 * @param array $current_header The current header list displayed to filter and modify for new output
443
+	 *
444
+	 * @return array The new header to display
445
+	 */
446
+	public function list_table_header($current_header)
447
+	{
448
+		unset($current_header['title']);
449
+		unset($current_header['date']);
450
+
451
+		$current_header['customer_identifier'] = __('Customer ID', 'wpshop');
452
+		$current_header['customer_name'] = '<span class="wps-customer-last_name" >' . __('Last-name', 'wpshop') . '</span><span class="wps-customer-first_name" >' . __('First-name', 'wpshop') . '</span>';
453
+		$current_header['customer_email'] = __('E-mail', 'wpshop');
454
+		$current_header['customer_orders'] = __('Customer\'s orders', 'wpshop');
455
+		$current_header['customer_date_subscription'] = __('Subscription', 'wpshop');
456
+		$current_header['customer_date_lastlogin'] = __('Last login date', 'wpshop');
457
+
458
+		return $current_header;
459
+	}
460
+
461
+	/**
462
+	 * Display the content into list table column
463
+	 *
464
+	 * @param string $column THe column identifier to modify output for
465
+	 * @param integer $post_id The current post identifier
466
+	 */
467
+	public function list_table_column_content($column, $post_id)
468
+	{
469
+		global $wpdb;
470
+		/**    Get wp_users idenfifier from customer id    */
471
+		$current_user_id_in_list = self::get_author_id_by_customer_id($post_id);
472
+
473
+		/**    Get current post informations    */
474
+		$customer_post = get_post($post_id);
475
+
476
+		/**    Get user data    */
477
+		$current_user_datas = get_userdata($current_user_id_in_list);
478
+
479
+		/**    Switch current column for custom case    */
480
+		$use_template = true;
481
+		switch ($column) {
482
+			case 'customer_identifier':
483
+				echo $post_id;
484
+				$use_template = false;
485
+				break;
486
+			case 'customer_date_subscription':
487
+				echo mysql2date(get_option('date_format'), $current_user_datas->user_registered, true);
488
+				$use_template = false;
489
+				break;
490
+			case 'customer_date_lastlogin':
491
+				$last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true);
492
+				if (!empty($last_login)):
493
+					echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
494
+				else:
495
+					_e('Never logged in', 'wpshop');
496
+				endif;
497
+				$use_template = false;
498
+				break;
499
+		}
500
+
501
+		/**    Require the template for displaying the current column    */
502
+		if ($use_template) {
503
+			$template = wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . '/templates/', 'backend', 'customer_listtable/' . $column);
504
+			if (is_file($template)) {
505
+				require $template;
506
+			}
507
+		}
508
+	}
509
+
510
+	/**
511
+	 * Filter bulk actions into customer list table
512
+	 *
513
+	 * @param array $actions Current available actions list
514
+	 *
515
+	 * @return array The new action list to use into customer list table
516
+	 */
517
+	public function customer_list_table_bulk_actions($actions)
518
+	{
519
+		unset($actions['edit']);
520
+		unset($actions['trash']);
521
+
522
+		return $actions;
523
+	}
524
+
525
+	public function list_table_filters()
526
+	{
527
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
528
+		if (isset($post_type)) {
529
+			if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) {
530
+				$filter_possibilities = array();
531
+				$filter_possibilities[''] = __('-- Select Filter --', 'wpshop');
532
+				$filter_possibilities['orders'] = __('List customers with orders', 'wpshop');
533
+				$filter_possibilities['no_orders'] = __('List customers without orders', 'wpshop');
534
+				echo wpshop_form::form_input_select('entity_filter', 'entity_filter', $filter_possibilities, (!empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''), '', 'index');
535
+			}
536
+		}
537
+	}
538
+
539
+	public function list_table_filter_parse_query($query)
540
+	{
541
+		global $pagenow, $wpdb;
542
+		$post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
543
+		$entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : '';
544
+		if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && !empty($entity_filter)) {
545
+			$check = null;
546
+			switch ($entity_filter) {
547
+				case 'orders':
548
+					$sql_query = $wpdb->prepare(
549
+						"SELECT ID
550 550
 						FROM {$wpdb->posts}
551 551
 						WHERE post_type = %s
552 552
 						AND post_status != %s
@@ -555,15 +555,15 @@  discard block
 block discarded – undo
555 555
 						FROM {$wpdb->posts}
556 556
 						WHERE post_type = %s
557 557
 						AND post_status != %s)",
558
-                        WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
559
-                        'auto-draft',
560
-                        WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
561
-                        'auto-draft');
562
-                    $check = 'post__in';
563
-                    break;
564
-                case 'no_orders':
565
-                    $sql_query = $wpdb->prepare(
566
-                        "SELECT ID
558
+						WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
559
+						'auto-draft',
560
+						WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
561
+						'auto-draft');
562
+					$check = 'post__in';
563
+					break;
564
+				case 'no_orders':
565
+					$sql_query = $wpdb->prepare(
566
+						"SELECT ID
567 567
 						FROM {$wpdb->posts}
568 568
 						WHERE post_type = %s
569 569
 						AND post_status != %s
@@ -572,199 +572,199 @@  discard block
 block discarded – undo
572 572
 						FROM {$wpdb->posts}
573 573
 						WHERE post_type = %s
574 574
 						AND post_status != %s)",
575
-                        WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
576
-                        'auto-draft',
577
-                        WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
578
-                        'auto-draft');
579
-                    $check = 'post__in';
580
-                    break;
581
-            }
582
-
583
-            if (!empty($check)) {
584
-                $results = $wpdb->get_results($sql_query);
585
-                $user_id_list = array();
586
-                foreach ($results as $item) {
587
-                    $user_id_list[] = $item->ID;
588
-                }
589
-                if (empty($post_id_list)) {
590
-                    $post_id_list[] = 'no_result';
591
-                }
592
-                $query->query_vars[$check] = $user_id_list;
593
-            }
594
-            $query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
595
-            $query->query_vars['post_status'] = 'any';
596
-        }
597
-    }
598
-
599
-    /**
600
-     * Récupère la liste de tous les clients / Get the list of all customers
601
-     *
602
-     * @return array
603
-     */
604
-    public static function get_all_customer($post_status = 'publish')
605
-    {
606
-        global $wpdb;
607
-
608
-        $query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
609
-        $list_customer = $wpdb->get_results($query);
610
-
611
-        return $list_customer;
612
-    }
613
-
614
-    /**
615
-     * Récupère l'id du client selon son author id / Get customer id by the author id
616
-     *
617
-     * @param int $author_id
618
-     * @return int $customer_id
619
-     */
620
-    public static function get_customer_id_by_author_id($author_id)
621
-    {
622
-        global $wpdb;
623
-
624
-        $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
625
-        $customer_id = $wpdb->get_var($query);
626
-
627
-        return $customer_id;
628
-    }
629
-
630
-    /**
631
-     * Récupère l'id de l'utilisateur selon l'id du client / Get author id by customer id
632
-     *
633
-     * @method get_author_id_by_customer_id
634
-     * @param  int $customer_id ID in wpshop_customers type.
635
-     * @return int
636
-     */
637
-    public static function get_author_id_by_customer_id($customer_id)
638
-    {
639
-        global $wpdb;
640
-
641
-        $author_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id));
642
-
643
-        return $author_id;
644
-    }
645
-
646
-    /**
647
-     * Essaie de créer une corrélation entre le formulaire que l'on passe et customer ( ex: billing_address => customer )
648
-     *
649
-     * @param array $form Passer directement le $_POST pour créer un client.
650
-     * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà
651
-     */
652
-    public static function quick_add_customer($form)
653
-    {
654
-        $return = 1;
655
-        if (!empty($form)) {
656
-            global $wpdb;
657
-            $customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
658
-            $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
659
-            $customer_entity_id = $wpdb->get_var($query);
660
-            $attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
661
-            $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
662
-
663
-            $customer_attributes_to_save = $customer_attributes_to_save_temp = array();
664
-
665
-            foreach ($form['attribute'] as $attribute_type => $attributes) {
666
-                foreach ($attributes as $attribute_code => $attribute_value) {
667
-                    $customer_attributes_compare[$attribute_code] = $attribute_type;
668
-                }
669
-            }
670
-
671
-            foreach ($account_attributes as $account_attribute_group) {
672
-                foreach ($account_attribute_group['attribut'] as $attribute) {
673
-                    foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) {
674
-                        if ($customer_attributes_compare[$codeForm] == $attribute->data_type) {
675
-                            $user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm]));
676
-                            if ($attribute->code == 'user_email') {
677
-                                $email_founded = true;
678
-                            }
679
-                        }
680
-                    }
681
-                }
682
-            }
683
-
684
-            if ($email_founded && is_email($user['user_email']['value'])) {
685
-                $user_id = username_exists($user['user_email']['value']);
686
-                if (empty($user_id)) {
687
-                    $user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value'];
688
-                    $user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false);
689
-                    $user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']);
690
-
691
-                    if (!is_wp_error($user_id)) {
692
-                        $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
693
-                        $customer_entity_id = $wpdb->get_var($customer_entity_request);
694
-                        $return = array();
695
-                        $return['integer']['ID'] = $user_id;
696
-
697
-                        foreach ($user as $meta_key => $meta_values) {
698
-                            update_user_meta($user_id, $meta_key, $meta_values['value']);
699
-                            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value']));
700
-                            $return[$meta_values['data_type']][$meta_key] = $meta_values['value'];
701
-                        }
702
-                    }
703
-                } else {
704
-                    $return = 2;
705
-                }
706
-            }
707
-        }
708
-
709
-        return $return;
710
-    }
711
-
712
-    /**
713
-     * Search function for customer / Fonction de recherche des clients
714
-     *
715
-     * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données
716
-     */
717
-    public function search_customer($term)
718
-    {
719
-        global $wpdb;
720
-
721
-        /**    Build the customer search    */
722
-        $args = array(
723
-            'search' => "*" . $term . "*",
724
-            'search_columns' => array('user_login', 'user_email', 'user_nicename'),
725
-            'meta_query' => array(
726
-                'relation' => 'OR',
727
-                array(
728
-                    'key' => 'first_name',
729
-                    'value' => $term,
730
-                    'compare' => 'LIKE',
731
-                ),
732
-                array(
733
-                    'key' => 'last_name',
734
-                    'value' => $term,
735
-                    'compare' => 'LIKE',
736
-                ),
737
-            ),
738
-        );
739
-        $customer_search = new WP_User_Query($args);
740
-
741
-        $customer_list = array();
742
-        if (!empty($customer_search->results)) {
743
-            foreach ($customer_search->results as $customer) {
744
-                /** Check the username, if last name and first name are empty we select email **/
745
-                $last_name_meta = get_user_meta($customer->ID, 'last_name', true);
746
-                $first_name_meta = get_user_meta($customer->ID, 'first_name', true);
747
-                $user_data = $customer->data;
748
-                $email_data = $user_data->user_email;
749
-
750
-                if (!empty($last_name_meta)) {
751
-                    $user_name = $last_name_meta;
752
-                } elseif (!empty($first_name_meta)) {
753
-                    $user_name = $first_name_meta;
754
-                } else {
755
-                    $user_name = $email_data;
756
-                }
757
-
758
-                $customer_list[] = array(
759
-                    'ID' => $customer->ID,
760
-                    'last_name' => $last_name_meta,
761
-                    'first_name' => $first_name_meta,
762
-                    'email' => $email_data,
763
-                );
764
-            }
765
-        }
766
-
767
-        return $customer_list;
768
-    }
575
+						WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS,
576
+						'auto-draft',
577
+						WPSHOP_NEWTYPE_IDENTIFIER_ORDER,
578
+						'auto-draft');
579
+					$check = 'post__in';
580
+					break;
581
+			}
582
+
583
+			if (!empty($check)) {
584
+				$results = $wpdb->get_results($sql_query);
585
+				$user_id_list = array();
586
+				foreach ($results as $item) {
587
+					$user_id_list[] = $item->ID;
588
+				}
589
+				if (empty($post_id_list)) {
590
+					$post_id_list[] = 'no_result';
591
+				}
592
+				$query->query_vars[$check] = $user_id_list;
593
+			}
594
+			$query->query_vars['post_type'] = WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
595
+			$query->query_vars['post_status'] = 'any';
596
+		}
597
+	}
598
+
599
+	/**
600
+	 * Récupère la liste de tous les clients / Get the list of all customers
601
+	 *
602
+	 * @return array
603
+	 */
604
+	public static function get_all_customer($post_status = 'publish')
605
+	{
606
+		global $wpdb;
607
+
608
+		$query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $post_status);
609
+		$list_customer = $wpdb->get_results($query);
610
+
611
+		return $list_customer;
612
+	}
613
+
614
+	/**
615
+	 * Récupère l'id du client selon son author id / Get customer id by the author id
616
+	 *
617
+	 * @param int $author_id
618
+	 * @return int $customer_id
619
+	 */
620
+	public static function get_customer_id_by_author_id($author_id)
621
+	{
622
+		global $wpdb;
623
+
624
+		$query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s", $author_id, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
625
+		$customer_id = $wpdb->get_var($query);
626
+
627
+		return $customer_id;
628
+	}
629
+
630
+	/**
631
+	 * Récupère l'id de l'utilisateur selon l'id du client / Get author id by customer id
632
+	 *
633
+	 * @method get_author_id_by_customer_id
634
+	 * @param  int $customer_id ID in wpshop_customers type.
635
+	 * @return int
636
+	 */
637
+	public static function get_author_id_by_customer_id($customer_id)
638
+	{
639
+		global $wpdb;
640
+
641
+		$author_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID = %d", $customer_id));
642
+
643
+		return $author_id;
644
+	}
645
+
646
+	/**
647
+	 * Essaie de créer une corrélation entre le formulaire que l'on passe et customer ( ex: billing_address => customer )
648
+	 *
649
+	 * @param array $form Passer directement le $_POST pour créer un client.
650
+	 * @return array ou int : 1 = Aucun mail, 2 = L'utilisateur existe déjà
651
+	 */
652
+	public static function quick_add_customer($form)
653
+	{
654
+		$return = 1;
655
+		if (!empty($form)) {
656
+			global $wpdb;
657
+			$customer_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
658
+			$query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $customer_type_id);
659
+			$customer_entity_id = $wpdb->get_var($query);
660
+			$attributes_set = wpshop_attributes_set::getElement($customer_entity_id);
661
+			$account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'");
662
+
663
+			$customer_attributes_to_save = $customer_attributes_to_save_temp = array();
664
+
665
+			foreach ($form['attribute'] as $attribute_type => $attributes) {
666
+				foreach ($attributes as $attribute_code => $attribute_value) {
667
+					$customer_attributes_compare[$attribute_code] = $attribute_type;
668
+				}
669
+			}
670
+
671
+			foreach ($account_attributes as $account_attribute_group) {
672
+				foreach ($account_attribute_group['attribut'] as $attribute) {
673
+					foreach (preg_grep('/' . $attribute->code . '/', array_keys($customer_attributes_compare)) as $codeForm) {
674
+						if ($customer_attributes_compare[$codeForm] == $attribute->data_type) {
675
+							$user[$attribute->code] = array('attribute_id' => $attribute->id, 'data_type' => $attribute->data_type, 'value' => sanitize_text_field($_POST['attribute'][$attribute->data_type][$codeForm]));
676
+							if ($attribute->code == 'user_email') {
677
+								$email_founded = true;
678
+							}
679
+						}
680
+					}
681
+				}
682
+			}
683
+
684
+			if ($email_founded && is_email($user['user_email']['value'])) {
685
+				$user_id = username_exists($user['user_email']['value']);
686
+				if (empty($user_id)) {
687
+					$user_name = isset($user['user_login']['value']) ? $user['user_login']['value'] : $user['user_email']['value'];
688
+					$user_pass = isset($user['user_pass']['value']) ? $user['user_pass']['value'] : wp_generate_password(12, false);
689
+					$user_id = wp_create_user($user_name, $user_pass, $user['user_email']['value']);
690
+
691
+					if (!is_wp_error($user_id)) {
692
+						$customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id);
693
+						$customer_entity_id = $wpdb->get_var($customer_entity_request);
694
+						$return = array();
695
+						$return['integer']['ID'] = $user_id;
696
+
697
+						foreach ($user as $meta_key => $meta_values) {
698
+							update_user_meta($user_id, $meta_key, $meta_values['value']);
699
+							$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($meta_values['data_type']), array('entity_type_id' => $customer_type_id, 'attribute_id' => $meta_values['attribute_id'], 'entity_id' => $customer_entity_id, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0), 'language' => 'fr_FR', 'value' => $meta_values['value']));
700
+							$return[$meta_values['data_type']][$meta_key] = $meta_values['value'];
701
+						}
702
+					}
703
+				} else {
704
+					$return = 2;
705
+				}
706
+			}
707
+		}
708
+
709
+		return $return;
710
+	}
711
+
712
+	/**
713
+	 * Search function for customer / Fonction de recherche des clients
714
+	 *
715
+	 * @param string $term The term we have to search into database for getting existing users / Le terme qu'il faut rechercher pour retrouver les utilisateurs dans la base de données
716
+	 */
717
+	public function search_customer($term)
718
+	{
719
+		global $wpdb;
720
+
721
+		/**    Build the customer search    */
722
+		$args = array(
723
+			'search' => "*" . $term . "*",
724
+			'search_columns' => array('user_login', 'user_email', 'user_nicename'),
725
+			'meta_query' => array(
726
+				'relation' => 'OR',
727
+				array(
728
+					'key' => 'first_name',
729
+					'value' => $term,
730
+					'compare' => 'LIKE',
731
+				),
732
+				array(
733
+					'key' => 'last_name',
734
+					'value' => $term,
735
+					'compare' => 'LIKE',
736
+				),
737
+			),
738
+		);
739
+		$customer_search = new WP_User_Query($args);
740
+
741
+		$customer_list = array();
742
+		if (!empty($customer_search->results)) {
743
+			foreach ($customer_search->results as $customer) {
744
+				/** Check the username, if last name and first name are empty we select email **/
745
+				$last_name_meta = get_user_meta($customer->ID, 'last_name', true);
746
+				$first_name_meta = get_user_meta($customer->ID, 'first_name', true);
747
+				$user_data = $customer->data;
748
+				$email_data = $user_data->user_email;
749
+
750
+				if (!empty($last_name_meta)) {
751
+					$user_name = $last_name_meta;
752
+				} elseif (!empty($first_name_meta)) {
753
+					$user_name = $first_name_meta;
754
+				} else {
755
+					$user_name = $email_data;
756
+				}
757
+
758
+				$customer_list[] = array(
759
+					'ID' => $customer->ID,
760
+					'last_name' => $last_name_meta,
761
+					'first_name' => $first_name_meta,
762
+					'email' => $email_data,
763
+				);
764
+			}
765
+		}
766
+
767
+		return $customer_list;
768
+	}
769 769
 
770 770
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                             $company_value = $wpdb->get_var($query);
139 139
                         }
140 140
                     }
141
-                    ob_start();?>
141
+                    ob_start(); ?>
142 142
 					<option value="<?php echo $user->ID; ?>" <?php echo ((!$multiple) && ($selected_user == $user->ID)) ? ' selected="selected"' : ''; ?>>
143 143
 						<?php echo $lastname; ?> <?php echo $firstname; ?> (<?php echo $user->user_email; ?>)<?php echo isset($company_value) ? ' : ' . $company_value : ''; ?>
144 144
 					</option>
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         }
321 321
         $user_id = $post->post_author;
322 322
         $user_info = array();
323
-        $attribute = !empty($_POST['attribute']) ? (array) $_POST['attribute'] : array();
323
+        $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array();
324 324
         if (!empty($attribute)) {
325 325
             foreach ($attribute as $type => $attributes) {
326 326
                 foreach ($attributes as $meta => $attribute) {
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -491,8 +491,10 @@
 block discarded – undo
491 491
                 $last_login = get_user_meta($current_user_id_in_list, 'last_login_time', true);
492 492
                 if (!empty($last_login)):
493 493
                     echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $last_login, true);
494
-                else:
495
-                    _e('Never logged in', 'wpshop');
494
+                else {
495
+                	:
496
+                    _e('Never logged in', 'wpshop');
497
+                }
496 498
                 endif;
497 499
                 $use_template = false;
498 500
                 break;
Please login to merge, or discard this patch.