2013-07-10 11:05:45 +00:00
< ? php
/**
2014-02-14 13:02:37 +00:00
* WC_Report_Taxes_By_Code
*
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin / Reports
* @ version 2.1 . 0
2013-07-10 11:05:45 +00:00
*/
class WC_Report_Taxes_By_Code extends WC_Admin_Report {
/**
* Get the legend for the main chart sidebar
* @ return array
*/
public function get_chart_legend () {
$legend = array ();
return array ();
}
2013-07-18 11:56:12 +00:00
/**
* Output an export link
*/
public function get_export_button () {
$current_range = ! empty ( $_GET [ 'range' ] ) ? $_GET [ 'range' ] : 'last_month' ;
?>
< a
href = " # "
download = " report-<?php echo $current_range ; ?>-<?php echo date_i18n( 'Y-m-d', current_time('timestamp') ); ?>.csv "
class = " export_csv "
data - export = " table "
>
< ? php _e ( 'Export CSV' , 'woocommerce' ); ?>
</ a >
< ? php
}
2013-07-10 11:05:45 +00:00
/**
* Output the report
*/
public function output_report () {
$ranges = array (
'year' => __ ( 'Year' , 'woocommerce' ),
'last_month' => __ ( 'Last Month' , 'woocommerce' ),
'month' => __ ( 'This Month' , 'woocommerce' ),
);
$current_range = ! empty ( $_GET [ 'range' ] ) ? $_GET [ 'range' ] : 'last_month' ;
2013-07-30 10:12:42 +00:00
if ( ! in_array ( $current_range , array ( 'custom' , 'year' , 'last_month' , 'month' , '7day' ) ) )
$current_range = 'last_month' ;
2013-07-10 11:05:45 +00:00
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 ;
2013-07-24 16:01:36 +00:00
include ( WC () -> plugin_path () . '/includes/admin/views/html-report-by-date.php' );
2013-07-10 11:05:45 +00:00
}
/**
* Get the main chart
* @ return string
*/
public function get_main_chart () {
global $wpdb ;
$tax_rows = $this -> get_order_report_data ( array (
'data' => array (
'order_item_name' => array (
'type' => 'order_item' ,
'function' => '' ,
'name' => 'tax_rate'
),
'tax_amount' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
2013-10-24 18:22:22 +00:00
'function' => '' ,
2013-07-10 11:05:45 +00:00
'name' => 'tax_amount'
),
'shipping_tax_amount' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
2013-10-24 18:22:22 +00:00
'function' => '' ,
2013-07-10 11:05:45 +00:00
'name' => 'shipping_tax_amount'
),
'rate_id' => array (
'type' => 'order_item_meta' ,
'order_item_type' => 'tax' ,
'function' => '' ,
'name' => 'rate_id'
2013-10-24 18:22:22 +00:00
)
2013-07-10 11:05:45 +00:00
),
'where' => array (
array (
'key' => 'order_item_type' ,
'value' => 'tax' ,
'operator' => '='
),
array (
'key' => 'order_item_name' ,
'value' => '' ,
'operator' => '!='
)
),
'order_by' => 'post_date ASC' ,
'query_type' => 'get_results' ,
'filter_range' => true
) );
?>
< table class = " widefat " >
< thead >
< tr >
< th >< ? php _e ( 'Tax' , 'woocommerce' ); ?> </th>
< th >< ? php _e ( 'Rate' , 'woocommerce' ); ?> </th>
< th class = " total_row " >< ? php _e ( 'Number of orders' , 'woocommerce' ); ?> </th>
< th class = " total_row " >< ? php _e ( 'Tax Amount' , 'woocommerce' ); ?> <a class="tips" data-tip="<?php esc_attr_e( 'This is the sum of the "Tax Rows" tax amount within your orders.', 'woocommerce' ); ?>" href="#">[?]</a></th>
< th class = " total_row " >< ? php _e ( 'Shipping Tax Amount' , 'woocommerce' ); ?> <a class="tips" data-tip="<?php esc_attr_e( 'This is the sum of the "Tax Rows" shipping tax amount within your orders.', 'woocommerce' ); ?>" href="#">[?]</a></th>
< th class = " total_row " >< ? php _e ( 'Total Tax' , 'woocommerce' ); ?> <a class="tips" data-tip="<?php esc_attr_e( 'This is the total tax for the rate (shipping tax + product tax).', 'woocommerce' ); ?>" href="#">[?]</a></th>
</ tr >
</ thead >
< ? php if ( $tax_rows ) : ?>
< tfoot >
< tr >
< th scope = " row " colspan = " 3 " >< ? php _e ( 'Total' , 'woocommerce' ); ?> </th>
2013-11-25 13:34:21 +00:00
< 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>
2013-07-10 11:05:45 +00:00
</ tr >
</ tfoot >
< tbody >
< ? php
2013-10-24 18:22:22 +00:00
$grouped_tax_tows = array ();
2013-07-10 11:05:45 +00:00
foreach ( $tax_rows as $tax_row ) {
2013-10-24 18:22:22 +00:00
if ( ! isset ( $grouped_tax_tows [ $tax_row -> rate_id ] ) ) {
$grouped_tax_tows [ $tax_row -> rate_id ] = ( object ) array (
'tax_rate' => $tax_row -> tax_rate ,
'total_orders' => 0 ,
'tax_amount' => 0 ,
'shipping_tax_amount' => 0
);
}
$grouped_tax_tows [ $tax_row -> rate_id ] -> total_orders ++ ;
2013-11-25 13:34:21 +00:00
$grouped_tax_tows [ $tax_row -> rate_id ] -> tax_amount += wc_round_tax_total ( $tax_row -> tax_amount );
$grouped_tax_tows [ $tax_row -> rate_id ] -> shipping_tax_amount += wc_round_tax_total ( $tax_row -> shipping_tax_amount );
2013-10-24 18:22:22 +00:00
}
foreach ( $grouped_tax_tows as $rate_id => $tax_row ) {
$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 >
< th scope = " row " >< ? php echo $tax_row -> tax_rate ; ?> </th>
< td >< ? php echo $rate ; ?> %</td>
< 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 >
< ? php else : ?>
< tbody >
< tr >
< td >< ? php _e ( 'No taxes found in this period' , 'woocommerce' ); ?> </td>
</ tr >
</ tbody >
< ? php endif ; ?>
</ table >
< ? php
}
}