2018-11-19 15:55:15 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2020-02-14 02:23:21 +00:00
|
|
|
import {
|
|
|
|
formatCurrency,
|
|
|
|
getCurrencyFormatDecimal,
|
|
|
|
renderCurrency,
|
|
|
|
} from 'lib/currency-format';
|
2019-11-13 03:22:06 +00:00
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2018-12-18 02:26:46 +00:00
|
|
|
import { getTaxCode } from './utils';
|
2019-11-21 21:51:52 +00:00
|
|
|
import { formatValue } from 'lib/number-format';
|
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 ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
return map( taxes, ( tax ) => {
|
2019-11-13 03:22:06 +00:00
|
|
|
const { query } = this.props;
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
order_tax: orderTax,
|
|
|
|
orders_count: ordersCount,
|
|
|
|
tax_rate: taxRate,
|
|
|
|
tax_rate_id: taxRateId,
|
|
|
|
total_tax: totalTax,
|
|
|
|
shipping_tax: shippingTax,
|
|
|
|
} = tax;
|
2019-03-15 20:44:03 +00:00
|
|
|
const taxCode = getTaxCode( tax );
|
2018-11-19 15:55:15 +00:00
|
|
|
|
2019-11-13 03:22:06 +00:00
|
|
|
const persistedQuery = getPersistedQuery( query );
|
2020-02-14 02:23:21 +00:00
|
|
|
const ordersTaxLink = getNewPath(
|
|
|
|
persistedQuery,
|
|
|
|
'/analytics/orders',
|
|
|
|
{
|
|
|
|
filter: 'advanced',
|
|
|
|
tax_rate_includes: taxRateId,
|
|
|
|
}
|
|
|
|
);
|
2018-11-19 15:55:15 +00:00
|
|
|
const taxLink = (
|
2019-11-13 03:22:06 +00:00
|
|
|
<Link href={ ordersTaxLink } 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
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: taxRate.toFixed( 2 ) + '%',
|
|
|
|
value: taxRate,
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: renderCurrency( totalTax ),
|
|
|
|
value: getCurrencyFormatDecimal( totalTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: renderCurrency( orderTax ),
|
|
|
|
value: getCurrencyFormatDecimal( orderTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: renderCurrency( shippingTax ),
|
|
|
|
value: getCurrencyFormatDecimal( shippingTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: formatValue( 'number', ordersCount ),
|
|
|
|
value: ordersCount,
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
getSummary( totals ) {
|
2019-02-05 12:00:37 +00:00
|
|
|
const {
|
2020-02-14 02:23:21 +00:00
|
|
|
tax_codes: taxesCodes = 0,
|
|
|
|
total_tax: totalTax = 0,
|
|
|
|
order_tax: orderTax = 0,
|
|
|
|
shipping_tax: shippingTax = 0,
|
|
|
|
orders_count: ordersCount = 0,
|
2019-02-05 12:00:37 +00:00
|
|
|
} = totals;
|
2018-11-19 15:55:15 +00:00
|
|
|
return [
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
label: _n(
|
|
|
|
'tax code',
|
|
|
|
'tax codes',
|
|
|
|
taxesCodes,
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
value: formatValue( 'number', taxesCodes ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'total tax', 'woocommerce-admin' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
value: formatCurrency( totalTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'order tax', 'woocommerce-admin' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
value: formatCurrency( orderTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'shipping tax', 'woocommerce-admin' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
value: formatCurrency( shippingTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
label: _n(
|
|
|
|
'order',
|
|
|
|
'orders',
|
|
|
|
ordersCount,
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
value: formatValue( 'number', ordersCount ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-08-27 19:33:31 +00:00
|
|
|
const { advancedFilters, filters, isRequesting, query } = 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 }
|
2019-08-27 19:33:31 +00:00
|
|
|
advancedFilters={ advancedFilters }
|
2018-11-19 15:55:15 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|