Initial repo created
[timetracker.git] / WEB-INF / templates / expenses.tpl
1 <script>
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.
4 // Format:
5 // project_ids[143] = "325,370,390,400";  // Comma-separated list of project ids for client.
6 // project_names[325] = "Time Tracker";   // Project name.
7
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}";
12 {/foreach}
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'}";
17 {/foreach}
18 // We'll use this array to populate project dropdown when client is not selected.
19 var idx = 0;
20 projects = new Array();
21 {foreach $project_list as $project}
22   projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
23   idx++;
24 {/foreach}
25
26 // Mandatory top option for project dropdown.
27 empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}';
28
29 // The fillProjectDropdown function populates the project combo box with
30 // projects associated with a selected client (client id is passed here as id).    
31 function fillProjectDropdown(id) {
32   var str_ids = project_ids[id];
33   var dropdown = document.getElementById("project");
34   // Determine previously selected item.
35   var selected_item = dropdown.options[dropdown.selectedIndex].value;
36
37   // Remove existing content.
38   dropdown.length = 0;
39   // Add mandatory top option.
40   dropdown.options[0] = new Option(empty_label_project, '', true);
41
42   // Populate project dropdown.
43   if (!id) {
44     // If we are here, client is not selected.
45         var len = projects.length;
46     for (var i = 0; i < len; i++) {
47       dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
48       if (dropdown.options[i+1].value == selected_item)
49         dropdown.options[i+1].selected = true;
50     }
51   } else if (str_ids) {
52     var ids = new Array();
53     ids = str_ids.split(",");
54     var len = ids.length;
55
56     for (var i = 0; i < len; i++) {
57       var p_id = ids[i];
58       dropdown.options[i+1] = new Option(project_names[p_id], p_id);
59       if (dropdown.options[i+1].value == selected_item)
60         dropdown.options[i+1].selected = true;
61     }
62   }
63 }
64
65 function get_date() {
66   var date = new Date();
67   return date.strftime("%Y-%m-%d");
68 }
69 </script>
70
71 {$forms.expensesForm.open}
72 <table cellspacing="4" cellpadding="0" border="0">
73   <tr>
74     <td valign="top">
75       <table>
76 {if $on_behalf_control}
77         <tr>
78           <td align="right">{$i18n.label.user}:</td>
79           <td>{$forms.expensesForm.onBehalfUser.control}</td>
80         </tr>
81 {/if}
82 {if in_array('cl', explode(',', $user->plugins))}
83         <tr>
84           <td align="right">{$i18n.label.client}{if in_array('cm', explode(',', $user->plugins))} (*){/if}:</td>
85           <td>{$forms.expensesForm.client.control}</td>
86         </tr>
87 {/if}
88 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
89         <tr>
90           <td align="right">{$i18n.label.project} (*):</td>
91           <td>{$forms.expensesForm.project.control}</td>
92         </tr>
93 {/if}
94         <tr>
95           <td align="right">{$i18n.label.item} (*):</td>
96           <td>{$forms.expensesForm.item_name.control}</td>
97         </tr>
98         <tr>
99           <td align="right">{$i18n.label.cost} (*):</td>
100           <td>{$forms.expensesForm.cost.control} {$user->currency|escape:'html'}</td>
101         </tr>
102       </table>
103     </td>
104     <td valign="top">
105       <table>
106         <tr><td>{$forms.expensesForm.date.control}</td></tr>
107       </table>
108     </td>
109   </tr>
110 </table>
111
112 <table>
113   <tr>
114     <td align="center" colspan="2">{$forms.expensesForm.btn_submit.control}</td>
115   </tr>
116 </table>
117
118 <table width="720">
119 <tr>
120   <td valign="top">
121     {if $expense_items}
122       <table border="0" cellpadding="3" cellspacing="1" width="100%">
123       <tr>
124 {if in_array('cl', explode(',', $user->plugins))}
125         <td width="20%" class="tableHeader">{$i18n.label.client}</td>
126 {/if}
127 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
128         <td class="tableHeader">{$i18n.label.project}</td>
129 {/if}
130         <td class="tableHeader">{$i18n.label.item}</td>
131         <td width="5%" class="tableHeaderCentered">{$i18n.label.cost}</td>
132         <td width="5%" class="tableHeader">{$i18n.label.edit}</td>
133       </tr>
134       {foreach $expense_items as $item}
135       <tr bgcolor="{cycle values="#f5f5f5,#ccccce"}">
136 {if in_array('cl', explode(',', $user->plugins))}
137         <td valign='top'>{$item.client|escape:'html'}</td>
138 {/if}
139 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
140         <td valign='top'>{$item.project|escape:'html'}</td>
141 {/if}
142         <td valign='top'>{$item.item|escape:'html'}</td>
143         <td valign='top' align='right'>{$item.cost}</td>
144         <td valign='top' align='center'>
145         {if $item.invoice_id}
146           &nbsp;
147         {else}
148           <a href='expense_edit.php?id={$item.id}'>{$i18n.label.edit}</a>
149         {/if}
150         </td>
151       </tr>
152       {/foreach}
153           </table>
154           {if $expense_items}
155       <table border="0" cellpadding="3" cellspacing="1" width="100%">
156         <tr>
157           <td nowrap align="right">{$i18n.label.day_total}: {$user->currency|escape:'html'} {$day_total}</td>
158         </tr>
159       </table>
160       {/if}
161           
162     {/if}
163   </td>
164 </tr>
165 </table>
166 {$forms.expensesForm.close}
167
168