function generate_financials_csv($export_event_id)
{
    $orders = TribeEventsTickets::get_event_attendees($export_event_id);
    $counter = 1;
    $export_financials = array();
    $temp_order_id = 0;
    $temp_product_id = 0;
    $temp_counter = 1;
    foreach ($orders as $order) {
        $number = $counter;
        $order_id = $order['order_id'];
        $order_meta = get_post_meta($order_id);
        $temp_product_id = $order['product_id'];
        $ticket = $order['ticket'];
        $purchase_date = get_the_date('F j, Y g:i a', $order_id);
        // $order_meta['_paid_date'][0];
        $purchaser_name = $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0];
        $user_id = $order_meta['_customer_user'][0];
        $purchaser_email = $order_meta['_billing_email'][0];
        $purchaser_phone = $order_meta['_billing_phone'][0];
        $company = $order_meta['_billing_company'][0];
        $address1 = $order_meta['_billing_address_1'][0];
        $address2 = $order_meta['_billing_address_2'][0];
        $address = $address1 . ', ' . $address2;
        $city = $order_meta['_billing_city'][0];
        $state = $order_meta['_billing_state'][0];
        $zip = $order_meta['_billing_postcode'][0];
        $discount = round($order_meta['_cart_discount'][0], 2);
        $total = $order_meta['_order_total'][0];
        $payment_method = $order_meta['_payment_method_title'][0];
        if ($temp_order_id == $order_id && $temp_product_id == $order['product_id']) {
            $temp_counter++;
        } else {
            $temp_counter = 1;
        }
        $attendee_first_name = $order_meta["attendee_first_name_" . $temp_product_id . "_" . $temp_counter][0];
        if (empty($attendee_first_name)) {
            $attendee_first_name = $order_meta["attendee_name_" . $temp_product_id . "_" . $temp_counter][0];
        }
        $attendee_last_name = $order_meta["attendee_last_name_" . $temp_product_id . "_" . $temp_counter][0];
        $attendee_job = $order_meta["attendee_job_title_" . $temp_product_id . "_" . $temp_counter][0];
        $attendee_phone = $order_meta["attendee_primary_phone_" . $temp_product_id . "_" . $temp_counter][0];
        $order_cst = new WC_Order($order_id);
        $order_items = $order_cst->get_items();
        foreach ($order_items as $item_id => $values) {
            $attendee_count = $values['qty'];
            break;
        }
        $coupons = $order_cst->get_used_coupons();
        $coupon = $coupons[0];
        if (!$coupon) {
            $coupon = "";
        }
        if ($discount == 0) {
            $discount = "";
        } else {
            $discount = "\$" . $discount;
        }
        $export_financials[$counter] = array($order_id, $purchase_date, $ticket, $user_id, $purchaser_name, $purchaser_email, $purchaser_phone, $company, $address, $city, $state, $zip, $attendee_first_name, $attendee_last_name, $attendee_job, $attendee_cell_phone, $attendee_work_phone, $attendee_count, $total, $payment_method, $coupon, $discount);
        $counter++;
        $temp_order_id = $order_id;
        $temp_product_id = $order['product_id'];
    }
    $event = get_post($export_event_id);
    if (!empty($export_financials)) {
        $charset = get_option('blog_charset');
        $start_date = strtotime(get_post_meta($event, '_EventStartDate', true));
        $filename = $event->post_name;
        // output headers so that the file is downloaded rather than displayed
        header("Content-Type: text/csv; charset={$charset}");
        header("Content-Disposition: attachment; filename={$filename}-fiancial-data.csv");
        // create a file pointer connected to the output stream
        $output = fopen('php://output', 'w');
        fputcsv($output, array('Order ID', 'Purchase Date', 'Ticket Name', 'User ID', 'Purchaser Name', 'Purchaser Email', 'Purchaser Phone', 'Purchaser Company', 'Address', 'City', 'State', 'Zip', 'Attendee First Name', 'Attendee Last Name', 'Job Title', 'Cell Phone', 'Work Phone', 'Number of Tickets Purchased', 'Total Paid', 'Payment Method', 'Coupon Code', 'Discount Amount'));
        // And echo the data
        foreach ($export_financials as $item) {
            fputcsv($output, $item);
        }
        fclose($output);
        exit;
    }
}
function calculate_attendee_financial_Data()
{
    global $value_to_display;
    // Load the ajax js in header after jquery
    wp_enqueue_script('btcg-attendees-finance-data', plugin_dir_url(__FILE__) . 'js/btcg-event-attendees-finance-data.js', array('jquery'), false, false);
    // Get Event ID and load the event tickets
    $current_event_id = isset($_GET['event_id']) ? intval($_GET['event_id']) : 0;
    //$current_event = get_post( $current_event_id );
    $current_event_tickets = TribeEventsTickets::get_event_tickets($current_event_id);
    // Getting Ticket Ids
    $ticket_ids = array();
    foreach ($current_event_tickets as $current_event_ticket) {
        $ticket_ids[] = $current_event_ticket->ID;
    }
    // Fetching all orders and searching the ticket id in the orders
    $attendees_list = TribeEventsTickets::get_event_attendees($current_event_id);
    $amount_sold_online = 0;
    $amount_sold_offline = 0;
    foreach ($attendees_list as $attendee) {
        $current_order_id = $attendee['order_id'];
        $order_details = new WC_Order($current_order_id);
        // Getting order detail
        $current_order_items = $order_details->get_items();
        // Getting line items in the order
        $current_orderpayment_method = get_post_meta($current_order_id, '_payment_method', true);
        // Get payment method
        $offline_methods = array('bacs', 'cod', 'cheque');
        $online_methods = array('paypal', 'simplify_commerce', 'authorize_net_cim_credit_card', 'authorize_net_cim_echeck');
        foreach ($current_order_items as $current_order_item) {
            if (in_array($current_order_item['product_id'], $ticket_ids)) {
                if (in_array($current_orderpayment_method, $offline_methods)) {
                    $amount_sold_offline = $amount_sold_offline + $current_order_item['line_total'];
                }
                if (in_array($current_orderpayment_method, $online_methods)) {
                    $amount_sold_online = $amount_sold_online + $current_order_item['line_total'];
                }
            }
        }
    }
    $value_to_display = '<strong>Online Sales:</strong> ' . wc_price($amount_sold_online) . '<br/>';
    $value_to_display .= '<strong>Offline Sales:</strong> ' . wc_price($amount_sold_offline) . '<br/>';
    $value_to_display .= '<strong>Gross Sales:</strong> ' . wc_price($amount_sold_offline + $amount_sold_online);
    // Adding inline javascript
    add_action('admin_head', 'attendees_inline_js');
}
 /**
  * Prepares the list of items for displaying.
  */
 function prepare_items()
 {
     $this->process_bulk_action();
     $event_id = isset($_GET['event_id']) ? $_GET['event_id'] : 0;
     $items = TribeEventsTickets::get_event_attendees($event_id);
     $this->items = $items;
     $total_items = count($this->items);
     $per_page = $total_items;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => 1));
 }
Пример #4
0
 /**
  * Returns the sum of all checked-in attendees for an event. Queries all registered providers.
  *
  * @static
  *
  * @param $event_id
  *
  * @return mixed
  */
 public static final function get_event_checkedin_attendees_count($event_id)
 {
     $checkedin = TribeEventsTickets::get_event_attendees($event_id);
     return array_reduce($checkedin, array("TribeEventsTickets", "_checkedin_attendees_array_filter"), 0);
 }
Пример #5
0
 /**
  * Generates a list of attendees taking into account the Screen Options.
  * It's used both for the Email functionality, as for the CSV export.
  *
  * @param $event_id
  *
  * @return array
  */
 private function _generate_filtered_attendees_list($event_id)
 {
     if (empty($this->attendees_page)) {
         $this->attendees_page = 'tribe_events_page_tickets-attendees';
     }
     $columns = $this->attendees_table->get_columns();
     $hidden = get_hidden_columns($this->attendees_page);
     // We dont want to export html inputs or private data
     $hidden[] = 'cb';
     $hidden[] = 'provider';
     // remove the hidden fields from the final list of columns
     $hidden = array_filter($hidden);
     $hidden = array_flip($hidden);
     $export_columns = array_diff_key($columns, $hidden);
     $columns_names = array_filter(array_values($export_columns));
     $export_columns = array_filter(array_keys($export_columns));
     // Get the data
     $items = TribeEventsTickets::get_event_attendees($event_id);
     $rows = array($columns_names);
     //And echo the data
     foreach ($items as $item) {
         $row = array();
         foreach ($item as $key => $data) {
             if (in_array($key, $export_columns)) {
                 if ($key == 'check_in' && $data == 1) {
                     $data = __('Yes', 'tribe-events-calendar');
                 }
                 $row[$key] = $data;
             }
         }
         $rows[] = array_values($row);
     }
     return array_filter($rows);
 }
Пример #6
0
 function prepare_items()
 {
     global $wpdb;
     $this->process_bulk_action();
     $per_page = 10000;
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = array();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $current_page = $this->get_pagenum();
     $event_id = isset($_GET['event_id']) ? $_GET['event_id'] : 0;
     $items = TribeEventsTickets::get_event_attendees($event_id);
     $this->items = $items;
     $total_items = count($this->items);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
Пример #7
0
function generate_attendee_csv($export_event_id)
{
    $all_attendees = TribeEventsTickets::get_event_attendees($export_event_id);
    $export_attendee_list = array();
    $counter = 0;
    $attendee_counter = 1;
    $old_order_id = 0;
    foreach ($all_attendees as $attendee) {
        $order_id = $attendee['order_id'];
        $order = new WC_Order($order_id);
        $order_meta = get_post_meta($order_id);
        $_product_id = $attendee['product_id'];
        // Purchaser Name
        $purchaser_name = $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0];
        // Company
        $company = $order_meta['_billing_company'][0];
        // Address
        $address1 = $order_meta['_billing_address_1'][0];
        $address2 = $order_meta['_billing_address_2'][0];
        $address = $address1 . ' ' . $address2;
        // City, State & Zip
        $city = $order_meta['_billing_city'][0];
        $state = $order_meta['_billing_state'][0];
        $zip = $order_meta['_billing_postcode'][0];
        // Email
        $purchaser_email = $order_meta['_billing_email'][0];
        // Amount paid
        $amt_paid = $order->get_formatted_order_total();
        $amt_paid = html_entity_decode(strip_tags($amt_paid), ENT_QUOTES, 'utf-8');
        // Reset the counter after each order
        if ($old_order_id == 0) {
            $old_order_id = $order_id;
        } else {
            if ($order_id != $old_order_id) {
                $attendee_counter = 1;
                $old_order_id = $order_id;
            }
        }
        // Attendee Name, Attendee Email, Job Title, Dietary Restrictions & Phone
        //$attendee_name                 = get_post_meta( $order_id, 'attendee_name_'.$_product_id.'_'.$attendee_counter, true);
        $attendee_first_name = get_post_meta($order_id, 'attendee_first_name_' . $_product_id . '_' . $attendee_counter, true);
        if (empty($attendee_first_name)) {
            $attendee_first_name = get_post_meta($order_id, 'attendee_name_' . $_product_id . '_' . $attendee_counter, true);
        }
        $attendee_last_name = get_post_meta($order_id, 'attendee_last_name_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_email = get_post_meta($order_id, 'attendee_email_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_job_title = get_post_meta($order_id, 'attendee_job_title_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_dietary_restrictions = get_post_meta($order_id, 'attendee_dietary_restrictions_' . $_product_id . '_' . $attendee_counter, true);
        $phone = $order_meta['_billing_phone'][0];
        $discount = round($order_meta['_cart_discount'][0], 2);
        $coupons = $order->get_used_coupons();
        $coupon = $coupons[0];
        if (!$coupon) {
            $coupon = $discount = "";
        } else {
            $discount = "\$" . $discount;
        }
        $export_attendee_list[$counter] = array($purchaser_name, $phone, $company, $address, $city, $state, $zip, $purchaser_email, $amt_paid, $attendee_first_name, $attendee_last_name, $attendee_email, $attendee_company, $attendee_job_title, $attendee_dietary_restrictions, $attendee_cell_phone, $attendee_work_phone, $coupon, $discount);
        $counter++;
        $attendee_counter++;
    }
    $event = get_post($export_event_id);
    if (!empty($export_attendee_list)) {
        $charset = get_option('blog_charset');
        $start_date = strtotime(get_post_meta($event, '_EventStartDate', true));
        $filename = $event->post_name;
        // output headers so that the file is downloaded rather than displayed
        header("Content-Type: text/csv; charset={$charset}");
        header("Content-Disposition: attachment; filename={$filename}-attendees.csv");
        // create a file pointer connected to the output stream
        $output = fopen('php://output', 'w');
        fputcsv($output, array('Purchaser Name', 'Purchaser Phone', 'Purchaser Company', 'Address', 'City', 'State', 'Zip', 'Purchaser Email', 'Amount Paid', 'Attendee First Name', 'Attendee Last Name', 'Attendee Email', 'Attendee Company', 'Job Title', 'Dietary Restrictions', 'Cell Phone', 'Work Phone', 'Coupon Code', 'Coupon Amount'));
        foreach ($export_attendee_list as $item) {
            fputcsv($output, $item);
        }
        fclose($output);
        exit;
    }
}