Changeset 7434 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-ticket-revenue.php
- Timestamp:
- 07/12/2018 12:22:11 AM (8 years ago)
- 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 49 49 <li>Query each WordCamp site with matched events and retrieve ticket data related to each event.</li> 50 50 <li>Append the ticket data to the event data.</li> 51 <li>Group the events b ased 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> 52 52 </ol> 53 53 "; … … 319 319 320 320 foreach ( $ticket_ids as $ticket_id ) { 321 $method = get_post_meta( $ticket_id, 'tix_payment_method', true ) ?: 'none'; 322 321 323 $ticket_details[ $blog_id . '_' . $ticket_id ] = array( 322 'method' => get_post_meta( $ticket_id, 'tix_payment_method', true ),324 'method' => $method, 323 325 'currency' => $currency, 324 326 'full_price' => floatval( get_post_meta( $ticket_id, 'tix_ticket_price', true ) ), … … 354 356 355 357 $data_groups = array( 356 ' wpcs' => array_merge( $initial_data, array(357 'label' => ' WPCSticket 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.', 359 361 ) ), 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' => '', 363 365 ) ), 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( 365 379 'label' => 'Ticket transactions with no payment', 366 380 'description' => 'Transactions for which no payment method was recorded.', 367 381 ) ), 368 'total' => array_merge( $initial_data, array(369 'label' => 'Total ticket revenue',370 'description' => '',371 ) ),372 382 ); 373 383 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' );376 384 $currencies = array(); 377 385 378 386 foreach ( $events as $event ) { 379 387 $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 ) ); 387 399 } 388 400 389 401 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 ) { 402 414 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']; 411 423 break; 412 424 413 425 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']; 417 429 $data_groups['total']['tickets_refunded'] ++; 418 430 $data_groups['total']['amount_refunded_by_currency'][ $currency ] += $event['discounted_price']; … … 461 473 */ 462 474 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; 467 480 $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() ); 471 482 $total = $data['total']; 472 483
Note: See TracChangeset
for help on using the changeset viewer.