X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=WEB-INF%2Ftemplates%2Fmobile%2Fexpenses.tpl;h=d8e8612dadafff9ba6ac60acc413c67f026ecdbb;hb=9d2d670570a584098a4e19c22d052412cdf18633;hp=a0fe73f9657a54c8d8c879f51dcb2e0105acf6f6;hpb=5519f0c3855c71a81442f3da1d135df89f1baf71;p=timetracker.git diff --git a/WEB-INF/templates/mobile/expenses.tpl b/WEB-INF/templates/mobile/expenses.tpl index a0fe73f9..d8e8612d 100644 --- a/WEB-INF/templates/mobile/expenses.tpl +++ b/WEB-INF/templates/mobile/expenses.tpl @@ -26,6 +26,14 @@ projects = new Array(); // Mandatory top option for project dropdown. empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}'; +// Prepare an array of predefined expenses. +idx = 0; +var defined_expenses = new Array(); +{foreach $predefined_expenses as $predefined_expense} + defined_expenses[idx] = new Array("{$predefined_expense.id}", "{$predefined_expense.name|escape:'javascript'}", "{$predefined_expense.cost}"); + idx++; +{/foreach} + // The fillProjectDropdown function populates the project combo box with // projects associated with a selected client (client id is passed here as id). function fillProjectDropdown(id) { @@ -66,6 +74,42 @@ function get_date() { var date = new Date(); return date.strftime("%Y-%m-%d"); } + +// The recalculateCost function recalculates cost based on the current selection +// of predefined expense and quantity and also changes the comment accordingly. +function recalculateCost() { + var quantity_control = document.getElementById("quantity"); + // Set quantity to 1 if it is not set already. + if (!quantity_control.value) { + quantity_control.value = "1"; + } + + 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"); + if (dropdown.selectedIndex == 0) { + quantity_control.value = ""; + comment_control.value = ""; + cost_control.value = ""; + } else { + comment_control.value = defined_expenses[dropdown.selectedIndex - 1][1] + " - " + quantity_control.value; + var quantity = quantity_control.value; + if (isNaN(quantity)) + cost_control.value = ""; + 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; + } + } +} @@ -99,6 +143,16 @@ function get_date() {
{$i18n.label.day_total}: {$user->currency|escape:'html'} {$day_total} | +{$i18n.label.day_total}: {$user->currency|escape} {$day_total} |