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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 / src / Admin / API / Reports / Taxes / Controller.php
woocommerce / src / Admin / API / Reports / Taxes Last commit date
Stats 4 weeks ago Controller.php 3 months ago DataStore.php 2 months ago Query.php 1 year ago
Controller.php
282 lines
1 <?php
2 /**
3 * REST API Reports taxes controller
4 *
5 * Handles requests to the /reports/taxes endpoint.
6 */
7
8 namespace Automattic\WooCommerce\Admin\API\Reports\Taxes;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Automattic\WooCommerce\Admin\API\Reports\ExportableInterface;
13 use Automattic\WooCommerce\Admin\API\Reports\ExportableTraits;
14 use Automattic\WooCommerce\Admin\API\Reports\GenericController;
15 use Automattic\WooCommerce\Admin\API\Reports\GenericQuery;
16 use WP_REST_Request;
17 use WP_REST_Response;
18
19 /**
20 * REST API Reports taxes controller class.
21 *
22 * @internal
23 * @extends GenericController
24 */
25 class Controller extends GenericController implements ExportableInterface {
26 /**
27 * Exportable traits.
28 */
29 use ExportableTraits;
30
31 /**
32 * Route base.
33 *
34 * @var string
35 */
36 protected $rest_base = 'reports/taxes';
37
38 /**
39 * Get data from `'taxes'` GenericQuery.
40 *
41 * @override GenericController::get_datastore_data()
42 *
43 * @param array $query_args Query arguments.
44 * @return mixed Results from the data store.
45 */
46 protected function get_datastore_data( $query_args = array() ) {
47 $query = new GenericQuery( $query_args, 'taxes' );
48 return $query->get_data();
49 }
50
51 /**
52 * Maps query arguments from the REST request.
53 *
54 * @param array $request Request array.
55 * @return array
56 */
57 protected function prepare_reports_query( $request ) {
58 $args = array();
59 $args['before'] = $request['before'];
60 $args['after'] = $request['after'];
61 $args['page'] = $request['page'];
62 $args['per_page'] = $request['per_page'];
63 $args['orderby'] = $request['orderby'];
64 $args['order'] = $request['order'];
65 $args['taxes'] = $request['taxes'];
66 $args['force_cache_refresh'] = $request['force_cache_refresh'];
67
68 return $args;
69 }
70
71 /**
72 * Prepare a report data item for serialization.
73 *
74 * @param mixed $report Report data item as returned from Data Store.
75 * @param WP_REST_Request $request Request object.
76 * @return WP_REST_Response
77 */
78 public function prepare_item_for_response( $report, $request ) {
79 $response = parent::prepare_item_for_response( $report, $request );
80
81 // Map to `object` for backwards compatibility.
82 $report = (object) $report;
83 $response->add_links( $this->prepare_links( $report ) );
84
85 /**
86 * Filter a report returned from the API.
87 *
88 * Allows modification of the report data right before it is returned.
89 *
90 * @param WP_REST_Response $response The response object.
91 * @param object $report The original report object.
92 * @param WP_REST_Request $request Request used to generate the response.
93 */
94 return apply_filters( 'woocommerce_rest_prepare_report_taxes', $response, $report, $request );
95 }
96
97 /**
98 * Prepare links for the request.
99 *
100 * @param WC_Reports_Query $object Object data.
101 * @return array
102 */
103 protected function prepare_links( $object ) {
104 $links = array(
105 'tax' => array(
106 'href' => rest_url( sprintf( '/%s/taxes/%d', $this->namespace, $object->tax_rate_id ) ),
107 ),
108 );
109
110 return $links;
111 }
112
113 /**
114 * Get the Report's schema, conforming to JSON Schema.
115 *
116 * @return array
117 */
118 public function get_item_schema() {
119 $schema = array(
120 '$schema' => 'http://json-schema.org/draft-04/schema#',
121 'title' => 'report_taxes',
122 'type' => 'object',
123 'properties' => array(
124 'tax_rate_id' => array(
125 'description' => __( 'Tax rate ID.', 'woocommerce' ),
126 'type' => 'integer',
127 'context' => array( 'view', 'edit' ),
128 'readonly' => true,
129 ),
130 'name' => array(
131 'description' => __( 'Tax rate name.', 'woocommerce' ),
132 'type' => 'string',
133 'context' => array( 'view', 'edit' ),
134 'readonly' => true,
135 ),
136 'tax_rate' => array(
137 'description' => __( 'Tax rate.', 'woocommerce' ),
138 'type' => 'number',
139 'context' => array( 'view', 'edit' ),
140 'readonly' => true,
141 ),
142 'country' => array(
143 'description' => __( 'Country / Region.', 'woocommerce' ),
144 'type' => 'string',
145 'context' => array( 'view', 'edit' ),
146 'readonly' => true,
147 ),
148 'state' => array(
149 'description' => __( 'State.', 'woocommerce' ),
150 'type' => 'string',
151 'context' => array( 'view', 'edit' ),
152 'readonly' => true,
153 ),
154 'priority' => array(
155 'description' => __( 'Priority.', 'woocommerce' ),
156 'type' => 'integer',
157 'context' => array( 'view', 'edit' ),
158 'readonly' => true,
159 ),
160 'total_tax' => array(
161 'description' => __( 'Total tax.', 'woocommerce' ),
162 'type' => 'number',
163 'context' => array( 'view', 'edit' ),
164 'readonly' => true,
165 ),
166 'order_tax' => array(
167 'description' => __( 'Order tax.', 'woocommerce' ),
168 'type' => 'number',
169 'context' => array( 'view', 'edit' ),
170 'readonly' => true,
171 ),
172 'shipping_tax' => array(
173 'description' => __( 'Shipping tax.', 'woocommerce' ),
174 'type' => 'number',
175 'context' => array( 'view', 'edit' ),
176 'readonly' => true,
177 ),
178 'orders_count' => array(
179 'description' => __( 'Number of orders.', 'woocommerce' ),
180 'type' => 'integer',
181 'context' => array( 'view', 'edit' ),
182 'readonly' => true,
183 ),
184 ),
185 );
186
187 return $this->add_additional_fields_schema( $schema );
188 }
189
190 /**
191 * Get the query params for collections.
192 *
193 * @return array
194 */
195 public function get_collection_params() {
196 $params = parent::get_collection_params();
197 $params['orderby']['default'] = 'tax_rate_id';
198 $params['orderby']['enum'] = $this->apply_custom_orderby_filters(
199 array(
200 'name',
201 'tax_rate_id',
202 'tax_code',
203 'rate',
204 'order_tax',
205 'total_tax',
206 'shipping_tax',
207 'orders_count',
208 )
209 );
210 $params['taxes'] = array(
211 'description' => __( 'Limit result set to items assigned one or more tax rates.', 'woocommerce' ),
212 'type' => 'array',
213 'sanitize_callback' => 'wp_parse_id_list',
214 'validate_callback' => 'rest_validate_request_arg',
215 'items' => array(
216 'type' => 'string',
217 ),
218 );
219
220 return $params;
221 }
222
223 /**
224 * Get the column names for export.
225 *
226 * @return array Key value pair of Column ID => Label.
227 */
228 public function get_export_columns() {
229 $export_columns = array(
230 'tax_code' => __( 'Tax code', 'woocommerce' ),
231 'rate' => __( 'Rate', 'woocommerce' ),
232 'total_tax' => __( 'Total tax', 'woocommerce' ),
233 'order_tax' => __( 'Order tax', 'woocommerce' ),
234 'shipping_tax' => __( 'Shipping tax', 'woocommerce' ),
235 'orders_count' => __( 'Orders', 'woocommerce' ),
236 );
237
238 /**
239 * Filter to add or remove column names from the taxes report for export.
240 *
241 * @since 10.7.0
242 * @param array $export_columns Key value pair of column ID and label.
243 */
244 return apply_filters( 'woocommerce_report_taxes_export_columns', $export_columns );
245 }
246
247 /**
248 * Get the column values for export.
249 *
250 * @param array $item Single report item/row.
251 * @return array Key value pair of Column ID => Row Value.
252 */
253 public function prepare_item_for_export( $item ) {
254 $export_item = array(
255 'tax_code' => \WC_Tax::get_rate_code(
256 (object) array(
257 'tax_rate_id' => $item['tax_rate_id'],
258 'tax_rate_country' => $item['country'],
259 'tax_rate_state' => $item['state'],
260 'tax_rate_name' => $item['name'],
261 'tax_rate_priority' => $item['priority'],
262 )
263 ),
264 'rate' => $item['tax_rate'],
265 'total_tax' => self::csv_number_format( $item['total_tax'] ),
266 'order_tax' => self::csv_number_format( $item['order_tax'] ),
267 'shipping_tax' => self::csv_number_format( $item['shipping_tax'] ),
268 'orders_count' => $item['orders_count'],
269 );
270
271 /**
272 * Filter to prepare extra columns in the export item for the taxes
273 * report.
274 *
275 * @since 10.7.0
276 * @param array $export_item Key value pair of column ID and row value.
277 * @param array $item The original report item.
278 */
279 return apply_filters( 'woocommerce_report_taxes_prepare_export_item', $export_item, $item );
280 }
281 }
282