Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • BKAP
    • Addons
    • Admin-Bookings
    • Attribute-Lockout
    • Block-Pricing
    • Booking-Box
    • Booking-Confirmation
    • Booking-Process
    • Cancel-Order
    • Cart
    • Checkout-Process
    • Core
    • Date-Time
    • Emails
    • Functions
    • Global-Function
    • Global-Settings
    • Google-Calendar-Sync
    • ICS
    • Import-Booking
    • Labels
    • License
    • Menus
    • Meta-Boxes
    • Reschedule
    • Resources
    • Search-Widget
    • Special-Price
    • Uninstall
    • Validation
    • Variation-Lockout
    • Vendors
      • Dokan
      • WC-Vendors
    • View-Bookings
  • None

Classes

  • bkap_addon_compatibility_class
  • bkap_admin_bookings
  • bkap_approve_booking
  • bkap_attributes
  • bkap_block_booking
  • BKAP_Booking
  • bkap_booking_box_class
  • bkap_booking_confirmation
  • bkap_booking_process
  • BKAP_Bookings_View
  • bkap_calendar_sync
  • bkap_cancel_order
  • bkap_cart
  • bkap_checkout
  • bkap_common
  • BKAP_Customer_Meta_Box
  • BKAP_Details_Meta_Box
  • bkap_dokan_calendar_class
  • bkap_dokan_class
  • bkap_dokan_orders_class
  • bkap_dokan_products_class
  • bkap_edit_bookings_class
  • BKAP_Email_Booking_Cancelled
  • BKAP_Email_Booking_Confirmed
  • BKAP_Email_Booking_Rescheduled_Admin
  • BKAP_Email_Imported_Event
  • BKAP_Email_Manager
  • BKAP_Email_New_Booking
  • BKAP_Gcal
  • BKAP_Gcal_Event
  • bkap_gcal_sync_settings
  • bkap_global_settings
  • BKAP_Google_Events_View
  • bkap_ics
  • bkap_license
  • bkap_load_scripts_class
  • BKAP_OPC_Addon
  • BKAP_Payment_Gateway
  • BKAP_Product_Resource
  • bkap_rescheduled_order_class
  • BKAP_Resource_Details_Meta_Box
  • BKAP_Save_Meta_Box
  • bkap_special_booking_price
  • bkap_timeslot_price
  • bkap_validation
  • bkap_variations
  • BKAP_Vendors
  • bkap_wc_vendors
  • bkap_wcv_product
  • Booking_Information_In_Voucher_Template
  • Class_Bkap_Product_Resource
  • Custom_WooCommerce_Widget_Product_Search
  • EDD_BOOK_Plugin_Updater
  • global_menu
  • import_bookings
  • product_gcal_settings
  • view_bookings
  • WAPBK_Import_Bookings_Table
  • WAPBK_View_Bookings_Table
  • woocommerce_booking

Functions

  • addDayswithdate
  • bkap_400_create_meta
  • bkap_400_recurring_data
  • bkap_400_update_db_tab
  • bkap_400_update_enable_specific
  • bkap_400_update_enable_week_blocking
  • bkap_400_update_holidays
  • bkap_400_update_ranges
  • bkap_400_update_recurring_lockout
  • bkap_400_update_settings
  • bkap_400_update_special
  • bkap_400_update_specific
  • bkap_410_create_meta
  • bkap_410_update_block_pricing_option_values_in_new_way
  • bkap_410_update_fixed_blocks
  • bkap_410_update_price_ranges
  • bkap_410_update_settings
  • bkap_420_add_gcal_posts
  • bkap_420_add_gcal_tour_posts
  • bkap_420_gcal_batch_size
  • bkap_420_gcal_meta
  • bkap_420_update_settings
  • bkap_add_days_to_date
  • bkap_array_of_given_date_range
  • bkap_booked_resources
  • bkap_booking_posts_for_resource
  • bkap_calculate_bookings_for_resource
  • bkap_check_booking_available
  • bkap_check_day_booking_available
  • bkap_check_for_max_date
  • bkap_check_for_min_date
  • bkap_check_holiday
  • bkap_check_in_custom_holiday_range
  • bkap_check_resource_available
  • bkap_check_resource_booked_in_date_range
  • bkap_db_420_1
  • bkap_db_420_2
  • bkap_delete_event_from_gcal
  • bkap_delete_folder_and_files
  • bkap_delete_options
  • bkap_delete_tables
  • bkap_find_matching_product_variation
  • bkap_generate_bookable_data
  • bkap_get_book_arrays
  • bkap_get_book_t
  • bkap_get_booked
  • bkap_get_booked_checkout
  • bkap_get_custom_posts
  • bkap_get_dateToCal
  • bkap_get_day_between_Week
  • bkap_get_db_count
  • bkap_get_escapeString
  • bkap_get_lockout
  • bkap_get_month_range
  • bkap_get_post_meta
  • bkap_get_posted_availability
  • bkap_get_total_timeslot_maximum_booking
  • bkap_get_week_range
  • bkap_import_events_cron
  • bkap_insert_event_to_gcal
  • bkap_manual_db_update_v420
  • bkap_orderby_date_key
  • bkap_save_resources
  • bkap_sort_by_from_time
  • bkap_update_po_file
  • bkap_vendors_get_bookings
  • bkap_widgets_init
  • bkapSortByPriority
  • calback_bkap_max_date
  • check_in_fixed_block_booking
  • check_in_range
  • check_in_range_abp
  • check_in_range_holidays
  • check_in_range_weekdays
  • create_posts
  • get_availability_for_date
  • get_booked_multiple
  • get_bookings_for_date
  • get_bookings_for_range
  • get_date_lockout
  • get_slot_availability
  • get_slot_lockout
  • get_standard_decimal_thousand_separator_price
  • is_booking_active
  • woocommerce_bkap_add_cron_schedule
   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99  100  101  102  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128  129  130  131  132  133  134  135  136  137  138  139  140  141  142  143  144  145  146  147  148  149  150  151  152  153  154  155  156  157  158  159  160  161  162  163  164  165  166  167  168  169  170  171  172  173  174  175  176  177  178  179  180  181  182  183  184  185  186  187  188  189  190  191  192  193  194  195  196  197  198  199  200  201  202  203  204  205  206  207  208  209  210  211  212  213  214  215  216  217  218  219  220  221  222  223  224  225  226  227  228  229  230  231  232  233  234  235  236  237  238  239  240  241  242  243  244  245  246  247  248  249  250  251  252  253  254  255  256  257  258  259  260  261  262  263  264  265  266  267  268  269  270  271  272  273  274  275  276  277  278  279  280  281  282  283  284  285  286  287  288  289  290  291  292  293  294  295  296  297  298  299  300  301  302  303  304  305  306  307  308  309  310  311  312  313  314  315  316  317  318  319  320  321  322  323  324  325  326  327  328  329  330  331  332  333  334  335  336  337  338  339  340  341  342  343  344  345  346  347  348  349  350  351  352  353  354  355  356  357  358  359  360  361  362  363  364  365  366  367  368  369  370  371  372  373  374  375  376  377  378  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410  411  412  413  414  415  416  417  418  419  420  421  422  423  424  425  426  427  428  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588  589  590  591  592  593  594  595  596  597  598  599  600  601  602  603  604  605  606  607  608  609  610  611  612  613  614  615  616  617  618  619  620  621  622  623  624  625  626  627  628  629  630  631  632  633  634  635  636  637  638  639  640  641  642  643  644  645  646  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662  663  664  665  666  667  668  669  670  671  672  673  674  675  676  677  678  679  680  681  682  683  684  685  686  687  688  689  690  691  692  693  694  695  696  697  698  699  700  701  702  703  704  705  706  707  708  709  710  711  712  713  714  715  716  717  718  719  720  721  722  723  724  725  726  727  728  729  730  731  732  733  734  735  736  737  738  739  740  741  742  743  744  745  746  747  748  749  750  751  752  753  754  755  756  757  758  759  760  761  762  763  764  765  766  767  768  769  770  771  772  773  774  775  776  777  778  779  780  781  782  783  784  785  786  787  788  789  790  791  792  793  794  795  796  797  798  799  800  801  802  803  804  805  806  807  808  809  810  811  812  813  814  815  816  817  818  819  820  821  822  823  824  825  826  827  828  829  830  831  832  833  834  835  836  837  838  839  840  841  842  843  844  845  846  847  848  849  850  851  852  853  854  855  856  857  858  859  860  861  862  863  864  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880  881  882  883  884  885  886  887  888  889  890  891  892  893  894  895  896  897  898  899  900  901  902  903  904  905  906  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 
<?php
/**
 * Bookings and Appointment Plugin for WooCommerce
 *
 * Allow Bookings to be edited from Cart and Checkout Page
 *
 * @author      Tyche Softwares
 * @package     BKAP/View-Bookings
 * @since       1.7
 * @category    Classes
 */
    
class view_bookings{

    /**
     * Default constructor
     *
     * @since 1.7
     */
    
    public function __construct() {
        add_action( 'admin_init', array( &$this, 'bkap_data_export' ) );
        
    }
    
   /**
    * This function adds a page on View Bookings submenu which displays the orders with the booking details. 
    * The orders which are cancelled or refunded are not displayed.
    *
    * @since 1.7
    * @global object $wpdb Global wpdb object
    */

   public static function bkap_woocommerce_history_page() {

        if ( isset( $_GET['action'] ) ) {
            $action = $_GET['action'];
        } else {
            $action = '';
        }
        
        if ( $action == 'history' || $action == '' ) {
            $active_settings = "nav-tab-active";
        }

        if ( $action == 'history' || $action == '' ) {
            global $wpdb;
            
            include_once( 'class-view-bookings-table.php' );
            $bookings_table = new WAPBK_View_Bookings_Table();
            $bookings_table->bkap_prepare_items();
            if ( !isset( $_GET[ 'item_id' ] ) || ( isset( $_GET[ 'item_id' ] ) && $_GET[ 'item_id' ] == 0 ) ) {
            ?>
            <div class="wrap">
            <h2><?php _e( 'All Bookings', 'woocommerce-booking' ); ?></h2>
                <?php do_action( 'bkap_bookings_page_top' ); ?>
                
                <form id="bkap-view-bookings" method="get" action="<?php echo admin_url( 'admin.php?page=woocommerce_history_page' ); ?>">
                
                    <div id="bkap_update_event_message"></div>
                        <?php
                        //get the current logged in user
                        $user_id = get_current_user_id();
                         
                        // get the user role
                        $user = new WP_User( $user_id );
                        if( 'tour_operator' == $user->roles[ 0 ] ) {
                            $url = admin_url( 'edit.php?post_type=bkap_booking' );
                        } else {
                            $url = admin_url( 'edit.php?post_type=bkap_booking' );
                        }
                        ?>
                    <p id="bkap_add_order">
                        <a href="<?php echo esc_url( admin_url( 'admin.php?page=bkap_create_booking_page' ) ); ?>" class="button-secondary" id="bkap_create_booking" ><?php _e( 'Create Booking', 'woocommerce-booking' ); ?></a>
                         <a href="
                            <?php echo isset ( $_GET['booking_view'] ) && $_GET['booking_view'] == "booking_calender" ? $url : esc_url( add_query_arg( 'booking_view', 'booking_calender' ) ) ;  ?>" 
                            class="button-secondary">
                            <?php isset ( $_GET['booking_view'] ) && $_GET['booking_view'] == "booking_calender" ? _e( 'View Booking Listing', 'woocommerce-booking' )  : _e ( 'Calendar View', 'woocommerce-booking' );  ?>
                        </a>
                    <?php 
                    if ( !isset( $_GET['booking_view'] ) ) {
                        $gcal = new BKAP_Gcal();
                        $total_bookings_to_export = bkap_common::bkap_get_total_bookings_to_export( $user_id );
                        
                        if( 'tour_operator' == $user->roles[ 0 ] ) {
                            $display_button_setting = esc_attr( get_the_author_meta( 'tours_add_to_calendar_view_booking', $user_id ) );
                        } else {
                            $display_button_setting =  get_option( 'bkap_admin_add_to_calendar_view_booking' );
                        }
                         
                        if( $gcal->get_api_mode( $user_id ) == "directly" && 'on' == $display_button_setting ) {
                        ?>
                        
                        <input type="button" class="button-secondary" id="bkap_admin_add_to_calendar_booking" style="float:right;" value="<?php _e( 'Add to Google Calendar', 'woocommerce-booking' ); ?>">
                            
                            <script type="text/javascript">
                            jQuery( document ).ready( function(){ 
                                jQuery( "#bkap_admin_add_to_calendar_booking" ).on( 'click', function() {
                                    <?php if ( count( $total_bookings_to_export ) > 0 ) {?>
                                        var orders_to_export = "<?php echo count( $total_bookings_to_export ); ?>";
                                        jQuery( "#bkap_update_event_message" ).html( "Total orders to export " +  orders_to_export + " ... " );
                                        var data = {
                                               user_id: <?php echo $user_id; ?>, 
                                               action: "bkap_admin_booking_calendar_events"
                                        };
                                        jQuery.post( "<?php echo get_admin_url(); ?>/admin-ajax.php", data, function( response ) {
                                           jQuery( "#bkap_update_event_message" ).html( orders_to_export + " bookings have been exported to your Google Calendar. Please refresh your Google Calendar." );
                                        });
                                    <?php } else {?>
                                    jQuery( "#bkap_update_event_message" ).html( "No pending orders left to be exported." );
                                    <?php }?>
                                });
                            });
                            </script>
                        <?php 
                        }
                        ?>
                        <a href="<?php echo esc_url( add_query_arg( 'download', 'data.print' ) ); ?>" target="_blank" style="float:right;" class="button-secondary"><?php _e( 'Print', 'woocommerce-booking' ); ?></a>
                        <a href="<?php echo esc_url( add_query_arg( 'download', 'data.csv' ) ); ?>" style="float:right;" class="button-secondary"><?php _e( 'CSV', 'woocommerce-booking' ); ?></a>
                        <?php do_action( 'bkap_bookings_print_summary' ); ?>
                        <?php }?>
                    </p>
        
                    <input type="hidden" name="page" value="woocommerce_history_page" />

                    <?php if ( isset($_GET['booking_view'] ) && ( $_GET['booking_view'] == 'booking_calender' ) ) {
                        ?>
                            <h2><?php _e( 'Calendar View', 'woocommerce-booking' ); ?></h2>
                            <div id="bkap_events_loader" style="font-size: medium;">Loading Calendar Events....<img src=<?php echo plugins_url() . "/woocommerce-booking/images/ajax-loader.gif"; ?>></div>
                            <div id='calendar'></div>
                        <?php }else{
                     ?>
                    <?php $bookings_table->views() ?>
                    
                    <?php 
                           $bookings_table->advanced_filters();  
                           $bookings_table->advanced_filters_by_date();
                           
                           $bookings_table->bkap_order_status();
                           $bookings_table->bkap_vehicle_filter();
                           
                      ?>
                    <?php $bookings_table->display() ?>
                    <?php } ?>
                
                    
                    </form>
                <?php do_action( 'bkap_bookings_page_bottom' ); ?>
            </div>
            <?php 
            }
        }
    }
    
    /**
     * This function will download CSV or Print Bookings based on the CSV on Print button is clicked
     *
     * @since 2.0
     * @global $wpdb Global wpdb object
     */
    
    public function bkap_data_export() {    
        global $wpdb;
        
        $tab_status = '';
        
        if ( isset( $_GET['status'] ) ) {
            $tab_status = $_GET['status'];
        }
        
        if (isset( $_GET['duration_select'] ) && $_GET['duration_select'] !='' && !( isset( $_GET['s'] ) ) ){
            $tab_status = 'custom';
        }
        
        if ( isset( $_GET['download'] ) && ( $_GET['download'] == 'data.csv' ) && 
            isset( $_GET['page'] ) && $_GET['page'] = 'woocommerce_history_page' ) {
            $report  = view_bookings::generate_data( $tab_status );
            $csv     = view_bookings::generate_csv( $report );
            
            header("Content-type: application/x-msdownload");
            header("Content-Disposition: attachment; filename=data.csv");
            header("Pragma: no-cache");
            header("Expires: 0");
            echo "\xEF\xBB\xBF";
            echo $csv;
            exit;
        }else if( isset( $_GET['download'] ) && ( $_GET['download'] == 'data.print' ) && 
            isset( $_GET['page'] ) && $_GET['page'] = 'woocommerce_history_page' ) {
            $report              = view_bookings::generate_data($tab_status);
            
            $print_data_columns  = "
                                    <tr>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Order ID', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Customer Name', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Product Name', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Check-in Date', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Check-out Date', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Booking Time', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Quantity', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Amount', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Order Date', 'woocommerce-booking' )."</th>
                                    </tr>";
            $print_data_row_data =  '';
            
            foreach ( $report as $key => $value ) {
                // Currency Symbol
                // The order currency is fetched to ensure the correct currency is displayed if the site uses multi-currencies
                $the_order          = wc_get_order( $value->order_id );
                $currency           = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $the_order->get_order_currency() : $the_order->get_currency();
                $currency_symbol    = get_woocommerce_currency_symbol( $currency );
                 
                $print_data_row_data .= "<tr>
                                        <td style='border:1px solid black;padding:5px;'>".$value->order_id."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->customer_name."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->product_name."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->checkin_date."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->checkout_date."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->time."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->quantity."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$currency_symbol . $value->amount."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->order_date."</td>
                                        </tr>";
            }
            $print_data_columns  =   apply_filters( 'bkap_view_bookings_print_columns', $print_data_columns );
            $print_data_row_data =   apply_filters( 'bkap_view_bookings_print_rows', $print_data_row_data, $report );
            $print_data          =   "<table style='border:1px solid black;border-collapse:collapse;'>" . $print_data_columns . $print_data_row_data . "</table>";
            $print_data          =   "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><table style='border:1px solid black;border-collapse:collapse;'>" . $print_data_columns . $print_data_row_data . "</table></body></html>";
            echo $print_data;
            ?>
            
            <?php 
            exit;
        } 
        do_action( 'bkap_add_print_summary_data', $tab_status );
    }

    /**
     * This function will generate the data require for CSV and Print of bookings
     *
     * @since 2.0
     * @param string $tab_status selected filter E.g status for Booking from today onwards is 'future'
     * @global object $wpdb Global wpdb object
     * @return array $report All booking details required to show on old View Bookings page.
     */
    
    function generate_data( $tab_status ) {
        global $wpdb;
        
        $results = array();
        $current_time = current_time( 'timestamp' );
        $current_date = date( "Y-m-d", $current_time );

        $get_s = '';
        if ( isset( $_GET[ 's' ] ) ) {
            $get_s = $_GET[ 's' ];
        }
        
        $get_duration = '';
        if ( isset(  $_GET['duration_select'] ) ) {
            $get_duration =  $_GET['duration_select'];
        }
        
        if ( $get_s != '' ) {
            if ( is_numeric( $get_s ) ) {
                $order_number = $get_s;
            } else {
                // strtotime does not support all date formats. hence it is suggested to use the "DateTime date_create_from_format" fn
                $date_formats    =   bkap_get_book_arrays( 'bkap_date_formats' );
                // get the global settings to find the date formats
                $global_settings =   json_decode( get_option( 'woocommerce_booking_global_settings' ) );
                $date_format_set =   $date_formats[ $global_settings->booking_date_format ];
                $date_formatted  =   date_create_from_format( $date_format_set, $get_s );
                if ( isset( $date_formatted ) && $date_formatted != '' ) {
                    $date = date_format( $date_formatted, 'Y-m-d' );
                }
        
                if ( strpos( $get_s, '-' ) && substr_count( $get_s, '-' ) == '1' ) {
                    $time_array = explode( '-', $get_s );
                    if ( isset( $time_array[0] ) && $time_array[0] != '' ) {
                        $from_time = date( 'G:i', strtotime( trim( $time_array[0] ) ) );
                    }
                    if ( isset( $time_array[1] ) && $time_array[1] !== '' ) {
                        $to_time = date( 'G:i', strtotime( trim( $time_array[1] ) ) );
                    }
                }
        
                $search_result =  $get_s;
            }
        }
        
        if ( isset( $_GET[ 'bkap_start_date' ] ) && isset( $_GET[ 'bkap_end_date' ] ) ) {
            $start_date_ts = strtotime( $_GET[ 'bkap_start_date' ] );
            $start_date    = date( "Y-m-d",$start_date_ts);
             
            $end_date_ts = strtotime( $_GET[ 'bkap_end_date' ] );
            $end_date    = date( "Y-m-d",$end_date_ts);
        
            $user_set_from_time = false;
            $user_set_to_time = false;
        
            if ( isset( $_GET[ 'bkap_from_time' ] ) && $_GET[ 'bkap_from_time' ] != '' ) {
                $user_selected_from_time = $_GET[ 'bkap_from_time' ];
                $user_set_from_time = true;
            }else{
                $user_selected_from_time = "00:00";
            }
        
            if ( isset( $_GET[ 'bkap_to_time' ] ) && $_GET[ 'bkap_to_time' ] != '' ) {
                $user_selected_to_time   = $_GET[ 'bkap_to_time' ];
                $user_set_to_time = true;
            }else{
                $user_selected_to_time = "23:59";
            }
        
            $time_query = '';
            if ( $user_selected_from_time && $user_set_to_time ) {
                //          $user_selected_to_time   = $_GET ['bkap_to_time'];
                //          $user_selected_from_time = $_GET ['bkap_from_time'];
        
                $time_query = " AND DATE_FORMAT( STR_TO_DATE( a1.`from_time` ,  '%H:%i' ) ,  '%H:%i' ) BETWEEN  '".$user_selected_from_time."' AND  '".$user_selected_to_time."' " ;
            }
        }
        
        if ( $tab_status == 'future' ) {
            
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a1.start_date >= '".$current_date."' ORDER BY a2.order_id DESC";
            $query_results         = $wpdb->get_results( $booking_query );
        }else if ( $tab_status == 'today_checkin' ) {
            
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a1.start_date = '".$current_date."' ORDER BY a2.order_id DESC";
            $query_results         = $wpdb->get_results( $booking_query );
        }else if ( $tab_status == 'today_checkout' ) {
            
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a1.end_date = '".$current_date."' ORDER BY a2.order_id DESC";
            $query_results         = $wpdb->get_results( $booking_query );
        }else if ( $tab_status == 'custom' ) {
            
            
            $start_date_ts = strtotime($_GET['bkap_start_date']);
            $start_date    = date( "Y-m-d",$start_date_ts);
                
            $end_date_ts = strtotime($_GET['bkap_end_date']);
            $end_date    = date( "Y-m-d",$end_date_ts);
            
            if (isset($_GET ['bkap_from_time']) && $_GET ['bkap_from_time'] !=''){
                $user_selected_from_time = $_GET ['bkap_from_time'];
            }else{
                $user_selected_from_time = "00:00";
            }
            
            if ( isset($_GET ['bkap_to_time']) && $_GET ['bkap_to_time'] !='' ){
                $user_selected_to_time   = $_GET ['bkap_to_time'];
            }else{
                $user_selected_to_time = "23:59";
            }

            $time_query = '';
            if ( isset($_GET ['bkap_to_time']) && $_GET ['bkap_to_time'] !='' && isset($_GET ['bkap_from_time']) && $_GET ['bkap_from_time'] !='' ){
                $user_selected_to_time   = $_GET ['bkap_to_time'];
                $user_selected_from_time = $_GET ['bkap_from_time'];
            
                $time_query = " AND DATE_FORMAT( STR_TO_DATE( a1.`from_time` ,  '%H:%i' ) ,  '%H:%i' ) BETWEEN  '".$user_selected_from_time."' AND  '".$user_selected_to_time."' " ;
            }
            
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a1.start_date BETWEEN '".$start_date."' AND '".$end_date ."' ". $time_query . " ORDER BY a2.order_id DESC";
            
            $query_results   = $wpdb->get_results( $booking_query );
            
        } else if ( isset( $get_duration ) && $get_duration != '' && $get_s == '' ) {
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id AND a1.start_date BETWEEN '".$start_date."' AND '".$end_date ."' ". $time_query . " AND a2.order_id IN ( SELECT ID FROM `" . $wpdb->prefix . "posts` WHERE post_type = 'shop_order' AND post_status NOT IN ('wc-cancelled', 'wc-refunded', 'trash', 'wc-failed', '') ) ORDER BY a2.order_id DESC";
            
            $query_results   = $wpdb->get_results( $booking_query );
        } else {
            
            $booking_query   = "SELECT a1.post_id,a1.start_date,a1.end_date,a1.from_time,a1.to_time,a2.booking_id,a2.order_id FROM `".$wpdb->prefix."booking_history` AS a1,`".$wpdb->prefix."booking_order_history` AS a2 WHERE a1.id = a2.booking_id ORDER BY a2.order_id DESC";
            $query_results         = $wpdb->get_results( $booking_query );
        }
        
        $results = array();
        
        $_status = $tab_status;
        
        switch ( $_status ) {
            case 'pending_confirmation':
                $_status = 'pending-confirmation';
                break;
            case 'unpaid':
                $_status = 'confirmed';
                break;
            case 'future':
                $_status = 'paid';
                break;
            case 'today_checkout':
                $_status = 'paid';
                break;
            case 'today_checkin':
                $_status = 'paid';
                break;
            default:
                $_status = '';
                break;
        
        }
        
        foreach ( $query_results as $key => $value ) {
            $order_id = $value->order_id;
        
            $get_items_sql  = $wpdb->get_results( $wpdb->prepare( "SELECT order_item_id, order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = %s", $order_id, 'line_item' ) );
             
            foreach ( $get_items_sql as $i_key => $i_value ) {
                $get_items = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key IN ( '_product_id', '_wapbk_booking_status' ) AND order_item_id = %d ORDER BY FIELD( meta_key, '_product_id', '_wapbk_booking_status' )" , $i_value->order_item_id ) );
            }
                 
            $include_status   = 'NO';
        
            for( $i = 0; $i < count( $get_items); $i++ ) {
                
                $item_values[ 'product_id' ] = $get_items[$i]->meta_value;
                if ( isset( $get_items[$i + 1]->meta_value ) ) {
                   $item_values[ 'wapbk_booking_status' ] = $get_items[$i + 1]->meta_value;
                }
                $booking_status = '';
                if ( $value->post_id == $item_values[ 'product_id' ] ) {
                    if ( isset( $item_values[ 'wapbk_booking_status' ] ) )  {
                        $booking_status = $item_values[ 'wapbk_booking_status' ];
                    }
        
                    if ( isset( $booking_status ) ) {
                        if ( $_status == $booking_status ) {
                            $include_status   = 'YES';
                        } else if ( ( $booking_status != 'confirmed' && $booking_status != 'pending-confirmation' ) && ( 'paid' == $_status ) ) {
                            $include_status   = 'YES';
                        } else if( $booking_status != 'cancelled' && '' == $_status ) {
                            $include_status   = 'YES';
                        }
                    }
                }
                $i++;
            }
            if( $include_status == 'YES' ) {
                $results[] = $query_results[ $key ];
            }
        }
        
        // Date formats
        $date_formats     = bkap_get_book_arrays( 'bkap_date_formats' );
        // get the global settings to find the date & time formats
        $global_settings  = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
        $date_format_set  = $date_formats[ $global_settings->booking_date_format ];
        //Time format
        $time_format_set  = $global_settings->booking_time_format;
        $report           = array();
        $i                = 0;
        
        foreach ( $results as $key => $value ) {
            $checkout_date   = $time = '';
            $res_order_id = $value->order_id;
            
            if ( false !== get_post_status( $res_order_id ) ) {
                $order           = new WC_Order( $res_order_id );
            }else{
                continue;
            }
            
            // check if the order is refunded, trashed or cancelled
            $order_status = $order->get_status();
            $order_status = "wc-$order_status";
            if( isset( $order_status ) && ( $order_status != 'wc-cancelled' ) && ( $order_status != 'wc-refunded' ) && ( $order_status != 'trash' ) && ( $order_status != '' ) && ( $order_status != 'wc-failed' ) && ( 'auto-draft' != $order_status ) ) {
                
                $report[ $i ]                   = new stdClass();
                // Order ID
                $report[ $i ]->order_id         = $res_order_id;
                // Booking ID
                $report[ $i ]->booking_id       = $value->booking_id;
                // Customer Name
                if ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) {
                    $report[ $i ]->customer_name = $order->billing_first_name . " " . $order->billing_last_name;
                } else {
                    $report[ $i ]->customer_name    = $order->get_billing_first_name() . " " . $order->get_billing_last_name();
                }
                // Product ID
                $report[ $i ]->product_id       = $value->post_id;
                
                // Check-in Date
                $report[ $i ]->checkin_date     = date( $date_format_set, strtotime( $value->start_date ) );
                
                // Checkout Date
                if ( $value->end_date != '1970-01-01' && $value->end_date != '0000-00-00' ) {
                    $report[ $i ]->checkout_date = date( $date_format_set, strtotime( $value->end_date ) );
                }else {
                    $report[ $i ]->checkout_date = '';
                }
                
                // Booking Time
                $time = '';
                
                if ( $value->from_time != "" ) {
                    $time = $value->from_time;
                }
                
                if ( $value->to_time != "" ) {
                    $time .=  " - " . $value->to_time;
                }
                
                if ( $time != '' ) {
                    
                    if ( $time_format_set == 12 ) {
                        $from_time    = date( 'h:i A', strtotime( $value->from_time ) );
                        $to_time      = date( 'h:i A', strtotime( $value->to_time ) );
                        $time         = $from_time . " - " . $to_time;
                    }
                }
                
                $report[$i]->time   = $time;
                // Quantity & amount
                $get_items_sql  = $wpdb->get_results( $wpdb->prepare( "SELECT order_item_id, order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = %s", $res_order_id, 'line_item' ) );
            
                foreach ( $get_items_sql as $i_key => $i_value ) {
                    $get_items = $wpdb->get_results( $wpdb->prepare( "SELECT order_item_id, meta_key, meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key IN ( '_product_id', '_qty', '_line_total', '_line_tax' ) AND order_item_id = %d ORDER BY FIELD( meta_key, '_product_id', '_qty', '_line_total', '_line_tax' )" , $i_value->order_item_id ) );
                }
                $get_quantity = array();
        
                foreach ( $get_items as $get_key => $get_value ) {
                    switch ( $get_value->meta_key ) {
                        case '_product_id':
                            $get_quantity[ $get_value->order_item_id ][ 'product_id' ] = $get_value->meta_value;
                            break;
                        case '_qty':
                            $get_quantity[ $get_value->order_item_id ][ 'qty' ] = $get_value->meta_value;
                            break;
                        case '_line_total':
                            $get_quantity[ $get_value->order_item_id ][ 'line_total' ] = $get_value->meta_value;
                            break;
                        case '_line_tax':
                            $get_quantity[ $get_value->order_item_id ][ 'line_tax' ] = $get_value->meta_value;
                            break;
                        default:
                            break;                  
                    }
                    $get_quantity[ $get_value->order_item_id ]['item_meta'] = get_metadata( 'order_item', $get_value->order_item_id );
                }               

                // The array needs to be reversed as we r displaying the last item first
                $get_quantity       = array_reverse( $get_quantity, true );
                
                foreach( $get_quantity as $k => $v ) {
                    $product_exists     =  'NO';
                    $duplicate_of       =  bkap_common::bkap_get_product_id( $v[ 'product_id' ] );
                    $attributes_array   =  array();
                    $var                =  '';
                    
                    $attributes         =  get_post_meta( $duplicate_of , '_product_attributes' );
                    
                    $product            =  wc_get_product( $duplicate_of );
                    $product_type = '';
                    if ( is_object( $product ) ) { // this is to ensure the product exists
                        $product_type       =  $product->get_type();
                    }
                    
                    if ( isset( $product_type ) && $product_type == 'variable' ) {
                    
                            foreach ( $attributes[0] as $attributes_key => $attributes_value ){
                        
                                $attribute_name = $attributes_key;
                            
                                if ( array_key_exists ( $attribute_name, $v ) ){
                                    $attributes_array [$attributes_value['name']] = $v[$attribute_name];
                                }
                                if ( isset( $attributes_array [ $attributes_value[ 'name' ] ] ) ) {
                                   $var .= "<br>".$attributes_value['name']." : ".$attributes_array [$attributes_value['name']];
                                }
                            
                            }
                    }
                    
                    if ( $duplicate_of == $value->post_id ) {
                        
                        foreach ( $report as $book_key => $book_value ) {
                            
                            if ( $book_value->order_id == $res_order_id && $duplicate_of == $book_value->product_id ) {
                                
                                if ( isset( $book_value->item_id ) && $k == $book_value->item_id ) {
                                    $product_exists = 'YES';
                                }
                            }
                        } 
                        if ( $product_exists == 'NO' ) {
                            
                            $selected_quantity   = $v['qty'];
                            $amount              = $v['line_total'] + $v['line_tax'];
                            $report[$i]->item_id = $k;
                            break;
                        }
                    }
                }
                
                $report[ $i ]->quantity     = $selected_quantity;
                $report[ $i ]->amount       = $amount;
                
                // Product Name
                $report[ $i ]->product_name     = get_the_title( $value->post_id ).$var;
                // Order Date
                $order_date = '';
                if ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) {
                    $order_date = $order->completed_date;
                } else {
                    $order_post = get_post( $res_order_id );
                    $post_date = strtotime ( $order_post->post_date );
                    $order_date = date( 'Y-m-d H:i:s', $post_date );
                    
                 /*   $order_completed_obj = $order->get_date_completed();
                    $order_created_obj = $order->get_date_created();
                    
                    if ( isset( $order_completed_obj ) && count( $order_completed_obj ) > 0 ) {
                        $order_date      = $order_completed_obj->format('Y-m-d H:i:s');
                    } else {
                        $order_date      = $order_created_obj->format('Y-m-d H:i:s');
                    } */
                }
                $report[ $i ]->order_date = $order_date;
                
                $i++;
            }
        }
        
        //sort for order Id
        if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'ID' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                    usort( $report, array( __CLASS__ , "bkap_order_id_asc" ) );
            }else {
                    usort( $report, array( __CLASS__ , "bkap_order_id_dsc" ) );
            }
        }
        // sort for amount
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'amount' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                    usort( $report, array( __CLASS__ , "bkap_amount_asc" ) );
            }else {
                    usort( $report, array( __CLASS__ , "bkap_amount_dsc" ) );
            }
        }
        // sort for qty
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'quantity' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                    usort( $report, array( __CLASS__ ,"bkap_quantity_asc" ) );
            }else {
                    usort( $report,  array( __CLASS__ ,"bkap_quantity_dsc" ) );
            }
        }
        // sort for order date
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'order_date' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                    usort( $report, array( __CLASS__ , "bkap_order_date_asc" ) );
            }else {
                    usort( $report, array( __CLASS__ , "bkap_order_date_dsc" ) );
            } 
        }
        // sort for booking/checkin date
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'checkin_date' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                usort( $report, array( __CLASS__ , "bkap_checkin_date_asc" ) );
            }else {
                usort( $report, array( __CLASS__ , "bkap_checkin_date_dsc" ) );
            }
        }
        // sort for check out date
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'checkout_date' ) {
            
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                    usort( $report, array( __CLASS__ , "bkap_checkout_date_asc" ) );
             }else {
                    usort( $report, array( __CLASS__ , "bkap_checkout_date_dsc" ) );
            }
        }
        // sort for customer name
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'name' ) {
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                usort( $report, array( __CLASS__ , "bkap_name_asc" ) );
            }else {
                usort( $report, array( __CLASS__ , "bkap_name_dsc" ) );
            }
        }
        // sort for product name
        else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'product_name' ) {
            if ( isset( $_GET['order'] ) && $_GET['order'] == 'asc' ) {
                usort( $report, array( __CLASS__ , "bkap_product_name_asc" ) );
            }else {
                usort( $report, array( __CLASS__ , "bkap_product_name_dsc" ) );
            }
        }

        $search_results = array();
        
        if ( isset( $_GET['s'] ) && $_GET['s'] != '' ) {
        
            $date            = '';
            // strtotime does not support all date formats. hence it is suggested to use the "DateTime date_create_from_format" fn 
            $date_formats    = bkap_get_book_arrays( 'bkap_date_formats' );
            // get the global settings to find the date formats
            $global_settings = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
            $date_format_set = $date_formats[ $global_settings->booking_date_format ];
            $date_formatted  = date_create_from_format( $date_format_set, $_GET['s'] );
            
            if ( isset( $date_formatted ) && $date_formatted != '' ) {
                $date = date_format( $date_formatted, 'Y-m-d' );
            }
            
            $time = $from_time = $to_time = '';
            
            if ( strpos( $_GET['s'], '-' ) ) {
                $time_array = explode( '-', $_GET['s'] );
                
                if ( isset( $time_array[0] ) && $time_array[0] != '' ) {
                    $from_time = date( 'G:i', strtotime( trim( $time_array[0] ) ) );
                }
                
                if ( isset( $time_array[1] ) && $time_array[1] !== '' ) {
                    $to_time = date( 'G:i', strtotime( trim( $time_array[1] ) ) );
                }
                
                $time = $from_time . " - " . $to_time;
            }
            
            foreach ( $report as $key => $value ) {
                
                if ( is_numeric($_GET['s'] ) ) {
                    
                    if ( $value->order_id == $_GET['s'] ) {
                        $search_results[] = $report[ $key ];
                    }
                }
                else {
                    
                    foreach ( $value as $k => $v ) {
                        
                        if ( $k == 'checkin_date' || $k == 'checkout_date' && $date != '' ) {
                            $date_value_formatted = date_create_from_format( $date_format_set, $v );    
                            
                            if ( isset( $date_value_formatted ) && $date_value_formatted != '' ) {
                                $date_value = date_format( $date_value_formatted, 'Y-m-d' );
                                
                                if ( stripos( $date_value, $date ) !== false ) {
                                    $search_results[] = $report[ $key ];
                                }
                            }
                        }else if ( $k == 'booking_time' ) {
                            if ( isset( $v ) && $v != '' && $time != '' ) {
                                if ( stripos( $v, $time ) !== false ) {
                                    $search_results[] = $report[ $key ];
                                }
                            }
                        }
                        else {
                            if ( stripos( $v, $_GET['s'] ) !== false ) {
                                $search_results[] = $report[ $key ];
                            }
                        }
                    }
                }
            }
            
            if ( is_array( $search_results ) && count( $search_results ) > 0 ) {
                $report = $search_results;
            }
            else {
                $report = array();
            }
            
        }
        return apply_filters( 'bkap_bookings_export_data', $report );
    }

    /**
     * Function to sort the Order ids in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_order_id_asc( $value1, $value2 ) {
        return $value1->order_id - $value2->order_id;
    }

    /**
     * Function to sort the Order ids in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_order_id_dsc( $value1, $value2 ) {
        return $value2->order_id - $value1->order_id;
    }

    /**
     * Function to sort the amount in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_amount_asc( $value1, $value2 ) {
        return $value1->amount - $value2->amount;
    }

    /**
     * Function to sort the amount in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_amount_dsc ( $value1, $value2 ) {
        return $value2->amount - $value1->amount;
    }

    /**
     * Function to sort the quantity in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_quantity_asc( $value1, $value2 ) {
        return $value1->quantity - $value2->quantity;
    }

    /**
     * Function to sort the quantity in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_quantity_dsc( $value1, $value2 ) {
        return $value2->quantity - $value1->quantity;
    }

    /**
     * Function to sort the order date in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_order_date_asc( $value1, $value2 ) {
        return strtotime( $value1->order_date ) - strtotime( $value2->order_date );
    }

    /**
     * Function to sort the order date in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
     
    function bkap_order_date_dsc( $value1, $value2 ) {
        return strtotime( $value2->order_date ) - strtotime( $value1->order_date );
    }

    /**
     * Function to sort the check-in date in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_checkin_date_asc( $value1, $value2 ) {
        return strtotime( $value1->checkin_date) - strtotime( $value2->checkin_date );
    }

    /**
     * Function to sort the check-in date in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */
    
    function bkap_checkin_date_dsc( $value1, $value2 ) {
        return strtotime( $value2->checkin_date ) - strtotime( $value1->checkin_date );
    }

    /**
     * Function to sort the check-out date in ascending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */     
    
    function bkap_checkout_date_asc( $value1, $value2 ) {
        return strtotime( $value1->checkout_date ) - strtotime( $value2->checkout_date );
    }

    /**
     * Function to sort the check-out date in descending order
     *
     * @since 2.0
     * @param int $value1
     * @param int $value2
     * @return int
     */   
    
    function bkap_checkout_date_dsc( $value1, $value2 ) {
        return strtotime( $value2->checkout_date ) - strtotime( $value1->checkout_date );
    }

    /**
     * Function to sort the name date in ascending order
     *
     * @since 2.0
     * @param string $value1
     * @param string $value2
     * @return int
     */
    
    function bkap_name_asc( $value1, $value2 ) {
        return strcasecmp( $value1->customer_name, $value2->customer_name );
    }

    /**
     * Function to sort the name date in descending order
     *
     * @since 2.0
     * @param string $value1
     * @param string $value2
     * @return int
     */
    
    function bkap_name_dsc( $value1, $value2 ) {
        return strcasecmp( $value2->customer_name, $value1->customer_name );
    }

    /**
     * Function to sort the name date in ascending order
     *
     * @since 2.0
     * @param string $value1
     * @param string $value2
     * @return int
     */
    
    function bkap_product_name_asc( $value1, $value2 ) {
        return strcasecmp( $value1->product_name, $value2->product_name );
    }

    /**
     * Function to sort the name date in descending order
     *
     * @since 2.0
     * @param string $value1
     * @param string $value2
     * @return int
     */
    
    function bkap_product_name_dsc( $value1, $value2 ) {
        return strcasecmp( $value2->product_name, $value1->product_name );
    }

    /**
     * This function will create the string to be required for CSV download
     *
     * @since 2.0
     * @param array $report Array of all booking details
     * @return string $csv Returns the strings which is created based on the booking details 
     */
    
    function generate_csv( $report ) {
        
        // Column Names
        $csv               = 'Order ID,Customer Name,Product Name,Check-in Date, Check-out Date,Booking Time,Quantity,Amount, Order Date';
        $csv              .= "\n";
        
        foreach ( $report as $key => $value ) {
            // Order ID
            $order_id         = $value->order_id;
            // Customer Name
            $customer_name    = $value->customer_name;
            // Product Name
            $product_name     = $value->product_name;
            $product_name_array = explode( '<br>', $product_name );
            $product_name = implode( "\n", $product_name_array );
            
            // Check-in Date
            $checkin_date     = $value->checkin_date;
            // Checkout Date
            $checkout_date    = $value->checkout_date;
            // Booking Time
            $time             = $value->time;
            // Quantity & amount
            $selected_quantity= $value->quantity;
            $amount           = $value->amount;
            // Order Date
            $order_date       = $value->order_date;
            // Currency Symbol
            // The order currency is fetched to ensure the correct currency is displayed if the site uses multi-currencies
            $the_order          = wc_get_order( $value->order_id );
            $currency           = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $the_order->get_order_currency() : $the_order->get_currency();
            $final_amt          = strip_tags( html_entity_decode( wc_price( $amount, array( 'currency' => $currency ) ) ) );
            
            // Create the data row
            $csv             .= $order_id . ',' . $customer_name . ',"' . $product_name . '","' . $checkin_date . '","' . $checkout_date . '","' . $time . '",' . $selected_quantity . ',' . $final_amt . ',' . $order_date;
            $csv             .= "\n";  
        }
        $csv = apply_filters( 'bkap_bookings_csv_data', $csv, $report );
        return $csv;
    }
    
}

$view_bookings = new view_bookings();
API documentation generated by ApiGen