mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Licence cost calculation
Licences use diffrent key to track quantity. sumFormatterQuantity has been modified to detect which key to use. Signed-off-by: Computroniks <mnickson@sidingsmedia.com>
This commit is contained in:
parent
f994af16da
commit
8121d904e7
|
@ -608,19 +608,26 @@
|
||||||
|
|
||||||
function sumFormatterQuantity(data){
|
function sumFormatterQuantity(data){
|
||||||
if(Array.isArray(data)) {
|
if(Array.isArray(data)) {
|
||||||
// Check that we are actually trying to sum cost from a table
|
|
||||||
// that has a quantity column
|
// Prevents issues on page load where data is an empty array
|
||||||
if(data[0] == undefined){
|
if(data[0] == undefined){
|
||||||
return 0.00
|
return 0.00
|
||||||
}
|
}
|
||||||
if("qty" in data[0]) {
|
// 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) {
|
var total_sum = data.reduce(function(sum, row) {
|
||||||
return (sum) + (parseFloat(row["purchase_cost"])*row["qty"] || 0);
|
return (sum) + (parseFloat(row["purchase_cost"])*row[multiplier] || 0);
|
||||||
}, 0);
|
}, 0);
|
||||||
return numberWithCommas(total_sum.toFixed(2));
|
return numberWithCommas(total_sum.toFixed(2));
|
||||||
}
|
}
|
||||||
return 'no quantity';
|
|
||||||
}
|
|
||||||
return 'not an array';
|
return 'not an array';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue