function invoice_export($order_id, $invoice_id = null)
 {
     $current_user_id = get_current_user_id();
     $order = get_post_meta($order_id, '_order_postmeta', true);
     if ($order['customer_id'] == $current_user_id or is_admin()) {
         if (in_array($order['order_status'], array('completed', 'shipped', 'partially_paid'))) {
             $invoice_dir = WP_CONTENT_DIR . "/uploads/wpshop_invoices/";
             $filename = $this->get_invoice_filename($order_id);
             $invoice_url = $invoice_dir . $filename;
             // If the invoice has not been already generated
             // 				if ( !file_exists($invoice_url) ) {
             $invoice_ref = $order['order_invoice_ref'];
             // Currency management
             $currency = $order['order_currency'];
             if ($currency == 'EUR') {
                 $currency = EUR;
             } else {
                 $currency = html_entity_decode(wpshop_tools::wpshop_get_sigle($currency));
             }
             // On d�finit un alias pour le nombre de pages total
             $this->AliasNbPages();
             // On ajoute une page au document
             $this->AddPage();
             // On lui applique une police
             $this->SetFont('Arial', '', 10);
             // Coordonn�es magasin
             $this->store_head($order_id);
             // Coordonn�es client
             $this->client_head($order_id);
             // Date de facturation et r�f�rence facture
             $refdate = $this->invoice_refdate($order_id, $invoice_ref);
             // Tableau des lignes de facture
             $this->rows($order_id, $currency, $invoice_id);
             // Ligne de total
             $this->total($order_id, $currency, $invoice_id);
             // On affiche le rib du magasin
             //$this->rib($store_selected);
             // On mentionnes les informations obigatoires en bas de page
             $this->pre_footer($order_id);
             // On cr�e le dossier si celui ci n'existe pas
             $this->make_recursiv_dir($invoice_dir);
             // On enregistre
             $path = $invoice_url;
             $this->Output($path, "F");
             // On force le t�l�chargement de la facture
             $Fichier_a_telecharger = $refdate . ".pdf";
             $this->forceDownload($Fichier_a_telecharger, $path, filesize($path));
             // 				}
             // 				else $this->forceDownload($filename, $invoice_url, filesize($invoice_url));
         } else {
             echo __('The payment regarding the invoice you requested isn\'t completed', 'wpshop');
         }
     } else {
         echo __('You don\'t have the rights to access this invoice.', 'wpshop');
     }
 }
 /** Give the content by column
  * @return array
  */
 public static function orders_custom_columns($column, $post_id)
 {
     if (get_post_type($post_id) == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
         global $civility, $order_status;
         $metadata = get_post_custom();
         $order_postmeta = isset($metadata['_order_postmeta'][0]) ? unserialize($metadata['_order_postmeta'][0]) : '';
         $addresses = get_post_meta($post_id, '_order_info', true);
         switch ($column) {
             case "order_identifier":
                 if (!empty($order_postmeta['order_key'])) {
                     echo '<b>' . $order_postmeta['order_key'] . '</b><br>';
                 }
                 if (!empty($order_postmeta['order_invoice_ref'])) {
                     echo !empty($order_postmeta['order_temporary_key']) ? '<b>' . $order_postmeta['order_invoice_ref'] . '</b>' : '<i>' . $order_postmeta['order_invoice_ref'] . '</i>';
                 }
                 break;
             case "order_status":
                 echo !empty($order_postmeta['order_status']) ? sprintf('<mark class="%s" id="order_status_' . $post_id . '">%s</mark>', sanitize_title(strtolower($order_postmeta['order_status'])), __($order_status[strtolower($order_postmeta['order_status'])], 'wpshop')) : __('Unknown Status', 'wpshop');
                 break;
             case "order_billing":
                 if (!empty($addresses['billing']) && !empty($addresses['billing']['address']) && is_array($addresses['billing']['address'])) {
                     $billing = $addresses['billing']['address'];
                 } else {
                     if (!empty($addresses['billing'])) {
                         $billing = $addresses['billing'];
                     }
                 }
                 if (!empty($billing)) {
                     echo (!empty($billing['civility']) ? __(wpshop_attributes::get_attribute_type_select_option_info($billing['civility'], 'label', 'custom'), 'wpshop') : null) . ' <strong>' . (!empty($billing['address_first_name']) ? $billing['address_first_name'] : null) . ' ' . (!empty($billing['address_last_name']) ? $billing['address_last_name'] : null) . '</strong>';
                     echo empty($billing['company']) ? '<br />' : ', <i>' . $billing['company'] . '</i><br />';
                     echo (!empty($billing['address']) ? $billing['address'] : null) . '<br />';
                     echo (!empty($billing['postcode']) ? $billing['postcode'] : null) . ' ' . (!empty($billing['city']) ? $billing['city'] : null) . ', ' . (!empty($billing['country']) ? $billing['country'] : null);
                 } else {
                     echo __('No information available for user billing', 'wpshop');
                 }
                 break;
             case "order_shipping":
                 if (!empty($addresses['shipping']) && !empty($addresses['shipping']['address']) && is_array($addresses['shipping']['address'])) {
                     $shipping = $addresses['shipping']['address'];
                 } else {
                     if (!empty($addresses['shipping'])) {
                         $shipping = $addresses['shipping'];
                     }
                 }
                 if (!empty($shipping)) {
                     echo '<strong>' . (!empty($shipping['address_first_name']) ? $shipping['address_first_name'] : null) . ' ' . (!empty($shipping['address_last_name']) ? $shipping['address_last_name'] : null) . '</strong>';
                     echo empty($shipping['company']) ? '<br />' : ', <i>' . $shipping['company'] . '</i><br />';
                     echo (!empty($shipping['address']) ? $shipping['address'] : null) . '<br />';
                     echo (!empty($shipping['postcode']) ? $shipping['postcode'] : null) . ' ' . (!empty($shipping['city']) ? $shipping['city'] : null) . ', ' . (!empty($shipping['country']) ? $shipping['country'] : null);
                 } else {
                     echo __('No information available for user shipping', 'wpshop');
                 }
                 break;
             case "order_type":
                 echo '<a href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . (!empty($order_postmeta['order_temporary_key']) ? __('Quotation', 'wpshop') : __('Basic order', 'wpshop')) . '</a>';
                 $buttons = '<p class="row-actions">';
                 // Voir la commande
                 $buttons .= '<a class="button button-small" href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . __('View', 'wpshop') . '</a>';
                 // Marquer comme envoy�
                 if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] == 'completed') {
                     $buttons .= '<a data-id="' . $post_id . '" class="wps-bton-second-mini-rounded markAsShipped order_' . $post_id . ' wps-bton-loader">' . __('Mark as shipped', 'wpshop') . '</a> ';
                 } else {
                     if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] == 'awaiting_payment') {
                         //		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
                     }
                 }
                 $buttons .= '</p>';
                 $buttons .= '<input type="hidden" name="input_wpshop_change_order_state" id="input_wpshop_change_order_state" value="' . wp_create_nonce("wpshop_change_order_state") . '" />';
                 $buttons .= '<input type="hidden" name="input_wpshop_dialog_inform_shipping_number" id="input_wpshop_dialog_inform_shipping_number" value="' . wp_create_nonce("wpshop_dialog_inform_shipping_number") . '" />';
                 $buttons .= '<input type="hidden" name="input_wpshop_validate_payment_method" id="input_wpshop_validate_payment_method" value="' . wp_create_nonce("wpshop_validate_payment_method") . '" />';
                 echo $buttons;
                 break;
             case "order_total":
                 $currency = !empty($order_postmeta['order_currency']) ? $order_postmeta['order_currency'] : get_option('wpshop_shop_default_currency');
                 echo isset($order_postmeta['order_grand_total']) ? number_format($order_postmeta['order_grand_total'], 2, '.', '') . ' ' . wpshop_tools::wpshop_get_sigle($currency) : 'NaN';
                 break;
                 /*case "order_actions":
                 					$buttons = '<p class="row-actions">';
                 					// Marquer comme envoy�
                 					if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'completed')) {
                 							$buttons .= '<a class="button markAsShipped order_'.$post_id.'">'.__('Mark as shipped', 'wpshop').'</a> ';
                 					}
                 					else if (!empty($order_postmeta['order_status']) && ($order_postmeta['order_status'] == 'awaiting_payment' )) {
                 					//		$buttons .= '<a class="button markAsCompleted order_'.$post_id.' alignleft" >'.__('Payment received', 'wpshop').'</a>' . wpshop_payment::display_payment_receiver_interface($post_id) . ' ';
                 					}
                 
                 					// Voir la commande
                 					$buttons .= '<a class="button alignright" href="'.admin_url('post.php?post='.$post_id.'&action=edit').'">'.__('View', 'wpshop').'</a>';
                 					$buttons .= '</p>';
                 					$buttons .= '<input type="hidden" name="input_wpshop_change_order_state" id="input_wpshop_change_order_state" value="' . wp_create_nonce("wpshop_change_order_state") . '" />';
                 					$buttons .= '<input type="hidden" name="input_wpshop_dialog_inform_shipping_number" id="input_wpshop_dialog_inform_shipping_number" value="' . wp_create_nonce("wpshop_dialog_inform_shipping_number") . '" />';
                 					$buttons .= '<input type="hidden" name="input_wpshop_validate_payment_method" id="input_wpshop_validate_payment_method" value="' . wp_create_nonce("wpshop_validate_payment_method") . '" />';
                 
                 					echo $buttons;
                 				break;*/
         }
     }
 }