2013-07-10 11:05:45 +00:00
< ? php
2016-01-05 11:47:44 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-07-10 11:05:45 +00:00
/**
2015-11-03 13:53:50 +00:00
* WC_Report_Taxes_By_Code
2014-02-14 13:02:37 +00:00
*
2014-08-31 07:19:13 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin / Reports
2014-02-14 13:02:37 +00:00
* @ version 2.1 . 0
2013-07-10 11:05:45 +00:00
*/
class WC_Report_Taxes_By_Code extends WC_Admin_Report {
/**
2015-11-03 13:31:20 +00:00
* Get the legend for the main chart sidebar .
2013-07-10 11:05:45 +00:00
* @ return array
*/
public function get_chart_legend () {
return array ();
}
2013-07-18 11:56:12 +00:00
/**
2015-11-03 13:31:20 +00:00
* Output an export link .
2013-07-18 11:56:12 +00:00
*/
public function get_export_button () {
2014-08-31 07:19:13 +00:00
2014-09-16 09:33:47 +00:00
$current_range = ! empty ( $_GET [ 'range' ] ) ? sanitize_text_field ( $_GET [ 'range' ] ) : 'last_month' ;
2013-07-18 11:56:12 +00:00
?>
< a
href = " # "
2016-09-02 01:51:31 +00:00
download = " report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); ?>.csv "
2013-07-18 11:56:12 +00:00
class = " export_csv "
data - export = " table "
>
< ? php _e ( 'Export CSV' , 'woocommerce' ); ?>
</ a >
< ? php
}
2013-07-10 11:05:45 +00:00
/**
2015-11-03 13:31:20 +00:00
* Output the report .
2013-07-10 11:05:45 +00:00
*/
public function output_report () {
2014-08-31 07:19:13 +00:00
2013-07-10 11:05:45 +00:00
$ranges = array (
'year' => __ ( 'Year' , 'woocommerce' ),
2016-10-12 10:16:30 +00:00
'last_month' => __ ( 'Last month' , 'woocommerce' ),
'month' => __ ( 'This month' , 'woocommerce' ),
2013-07-10 11:05:45 +00:00
);
2014-09-16 09:33:47 +00:00
$current_range = ! empty ( $_GET [ 'range' ] ) ? sanitize_text_field ( $_GET [ 'range' ] ) : 'last_month' ;
2013-07-10 11:05:45 +00:00
2014-08-31 07:19:13 +00:00
if ( ! in_array ( $current_range , array ( 'custom' , 'year' , 'last_month' , 'month' , '7day' ) ) ) {
2013-07-30 10:12:42 +00:00
$current_range = 'last_month' ;
2014-08-31 07:19:13 +00:00
}
2013-07-10 11:05:45 +00:00
2017-04-18 23:33:25 +00:00
$this -> check_current_range_nonce ( $current_range );
2013-07-30 10:12:42 +00:00
$this -> calculate_current_range ( $current_range );
2013-07-10 11:05:45 +00:00
$hide_sidebar = true ;
2016-09-02 01:33:57 +00:00
include ( WC () -> plugin_path () . '/includes/admin/views/html-report-by-date.php' );
2013-07-10 11:05:45 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get the main chart .
2013-07-10 11:05:45 +00:00
*/
public function get_main_chart () {
global $wpdb ;
2015-02-13 13:39:34 +00:00
$query_data = array (
'order_item_name' => array (
'type' => 'order_item' ,
'function' => '' ,
2016-08-27 01:46:45 +00:00
'name' => 'tax_rate' ,
2013-07-10 11:05:45 +00:00
),
2015-02-13 13:39:34 +00:00
'tax_amount' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
'function' => '' ,
2016-08-27 01:46:45 +00:00
'name' => 'tax_amount' ,
2013-07-10 11:05:45 +00:00
),
2015-02-13 13:39:34 +00:00
'shipping_tax_amount' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
'function' => '' ,
2016-08-27 01:46:45 +00:00
'name' => 'shipping_tax_amount' ,
2015-02-13 13:39:34 +00:00
),
'rate_id' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
'function' => '' ,
2016-08-27 01:46:45 +00:00
'name' => 'rate_id' ,
2015-02-13 13:39:34 +00:00
),
'ID' => array (
'type' => 'post_data' ,
'function' => '' ,
2016-08-27 01:46:45 +00:00
'name' => 'post_id' ,
2015-02-13 13:39:34 +00:00
),
);
$query_where = array (
array (
'key' => 'order_item_type' ,
'value' => 'tax' ,
2016-08-27 01:46:45 +00:00
'operator' => '=' ,
2015-02-13 13:39:34 +00:00
),
array (
'key' => 'order_item_name' ,
'value' => '' ,
2016-08-27 01:46:45 +00:00
'operator' => '!=' ,
2016-08-27 02:08:49 +00:00
),
2015-02-13 13:39:34 +00:00
);
$tax_rows_orders = $this -> get_order_report_data ( array (
'data' => $query_data ,
'where' => $query_where ,
'order_by' => 'posts.post_date ASC' ,
'query_type' => 'get_results' ,
'filter_range' => true ,
'order_types' => array_merge ( wc_get_order_types ( 'sales-reports' ), array ( 'shop_order_refund' ) ),
'order_status' => array ( 'completed' , 'processing' , 'on-hold' ),
2016-08-27 01:46:45 +00:00
'parent_order_status' => array ( 'completed' , 'processing' , 'on-hold' ), // Partial refunds inside refunded orders should be ignored
2013-07-10 11:05:45 +00:00
) );
2015-02-13 13:39:34 +00:00
// Merge
$tax_rows = array ();
foreach ( $tax_rows_orders as $tax_row ) {
$key = $tax_row -> rate_id ;
$tax_rows [ $key ] = isset ( $tax_rows [ $key ] ) ? $tax_rows [ $key ] : ( object ) array ( 'tax_amount' => 0 , 'shipping_tax_amount' => 0 , 'total_orders' => 0 );
if ( 'shop_order_refund' !== get_post_type ( $tax_row -> post_id ) ) {
$tax_rows [ $key ] -> total_orders += 1 ;
}
$tax_rows [ $key ] -> tax_rate = $tax_row -> tax_rate ;
$tax_rows [ $key ] -> tax_amount += wc_round_tax_total ( $tax_row -> tax_amount );
$tax_rows [ $key ] -> shipping_tax_amount += wc_round_tax_total ( $tax_row -> shipping_tax_amount );
}
2013-07-10 11:05:45 +00:00
?>
< table class = " widefat " >
< thead >
< tr >
< th >< ? php _e ( 'Tax' , 'woocommerce' ); ?> </th>
< th >< ? php _e ( 'Rate' , 'woocommerce' ); ?> </th>
2016-10-12 10:16:30 +00:00
< th class = " total_row " >< ? php _e ( 'Number of orders' , 'woocommerce' ); ?> </th>
< th class = " total_row " >< ? php _e ( 'Tax amount' , 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the sum of the "Tax rows" tax amount within your orders.', 'woocommerce' ) ); ?></th>
< th class = " total_row " >< ? php _e ( 'Shipping tax amount' , 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the sum of the "Tax rows" shipping tax amount within your orders.', 'woocommerce' ) ); ?></th>
< th class = " total_row " >< ? php _e ( 'Total tax' , 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the total tax for the rate (shipping tax + product tax).', 'woocommerce' ) ); ?></th>
2013-07-10 11:05:45 +00:00
</ tr >
</ thead >
2016-06-06 16:24:31 +00:00
< ? php if ( ! empty ( $tax_rows ) ) : ?>
2013-07-10 11:05:45 +00:00
< tbody >
< ? php
2015-02-13 13:39:34 +00:00
foreach ( $tax_rows as $rate_id => $tax_row ) {
2013-10-24 18:22:22 +00:00
$rate = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT tax_rate FROM { $wpdb -> prefix } woocommerce_tax_rates WHERE tax_rate_id = %d; " , $rate_id ) );
2013-07-10 11:05:45 +00:00
?>
< tr >
2014-12-01 12:36:50 +00:00
< th scope = " row " >< ? php echo apply_filters ( 'woocommerce_reports_taxes_tax_rate' , $tax_row -> tax_rate , $rate_id , $tax_row ); ?> </th>
< td >< ? php echo apply_filters ( 'woocommerce_reports_taxes_rate' , $rate , $rate_id , $tax_row ); ?> %</td>
2013-07-10 11:05:45 +00:00
< td class = " total_row " >< ? php echo $tax_row -> total_orders ; ?> </td>
2013-11-25 13:34:21 +00:00
< td class = " total_row " >< ? php echo wc_price ( $tax_row -> tax_amount ); ?> </td>
< td class = " total_row " >< ? php echo wc_price ( $tax_row -> shipping_tax_amount ); ?> </td>
< td class = " total_row " >< ? php echo wc_price ( $tax_row -> tax_amount + $tax_row -> shipping_tax_amount ); ?> </td>
2013-07-10 11:05:45 +00:00
</ tr >
< ? php
}
?>
</ tbody >
2014-07-11 01:50:51 +00:00
< tfoot >
< tr >
< th scope = " row " colspan = " 3 " >< ? php _e ( 'Total' , 'woocommerce' ); ?> </th>
< th class = " total_row " >< ? php echo wc_price ( wc_round_tax_total ( array_sum ( wp_list_pluck ( ( array ) $tax_rows , 'tax_amount' ) ) ) ); ?> </th>
< th class = " total_row " >< ? php echo wc_price ( wc_round_tax_total ( array_sum ( wp_list_pluck ( ( array ) $tax_rows , 'shipping_tax_amount' ) ) ) ); ?> </th>
< th class = " total_row " >< strong >< ? php echo wc_price ( wc_round_tax_total ( array_sum ( wp_list_pluck ( ( array ) $tax_rows , 'tax_amount' ) ) + array_sum ( wp_list_pluck ( ( array ) $tax_rows , 'shipping_tax_amount' ) ) ) ); ?> </strong></th>
</ tr >
</ tfoot >
2013-07-10 11:05:45 +00:00
< ? php else : ?>
< tbody >
< tr >
< td >< ? php _e ( 'No taxes found in this period' , 'woocommerce' ); ?> </td>
</ tr >
</ tbody >
< ? php endif ; ?>
</ table >
< ? php
}
2014-08-31 07:19:13 +00:00
}