WC_Report_Taxes_By_Code

WC_Report_Taxes_By_Code.

Defined (1)

The class is defined in the following location(s).

/includes/admin/reports/class-wc-report-taxes-by-code.php  
  1. class WC_Report_Taxes_By_Code extends WC_Admin_Report { 
  2.  
  3. /** 
  4. * Get the legend for the main chart sidebar. 
  5. * @return array 
  6. */ 
  7. public function get_chart_legend() { 
  8. return array(); 
  9.  
  10. /** 
  11. * Output an export link. 
  12. */ 
  13. public function get_export_button() { 
  14.  
  15. $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month'; 
  16. ?> 
  17. <a 
  18. href="#" 
  19. download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); ?>.csv" 
  20. class="export_csv" 
  21. data-export="table" 
  22. <?php _e( 'Export CSV', 'woocommerce' ); ?> 
  23. </a> 
  24. <?php 
  25.  
  26. /** 
  27. * Output the report. 
  28. */ 
  29. public function output_report() { 
  30.  
  31. $ranges = array( 
  32. 'year' => __( 'Year', 'woocommerce' ),  
  33. 'last_month' => __( 'Last month', 'woocommerce' ),  
  34. 'month' => __( 'This month', 'woocommerce' ),  
  35. ); 
  36.  
  37. $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month'; 
  38.  
  39. if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { 
  40. $current_range = 'last_month'; 
  41.  
  42. $this->check_current_range_nonce( $current_range ); 
  43. $this->calculate_current_range( $current_range ); 
  44.  
  45. $hide_sidebar = true; 
  46.  
  47. include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' ); 
  48.  
  49. /** 
  50. * Get the main chart. 
  51. * @return string 
  52. */ 
  53. public function get_main_chart() { 
  54. global $wpdb; 
  55.  
  56. $query_data = array( 
  57. 'order_item_name' => array( 
  58. 'type' => 'order_item',  
  59. 'function' => '',  
  60. 'name' => 'tax_rate',  
  61. ),  
  62. 'tax_amount' => array( 
  63. 'type' => 'order_item_meta',  
  64. 'order_item_type' => 'tax',  
  65. 'function' => '',  
  66. 'name' => 'tax_amount',  
  67. ),  
  68. 'shipping_tax_amount' => array( 
  69. 'type' => 'order_item_meta',  
  70. 'order_item_type' => 'tax',  
  71. 'function' => '',  
  72. 'name' => 'shipping_tax_amount',  
  73. ),  
  74. 'rate_id' => array( 
  75. 'type' => 'order_item_meta',  
  76. 'order_item_type' => 'tax',  
  77. 'function' => '',  
  78. 'name' => 'rate_id',  
  79. ),  
  80. 'ID' => array( 
  81. 'type' => 'post_data',  
  82. 'function' => '',  
  83. 'name' => 'post_id',  
  84. ),  
  85. ); 
  86.  
  87. $query_where = array( 
  88. array( 
  89. 'key' => 'order_item_type',  
  90. 'value' => 'tax',  
  91. 'operator' => '=',  
  92. ),  
  93. array( 
  94. 'key' => 'order_item_name',  
  95. 'value' => '',  
  96. 'operator' => '!=',  
  97. ),  
  98. ); 
  99.  
  100. $tax_rows_orders = $this->get_order_report_data( array( 
  101. 'data' => $query_data,  
  102. 'where' => $query_where,  
  103. 'order_by' => 'posts.post_date ASC',  
  104. 'query_type' => 'get_results',  
  105. 'filter_range' => true,  
  106. 'order_types' => array_merge( wc_get_order_types( 'sales-reports' ), array( 'shop_order_refund' ) ),  
  107. 'order_status' => array( 'completed', 'processing', 'on-hold' ),  
  108. 'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored 
  109. ) ); 
  110.  
  111. // Merge 
  112. $tax_rows = array(); 
  113.  
  114. foreach ( $tax_rows_orders as $tax_row ) { 
  115. $key = $tax_row->rate_id; 
  116. $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_orders' => 0 ); 
  117.  
  118. if ( 'shop_order_refund' !== get_post_type( $tax_row->post_id ) ) { 
  119. $tax_rows[ $key ]->total_orders += 1; 
  120.  
  121. $tax_rows[ $key ]->tax_rate = $tax_row->tax_rate; 
  122. $tax_rows[ $key ]->tax_amount += wc_round_tax_total( $tax_row->tax_amount ); 
  123. $tax_rows[ $key ]->shipping_tax_amount += wc_round_tax_total( $tax_row->shipping_tax_amount ); 
  124. ?> 
  125. <table class="widefat"> 
  126. <thead> 
  127. <tr> 
  128. <th><?php _e( 'Tax', 'woocommerce' ); ?></th> 
  129. <th><?php _e( 'Rate', 'woocommerce' ); ?></th> 
  130. <th class="total_row"><?php _e( 'Number of orders', 'woocommerce' ); ?></th> 
  131. <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> 
  132. <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> 
  133. <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> 
  134. </tr> 
  135. </thead> 
  136. <?php if ( ! empty( $tax_rows ) ) : ?> 
  137. <tbody> 
  138. <?php 
  139. foreach ( $tax_rows as $rate_id => $tax_row ) { 
  140. $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) ); 
  141. ?> 
  142. <tr> 
  143. <th scope="row"><?php echo apply_filters( 'woocommerce_reports_taxes_tax_rate', $tax_row->tax_rate, $rate_id, $tax_row ); ?></th> 
  144. <td><?php echo apply_filters( 'woocommerce_reports_taxes_rate', $rate, $rate_id, $tax_row ); ?>%</td> 
  145. <td class="total_row"><?php echo $tax_row->total_orders; ?></td> 
  146. <td class="total_row"><?php echo wc_price( $tax_row->tax_amount ); ?></td> 
  147. <td class="total_row"><?php echo wc_price( $tax_row->shipping_tax_amount ); ?></td> 
  148. <td class="total_row"><?php echo wc_price( $tax_row->tax_amount + $tax_row->shipping_tax_amount ); ?></td> 
  149. </tr> 
  150. <?php 
  151. ?> 
  152. </tbody> 
  153. <tfoot> 
  154. <tr> 
  155. <th scope="row" colspan="3"><?php _e( 'Total', 'woocommerce' ); ?></th> 
  156. <th class="total_row"><?php echo wc_price( wc_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) ) ); ?></th> 
  157. <th class="total_row"><?php echo wc_price( wc_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ) ); ?></th> 
  158. <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> 
  159. </tr> 
  160. </tfoot> 
  161. <?php else : ?> 
  162. <tbody> 
  163. <tr> 
  164. <td><?php _e( 'No taxes found in this period', 'woocommerce' ); ?></td> 
  165. </tr> 
  166. </tbody> 
  167. <?php endif; ?> 
  168. </table> 
  169. <?php