Example #1
0
/**
 * Display the event playlist page.
 *
 * @since	1.3
 * @param	
 * @return	str		The event playlist page content.
 */
function mdjm_display_event_playlist_page()
{
    if (!mdjm_employee_can('read_events') && !mdjm_employee_working_event($_GET['event_id'])) {
        wp_die('<h1>' . __('Cheatin&#8217; uh?') . '</h1>' . '<p>' . __('You do not have permission to view this playlist.', 'mobile-dj-manager') . '</p>', 403);
    }
    if (!class_exists('MDJM_PlayList_Table')) {
        require_once MDJM_PLUGIN_DIR . '/includes/admin/events/class-mdjm-playlist-table.php';
    }
    $playlist_obj = new MDJM_PlayList_Table();
    ?>
	<div class="wrap">
		<h1><?php 
    printf(__('Playlist for %s %s', 'mobile-dj-manager'), mdjm_get_label_singular(), mdjm_get_event_contract_id($_GET['event_id']));
    ?>
</h1>

        <form method="post">
            <?php 
    $playlist_obj->prepare_items();
    $playlist_obj->display_header();
    if (count($playlist_obj->items) > 0) {
        $playlist_obj->views();
    }
    $playlist_obj->display();
    $playlist_obj->entry_form();
    ?>
        </form>
        <br class="clear">
	</div>
	<?php 
}
/**
 * Mark an event employee as paid.
 *
 * @since	1.3
 * @param	int		$employee_id	User ID of employee
 * @param	int		$event_id		Event ID
 * @param	int		$txn_id			The transaction ID associated with this payment.
 * @return	bool	True if payment data updated for event employee, otherwise false.
 */
function mdjm_set_employee_paid($employee_id, $event_id, $txn_id = '')
{
    global $wp_roles;
    if (!mdjm_get_option('enable_employee_payments')) {
        return;
    }
    if (!mdjm_is_employee($employee_id)) {
        return false;
    }
    $return = false;
    if ($employee_id == mdjm_get_event_primary_employee($event_id)) {
        /**
         *
         * Hook fires before marking event employee as paid.
         *
         * @since	1.3
         * @param	int	$event_id	The event ID.
         */
        do_action("mdjm_pre_mdjm_set_employee_paid_{$employee_id}", $event_id);
        $role = 'dj';
        $payment = mdjm_get_txn_price($txn_id);
        $payment_data = get_post_meta($event_id, '_mdjm_event_dj_payment_status', true);
        $payment_data['payment_status'] = mdjm_get_employees_event_wage($event_id, $employee_id) > $payment ? 'part-paid' : 'paid';
        $payment_data['payment_date'] = current_time('mysql');
        $payment_data['txn_id'] = $txn_id;
        $payment_data['payment_amount'] = $payment;
        $payment_update = update_post_meta($event_id, '_mdjm_event_dj_payment_status', $payment_data);
        if (!empty($payment_update)) {
            MDJM()->debug->log_it(sprintf('%s successfully paid %s for Event %d', mdjm_get_employee_display_name($employee_id), mdjm_currency_filter(mdjm_get_txn_price($txn_id)), $event_id));
            $return = true;
        } else {
            MDJM()->debug->log_it(sprintf('Unable to pay %s for Event %d', mdjm_get_employee_display_name($employee_id), $event_id));
            $return = false;
        }
    } else {
        $payment_data = get_post_meta($event_id, '_mdjm_event_employees_data', true);
        if (!mdjm_employee_working_event($event_id, $employee_id)) {
            MDJM()->debug->log_it('Employee not working this event');
            return false;
        } else {
            /**
             *
             * Hook fires before marking event employee as paid.
             *
             * @since	1.3
             * @param	int	$event_id	The event ID.
             */
            do_action("mdjm_pre_mdjm_set_employee_paid_{$employee_id}", $event_id);
            $role = $payment_data[$employee_id]['role'];
            $payment = mdjm_get_txn_price($payment_data[$employee_id]['txn_id']);
            $payment_data[$employee_id]['payment_status'] = mdjm_get_employees_event_wage($event_id, $employee_id) > $payment ? 'part-paid' : 'paid';
            $payment_data[$employee_id]['payment_date'] = current_time('mysql');
            $payment_data[$employee_id]['payment_amount'] = $payment;
            $payment_update = mdjm_update_txn_meta($payment_data[$employee_id]['txn_id'], array('_mdjm_txn_status' => 'Completed'));
            if (!empty($payment_update)) {
                $payment_update = update_post_meta($event_id, '_mdjm_event_employees_data', $payment_data);
            }
            if (!empty($payment_update)) {
                MDJM()->debug->log_it(sprintf('%s successfully paid %s for Event %d', mdjm_get_employee_display_name($employee_id), mdjm_currency_filter(mdjm_get_txn_price($txn_id)), $event_id));
                $return = true;
            } else {
                MDJM()->debug->log_it(sprintf('Unable to pay %s for Event %d', mdjm_get_employee_display_name($employee_id), $event_id));
                $return = false;
            }
        }
    }
    if (!empty($return)) {
        $journal_args = array('user_id' => 1, 'event_id' => $event_id, 'comment_content' => sprintf(__('Employee %s paid %s for their role as %s', 'mobile-dj-manager'), mdjm_get_employee_display_name($employee_id), $payment, translate_user_role($wp_roles->roles[$role]['name'])));
        $journal_meta = array('mdjm_visibility' => !empty($meta['visibility']) ? $meta['visibility'] : '2');
        mdjm_add_journal($journal_args, $journal_meta);
        /**
         *
         * Hook fires after successfully marking event employee as paid.
         *
         * @since	1.3
         * @param	int	$event_id	The event ID.
         * @param	int	$txn_id		The transaction ID associated with the payment
         */
        do_action("mdjm_post_mdjm_set_employee_paid_{$employee_id}", $event_id, $txn_id);
    }
    return $return;
}