From 70e093333627d5340003d0ea816c7fa368af0b47 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 16 Jun 2021 23:52:00 +0200 Subject: [PATCH 1/4] total price column as per #1660 --- .../templates/order/purchase_order_detail.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index ef844409fd..fda45240dc 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -182,6 +182,20 @@ $("#po-table").inventreeTable({ return row.purchase_price_string || row.purchase_price; } }, + { + sortable: true, + title: '{% trans "Total price" %}', + formatter: function(value, row) { + var total = row.purchase_price * row.quantity; + + // Create our number formatter. + var formatter = new Intl.NumberFormat('en-US', { + style: 'currency', + currency: row.purchase_price_currency, + }); + return formatter.format(total) + }, + }, { sortable: true, field: 'received', From 2fc185bd7147abf1beff6924adb1c98008b830d1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 16 Jun 2021 23:57:33 +0200 Subject: [PATCH 2/4] show footer --- InvenTree/order/templates/order/purchase_order_detail.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index fda45240dc..155fb50eae 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -117,6 +117,7 @@ $("#po-table").inventreeTable({ part_detail: true, }, url: "{% url 'api-po-line-list' %}", + showFooter: true, columns: [ { field: 'pk', @@ -137,6 +138,9 @@ $("#po-table").inventreeTable({ return '-'; } }, + footerFormatter: function() { + return 'Total' + } }, { field: 'part_detail.description', From dac112d9081a0aacb69a61fa5fdbc6b33336d8ed Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 00:22:32 +0200 Subject: [PATCH 3/4] added footer total for price --- .../templates/order/purchase_order_detail.html | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 155fb50eae..acfce032e7 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -191,14 +191,20 @@ $("#po-table").inventreeTable({ title: '{% trans "Total price" %}', formatter: function(value, row) { var total = row.purchase_price * row.quantity; - - // Create our number formatter. - var formatter = new Intl.NumberFormat('en-US', { - style: 'currency', - currency: row.purchase_price_currency, - }); + var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: row.purchase_price_currency}); return formatter.format(total) }, + footerFormatter: function(data) { + var total = data.map(function (row) { + return +row['purchase_price']*row['quantity'] + }).reduce(function (sum, i) { + return sum + i + }, 0) + var currency = (data.slice(-1)[0] && data.slice(-1)[0].purchase_price_currency) || 'USD'; + var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: currency}); + return formatter.format(total) + } + }, { sortable: true, From 5d3360e63b2666f6dd8a4268b60354bef43ee6fa Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 00:23:08 +0200 Subject: [PATCH 4/4] added quantity total --- .../order/templates/order/purchase_order_detail.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index acfce032e7..08236fe773 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -176,7 +176,14 @@ $("#po-table").inventreeTable({ { sortable: true, field: 'quantity', - title: '{% trans "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, @@ -204,7 +211,6 @@ $("#po-table").inventreeTable({ var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: currency}); return formatter.format(total) } - }, { sortable: true,