Skip to content

A free open source IT asset/license management system

Added function to calculate cost based on quantity

Computroniksf994af16dabb
diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php
index bf7074ad55..6295d5174f 100644
--- a/app/Presenters/AccessoryPresenter.php
+++ b/app/Presenters/AccessoryPresenter.php
@@ -102,7 +102,7 @@ class AccessoryPresenter extends Presenter
"searchable" => true,
"sortable" => true,
"title" => trans('general.purchase_cost'),
- "footerFormatter" => 'sumFormatter',
+ "footerFormatter" => 'sumFormatterQuantity',
], [
"field" => "order_number",
"searchable" => true,
diff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.php
index 669b5c651f..ae85a0720d 100644
--- a/app/Presenters/ComponentPresenter.php
+++ b/app/Presenters/ComponentPresenter.php
@@ -103,7 +103,7 @@ class ComponentPresenter extends Presenter
"sortable" => true,
"title" => trans('general.purchase_cost'),
"visible" => true,
- "footerFormatter" => 'sumFormatter',
+ "footerFormatter" => 'sumFormatterQuantity',
],
];
diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php
index 334398fabd..a7511098cb 100644
--- a/app/Presenters/ConsumablePresenter.php
+++ b/app/Presenters/ConsumablePresenter.php
@@ -116,7 +116,7 @@ class ConsumablePresenter extends Presenter
"sortable" => true,
"title" => trans('general.purchase_cost'),
"visible" => true,
- "footerFormatter" => 'sumFormatter',
+ "footerFormatter" => 'sumFormatterQuantity',
],[
"field" => "change",
"searchable" => false,
diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php
index be5a600c4f..9b79d7e790 100644
--- a/app/Presenters/LicensePresenter.php
+++ b/app/Presenters/LicensePresenter.php
@@ -137,7 +137,7 @@ class LicensePresenter extends Presenter
"sortable" => true,
"visible" => false,
"title" => trans('general.purchase_cost'),
- "footerFormatter" => 'sumFormatter',
+ "footerFormatter" => 'sumFormatterQuantity',
], [
"field" => "purchase_order",
"searchable" => true,
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index 13de846d39..2a319ef64e 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -606,6 +606,24 @@
return 'not an array';
}
+ function sumFormatterQuantity(data){
+ if(Array.isArray(data)) {
+ // Check that we are actually trying to sum cost from a table
+ // that has a quantity column
+ if(data[0] == undefined){
+ return 0.00
+ }
+ if("qty" in data[0]) {
+ var total_sum = data.reduce(function(sum, row) {
+ return (sum) + (parseFloat(row["purchase_cost"])*row["qty"] || 0);
+ }, 0);
+ return numberWithCommas(total_sum.toFixed(2));
+ }
+ return 'no quantity';
+ }
+ return 'not an array';
+ }
+
function numberWithCommas(value) {
if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){
var parts = value.toString().split(".");