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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / reports / class-wc-report-taxes-by-code.php
woocommerce / includes / admin / reports Last commit date
class-wc-admin-report.php 1 year ago class-wc-report-coupon-usage.php 5 years ago class-wc-report-customer-list.php 9 months ago class-wc-report-customers.php 9 months ago class-wc-report-downloads.php 5 years ago class-wc-report-low-in-stock.php 5 years ago class-wc-report-most-stocked.php 5 years ago class-wc-report-out-of-stock.php 5 years ago class-wc-report-sales-by-category.php 2 years ago class-wc-report-sales-by-date.php 1 year ago class-wc-report-sales-by-product.php 3 months ago class-wc-report-stock.php 1 year ago class-wc-report-taxes-by-code.php 1 year ago class-wc-report-taxes-by-date.php 1 year ago
class-wc-report-taxes-by-code.php
243 lines
1 <?php
2 /**
3 * Taxes by tax code report.
4 *
5 * @package WooCommerce\Admin\Reports
6 */
7
8 use Automattic\WooCommerce\Enums\OrderStatus;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * WC_Report_Taxes_By_Code
16 *
17 * @package WooCommerce\Admin\Reports
18 * @version 2.1.0
19 */
20 class WC_Report_Taxes_By_Code extends WC_Admin_Report {
21
22 /**
23 * Get the legend for the main chart sidebar.
24 *
25 * @return array
26 */
27 public function get_chart_legend() {
28 return array();
29 }
30
31 /**
32 * Output an export link.
33 */
34 public function get_export_button() {
35
36 $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : 'last_month';
37 ?>
38 <a
39 href="#"
40 download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo esc_attr( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ); ?>.csv"
41 class="export_csv"
42 data-export="table"
43 >
44 <?php esc_html_e( 'Export CSV', 'woocommerce' ); ?>
45 </a>
46 <?php
47 }
48
49 /**
50 * Output the report.
51 */
52 public function output_report() {
53
54 $ranges = array(
55 'year' => __( 'Year', 'woocommerce' ),
56 'last_month' => __( 'Last month', 'woocommerce' ),
57 'month' => __( 'This month', 'woocommerce' ),
58 );
59
60 $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : 'last_month';
61
62 if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) {
63 $current_range = 'last_month';
64 }
65
66 $this->check_current_range_nonce( $current_range );
67 $this->calculate_current_range( $current_range );
68
69 $hide_sidebar = true;
70
71 include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
72 }
73
74 /**
75 * Get the main chart.
76 */
77 public function get_main_chart() {
78 global $wpdb;
79
80 $query_data = array(
81 'order_item_name' => array(
82 'type' => 'order_item',
83 'function' => '',
84 'name' => 'tax_rate',
85 ),
86 'tax_amount' => array(
87 'type' => 'order_item_meta',
88 'order_item_type' => 'tax',
89 'function' => '',
90 'name' => 'tax_amount',
91 ),
92 'shipping_tax_amount' => array(
93 'type' => 'order_item_meta',
94 'order_item_type' => 'tax',
95 'function' => '',
96 'name' => 'shipping_tax_amount',
97 ),
98 'rate_id' => array(
99 'type' => 'order_item_meta',
100 'order_item_type' => 'tax',
101 'function' => '',
102 'name' => 'rate_id',
103 ),
104 'ID' => array(
105 'type' => 'post_data',
106 'function' => '',
107 'name' => 'post_id',
108 ),
109 );
110
111 $query_where = array(
112 array(
113 'key' => 'order_item_type',
114 'value' => 'tax',
115 'operator' => '=',
116 ),
117 array(
118 'key' => 'order_item_name',
119 'value' => '',
120 'operator' => '!=',
121 ),
122 );
123
124 // We exclude on-hold orders as they are still pending payment.
125 $tax_rows_orders = $this->get_order_report_data(
126 array(
127 'data' => $query_data,
128 'where' => $query_where,
129 'order_by' => 'posts.post_date ASC',
130 'query_type' => 'get_results',
131 'filter_range' => true,
132 'order_types' => wc_get_order_types( 'sales-reports' ),
133 'order_status' => array( OrderStatus::COMPLETED, OrderStatus::PROCESSING, OrderStatus::REFUNDED ),
134 )
135 );
136
137 $tax_rows_partial_refunds = $this->get_order_report_data(
138 array(
139 'data' => $query_data,
140 'where' => $query_where,
141 'order_by' => 'posts.post_date ASC',
142 'query_type' => 'get_results',
143 'filter_range' => true,
144 'order_types' => array( 'shop_order_refund' ),
145 'parent_order_status' => array( OrderStatus::COMPLETED, OrderStatus::PROCESSING ), // Partial refunds inside refunded orders should be ignored.
146 )
147 );
148
149 $tax_rows_full_refunds = $this->get_order_report_data(
150 array(
151 'data' => $query_data,
152 'where' => $query_where,
153 'order_by' => 'posts.post_date ASC',
154 'query_type' => 'get_results',
155 'filter_range' => true,
156 'order_types' => array( 'shop_order_refund' ),
157 'parent_order_status' => array( OrderStatus::REFUNDED ),
158 )
159 );
160
161 // Merge.
162 $tax_rows = array();
163 // Initialize an associative array to store unique post_ids.
164 $unique_post_ids = array();
165
166 foreach ( $tax_rows_orders + $tax_rows_partial_refunds as $tax_row ) {
167 $key = $tax_row->tax_rate;
168 $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
169 'tax_amount' => 0,
170 'shipping_tax_amount' => 0,
171 'total_orders' => 0,
172 );
173 $tax_rows[ $key ]->tax_rate = $tax_row->tax_rate;
174 $tax_rows[ $key ]->tax_amount += wc_round_tax_total( $tax_row->tax_amount );
175 $tax_rows[ $key ]->shipping_tax_amount += wc_round_tax_total( $tax_row->shipping_tax_amount );
176 if ( ! isset( $unique_post_ids[ $key ] ) || ! in_array( $tax_row->post_id, $unique_post_ids[ $key ], true ) ) {
177 $unique_post_ids[ $key ] = isset( $unique_post_ids[ $key ] ) ? $unique_post_ids[ $key ] : array();
178 $unique_post_ids[ $key ][] = $tax_row->post_id;
179 $tax_rows[ $key ]->total_orders += 1;
180 }
181 }
182
183 foreach ( $tax_rows_full_refunds as $tax_row ) {
184 $key = $tax_row->tax_rate;
185 $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
186 'tax_amount' => 0,
187 'shipping_tax_amount' => 0,
188 'total_orders' => 0,
189 );
190 $tax_rows[ $key ]->tax_rate = $tax_row->tax_rate;
191 $tax_rows[ $key ]->tax_amount += wc_round_tax_total( $tax_row->tax_amount );
192 $tax_rows[ $key ]->shipping_tax_amount += wc_round_tax_total( $tax_row->shipping_tax_amount );
193 }
194 ?>
195 <table class="widefat">
196 <thead>
197 <tr>
198 <th><?php esc_html_e( 'Tax', 'woocommerce' ); ?></th>
199 <th><?php esc_html_e( 'Rate', 'woocommerce' ); ?></th>
200 <th class="total_row"><?php esc_html_e( 'Number of orders', 'woocommerce' ); ?></th>
201 <th class="total_row"><?php esc_html_e( 'Tax amount', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the sum of the "Tax rows" tax amount within your orders.', 'woocommerce' ) ); ?></th>
202 <th class="total_row"><?php esc_html_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>
203 <th class="total_row"><?php esc_html_e( 'Total tax', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the total tax for the rate (shipping tax + product tax).', 'woocommerce' ) ); ?></th>
204 </tr>
205 </thead>
206 <?php if ( ! empty( $tax_rows ) ) : ?>
207 <tbody>
208 <?php
209 foreach ( $tax_rows as $rate_id => $tax_row ) {
210 $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
211 ?>
212 <tr>
213 <th scope="row"><?php echo wp_kses_post( apply_filters( 'woocommerce_reports_taxes_tax_rate', $tax_row->tax_rate, $rate_id, $tax_row ) ); ?></th>
214 <td><?php echo wp_kses_post( apply_filters( 'woocommerce_reports_taxes_rate', $rate, $rate_id, $tax_row ) ); ?>%</td>
215 <td class="total_row"><?php echo esc_html( $tax_row->total_orders ); ?></td>
216 <td class="total_row"><?php echo wc_price( $tax_row->tax_amount ); // phpcs:ignore ?></td>
217 <td class="total_row"><?php echo wc_price( $tax_row->shipping_tax_amount ); // phpcs:ignore ?></td>
218 <td class="total_row"><?php echo wc_price( $tax_row->tax_amount + $tax_row->shipping_tax_amount ); // phpcs:ignore ?></td>
219 </tr>
220 <?php
221 }
222 ?>
223 </tbody>
224 <tfoot>
225 <tr>
226 <th scope="row" colspan="3"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
227 <th class="total_row"><?php echo wc_price( wc_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) ) ); // phpcs:ignore ?></th>
228 <th class="total_row"><?php echo wc_price( wc_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ) ); // phpcs:ignore ?></th>
229 <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' ) ) ) ); // phpcs:ignore ?></strong></th>
230 </tr>
231 </tfoot>
232 <?php else : ?>
233 <tbody>
234 <tr>
235 <td><?php esc_html_e( 'No taxes found in this period', 'woocommerce' ); ?></td>
236 </tr>
237 </tbody>
238 <?php endif; ?>
239 </table>
240 <?php
241 }
242 }
243