mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Merge pull request #9902 from SidingsMedia/sum_cost_by_quantity
Fixed #5676: Sum cost by quantity
This commit is contained in:
commit
cae62fd4c7
|
@ -102,7 +102,7 @@ class AccessoryPresenter extends Presenter
|
||||||
'searchable' => true,
|
'searchable' => true,
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'title' => trans('general.purchase_cost'),
|
'title' => trans('general.purchase_cost'),
|
||||||
'footerFormatter' => 'sumFormatter',
|
'footerFormatter' => 'sumFormatterQuantity',
|
||||||
'class' => 'text-right',
|
'class' => 'text-right',
|
||||||
], [
|
], [
|
||||||
'field' => 'order_number',
|
'field' => 'order_number',
|
||||||
|
|
|
@ -101,7 +101,7 @@ class ComponentPresenter extends Presenter
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'title' => trans('general.purchase_cost'),
|
'title' => trans('general.purchase_cost'),
|
||||||
'visible' => true,
|
'visible' => true,
|
||||||
'footerFormatter' => 'sumFormatter',
|
'footerFormatter' => 'sumFormatterQuantity',
|
||||||
'class' => 'text-right',
|
'class' => 'text-right',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -113,7 +113,7 @@ class ConsumablePresenter extends Presenter
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'title' => trans('general.purchase_cost'),
|
'title' => trans('general.purchase_cost'),
|
||||||
'visible' => true,
|
'visible' => true,
|
||||||
'footerFormatter' => 'sumFormatter',
|
'footerFormatter' => 'sumFormatterQuantity',
|
||||||
'class' => 'text-right',
|
'class' => 'text-right',
|
||||||
], [
|
], [
|
||||||
'field' => 'change',
|
'field' => 'change',
|
||||||
|
|
|
@ -136,7 +136,7 @@ class LicensePresenter extends Presenter
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
'title' => trans('general.purchase_cost'),
|
'title' => trans('general.purchase_cost'),
|
||||||
'footerFormatter' => 'sumFormatter',
|
'footerFormatter' => 'sumFormatterQuantity',
|
||||||
'class' => 'text-right',
|
'class' => 'text-right',
|
||||||
], [
|
], [
|
||||||
'field' => 'purchase_order',
|
'field' => 'purchase_order',
|
||||||
|
|
|
@ -653,6 +653,31 @@
|
||||||
return 'not an array';
|
return 'not an array';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sumFormatterQuantity(data){
|
||||||
|
if(Array.isArray(data)) {
|
||||||
|
|
||||||
|
// Prevents issues on page load where data is an empty array
|
||||||
|
if(data[0] == undefined){
|
||||||
|
return 0.00
|
||||||
|
}
|
||||||
|
// Check that we are actually trying to sum cost from a table
|
||||||
|
// that has a quantity column. We must perform this check to
|
||||||
|
// support licences which use seats instead of qty
|
||||||
|
if('qty' in data[0]) {
|
||||||
|
var multiplier = 'qty';
|
||||||
|
} else if('seats' in data[0]) {
|
||||||
|
var multiplier = 'seats';
|
||||||
|
} else {
|
||||||
|
return 'no quantity';
|
||||||
|
}
|
||||||
|
var total_sum = data.reduce(function(sum, row) {
|
||||||
|
return (sum) + (cleanFloat(row["purchase_cost"])*row[multiplier] || 0);
|
||||||
|
}, 0);
|
||||||
|
return numberWithCommas(total_sum.toFixed(2));
|
||||||
|
}
|
||||||
|
return 'not an array';
|
||||||
|
}
|
||||||
|
|
||||||
function numberWithCommas(value) {
|
function numberWithCommas(value) {
|
||||||
if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){
|
if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){
|
||||||
var parts = value.toString().split(".");
|
var parts = value.toString().split(".");
|
||||||
|
|
Loading…
Reference in a new issue