1 <?php
2 3 4 5 6 7 8 9
10 class WC_Report_Taxes_By_Date extends WC_Admin_Report {
11
12 13 14 15
16 public function get_chart_legend() {
17 $legend = array();
18
19 return array();
20 }
21
22 23 24
25 public function get_export_button() {
26 $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month';
27 ?>
28 <a
29 href="#"
30 download="report-<?php echo $current_range; ?>-<?php echo date_i18n( 'Y-m-d', current_time('timestamp') ); ?>.csv"
31 class="export_csv"
32 data-export="table"
33 >
34 <?php _e( 'Export CSV', 'woocommerce' ); ?>
35 </a>
36 <?php
37 }
38
39 40 41
42 public function output_report() {
43 global $woocommerce, $wpdb, $wp_locale;
44
45 $ranges = array(
46 'year' => __( 'Year', 'woocommerce' ),
47 'last_month' => __( 'Last Month', 'woocommerce' ),
48 'month' => __( 'This Month', 'woocommerce' ),
49 );
50
51 $current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month';
52
53 if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
54 $current_range = 'last_month';
55
56 $this->calculate_current_range( $current_range );
57
58 $hide_sidebar = true;
59
60 include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php');
61 }
62
63 64 65 66
67 public function get_main_chart() {
68 global $wpdb;
69
70 $tax_rows = $this->get_order_report_data( array(
71 'data' => array(
72 '_order_tax' => array(
73 'type' => 'meta',
74 'function' => 'SUM',
75 'name' => 'tax_amount'
76 ),
77 '_order_shipping_tax' => array(
78 'type' => 'meta',
79 'function' => 'SUM',
80 'name' => 'shipping_tax_amount'
81 ),
82 '_order_total' => array(
83 'type' => 'meta',
84 'function' => 'SUM',
85 'name' => 'total_sales'
86 ),
87 '_order_shipping' => array(
88 'type' => 'meta',
89 'function' => 'SUM',
90 'name' => 'total_shipping'
91 ),
92 'ID' => array(
93 'type' => 'post_data',
94 'function' => 'COUNT',
95 'name' => 'total_orders',
96 'distinct' => true,
97 ),
98 'post_date' => array(
99 'type' => 'post_data',
100 'function' => '',
101 'name' => 'post_date'
102 ),
103 ),
104 'group_by' => $this->group_by_query,
105 'order_by' => 'post_date ASC',
106 'query_type' => 'get_results',
107 'filter_range' => true
108 ) );
109 ?>
110 <table class="widefat">
111 <thead>
112 <tr>
113 <th><?php _e( 'Period', 'woocommerce' ); ?></th>
114 <th class="total_row"><?php _e( 'Number of orders', 'woocommerce' ); ?></th>
115 <th class="total_row"><?php _e( 'Total Sales', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e("This is the sum of the 'Order Total' field within your orders.", 'woocommerce'); ?>" href="#">[?]</a></th>
116 <th class="total_row"><?php _e( 'Total Shipping', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e("This is the sum of the 'Shipping Total' field within your orders.", 'woocommerce'); ?>" href="#">[?]</a></th>
117 <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>
118 <th class="total_row"><?php _e( 'Net profit', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e("Total sales minus shipping and tax.", 'woocommerce'); ?>" href="#">[?]</a></th>
119 </tr>
120 </thead>
121 <?php if ( $tax_rows ) :
122 $gross = array_sum( wp_list_pluck( (array) $tax_rows, 'total_sales' ) ) - array_sum( wp_list_pluck( (array) $tax_rows, 'total_shipping' ) );
123 $total_tax = array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) - array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) );
124 ?>
125 <tfoot>
126 <tr>
127 <th scope="row"><?php _e( 'Totals', 'woocommerce' ); ?></th>
128 <th class="total_row"><?php echo array_sum( wp_list_pluck( (array) $tax_rows, 'total_orders' ) ); ?></th>
129 <th class="total_row"><?php echo wc_price( $gross ); ?></th>
130 <th class="total_row"><?php echo wc_price( array_sum( wp_list_pluck( (array) $tax_rows, 'total_shipping' ) ) ); ?></th>
131 <th class="total_row"><?php echo wc_price( $total_tax ); ?></th>
132 <th class="total_row"><?php echo wc_price( $gross - $total_tax ); ?></th>
133 </tr>
134 </tfoot>
135 <tbody>
136 <?php
137 foreach ( $tax_rows as $tax_row ) {
138 $gross = $tax_row->total_sales - $tax_row->total_shipping;
139 $total_tax = $tax_row->tax_amount + $tax_row->shipping_tax_amount;
140 ?>
141 <tr>
142 <th scope="row"><?php
143 if ( $this->chart_groupby == 'month' )
144 echo date_i18n( 'F', strtotime( $tax_row->post_date ) );
145 else
146 echo date_i18n( get_option( 'date_format' ), strtotime( $tax_row->post_date ) );
147 ?></th>
148 <td class="total_row"><?php echo $tax_row->total_orders; ?></td>
149 <td class="total_row"><?php echo wc_price( $gross ); ?></td>
150 <td class="total_row"><?php echo wc_price( $tax_row->total_shipping ); ?></td>
151 <td class="total_row"><?php echo wc_price( $total_tax ); ?></td>
152 <td class="total_row"><?php echo wc_price( $gross - $total_tax ); ?></td>
153 </tr>
154 <?php
155 }
156 ?>
157 </tbody>
158 <?php else : ?>
159 <tbody>
160 <tr>
161 <td><?php _e( 'No taxes found in this period', 'woocommerce' ); ?></td>
162 </tr>
163 </tbody>
164 <?php endif; ?>
165 </table>
166 <?php
167 }
168 }