Skip to content

Commit

Permalink
Added function to calculate cost based on quantity
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Computroniks committed Aug 4, 2021
1 parent cdc4940 commit f994af1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Presenters/AccessoryPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/ComponentPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function dataTableLayout()
"sortable" => true,
"title" => trans('general.purchase_cost'),
"visible" => true,
"footerFormatter" => 'sumFormatter',
"footerFormatter" => 'sumFormatterQuantity',
],
];

Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/ConsumablePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/LicensePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions resources/views/partials/bootstrap-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(".");
Expand Down

0 comments on commit f994af1

Please sign in to comment.