Making WordPress.org


Ignore:
Timestamp:
07/12/2018 12:22:11 AM (8 years ago)
Author:
coreymckrill
Message:

WordCamp Reports: Update Ticket Revenue report, other minor changes

  • Show ticket revenue results split out by payment method (instead of WPCS vs non-WPCS).
  • Minor HTML markup changes on several reports.
  • Minor code cleanup changes on several reports.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-ticket-revenue.php

    r7378 r7434  
    4949            <li>Query each WordCamp site with matched events and retrieve ticket data related to each event.</li>
    5050            <li>Append the ticket data to the event data.</li>
    51             <li>Group the events based on whether the transaction was handled by WPCS. Assume all transactions in a currency supported by PayPal were handled by WPCS.</li>
     51            <li>Group the events by payment method.</li>
    5252        </ol>
    5353    ";
     
    319319
    320320        foreach ( $ticket_ids as $ticket_id ) {
     321            $method = get_post_meta( $ticket_id, 'tix_payment_method', true ) ?: 'none';
     322
    321323            $ticket_details[ $blog_id . '_' . $ticket_id ] = array(
    322                 'method'           => get_post_meta( $ticket_id, 'tix_payment_method', true ),
     324                'method'           => $method,
    323325                'currency'         => $currency,
    324326                'full_price'       => floatval( get_post_meta( $ticket_id, 'tix_ticket_price', true ) ),
     
    354356
    355357        $data_groups = array(
    356             'wpcs'     => array_merge( $initial_data, array(
    357                 'label'       => 'WPCS ticket revenue',
    358                 'description' => 'Transactions using a payment method for which WPCS has an established account.',
     358            'total'     => array_merge( $initial_data, array(
     359                'label'       => 'Total ticket revenue',
     360                'description' => 'Not including transaction fees.',
    359361            ) ),
    360             'non_wpcs' => array_merge( $initial_data, array(
    361                 'label'       => 'Non-WPCS ticket revenue',
    362                 'description' => 'Transactions using a payment method for which WPCS does not have an established account.',
     362            'stripe'    => array_merge( $initial_data, array(
     363                'label'       => 'Ticket transactions through Stripe',
     364                'description' => '',
    363365            ) ),
    364             'none'     => array_merge( $initial_data, array(
     366            'paypal'    => array_merge( $initial_data, array(
     367                'label'       => 'Ticket transactions through PayPal',
     368                'description' => '',
     369            ) ),
     370            'instamojo' => array_merge( $initial_data, array(
     371                'label'       => 'Ticket transactions through Instamojo',
     372                'description' => '',
     373            ) ),
     374            'razorpay'  => array_merge( $initial_data, array(
     375                'label'       => 'Ticket transactions through Razorpay',
     376                'description' => '',
     377            ) ),
     378            'none'      => array_merge( $initial_data, array(
    365379                'label'       => 'Ticket transactions with no payment',
    366380                'description' => 'Transactions for which no payment method was recorded.',
    367381            ) ),
    368             'total'    => array_merge( $initial_data, array(
    369                 'label'       => 'Total ticket revenue',
    370                 'description' => '',
    371             ) ),
    372382        );
    373383
    374         // Assume that all transactions through a gateway for which WPCS has an account, used the WPCS account.
    375         $wpcs_payment_methods = array( 'paypal', 'stripe' );
    376384        $currencies           = array();
    377385
    378386        foreach ( $events as $event ) {
    379387            $currency = $event['currency'];
    380 
    381             if ( ! $event['method'] ) {
    382                 $group = 'none';
    383             } elseif ( in_array( $event['method'], $wpcs_payment_methods, true ) ) {
    384                 $group = 'wpcs';
    385             } else {
    386                 $group = 'non_wpcs';
     388            $method   = $event['method'];
     389            $type     = $event['type'];
     390
     391            if ( ! isset( $data_groups[ $method ] ) ) {
     392                $data_groups[ $method ] = array_merge( $initial_data, array(
     393                    'label'       => sprintf(
     394                        'Ticket transactions through %s',
     395                        esc_html( $method )
     396                    ),
     397                    'description' => '',
     398                ) );
    387399            }
    388400
    389401            if ( ! in_array( $currency, $currencies, true ) ) {
    390                 $data_groups[ $group ]['gross_revenue_by_currency'][ $currency ]   = 0;
    391                 $data_groups[ $group ]['discounts_by_currency'][ $currency ]       = 0;
    392                 $data_groups[ $group ]['amount_refunded_by_currency'][ $currency ] = 0;
    393                 $data_groups[ $group ]['net_revenue_by_currency'][ $currency ]     = 0;
    394                 $data_groups['total']['gross_revenue_by_currency'][ $currency ]    = 0;
    395                 $data_groups['total']['discounts_by_currency'][ $currency ]        = 0;
    396                 $data_groups['total']['amount_refunded_by_currency'][ $currency ]  = 0;
    397                 $data_groups['total']['net_revenue_by_currency'][ $currency ]      = 0;
    398                 $currencies[]                                                      = $currency;
    399             }
    400 
    401             switch ( $event['type'] ) {
     402                $data_groups[ $method ]['gross_revenue_by_currency'][ $currency ]   = 0;
     403                $data_groups[ $method ]['discounts_by_currency'][ $currency ]       = 0;
     404                $data_groups[ $method ]['amount_refunded_by_currency'][ $currency ] = 0;
     405                $data_groups[ $method ]['net_revenue_by_currency'][ $currency ]     = 0;
     406                $data_groups['total']['gross_revenue_by_currency'][ $currency ]     = 0;
     407                $data_groups['total']['discounts_by_currency'][ $currency ]         = 0;
     408                $data_groups['total']['amount_refunded_by_currency'][ $currency ]   = 0;
     409                $data_groups['total']['net_revenue_by_currency'][ $currency ]       = 0;
     410                $currencies[]                                                       = $currency;
     411            }
     412
     413            switch ( $type ) {
    402414                case 'Purchase' :
    403                     $data_groups[ $group ]['tickets_sold'] ++;
    404                     $data_groups[ $group ]['gross_revenue_by_currency'][ $currency ] += $event['full_price'];
    405                     $data_groups[ $group ]['discounts_by_currency'][ $currency ]     += $event['full_price'] - $event['discounted_price'];
    406                     $data_groups[ $group ]['net_revenue_by_currency'][ $currency ]   += $event['discounted_price'];
    407                     $data_groups['total']['tickets_sold']  ++;
    408                     $data_groups['total']['gross_revenue_by_currency'][ $currency ]  += $event['full_price'];
    409                     $data_groups['total']['discounts_by_currency'][ $currency ]      += $event['full_price'] - $event['discounted_price'];
    410                     $data_groups['total']['net_revenue_by_currency'][ $currency ]    += $event['discounted_price'];
     415                    $data_groups[ $method ]['tickets_sold'] ++;
     416                    $data_groups[ $method ]['gross_revenue_by_currency'][ $currency ] += $event['full_price'];
     417                    $data_groups[ $method ]['discounts_by_currency'][ $currency ]     += $event['full_price'] - $event['discounted_price'];
     418                    $data_groups[ $method ]['net_revenue_by_currency'][ $currency ]   += $event['discounted_price'];
     419                    $data_groups['total']['tickets_sold'] ++;
     420                    $data_groups['total']['gross_revenue_by_currency'][ $currency ] += $event['full_price'];
     421                    $data_groups['total']['discounts_by_currency'][ $currency ]     += $event['full_price'] - $event['discounted_price'];
     422                    $data_groups['total']['net_revenue_by_currency'][ $currency ]   += $event['discounted_price'];
    411423                    break;
    412424
    413425                case 'Refund' :
    414                     $data_groups[ $group ]['tickets_refunded'] ++;
    415                     $data_groups[ $group ]['amount_refunded_by_currency'][ $currency ] += $event['discounted_price'];
    416                     $data_groups[ $group ]['net_revenue_by_currency'][ $currency ]     -= $event['discounted_price'];
     426                    $data_groups[ $method ]['tickets_refunded'] ++;
     427                    $data_groups[ $method ]['amount_refunded_by_currency'][ $currency ] += $event['discounted_price'];
     428                    $data_groups[ $method ]['net_revenue_by_currency'][ $currency ]     -= $event['discounted_price'];
    417429                    $data_groups['total']['tickets_refunded']  ++;
    418430                    $data_groups['total']['amount_refunded_by_currency'][ $currency ]  += $event['discounted_price'];
     
    461473     */
    462474    public function render_html() {
    463         $data       = $this->compile_report_data( $this->get_data() );
    464         $start_date = $this->start_date;
    465         $end_date   = $this->end_date;
    466 
     475        $now = new \DateTime();
     476
     477        $start_date    = $this->start_date;
     478        $end_date      = $this->end_date;
     479        $xrt_date      = ( $end_date > $now ) ? $now : $end_date;
    467480        $wordcamp_name = ( $this->wordcamp_site_id ) ? get_wordcamp_name( $this->wordcamp_site_id ) : '';
    468         $wpcs          = $data['wpcs'];
    469         $non_wpcs      = $data['non_wpcs'];
    470         $none          = $data['none'];
     481        $data          = $this->compile_report_data( $this->get_data() );
    471482        $total         = $data['total'];
    472483
Note: See TracChangeset for help on using the changeset viewer.