* Create Stock report

* Create Stock report page

* Display product name in Stock table

* Hide 'Parent' column in Stock table

* Add stock to endpoints map

* Remove dateRangeFilter.show from ReportFilters

* Fix stock status link

* Set the default order to 'stock_quanity'

* Add correct name to StockReport
This commit is contained in:
Albert Juhé Lluveras 2018-12-15 00:58:08 +01:00 committed by Timmy Crawford
parent f9533afdda
commit e4fb53b8f8
6 changed files with 221 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import RevenueReport from './revenue';
import CategoriesReport from './categories';
import CouponsReport from './coupons';
import TaxesReport from './taxes';
import StockReport from './stock';
import CustomersReport from './customers';
const REPORTS_FILTER = 'woocommerce-reports-list';
@ -60,6 +61,11 @@ const getReports = () => {
title: __( 'Taxes', 'wc-admin' ),
component: TaxesReport,
},
{
report: 'stock',
title: __( 'Stock', 'wc-admin' ),
component: StockReport,
},
{
report: 'customers',
title: __( 'Customers', 'wc-admin' ),

View File

@ -0,0 +1,22 @@
/** @format */
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
export const showDatePicker = false;
export const filters = [
{
label: __( 'Show', 'wc-admin' ),
staticParams: [],
param: 'type',
showFilters: () => true,
filters: [
{ label: __( 'All Products', 'wc-admin' ), value: 'all' },
{ label: __( 'Out of Stock', 'wc-admin' ), value: 'outofstock' },
{ label: __( 'Low Stock', 'wc-admin' ), value: 'lowstock' },
{ label: __( 'In Stock', 'wc-admin' ), value: 'instock' },
],
},
];

View File

@ -0,0 +1,39 @@
/** @format */
/**
* External dependencies
*/
import { Component, Fragment } from '@wordpress/element';
import PropTypes from 'prop-types';
/**
* WooCommerce dependencies
*/
import { ReportFilters } from '@woocommerce/components';
/**
* Internal dependencies
*/
import { showDatePicker, filters } from './config';
import StockReportTable from './table';
export default class StockReport extends Component {
render() {
const { query, path } = this.props;
return (
<Fragment>
<ReportFilters
query={ query }
path={ path }
showDatePicker={ showDatePicker }
filters={ filters }
/>
<StockReportTable query={ query } />
</Fragment>
);
}
}
StockReport.propTypes = {
query: PropTypes.object.isRequired,
};

View File

@ -0,0 +1,145 @@
/** @format */
/**
* External dependencies
*/
import { __, _n } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
/**
* WooCommerce dependencies
*/
import { Link } from '@woocommerce/components';
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import ReportTable from 'analytics/components/report-table';
import { numberFormat } from 'lib/number';
export default class StockReportTable extends Component {
constructor() {
super();
this.getHeadersContent = this.getHeadersContent.bind( this );
this.getRowsContent = this.getRowsContent.bind( this );
this.getSummary = this.getSummary.bind( this );
}
getHeadersContent() {
return [
{
label: __( 'Product / Variation', 'wc-admin' ),
key: 'product_variation',
required: true,
isLeftAligned: true,
},
{
label: __( 'SKU', 'wc-admin' ),
key: 'sku',
},
{
label: __( 'Status', 'wc-admin' ),
key: 'stock_status',
},
{
label: __( 'Stock', 'wc-admin' ),
key: 'stock_quantity',
isSortable: true,
defaultSort: true,
},
];
}
getRowsContent( products ) {
const { query } = this.props;
const persistedQuery = getPersistedQuery( query );
const { stockStatuses } = wcSettings;
return products.map( product => {
const { id, name, parent_id, sku, stock_quantity, stock_status } = product;
const productDetailLink = getNewPath( persistedQuery, 'products', {
filter: 'single_product',
products: parent_id || id,
} );
const formattedName = name.replace( ' - ', ' / ' );
const nameLink = (
<Link href={ productDetailLink } type="wc-admin">
{ formattedName }
</Link>
);
const stockStatusLink = (
<Link href={ 'post.php?action=edit&post=' + parent_id || id } type="wp-admin">
{ stockStatuses[ stock_status ] }
</Link>
);
return [
{
display: nameLink,
value: formattedName,
},
{
display: sku,
value: sku,
},
{
display: stockStatusLink,
value: stock_status,
},
{
display: numberFormat( stock_quantity ),
value: stock_quantity,
},
];
} );
}
getSummary( totals ) {
if ( ! totals ) {
return [];
}
return [
{
label: _n( 'product', 'products', totals.products, 'wc-admin' ),
value: numberFormat( totals.products ),
},
{
label: __( 'out of stock', totals.out_of_stock, 'wc-admin' ),
value: numberFormat( totals.out_of_stock ),
},
{
label: __( 'low stock', totals.low_stock, 'wc-admin' ),
value: numberFormat( totals.low_stock ),
},
{
label: __( 'in stock', totals.in_stock, 'wc-admin' ),
value: numberFormat( totals.in_stock ),
},
];
}
render() {
const { query } = this.props;
return (
<ReportTable
endpoint="stock"
getHeadersContent={ this.getHeadersContent }
getRowsContent={ this.getRowsContent }
// getSummary={ this.getSummary }
query={ query }
tableQuery={ {
orderby: query.orderby || 'stock_quantity',
order: query.order || 'desc',
type: query.type || 'all',
} }
title={ __( 'Stock', 'wc-admin' ) }
/>
);
}
}

View File

@ -28,6 +28,7 @@ const typeEndpointMap = {
'report-items-query-taxes': 'taxes',
'report-items-query-variations': 'variations',
'report-items-query-customers': 'customers',
'report-items-query-stock': 'stock',
};
function read( resourceNames, fetch = apiFetch ) {

View File

@ -133,6 +133,14 @@ function wc_admin_register_pages() {
)
);
wc_admin_register_page(
array(
'title' => __( 'Stock', 'wc-admin' ),
'parent' => '/analytics/revenue',
'path' => '/analytics/stock',
)
);
wc_admin_register_page(
array(
'title' => __( 'Customers', 'wc-admin' ),