updated plugin Easy Digital Downloads
version 3.1.1.2
This commit is contained in:
@ -28,6 +28,15 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
*/
|
||||
public $export_type = 'earnings_report';
|
||||
|
||||
/**
|
||||
* Refund amounts for partially refunded orders.
|
||||
* Stored separately from the main data as it's only required for the net columns.
|
||||
*
|
||||
* @since 3.1.0.5
|
||||
* @var array
|
||||
*/
|
||||
private $partial_refunds;
|
||||
|
||||
/**
|
||||
* Set the export headers.
|
||||
*
|
||||
@ -103,7 +112,7 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
unset( $statuses['pending'], $statuses['processing'], $statuses['preapproval'] );
|
||||
$supported_statuses = array_keys( $statuses );
|
||||
|
||||
return apply_filters( 'edd_export_earnings_supported_statuses', $supported_statuses );
|
||||
return array_unique( apply_filters( 'edd_export_earnings_supported_statuses', $supported_statuses ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,11 +197,9 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
}
|
||||
}
|
||||
|
||||
$supported_statuses = $this->get_supported_statuses();
|
||||
|
||||
$gross_count = 0;
|
||||
$gross_amount = 0;
|
||||
foreach ( $supported_statuses as $status ) {
|
||||
foreach ( edd_get_gross_order_statuses() as $status ) {
|
||||
$gross_count += absint( $data[ $status ]['count'] );
|
||||
$gross_amount += $data[ $status ]['amount'];
|
||||
}
|
||||
@ -212,7 +219,7 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
}
|
||||
|
||||
// Allows extensions with other 'completed' statuses to alter net earnings, like recurring.
|
||||
$completed_statuses = apply_filters( 'edd_export_earnings_completed_statuses', edd_get_complete_order_statuses() );
|
||||
$completed_statuses = array_unique( apply_filters( 'edd_export_earnings_completed_statuses', edd_get_net_order_statuses() ) );
|
||||
|
||||
$net_count = 0;
|
||||
$net_amount = 0;
|
||||
@ -223,6 +230,9 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
$net_count += absint( $data[ $status ]['count'] );
|
||||
$net_amount += floatval( $data[ $status ]['amount'] );
|
||||
}
|
||||
if ( ! empty( $this->partial_refunds ) ) {
|
||||
$net_amount += floatval( $this->partial_refunds['total'] );
|
||||
}
|
||||
$row_data .= $net_count . ',';
|
||||
$row_data .= '"' . edd_format_amount( $net_amount ) . '"';
|
||||
|
||||
@ -265,7 +275,8 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
$totals = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT SUM(total) AS total, COUNT(DISTINCT id) AS count, status
|
||||
FROM {$wpdb->edd_orders}
|
||||
WHERE date_created >= %s AND date_created <= %s
|
||||
WHERE type = 'sale'
|
||||
AND date_created >= %s AND date_created <= %s
|
||||
GROUP BY YEAR(date_created), MONTH(date_created), status
|
||||
ORDER by date_created ASC", $start_date, $end_date ), ARRAY_A );
|
||||
|
||||
@ -273,7 +284,7 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
foreach ( $totals as $row ) {
|
||||
$total_data[ $row['status'] ] = array(
|
||||
'count' => $row['count'],
|
||||
'amount' => floatval( $row['total'] )
|
||||
'amount' => floatval( $row['total'] ),
|
||||
);
|
||||
}
|
||||
|
||||
@ -290,7 +301,30 @@ class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
'amount' => $total_data[ $status ]['amount'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Get partial refund amounts to factor into net activity amounts.
|
||||
$partial_refunds = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT SUM(total) AS total, COUNT(DISTINCT id) AS count
|
||||
FROM {$wpdb->edd_orders}
|
||||
WHERE type = 'refund'
|
||||
AND parent IN (
|
||||
SELECT id
|
||||
FROM {$wpdb->edd_orders}
|
||||
WHERE status = 'partially_refunded'
|
||||
AND date_created >= %s
|
||||
AND date_created <= %s
|
||||
GROUP BY YEAR(date_created), MONTH(date_created)
|
||||
ORDER by date_created ASC
|
||||
);",
|
||||
$start_date,
|
||||
$end_date
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
if ( ! empty( $partial_refunds ) ) {
|
||||
$this->partial_refunds = reset( $partial_refunds );
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
|
@ -91,21 +91,21 @@ class EDD_Batch_Payments_Export extends EDD_Batch_Export {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'type' => 'sale',
|
||||
'status__not_in' => array( 'trash' ),
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'type' => 'sale',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'all' === $args['status'] ) {
|
||||
if ( in_array( $args['status'], array( 'any', 'all' ), true ) ) {
|
||||
unset( $args['status'] );
|
||||
$args['status__not_in'] = array( 'trash' );
|
||||
}
|
||||
|
||||
$orders = edd_get_orders( $args );
|
||||
@ -241,14 +241,15 @@ class EDD_Batch_Payments_Export extends EDD_Batch_Export {
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
'status' => $this->status,
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' !== $this->status ) {
|
||||
$args['status'] = $this->status;
|
||||
if ( in_array( $args['status'], array( 'any', 'all' ), true ) ) {
|
||||
unset( $args['status'] );
|
||||
}
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
|
@ -35,13 +35,12 @@ class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'ID' => __( 'Log ID', 'easy-digital-downloads' ),
|
||||
return array(
|
||||
'ID' => __( 'Product ID', 'easy-digital-downloads' ),
|
||||
'user_id' => __( 'User', 'easy-digital-downloads' ),
|
||||
'customer_id' => __( 'Customer ID', 'easy-digital-downloads' ),
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'first_name' => __( 'First Name', 'easy-digital-downloads' ),
|
||||
'last_name' => __( 'Last Name', 'easy-digital-downloads' ),
|
||||
'name' => __( 'Name', 'easy-digital-downloads' ),
|
||||
'download' => edd_get_label_singular(),
|
||||
'quantity' => __( 'Quantity', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Item Amount', 'easy-digital-downloads' ),
|
||||
@ -49,8 +48,6 @@ class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
'price_id' => __( 'Price ID', 'easy-digital-downloads' ),
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,29 +79,15 @@ class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
/** @var EDD\Orders\Order_Item $item */
|
||||
$order = edd_get_order( $item->order_id );
|
||||
$download = edd_get_download( $item->product_id );
|
||||
$user_info = $order->get_user_info();
|
||||
|
||||
$download_title = $item->product_name;
|
||||
|
||||
// Maybe append variable price name.
|
||||
if ( $download->has_variable_prices() ) {
|
||||
$price_option = edd_get_price_option_name( $item->product_id, $item->price_id, $order->id );
|
||||
|
||||
$download_title .= ! empty( $price_option )
|
||||
? ' - ' . $price_option
|
||||
: '';
|
||||
}
|
||||
$order = edd_get_order( $item->order_id );
|
||||
|
||||
$data[] = array(
|
||||
'ID' => $item->product_id,
|
||||
'user_id' => $order->user_id,
|
||||
'customer_id' => $order->customer_id,
|
||||
'email' => $order->email,
|
||||
'first_name' => isset( $user_info['first_name'] ) ? $user_info['first_name'] : '',
|
||||
'last_name' => isset( $user_info['last_name'] ) ? $user_info['last_name'] : '',
|
||||
'download' => $download_title,
|
||||
'name' => edd_get_customer_field( $order->customer_id, 'name' ),
|
||||
'download' => $item->product_name,
|
||||
'quantity' => $item->quantity,
|
||||
'amount' => $order->total,
|
||||
'payment_id' => $order->id,
|
||||
@ -129,9 +112,7 @@ class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
$args = array();
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
@ -141,7 +122,7 @@ class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
$args['product_id'] = $this->download_id;
|
||||
}
|
||||
|
||||
$total = edd_count_order_items( $args );
|
||||
$total = edd_count_order_items( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
|
@ -90,20 +90,20 @@ class EDD_Batch_Taxed_Orders_Export extends EDD_Batch_Export {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'status__not_in' => array( 'trash' ),
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' === $args['status'] || 'all' === $args['status'] ) {
|
||||
if ( in_array( $args['status'], array( 'any', 'all' ), true ) ) {
|
||||
unset( $args['status'] );
|
||||
$args['status__not_in'] = array( 'trash' );
|
||||
}
|
||||
|
||||
add_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10, 2 );
|
||||
@ -236,14 +236,15 @@ class EDD_Batch_Taxed_Orders_Export extends EDD_Batch_Export {
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
'status' => $this->status,
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' !== $this->status ) {
|
||||
$args['status'] = $this->status;
|
||||
if ( in_array( $args['status'], array( 'any', 'all' ), true ) ) {
|
||||
unset( $args['status'] );
|
||||
}
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
|
Reference in New Issue
Block a user