From ad98b13400fdc2fa2299a22c9bd54c4cd27960c3 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 23 Feb 2018 17:44:37 +0000 Subject: [PATCH] Fixed a problem with predefined expenses missing on mobile pages. --- WEB-INF/templates/expenses.tpl | 1 - WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/mobile/expense_edit.tpl | 54 +++++++++++++++++++++++ WEB-INF/templates/mobile/expenses.tpl | 54 +++++++++++++++++++++++ mobile/expense_edit.php | 14 ++++++ mobile/expenses.php | 14 ++++++ 6 files changed, 137 insertions(+), 2 deletions(-) diff --git a/WEB-INF/templates/expenses.tpl b/WEB-INF/templates/expenses.tpl index 8a3ae4c7..ed98bb57 100644 --- a/WEB-INF/templates/expenses.tpl +++ b/WEB-INF/templates/expenses.tpl @@ -136,7 +136,6 @@ function recalculateCost() { {/if} {if $predefined_expenses} - {$i18n.label.expense}: {$forms.expensesForm.predefined_expense.control} diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index e63b199c..571e5a40 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- +{/if} +{if $predefined_expenses} + + + + + + + + {/if} diff --git a/WEB-INF/templates/mobile/expenses.tpl b/WEB-INF/templates/mobile/expenses.tpl index a4a38478..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() { +{/if} +{if $predefined_expenses} + + + + + + + + {/if} diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index 69c13ecc..a4b1f2d0 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -119,6 +119,19 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); } } +// If predefined expenses are configured, add controls to select an expense and quantity. +$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->team_id); +if ($predefined_expenses) { + $form->addInput(array('type'=>'combobox', + 'onchange'=>'recalculateCost();', + 'name'=>'predefined_expense', + 'style'=>'width: 250px;', + 'value'=>$cl_predefined_expense, + 'data'=>$predefined_expenses, + 'datakeys'=>array('id', 'name'), + 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); + $form->addInput(array('type'=>'text','onchange'=>'recalculateCost();','maxlength'=>'40','name'=>'quantity','style'=>'width: 100px;','value'=>$cl_quantity)); +} $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'item_name','style'=>'width: 250px;','value'=>$cl_item_name)); $form->addInput(array('type'=>'text','maxlength'=>'40','name'=>'cost','style'=>'width: 100px;','value'=>$cl_cost)); $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','value'=>$cl_date)); @@ -198,6 +211,7 @@ if ($request->isPost()) { } } // isPost +$smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('task_list', $task_list); diff --git a/mobile/expenses.php b/mobile/expenses.php index dd8e87c0..82fe428f 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -131,6 +131,19 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); } } +// If predefined expenses are configured, add controls to select an expense and quantity. +$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->team_id); +if ($predefined_expenses) { + $form->addInput(array('type'=>'combobox', + 'onchange'=>'recalculateCost();', + 'name'=>'predefined_expense', + 'style'=>'width: 250px;', + 'value'=>$cl_predefined_expense, + 'data'=>$predefined_expenses, + 'datakeys'=>array('id', 'name'), + 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); + $form->addInput(array('type'=>'text','onchange'=>'recalculateCost();','maxlength'=>'40','name'=>'quantity','style'=>'width: 100px;','value'=>$cl_quantity)); +} $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'item_name','style'=>'width: 250px;','value'=>$cl_item_name)); $form->addInput(array('type'=>'text','maxlength'=>'40','name'=>'cost','style'=>'width: 100px;','value'=>$cl_cost)); $form->addInput(array('type'=>'calendar','name'=>'date','highlight'=>'expenses','value'=>$cl_date)); // calendar @@ -189,6 +202,7 @@ $smarty->assign('next_date', $next_date); $smarty->assign('prev_date', $prev_date); $smarty->assign('day_total', ttExpenseHelper::getTotalForDay($user->getActiveUser(), $cl_date)); $smarty->assign('expense_items', ttExpenseHelper::getItems($user->getActiveUser(), $cl_date)); +$smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('forms', array($form->getName()=>$form->toArray())); -- 2.20.1
 Anuko Time Tracker 1.17.30.4018 | Copyright © Anuko | +  Anuko Time Tracker 1.17.31.4019 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/expense_edit.tpl b/WEB-INF/templates/mobile/expense_edit.tpl index a9c09580..ea297238 100644 --- a/WEB-INF/templates/mobile/expense_edit.tpl +++ b/WEB-INF/templates/mobile/expense_edit.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; + } + } +} {$forms.expenseItemForm.open} @@ -87,6 +131,16 @@ function get_date() { {$i18n.label.project} (*): {$forms.expenseItemForm.project.control}
{$i18n.label.expense}:{$forms.expenseItemForm.predefined_expense.control}
{$i18n.label.quantity}:{$forms.expenseItemForm.quantity.control}
{$i18n.label.item}: {$i18n.label.project} (*): {$forms.expensesForm.project.control}
{$i18n.label.expense}:{$forms.expensesForm.predefined_expense.control}
{$i18n.label.quantity}:{$forms.expensesForm.quantity.control}
{$i18n.label.item} (*):