Skip to content

Commit

Permalink
Licence cost calculation
Browse files Browse the repository at this point in the history
Licences use diffrent key to track quantity. sumFormatterQuantity has
been modified to detect which key to use.

Signed-off-by: Computroniks <mnickson@sidingsmedia.com>
  • Loading branch information
Computroniks committed Aug 4, 2021
1 parent f994af1 commit 8121d90
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions resources/views/partials/bootstrap-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,25 @@ function sumFormatter(data) {
function sumFormatterQuantity(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){
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));
// 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';
}
return 'no quantity';
var total_sum = data.reduce(function(sum, row) {
return (sum) + (parseFloat(row["purchase_cost"])*row[multiplier] || 0);
}, 0);
return numberWithCommas(total_sum.toFixed(2));
}
return 'not an array';
}
Expand Down

0 comments on commit 8121d90

Please sign in to comment.