/**
  * @param Bring_WC_Order_Adapter $order
  * @return string
  */
 static function get_booking_status_info($order)
 {
     $result = ['text' => __('No', 'bring-fraktguiden'), 'icon' => 'dashicons-minus'];
     if (self::is_step2()) {
         $result = ['text' => __('In progress', 'bring-fraktguiden'), 'icon' => ''];
     }
     if ($order->is_booked()) {
         $result = ['text' => __('Booked', 'bring-fraktguiden'), 'icon' => 'dashicons-yes'];
     }
     if ($order->has_booking_errors()) {
         $result = ['text' => __('Failed', 'bring-fraktguiden'), 'icon' => 'dashicons-warning'];
     }
     return $result;
 }
 /**
  * Display tracking on Order/Mail etc.
  *
  * @param string $content
  * @param WC_Order $wc_order
  * @return string
  */
 static function order_display_tracking_info($content, $wc_order)
 {
     $order = new Bring_WC_Order_Adapter($wc_order);
     if ($order->is_booked()) {
         $content .= '<div class="bring-order-details-booking">';
         $content .= '<strong>' . __('Your tracking number: ', 'bring-fraktguiden') . '</strong>';
         $content .= '<ul>';
         foreach ($order->get_booking_consignments() as $consignment) {
             $confirmation = $consignment->confirmation;
             $consignment_number = $confirmation->consignmentNumber;
             $content .= '<li><a href="' . $confirmation->links->tracking . '">' . $consignment_number . '</a></li>';
         }
         $content .= '</ul>';
         $content .= '</div>';
     }
     return $content;
 }
    /**
     * @param Bring_WC_Order_Adapter $order
     * @return string
     */
    static function render_errors($order)
    {
        $errors = $order->get_booking_errors();
        ?>
    <div class="bring-info-box">
      <div>
        <?php 
        $status = Bring_Booking_Common_View::get_booking_status_info($order);
        echo Bring_Booking_Common_View::create_status_icon($status);
        ?>
        <h3><?php 
        echo $status['text'];
        ?>
</h3>
      </div>

      <div class="bring-booking-errors">
        <div><?php 
        _e('Previous booking request failed with the following errors:', 'bring-fraktguiden');
        ?>
</div>
        <ul>
          <?php 
        foreach ($errors as $error) {
            ?>
            <li><?php 
            echo $error;
            ?>
</li>
          <?php 
        }
        ?>
        </ul>
        <div><?php 
        _e('Press Start to try again', 'bring-fraktguiden');
        ?>
</div>
      </div>
    </div>
    <?php 
    }
 /**
  * Updates pickup points from admin/order items.
  *
  * @param $order_id
  * @param $shipping_items
  */
 static function admin_saved_order_items($order_id, $shipping_items)
 {
     $order = new Bring_WC_Order_Adapter(new WC_Order($order_id));
     $order->admin_update_pickup_point($shipping_items);
 }
 /**
  * Bulk booking requests.
  *
  * @param array $post_ids Array of WC_Order ID's
  */
 static function bulk_send_booking($post_ids)
 {
     foreach ($post_ids as $post_id) {
         $order = new Bring_WC_Order_Adapter(new WC_Order($post_id));
         if (!$order->has_booking_consignments()) {
             self::send_booking($order->order);
         }
     }
 }
 static function open_pdfs()
 {
     add_submenu_page(null, 'Download', 'Download', 'manage_woocommerce', 'bring_labels', function () {
         if (!isset($_GET['order_ids']) || $_GET['order_ids'] == '') {
             return;
         }
         $current_user = wp_get_current_user();
         // ID 0 is a not an user.
         if ($current_user->ID == 0) {
             exit;
         }
         // Admins and managers can download all orders.
         $can_download = in_array('manage_woocommerce', $current_user->roles) || in_array('administrator', $current_user->roles);
         if (!$can_download) {
             exit;
         }
         $order_ids = explode(',', $_GET['order_ids']);
         $files_to_merge = [];
         foreach ($order_ids as $order_id) {
             $order = new Bring_WC_Order_Adapter(new WC_Order($order_id));
             if (!$order->has_booking_consignments()) {
                 continue;
             }
             $consignments = $order->get_booking_consignments();
             foreach ($consignments as $consignment) {
                 $confirmation = $consignment->confirmation;
                 $consignment_number = $confirmation->consignmentNumber;
                 $file_path = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number);
                 if (file_exists($file_path)) {
                     $files_to_merge[] = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number);
                 }
             }
         }
         include_once FRAKTGUIDEN_PLUGIN_PATH . '/vendor/myokyawhtun/pdfmerger/PDFMerger.php';
         $merger = new PDFMerger();
         foreach ($files_to_merge as $file) {
             $merger->addPDF($file);
         }
         $merge_result_file = Bring_Booking_Labels::get_local_dir() . '/labels-merged.pdf';
         $merger->merge('file', $merge_result_file);
         header("Content-Length: " . filesize($merge_result_file));
         header("Content-type: application/pdf");
         header("Content-disposition: inline; filename=" . basename($merge_result_file));
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         // Workaround for Chrome's inline pdf viewer
         ob_clean();
         flush();
         readfile($merge_result_file);
         exit;
     });
 }