__( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
);
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month';
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) {
$current_range = 'last_month';
}
$this->check_current_range_nonce( $current_range );
$this->calculate_current_range( $current_range );
$hide_sidebar = true;
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
* Get the main chart.
*/
public function get_main_chart() {
$query_data = array(
'_order_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'tax_amount',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'shipping_tax_amount',
),
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping',
),
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
'distinct' => true,
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
);
// We exlude on-hold orders are they are still pending payment.
$tax_rows_orders = $this->get_order_report_data(
array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'refunded' ),
)
);
$tax_rows_full_refunds = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'distinct' => true,
'function' => '',
'name' => 'ID',
),
'post_parent' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_parent',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'refunded' ),
)
);
$tax_rows_partial_refunds = $this->get_order_report_data(
array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'completed', 'processing' ), // Partial refunds inside refunded orders should be ignored.
)
);
$tax_rows = array();
foreach ( $tax_rows_orders + $tax_rows_partial_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_sales' => 0,
'total_shipping' => 0,
'total_orders' => 0,
);
}
foreach ( $tax_rows_orders as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ]->total_orders += $tax_row->total_orders;
$tax_rows[ $key ]->tax_amount += $tax_row->tax_amount;
$tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount;
$tax_rows[ $key ]->total_sales += $tax_row->total_sales;
$tax_rows[ $key ]->total_shipping += $tax_row->total_shipping;
}
foreach ( $tax_rows_partial_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ]->tax_amount += $tax_row->tax_amount;
$tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount;
$tax_rows[ $key ]->total_sales += $tax_row->total_sales;
$tax_rows[ $key ]->total_shipping += $tax_row->total_shipping;
}
foreach ( $tax_rows_full_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_sales' => 0,
'total_shipping' => 0,
'total_orders' => 0,
);
$parent_order = wc_get_order( $tax_row->post_parent );
if ( $parent_order ) {
$tax_rows[ $key ]->tax_amount += $parent_order->get_cart_tax() * -1;
$tax_rows[ $key ]->shipping_tax_amount += $parent_order->get_shipping_tax() * -1;
$tax_rows[ $key ]->total_sales += $parent_order->get_total() * -1;
$tax_rows[ $key ]->total_shipping += $parent_order->get_shipping_total() * -1;
}
}
?>
|
|
|
|
|
|
$tax_row ) {
$gross = $tax_row->total_sales - $tax_row->total_shipping;
$total_tax = $tax_row->tax_amount + $tax_row->shipping_tax_amount;
?>
chart_groupby ) ? date_i18n( 'F', strtotime( $date . '01' ) ) : date_i18n( get_option( 'date_format' ), strtotime( $date ) ); ?>
|
total_orders; ?> |
|
total_shipping ); ?> |
|
|
|
|
|
|
|
|
|