/**
  * 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);
         $packages = mdjm_get_packages();
         if ($packages) {
             foreach ($packages as $package) {
                 $event_count = 0;
                 $total_value = 0;
                 $event_args = array('fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => '_mdjm_event_package', 'value' => $package->ID, 'type' => 'NUMERIC'), 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_package_price($package->ID, $event_date);
                     }
                 } else {
                     continue;
                 }
                 $reports_data[] = array('ID' => $package->ID, 'package' => mdjm_get_package_name($package->ID), 'events' => $event_count, 'value' => mdjm_currency_filter(mdjm_format_amount($total_value)), 'value_raw' => $total_value);
             }
         }
     }
     return $reports_data;
 }
 /**
  * Renders a dropdown list of packages.
  *
  * @since	1.3.7
  * @param	arr		$args	@see $default
  * @return	str
  */
 public function packages_dropdown($args = array())
 {
     $defaults = array('name' => '_mdjm_event_package', 'id' => '', 'class' => '', 'selected' => '', 'show_option_none' => __('No Package', 'mobile-dj-manager'), 'show_option_all' => false, 'chosen' => false, 'employee' => false, 'event_type' => false, 'event_date' => false, 'placeholder' => __('Select a Package', 'mobile-dj-manager'), 'multiple' => false, 'cost' => true, 'titles' => false, 'options_only' => false, 'blank_first' => true, 'data' => array());
     $args = wp_parse_args($args, $defaults);
     $options = array();
     $args['id'] = !empty($args['id']) ? $args['id'] : $args['name'];
     $packages = mdjm_get_packages();
     if ($packages) {
         foreach ($packages as $package) {
             if ($args['employee']) {
                 if (!mdjm_employee_has_package($package->ID, $args['employee'])) {
                     continue;
                 }
             }
             if ($args['event_type']) {
                 if (!mdjm_package_is_available_for_event_type($package->ID, $args['event_type'])) {
                     continue;
                 }
             }
             if ($args['event_date']) {
                 if (!mdjm_package_is_available_for_event_date($package->ID, $args['event_date'])) {
                     continue;
                 }
             } else {
                 $args['event_date'] = NULL;
             }
             $price = '';
             if ($args['cost'] == true) {
                 $price .= ' - ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_package_price($package->ID, $args['event_date'])));
             }
             $args['options'][$package->ID] = $package->post_title . '' . $price;
             if ($args['titles']) {
                 $titles[$package->ID] = mdjm_get_package_excerpt($package->ID);
             }
         }
     }
     if (empty($args['options'])) {
         $args['placeholder'] = __('No Packages Available', 'mobile-dj-manager');
     }
     if (!empty($titles)) {
         $args['titles'] = $titles;
     }
     $output = $this->select($args);
     return $output;
 }
/**
 * List all available packages. If an employee ID is provided, list what that 
 * employee can provide only.
 *
 * @since	1.3
 * @param	int		$employee_id	An employee user ID, otherwise query current user.
 * @param	bool	$price			True to display the formatted package price
 * @return	str		HTML formatted string listing package information
 */
function mdjm_list_available_packages($employee_id = 0, $price = false)
{
    if (!mdjm_packages_enabled()) {
        return __('No packages available', 'mobile-dj-manager');
    }
    if (!empty($employee_id)) {
        $packages = mdjm_get_packages_by_employee($employee_id, false);
    } else {
        $packages = mdjm_get_packages();
    }
    if (empty($packages)) {
        return __('No packages available', 'mobile-dj-manager');
    }
    $return = array();
    foreach ($packages as $package) {
        $package_price = '';
        if ($price) {
            $package_price = ' ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_package_price($package->ID)));
        }
        $return[] = get_the_title($package->ID) . '' . $package_price;
    }
    $return = apply_filters('mdjm_list_packages', $return, $price);
    return implode('<br />', $return);
}
Esempio n. 4
0
 /**
  * Retrieve packages filtered by employee, event month, event type or category.
  *
  * @since	1.4
  * @return	void
  */
 public function list_packages()
 {
     $response = array();
     $packages = array();
     do_action('mdjm_before_api_list_packages', $this);
     $all_packages = mdjm_get_packages(array('suppress_filters' => false));
     if ($all_packages) {
         foreach ($all_packages as $package) {
             if (isset($this->request['employee_id']) && !mdjm_employee_has_package($package->ID, $this->request['employee_id'])) {
                 continue;
             }
             if (isset($this->request['event_month']) && !mdjm_package_is_available_for_event_date($package->ID, $this->request['event_month'])) {
                 continue;
             }
             if (isset($this->request['event_type']) && !mdjm_package_is_available_for_event_type($package->ID, $this->request['event_type'])) {
                 continue;
             }
             $packages[] = $package->ID;
         }
     }
     if (empty($packages)) {
         $error = array();
         $error['error'] = __('No packages found.', 'mobile-dj-manager');
         $this->data = $error;
         $this->output();
     }
     $response['packages'] = array();
     $i = 0;
     foreach ($packages as $package) {
         $response['packages'][$package] = mdjm_get_package_data($package);
         $i++;
     }
     $response['count'] = $i;
     $this->data = array_merge($this->data, $response);
     do_action('mdjm_after_api_list_packages', $this);
     $this->output();
 }
function get_package_details($slug)
{
    _deprecated_function(__FUNCTION__, '1.4');
    if (empty($slug)) {
        return false;
    }
    $packages = mdjm_get_packages();
    if (empty($packages[$slug])) {
        return false;
    }
    $package['slug'] = $slug;
    $package['name'] = stripslashes(esc_attr($packages[$slug]['name']));
    $package['desc'] = stripslashes(esc_textarea($packages[$slug]['desc']));
    $package['equipment'] = $packages[$slug]['equipment'];
    $package['cost'] = $packages[$slug]['cost'];
    return $package;
}