Пример #1
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);
}
Пример #2
0
/**
 * Adds the travel data row to the venue details metabox on the event screen.
 *
 * @since	1.4
 * @param	int|arr|obj	$dest			An address array, event ID, event object or venue ID.
 * @param	int			$employee_id	An employee user ID.
 * @return	void
 */
function mdjm_show_travel_data_row($dest, $employee_id = '')
{
    $mdjm_travel = new MDJM_Travel();
    if (!empty($employee_id)) {
        $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($employee_id));
    }
    $mdjm_travel->set_destination($dest);
    if (empty($employee_id)) {
        if (is_object($dest)) {
            $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($dest->employee_id));
        } elseif (is_numeric($dest)) {
            if ('mdjm-event' == get_post_type($dest)) {
                $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address(mdjm_get_event_primary_employee_id($dest)));
            }
        }
    }
    $mdjm_travel->get_travel_data();
    $distance = '';
    $duration = '';
    $cost = '';
    $directions_url = '';
    $directions = $mdjm_travel->get_directions_url();
    $class = 'mdjm-hidden';
    if (!empty($mdjm_travel->data)) {
        $distance = mdjm_format_distance($mdjm_travel->data['distance'], false, true);
        $duration = mdjm_seconds_to_time($mdjm_travel->data['duration']);
        $cost = mdjm_currency_filter(mdjm_format_amount($mdjm_travel->get_cost()));
        $directions_url = $directions ? $directions : '';
        $class = '';
    }
    ob_start();
    ?>
	<tr id="mdjm-travel-data" class="<?php 
    echo $class;
    ?>
">
		<td><i class="fa fa-car" aria-hidden="true" title="<?php 
    _e('Distance', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-distance"><?php 
    echo $distance;
    ?>
</span></td>
		<td><i class="fa fa-clock-o" aria-hidden="true" title="<?php 
    _e('Travel Time', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-time"><?php 
    echo $duration;
    ?>
</span></td>
		<td><i class="fa fa-money" aria-hidden="true" title="<?php 
    _e('Cost', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-cost"><?php 
    echo $cost;
    ?>
</span></td>
	</tr>

    <tr id="mdjm-travel-directions" class="<?php 
    echo $class;
    ?>
">
        <td colspan="3"><i class="fa fa-map-signs" aria-hidden="true" title="<?php 
    _e('Directions', 'mobile-dj-manager');
    ?>
"></i>
        <span class="mdjm-travel-directions"><a id="travel_directions" href="<?php 
    echo $directions_url;
    ?>
" target="_blank"><?php 
    _e('Directions', 'mobile-dj-manager');
    ?>
</a></span></td>
    </tr>

	<?php 
    $travel_data_row = ob_get_contents();
    ob_end_clean();
    echo $travel_data_row;
}