2 // We need a few arrays to populate project dropdown.
3 // When client selection changes, the project dropdown must be re-populated with only relevant projects.
5 // project_ids[143] = "325,370,390,400"; // Comma-separated list of project ids for client.
6 // project_names[325] = "Time Tracker"; // Project name.
8 // Prepare an array of project ids for clients.
9 project_ids = new Array();
10 {foreach $client_list as $client}
11 project_ids[{$client.id}] = "{$client.projects}";
13 // Prepare an array of project names.
14 project_names = new Array();
15 {foreach $project_list as $project}
16 project_names[{$project.id}] = "{$project.name|escape:'javascript'}";
18 // We'll use this array to populate project dropdown when client is not selected.
20 projects = new Array();
21 {foreach $project_list as $project}
22 projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
26 // Mandatory top option for project dropdown.
27 empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}';
29 // Prepare an array of predefined expenses.
31 var defined_expenses = new Array();
32 {foreach $predefined_expenses as $predefined_expense}
33 defined_expenses[idx] = new Array("{$predefined_expense.id}", "{$predefined_expense.name|escape:'javascript'}", "{$predefined_expense.cost}");
37 // The fillProjectDropdown function populates the project combo box with
38 // projects associated with a selected client (client id is passed here as id).
39 function fillProjectDropdown(id) {
40 var str_ids = project_ids[id];
41 var dropdown = document.getElementById("project");
42 // Determine previously selected item.
43 var selected_item = dropdown.options[dropdown.selectedIndex].value;
45 // Remove existing content.
47 // Add mandatory top option.
48 dropdown.options[0] = new Option(empty_label_project, '', true);
50 // Populate project dropdown.
52 // If we are here, client is not selected.
53 var len = projects.length;
54 for (var i = 0; i < len; i++) {
55 dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
56 if (dropdown.options[i+1].value == selected_item)
57 dropdown.options[i+1].selected = true;
60 var ids = new Array();
61 ids = str_ids.split(",");
64 for (var i = 0; i < len; i++) {
66 dropdown.options[i+1] = new Option(project_names[p_id], p_id);
67 if (dropdown.options[i+1].value == selected_item)
68 dropdown.options[i+1].selected = true;
74 var date = new Date();
75 return date.strftime("%Y-%m-%d");
78 // The recalculateCost function recalculates cost based on the current selection
79 // of predefined expense and quantity and also changes the comment accordingly.
80 function recalculateCost() {
81 var quantity_control = document.getElementById("quantity");
82 // Set quantity to 1 if it is not set already.
83 if (!quantity_control.value) {
84 quantity_control.value = "1";
87 var comment_control = document.getElementById("item_name");
88 var cost_control = document.getElementById("cost");
89 var replaceDecimalMark = ("." != "{$user->getDecimalMark()}");
92 var dropdown = document.getElementById("predefined_expense");
93 if (dropdown.selectedIndex == 0) {
94 quantity_control.value = "";
95 comment_control.value = "";
96 cost_control.value = "";
98 comment_control.value = defined_expenses[dropdown.selectedIndex - 1][1] + " - " + quantity_control.value;
99 var quantity = quantity_control.value;
101 cost_control.value = "";
103 var expenseCost = defined_expenses[dropdown.selectedIndex - 1][2];
104 if (replaceDecimalMark)
105 expenseCost = expenseCost.replace("{$user->getDecimalMark()}", ".");
106 var newCost = (quantity_control.value * expenseCost).toFixed(2);
107 if (replaceDecimalMark)
108 newCost = newCost.replace(".", "{$user->getDecimalMark()}");
109 cost_control.value = newCost;
115 <!-- Inserted from time.tpl -->
116 <table cellspacing="3" cellpadding="0" border="0" width="100%">
118 <td class="sectionHeaderNoBorder" align="right"><a href="expenses.php?date={$prev_date}"><<</a></td>
119 <td class="sectionHeaderNoBorder" align="center">{$timestring}</td>
120 <td class="sectionHeaderNoBorder" align="left"><a href="expenses.php?date={$next_date}">>></a></td>
124 {$forms.expensesForm.open}
125 <table cellspacing="4" cellpadding="0" border="0">
131 <td align="right">{$i18n.label.user}:</td>
132 <td>{$forms.expensesForm.user.control}</td>
135 {if $user->isPluginEnabled('cl')}
137 <td align="right">{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:</td>
138 <td>{$forms.expensesForm.client.control}</td>
143 <td align="right">{$i18n.label.project} (*):</td>
144 <td>{$forms.expensesForm.project.control}</td>
147 {if $predefined_expenses}
149 <td align="right">{$i18n.label.expense}:</td>
150 <td>{$forms.expensesForm.predefined_expense.control}</td>
153 <td align="right">{$i18n.label.quantity}:</td>
154 <td>{$forms.expensesForm.quantity.control}</td>
158 <td align="right">{$i18n.label.item} (*):</td>
159 <td>{$forms.expensesForm.item_name.control}</td>
162 <td align="right">{$i18n.label.cost} (*):</td>
163 <td>{$forms.expensesForm.cost.control} {$user->getCurrency()|escape}</td>
170 <tr><td>{$forms.expensesForm.date.control}</td></tr>
179 <td align="center" colspan="2">{$forms.expensesForm.btn_submit.control}</td>
183 <table class="mobile-table">
187 <table class="mobile-table-details">
189 {if $user->isPluginEnabled('cl')}
190 <td width="20%" class="tableHeader">{$i18n.label.client}</td>
193 <td class="tableHeader">{$i18n.label.project}</td>
195 <td class="tableHeader">{$i18n.label.item}</td>
196 <td width="5%" class="tableHeaderCentered">{$i18n.label.cost}</td>
198 {foreach $expense_items as $item}
199 <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
200 {if $user->isPluginEnabled('cl')}
201 <td valign="top">{$item.client|escape}</td>
204 <td valign="top">{$item.project|escape}</td>
207 {if $item.approved || $item.invoice_id}
210 <a href="expense_edit.php?id={$item.id}">{$item.item|escape}</a>
213 <td valign="top" align="right">{$item.cost}</td>
217 <table border="0" cellpadding="3" cellspacing="1" width="100%">
219 <td nowrap align="right">{$i18n.label.day_total}: {$user->getCurrency()|escape} {$day_total}</td>
226 {$forms.expensesForm.close}