From bbe7edbf827b2d78112ab57141e3e59a3f434d6b Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 00:50:10 +0200 Subject: [PATCH] totals like in #1666 --- .../templates/order/sales_order_detail.html | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index a90e61bff9..3bbd458da5 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -199,6 +199,7 @@ $("#so-lines-table").inventreeTable({ detailFormatter: showFulfilledSubTable, {% endif %} {% endif %} + showFooter: true, columns: [ { field: 'pk', @@ -217,7 +218,10 @@ $("#so-lines-table").inventreeTable({ } else { return '-'; } - } + }, + footerFormatter: function() { + return '{% trans "Total" %}' + }, }, { sortable: true, @@ -228,6 +232,13 @@ $("#so-lines-table").inventreeTable({ sortable: true, field: 'quantity', title: '{% trans "Quantity" %}', + footerFormatter: function(data) { + return data.map(function (row) { + return +row['quantity'] + }).reduce(function (sum, i) { + return sum + i + }, 0) + }, }, { sortable: true, @@ -237,6 +248,26 @@ $("#so-lines-table").inventreeTable({ return row.sale_price_string || row.sale_price; } }, + { + sortable: true, + title: '{% trans "Total price" %}', + formatter: function(value, row) { + var total = row.sale_price * row.quantity; + var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: row.sale_price_currency}); + return formatter.format(total) + }, + footerFormatter: function(data) { + var total = data.map(function (row) { + return +row['sale_price']*row['quantity'] + }).reduce(function (sum, i) { + return sum + i + }, 0) + var currency = (data.slice(-1)[0] && data.slice(-1)[0].sale_price_currency) || 'USD'; + var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: currency}); + return formatter.format(total) + } + }, + { field: 'allocated', {% if order.status == SalesOrderStatus.PENDING %}