コード例 #1
0
/**
 * 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;
}
コード例 #2
0
/**
 * Sets the recipients that should receive a copy of the email
 *
 * @since	1.3
 * @param	str		$recipient	The address of the original email recipient
 * @param	int		$event_id	Event ID to which the email is associated
 * @param	arr		$others		Array of additional addresses to whom to send a copy of the email
 * @return	arr		$copy_to	Array of addresses to send a copy of the email to
 */
function mdjm_email_maybe_send_a_copy($recipient, $event_id = '', $others = array())
{
    if (is_array($recipient)) {
        return;
    }
    if (!empty($event_id)) {
        $client = get_userdata(mdjm_get_event_client_id($event_id));
        $employee = get_userdata(mdjm_get_event_primary_employee($event_id));
    } else {
        $client = get_user_by('email', $recipient);
    }
    if (!$client) {
        return;
    }
    if (!mdjm_user_is_client($client->ID)) {
        return;
    }
    $copy_to = array();
    if (mdjm_get_option('bcc_admin_to_client')) {
        $copy_to[] = mdjm_get_option('system_email');
    }
    if (mdjm_get_option('bcc_dj_to_client') && !empty($employee)) {
        $copy_to[] = $employee->user_email;
    }
    $copy_to = array_merge($others, $copy_to);
    return array_unique($copy_to);
}
コード例 #3
0
ファイル: events.php プロジェクト: mdjm/mobile-dj-manager
/**
 * Define the data to be displayed in each of the custom columns for the Transaction post types
 *
 * @since	0.9
 * @param	str		$column_name	The name of the column to display
 * @param	int		$post_id		The current post ID
 * @return
 */
function mdjm_event_posts_custom_column($column_name, $post_id)
{
    global $post;
    if (mdjm_employee_can('edit_txns') && ($column_name == 'value' || $column_name == 'balance')) {
        $value = mdjm_get_event_price($post_id);
    }
    switch ($column_name) {
        // Event Date
        case 'event_date':
            if (mdjm_employee_can('read_events')) {
                echo '<strong><a href="' . admin_url('post.php?post=' . $post_id . '&action=edit') . '">' . date('d M Y', strtotime(get_post_meta($post_id, '_mdjm_event_date', true))) . '</a>';
            } else {
                echo '<strong>' . date('d M Y', strtotime(get_post_meta($post_id, '_mdjm_event_date', true))) . '</strong>';
            }
            break;
            // Client
        // Client
        case 'client':
            $client = get_userdata(get_post_meta($post->ID, '_mdjm_event_client', true));
            if (!empty($client)) {
                if (mdjm_employee_can('send_comms')) {
                    printf('<a href="%s">%s</a>', add_query_arg(array('recipient' => $client->ID, 'event_id' => $post_id), admin_url('admin.php?page=mdjm-comms')), $client->display_name);
                } else {
                    echo $client->display_name;
                }
            } else {
                _e('<span class="mdjm-form-error">Not Assigned</span>', 'mobile-dj-manager');
            }
            break;
            // Employees
        // Employees
        case 'employees':
            global $wp_roles;
            $primary = get_userdata(mdjm_get_event_primary_employee($post->ID));
            $employees = mdjm_get_event_employees_data($post->ID);
            if (!empty($primary)) {
                if (mdjm_employee_can('send_comms')) {
                    printf('<a href="%s" title="%s">%s</a>', add_query_arg(array('recipient' => $primary->ID, 'event_id' => $post_id), admin_url('admin.php?page=mdjm-comms')), mdjm_get_option('artist', __('DJ', 'mobile-dj-manager')), $primary->display_name);
                } else {
                    echo '<a title="' . mdjm_get_option('artist', __('DJ', 'mobile-dj-manager')) . '">' . $primary->display_name . '</a>';
                }
            } else {
                _e('<span class="mdjm-form-error">Not Assigned</span>', 'mobile-dj-manager');
            }
            if (!empty($employees)) {
                echo '<br />';
                $i = 1;
                foreach ($employees as $employee) {
                    echo '<em>';
                    if (mdjm_employee_can('send_comms')) {
                        printf('<a href="%s" title="%s">%s</a>', add_query_arg(array('recipient' => $employee['id'], 'event_id' => $post_id), admin_url('admin.php?page=mdjm-comms')), translate_user_role($wp_roles->roles[$employee['role']]['name']), mdjm_get_employee_display_name($employee['id']));
                    } else {
                        echo '<a title="' . translate_user_role($wp_roles->roles[$employee['role']]['name']) . '">' . mdjm_get_employee_display_name($employee['id']) . '</a>';
                    }
                    echo '</em>';
                    if ($i != count($employees)) {
                        echo '<br />';
                    }
                }
            }
            break;
            // Status
        // Status
        case 'event_status':
            echo get_post_status_object($post->post_status)->label;
            break;
            // Event Type
        // Event Type
        case 'event_type':
            $event_types = get_the_terms($post_id, 'event-types');
            if (is_array($event_types)) {
                foreach ($event_types as $key => $event_type) {
                    $event_types[$key] = $event_type->name;
                }
                echo implode("<br/>", $event_types);
            }
            break;
            // Value
        // Value
        case 'value':
            if (mdjm_employee_can('edit_txns')) {
                if (!empty($value) && $value != '0.00') {
                    echo mdjm_currency_filter(mdjm_format_amount($value));
                    echo '<br />';
                } else {
                    echo '<span class="mdjm-form-error">' . mdjm_currency_filter(mdjm_format_amount('0.00')) . '</span>';
                }
            } else {
                echo '&mdash;';
            }
            break;
            // Balance
        // Balance
        case 'balance':
            if (mdjm_employee_can('edit_txns')) {
                echo mdjm_currency_filter(mdjm_format_amount(mdjm_get_event_balance($post_id)));
                echo '<br />';
                $deposit_status = mdjm_get_event_deposit_status($post_id);
                if ('Paid' == mdjm_get_event_deposit_status($post_id)) {
                    printf(__('<i title="%s %s paid" class="fa fa-check-square-o" aria-hidden="true">', 'mobile-dj-manager'), mdjm_currency_filter(mdjm_format_amount(mdjm_get_event_deposit($post_id))), mdjm_get_deposit_label());
                }
            } else {
                echo '&mdash;';
            }
            break;
            // Playlist
        // Playlist
        case 'playlist':
            if (mdjm_employee_can('read_events')) {
                $total = mdjm_count_playlist_entries($post_id);
                echo '<a href="' . mdjm_get_admin_page('playlists') . $post_id . '">' . $total . ' ' . _n('Song', 'Songs', $total, 'mobile-dj-manager') . '</a>' . "\r\n";
            } else {
                echo '&mdash;';
            }
            break;
            // Journal
        // Journal
        case 'journal':
            if (mdjm_employee_can('read_events_all')) {
                $total = wp_count_comments($post_id)->approved;
                echo '<a href="' . admin_url('/edit-comments.php?p=' . $post_id) . '">' . $total . ' ' . _n('Entry', 'Entries', $total, 'mobile-dj-manager') . '</a>' . "\r\n";
            } else {
                echo '&mdash;';
            }
            break;
    }
    // switch
}