From: anuko Date: Mon, 8 Jan 2018 14:58:18 +0000 (+0000) Subject: Fixed predefined expenses logic for comma as decimal mark. X-Git-Tag: timetracker_1.19-1~1390 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f270b1e143509303e32f65c3dda3fbecaee56c6b;p=timetracker.git Fixed predefined expenses logic for comma as decimal mark. --- diff --git a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php index 4c33c427..556bc42f 100644 --- a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php +++ b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php @@ -34,6 +34,7 @@ class ttPredefinedExpenseHelper { static function get($id) { global $user; + $replaceDecimalMark = ('.' != $user->decimal_mark); $mdb2 = getConnection(); @@ -42,8 +43,11 @@ class ttPredefinedExpenseHelper { $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); - if ($val && $val['id']) + if ($val && $val['id']) { + if ($replaceDecimalMark) + $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); return $val; + } } return false; } @@ -65,11 +69,15 @@ class ttPredefinedExpenseHelper { // insert function inserts a new predefined expense into database. static function insert($fields) { + global $user; + $mdb2 = getConnection(); $team_id = (int) $fields['team_id']; $name = $fields['name']; $cost = $fields['cost']; + if ('.' != $user->decimal_mark) + $cost = str_replace($user->decimal_mark, '.', $cost); $sql = "insert into tt_predefined_expenses (team_id, name, cost) values ($team_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")"; @@ -83,12 +91,16 @@ class ttPredefinedExpenseHelper { // update function - updates a predefined expense in database. static function update($fields) { + global $user; + $mdb2 = getConnection(); $predefined_expense_id = (int) $fields['id']; $team_id = (int) $fields['team_id']; $name = $fields['name']; $cost = $fields['cost']; + if ('.' != $user->decimal_mark) + $cost = str_replace($user->decimal_mark, '.', $cost); $sql = "update tt_predefined_expenses set name = ".$mdb2->quote($name).", cost = ".$mdb2->quote($cost). " where id = $predefined_expense_id and team_id = $team_id"; diff --git a/WEB-INF/lib/ttProjectHelper.class.php b/WEB-INF/lib/ttProjectHelper.class.php index 0a97de22..06605c76 100644 --- a/WEB-INF/lib/ttProjectHelper.class.php +++ b/WEB-INF/lib/ttProjectHelper.class.php @@ -77,9 +77,9 @@ class ttProjectHelper { // getProjects - returns an array of active and inactive projects in a team. static function getProjects() { - global $user; - - $result = array(); + global $user; + + $result = array(); $mdb2 = getConnection(); $sql = "select id, name, tasks from tt_projects diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index ba678fcb..6f716f58 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -500,6 +500,9 @@ class ttTeamHelper { // getPredefinedExpenses - obtains predefined expenses for team. static function getPredefinedExpenses($team_id) { + global $user; + $replaceDecimalMark = ('.' != $user->decimal_mark); + $mdb2 = getConnection(); $result = array(); @@ -508,6 +511,8 @@ class ttTeamHelper { $result = array(); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { + if ($replaceDecimalMark) + $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); $result[] = $val; } return $result; diff --git a/WEB-INF/templates/expense_edit.tpl b/WEB-INF/templates/expense_edit.tpl index 00b1ae53..bcd393a5 100644 --- a/WEB-INF/templates/expense_edit.tpl +++ b/WEB-INF/templates/expense_edit.tpl @@ -86,6 +86,7 @@ function recalculateCost() { var comment_control = document.getElementById("item_name"); var cost_control = document.getElementById("cost"); + var replaceDecimalMark = ("." != "{$user->decimal_mark}"); // Calculate cost. var dropdown = document.getElementById("predefined_expense"); @@ -98,8 +99,15 @@ function recalculateCost() { var quantity = quantity_control.value; if (isNaN(quantity)) cost_control.value = ""; - else - cost_control.value = (quantity_control.value * defined_expenses[dropdown.selectedIndex - 1][2]).toFixed(2); + else { + var expenseCost = defined_expenses[dropdown.selectedIndex - 1][2]; + if (replaceDecimalMark) + expenseCost = expenseCost.replace("{$user->decimal_mark}", "."); + var newCost = (quantity_control.value * expenseCost).toFixed(2); + if (replaceDecimalMark) + newCost = newCost.replace(".", "{$user->decimal_mark}"); + cost_control.value = newCost; + } } } diff --git a/WEB-INF/templates/expenses.tpl b/WEB-INF/templates/expenses.tpl index 85d27eae..8a3ae4c7 100644 --- a/WEB-INF/templates/expenses.tpl +++ b/WEB-INF/templates/expenses.tpl @@ -86,6 +86,7 @@ function recalculateCost() { var comment_control = document.getElementById("item_name"); var cost_control = document.getElementById("cost"); + var replaceDecimalMark = ("." != "{$user->decimal_mark}"); // Calculate cost. var dropdown = document.getElementById("predefined_expense"); @@ -98,8 +99,15 @@ function recalculateCost() { var quantity = quantity_control.value; if (isNaN(quantity)) cost_control.value = ""; - else - cost_control.value = (quantity_control.value * defined_expenses[dropdown.selectedIndex - 1][2]).toFixed(2); + else { + var expenseCost = defined_expenses[dropdown.selectedIndex - 1][2]; + if (replaceDecimalMark) + expenseCost = expenseCost.replace("{$user->decimal_mark}", "."); + var newCost = (quantity_control.value * expenseCost).toFixed(2); + if (replaceDecimalMark) + newCost = newCost.replace(".", "{$user->decimal_mark}"); + cost_control.value = newCost; + } } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 08f1afa9..b62eb7da 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.10.3730 | Copyright © Anuko | +  Anuko Time Tracker 1.13.11.3731 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve}