Update filter select elements after selecting a new year
[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('kostenstellen ON einsatz.kostenstelle = kostenstellen.id'),
43               'list' => array(
44                               'id' => array(
45                                             'name' => 'ID',
46                                             'sql' => 'einsatz.id',
47                                             'visible' => false,
48                                             ),
49                               'datum' => array(
50                                             'name' => 'Datum',
51                                             'type' => 'date',
52                                             'width' => 70,
53                                             ),
54                               'kostenstelle' => array(
55                                             'name' => 'Kostenstelle',
56                                             'width' => 230,
57                                             'sql' => 'kostenstellen.kostenstelle',
58                                             ),
59                               'material' => array(
60                                             'name' => 'Material',
61                                             'width' => 70,
62                                             'control' => "new Rico.TableColumn.checkbox('t','f','0',true)",
63                                             'sql' => '(SELECT count(*) > 0 FROM materialverbrauch WHERE einsatz = einsatz.id)',
64                                             'specs' => "ClassName: 'aligncenter', canSort: false",
65                                             ),
66                               ),
67               'rows' => 20,
68               'details' => array(
69                                  'html' => '<table id="materialverbrauch_table" cellspacing="0" style="margin-top: -13px;" border="0" width="100%">'.
70                                  '<thead>'.
71                                  '<tr bgcolor="#ffd76d" style="color: #444;"><th>Material</th><th>Menge</th></tr>'.
72                                  '</thead>'.
73                                  '<tbody id="detail_materialverbrauch_tbody"></tbody>'.
74                                  '</table>',
75                                  'list' => array(
76                                                  'materialverbrauch_tbody' => array(
77                                                                                     'fetch' => fetch_tbody,
78                                                                                     ),
79                                                  ),
80                                  ),
81               'edit_title' => 'Materialverbrauch vermerken',
82               'edit_table' => 'materialverbrauch',
83               'edit' => array(
84                               'einsatz' => array(
85                                             'name' => 'Einsatz',
86                                             'type' => 'hidden',
87                                             'size' => 10,
88                                             'sql' => 'id',
89                                             ),
90                               'material' => array(
91                                             'name' => 'Material',
92                                             'type' => 'select',
93                                             'options' => 'SELECT id,material AS text FROM materialien ORDER BY text',
94                                             'onchange' => 'select_material(this)',
95                                             'sql' => false,
96                                             ),
97                               'menge' => array(
98                                             'name' => 'Menge',
99                                             'type' => 'decimal',
100                                             'size' => 10,
101                                             'comment' => ' <span id="edit_einheit"></span>',
102                                             'sql' => false,
103                                             'required' => true,
104                                             ),
105                               ),
106               'buttons' => array(
107                                  'save' => false,
108                                  'delete' => false,
109                                  ),
110               'info' => array(
111                               'einheit' => array(
112                                             'sql' => 'SELECT einheiten.einheit FROM einheiten ' .
113                                                      'JOIN materialien ON materialien.einheit = einheiten.id ' .
114                                                      'WHERE materialien.id = {id}',
115                                             ),
116                                    ),
117               );
118
119 ?>