c739695d66f5aa2cfde159e0adc494fc1423f756
[misc/kostenrechnung] / masks / overview_stunden.php
1 <?php
2
3 include_once($_SESSION['sys']['basedir'].'/lib/overview_utils.php');
4
5 if (empty($_SESSION['overview_stunden.year'])) $_SESSION['overview_stunden.year'] = 0;
6
7 $details = <<<EOC
8 <div style="padding-left: 3px; margin-top: -10px;">
9 <b>Gebiet</b>: <span id="detail_gebiet"></span><br>
10 <b>Länge</b>: <span id="detail_laenge"></span><br>
11 <b>Gesamtstunden</b>: <span id="detail_gewaesserstunden"></span><br>
12 <b>Personalstunden</b>: <span id="detail_personalstunden"></span><br>
13 <b>Gerätestunden</b>: <span id="detail_geraetestunden"></span>
14 </div>
15 EOC;
16
17 $mask = array(
18               'table' => 'einsatz',
19               'title' => 'Stundenübersicht nach Kostenstellen',
20               'join' => array(
21                               'arbeitsarten ON einsatz.arbeiten = arbeitsarten.id',
22                               'einsatzpersonal ON einsatzpersonal.einsatz = einsatz.id',
23                               'einsatzgeraete ON einsatzgeraete.einsatz = einsatz.id',
24                               'gebiet ON einsatz.gebiet = gebiet.id',
25                               'kostenstellen ON einsatz.kostenstelle = kostenstellen.id',
26                               'personal ON einsatzpersonal.personal = personal.id',
27                               'gerate ON einsatzgeraete.geraet = gerate.id',
28                               'anbaugeraete ON einsatzgeraete.anbaugeraet = anbaugeraete.id',
29                               ),
30               'where' => "arbeitsarten.arbeitsart <> 'Urlaub' AND arbeitsarten.arbeitsart <> 'Krank' AND arbeitsarten.arbeitsart <> 'Sonstige Fehltage'"
31                        . " AND date_part('year', datum) = " . $_SESSION['overview_stunden.year'],
32               'select' => array(
33                                 'title' => 'Auswahl',
34                                 'options' => discover_years(),
35                                 'default' => 'Jahr wählen',
36                                 'selected' => $_SESSION['overview_stunden.year'],
37                                 'onchange' => "setvar(this,'year',select_year_calback,select_year_status)",
38                                 ),
39               'variables' => array(
40                                    'year' => array(),
41                                    ),
42               'list' => array(
43                               'id' => array(
44                                             'name' => 'ID',
45                                             'visible' => false,
46                                             'width' => 60,
47                                             'sql' => 'einsatz.id',
48                                             ),
49                               'datum' => array(
50                                             'name' => 'Datum',
51                                             'type' => 'date',
52                                             'width' => 70,
53                                             ),
54                               'gebiet' => array(
55                                             'name' => 'Gebiet',
56                                             'sql' => "gebiet.gebiet",
57                                             'width' => 150,
58                                             'specs' => "filterUI: 's'",
59                                             ),
60                               'kostenstelle' => array(
61                                             'name' => 'Kostenstelle',
62                                             'sql' => "kostenstellen.kostenstelle",
63                                             'width' => 150,
64                                             'specs' => "filterUI: 's'",
65                                             ),
66                               'arbeitsarten' => array(
67                                             'name' => 'Arbeiten',
68                                             'sql' => "arbeitsarten.arbeitsart",
69                                             'width' => 150,
70                                             'specs' => "filterUI: 's'",
71                                             ),
72                               'personal' => array(
73                                             'name' => 'Mitarbeiter',
74                                             'sql' => "personal.vorname || ' ' || personal.name",
75                                             'width' => 150,
76                                             'specs' => "filterUI: 's'",
77                                             ),
78                               'stunden' => array(
79                                             'name' => 'Mitarbeiterstunden',
80                                             'type' => 'number',
81                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
82                                             'width' => 60,
83                                             'sql' => 'einsatzpersonal.stunden'
84                                             ),
85                               'geraet' => array(
86                                             'name' => 'Gerät',
87                                             'sql' => "gerate.geraet",
88                                             'width' => 150,
89                                             'specs' => "filterUI: 's'",
90                                             ),
91                               'anbaugeraet' => array(
92                                             'name' => 'Anbaugerät',
93                                             'sql' => "anbaugeraete.anbaugeraet",
94                                             'width' => 150,
95                                             'specs' => "filterUI: 's'",
96                                             ),
97                               'geraetstunden' => array(
98                                             'name' => 'Gerätstunden',
99                                             'type' => 'number',
100                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
101                                             'width' => 60,
102                                             'sql' => 'einsatzgeraete.stunden'
103                                             ),
104                               'gesamtstunden' => array(
105                                             'name' => 'Gesamtstunden',
106                                             'type' => 'number',
107                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
108                                             'width' => 60,
109                                             'sql' => 'einsatzpersonal.stunden + einsatzgeraete.stunden',
110                                             ),
111                               'stdlfdm' => array(
112                                             'name' => 'Stunden pro lfdm',
113                                             'type' => 'number',
114                                             'specs' => "decPlaces: 2, ClassName: 'alignright', suffix: '&nbsp;', canSort: false",
115                                             'width' => 60,
116                                             'sql' => '(einsatzpersonal.stunden + einsatzgeraete.stunden) / laenge',
117                                             ),
118                               ),
119               'details' => array(
120                                  'html' => $details,
121                                  'list' => array(
122                                                  'gebiet' => array('fetch' => fetch_gebiet),
123                                                  'laenge' => array('fetch' => fetch_laenge),
124                                                  'gewaesserstunden' => array('fetch' => fetch_gewaesserstunden),
125                                                  'personalstunden' => array('fetch' => fetch_personalstunden),
126                                                  'geraetestunden' => array('fetch' => fetch_geraetestunden),
127                                                  ),
128
129                               ),
130               );
131
132 function fetch_gebiet()
133 {
134   $sql = 'SELECT gebiet.gebiet FROM gebiet JOIN einsatz ON einsatz.gebiet = gebiet.id WHERE einsatz.id = ' . intval($_POST['id']);
135   $res = query_db($sql);
136   if ($res === false) return '';
137
138   return $res[0]['gebiet'];
139 }
140
141 function fetch_laenge()
142 {
143   $sql = 'SELECT laenge FROM kostenstellen JOIN einsatz ON einsatz.kostenstelle = kostenstellen.id WHERE einsatz.id = ' . intval($_POST['id']);
144   $res = query_db($sql);
145   if ($res === false) return '';
146
147   return $res[0]['laenge'] . ' m';
148 }
149
150 function fetch_gewaesserstunden()
151 {
152   $sql = <<<EOC
153   SELECT sum(einsatzpersonal.stunden +
154              einsatzgeraete.stunden) AS gesamt
155   FROM einsatz
156   JOIN einsatzpersonal ON einsatzpersonal.einsatz = einsatz.id
157   JOIN einsatzgeraete ON einsatzgeraete.einsatz = einsatz.id
158   WHERE einsatz.id = %d
159 EOC;
160
161   $sql = sprintf($sql, $_POST['id']);
162   $res = query_db($sql);
163   if ($res === false) return '';
164
165   return sprintf('%.2f', $res[0]['gesamt']);
166 }
167
168 function fetch_personalstunden()
169 {
170   $sql = <<<EOC
171   SELECT sum(einsatzpersonal.stunden) AS kosten
172   FROM einsatz
173   JOIN einsatzpersonal ON einsatzpersonal.einsatz = einsatz.id
174   WHERE einsatz.id = %d
175 EOC;
176
177   $sql = sprintf($sql, $_POST['id']);
178   $res = query_db($sql);
179   if ($res === false) return '';
180
181   return sprintf('%.2f', $res[0]['kosten']);
182 }
183
184 function fetch_geraetestunden()
185 {
186   $sql = <<<EOC
187   SELECT sum(einsatzgeraete.stunden) AS gesamt
188   FROM einsatz
189   JOIN einsatzgeraete ON einsatzgeraete.einsatz = einsatz.id
190   WHERE einsatz.id = %d
191 EOC;
192
193   $sql = sprintf($sql, $_POST['id']);
194   $res = query_db($sql);
195   if ($res === false) return '';
196
197   return sprintf('%.2f', $res[0]['gesamt']);
198 }
199
200 ?>