Exemplo n.º 1
0
/**
 * Log the primary employees payment settings and update if employee or wage changes.
 *
 * @since	1.3
 * @param	int			$event_id	Event ID.
 * @param	arr			$old_meta	Old meta values from before event save.
 * @param	arr			$new_meta	New meta values after event save.
 * @return	void
 */
function mdjm_manage_primary_employee_payment_status($event_id, $old_meta, $new_meta)
{
    if (!mdjm_get_option('enable_employee_payments')) {
        return;
    }
    $mdjm_event = new MDJM_Event($event_id);
    $employee_id = $mdjm_event->get_employee();
    if (empty($employee_id)) {
        return;
    }
    $payment_amount = mdjm_get_employees_event_wage($event_id, $employee_id);
    $payment_status = get_post_meta($event_id, '_mdjm_event_dj_payment_status', true);
    if (empty($payment_status)) {
        if (empty($payment_amount) || $payment_amount < 1) {
            return;
        }
        $mdjm_txn = new MDJM_Txn();
        $mdjm_txn->create(array('post_title' => sprintf(__('Wage payment to %s for %d', 'mobile-dj-manager'), mdjm_get_employee_display_name($employee_id), $event_id), 'post_status' => 'mdjm-expenditure', 'post_author' => 1, 'post_parent' => $event_id), array('_mdjm_txn_status' => 'Pending', '_mdjm_payment_to' => $employee_id, '_mdjm_txn_total' => $payment_amount));
        if (!empty($mdjm_txn)) {
            $data['txn_id'] = $mdjm_txn->ID;
        }
        mdjm_set_txn_type($mdjm_txn->ID, mdjm_get_txn_cat_id('slug', 'mdjm-employee-wages'));
        $payment_data = array('payment_status' => 'unpaid', 'payment_date' => '', 'txn_id' => $mdjm_txn->ID, 'payment_amount' => '');
        update_post_meta($event_id, '_mdjm_event_dj_payment_status', $payment_data);
    } else {
        if ($payment_status['payment_status'] == 'paid') {
            return;
        }
        if (in_array($mdjm_event->post_status, array('mdjm-cancelled', 'mdjm-rejected', 'mdjm-failed'))) {
            update_post_meta($mdjm_txn->ID, '_mdjm_txn_status', 'Cancelled');
        }
        $mdjm_txn = new MDJM_Txn($payment_status['txn_id']);
        if ($mdjm_txn->recipient_id != $employee_id) {
            update_post_meta($mdjm_txn->ID, '_mdjm_payment_to', $employee_id);
        }
        if ($payment_amount != $mdjm_txn->price) {
            update_post_meta($mdjm_txn->ID, '_mdjm_txn_total', $payment_amount);
        }
    }
}
Exemplo n.º 2
0
/**
 * Returns the primary employee ID.
 *
 * @since	1.3
 * @param	int		$event_id	The event ID.
 * @return	int					The user ID of the events primary employee.
 */
function mdjm_get_event_primary_employee_id($event_id)
{
    if (empty($event_id)) {
        return false;
    }
    $event = new MDJM_Event($event_id);
    return $event->get_employee();
}