Rounded report

This commit is contained in:
Mike Jolley 2013-10-24 19:22:22 +01:00
parent 92fa4e379b
commit af6996866e
1 changed files with 24 additions and 14 deletions

View File

@ -72,13 +72,13 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'tax_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
'function' => 'SUM',
'function' => '',
'name' => 'tax_amount'
),
'shipping_tax_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
'function' => 'SUM',
'function' => '',
'name' => 'shipping_tax_amount'
),
'rate_id' => array(
@ -86,13 +86,7 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'order_item_type' => 'tax',
'function' => '',
'name' => 'rate_id'
),
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
'distinct' => true,
),
)
),
'where' => array(
array(
@ -106,7 +100,6 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'operator' => '!='
)
),
'group_by' => 'tax_rate',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true
@ -134,16 +127,33 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
</tfoot>
<tbody>
<?php
$grouped_tax_tows = array();
foreach ( $tax_rows as $tax_row ) {
$rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_row->rate_id ) );
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 ++;
$grouped_tax_tows[ $tax_row->rate_id ]->tax_amount += woocommerce_round_tax_total( $tax_row->tax_amount );
$grouped_tax_tows[ $tax_row->rate_id ]->shipping_tax_amount += woocommerce_round_tax_total( $tax_row->shipping_tax_amount );
}
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 ) );
?>
<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>
<td class="total_row"><?php echo woocommerce_price( woocommerce_round_tax_total( $tax_row->tax_amount ) ); ?></td>
<td class="total_row"><?php echo woocommerce_price( woocommerce_round_tax_total( $tax_row->shipping_tax_amount ) ); ?></td>
<td class="total_row"><?php echo woocommerce_price( woocommerce_round_tax_total( $tax_row->tax_amount + $tax_row->shipping_tax_amount ) ); ?></td>
<td class="total_row"><?php echo woocommerce_price( $tax_row->tax_amount ); ?></td>
<td class="total_row"><?php echo woocommerce_price( $tax_row->shipping_tax_amount ); ?></td>
<td class="total_row"><?php echo woocommerce_price( $tax_row->tax_amount + $tax_row->shipping_tax_amount ); ?></td>
</tr>
<?php
}