2018-11-19 15:55:15 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
2018-11-26 14:01:20 +00:00
|
|
|
import { map } from 'lodash';
|
2018-11-19 15:55:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2018-11-26 14:01:20 +00:00
|
|
|
import { Link } from '@woocommerce/components';
|
2019-05-16 05:04:37 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal, renderCurrency } from '@woocommerce/currency';
|
2018-12-18 02:26:46 +00:00
|
|
|
import { getTaxCode } from './utils';
|
2019-01-29 16:48:46 +00:00
|
|
|
import { numberFormat } from '@woocommerce/number';
|
2018-11-19 15:55:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-11-26 14:01:20 +00:00
|
|
|
import ReportTable from 'analytics/components/report-table';
|
2018-11-19 15:55:15 +00:00
|
|
|
|
2018-11-26 14:01:20 +00:00
|
|
|
export default class TaxesReportTable extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
|
|
|
this.getSummary = this.getSummary.bind( this );
|
|
|
|
}
|
|
|
|
|
2018-11-19 15:55:15 +00:00
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Tax Code', 'woocommerce-admin' ),
|
2019-03-15 20:44:03 +00:00
|
|
|
key: 'tax_code',
|
2018-11-19 15:55:15 +00:00
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Rate', 'woocommerce-admin' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'rate',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Total Tax', 'woocommerce-admin' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'total_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Order Tax', 'woocommerce-admin' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'order_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Shipping Tax', 'woocommerce-admin' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'shipping_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Orders', 'woocommerce-admin' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'orders_count',
|
|
|
|
required: true,
|
|
|
|
defaultSort: true,
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( taxes ) {
|
|
|
|
return map( taxes, tax => {
|
2019-03-15 20:44:03 +00:00
|
|
|
const { order_tax, orders_count, tax_rate, total_tax, shipping_tax } = tax;
|
|
|
|
const taxCode = getTaxCode( tax );
|
2018-11-19 15:55:15 +00:00
|
|
|
|
2019-02-06 06:41:53 +00:00
|
|
|
// @todo Must link to the tax detail report
|
2018-11-19 15:55:15 +00:00
|
|
|
const taxLink = (
|
|
|
|
<Link href="" type="wc-admin">
|
2019-03-15 20:44:03 +00:00
|
|
|
{ taxCode }
|
2018-11-19 15:55:15 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: taxLink,
|
2019-03-15 20:44:03 +00:00
|
|
|
value: taxCode,
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-18 02:26:46 +00:00
|
|
|
display: tax_rate.toFixed( 2 ) + '%',
|
|
|
|
value: tax_rate,
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-05-16 05:04:37 +00:00
|
|
|
display: renderCurrency( total_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
value: getCurrencyFormatDecimal( total_tax ),
|
|
|
|
},
|
|
|
|
{
|
2019-05-16 05:04:37 +00:00
|
|
|
display: renderCurrency( order_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
value: getCurrencyFormatDecimal( order_tax ),
|
|
|
|
},
|
|
|
|
{
|
2019-05-16 05:04:37 +00:00
|
|
|
display: renderCurrency( shipping_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
value: getCurrencyFormatDecimal( shipping_tax ),
|
|
|
|
},
|
|
|
|
{
|
2018-11-26 03:31:38 +00:00
|
|
|
display: numberFormat( orders_count ),
|
2018-11-19 15:55:15 +00:00
|
|
|
value: orders_count,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
getSummary( totals ) {
|
2019-02-05 12:00:37 +00:00
|
|
|
const {
|
|
|
|
tax_codes = 0,
|
|
|
|
total_tax = 0,
|
|
|
|
order_tax = 0,
|
|
|
|
shipping_tax = 0,
|
|
|
|
orders_count = 0,
|
|
|
|
} = totals;
|
2018-11-19 15:55:15 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: _n( 'tax code', 'tax codes', tax_codes, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: numberFormat( tax_codes ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'total tax', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: formatCurrency( total_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'order tax', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: formatCurrency( order_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'shipping tax', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: formatCurrency( shipping_tax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: _n( 'order', 'orders', orders_count, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: numberFormat( orders_count ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-03-21 03:25:05 +00:00
|
|
|
const { isRequesting, query, filters } = this.props;
|
2018-11-19 15:55:15 +00:00
|
|
|
|
|
|
|
return (
|
2018-11-26 14:01:20 +00:00
|
|
|
<ReportTable
|
|
|
|
compareBy="taxes"
|
|
|
|
endpoint="taxes"
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
|
|
|
getSummary={ this.getSummary }
|
2019-02-26 09:28:50 +00:00
|
|
|
isRequesting={ isRequesting }
|
2018-11-26 14:01:20 +00:00
|
|
|
itemIdField="tax_rate_id"
|
2018-11-22 23:12:12 +00:00
|
|
|
query={ query }
|
2019-02-01 09:55:19 +00:00
|
|
|
searchBy="taxes"
|
2018-12-18 02:26:46 +00:00
|
|
|
tableQuery={ {
|
|
|
|
orderby: query.orderby || 'tax_rate_id',
|
|
|
|
} }
|
2019-03-13 17:14:02 +00:00
|
|
|
title={ __( 'Taxes', 'woocommerce-admin' ) }
|
2018-12-13 20:34:23 +00:00
|
|
|
columnPrefsKey="taxes_report_columns"
|
2019-03-21 03:25:05 +00:00
|
|
|
filters={ filters }
|
2018-11-19 15:55:15 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|