2019-01-31 01:04:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2022-02-21 02:34:25 +00:00
|
|
|
import interpolateComponents from '@automattic/interpolate-components';
|
2019-01-31 01:04:11 +00:00
|
|
|
|
2019-03-22 08:48:20 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-05-22 21:43:04 +00:00
|
|
|
import DefaultDate from './default-date';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting, ORDER_STATUSES } from '~/utils/admin-settings';
|
2019-03-22 08:48:20 +00:00
|
|
|
|
2019-01-31 01:04:11 +00:00
|
|
|
const SETTINGS_FILTER = 'woocommerce_admin_analytics_settings';
|
2020-03-25 03:20:17 +00:00
|
|
|
export const DEFAULT_ACTIONABLE_STATUSES = [ 'processing', 'on-hold' ];
|
|
|
|
export const DEFAULT_ORDER_STATUSES = [
|
2019-01-31 01:04:11 +00:00
|
|
|
'completed',
|
|
|
|
'processing',
|
|
|
|
'refunded',
|
|
|
|
'cancelled',
|
|
|
|
'failed',
|
|
|
|
'pending',
|
|
|
|
'on-hold',
|
|
|
|
];
|
2020-03-25 03:20:17 +00:00
|
|
|
export const DEFAULT_DATE_RANGE = 'period=month&compare=previous_year';
|
2019-07-05 14:12:03 +00:00
|
|
|
|
2020-03-25 03:20:17 +00:00
|
|
|
const filteredOrderStatuses = Object.keys( ORDER_STATUSES )
|
2020-04-10 14:42:03 +00:00
|
|
|
.filter( ( status ) => status !== 'refunded' )
|
|
|
|
.map( ( key ) => {
|
2019-01-31 01:04:11 +00:00
|
|
|
return {
|
|
|
|
value: key,
|
2019-09-23 21:47:08 +00:00
|
|
|
label: ORDER_STATUSES[ key ],
|
2019-01-31 01:04:11 +00:00
|
|
|
description: sprintf(
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Exclude the %s status from reports', 'woocommerce' ),
|
2019-09-23 21:47:08 +00:00
|
|
|
ORDER_STATUSES[ key ]
|
2019-01-31 01:04:11 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2022-01-06 12:53:30 +00:00
|
|
|
const unregisteredOrderStatuses = getAdminSetting(
|
|
|
|
'unregisteredOrderStatuses',
|
|
|
|
{}
|
|
|
|
);
|
2020-04-10 14:42:03 +00:00
|
|
|
|
|
|
|
const orderStatusOptions = [
|
|
|
|
{
|
|
|
|
key: 'defaultStatuses',
|
|
|
|
options: filteredOrderStatuses.filter( ( status ) =>
|
|
|
|
DEFAULT_ORDER_STATUSES.includes( status.value )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'customStatuses',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Custom Statuses', 'woocommerce' ),
|
2020-04-10 14:42:03 +00:00
|
|
|
options: filteredOrderStatuses.filter(
|
|
|
|
( status ) => ! DEFAULT_ORDER_STATUSES.includes( status.value )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'unregisteredStatuses',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Unregistered Statuses', 'woocommerce' ),
|
2020-04-10 14:42:03 +00:00
|
|
|
options: Object.keys( unregisteredOrderStatuses ).map( ( key ) => {
|
|
|
|
return {
|
|
|
|
value: key,
|
|
|
|
label: key,
|
|
|
|
description: sprintf(
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Exclude the %s status from reports', 'woocommerce' ),
|
2020-04-10 14:42:03 +00:00
|
|
|
key
|
|
|
|
),
|
|
|
|
};
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Filter Analytics Report settings. Add a UI element to the Analytics Settings page.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_analytics_settings
|
|
|
|
* @param {Object} reportSettings Report settings.
|
|
|
|
*/
|
2020-03-25 03:20:17 +00:00
|
|
|
export const config = applyFilters( SETTINGS_FILTER, {
|
|
|
|
woocommerce_excluded_report_order_statuses: {
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Excluded statuses:', 'woocommerce' ),
|
2019-01-31 01:04:11 +00:00
|
|
|
inputType: 'checkboxGroup',
|
2020-04-10 14:42:03 +00:00
|
|
|
options: orderStatusOptions,
|
2019-01-31 01:04:11 +00:00
|
|
|
helpText: interpolateComponents( {
|
|
|
|
mixedString: __(
|
|
|
|
'Orders with these statuses are excluded from the totals in your reports. ' +
|
2019-07-02 19:42:29 +00:00
|
|
|
'The {{strong}}Refunded{{/strong}} status can not be excluded.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-01-31 01:04:11 +00:00
|
|
|
),
|
|
|
|
components: {
|
|
|
|
strong: <strong />,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
defaultValue: [ 'pending', 'cancelled', 'failed' ],
|
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
woocommerce_actionable_order_statuses: {
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Actionable statuses:', 'woocommerce' ),
|
2019-03-06 05:14:38 +00:00
|
|
|
inputType: 'checkboxGroup',
|
2020-04-10 14:42:03 +00:00
|
|
|
options: orderStatusOptions,
|
2019-03-06 05:14:38 +00:00
|
|
|
helpText: __(
|
2020-11-06 01:21:05 +00:00
|
|
|
'Orders with these statuses require action on behalf of the store admin. ' +
|
|
|
|
'These orders will show up in the Home Screen - Orders task.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-03-06 05:14:38 +00:00
|
|
|
),
|
2019-03-22 08:48:20 +00:00
|
|
|
defaultValue: DEFAULT_ACTIONABLE_STATUSES,
|
2019-03-06 05:14:38 +00:00
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
woocommerce_default_date_range: {
|
2019-05-22 21:43:04 +00:00
|
|
|
name: 'woocommerce_default_date_range',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Default date range:', 'woocommerce' ),
|
2019-05-22 21:43:04 +00:00
|
|
|
inputType: 'component',
|
|
|
|
component: DefaultDate,
|
|
|
|
helpText: __(
|
|
|
|
'Select a default date range. When no range is selected, reports will be viewed by ' +
|
|
|
|
'the default date range.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-05-22 21:43:04 +00:00
|
|
|
),
|
2019-09-23 21:47:08 +00:00
|
|
|
defaultValue: DEFAULT_DATE_RANGE,
|
2019-05-22 21:43:04 +00:00
|
|
|
},
|
2023-02-17 13:29:36 +00:00
|
|
|
woocommerce_date_type: {
|
|
|
|
name: 'woocommerce_date_type',
|
|
|
|
label: __( 'Date type:', 'woocommerce' ),
|
|
|
|
inputType: 'select',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: __( 'Date created', 'woocommerce' ),
|
|
|
|
value: 'date_created',
|
|
|
|
key: 'date_created',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Date paid', 'woocommerce' ),
|
|
|
|
value: 'date_paid',
|
|
|
|
key: 'date_paid',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Date completed', 'woocommerce' ),
|
|
|
|
value: 'date_completed',
|
|
|
|
key: 'date_completed',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
helpText: __(
|
|
|
|
'Database date field considered for Revenue and Orders reports',
|
|
|
|
'woocommerce'
|
|
|
|
),
|
|
|
|
defaultValue: 'date_created',
|
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
} );
|