2018-12-03 03:40:57 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-11-21 21:51:52 +00:00
|
|
|
import { getCurrencyFormatDecimal } from 'lib/currency-format';
|
2018-12-05 02:06:00 +00:00
|
|
|
import { getOrderRefundTotal } from 'lib/order-values';
|
2018-12-03 03:40:57 +00:00
|
|
|
|
|
|
|
export function formatTableOrders( orders ) {
|
|
|
|
return orders.map( order => {
|
|
|
|
const {
|
|
|
|
date_created,
|
|
|
|
id,
|
|
|
|
status,
|
|
|
|
customer_id,
|
|
|
|
line_items,
|
|
|
|
coupon_lines,
|
|
|
|
currency,
|
|
|
|
total,
|
|
|
|
total_tax,
|
|
|
|
shipping_total,
|
|
|
|
discount_total,
|
|
|
|
} = order;
|
|
|
|
|
|
|
|
return {
|
|
|
|
date: date_created,
|
|
|
|
id,
|
|
|
|
status,
|
|
|
|
customer_id,
|
|
|
|
line_items,
|
|
|
|
items_sold: line_items.reduce( ( acc, item ) => item.quantity + acc, 0 ),
|
|
|
|
coupon_lines,
|
|
|
|
currency,
|
2018-12-05 02:06:00 +00:00
|
|
|
net_revenue: getCurrencyFormatDecimal(
|
|
|
|
total - total_tax - shipping_total - discount_total + getOrderRefundTotal( order )
|
|
|
|
),
|
2018-12-03 03:40:57 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
}
|