WC_Report_Taxes_By_Date

WC_Report_Taxes_By_Date.

Defined (1)

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

/includes/admin/reports/class-wc-report-taxes-by-date.php  
  1. class WC_Report_Taxes_By_Date 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. $query_data = array( 
  55. '_order_tax' => array( 
  56. 'type' => 'meta',  
  57. 'function' => 'SUM',  
  58. 'name' => 'tax_amount',  
  59. ),  
  60. '_order_shipping_tax' => array( 
  61. 'type' => 'meta',  
  62. 'function' => 'SUM',  
  63. 'name' => 'shipping_tax_amount',  
  64. ),  
  65. '_order_total' => array( 
  66. 'type' => 'meta',  
  67. 'function' => 'SUM',  
  68. 'name' => 'total_sales',  
  69. ),  
  70. '_order_shipping' => array( 
  71. 'type' => 'meta',  
  72. 'function' => 'SUM',  
  73. 'name' => 'total_shipping',  
  74. ),  
  75. 'ID' => array( 
  76. 'type' => 'post_data',  
  77. 'function' => 'COUNT',  
  78. 'name' => 'total_orders',  
  79. 'distinct' => true,  
  80. ),  
  81. 'post_date' => array( 
  82. 'type' => 'post_data',  
  83. 'function' => '',  
  84. 'name' => 'post_date',  
  85. ),  
  86. ); 
  87.  
  88. $tax_rows_orders = $this->get_order_report_data( array( 
  89. 'data' => $query_data,  
  90. 'group_by' => $this->group_by_query,  
  91. 'order_by' => 'post_date ASC',  
  92. 'query_type' => 'get_results',  
  93. 'filter_range' => true,  
  94. 'order_types' => wc_get_order_types( 'sales-reports' ),  
  95. 'order_status' => array( 'completed', 'processing', 'on-hold' ),  
  96. ) ); 
  97.  
  98. $tax_rows_partial_refunds = $this->get_order_report_data( array( 
  99. 'data' => $query_data,  
  100. 'group_by' => $this->group_by_query,  
  101. 'order_by' => 'post_date ASC',  
  102. 'query_type' => 'get_results',  
  103. 'filter_range' => true,  
  104. 'order_types' => array( 'shop_order_refund' ),  
  105. 'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored 
  106. ) ); 
  107.  
  108. // Merge 
  109. $tax_rows = array(); 
  110.  
  111. foreach ( $tax_rows_orders as $tax_row ) { 
  112. $key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) ); 
  113. $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_sales' => 0, 'total_shipping' => 0, 'total_orders' => 0 ); 
  114. $tax_rows[ $key ]->tax_amount += $tax_row->tax_amount; 
  115. $tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount; 
  116. $tax_rows[ $key ]->total_sales += $tax_row->total_sales; 
  117. $tax_rows[ $key ]->total_shipping += $tax_row->total_shipping; 
  118. $tax_rows[ $key ]->total_orders += $tax_row->total_orders; 
  119.  
  120. foreach ( $tax_rows_partial_refunds as $tax_row ) { 
  121. $key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) ); 
  122. $tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_sales' => 0, 'total_shipping' => 0, 'total_orders' => 0 ); 
  123. $tax_rows[ $key ]->tax_amount += $tax_row->tax_amount; 
  124. $tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount; 
  125. $tax_rows[ $key ]->total_sales += $tax_row->total_sales; 
  126. $tax_rows[ $key ]->total_shipping += $tax_row->total_shipping; 
  127. ?> 
  128. <table class="widefat"> 
  129. <thead> 
  130. <tr> 
  131. <th><?php _e( 'Period', 'woocommerce' ); ?></th> 
  132. <th class="total_row"><?php _e( 'Number of orders', 'woocommerce' ); ?></th> 
  133. <th class="total_row"><?php _e( 'Total sales', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "This is the sum of the 'Order total' field within your orders.", 'woocommerce' ) ); ?></th> 
  134. <th class="total_row"><?php _e( 'Total shipping', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "This is the sum of the 'Shipping total' field within your orders.", 'woocommerce' ) ); ?></th> 
  135. <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> 
  136. <th class="total_row"><?php _e( 'Net profit', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "Total sales minus shipping and tax.", 'woocommerce' ) ); ?></th> 
  137. </tr> 
  138. </thead> 
  139. <?php if ( ! empty( $tax_rows ) ) : ?> 
  140. <tbody> 
  141. <?php 
  142. foreach ( $tax_rows as $date => $tax_row ) { 
  143. $gross = $tax_row->total_sales - $tax_row->total_shipping; 
  144. $total_tax = $tax_row->tax_amount + $tax_row->shipping_tax_amount; 
  145. ?> 
  146. <tr> 
  147. <th scope="row"> 
  148. <?php echo ( 'month' === $this->chart_groupby ) ? date_i18n( 'F', strtotime( $date . '01' ) ) : date_i18n( get_option( 'date_format' ), strtotime( $date ) ); ?> 
  149. </th> 
  150. <td class="total_row"><?php echo $tax_row->total_orders; ?></td> 
  151. <td class="total_row"><?php echo wc_price( $gross ); ?></td> 
  152. <td class="total_row"><?php echo wc_price( $tax_row->total_shipping ); ?></td> 
  153. <td class="total_row"><?php echo wc_price( $total_tax ); ?></td> 
  154. <td class="total_row"><?php echo wc_price( $gross - $total_tax ); ?></td> 
  155. </tr> 
  156. <?php 
  157. ?> 
  158. </tbody> 
  159. <tfoot> 
  160. <?php 
  161. $gross = array_sum( wp_list_pluck( (array) $tax_rows, 'total_sales' ) ) - array_sum( wp_list_pluck( (array) $tax_rows, 'total_shipping' ) ); 
  162. $total_tax = array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) + array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ); 
  163. ?> 
  164. <tr> 
  165. <th scope="row"><?php _e( 'Totals', 'woocommerce' ); ?></th> 
  166. <th class="total_row"><?php echo array_sum( wp_list_pluck( (array) $tax_rows, 'total_orders' ) ); ?></th> 
  167. <th class="total_row"><?php echo wc_price( $gross ); ?></th> 
  168. <th class="total_row"><?php echo wc_price( array_sum( wp_list_pluck( (array) $tax_rows, 'total_shipping' ) ) ); ?></th> 
  169. <th class="total_row"><?php echo wc_price( $total_tax ); ?></th> 
  170. <th class="total_row"><?php echo wc_price( $gross - $total_tax ); ?></th> 
  171. </tr> 
  172. </tfoot> 
  173. <?php else : ?> 
  174. <tbody> 
  175. <tr> 
  176. <td><?php _e( 'No taxes found in this period', 'woocommerce' ); ?></td> 
  177. </tr> 
  178. </tbody> 
  179. <?php endif; ?> 
  180. </table> 
  181. <?php