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 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 
<?php

/**
 * Bookings and Appointment Plugin for WooCommerce
 * 
 * Class for View Bookings
 *
 * @author   Tyche Softwares
 * @package  BKAP/View-Bookings
 * @category Classes
 */

if ( ! class_exists( 'BKAP_Bookings_View' ) ) {

    /**
     * Class for View Bookings
     * 
     * @since 4.1.0
     */

    class BKAP_Bookings_View {
    
        /**
         * Default constructor
         *
         * @since 4.1.0
         */

        public function __construct() {
            $this->type = 'bkap_booking';
    
            // Post title fields
            //add_filter( 'enter_title_here', array( $this, 'bkap_title' ), 1, 2 );

            add_action( 'admin_enqueue_scripts',                                array( &$this, 'bkap_post_enqueue' ) );
            // Admin Columns
            add_filter( 'manage_edit-' . $this->type . '_columns',              array( &$this, 'bkap_edit_columns' ) );
            add_action( 'manage_' . $this->type . '_posts_custom_column',       array( &$this, 'bkap_custom_columns' ), 2 );
            add_filter( 'manage_edit-' . $this->type . '_sortable_columns',     array( &$this, 'bkap_custom_columns_sort' ), 1 );
            add_filter( 'request',                                              array( $this, 'bkap_custom_columns_orderby' ) );
        
            // Setting class name for the primary column for view in mobile
            add_filter( 'list_table_primary_column',                            array( $this, 'list_table_primary_column' ), 10, 2 );
            // Altering the actions in the mobile view.
            add_filter( 'post_row_actions',                                     array( $this, 'row_actions' ), 100, 2 );

            // Filtering
            add_action( 'restrict_manage_posts',                                array( $this, 'bkap_filters' ) );
            add_filter( 'parse_query',                                          array( $this, 'bkap_filters_query' ) );
            add_filter( 'get_search_query',                                     array( $this, 'bkap_search_label' ) );
            
            // Search
            add_filter( 'parse_query',                                          array( $this, 'bkap_search_custom_fields' ) );
            
            // Actions
            add_filter( 'bulk_actions-edit-' . $this->type,                     array( $this, 'bkap_bulk_actions' ), 10, 1 );
            add_action( 'load-edit.php',                                        array( $this, 'bkap_bulk_action' ) );
            add_action( 'admin_footer',                                         array( $this, 'bkap_bulk_admin_footer' ), 10 );
            add_action( 'admin_notices',                                        array( $this, 'bkap_bulk_admin_notices' ) );
            
            // Message for old View Bookings page
            add_action( 'admin_notices',                                        array( $this, 'bkap_old_view' ) );
            
            // ajax action for confirming bookings
            add_action( 'wp_ajax_bkap-booking-confirm',                         array( $this, 'bkap_booking_confirmed' ) );

            add_action( 'admin_init',                                           array( &$this, 'bkap_export_data' ) );
            add_filter( 'months_dropdown_results',                              array( &$this, 'bkap_custom_date_dropdown' ));
            add_action( 'pre_get_posts',                                        array( &$this, 'bkap_date_meta_query') );
        }
        
        /**
         * Modify the date filter dropdown to show Booking months & year
         * 
         * @param mixed $months Current Months present
         * 
         * @global mixed $wpdb Global wpdb Object
         * 
         * @since 4.1.0
         * 
         * @return mixed Months having Booking Details
         * 
         * @hook months_dropdown_results
         */

        function bkap_custom_date_dropdown( $months ) {
            global $wpdb;

            $months = $wpdb->get_results( "
                        SELECT DISTINCT YEAR( meta_value ) AS year, 
                        MONTH(meta_value) AS month FROM {$wpdb->prefix}woocommerce_order_itemmeta
                        WHERE meta_key = '_wapbk_booking_date' OR meta_key = '_wapbk_checkout_date' ORDER BY meta_value DESC
                    ");

            return $months;
        }
        
        /**
         * Modify the date filter query to filter by booking start & end dates 
         * 
         * @param string $wp_query Query String to set
         * 
         * @since 4.1.0
         * 
         * @hook pre_get_posts
         */

        function bkap_date_meta_query( $wp_query ) {

            if ( is_admin() && $wp_query->is_main_query() && $wp_query->get( 'post_type' ) === 'bkap_booking' ) {
                    $m = $wp_query->get( 'm' );
        
                    if ( ! $meta_query = $wp_query->get( 'meta_query' ) ) // Keep meta query if there currently is one
                        $meta_query = array();
                
                    $meta_query[] = array(
                        array( 
                            'key' => '_bkap_start',
                            'value' => $m,
                            'compare' => 'LIKE',
                        ),
                        array(
                            'key' => '_bkap_end',
                            'value' => $m,
                            'compare' => 'LIKE',
                        )
                    );
    
        
                    $wp_query->set( 'meta_query', $meta_query );
                    $wp_query->set( 'm', null );
            }
        }

        /**
         * Enqueue Scripts on View Bookings Page
         * 
         * @since 4.1.0
         * 
         * @hook admin_enqueue_scripts
         */

        function bkap_post_enqueue() {
            
            $plugin_version_number = get_option( 'woocommerce_booking_db_version' );
            wp_enqueue_script( 'bkap-jquery-tip', plugins_url( '/js/jquery.tipTip.minified.js', __FILE__ ), '', $plugin_version_number, false );
            wp_enqueue_style( 'bkap-edit-bookings-css', plugins_url() . '/woocommerce-booking/css/edit-booking.css', null, $plugin_version_number );
         
        }

        /**
         * Change title boxes in admin.
         *
         * @param  string $text Text to be displayed
         * @param  WP_Post $post Post Object
         * @return string
         * 
         * @since 4.1.0
         * 
         * @hook enter_title_here
         */

        public function bkap_title( $text, $post ) {
            if ( 'bkap_booking' === $post->post_type ) {
                return __( 'Booking Title', 'woocommerce-booking' );
            }
            return $text;
        }

        /**
         * Set list table primary column for bookings.
         * @param  string $default Default Column
         * @param  string $screen_id Screen ID
         *
         * @return string Text to be displayed
         * 
         * @since 4.1.0
         * 
         * @hook list_table_primary_column
         */

        public function list_table_primary_column( $default, $screen_id ) {

            if ( 'edit-bkap_booking' === $screen_id ) {
                return 'bkap_id';
            }

            return $default;
        }

        /**
         * Set row actions for booking.
         *
         * @param  array $actions Current Actions
         * @param  WP_Post $post Booking Post Object
         *
         * @return array Actions
         * 
         * @since 4.1.0
         * 
         * @hook post_row_actions
         */

        public function row_actions( $actions, $post ) {
            if ( 'bkap_booking' === $post->post_type ) {

                if ( isset( $actions['inline hide-if-no-js'] ) ) {
                    unset( $actions['inline hide-if-no-js'] );
                }

                if ( isset( $actions['view'] ) ) {
                    unset( $actions['view'] );
                }

                return array_merge( array( 'id' => 'ID: ' . $post->ID ), $actions );
            }

            return $actions;
        }

        /**
         * Change the columns shown in admin.
         * 
         * @param array $exisitng_columns Exiting Columns Array
         * @return array Columns Modified Array
         * 
         * @since 4.1.0
         * 
         * @hook manage_edit-bkap_booking_columns
         */

        public function bkap_edit_columns( $existing_columns ) {
            if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
                $existing_columns = array();
            }
        
            unset( $existing_columns['comments'], $existing_columns['title'], $existing_columns['date'] );
        
            $columns                    = array();
            $columns["bkap_status"]     = '<span class="status_head tips" data-tip="' . esc_attr__( 'Status', 'woocommerce-booking' ) . '"></span>';
            $columns["bkap_id"]         = __( 'ID', 'woocommerce-booking' );
            $columns["bkap_product"]    = __( 'Booked Product', 'woocommerce-booking' );
            $columns["bkap_customer"]   = __( 'Booked By', 'woocommerce-booking' );
            $columns["bkap_order"]      = __( 'Order', 'woocommerce-booking' );
            $columns["bkap_start_date"] = __( 'Start Date', 'woocommerce-booking' );
            $columns["bkap_end_date"]   = __( 'End Date', 'woocommerce-booking' );
            $columns["bkap_qty"]        = __( 'Quantity', 'woocommerce-booking' );
            $columns["bkap_amt"]        = __( 'Amount', 'woocommerce-booking' );
            $columns["bkap_order_date"] = __( 'Order Date', 'woocommerce-booking' );            
            $columns["bkap_actions"]    = __( 'Actions', 'woocommerce-booking' ); 
        
            return array_merge( $existing_columns, $columns );
        }
         
        /**
         * Define our custom columns shown in admin.
         *
         * @param  string $column Custom Columns Array
         * @global object $post WP_Post 
         * 
         * @since 4.1.0
         * 
         * @hook manage_bkap_booking_posts_custom_column
         */

        public function bkap_custom_columns( $column ) {
            global $post;
        
            if ( get_post_type( $post->ID ) === 'bkap_booking' ) {
                $booking = new BKAP_Booking( $post->ID );
            }
        
            $product = $booking->get_product();
        
            $status = $booking->get_status();
            switch ( $column ) {
                case 'bkap_status' :
                    $booking_statuses = bkap_common::get_bkap_booking_statuses();
                    $status_label = ( array_key_exists( $status, $booking_statuses ) ) ? $booking_statuses[ $status ] : ucwords( $status );
                    echo '<span class="status-' . esc_attr( $status ) . ' tips" date-tip="' . esc_attr( $status_label ) . '">' . esc_html( $status_label ) . '</span>';
                    break;
                case 'bkap_id' :
                    printf( '<a href="%s">' . __( 'Booking #%d', 'woocommerce-booking' ) . '</a>', admin_url( 'post.php?post=' . $post->ID . '&action=edit' ), $post->ID );
                    break;
                case 'bkap_customer':
                    $customer = $booking->get_customer();
        
                    if ( $customer->email && $customer->name ) {
                        echo esc_html( $customer->name );
                    } else {
                        echo '-';
                    } 
                    break;
                case 'bkap_product':
                    $product = $booking->get_product();
                    $resource_id = $booking->get_resource();
        
                    if ( $product ) {
                        echo '<a href="' . admin_url( 'post.php?post=' . ( is_callable( array( $product, 'get_id' ) ) ? $product->get_id() : $product->id ) . '&action=edit' ) . '">' . $product->get_title() . '</a>';
                        
                        if( $resource_id != "" ){
                            $resource_title = $booking->get_resource_title();
                            echo '<br>( <a href="' . admin_url( 'post.php?post=' . $resource_id . '&action=edit' ) . '">' . $resource_title . '</a> )';
                        }
                    } else {
                        echo '-';
                    } 
                    break;
                case 'bkap_qty' :
                    $quantity = $booking->get_quantity();
                    echo "$quantity";
                    break;
                case 'bkap_amt' :
                    $amount = $booking->get_cost();
                    $final_amt = $amount * $booking->get_quantity();
                    $order_id = $booking->get_order_id();
                    
                    if ( absint( $order_id ) > 0 && false !== get_post_status( $order_id ) ) {
                        $the_order          = wc_get_order( $order_id );
                        $currency           = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $the_order->get_order_currency() : $the_order->get_currency();
                    } else {
                        // get default woocommerce currency
                        $currency = get_woocommerce_currency();
                    }
                    $currency_symbol    = get_woocommerce_currency_symbol( $currency );
                    
                    echo wc_price( $final_amt, array( 'currency' => $currency) );
                    break;
                case 'bkap_order':
                    $order = $booking->get_order();
                    if ( $order ) {
                        echo '<a href="' . admin_url( 'post.php?post=' . ( is_callable( array( $order, 'get_id' ) ) ? $order->get_id() : $order->id ) . '&action=edit' ) . '">#' . $order->get_order_number() . '</a> - ' . esc_html( wc_get_order_status_name( $order->get_status() ) );
                    } else {
                        echo '-';
                    } 
                    break;
                case 'bkap_start_date' :
                    echo $booking->get_start_date() . "<br>" . $booking->get_start_time();
                    break;
                case 'bkap_end_date' :
                    echo $booking->get_end_date() . "<br>" . $booking->get_end_time();
                    break;
                case 'bkap_order_date':
                    echo $booking->get_date_created();
                    break;
                case 'bkap_actions' :
                    echo '<p>';
                    $actions = array(
                        'view' => array(
                            'url'    => admin_url( 'post.php?post=' . $post->ID . '&action=edit' ),
                            'name'   => __( 'View', 'woocommerce-booking' ),
                            'action' => 'view',
                        ),
                    );
        
                    if ( in_array( $status, array( 'pending-confirmation' ) ) ) {
                        $actions['confirm'] = array(
                            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=bkap-booking-confirm&booking_id=' . $post->ID ), 'bkap-booking-confirm' ),
                            'name'   => __( 'Confirm', 'woocommerce-booking' ),
                            'action' => 'confirm',
                        );
                    }
        
                    $actions = apply_filters( 'bkap_view_bookings_actions', $actions, $booking );
        
                    foreach ( $actions as $action ) {
                        printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
                    }
                    echo '</p>';
                    break;
            }
        }
         
        /**
         * Sortable Columns List
         * @access public
         * @param mixed $columns Array of columns
         * @since 4.1.0
         *
         * @return array array of the columns keys to be displayed on the View Bookings page
         */

        public function bkap_custom_columns_sort( $columns ) {
            $custom = array(
                'bkap_id'          => 'bkap_id',
                //'bkap_product'     => 'bkap_product',
                'bkap_status'      => 'bkap_status',
                'bkap_start_date'  => 'bkap_start_date',
                'bkap_end_date'    => 'bkap_end_date',
                'bkap_order_date'  => 'bkap_order_date'
            );
            
            return wp_parse_args( $custom, $columns );
        }
         
        /**
         * For Sortable columns
         *
         * @access public
         * @param mixed $vars
         * @since 4.1.0
         *
         * @return array
         */

        public function bkap_custom_columns_orderby( $vars ) {
            if ( isset( $vars['orderby'] ) ) {
                if ( 'bkap_id' == $vars['orderby'] ) {
                    $vars = array_merge( $vars, array(
                        'orderby' => 'ID', // sort using the ID column in posts
                    ) );
                }
        
            /*    if ( 'bkap_product' == $vars['orderby'] ) {
                    $vars = array_merge( $vars, array(
                        'meta_key' => '_bkap_product_id',
                        'orderby'  => 'meta_value_num',
                    ) );
                } */ 
        
                if ( 'status' == $vars['orderby'] ) {
                    $vars = array_merge( $vars, array(
                        'orderby' => 'post_status', // sort using the post status
                    ) );
                } 
         
                if ( 'bkap_start_date' == $vars['orderby'] ) {
         
                    $vars = array_merge( $vars, array(
                        'meta_key' => '_bkap_start',
                        'orderby'  => 'meta_value_num',
                    ) );                    
                } 
        
                if ( 'bkap_end_date' == $vars['orderby'] ) {
                    $vars = array_merge( $vars, array(
                        'meta_key' => '_bkap_end',
                        'orderby'  => 'meta_value_num',
                    ) );
                }
                
                if ( 'bkap_order_date' == $vars['orderby'] ) {
                    $vars = array_merge( $vars, array(
                        'orderby'  => 'post_date',
                    ) );
                }
            } 
        
            return $vars;         
        }

        /**
         * Remove Edit link from the bulk actions
         * @param array $actions
         * @since 4.1.0
         *
         * @return array
         */

        function bkap_bulk_actions( $actions ) {
            if ( isset( $actions['edit'] ) ) {
                unset( $actions['edit'] );
            }
            return $actions;
        }
        
        /**
         * This functions will filter the bookings on the View Bookings page
         * @since 4.1.0
         * @global string $typenow page string
         * @global object $wp_query Query String to set
         *
         * @hook restrict_manage_posts
         */

        public function bkap_filters() {
            global $typenow, $wp_query;
    
            if ( $typenow !== $this->type ) {
                return;
            }           
            
            $filters = array();
    
            $products = bkap_common::get_woocommerce_product_list( false );
    
            foreach ( $products as $product ) {
                // check if a booking is present for that product
                $present = $this->bkap_check_booking_present( $product[1] );
                
                if ( $present ) {
                    $filters[ $product[1] ] = $product[0];
                }
    
            } 
    
            $output = '';
    
            if ( is_array( $filters ) && count( $filters ) > 0 ) {
                $output .= '<select name="filter_products">';
                $output .= '<option value="">' . __( 'All Bookable Products', 'woocommerce-booking' ) . '</option>';
    
                foreach ( $filters as $filter_id => $filter ) {
                    $output .= '<option value="' . absint( $filter_id ) . '" ';
    
                    if ( isset( $_REQUEST['filter_products'] ) ) {
                        $output .= selected( $filter_id, $_REQUEST['filter_products'], false );
                    }
    
                    $output .= '>' . esc_html( $filter ) . '</option>';
                }
  
                $output .= '</select>';
            }
    
            
            $views = array( 'today_onwards'  => 'Bookings From Today Onwards',
                            'today_checkin'  => 'Today Check-ins',
                            'today_checkout' => 'Today Checkouts',
                            'gcal'           => 'Imported Bookings',
             );
            
            $output .= '<select name="filter_views">';
            $output .= '<option value="">' . __( 'Select Booking Type', 'woocommerce-booking' ) . '</option>';
            
            foreach( $views as $v_key => $v_value ) {
    
                $output .= '<option value="' . $v_key . '" ';
            
                if ( isset( $_REQUEST['filter_views'] ) ) {
                    $output .= selected( $v_key, $_REQUEST['filter_views'], false );
                }
            
                $output .= '>' . esc_html( $v_value ) . '</option>';
            }
                
            $output .= '</select>';
                
            echo $output;
        }
        
        /**
         * Custom filter queries
         * @param $query
         * @global string $typenow page string
         * @global object $wp_query Query String to set
         * @since 4.1.0
         *
         * @hook parse_query
         */

        public function bkap_filters_query( $query ) {
            global $typenow, $wp_query;
        
            if ( $typenow === $this->type ) {
                
                $current_timestamp = current_time( 'timestamp' );
                $current_time = date( 'YmdHis', $current_timestamp );
                $current_date = date( 'Ymd', $current_timestamp );
                
                if ( ! empty( $_REQUEST['filter_products'] ) && ! empty( $_REQUEST['filter_views'] ) && empty( $query->query_vars['suppress_filters'] ) ) {
                     
                    switch ( $_REQUEST['filter_views'] ) {
                        case 'today_onwards':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_time,
                                    'compare' => '>=',
                                ),
                                array(
                                    'key'   => '_bkap_product_id',
                                    'value' => absint( $_REQUEST['filter_products'] ),
                                ),
                            );
                            break;
                        case 'today_checkin':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_date,
                                    'compare' => 'LIKE',
                                ),
                                array(
                                    'key'   => '_bkap_product_id',
                                    'value' => absint( $_REQUEST['filter_products'] ),
                                ),
                            );
                            break;
                        case 'today_checkout':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_end',
                                    'value' => $current_date,
                                    'compare' => 'LIKE',
                                ),
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_date,
                                    'compare' => 'NOT LIKE',
                                ),
                                array(
                                    'key'   => '_bkap_product_id',
                                    'value' => absint( $_REQUEST['filter_products'] ),
                                ),
                            );
                            break;
                        case 'gcal':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_gcal_event_uid',
                                    'value' => false,
                                    'compare' => '!=',
                                ),
                                array(
                                    'key'   => '_bkap_product_id',
                                    'value' => absint( $_REQUEST['filter_products'] ),
                                ),
                            );
                            break;
                    }
                } else if ( ! empty( $_REQUEST['filter_products'] ) && empty( $query->query_vars['suppress_filters'] ) ) {
                    $query->query_vars['meta_query'] = array(
                        array(
                            'key'   => '_bkap_product_id',
                            'value' => absint( $_REQUEST['filter_products'] ),
                        ),
                    );
                } else if ( ! empty( $_REQUEST['filter_views'] ) && empty( $query->query_vars['suppress_filters'] ) ) {
                     
                    switch ( $_REQUEST['filter_views'] ) {
                        case 'today_onwards':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_time,
                                    'compare' => '>=',
                                ),
                            );
                            break;
                        case 'today_checkin':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_date,
                                    'compare' => 'LIKE',
                                ),
                            );
                            break;
                        case 'today_checkout':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_end',
                                    'value' => $current_date,
                                    'compare' => 'LIKE',
                                ),
                                array(
                                    'key'   => '_bkap_start',
                                    'value' => $current_date,
                                    'compare' => 'NOT LIKE',
                                ),
                            );
                            break;
                        case 'gcal':
                            $query->query_vars['meta_query'] = array(
                                array(
                                    'key'   => '_bkap_gcal_event_uid',
                                    'value' => false,
                                    'compare' => '!=',
                                ),
                            );
                            break;
                    }
                }               
            }
        }
        
        /**
         * To get the search parameter when search is made on View booking page
         * @param $query
         * @global string $typenow page string
         * @global string $pagenow current page
         * @since 4.1.0
         *
         * @hook get_search_query
         */

        public function bkap_search_label( $query ) {
            global $pagenow, $typenow;
        
            if ( 'edit.php' !== $pagenow ) {
                return $query;
            }
        
            if ( $typenow != $this->type ) {
                return $query;
            }
        
            if ( ! get_query_var( 'booking_search' ) ) {
                return $query;
            }
        
            return wc_clean( $_GET['s'] );
        }
         
        /**
         * Search custom columns
         * @param object $wp WP Object
         * @global string $pagenow Current page
         * @global object $wpdb Global wpdb Object
         * @since 4.1.0
         *
         * @hook parse_query
         */

        public function bkap_search_custom_fields( $wp ) {
            global $pagenow, $wpdb;
        
            if ( 'edit.php' != $pagenow || empty( $wp->query_vars['s'] ) || $wp->query_vars['post_type'] !== $this->type || 'bkap_gcal_event' == $this->type ) {
                return $wp;
            }
        
            $term = wc_clean( $_GET['s'] );
        
            if ( is_numeric( $term ) ) {
                // check if a booking exists by this ID
                if ( false !== get_post_status( $term ) && 'bkap_booking' === get_post_type( $term ) )
                    $booking_ids = array( $term );
                else { // else assume the numeric value is an order ID
                    if ( function_exists( 'wc_order_search' ) ) {
                        $order_ids = wc_order_search( wc_clean( $_GET['s'] ) );
                        $booking_ids = $order_ids ? bkap_common::get_booking_ids_from_order_id( $order_ids ) : array( 0 );
                         
                        if ( is_array( $booking_ids ) && count( $booking_ids ) == 0 ) {
                            $booking_ids = array( 0 );
                        }
                    }
                }
                 
            } else {

                $search_string = esc_attr($_GET['s']);
              
                $white_space = strpos( $search_string, ' ' );
                
                if( $white_space > 0 ) { 
                    
                    $search_texts = explode(" ", $search_string );
                   
                    $regex_text = implode( "|", $search_texts );
                } else {
                    $regex_text = $search_string;
                }

                $search_fields = array_map( 'wc_clean', array(
                    '_billing_first_name',
                    '_billing_last_name',
                    '_billing_company',
                    '_billing_address_1',
                    '_billing_address_2',
                    '_billing_city',
                    '_billing_postcode',
                    '_billing_country',
                    '_billing_state',
                    '_billing_email',
                    '_billing_phone',
                    '_shipping_first_name',
                    '_shipping_last_name',
                    '_shipping_address_1',
                    '_shipping_address_2',
                    '_shipping_city',
                    '_shipping_postcode',
                    '_shipping_country',
                    '_shipping_state',
                ) );
                
                // Search orders
                $order_ids = $wpdb->get_col("
                        SELECT post_id
                        FROM {$wpdb->postmeta}
                        WHERE meta_key IN ('" . implode( "','", $search_fields ) . "')
                        AND meta_value REGEXP '". $regex_text ."'"
                );
                
                //Search query for date
                $timestamp = strtotime( $term );                
                if( empty( $order_ids ) && false !== $timestamp ) {

                    $date = date( 'Y-m-d', $timestamp );
                    $order_ids = $wpdb->get_col(
                        $wpdb->prepare( "
                            SELECT post_id
                            FROM {$wpdb->postmeta}
                            WHERE meta_key = '_bkap_order_item_id' AND meta_value IN 
                            ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta where ( meta_key = '_wapbk_booking_date' OR meta_key = '_wapbk_checkout_date' ) AND meta_value = %s )",
                            esc_attr( $date )
                        )
                    );

                    $booking_ids = $order_ids;
                }
                
                //If the search is not for date, search for product name
                if( empty( $order_ids ) ) {
                    $order_ids = $wpdb->get_col(
                        $wpdb->prepare( "
                            SELECT post_id
                            FROM {$wpdb->postmeta}
                            WHERE ( meta_key = '_bkap_product_id' )
                            AND meta_value IN ( SELECT ID from {$wpdb->posts} WHERE post_title LIKE '%%%s%%' ) ",
                            esc_attr( $_GET['s'] )
                        )
                    );
                    
                    $booking_ids = $order_ids;
                }
                
               // ensure db query doesn't throw an error due to empty post_parent value
               $order_ids = empty( $order_ids ) ? array( '-1' ) : $order_ids;
    
                // so we know we're doing this
                if( empty( $booking_ids ) ) {
                    $booking_ids = array_merge(
                    $wpdb->get_col( "
                        SELECT ID FROM {$wpdb->posts}
                        WHERE post_parent IN (" . implode( ',', $order_ids ) . ");
                        "),
                        $wpdb->get_col(
                        $wpdb->prepare( "
                            SELECT ID
                            FROM {$wpdb->posts}
                            WHERE post_title LIKE '%%%s%%'
                            OR ID = %d
                    ;",
                    esc_attr( $_GET['s'] ),
                    absint( $_GET['s'] )
                    )
                        ),
                            array( 0 ) // so we don't get back all results for incorrect search
                    );
                }
            }
    
            $wp->query_vars['s']              = false;
            $wp->query_vars['post__in']       = $booking_ids;
            $wp->query_vars['booking_search'] = true;
        }

        /**
         * Add Bulk Actions
         * @global string $post_type type of post
         * @since 4.1.0
         *
         * @hook admin_footer
         */

        public function bkap_bulk_admin_footer() {
            global $post_type;
        
            if ( $this->type === $post_type ) {
                ?>
                    <script type="text/javascript">
                        jQuery( document ).ready( function ( $ ) {
                            $( '<option value="confirm_booking"><?php _e( 'Confirm bookings', 'woocommerce-booking' )?></option>' ).appendTo( 'select[name="action"], select[name="action2"]' );
                            $( '<option value="cancel_booking"><?php _e( 'Cancel bookings', 'woocommerce-booking' )?></option>' ).appendTo( 'select[name="action"], select[name="action2"]' );
                        });
                    </script>
                <?php
            }
        }

        /**
         * Bulk Actions execution
         * @global string $post_type type of post
         * @since 4.1.0
         *
         * @hook load-edit.php
         */

        public function bkap_bulk_action() {
            
            global $post_type;
            
            if ( $this->type === $post_type ) {
                $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
                $action = $wp_list_table->current_action();
            
                switch ( $action ) {
                    case 'confirm_booking' :
                        $new_status = 'confirmed';
                        $report_action = 'bookings_confirmed';
                        break;
                    case 'cancel_booking' :
                        $new_status = 'cancelled';
                        $report_action = 'bookings_cancelled';
                        break;
                    case 'trash':
                        $new_status = 'trash';
                        $report_action = 'bookings_trashed';
                        break;
                    default:
                        return;
                }
            
                $changed = 0;
            
                $post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
            
                foreach ( $post_ids as $post_id ) {
                    
                    if ( $new_status === 'trash' ) {
                        woocommerce_booking::bkap_delete_booking( $post_id );
                    } else {
                        $item_id = get_post_meta( $post_id, '_bkap_order_item_id', true );
                        bkap_booking_confirmation::bkap_save_booking_status( $item_id, $new_status );
                    }
                    $changed++;
                }
            
                $sendback = add_query_arg( array( 'post_type' => $this->type, $report_action => true, 'changed' => $changed, 'ids' => join( ',', $post_ids ) ), '' );
                wp_redirect( $sendback );
                exit();
            }
        }
        
        /**
         * Bulk Action messages
         * @global string $post_type type of post
         * @global string $pagenow current page
         * @since 4.1.0
         *
         * @hook admin_notices
         */

        public function bkap_bulk_admin_notices() {
            global $post_type, $pagenow;
        
            if ( isset( $_REQUEST['bookings_confirmed'] ) || isset( $_REQUEST['bookings_unconfirmed'] ) || isset( $_REQUEST['bookings_cancelled'] ) ) {
                $number = isset( $_REQUEST['changed'] ) ? absint( $_REQUEST['changed'] ) : 0;
        
                if ( 'edit.php' == $pagenow && $this->type == $post_type ) {
                    $message = sprintf( _n( 'Booking status changed.', '%s booking statuses changed.', $number, 'woocommerce-booking' ), number_format_i18n( $number ) );
                    echo '<div class="updated"><p>' . $message . '</p></div>';
                }
            }
        }
        
        /**
         * Add notice for linking to the old View Bookings page
         * @global string $post_type type of post
         * @global string $pagenow current page
         * @since 4.1.0
         *
         * @hook admin_notices
         */

        function bkap_old_view() {
            
            global $post_type, $pagenow;
            
            if ( 'edit.php' == $pagenow && $this->type == $post_type ) {
                
                  if ( current_user_can( 'operator_bookings' ) ) {
                    
                      $link = 'admin.php?page=operator_bookings';
                    }else {
                    
                      $link = 'admin.php?page=woocommerce_history_page';
                    }
                
                $message = 'Think some bookings are missing? If yes, please try checking for them <a href="' . get_admin_url() . $link . '">here</a>';
                $message = __( $message, 'woocommerce-booking' );
                echo '<div class="updated"><p>' . $message . '</p></div>';
            }
        }
        
        /**
         * Ajax for confirming bookings from Actions column
         *
         * @since 4.1.0
         *
         * @hook wp_ajax_bkap-booking-confirm
         */

        function bkap_booking_confirmed() {
        
            if ( ! check_admin_referer( 'bkap-booking-confirm' ) ) {
                wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce-booking' ) );
            }
            $booking_id = isset( $_GET['booking_id'] ) && (int) $_GET['booking_id'] ? (int) $_GET['booking_id'] : '';
            if ( ! $booking_id ) {
                die;
            }
        
            $item_id = get_post_meta( $booking_id, '_bkap_order_item_id', true );
        
            bkap_booking_confirmation::bkap_save_booking_status( $item_id, 'confirmed' );
        
            wp_safe_redirect( wp_get_referer() );
        
        }
        
        /**
         * Returns true if at least one booking has been received for the given product ID
         *
         * @param int $product_id Product ID
         *
         * @since 4.1.0
         *
         * @return boolean
         */
        
        function bkap_check_booking_present( $product_id ) {
            
            $bookings_present = false; // assume no bookings are present for this product
            global $wpdb;
            
            $query = "SELECT post_id FROM `" . $wpdb->prefix . "postmeta`
                        WHERE meta_key = %s
                        AND meta_value = %d
                        ORDER BY post_id DESC LIMIT 1";
            
            $results_query = $wpdb->get_results( $wpdb->prepare( $query, '_bkap_product_id', $product_id ) );
            
            if ( isset( $results_query ) && count( $results_query ) > 0 ) {
                $bookings_present = true;
            }
            
            return $bookings_present;
        }

        /**
         * Preparing the data of bookings and Exporting that in the CSV file OR for Printing 
         *
         * @since 4.1.0
         *
         * @hook admin_init
         */     

        public function bkap_export_data() {
            global $wpdb;
        
            $post_status = '';
        
            if ( isset( $_GET['post_status'] ) ) {
                $post_status = $_GET['post_status'];
            }
            
            /*if ( isset( $_GET['duration_select'] ) && $_GET['duration_select'] !='' && !( isset( $_GET['s'] ) ) ){
                $tab_status = 'custom';
            }*/
            
            if ( isset( $_GET['download'] ) && ( $_GET['download'] == 'data.csv' ) ) {
                $report = self::generate_data( $post_status );
                self::bkap_download_csv_file( $report );
            } else if ( isset( $_GET['download'] ) && ( $_GET['download'] == 'data.print' ) ) {
                $report = self::generate_data($post_status);
                self::bkap_download_print_file( $report );
            }
        }

        /**
         * Download the CSV of the bookings.
         * @param array $report array of bookings based on filter
         *
         * @since 4.1.0
         */

        public static function bkap_download_csv_file( $report ) {

            $csv = self::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;
        }

        /**
         * Print of the bookings.
         * @param array $report array of bookings based on filter
         *
         * @since 4.1.0
         */

        public static function bkap_download_print_file( $report ){
            
            $print_data_columns  = "
                                    <tr>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Status', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'ID', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Booked Product', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Booked By', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Order', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Start Date', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'End Date', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Quantity', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Order Date', 'woocommerce-booking' )."</th>
                                        <th style='border:1px solid black;padding:5px;'>".__( 'Amount', 'woocommerce-booking' )."</th>
                                    </tr>";
            $print_data_row_data =  '';
            
            foreach ( $report as $key => $value ) {
                
                // Status
                $status_raw = $value->get_status();
                $status = bkap_common::get_mapped_status( $status_raw );

                // Booked Product
                $product = $value->get_product();
                $product_name = "";
                if ( $product !== null && $product != false ) {
                    $product_name = $product->get_title();
                }
                
                $resource_id = $value->get_resource();
                $resource_title = "";
                
                if( $resource_id != "" ){
                    $resource_title = $value->get_resource_title();
                
                    $product_name .= "<br>( ". $resource_title . " )";
                
                }

                // Booked By
                $customer = $value->get_customer();
                $booked_by = $customer->name;

                // Start Date
                $start_date = $value->get_start_date();
                if ( $value->get_start_time() !== '' ) {
                    $start_date .= " - " . $value->get_start_time();
                }

                // End Date
                $end_date = "";
                if ( $value->get_end_date() !== '' ) {
                    $end_date = $value->get_end_date();

                    if ( $value->get_end_time() !== '' ) {
                        $end_date .= " - " . $value->get_end_time();
                    }
                }
                
                // Order Date
                $order_date = $value->get_date_created();

                // Amount
                $amount = $value->get_cost();
                $final_amt = $amount * $value->get_quantity();
                
                if ( absint( $value->order_id ) > 0 && false !== get_post_status( $value->order_id ) ) {
                    $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();
                } else {
                    // get default woocommerce currency
                    $currency = get_woocommerce_currency();
                }
                $currency_symbol = get_woocommerce_currency_symbol( $currency );

                $final_amt = wc_price( $final_amt, array( 'currency' => $currency) );
                $print_data_row_data .= "<tr>
                                        <td style='border:1px solid black;padding:5px;'>".$status."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->id."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$product_name."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$booked_by."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->order_id."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$start_date."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$end_date."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$value->get_quantity()."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$order_date."</td>
                                        <td style='border:1px solid black;padding:5px;'>".$final_amt."</td>
                                        </tr>";
            }
            
            $print_data_title    =   apply_filters( 'bkap_view_bookings_print_title', __("Print Bookings", 'woocommerce-booking') );
            $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><title>". $print_data_title. "</title><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;
        }

        /**
         * Generate list of booking.
         * @param string $post_status status of the booking
         *
         * @since 4.1.0
         * return array array contains all the booking details for the given status
         */

        public function generate_data( $post_status ) {
            
            return bkap_common::bkap_get_bookings( $post_status );
        }

        /**
         * Generate string for CSV of booking.
         * @param array $data array of booking information
         *
         * @since 4.1.0
         */

        public static function generate_csv( $data ) {
            
            // Column Names
            $csv = 'Status,ID,Booked Product,Booked By,Order ID,Start Date,End Date,Quantity,Order Date,Amount';
            $csv .= "\n";
            
            foreach ( $data as $key => $value ) {
                // Status
                $status_raw = $value->get_status();
                $status = bkap_common::get_mapped_status( $status_raw );

                // ID
                $booking_id = $value->id;

                // Booked Product
                $product = $value->get_product();
                $product_name = "";
                if ( $product !== null && $product !== false ) {
                    $product_name = $product->get_title();
                }
                
                $resource_id = $value->get_resource();
                $resource_title = "";
                
                if( $resource_id != "" ){
                    $resource_title = $value->get_resource_title();
                
                    $product_name .= " ( ". $resource_title . " )";
                
                }

                // Booked By
                $customer = $value->get_customer();
                $booked_by = $customer->name;
                
                // Order ID
                $order_id = $value->order_id;
                
                // Start Date
                $start_date = $value->get_start_date();
                if ( $value->get_start_time() !== '' ) {
                    $start_date .= " - " . $value->get_start_time();
                }

                // End Date
                $end_date = "";
                if ( $value->get_end_date() !== '' ) {
                    $end_date = $value->get_end_date();

                    if ( $value->get_end_time() !== '' ) {
                        $end_date .= " - " . $value->get_end_time();
                    }
                }
                
                //Order date
                $order_date = $value->get_date_created();

                // Quantity
                $quantity= $value->get_quantity();
                
                // Amount
                $amount = $value->get_cost();
                $final_amt = $amount * $quantity;
                
                if ( absint( $order_id ) > 0 && false !== get_post_status( $order_id ) ) {
                    $the_order = wc_get_order( $order_id );
                    $currency = ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) < 0 ) ? $the_order->get_order_currency() : $the_order->get_currency();
                } else {
                    // get default woocommerce currency
                    $currency = get_woocommerce_currency();
                }
                $currency_symbol = get_woocommerce_currency_symbol( $currency );

                $final_amt = strip_tags( html_entity_decode( wc_price( $final_amt, array( 'currency' => $currency ) ) ) );
                
                // Create the data row
                $csv .= $status . ',' . $booking_id . ',"' . $product_name . '",' . $booked_by . ',' . $order_id . ',"' . $start_date . '","' . $end_date . '",' . $quantity . ',' . $order_date . ',"' . $final_amt . '"';
                $csv .= "\n";  
            }
            $csv = apply_filters( 'bkap_bookings_csv_data', $csv, $data );
            return $csv;
        }   
    }// end of class
}
return new BKAP_Bookings_View();
API documentation generated by ApiGen