diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index bf7074ad55e7..6295d5174f09 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -102,7 +102,7 @@ public static function dataTableLayout() "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 669b5c651ff5..ae85a0720d28 100644 --- a/app/Presenters/ComponentPresenter.php +++ b/app/Presenters/ComponentPresenter.php @@ -103,7 +103,7 @@ public static function dataTableLayout() "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 334398fabd74..a7511098cbc7 100644 --- a/app/Presenters/ConsumablePresenter.php +++ b/app/Presenters/ConsumablePresenter.php @@ -116,7 +116,7 @@ public static function dataTableLayout() "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 be5a600c4f50..9b79d7e790f9 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -137,7 +137,7 @@ public static function dataTableLayout() "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 13de846d3918..2a319ef64e51 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -606,6 +606,24 @@ function sumFormatter(data) { 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(".");