mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added function to calculate cost based on quantity
sumFormatterQuantity takes the same input as sumFormatter but instead of calculating the specified columns total it calculates the total purchase cost of an item based upon its quantity. Also updated affected pressenters to use this formatter. Signed-off-by: Computroniks <mnickson@sidingsmedia.com>
This commit is contained in:
parent
cdc4940338
commit
f994af16da
|
@ -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,
|
||||
|
|
|
@ -103,7 +103,7 @@ class ComponentPresenter extends Presenter
|
|||
"sortable" => true,
|
||||
"title" => trans('general.purchase_cost'),
|
||||
"visible" => true,
|
||||
"footerFormatter" => 'sumFormatter',
|
||||
"footerFormatter" => 'sumFormatterQuantity',
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(".");
|
||||
|
|
Loading…
Reference in a new issue