/** * List the event transactions for client view * * @params int $eventID Required. Post ID of the event * str $display Optional: 'list' to list each payment date, amount and reason * * @return str 'No Payments Received' if no txns, otherwise txn detail as specified by $display */ function list_event_transactions($eventID, $display = 'list') { $txns = $this->get_transactions($eventID, 'mdjm-income', 'Completed', 'obj'); if (empty($txns)) { return __('No Payments Found', 'mobile-dj-manager'); } $i = 1; switch ($display) { case 'list': foreach ($txns as $txn) { $types = wp_get_object_terms($txn->ID, 'transaction-types'); $txn_type = !is_wp_error($types) && !empty($types) ? $types[0]->name : ''; $output = mdjm_currency_filter(mdjm_sanitize_amount(get_post_meta($txn->ID, '_mdjm_txn_total', true))); $output .= ' '; $output .= 'on ' . date(MDJM_SHORTDATE_FORMAT, strtotime($txn->post_date)) . ' (' . $txn_type . ')'; if ($i < count($txns)) { $output .= '<br />'; } $i++; } break; } return $output; }
public function single_event() { global $clientzone, $mdjm, $my_mdjm, $mdjm_settings, $post; if (isset($_POST['submit']) && $_POST['submit'] == 'Submit Changes') { $this->update_event(); } $event = isset($_GET['event_id']) ? get_post($_GET['event_id']) : $my_mdjm['next'][0]; $post = $event; if (!MDJM()->events->is_my_event($event->ID)) { if (MDJM_DEBUG == true) { MDJM()->debug->log_it('ERROR: ' . get_current_user_id() . ' is attempting to access event ID ' . $event->ID . ' which is not theirs. In ' . __METHOD__, true); } wp_die($clientzone->display_message(9, 5), 'Event Ownership Error'); } $eventinfo = MDJM()->events->event_detail($event->ID); $expired = array('mdjm-failed', 'mdjm-cancelled', 'mdjm-completed'); // Event not active if (in_array($event->post_status, $expired)) { echo $clientzone->__text('home_notactive', '<p>The selected event is no longer active. <a href="' . mdjm_get_formatted_url(MDJM_CONTACT_PAGE, false) . '" title="Begin planning your next event with us">Contact us now</a> begin planning your next event.</p>'); } else { echo '<div id="mdjm_event_updated"></div>'; echo '<p>' . __('Below are the details of your upcoming event on ' . date('l, jS F Y', $eventinfo['date']) . '.') . '</p>' . "\r\n"; echo '<p>If any of the event details are incorrect, please <a href="mailto:' . $mdjm_settings['email']['system_email'] . '">contact me now</a>.</p>' . "\r\n"; // Incomplete Profile warning if (!$clientzone->client_profile_complete($my_mdjm['me']->ID) && $clientzone->warn_profile()) { $clientzone->display_notice(3, 'Your <a href="' . mdjm_get_formatted_url(MDJM_PROFILE_PAGE, false) . '">profile</a> appears to be incomplete. Please <a href="' . mdjm_get_formatted_url(MDJM_PROFILE_PAGE, false) . '">click here</a> to update it now. Incorrect <a href="' . mdjm_get_formatted_url(MDJM_PROFILE_PAGE, false) . '">profile</a> information can cause problems with your booking.'); } // Display the event details echo '<form name="mdjm_event" id="mdjm_event" method="post">' . "\r\n"; echo '<input type="hidden" name="event_id" id="event_id" value="' . $event->ID . '" />' . "\r\n"; wp_nonce_field('manage_client_event', '__mdjm_event'); $this->display_action_buttons($event->ID, $event->post_status); echo '<div id="mdjm-event-container">' . "\r\n"; echo '<div id="mdjm-event-table">' . "\r\n"; echo '<table id="mdjm-event-listing">' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th colspan="4"><span style="text-decoration: underline;">' . __('Event Details') . '</span> ' . $this->edit_event_link('edit', $event->ID) . '</th>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 20%;">' . __('Event Name:') . '</th>' . "\r\n"; echo '<td colspan="3">' . (!empty($eventinfo['name']) ? esc_attr($eventinfo['name']) : $eventinfo['type']) . '</span> ' . $this->edit_event_link('change', $event->ID) . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Status:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . __(get_post_status_object($event->post_status)->label) . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Your ' . MDJM_DJ . ':') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . (!empty($eventinfo['dj']->display_name) ? $eventinfo['dj']->display_name : $eventinfo['dj']) . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Event Date:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . date(MDJM_SHORTDATE_FORMAT, $eventinfo['date']) . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Event Type:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . __($eventinfo['type']) . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Start Time:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $eventinfo['start'] . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('End Time:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $eventinfo['finish'] . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; if (MDJM_PACKAGES == true) { echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Package:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">'; if (!empty($eventinfo['package'])) { $eventinfo['package'] = get_package_details($eventinfo['package']); echo !empty($eventinfo['package']) ? '<a title="' . (!empty($eventinfo['package']['desc']) ? $eventinfo['package']['desc'] : '') . (!empty($mdjm_settings['clientzone']['package_prices']) ? ' - ' . mdjm_currency_filter(mdjm_sanitize_amount($eventinfo['package']['cost'])) : '') . '">' . $eventinfo['package']['name'] . '</a>' : 'None'; } else { echo 'None'; } echo '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Addons:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">'; $eventinfo['addons'] = get_post_meta($event->ID, '_mdjm_event_addons', true); if (!empty($eventinfo['addons'])) { $i = 1; foreach ($eventinfo['addons'] as $addon) { $item = get_addon_details($addon); echo '<a title="' . (!empty($item['desc']) ? $item['desc'] : '') . (!empty($mdjm_settings['clientzone']['package_prices']) ? ' - ' . mdjm_currency_filter(mdjm_sanitize_amount($item['cost'])) : '') . '">' . $item['name'] . '</a>'; echo $i < count($eventinfo['addons']) ? '<br />' : ''; $i++; } } else { echo 'None'; } '</td>' . "\r\n"; echo '</tr>' . "\r\n"; } // if( MDJM_PACKAGES == true ) echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Total Cost:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $eventinfo['cost'] . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __(mdjm_get_deposit_label()) . ':</th>' . "\r\n"; echo '<td style="width: 35%;">' . $eventinfo['deposit'] . ' (' . __($eventinfo['deposit_status']) . ')</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __(mdjm_get_balance_label()) . ':</th>' . "\r\n"; echo '<td colspan="3">' . $eventinfo['balance'] . ' (' . __($eventinfo['balance_status']) . ')</td>' . "\r\n"; echo '</tr>' . "\r\n"; if (!empty($eventinfo['notes'])) { echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Information:') . '</th>' . "\r\n"; echo '<td colspan="3">' . stripslashes($eventinfo['notes']) . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; } echo '<tr>' . "\r\n"; echo '<td colspan="4"> </td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th colspan="4"><span style="text-decoration: underline;">' . __('Your Contact Details') . '</span> <a href="' . mdjm_get_formatted_url(MDJM_PROFILE_PAGE, false) . '">' . __('edit') . '</a></th>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Name:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $my_mdjm['me']->display_name . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Phone:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $my_mdjm['me']->phone1 . ' ' . (!empty($my_mdjm['me']->phone2) ? $my_mdjm['me']->phone2 : '') . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Email:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $my_mdjm['me']->user_email . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Address:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . $clientzone->get_client_address() . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<td colspan="4"> </td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '<tr>' . "\r\n"; echo '<th colspan="4"><span style="text-decoration: underline;">' . __('Venue Details') . '</span></th>' . "\r\n"; echo '</tr>' . "\r\n"; $venue_details = MDJM()->events->mdjm_get_venue_details(get_post_meta($event->ID, '_mdjm_event_venue_id', true), $event->ID); echo '<tr>' . "\r\n"; echo '<th style="width: 15%;">' . __('Venue:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . stripslashes($venue_details['name']) . '</td>' . "\r\n"; echo '<th style="width: 15%;">' . __('Address:') . '</th>' . "\r\n"; echo '<td style="width: 35%;">' . implode('<br />', $venue_details['full_address']) . '</td>' . "\r\n"; echo '</tr>' . "\r\n"; echo '</table>' . "\r\n"; echo '</div>' . "\r\n"; // End div mdjm-event-table echo '</div>' . "\r\n"; // End div mdjm-event-container echo '</form>' . "\r\n"; } // foreach( $posts as $post ) }
/** * Update the event deposit amount based upon the event cost * and the payment settings. * * @since 1.0 * @return void */ function mdjm_update_event_deposit_ajax() { $event_cost = $_POST['current_cost']; $deposit = mdjm_calculate_deposit($event_cost); if (!empty($deposit)) { $result['type'] = 'success'; $result['deposit'] = mdjm_sanitize_amount($deposit); } else { $result['type'] = 'error'; $result['msg'] = 'Unable to calculate deposit'; } $result = json_encode($result); echo $result; die; }
/** * Retrieves the total of all transactions over the given date period. * Total income - total expenditure if $status = any * * @since 1.4 * @param str $period The date period for which to collect the stats * @param int $status The transaction status' for which to collect the stats * @return int $total The total value for all transactions that meet the criteria */ public function get_txns_total_by_date($period = 'this_week', $status = 'any') { $this->setup_dates($period); $args = array('post_status' => $status, 'date_query' => array($this->start_date), 'meta_query' => array(array('key' => '_mdjm_txn_status', 'value' => 'Completed'))); $txns = mdjm_get_txns($args); $total = 0; if ($txns) { foreach ($txns as $txn) { if ($args['post_status'] == 'any') { if ($txn->post_status == 'mdjm-income') { $total += mdjm_sanitize_amount(get_post_meta($txn->ID, '_mdjm_txn_total', true)); } else { $total -= mdjm_sanitize_amount(get_post_meta($txn->ID, '_mdjm_txn_total', true)); } } else { $total += mdjm_sanitize_amount(get_post_meta($txn->ID, '_mdjm_txn_total', true)); } } } $total = apply_filters('get_txns_total_by_date', $total, $period, $status); return mdjm_currency_filter(mdjm_format_amount($total)); }
public function event_detail($post_id) { global $mdjm; if (empty($post_id) || !is_string(get_post_status($post_id))) { return; } $event_stati = mdjm_all_event_status(); $name = get_post_meta($post_id, '_mdjm_event_name', true); $date = get_post_meta($post_id, '_mdjm_event_date', true); $end_date = get_post_meta($post_id, '_mdjm_event_end_date', true); $client = get_post_meta($post_id, '_mdjm_event_client', true); $dj = get_post_meta($post_id, '_mdjm_event_dj', true); $dj_wage = get_post_meta($post_id, '_mdjm_event_dj_wage', true); $cost = get_post_meta($post_id, '_mdjm_event_cost', true); $deposit = get_post_meta($post_id, '_mdjm_event_deposit', true); $deposit_status = get_post_meta($post_id, '_mdjm_event_deposit_status', true); $paid = MDJM()->txns->get_transactions($post_id, 'mdjm-income'); $balance_status = get_post_meta($post_id, '_mdjm_event_balance_status', true); $start = get_post_meta($post_id, '_mdjm_event_start', true); $finish = get_post_meta($post_id, '_mdjm_event_finish', true); $status = !empty($event_stati[get_post_status($post_id)]) ? $event_stati[get_post_status($post_id)] : ''; $setup_date = get_post_meta($post_id, '_mdjm_event_djsetup', true); $setup_time = get_post_meta($post_id, '_mdjm_event_djsetup_time', true); $contract = get_post_meta($post_id, '_mdjm_event_contract', true); $contract_date = get_post_meta($post_id, '_mdjm_event_contract_approved', true); $signed_contract = get_post_meta($post_id, '_mdjm_event_signed_contract', true); $notes = get_post_meta($post_id, '_mdjm_event_notes', true); $dj_notes = get_post_meta($post_id, '_mdjm_event_dj_notes', true); $admin_notes = get_post_meta($post_id, '_mdjm_event_admin_notes', true); $package = get_post_meta($post_id, '_mdjm_event_package', true); $addons = get_post_meta($post_id, '_mdjm_event_addons', true); $online_quote = get_post_meta($post_id, '_mdjm_online_quote', true); $guest_playlist = get_post_meta($post_id, '_mdjm_event_playlist_access', true); $eventinfo = array('name' => !empty($name) ? $name : '', 'date' => !empty($date) && is_int(strtotime($date)) ? strtotime($date) : __('Not Specified', 'mobile-dj-manager'), 'end_date' => !empty($end_date) && is_int(strtotime($end_date)) ? strtotime($end_date) : __('Not Specified', 'mobile-dj-manager'), 'client' => !empty($client) ? get_userdata($client) : '', 'dj' => !empty($dj) ? get_userdata($dj) : __('Not Assigned', 'mobile-dj-manager'), 'dj_wage' => !empty($dj_wage) ? mdjm_currency_filter(mdjm_sanitize_amount($dj_wage)) : __('Not Specified', 'mobile-dj-manager'), 'start' => !empty($start) ? date(MDJM_TIME_FORMAT, strtotime($start)) : __('Not Specified', 'mobile-dj-manager'), 'finish' => !empty($finish) ? date(MDJM_TIME_FORMAT, strtotime($finish)) : __('Not Specified', 'mobile-dj-manager'), 'status' => !empty($status) ? $status : '', 'setup_date' => !empty($setup_date) ? strtotime($setup_date) : __('Not Specified', 'mobile-dj-manager'), 'setup_time' => !empty($setup_time) ? date(MDJM_TIME_FORMAT, strtotime($setup_time)) : __('Not Specified', 'mobile-dj-manager'), 'cost' => !empty($cost) ? mdjm_currency_filter(mdjm_sanitize_amount($cost)) : __('Not Specified', 'mobile-dj-manager'), 'deposit' => !empty($deposit) ? mdjm_currency_filter(mdjm_sanitize_amount($deposit)) : '0.00', 'balance' => !empty($paid) && $paid != '0.00' && !empty($cost) ? mdjm_currency_filter(mdjm_sanitize_amount($cost - $paid)) : mdjm_currency_filter(mdjm_sanitize_amount($cost)), 'deposit_status' => !empty($deposit_status) ? $deposit_status : __('Due', 'mobile-dj-manager'), 'balance_status' => !empty($balance_status) ? $balance_status : __('Due', 'mobile-dj-manager'), 'payment_history' => MDJM()->txns->list_event_transactions($post_id), 'type' => $this->get_event_type($post_id), 'online_quote' => mdjm_get_option('online_enquiry', false) && !empty($online_quote) ? $online_quote : '', 'contract' => !empty($contract) ? $contract : '', 'contract_date' => !empty($contract_date) ? date(MDJM_SHORTDATE_FORMAT, strtotime($contract_date)) : date(MDJM_SHORTDATE_FORMAT), 'signed_contract' => !empty($signed_contract) ? $signed_contract : '', 'notes' => !empty($notes) ? $notes : '', 'dj_notes' => !empty($dj_notes) ? $dj_notes : '', 'admin_notes' => !empty($admin_notes) ? $admin_notes : '', 'package' => !empty($package) ? $package : '', 'addons' => !empty($addons) ? implode("\n", $addons) : '', 'guest_playlist' => !empty($guest_playlist) ? mdjm_get_formatted_url(MDJM_PLAYLIST_PAGE) . 'mdjmeventid=' . $guest_playlist : ''); // Allow the $eventinfo array to be filtered $eventinfo = apply_filters('mdjm_event_info', $eventinfo); return $eventinfo; }
/** * Output the event transaction list table * * @since 1.3.7 * @global obj $mdjm_event MDJM_Event class object * @global bool $mdjm_event_update True if this event is being updated, false if new. * @param int $event_id The event ID. * @return str */ function mdjm_event_metabox_txn_add_new_row($event_id) { global $mdjm_event, $mdjm_event_update; mdjm_insert_datepicker(array('id' => 'mdjm_txn_display_date', 'altfield' => 'mdjm_txn_date', 'maxdate' => 'today')); ?> <div id="mdjm-event-add-txn-table"> <table id="mdjm_event_add_txn_table" class="widefat mdjm_event_add_txn_table mdjm_form_fields"> <thead> <tr> <th colspan="3"><?php _e('Add Transaction', 'mobile-dj-manager'); ?> <a id="toggle_add_txn_fields" class="mdjm-small mdjm-fake"><?php _e('show form', 'mobile-dj-manager'); ?> </a></th> </tr> </thead> <tbody class="mdjm-hidden"> <tr> <td><label for="mdjm_txn_amount"><?php _e('Amount:', 'mobile-dj-manager'); ?> </label><br /> <?php echo mdjm_currency_symbol() . MDJM()->html->text(array('name' => 'mdjm_txn_amount', 'class' => 'mdjm-input-currency', 'placeholder' => mdjm_sanitize_amount('10'))); ?> </td> <td><label for="mdjm_txn_display_date"><?php _e('Date:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->text(array('name' => 'mdjm_txn_display_date', 'class' => '')) . MDJM()->html->hidden(array('name' => 'mdjm_txn_date')); ?> </td> <td><label for="mdjm_txn_amount"><?php _e('Direction:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->select(array('name' => 'mdjm_txn_direction', 'options' => array('In' => __('Incoming', 'mobile-dj-manager'), 'Out' => __('Outgoing', 'mobile-dj-manager')), 'show_option_all' => false, 'show_option_none' => false)); ?> </td> </tr> <tr> <td><span id="mdjm_txn_from_container"><label for="mdjm_txn_from"><?php _e('From:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->text(array('name' => 'mdjm_txn_from', 'class' => '', 'placeholder' => __('Leave empty if client', 'mobile-dj-manager'))); ?> </span> <span id="mdjm_txn_to_container" class="mdjm-hidden"><label for="mdjm_txn_to"><?php _e('To:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->text(array('name' => 'mdjm_txn_to', 'class' => '', 'placeholder' => __('Leave empty if client', 'mobile-dj-manager'))); ?> </span></td> <td><label for="mdjm_txn_for"><?php _e('For:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->txn_type_dropdown(); ?> </td> <td><label for="mdjm_txn_src"><?php _e('Paid via:', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->select(array('name' => 'mdjm_txn_src', 'options' => mdjm_get_txn_source(), 'selected' => mdjm_get_option('default_type', 'Cash'), 'show_option_all' => false, 'show_option_none' => false)); ?> </td> </tr> <?php if (mdjm_get_option('manual_payment_cfm_template')) { ?> <tr id="mdjm-txn-email"> <td colspan="3"><?php echo MDJM()->html->checkbox(array('name' => 'mdjm_manual_txn_email', 'current' => mdjm_get_option('manual_payment_cfm_template') ? true : false, 'class' => 'mdjm-checkbox')); ?> <?php _e('Send manual payment confirmation email?', 'mobile-dj-manager'); ?> </td> </tr> <?php } ?> </tbody> </table> </div> <p id="save-event-txn" class="mdjm-hidden"><a id="save_transaction" class="button button-primary button-small"><?php _e('Add Transaction', 'mobile-dj-manager'); ?> </a></p> <?php }
public function notification_content($task) { global $mdjm, $mdjm_settings; if (empty($task)) { if (MDJM_DEBUG == true) { MDJM()->debug->log_it('ERROR: No task was parsed ' . __METHOD__); } } else { if (MDJM_DEBUG == true) { MDJM()->debug->log_it('Creating notification content for ' . $task['taskinfo']['name']); } } /* -- Start the email content -- */ $content = 'The ' . $task['taskinfo']['name'] . ' scheduled task from ' . MDJM_COMPANY . ' has completed. ' . "\r\n" . "\r\n" . 'Task Start time: ' . date('H:i:s l, jS F Y', $task['start']) . "\r\n" . "\r\n"; /* Build the email content relating to the current task */ switch ($task['taskinfo']['slug']) { case 'complete-events': // Notification content for Complete Events task $content .= $task['total'] . ' event(s) have been marked as completed...' . "\r\n" . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; /* -- List each event -- */ foreach ($task['data'] as $eventinfo) { $content .= 'Event ID: ' . $eventinfo['id'] . "\r\n" . 'Date: ' . $eventinfo['date'] . "\r\n" . 'Venue: ' . $eventinfo['venue'] . "\r\n" . 'Client: ' . $eventinfo['client'] . "\r\n" . 'DJ: ' . $eventinfo['djinfo']->display_name . "\r\n" . 'Link: ' . get_edit_post_link($eventinfo['id'], '') . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; } // End Foreach break; case 'fail-enquiry': $content .= $task['total'] . ' enquiry(s) have been marked as lost...' . "\r\n" . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; foreach ($task['data'] as $eventinfo) { $content .= 'Event ID: ' . $eventinfo['id'] . "\r\n" . 'Date: ' . $eventinfo['date'] . "\r\n" . 'Client: ' . $eventinfo['client'] . "\r\n" . 'DJ: ' . $eventinfo['djinfo']->display_name . "\r\n" . 'Link: ' . get_edit_post_link($eventinfo['id'], '') . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; } // End Foreach break; case 'request-deposit': $content .= $task['total'] . ' deposit requests ' . (!empty($task['taskinfo']['options']['email_client']) && $task['taskinfo']['options']['email_client'] == 'Y' ? ' have been sent' : ' need to be requested') . "\r\n" . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; foreach ($task['data'] as $eventinfo) { $content .= 'Event ID: ' . $eventinfo['id'] . "\r\n" . 'Date: ' . $eventinfo['date'] . "\r\n" . 'Client: ' . $eventinfo['client'] . "\r\n" . 'DJ: ' . $eventinfo['djinfo']->display_name . "\r\n" . mdjm_get_deposit_label() . ': ' . mdjm_currency_filter(mdjm_sanitize_amount($eventinfo['deposit'])) . "\r\n" . 'Link: ' . get_edit_post_link($eventinfo['id'], '') . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; } // End Foreach break; case 'balance-reminder': $content .= $task['total'] . ' balance requests have been sent' . "\r\n" . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; foreach ($task['data'] as $eventinfo) { $content .= 'Event ID: ' . $eventinfo['id'] . "\r\n" . 'Date: ' . $eventinfo['date'] . "\r\n" . 'Client: ' . $eventinfo['client'] . "\r\n" . 'DJ: ' . $eventinfo['djinfo']->display_name . "\r\n" . mdjm_get_balance_label() . ' Due: ' . mdjm_currency_filter(mdjm_sanitize_amount($eventinfo['cost'] - $eventinfo['deposit'])) . "\r\n" . 'Link: ' . get_edit_post_link($eventinfo['id'], '') . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; } // End Foreach break; case 'client-feedback': $content .= $task['total'] . ' client feedback requests have been sent' . "\r\n" . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; foreach ($task['data'] as $eventinfo) { $content .= 'Event ID: ' . $eventinfo['id'] . "\r\n" . 'Date: ' . $eventinfo['date'] . "\r\n" . 'Client: ' . $eventinfo['client'] . "\r\n" . 'DJ: ' . $eventinfo['djinfo']->display_name . "\r\n" . '----------------------------------------' . '----------------------------------------' . "\r\n"; } break; } // Switch /* -- Complete the email content -- */ $content .= 'Task End time: ' . date('H:i:s l, jS F Y', $task['end']) . "\r\n" . "\r\n" . 'This email was generated by the MDJM Event Management for WordPress plugin - http://mdjm.co.uk'; /* -- Return the content -- */ return $content; }
/** * Retrieve the event balance status * * @since 1.3 * @return str */ public function get_balance_status() { if (!isset($this->balance_status)) { $this->balance_status = get_post_meta($this->ID, '_mdjm_event_balance_status', true); if (!$this->balance_status || $this->balance_status != 'Paid' || $this->get_price() > 0) { $this->balance_status = 'Due'; if (mdjm_sanitize_amount($this->get_total_income()) >= mdjm_sanitize_amount($this->get_price())) { $this->balance_status = 'Paid'; } } else { if (empty($this->price) || $this->price == '0.00') { $this->balance_status = 'Paid'; } else { $this->balance_status = 'Due'; } } } /** * Override the event balance status. * * @since 1.3 * * @param str $balance_status The event balance_status. * @param str|int $id The event ID. */ return apply_filters('mdjm_get_event_balance_status', $this->balance_status, $this->ID); }
/> <?php echo esc_html(mdjm_get_balance_label()); ?> – <?php echo mdjm_currency_filter(mdjm_format_amount($mdjm_event->get_balance())); ?> <br /> <input type="radio" name="mdjm_payment_amount" id="mdjm-payment-part" value="part_payment"<?php checked($selected, 'part_payment'); ?> /> <?php echo mdjm_get_other_amount_label(); ?> <span id="mdjm-payment-custom"<?php echo $other_amount_style; ?> ><?php echo mdjm_currency_symbol(); ?> <input type="text" class="mdjm_other_amount_input mdjm-input" name="part_payment" id="part-payment" placeholder="0.00" size="10" value="<?php echo mdjm_sanitize_amount(mdjm_get_option('other_amount_default', true, false)); ?> " /></span> <span class="mdjm-description"><?php printf(__('To pay a custom amount, select %s and enter the value into the text field.', 'mobile-dj-manager'), mdjm_get_other_amount_label()); ?> </span> </p> </fieldset>
/** * Calculate the event cost as the package changes * * @since 1.0 * @return void */ function mdjm_update_event_cost_from_package_ajax() { _deprecated_function(__FUNCTION__, '1.4'); $mdjm_event = new MDJM_Event($_POST['event_id']); $package = $mdjm_event->get_package(); $addons = $mdjm_event->get_addons(); $event_cost = $mdjm_event->price; $event_date = !empty($_POST['event_date']) ? $_POST['event_date'] : NULL; $base_cost = '0.00'; $package_price = $package ? (double) mdjm_get_package_price($package->ID, $event_date) : false; if ($event_cost) { $event_cost = (double) $event_cost; $base_cost = $package_price ? $event_cost - $package_price : $event_cost; } if ($addons) { foreach ($addons as $addon) { $addon_cost = mdjm_get_package_price($addon->ID, $event_date); $base_cost = $base_cost - (double) $addon_cost; } } $cost = $base_cost; $new_package = $_POST['package']; $new_package_price = !empty($new_package) ? mdjm_get_package_price($new_package, $event_date) : false; if ($new_package_price) { $cost = $base_cost + (double) $new_package_price; } if (!empty($cost)) { $result['type'] = 'success'; $result['cost'] = mdjm_sanitize_amount((double) $cost); } else { $result['type'] = 'success'; $result['cost'] = mdjm_sanitize_amount(0); } $result = json_encode($result); echo $result; die; }
/** * Generate a list of all event employees and output as a HTML table. * * @since 1.3 * @param * @return */ function mdjm_do_event_employees_list_table($event_id) { global $wp_roles; $employees = mdjm_get_event_employees_data($event_id); if (!$employees) { return; } ?> <table class="widefat mdjm_event_employee_list"> <thead> <tr> <th style="text-align:left; width:25%;"><?php _e('Role', 'mobile-dj-manager'); ?> </th> <th style="text-align:left; width:25%;"><?php _e('Name', 'mobile-dj-manager'); ?> </th> <th style="text-align:left; width:20%;"><?php _e('Wage', 'mobile-dj-manager'); ?> </th> <th style="text-align:left;"><?php _e('Status', 'mobile-dj-manager'); ?> </th> </tr> </thead> <tbody> <?php foreach ($employees as $employee) { ?> <tr class="mdjm_field_wrapper"> <td><?php echo translate_user_role($wp_roles->roles[$employee['role']]['name']); ?> </td> <td><?php echo mdjm_get_employee_display_name($employee['id']); ?> </td> <td> <?php if (mdjm_get_option('enable_employee_payments') && mdjm_employee_can('manage_txns')) { ?> <?php echo mdjm_currency_filter(mdjm_sanitize_amount($employee['wage'])); ?> <?php } ?> </td> <td> <?php if (mdjm_employee_can('mdjm_event_edit')) { ?> <?php if ('paid' != mdjm_get_employees_event_payment_status($event_id, $employee['id'])) { ?> <?php printf(__('<a class="button button-secondary button-small remove_event_employee" style="margin: 6px 0 10px;" data-employee_id="%1$d" id="remove-employee-%1$d">Remove</a>', 'mobile-dj-manager'), $employee['id']); ?> <?php } elseif (mdjm_get_option('enable_employee_payments')) { ?> <?php printf(__('<a href="%s">Paid</a>', 'mobile-dj-manager'), !empty($employee['txn_id']) ? get_edit_post_link($employee['txn_id']) : ''); ?> <?php } ?> <?php } ?> </td> </tr> <?php } ?> </tbody> </table> <?php }
/** * Content tag: total_cost. * The event start time. * * @param int The event ID. * * @return str Formatted event total cost. */ function mdjm_content_tag_total_cost($event_id = '') { if (empty($event_id)) { return; } $return = __('Not specified', 'mobile-dj-manager'); $cost = get_post_meta($event_id, '_mdjm_event_cost', true); if (!empty($cost)) { $return = mdjm_currency_filter(mdjm_sanitize_amount($cost)); } return $return; }
/** * Displays all event transactions within a table. * * @since 1.3.7 * @global obj $mdjm_event MDJM_Event class object * @param int $event_id * @return str */ function mdjm_do_event_txn_table($event_id) { global $mdjm_event; $event_txns = apply_filters('mdjm_event_txns', mdjm_get_event_txns($event_id, array('orderby' => 'post_status'))); $in = 0; $out = 0; ?> <table class="widefat mdjm_event_txn_list"> <thead> <tr> <th style="width: 20%"><?php _e('Date', 'mobile-dj-manager'); ?> </th> <th style="width: 20%"><?php _e('To/From', 'mobile-dj-manager'); ?> </th> <th style="width: 15%"><?php _e('In', 'mobile-dj-manager'); ?> </th> <th style="width: 15%"><?php _e('Out', 'mobile-dj-manager'); ?> </th> <th><?php _e('Details', 'mobile-dj-manager'); ?> </th> <?php do_action('mdjm_event_txn_table_head', $event_id); ?> </tr> </thead> <tbody> <?php if ($event_txns) { ?> <?php foreach ($event_txns as $event_txn) { ?> <?php $txn = new MDJM_Txn($event_txn->ID); ?> <tr class="mdjm_field_wrapper"> <td><a href="<?php echo get_edit_post_link($txn->ID); ?> "><?php echo mdjm_format_short_date($txn->post_date); ?> </a></td> <td><?php echo esc_attr(mdjm_get_txn_recipient_name($txn->ID)); ?> </td> <td> <?php if ($txn->post_status == 'mdjm-income') { ?> <?php $in += mdjm_sanitize_amount($txn->price); ?> <?php echo mdjm_currency_filter(mdjm_format_amount($txn->price)); ?> <?php } else { ?> <?php echo '–'; ?> <?php } ?> </td> <td> <?php if ($txn->post_status == 'mdjm-expenditure') { ?> <?php $out += mdjm_sanitize_amount($txn->price); ?> <?php echo mdjm_currency_filter(mdjm_format_amount($txn->price)); ?> <?php } else { ?> <?php echo '–'; ?> <?php } ?> </td> <td><?php echo $txn->get_type(); ?> </td> </tr> <?php } ?> <?php } else { ?> <tr> <td colspan="5"><?php printf(__('There are currently no transactions for this %s', 'mobile-dj-manager'), mdjm_get_label_singular(true)); ?> </td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th style="width: 20%"> </th> <th style="width: 20%"> </th> <th style="width: 15%"><strong><?php echo mdjm_currency_filter(mdjm_format_amount($in)); ?> </strong></th> <th style="width: 15%"><strong><?php echo mdjm_currency_filter(mdjm_format_amount($out)); ?> </strong></th> <th><strong><?php printf(__('%s Earnings:', 'mobile-dj-manager'), mdjm_get_label_singular()); ?> <?php echo mdjm_currency_filter(mdjm_format_amount($in - $out)); ?> </strong></th> </tr> <?php do_action('mdjm_event_txn_table_foot', $event_id); ?> </tfoot> </table> <?php }
/** * Save the meta data for the event * * @since 0.7 * @param int $post_id The current event post ID. * @param obj $post The current event post object (WP_Post). * @param bool $update Whether this is an existing post being updated or not. * * @return void */ function mdjm_save_event_post($post_id, $post, $update) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if ($post->post_status == 'trash') { return; } if (empty($update)) { return; } // Permission Check if (!mdjm_employee_can('manage_events')) { MDJM()->debug->log_it(sprintf('PERMISSION ERROR: User %s is not allowed to edit events', get_current_user_id())); return; } // Remove the save post action to avoid loops. remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3); // Fire our pre-save hook do_action('mdjm_pre_event_save', $post_id, $post, $update); $debug[] = 'Starting Event Save'; // Get current meta data for the post so we can track changes within the journal. $current_meta = get_post_meta($post_id); /** * Get the Client ID and store it in the event data array. * If a client has been selected from the dropdown, we simply use that ID. * If adding a new client, call the method and use the returned user ID. */ $event_data['_mdjm_event_client'] = $_POST['client_name'] != 'add_new' ? $_POST['client_name'] : mdjm_add_client(); /** * For new events we fire the 'mdjm_add_new_event' action */ if (empty($update)) { do_action('mdjm_create_new_event', $post); } /** * If the client is flagged to have their password reset, set the flag. * The flag will be checked and processed during the content tag filtering process. */ if (!empty($_POST['mdjm_reset_pw'])) { $debug[] = sprintf('Client %s flagged for password reset', $event_data['_mdjm_event_client']); update_user_meta($event_data['_mdjm_event_client'], 'mdjm_pass_action', true); } /** * Determine the Venue ID if an existing venue was selected. * Otherwise, determine if we're using the client's address or adding a manual venue address */ if ($_POST['venue_id'] != 'manual' && $_POST['venue_id'] != 'client') { $event_data['_mdjm_event_venue_id'] = $_POST['venue_id']; } elseif (!empty($_POST['_mdjm_event_venue_id']) && $_POST['_mdjm_event_venue_id'] == 'client') { $event_data['_mdjm_event_venue_id'] = 'client'; } else { $event_data['_mdjm_event_venue_id'] = 'manual'; } /** * If the option was selected to save the venue, prepare the post and post meta data * for the venue. */ if ($_POST['venue_id'] == 'manual' && !empty($_POST['save_venue'])) { foreach ($_POST as $venue_key => $venue_value) { if (substr($venue_key, 0, 6) == 'venue_') { $venue_meta[$venue_key] = $venue_value; if ($venue_key == 'venue_postcode' && !empty($venue_value)) { $venue_meta[$venue_key] = strtoupper($venue_value); } elseif ($venue_key == 'venue_email' && !empty($venue_value)) { $venue_meta[$venue_key] = sanitize_email($venue_value); } else { $venue_meta[$venue_key] = sanitize_text_field(ucwords($venue_value)); } } } // Create the new venue $event_data['_mdjm_event_venue_id'] = mdjm_add_venue($_POST['venue_name'], $venue_meta); } else { // Manual venue address entry if ($_POST['venue_id'] != 'client') { $event_data['_mdjm_event_venue_name'] = sanitize_text_field(ucwords($_POST['venue_name'])); $event_data['_mdjm_event_venue_contact'] = sanitize_text_field(ucwords($_POST['venue_contact'])); $event_data['_mdjm_event_venue_phone'] = sanitize_text_field($_POST['venue_phone']); $event_data['_mdjm_event_venue_email'] = sanitize_email(strtolower($_POST['venue_email'])); $event_data['_mdjm_event_venue_address1'] = sanitize_text_field(ucwords($_POST['venue_address1'])); $event_data['_mdjm_event_venue_address2'] = sanitize_text_field(ucwords($_POST['venue_address2'])); $event_data['_mdjm_event_venue_town'] = sanitize_text_field(ucwords($_POST['venue_town'])); $event_data['_mdjm_event_venue_county'] = sanitize_text_field(ucwords($_POST['venue_county'])); $event_data['_mdjm_event_venue_postcode'] = strtoupper(sanitize_text_field($_POST['venue_postcode'])); } else { // Using clients address $client_data = get_userdata($event_data['_mdjm_event_client']); $event_data['_mdjm_event_venue_name'] = __('Client Address', 'mobile-dj-manager'); $event_data['_mdjm_event_venue_contact'] = sprintf('%s %s', !empty($client_data->first_name) ? sanitize_text_field($client_data->first_name) : '', !empty($client_data->last_name) ? sanitize_text_field($client_data->last_name) : ''); $event_data['_mdjm_event_venue_phone'] = !empty($client_data->phone1) ? $client_data->phone1 : ''; $event_data['_mdjm_event_venue_email'] = !empty($client_data->user_email) ? $client_data->user_email : ''; $event_data['_mdjm_event_venue_address1'] = !empty($client_data->address1) ? $client_data->address1 : ''; $event_data['_mdjm_event_venue_address2'] = !empty($client_data->address2) ? $client_data->address2 : ''; $event_data['_mdjm_event_venue_town'] = !empty($client_data->town) ? $client_data->town : ''; $event_data['_mdjm_event_venue_county'] = !empty($client_data->county) ? $client_data->county : ''; $event_data['_mdjm_event_venue_postcode'] = !empty($client_data->postcode) ? $client_data->postcode : ''; } } /** * Travel data */ $travel_fields = mdjm_get_event_travel_fields(); foreach ($travel_fields as $travel_field) { $field = 'travel_' . $travel_field; $travel_data[$travel_field] = !empty($_POST[$field]) ? $_POST[$field] : ''; if ('cost' == $travel_field && !empty($_POST[$field])) { $travel_data[$travel_field] = mdjm_sanitize_amount($_POST[$field]); } } $event_data['_mdjm_event_travel_data'] = $travel_data; /** * Prepare the remaining event meta data. */ $event_data['_mdjm_event_last_updated_by'] = get_current_user_id(); /** * Event name. * If no name is defined, use the event type. * Allow filtering of the event name with the `mdjm_event_name` filter. */ if (empty($_POST['_mdjm_event_name'])) { $_POST['_mdjm_event_name'] = get_term($_POST['mdjm_event_type'], 'event-types')->name; } $_POST['_mdjm_event_name'] = apply_filters('mdjm_event_name', $_POST['_mdjm_event_name'], $post_id); // Generate the playlist reference for guest access if (empty($update) || empty($current_meta['_mdjm_event_playlist_access'][0])) { $event_data['_mdjm_event_playlist_access'] = mdjm_generate_playlist_guest_code(); } // Set whether or not the playlist is enabled for the event $event_data['_mdjm_event_playlist'] = !empty($_POST['enable_playlist']) ? $_POST['enable_playlist'] : 'N'; /** * All the remaining custom meta fields are prefixed with '_mdjm_event_'. * Loop through all $_POST data and put all event meta fields into the $event_data array */ foreach ($_POST as $key => $value) { if (substr($key, 0, 12) == '_mdjm_event_') { if ($key == '_mdjm_event_dj_wage' || $key == '_mdjm_event_cost' || $key == '_mdjm_event_deposit') { $value = mdjm_sanitize_amount($value); } $event_data[$key] = $value; } } /** * We store all times in H:i:s but the user may prefer a different format so we * determine their time format setting and adjust to H:i:s for saving. */ if (mdjm_get_option('time_format', 'H:i') == 'H:i') { // 24 Hr $event_data['_mdjm_event_start'] = date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'])); $event_data['_mdjm_event_finish'] = date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'])); $event_data['_mdjm_event_djsetup_time'] = date('H:i:s', strtotime($_POST['dj_setup_hr'] . ':' . $_POST['dj_setup_min'])); } else { // 12 hr $event_data['_mdjm_event_start'] = date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'] . $_POST['event_start_period'])); $event_data['_mdjm_event_finish'] = date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'] . $_POST['event_finish_period'])); $event_data['_mdjm_event_djsetup_time'] = date('H:i:s', strtotime($_POST['dj_setup_hr'] . ':' . $_POST['dj_setup_min'] . $_POST['dj_setup_period'])); } if (empty($_POST['_mdjm_event_djsetup'])) { $event_data['_mdjm_event_djsetup'] = $_POST['_mdjm_event_date']; } /** * Set the event end date. * If the finish time is less than the start time, assume following day. */ if (date('H', strtotime($event_data['_mdjm_event_finish'])) > date('H', strtotime($event_data['_mdjm_event_start']))) { $event_data['_mdjm_event_end_date'] = $_POST['_mdjm_event_date']; } else { // End date is following day $event_data['_mdjm_event_end_date'] = date('Y-m-d', strtotime('+1 day', strtotime($_POST['_mdjm_event_date']))); } /** * Determine the state of the Deposit & Balance payments. * */ $event_data['_mdjm_event_deposit_status'] = !empty($_POST['deposit_paid']) ? $_POST['deposit_paid'] : 'Due'; $event_data['_mdjm_event_balance_status'] = !empty($_POST['balance_paid']) ? $_POST['balance_paid'] : 'Due'; $deposit_payment = $event_data['_mdjm_event_deposit_status'] == 'Paid' && $current_meta['_mdjm_event_deposit_status'][0] != 'Paid' ? true : false; $balance_payment = $event_data['_mdjm_event_balance_status'] == 'Paid' && $current_meta['_mdjm_event_balance_status'][0] != 'Paid' ? true : false; // Add-Ons if (mdjm_packages_enabled()) { $event_data['_mdjm_event_addons'] = !empty($_POST['event_addons']) ? $_POST['event_addons'] : ''; } // Assign the event type $existing_event_type = wp_get_object_terms($post_id, 'event-types'); mdjm_set_event_type($post_id, (int) $_POST['mdjm_event_type']); // Assign the enquiry source mdjm_set_enquiry_source($post_id, (int) $_POST['mdjm_enquiry_source']); /** * Update the event post meta data */ $debug[] = 'Beginning Meta Updates'; mdjm_update_event_meta($post_id, $event_data); $debug[] = 'Meta Updates Completed'; if ($deposit_payment == true || $balance_payment == true) { if ($balance_payment == true) { unset($event_data['_mdjm_event_balance_status']); unset($event_data['_mdjm_event_deposit_status']); mdjm_mark_event_balance_paid($post_id); } else { unset($event_data['_mdjm_event_deposit_status']); mdjm_mark_event_deposit_paid($post_id); } } // Set the event status & initiate tasks based on the status if ($_POST['original_post_status'] != $_POST['mdjm_event_status']) { mdjm_update_event_status($post_id, $_POST['mdjm_event_status'], $_POST['original_post_status'], array('client_notices' => empty($_POST['mdjm_block_emails']) ? true : false, 'email_template' => !empty($_POST['mdjm_email_template']) ? $_POST['mdjm_email_template'] : false, 'quote_template' => !empty($_POST['mdjm_online_quote']) ? $_POST['mdjm_online_quote'] : false)); } else { // Event status is un-changed so just log the changes to the journal mdjm_add_journal(array('user_id' => get_current_user_id(), 'event_id' => $post_id, 'comment_content' => sprintf('%s %s via Admin', mdjm_get_label_singular(), empty($update) ? 'created' : 'updated')), array('type' => 'update-event', 'visibility' => '2')); } // Fire the save event hook do_action('mdjm_save_event', $post, $_POST['mdjm_event_status']); // Fire our post save hook do_action('mdjm_after_event_save', $post_id, $post, $update); // Re-add the save post action to avoid loops add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3); $debug[] = sprintf('Completed Event Save for event %s', $post_id); if (!empty($debug) && MDJM_DEBUG == true) { $true = true; foreach ($debug as $log) { MDJM()->debug->log_it($log, $true); $true = false; } } }
public function period_earnings($period = '', $user_id = '', $earned = '') { global $mdjm; if (empty($period)) { if (MDJM_DEBUG == true) { MDJM()->debug->log_it('ERROR: No period was provided in ' . __METHOD__, true); } } elseif ($period == 'week') { $start_date = date('Y-m-d', strtotime("-7 day")); $end_date = date('Y-m-d'); } elseif ($period == 'month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); } else { $start_date = date('Y-01-01'); $end_date = date('Y-12-31'); } $user_id = !empty($user_id) ? $user_id : ''; $args = array('post_type' => 'mdjm-event', 'posts_per_page' => -1, 'meta_key' => '_mdjm_event_date', 'orderby' => 'meta_value', 'order' => 'DESC'); $args['post_status'] = empty($earned) ? array('mdjm-enquiry', 'mdjm-unattended', 'mdjm-contract', 'mdjm-approved', 'mdjm-completed') : 'mdjm-completed'; if (!empty($user_id)) { $args['meta_query'] = array('relation' => 'AND', array('key' => '_mdjm_event_date', 'value' => array($start_date, $end_date), 'type' => 'date', 'compare' => 'BETWEEN'), array('key' => '_mdjm_event_dj', 'value' => $user_id, 'compare' => '=')); } else { $args['meta_query'] = array('key' => '_mdjm_event_date', 'value' => array($start_date, $end_date), 'type' => 'date', 'compare' => 'BETWEEN'); } $earnings = '0.00'; $events = get_posts($args); foreach ($events as $event) { $event_cost = get_post_meta($event->ID, '_mdjm_event_cost', true); $earnings += $event_cost; if (!empty($earnings)) { $transactions = MDJM()->txns->get_event_transactions($event->ID); foreach ($transactions as $transaction) { $status = get_post_meta($transaction->ID, '_mdjm_txn_status', true); if (empty($status) || $status == 'Completed') { $txn_total = get_post_meta($transaction->ID, '_mdjm_txn_total', true); } if (!empty($txn_total)) { if ($transaction->post_status == 'mdjm-income') { $earnings += $txn_total; } else { $earnings -= $txn_total; } } } // foreach( $transactions as $transaction ) } // if( !empty( $earnings ) ) } // End foreach( $events as $event ) return mdjm_currency_filter(mdjm_sanitize_amount($earnings)); }