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';
|
|
|
|
import { Link } from '@woocommerce/components';
|
2019-11-13 03:22:06 +00:00
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2020-04-02 21:54:38 +00:00
|
|
|
import { formatValue } from '@woocommerce/number';
|
2023-02-28 16:55:49 +00:00
|
|
|
import { CurrencyContext } from '@woocommerce/currency';
|
2018-11-19 15:55:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getTaxCode } from './utils';
|
|
|
|
import ReportTable from '../../components/report-table';
|
2020-04-02 21:54:38 +00:00
|
|
|
class TaxesReportTable extends Component {
|
2018-11-26 14:01:20 +00:00
|
|
|
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 [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Tax code', 'woocommerce' ),
|
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,
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Rate', 'woocommerce' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'rate',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Total tax', 'woocommerce' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'total_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Order tax', 'woocommerce' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'order_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Shipping tax', 'woocommerce' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'shipping_tax',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Orders', 'woocommerce' ),
|
2018-11-19 15:55:15 +00:00
|
|
|
key: 'orders_count',
|
|
|
|
required: true,
|
|
|
|
defaultSort: true,
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( taxes ) {
|
2020-04-02 21:54:38 +00:00
|
|
|
const {
|
|
|
|
render: renderCurrency,
|
|
|
|
formatDecimal: getCurrencyFormatDecimal,
|
2020-06-17 23:33:40 +00:00
|
|
|
getCurrencyConfig,
|
2020-04-02 21:54:38 +00:00
|
|
|
} = this.context;
|
|
|
|
|
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-04-02 21:54:38 +00:00
|
|
|
display: formatValue(
|
2020-06-17 23:33:40 +00:00
|
|
|
getCurrencyConfig(),
|
2020-04-02 21:54:38 +00:00
|
|
|
'number',
|
|
|
|
ordersCount
|
|
|
|
),
|
2020-02-14 02:23:21 +00:00
|
|
|
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;
|
2020-06-17 23:33:40 +00:00
|
|
|
const { formatAmount, getCurrencyConfig } = this.context;
|
|
|
|
const currency = getCurrencyConfig();
|
2018-11-19 15:55:15 +00:00
|
|
|
return [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: _n( 'tax code', 'tax codes', taxesCodes, 'woocommerce' ),
|
2020-04-02 21:54:38 +00:00
|
|
|
value: formatValue( currency, 'number', taxesCodes ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'total tax', 'woocommerce' ),
|
2020-06-17 23:33:40 +00:00
|
|
|
value: formatAmount( totalTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'order tax', 'woocommerce' ),
|
2020-06-17 23:33:40 +00:00
|
|
|
value: formatAmount( orderTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'shipping tax', 'woocommerce' ),
|
2020-06-17 23:33:40 +00:00
|
|
|
value: formatAmount( shippingTax ),
|
2018-11-19 15:55:15 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: _n( 'order', 'orders', ordersCount, 'woocommerce' ),
|
2020-04-02 21:54:38 +00:00
|
|
|
value: formatValue( currency, '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 }
|
2020-03-31 15:08:40 +00:00
|
|
|
summaryFields={ [
|
|
|
|
'tax_codes',
|
|
|
|
'total_tax',
|
|
|
|
'order_tax',
|
|
|
|
'shipping_tax',
|
|
|
|
'orders_count',
|
|
|
|
] }
|
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',
|
|
|
|
} }
|
2022-03-30 09:00:04 +00:00
|
|
|
title={ __( 'Taxes', 'woocommerce' ) }
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 21:54:38 +00:00
|
|
|
|
|
|
|
TaxesReportTable.contextType = CurrencyContext;
|
|
|
|
|
|
|
|
export default TaxesReportTable;
|