Display gebiet
[misc/kostenrechnung] / masks / materialverbrauch.php
1 <?php
2
3 $jscode[] = <<<EOC
4
5 function einheit_callback(data)
6 {
7   var einheit = document.getElementById('edit_einheit');
8
9   if (!einheit) return false;
10
11   if (data.info[0].einheit.length)
12     einheit.innerHTML = data.info[0].einheit;
13 }
14
15 function select_material(obj)
16 {
17   get_info('einheit', {id: obj.options[obj.selectedIndex].value}, einheit_callback);
18 }
19
20 EOC;
21
22 function fetch_tbody()
23 {
24   $sql = 'SELECT materialien.material,menge,einheiten.einheit FROM materialverbrauch '
25     . 'JOIN materialien ON materialverbrauch.material = materialien.id '
26     . 'JOIN einheiten ON materialien.einheit = einheiten.id '
27     . 'WHERE einsatz = ' . intval($_POST['id']);
28
29   $data = query_db($sql);
30
31   $ret = '';
32   foreach ($data as $row)
33     $ret .= sprintf('<tr><td>%s</td><td align="right">%.2f %s</td></tr>',
34                     $row['material'], $row['menge'], $row['einheit']);
35
36   return $ret;
37 }
38
39 $mask = array(
40               'table' => 'einsatz',
41               'title' => 'Materialverbrauch zu Arbeitsberichten',
42               'join' => array(
43                               'kostenstellen ON einsatz.kostenstelle = kostenstellen.id',
44                               'gebiet ON kostenstellen.gebiet = gebiet.id',
45                               ),
46               'list' => array(
47                               'id' => array(
48                                             'name' => 'ID',
49                                             'sql' => 'einsatz.id',
50                                             'width' => 60,
51                                             'visible' => false,
52                                             ),
53                               'datum' => array(
54                                             'name' => 'Datum',
55                                             'type' => 'date',
56                                             'width' => 70,
57                                             ),
58                               'gebiet' => array(
59                                             'name' => 'Gebiet',
60                                             'width' => 230,
61                                             'sql' => 'gebiet.gebiet',
62                                             ),
63                               'kostenstelle' => array(
64                                             'name' => 'Kostenstelle',
65                                             'width' => 230,
66                                             'sql' => 'kostenstellen.kostenstelle',
67                                             ),
68                               'material' => array(
69                                             'name' => 'Material',
70                                             'width' => 70,
71                                             'control' => "new Rico.TableColumn.checkbox('t','f','0',true)",
72                                             'sql' => '(SELECT count(*) > 0 FROM materialverbrauch WHERE einsatz = einsatz.id)',
73                                             'specs' => "ClassName: 'aligncenter', canSort: false",
74                                             ),
75                               ),
76               'details' => array(
77                                  'html' => '<table id="materialverbrauch_table" cellspacing="0" style="margin-top: -13px;" border="0" width="100%">'.
78                                  '<thead>'.
79                                  '<tr bgcolor="#ffd76d" style="color: #444;"><th>Material</th><th>Menge</th></tr>'.
80                                  '</thead>'.
81                                  '<tbody id="detail_materialverbrauch_tbody"></tbody>'.
82                                  '</table>',
83                                  'list' => array(
84                                                  'materialverbrauch_tbody' => array(
85                                                                                     'fetch' => fetch_tbody,
86                                                                                     ),
87                                                  ),
88                                  ),
89               'edit_title' => 'Materialverbrauch vermerken',
90               'edit_table' => 'materialverbrauch',
91               'edit' => array(
92                               'einsatz' => array(
93                                             'name' => 'Einsatz',
94                                             'type' => 'hidden',
95                                             'size' => 10,
96                                             'sql' => 'id',
97                                             ),
98                               'material' => array(
99                                             'name' => 'Material',
100                                             'type' => 'select',
101                                             'options' => 'SELECT id,material AS text FROM materialien ORDER BY text',
102                                             'onchange' => 'select_material(this)',
103                                             'sql' => false,
104                                             ),
105                               'menge' => array(
106                                             'name' => 'Menge',
107                                             'type' => 'decimal',
108                                             'size' => 10,
109                                             'comment' => ' <span id="edit_einheit"></span>',
110                                             'sql' => false,
111                                             'required' => true,
112                                             ),
113                               ),
114               'buttons' => array(
115                                  'save' => false,
116                                  'delete' => false,
117                                  ),
118               'info' => array(
119                               'einheit' => array(
120                                             'sql' => 'SELECT einheiten.einheit FROM einheiten ' .
121                                                      'JOIN materialien ON materialien.einheit = einheiten.id ' .
122                                                      'WHERE materialien.id = {id}',
123                                             ),
124                                    ),
125               );
126
127 ?>