2018-12-14 23:58:08 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-05-08 14:25:46 +00:00
|
|
|
import { __, _n, _x } from '@wordpress/i18n';
|
2018-12-14 23:58:08 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2019-01-29 16:48:46 +00:00
|
|
|
import { numberFormat } from '@woocommerce/number';
|
2018-12-14 23:58:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
2019-05-08 14:25:46 +00:00
|
|
|
import { isLowStock } from './utils';
|
2018-12-14 23:58:08 +00:00
|
|
|
|
|
|
|
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 [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Product / Variation', 'woocommerce-admin' ),
|
2019-01-10 17:10:31 +00:00
|
|
|
key: 'title',
|
2018-12-14 23:58:08 +00:00
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
2019-01-10 17:10:31 +00:00
|
|
|
isSortable: true,
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'SKU', 'woocommerce-admin' ),
|
2018-12-14 23:58:08 +00:00
|
|
|
key: 'sku',
|
2019-01-10 17:10:31 +00:00
|
|
|
isSortable: true,
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Status', 'woocommerce-admin' ),
|
2018-12-14 23:58:08 +00:00
|
|
|
key: 'stock_status',
|
2019-01-21 17:11:20 +00:00
|
|
|
isSortable: true,
|
|
|
|
defaultSort: true,
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Stock', 'woocommerce-admin' ),
|
2018-12-14 23:58:08 +00:00
|
|
|
key: 'stock_quantity',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( products ) {
|
|
|
|
const { query } = this.props;
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
|
|
|
const { stockStatuses } = wcSettings;
|
|
|
|
|
|
|
|
return products.map( product => {
|
2019-05-08 14:25:46 +00:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
manage_stock,
|
|
|
|
name,
|
|
|
|
parent_id,
|
|
|
|
sku,
|
|
|
|
stock_quantity,
|
|
|
|
stock_status,
|
|
|
|
low_stock_amount,
|
|
|
|
} = product;
|
2018-12-14 23:58:08 +00:00
|
|
|
|
2019-03-19 01:27:31 +00:00
|
|
|
const productDetailLink = getNewPath( persistedQuery, '/analytics/products', {
|
2018-12-14 23:58:08 +00:00
|
|
|
filter: 'single_product',
|
|
|
|
products: parent_id || id,
|
|
|
|
} );
|
|
|
|
|
|
|
|
const nameLink = (
|
|
|
|
<Link href={ productDetailLink } type="wc-admin">
|
2019-02-18 18:24:48 +00:00
|
|
|
{ name }
|
2018-12-14 23:58:08 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
|
2019-05-08 14:25:46 +00:00
|
|
|
const stockStatusLink = isLowStock( stock_status, stock_quantity, low_stock_amount ) ? (
|
|
|
|
<Link href={ 'post.php?action=edit&post=' + ( parent_id || id ) } type="wp-admin">
|
|
|
|
{ _x( 'Low', 'Indication of a low quantity', 'woocommerce-admin' ) }
|
|
|
|
</Link>
|
|
|
|
) : (
|
2019-02-14 00:19:21 +00:00
|
|
|
<Link href={ 'post.php?action=edit&post=' + ( parent_id || id ) } type="wp-admin">
|
2018-12-14 23:58:08 +00:00
|
|
|
{ stockStatuses[ stock_status ] }
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: nameLink,
|
2019-02-18 18:24:48 +00:00
|
|
|
value: name,
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
display: sku,
|
|
|
|
value: sku,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: stockStatusLink,
|
|
|
|
value: stock_status,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
display: manage_stock ? numberFormat( stock_quantity ) : __( 'N/A', 'woocommerce-admin' ),
|
2018-12-14 23:58:08 +00:00
|
|
|
value: stock_quantity,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
getSummary( totals ) {
|
2019-02-14 03:31:27 +00:00
|
|
|
const { products = 0, outofstock = 0, lowstock = 0, instock = 0, onbackorder = 0 } = totals;
|
2018-12-14 23:58:08 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: _n( 'product', 'products', products, 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: numberFormat( products ),
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'out of stock', outofstock, 'woocommerce-admin' ),
|
2019-02-14 03:31:27 +00:00
|
|
|
value: numberFormat( outofstock ),
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'low stock', lowstock, 'woocommerce-admin' ),
|
2019-02-14 03:31:27 +00:00
|
|
|
value: numberFormat( lowstock ),
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'on backorder', onbackorder, 'woocommerce-admin' ),
|
2019-02-14 03:31:27 +00:00
|
|
|
value: numberFormat( onbackorder ),
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'in stock', instock, 'woocommerce-admin' ),
|
2019-02-14 03:31:27 +00:00
|
|
|
value: numberFormat( instock ),
|
2018-12-14 23:58:08 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-08-27 19:33:31 +00:00
|
|
|
const { advancedFilters, filters, query } = this.props;
|
2018-12-14 23:58:08 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ReportTable
|
|
|
|
endpoint="stock"
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
2019-02-14 03:31:27 +00:00
|
|
|
getSummary={ this.getSummary }
|
2018-12-14 23:58:08 +00:00
|
|
|
query={ query }
|
|
|
|
tableQuery={ {
|
2019-01-21 17:11:20 +00:00
|
|
|
orderby: query.orderby || 'stock_status',
|
|
|
|
order: query.order || 'asc',
|
2018-12-14 23:58:08 +00:00
|
|
|
type: query.type || 'all',
|
|
|
|
} }
|
2019-03-13 17:14:02 +00:00
|
|
|
title={ __( 'Stock', 'woocommerce-admin' ) }
|
2019-03-21 03:25:05 +00:00
|
|
|
filters={ filters }
|
2019-08-27 19:33:31 +00:00
|
|
|
advancedFilters={ advancedFilters }
|
2018-12-14 23:58:08 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|