/**
  * Renders a dropdown list of equipment add-ons.
  *
  * @since	1.3.7
  * @param	arr		$args	@see $default
  * @return	str
  */
 public function addons_dropdown($args = array())
 {
     $defaults = array('name' => 'event_addons', 'id' => '', 'class' => '', 'selected' => '', 'show_option_none' => __('No Addons', 'mobile-dj-manager'), 'show_option_all' => false, 'chosen' => false, 'employee' => false, 'event_type' => false, 'event_date' => false, 'placeholder' => null, 'multiple' => true, 'package' => '', 'cost' => true, 'desc' => false, 'titles' => false, 'options_only' => false, 'blank_first' => false, 'data' => array());
     $args = wp_parse_args($args, $defaults);
     $options = array();
     $titles = array();
     $addons = mdjm_get_addons();
     if ($addons) {
         foreach ($addons as $addon) {
             if (!empty($args['package'])) {
                 if (is_numeric($args['package'])) {
                     $package = mdjm_get_package($args['package']);
                 } else {
                     $package = mdjm_get_package_by('slug', $args['package']);
                 }
                 if ($package) {
                     $package_items = mdjm_get_package_addons($package->ID);
                 }
                 if (!empty($package_items) && in_array($addon->ID, $package_items)) {
                     continue;
                 }
             }
             if (!empty($args['employee'])) {
                 if (!mdjm_employee_has_addon($addon->ID, $args['employee'])) {
                     continue;
                 }
             }
             if ($args['event_type']) {
                 if (!mdjm_addon_is_available_for_event_type($addon->ID, $args['event_type'])) {
                     continue;
                 }
             }
             if ($args['event_date']) {
                 if (!mdjm_addon_is_available_for_event_date($addon->ID, $args['event_date'])) {
                     continue;
                 }
             } else {
                 $args['event_date'] = NULL;
             }
             $price = '';
             if ($args['cost'] == true) {
                 $price .= ' - ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_addon_price($addon->ID, $args['event_date'])));
             }
             $desc = '';
             if ($args['desc']) {
                 $desc .= ' - ' . mdjm_get_addon_excerpt($addon->ID, $args['desc']);
             }
             $term = '';
             $terms = get_the_terms($addon->ID, 'addon-category');
             if (!empty($terms)) {
                 $term = esc_html($terms[0]->name);
             }
             $args['options']['groups'][$term][] = array($addon->ID => $addon->post_title . $price . $desc);
             if ($args['titles']) {
                 $titles[$addon->ID] = mdjm_get_addon_excerpt($addon->ID);
             }
         }
     }
     if (!empty($args['options']['groups'])) {
         ksort($args['options']['groups']);
     }
     if (!empty($titles)) {
         $args['titles'] = $titles;
     }
     $output = $this->select($args);
     return $output;
 }
Ejemplo n.º 2
0
/**
 * Calculate the event cost as event elements change
 *
 * @since	1.0
 * @return	void
 */
function mdjm_update_event_cost_ajax()
{
    $mdjm_event = new MDJM_Event($_POST['event_id']);
    $mdjm_travel = new MDJM_Travel();
    $event_cost = $mdjm_event->price;
    $event_date = $event_date = !empty($_POST['event_date']) ? $_POST['event_date'] : NULL;
    $base_cost = '0.00';
    $package = $mdjm_event->get_package();
    $package_price = $package ? mdjm_get_package_price($package, $event_date) : '0.00';
    $addons = $mdjm_event->get_addons();
    $travel_data = $mdjm_event->get_travel_data();
    $employee_id = $_POST['employee_id'];
    $dest = $_POST['venue'];
    $dest = maybe_unserialize($dest);
    if ($event_cost) {
        $event_cost = (double) $event_cost;
        $base_cost = $package_price ? $event_cost - $package_price : $event_cost;
    }
    if ($package) {
        $base_cost = $event_cost - $package_price;
    }
    if ($addons) {
        foreach ($addons as $addon) {
            $addon_price = mdjm_get_addon_price($addon, $event_date);
            $base_cost = $base_cost - (double) $addon_price;
        }
    }
    if ($travel_data && !empty($travel_data['cost'])) {
        $base_cost = $base_cost - (double) $travel_data['cost'];
    }
    $new_package = !empty($_POST['package']) ? $_POST['package'] : false;
    $new_addons = !empty($_POST['addons']) ? $_POST['addons'] : false;
    $cost = $base_cost;
    if ($new_package) {
        $new_package_price = mdjm_get_package_price($new_package, $event_date);
        $cost += (double) $new_package_price;
    }
    if ($new_addons) {
        foreach ($new_addons as $new_addon) {
            $new_addon_price = mdjm_get_addon_price($new_addon, $event_date);
            $cost += (double) $new_addon_price;
        }
    }
    if ($mdjm_travel->add_travel_cost) {
        if (!empty($employee_id)) {
            $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($employee_id));
        }
        $mdjm_travel->set_destination($dest);
        $mdjm_travel->get_travel_data();
        $new_travel = !empty($mdjm_travel->data) ? $mdjm_travel->get_cost() : false;
        if ($new_travel && (double) preg_replace('/[^0-9.]*/', '', $mdjm_travel->data['distance']) >= mdjm_get_option('travel_min_distance')) {
            $cost += (double) $new_travel;
        }
    }
    if (!empty($cost)) {
        $result['type'] = 'success';
        $result['cost'] = mdjm_sanitize_amount((double) $cost);
    } else {
        $result['type'] = 'success';
        $result['cost'] = mdjm_sanitize_amount(0);
    }
    wp_send_json($result);
}
Ejemplo n.º 3
0
 /**
  * Creates an event
  *
  * @since 	1.3
  * @param 	arr		$data Array of attributes for an event. See $defaults.
  * @return	mixed	false if data isn't passed and class not instantiated for creation, or New Event ID
  */
 public function create($data = array(), $meta = array())
 {
     if ($this->id != 0) {
         return false;
     }
     remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     $defaults = array('post_type' => 'mdjm-event', 'post_author' => 1, 'post_content' => '', 'post_status' => 'mdjm-enquiry', 'post_title' => __('New Event', 'mobile-dj-manager'));
     $default_meta = array('_mdjm_event_date' => date('Y-m-d'), '_mdjm_event_dj' => !mdjm_get_option('employer') ? 1 : 0, '_mdjm_event_playlist_access' => mdjm_generate_playlist_guest_code(), '_mdjm_event_playlist' => mdjm_get_option('enable_playlists') ? 'Y' : 'N', '_mdjm_event_contract' => mdjm_get_default_event_contract(), '_mdjm_event_cost' => 0, '_mdjm_event_deposit' => 0, '_mdjm_event_deposit_status' => __('Due', 'mobile-dj-manager'), '_mdjm_event_balance_status' => __('Due', 'mobile-dj-manager'), 'mdjm_event_type' => mdjm_get_option('event_type_default'), 'mdjm_enquiry_source' => mdjm_get_option('enquiry_source_default'), '_mdjm_event_venue_id' => 'Manual');
     $data = wp_parse_args($data, $defaults);
     $meta = wp_parse_args($meta, $default_meta);
     do_action('mdjm_event_pre_create', $data, $meta);
     $id = wp_insert_post($data, true);
     $event = WP_Post::get_instance($id);
     if ($event) {
         if (!empty($meta['mdjm_event_type'])) {
             mdjm_set_event_type($event->ID, $meta['mdjm_event_type']);
             $meta['_mdjm_event_name'] = get_term($meta['mdjm_event_type'], 'event-types')->name;
             $meta['_mdjm_event_name'] = apply_filters('mdjm_event_name', $meta['_mdjm_event_name'], $id);
         }
         if (!empty($meta['mdjm_enquiry_source'])) {
             mdjm_set_enquiry_source($event->ID, $meta['mdjm_enquiry_source']);
         }
         if (!empty($meta['_mdjm_event_start']) && !empty($meta['_mdjm_event_finish'])) {
             if (date('H', strtotime($meta['_mdjm_event_finish'])) > date('H', strtotime($meta['_mdjm_event_start']))) {
                 $meta['_mdjm_event_end_date'] = $meta['_mdjm_event_date'];
             } else {
                 $meta['_mdjm_event_end_date'] = date('Y-m-d', strtotime('+1 day', strtotime($meta['_mdjm_event_date'])));
             }
         }
         if (!empty($meta['_mdjm_event_package'])) {
             $meta['_mdjm_event_cost'] += mdjm_get_package_price($meta['_mdjm_event_package'], $meta['_mdjm_event_date']);
         }
         if (!empty($meta['_mdjm_event_addons'])) {
             foreach ($meta['_mdjm_event_addons'] as $addon) {
                 $meta['_mdjm_event_cost'] += mdjm_get_addon_price($addon);
             }
         }
         if (empty($meta['_mdjm_event_deposit'])) {
             $meta['_mdjm_event_deposit'] = mdjm_calculate_deposit($meta['_mdjm_event_cost']);
         }
         mdjm_update_event_meta($event->ID, $meta);
         wp_update_post(array('ID' => $id, 'post_title' => mdjm_get_event_contract_id($id), 'post_name' => mdjm_get_event_contract_id($id)));
     }
     do_action('mdjm_event_post_create', $id, $data);
     add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     return $this->setup_event($event);
 }
Ejemplo n.º 4
0
/**
 * Renders the HTML code for an Addons checkbox list
 *
 * @since	1.0
 * @param	arr		$args	See @defaultsSettings for the dropdown
 * @return	HTML output for checkboxes
 */
function mdjm_addons_checkboxes($args = array())
{
    global $current_user;
    $defaults = array('name' => 'event_addons', 'id' => '', 'class' => '', 'current' => array(), 'employee' => is_user_logged_in() && !current_user_can('client') ? $current_user->ID : '', 'package' => '', 'event_type' => false, 'event_date' => false, 'title' => true, 'cost' => false);
    $args = wp_parse_args($args, $defaults);
    $output = '';
    $options = array();
    $addons = mdjm_get_addons();
    if (empty($args['id'])) {
        $args['id'] = $args['name'];
    }
    // For backwards compatibility
    if (isset($args['dj'])) {
        $args['employee'] = $args['dj'];
    }
    if ($addons) {
        foreach ($addons as $addon) {
            if (!empty($args['package'])) {
                if (is_numeric($args['package'])) {
                    $package = mdjm_get_package($args['package']);
                } else {
                    $package = mdjm_get_package_by('slug', $args['package']);
                }
                if ($package) {
                    $package_items = mdjm_get_package_addons($package->ID);
                }
                if (!empty($package_items) && in_array($addon->ID, $package_items)) {
                    continue;
                }
            }
            if (!empty($args['employee'])) {
                if (!mdjm_employee_has_addon($addon->ID, $args['employee'])) {
                    continue;
                }
            }
            if ($args['event_type']) {
                if (!mdjm_addon_is_available_for_event_type($addon->ID, $args['event_type'])) {
                    continue;
                }
            }
            if ($args['event_date']) {
                if (!mdjm_addon_is_available_for_event_date($addon->ID, $args['event_date'])) {
                    continue;
                }
            } else {
                $args['event_date'] = NULL;
            }
            $price = '';
            if ($args['cost'] == true) {
                $price .= ' - ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_addon_price($addon->ID, $args['event_date'])));
            }
            $term = '';
            $terms = get_the_terms($addon->ID, 'addon-category');
            if (!empty($terms)) {
                $term = esc_html($terms[0]->name);
            }
            $options[$term][] = array($addon->ID => $addon->post_title . $price);
        }
    }
    if (!empty($options)) {
        ksort($options);
        $i = 0;
        foreach ($options as $term => $addons) {
            if ($i == 0) {
                $output .= '<strong>' . $term . '</strong><br />' . "\n";
            }
            foreach ($addons as $items) {
                foreach ($items as $item_id => $item) {
                    $output .= sprintf('<input type="checkbox" name="%1$s[]" id="%1$s-%2$d" class="%3$s" value="%2$d" %4$s />', esc_attr($args['name']), $item_id, sanitize_html_class($args['class']), checked(in_array($item_id, $args['current']), true, false));
                    $output .= '<label for="' . esc_attr($args['name']) . '-' . $item_id . '" title="' . mdjm_get_addon_excerpt($item_id) . '">';
                    $output .= esc_html($item);
                    $output .= '</label>';
                    $output .= '<br />';
                    $i++;
                    if ($i >= count($items)) {
                        $i = 0;
                    }
                }
            }
        }
    } else {
        $output .= __('No add-ons are available', 'mobile-dj-manager');
    }
    return $output;
}
Ejemplo n.º 5
0
/**
 * Define the data to be displayed in each of the custom columns for the Addon post types
 *
 * @since	1.4
 * @param	str		$column_name	The name of the column to display
 * @param	int		$post_id		The current post ID
 * @return
 */
function mdjm_addon_posts_custom_column($column_name, $post_id)
{
    global $post;
    switch ($column_name) {
        // Category
        case 'addon_category':
            echo get_the_term_list($post_id, 'addon-category', '', ', ', '');
            break;
            // Availability
        // Availability
        case 'availability':
            $output = array();
            if (!mdjm_addon_is_restricted_by_date($post_id)) {
                $output[] = __('Always', 'mobile-dj-manager');
            } else {
                $availability = mdjm_get_addon_months_available($post_id);
                if (!$availability) {
                    $output[] = __('Always', 'mobile-dj-manager');
                } else {
                    $i = 0;
                    foreach ($availability as $month) {
                        $output[] = mdjm_month_num_to_name($availability[$i]);
                        $i++;
                    }
                }
            }
            echo implode(', ', $output);
            break;
            // Event Types
        // Event Types
        case 'event_types':
            $output = array();
            $event_label = mdjm_get_label_singular();
            $event_types = mdjm_get_addon_event_types($post_id);
            if (in_array('all', $event_types)) {
                $output[] = sprintf(__('All %s Types', 'mobile-dj-manager'), $event_label);
            } else {
                foreach ($event_types as $event_type) {
                    $term = get_term($event_type, 'event-types');
                    if (!empty($term)) {
                        $output[] = $term->name;
                    }
                }
            }
            echo implode(', ', $output);
            break;
            // Employees
        // Employees
        case 'employees':
            $employees = mdjm_get_employees_with_addon($post_id);
            $output = array();
            if (in_array('all', $employees)) {
                $output[] = __('All Employees', 'mobile-dj-manager');
            } else {
                foreach ($employees as $employee) {
                    if ('all' == $employee) {
                        continue;
                    }
                    $output[] = '<a href="' . get_edit_user_link($employee) . '">' . mdjm_get_employee_display_name($employee) . '</a>';
                }
            }
            echo implode('<br />', $output);
            break;
            // Price
        // Price
        case 'price':
            if (mdjm_addon_has_variable_prices($post_id)) {
                $range = mdjm_get_addon_price_range($post_id);
                echo mdjm_currency_filter(mdjm_format_amount($range['low']));
                echo ' &mdash; ';
                echo mdjm_currency_filter(mdjm_format_amount($range['high']));
            } else {
                echo mdjm_currency_filter(mdjm_format_amount(mdjm_get_addon_price($post_id)));
            }
            break;
            // Usage
        // Usage
        case 'usage':
            $packages = mdjm_count_packages_with_addon($post_id);
            $events = mdjm_count_events_with_addon($post_id);
            echo $packages . _n(' Package', ' Packages', $packages, 'mobile-dj-manager') . '<br />';
            echo $events . ' ' . _n(mdjm_get_label_singular(), mdjm_get_label_plural(), $events, 'mobile-dj-manager');
            break;
    }
    // switch
}
/**
 * Retrieve the cost of an addon.
 *
 * @since	1.4
 * @param	str		$slug	The slug identifier for the addon.
 * @return	int		The cost of the addon.
 */
function mdjm_get_addon_cost($slug)
{
    _deprecated_function(__FUNCTION__, '1.4', "mdjm_get_addon_by( 'field', 'value' )");
    $addon = mdjm_get_addon_by('slug', $slug);
    if ($addon) {
        return mdjm_format_amount(mdjm_get_addon_price($addon->ID));
    }
}
Ejemplo n.º 7
0
/**
 * Output the addon availability pricing options row
 *
 * @since	1.4
 * @param	int		$post		The WP_Post object.
 * @return	str
 */
function mdjm_addon_metabox_pricing_options_row($post)
{
    $month = 1;
    $price = mdjm_get_addon_price($post->ID);
    $variable = mdjm_addon_has_variable_prices($post->ID);
    $prices = mdjm_get_addon_variable_prices($post->ID);
    $variable_display = $variable ? '' : ' style="display:none;"';
    $currency_position = mdjm_get_option('currency_format', 'before');
    ?>
    <div class="mdjm_field_wrap mdjm_form_fields">
		<div id="mdjm-addon-regular-price-field" class="mdjm_pricing_fields">
		<?php 
    $price_args = array('name' => '_addon_price', 'value' => isset($price) ? esc_attr(mdjm_format_amount($price)) : '', 'class' => 'mdjm-currency', 'placeholder' => mdjm_format_amount('10.00'), 'desc' => __('Will be used if variable pricing is not in use, or for months that are not defined within variable pricing', 'mobile-dj-manager'));
    ?>
			<p><label for="<?php 
    echo $price_args['name'];
    ?>
"><?php 
    _e('Standard Price', 'mobile-dj-manager');
    ?>
</label><br />
			<?php 
    if ($currency_position == 'before') {
        ?>
				<?php 
        echo mdjm_currency_filter('');
        ?>
				<?php 
        echo MDJM()->html->text($price_args);
        ?>
			<?php 
    } else {
        ?>
				<?php 
        echo MDJM()->html->text($price_args);
        ?>
				<?php 
        echo mdjm_currency_filter('');
        ?>
			<?php 
    }
    ?>
</p>
	
			<?php 
    do_action('mdjm_addon_price_field', $post->ID);
    ?>
		</div>
		<?php 
    do_action('mdjm_after_addon_price_field', $post->ID);
    ?>
        <div id="addon-variable-price">
        	<p><?php 
    echo MDJM()->html->checkbox(array('name' => '_addon_variable_pricing', 'current' => $variable));
    ?>
            <label for="_addon_variable_pricing"><?php 
    _e('Enable variable pricing', 'mobile-dj-manager');
    ?>
</label></p>
        </div>
        <?php 
    do_action('mdjm_after_addon_variable_pricing_field', $post->ID);
    ?>
    </div>

	<div id="mdjm-addon-variable-price-fields" class="mdjm_pricing_fields" <?php 
    echo $variable_display;
    ?>
>
		<input type="hidden" id="mdjm_variable_prices" class="mdjm_variable_prices_name_field" value=""/>
        <div id="mdjm_price_fields" class="mdjm_meta_table_wrap">
			<table class="widefat mdjm_repeatable_table">
            	<thead>
					<tr>
						<th style="width: 50px;"><?php 
    _e('Month', 'mobile-dj-manager');
    ?>
</th>
						<th style="width: 100px;"><?php 
    _e('Price', 'mobile-dj-manager');
    ?>
</th>
						<?php 
    do_action('mdjm_addon_price_table_head', $post->ID);
    ?>
                        <th style="width: 2%"></th>
					</tr>
				</thead>
                <tbody>
                	<?php 
    if (!empty($prices)) {
        foreach ($prices as $key => $value) {
            $months = isset($value['months']) ? $value['months'] : '';
            $amount = isset($value['amount']) ? $value['amount'] : '';
            $index = isset($value['index']) ? $value['index'] : $key;
            $args = apply_filters('mdjm_price_row_args', compact('months', 'amount'), $value);
            ?>
								<tr class="mdjm_variable_prices_wrapper mdjm_repeatable_row" data-key="<?php 
            echo esc_attr($key);
            ?>
">
									<?php 
            do_action('mdjm_render_addon_price_row', $key, $args, $post->ID, $index);
            ?>
								</tr>
							<?php 
        }
    } else {
        ?>
						<tr class="mdjm_variable_prices_wrapper mdjm_repeatable_row" data-key="1">
							<?php 
        do_action('mdjm_render_addon_price_row', 1, array(), $post->ID, 1);
        ?>
						</tr>
					<?php 
    }
    ?>

                    <tr>
						<td class="submit" colspan="3" style="float: none; clear:both; background:#fff;">
							<a class="button-secondary mdjm_add_repeatable" style="margin: 6px 0;"><?php 
    _e('Add New Price', 'mobile-dj-manager');
    ?>
</a>
						</td>
					</tr>

                </tbody>
            </table>
        </div>
    </div>

    <?php 
}
Ejemplo n.º 8
0
/**
 * Addons List Shortcode.
 * 
 * @param	arr		$atts		Shortcode attributes. See $atts.
 * @param	str|int	$filter_value	The value to which to filter $filter_by. Default false (all).
 * @param	str		$list			List type to display. li for bulleted. Default p.
 * @param	bool	$cost			Whether or not display the price. Default false.
 *
 *
 */
function mdjm_shortcode_addons_list($atts)
{
    global $post;
    $atts = shortcode_atts(array('filter_by' => false, 'filter_value' => false, 'list' => 'p', 'desc' => false, 'desc_length' => mdjm_get_option('package_excerpt_length', 55), 'cost' => false, 'addon_class' => false, 'cost_class' => false, 'desc_class' => false), $atts, 'mdjm-addons');
    ob_start();
    $output = '';
    if (!empty($post) && 'mdjm-package' == get_post_type($post->ID)) {
        $package_addons = mdjm_get_package_addons($post->ID);
        $addons = array();
        foreach ($package_addons as $package) {
            $addons[] = mdjm_get_addon($package);
        }
    } elseif (!empty($atts['filter_by']) && !empty($atts['filter_value']) && $atts['filter_by'] != 'false' && $atts['filter_value'] != 'false') {
        // Filter addons by user
        if ($atts['filter_by'] == 'category') {
            $addons = mdjm_get_addons_in_category($atts['filter_value']);
        } elseif ($atts['filter_by'] == 'package') {
            if (!is_numeric($atts['filter_value'])) {
                // For backwards compatibility
                $package = mdjm_get_package_by('slug', $atts['filter_value']);
                if ($package) {
                    $atts['filter_value'] = $package->ID;
                }
            }
            $package_addons = mdjm_get_package_addons($atts['filter_value']);
            $addons = array();
            foreach ($package_addons as $package) {
                $addons[] = mdjm_get_addon($package);
            }
        } elseif ($atts['filter_by'] == 'user') {
            $addons = mdjm_get_addons_by_employee($atts['filter_value']);
        }
    } else {
        $addons = mdjm_get_addons();
    }
    /**
     * Output the results
     */
    if (!$addons) {
        $output .= '<p>' . __('No addons available', 'mobile-dj-manager') . '</p>';
    } else {
        // Check to start bullet list
        if ($atts['list'] == 'li') {
            $output .= '<ul>';
        }
        foreach ($addons as $addon) {
            // Output the remaining addons
            if (!empty($atts['list'])) {
                $output .= '<' . $atts['list'] . '>';
            }
            if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') {
                $output = '<span class="' . $atts['addon_class'] . '">';
            }
            $output .= $addon->post_title;
            if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') {
                $output = '</span>';
            }
            $cost = mdjm_get_addon_price($addon->ID);
            if (!empty($atts['cost']) && $atts['cost'] != 'false' && !empty($cost)) {
                if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') {
                    $output = '<span class="' . $atts['cost_class'] . '">';
                }
                $output .= '&nbsp;&ndash;&nbsp;' . mdjm_currency_filter(mdjm_format_amount($cost));
                if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') {
                    $output = '</span>';
                }
            }
            $desc = mdjm_get_addon_excerpt($addon->ID, $atts['desc_length']);
            if (!empty($atts['desc']) && $atts['desc'] != 'false' && !empty($desc)) {
                $output .= '<br />';
                if (!empty($atts['desc_class']) && $atts['desc_class'] != 'false') {
                    $output = '<span class="' . $atts['desc_class'] . '">';
                } else {
                    $output .= '<span style="font-style: italic; font-size: smaller;">';
                }
                $output .= $desc;
                $output .= '</span>';
            }
            if (!empty($atts['list'])) {
                $output .= '</' . $atts['list'] . '>';
            }
        }
        // Check to end bullet list
        if ($atts['list'] == 'li') {
            $output .= '</ul>';
        }
    }
    echo apply_filters('mdjm_shortcode_addons_list', $output);
    return ob_get_clean();
}
 /**
  * Build all the reports data
  *
  * @access	public
  * @since	1.4
  * @return	arr		$reports_data	All the data for customer reports
  */
 public function reports_data()
 {
     $stats = new MDJM_Stats();
     $dates = mdjm_get_report_dates();
     $stats->setup_dates($dates['range']);
     $cached_reports = false;
     if (false !== $cached_reports) {
         $reports_data = $cached_reports;
     } else {
         $reports_data = array();
         $term_args = array('parent' => 0, 'hierarchical' => 0);
         $addons = mdjm_get_addons();
         if ($addons) {
             foreach ($addons as $addon) {
                 $event_count = 0;
                 $total_value = 0;
                 $event_args = array('fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => '_mdjm_event_addons', 'value' => sprintf(':"%s";', $addon->ID), 'compare' => 'LIKE'), array('key' => '_mdjm_event_date', 'value' => array(date('Y-m-d', $stats->start_date), date('Y-m-d', $stats->end_date)), 'type' => 'date', 'compare' => 'BETWEEN')));
                 $events = mdjm_get_events($event_args);
                 if ($events) {
                     foreach ($events as $event) {
                         $event_count++;
                         $event_date = get_post_meta($event, '_mdjm_event_date', true);
                         $total_value += mdjm_get_addon_price($addon->ID, $event_date);
                     }
                 } else {
                     continue;
                 }
                 $reports_data[] = array('ID' => $addon->ID, 'addon' => mdjm_get_addon_name($addon->ID), 'events' => $event_count, 'value' => mdjm_currency_filter(mdjm_format_amount($total_value)), 'value_raw' => $total_value);
             }
         }
     }
     return $reports_data;
 }