woocommerce/plugins/woocommerce-admin/client/analytics/report/orders/utils.js

43 lines
805 B
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
/**
* WooCommerce dependencies
*/
import { getCurrencyFormatDecimal } from '@woocommerce/currency';
import { getOrderRefundTotal } from 'lib/order-values';
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,
net_revenue: getCurrencyFormatDecimal(
total - total_tax - shipping_total - discount_total + getOrderRefundTotal( order )
),
};
} );
}