c5079bfd69eea7b8a00917fda045bf7bd737fc1b
[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               'details' => array(
68                                  'html' => '<table id="materialverbrauch_table" cellspacing="0" style="margin-top: -13px;" border="0" width="100%">'.
69                                  '<thead>'.
70                                  '<tr bgcolor="#ffd76d" style="color: #444;"><th>Material</th><th>Menge</th></tr>'.
71                                  '</thead>'.
72                                  '<tbody id="detail_materialverbrauch_tbody"></tbody>'.
73                                  '</table>',
74                                  'list' => array(
75                                                  'materialverbrauch_tbody' => array(
76                                                                                     'fetch' => fetch_tbody,
77                                                                                     ),
78                                                  ),
79                                  ),
80               'edit_title' => 'Materialverbrauch vermerken',
81               'edit_table' => 'materialverbrauch',
82               'edit' => array(
83                               'einsatz' => array(
84                                             'name' => 'Einsatz',
85                                             'type' => 'hidden',
86                                             'size' => 10,
87                                             'sql' => 'id',
88                                             ),
89                               'material' => array(
90                                             'name' => 'Material',
91                                             'type' => 'select',
92                                             'options' => 'SELECT id,material AS text FROM materialien ORDER BY text',
93                                             'onchange' => 'select_material(this)',
94                                             'sql' => false,
95                                             ),
96                               'menge' => array(
97                                             'name' => 'Menge',
98                                             'type' => 'decimal',
99                                             'size' => 10,
100                                             'comment' => ' <span id="edit_einheit"></span>',
101                                             'sql' => false,
102                                             'required' => true,
103                                             ),
104                               ),
105               'buttons' => array(
106                                  'save' => false,
107                                  'delete' => false,
108                                  ),
109               'info' => array(
110                               'einheit' => array(
111                                             'sql' => 'SELECT einheiten.einheit FROM einheiten ' .
112                                                      'JOIN materialien ON materialien.einheit = einheiten.id ' .
113                                                      'WHERE materialien.id = {id}',
114                                             ),
115                                    ),
116               );
117
118 ?>