2018-12-03 03:40:57 +00:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
return orders.map( ( order ) => {
|
2018-12-03 03:40:57 +00:00
|
|
|
const {
|
2020-02-14 02:23:21 +00:00
|
|
|
date_created: date,
|
2018-12-03 03:40:57 +00:00
|
|
|
id,
|
|
|
|
status,
|
2020-02-14 02:23:21 +00:00
|
|
|
customer_id: customerId,
|
|
|
|
line_items: lineItems,
|
|
|
|
coupon_lines: couponLines,
|
2018-12-03 03:40:57 +00:00
|
|
|
currency,
|
|
|
|
total,
|
2020-02-14 02:23:21 +00:00
|
|
|
total_tax: totalTax,
|
|
|
|
shipping_total: shippingTotal,
|
|
|
|
discount_total: discountTotal,
|
2018-12-03 03:40:57 +00:00
|
|
|
} = order;
|
|
|
|
|
|
|
|
return {
|
2020-02-14 02:23:21 +00:00
|
|
|
date,
|
2018-12-03 03:40:57 +00:00
|
|
|
id,
|
|
|
|
status,
|
2020-02-14 02:23:21 +00:00
|
|
|
customer_id: customerId,
|
|
|
|
line_items: lineItems,
|
|
|
|
items_sold: lineItems.reduce(
|
|
|
|
( acc, item ) => item.quantity + acc,
|
|
|
|
0
|
|
|
|
),
|
|
|
|
coupon_lines: couponLines,
|
2018-12-03 03:40:57 +00:00
|
|
|
currency,
|
2018-12-05 02:06:00 +00:00
|
|
|
net_revenue: getCurrencyFormatDecimal(
|
2020-02-14 02:23:21 +00:00
|
|
|
total -
|
|
|
|
totalTax -
|
|
|
|
shippingTotal -
|
|
|
|
discountTotal +
|
|
|
|
getOrderRefundTotal( order )
|
2018-12-05 02:06:00 +00:00
|
|
|
),
|
2018-12-03 03:40:57 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
}
|