Alter anbaugraet according to the selected geraet
[misc/kostenrechnung] / masks / arbeitsberichte.php
1 <?php
2
3 $jscode[] = <<<EOC
4
5 function select_gebiet_callback(data)
6 {
7     var obj = document.getElementById('edit_kostenstelle');
8     if (!obj) return;
9
10     obj.options.length = 0;
11
12     for (var i=0; i < data.info.length; i++)
13       obj.options[i] = new Option(data.info[i].kostenstelle,data.info[i].id,false,false);
14 }
15
16 function select_group(obj)
17 {
18   setvar(obj,'gebiet',false,false);
19
20   get_info('kostenstellen', {gebiet: obj.options[obj.selectedIndex].value}, select_gebiet_callback);
21 }
22
23 function select_geraet_callback(data)
24 {
25     var obj = document.getElementById('edit_anbaugeraet');
26     if (!obj) return;
27
28     obj.options.length = 0;
29
30     for (var i=0; i < data.info.length; i++)
31       obj.options[i] = new Option(data.info[i].anbaugeraet,data.info[i].id,false,false);
32 }
33
34 function select_geraet(obj)
35 {
36   setvar(obj,'geraet',false,false);
37
38   get_info('anbaugeraete', {geraet: obj.options[obj.selectedIndex].value}, select_geraet_callback);
39 }
40 EOC;
41
42 function first_gebiet()
43 {
44   $sql = "SELECT id FROM gebiet ORDER BY gebiet LIMIT 1";
45
46   $sth = pg_query($sql);
47
48   if ($sth === false) return 0;
49
50   if ($row = pg_fetch_assoc($sth))
51     return $row['id'];
52
53   return 0;
54 }
55
56 if (empty($_SESSION['arbeitsberichte.gebiet'])) $_SESSION['arbeitsberichte.gebiet'] = first_gebiet();
57 if (empty($_SESSION['arbeitsberichte.geraet'])) $_SESSION['arbeitsberichte.geraet'] = 0;
58
59 $mask = array(
60               'table' => 'einsatz',
61               'title' => 'Arbeitsberichte',
62               'subtitle' => 'Eingabe und Übersicht',
63               'join' => array('personal ON einsatz.personal = personal.id',
64                               'gebiet ON einsatz.gebiet = gebiet.id',
65                               'gerate ON einsatz.geraet = gerate.id',
66                               'anbaugeraete ON einsatz.anbaugeraet = anbaugeraete.id',
67                               'arbeitsarten ON einsatz.arbeiten = arbeitsarten.id',
68                               'kostenstellen ON einsatz.kostenstelle = kostenstellen.id',
69                               ),
70               'where' => "arbeitsarten.arbeitsart <> 'Urlaub' AND arbeitsarten.arbeitsart <> 'Krank' AND arbeitsarten.arbeitsart <> 'Sonstige Fehltage'",
71               'variables' => array(
72                                    'gebiet' => array(),
73                                    'geraet' => array(),
74                                    ),
75               'list' => array(
76                               'id' => array(
77                                             'name' => 'ID',
78                                             'visible' => false,
79                                             'sql' => 'einsatz.id',
80                                             ),
81                               'datum' => array(
82                                             'name' => 'Datum',
83                                             'type' => 'date',
84                                             'width' => 70,
85                                             ),
86                               'kostenstelle' => array(
87                                             'name' => 'Gewässer',
88                                             'sql' => "kostenstellen.kostenstelle",
89                                             'width' => 200,
90                                             'specs' => "filterUI: 's'",
91                                             ),
92                               'gebiet' => array(
93                                             'name' => 'Gebiet',
94                                             'sql' => "gebiet.gebiet",
95                                             'width' => 150,
96                                             'specs' => "filterUI: 's'",
97                                             'visible' => false,
98                                             ),
99                               'name' => array(
100                                             'name' => 'Personal',
101                                             'sql' => "personal.vorname || ' ' || personal.name",
102                                             'width' => 150,
103                                             'specs' => "filterUI: 's'",
104                                             'visible' => false,
105                                             ),
106                               'geraet' => array(
107                                             'name' => 'Gerät',
108                                             'sql' => 'gerate.geraet',
109                                             'width' => 150,
110                                             'specs' => "filterUI: 's'",
111                                             ),
112                               'anbaugeraet' => array(
113                                             'name' => 'Anbaugerät',
114                                             'sql' => 'anbaugeraete.anbaugeraet',
115                                             'width' => 150,
116                                             'specs' => "filterUI: 's'",
117                                             ),
118                               'stunden' => array(
119                                             'name' => 'Stunden',
120                                             'type' => 'number',
121                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
122                                             'width' => 60,
123                                             'visible' => false,
124                                             ),
125                               'geraetstunden' => array(
126                                             'name' => 'Gerätstunden',
127                                             'type' => 'number',
128                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
129                                             'width' => 60,
130                                             'visible' => false,
131                                             ),
132                               ),
133               'edit' => array(
134                               'datum' => array(
135                                             'name' => 'Datum',
136                                             'type' => 'date',
137                                             ),
138                               'hhjahreinsatz' => array(
139                                             'name' => 'Haushaltsjahr',
140                                             'type' => 'select',
141                                             'options' => "SELECT id,hhjahr AS text FROM einstellungen ORDER BY text",
142                                             ),
143                               'personal' => array(
144                                             'name' => 'Mitarbeiter',
145                                             'type' => 'select',
146                                             'options' => "SELECT id,vorname || ' ' || name AS text FROM personal ORDER BY text",
147                                             ),
148                               'gebiet' => array(
149                                             'name' => 'Gebiet',
150                                             'type' => 'select',
151                                             'options' => "SELECT id,gebiet AS text FROM gebiet ORDER BY text",
152                                             'selected' => $_SESSION['arbeitsberichte.gebiet'],
153                                             'onchange' => 'select_group(this)',
154                                             ),
155                               'kostenstelle' => array(
156                                             'name' => 'Gewässer',
157                                             'type' => 'select',
158                                             'options' => "SELECT id,kostenstelle AS text FROM kostenstellen WHERE gebiet = " .
159                                                          intval($_SESSION['arbeitsberichte.gebiet']) .
160                                                          " ORDER BY text",
161                                             ),
162                               'geraet' => array(
163                                             'name' => 'Gerät',
164                                             'type' => 'select',
165                                             'options' => "SELECT id,geraet AS text FROM gerate ORDER BY text",
166                                             'selected' => $_SESSION['arbeitsberichte.geraet'],
167                                             'onchange' => 'select_geraet(this)',
168                                             ),
169                               'anbaugeraet' => array(
170                                             'name' => 'Anbaugerät',
171                                             'type' => 'select',
172                                             'options' => "SELECT anbaugeraete.id,anbaugeraet AS text FROM anbaugeraete " . 
173                                                          "JOIN gerate ON anbaugeraete.geraetetyp = gerate.geraetetyp " .
174                                                          "WHERE gerate.id = " . intval($_SESSION['arbeitsberichte.geraet']) . " " .
175                                                          "ORDER BY text",
176                                             ),
177                               'arbeiten' => array(
178                                             'name' => 'Arbeitsart',
179                                             'type' => 'select',
180                                             'options' => "SELECT id,arbeitsart AS text FROM arbeitsarten ORDER BY text",
181                                             ),
182                               'stunden' => array(
183                                             'name' => 'Stunden',
184                                             'type' => 'decimal',
185                                             'size' => 5,
186                                             ),
187                               'geraetstunden' => array(
188                                             'name' => 'Gerätstunden',
189                                             'type' => 'decimal',
190                                             'size' => 5,
191                                             ),
192                               'ordnung' => array(
193                                             'name' => 'Gewässerordnung',
194                                             'type' => 'select',
195                                             'options' => "SELECT id,name AS text FROM ordnungen ORDER BY text",
196                                             ),
197                               'akkord' => array(
198                                             'name' => 'Akkord',
199                                             'type' => 'boolean',
200                                             ),
201                               'bemerkung' => array(
202                                             'name' => 'Bemerkung',
203                                             'type' => 'textarea',
204                                             ),
205                               ),
206               'info' => array(
207                               'kostenstellen' => array(
208                                             'sql' => 'SELECT id,kostenstelle FROM kostenstellen WHERE gebiet = {gebiet}',
209                                             ),
210                               'anbaugeraete' => array(
211                                             'sql' => 'SELECT anbaugeraete.id,anbaugeraet FROM anbaugeraete ' .
212                                                      'JOIN gerate ON anbaugeraete.geraetetyp = gerate.geraetetyp ' .
213                                                      'WHERE gerate.id = {geraet}',
214                                             ),
215                                    ),
216               );
217
218 ?>