Several improvements
[misc/hallinta-metro] / artikel.php
index 14766c4..1f4ed5e 100644 (file)
@@ -38,7 +38,10 @@ function price_popup_open()
 
        price_popup = new Rico.Popup(options, false, false);
        price_popup.createWindow('<strong>Verbinden</strong>',content,'auto','130px');
-    }
+
+       price_popup.openPopup(100,300);
+    } else
+       price_popup.openPopup();
 
     price_popup.titleDiv.childNodes[0].innerHTML = 'Preis hinzufügen';
 
@@ -46,7 +49,12 @@ function price_popup_open()
     var artikel = document.getElementById('form_artikel');
     artikel.value = form_id.value;
 
-    price_popup.openPopup(100,300);
+    var datum = document.getElementById('form_datum');
+    var preis = document.getElementById('form_preis');
+    if (datum.value.length)
+      preis.activate();
+    else
+      datum.activate();
 }
 
 function open_popup()
@@ -61,6 +69,7 @@ function open_popup()
 function add_price_callback(data)
 {
     info('Preis gespeichert');
+    grid_update(grid);
 }
 
 function add_price(obj)
@@ -136,7 +145,7 @@ $mask = array(
                                            'name' => 'netto',
                                            'width' => 60,
                                            'type' => 'number',
-                                           'specs' => "decPlaces: 2, ClassName: 'alignrightpad', filterUI: 't'",
+                                           'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
                                            'sql' => '(SELECT preis FROM metro_artikel_preis ' .
                                                     'WHERE artikel = metro_artikel.id ORDER BY datum DESC LIMIT 1)',
                                            ),
@@ -144,10 +153,18 @@ $mask = array(
                                            'name' => 'Preis',
                                            'width' => 60,
                                            'type' => 'number',
-                                           'specs' => "decPlaces: 2, ClassName: 'alignrightpad', filterUI: 't'",
+                                           'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
                                            'sql' => '(SELECT preis * ((100 + steuersatz)/100) FROM metro_artikel_preis ' .
                                                     'WHERE artikel = metro_artikel.id ORDER BY datum DESC LIMIT 1)',
                                            ),
+                             'datum' => array(
+                                           'name' => 'Datum',
+                                           'width' => 85,
+                                           'type' => 'text',
+                                           'sql' => '(SELECT datum FROM metro_artikel_preis ' .
+                                                    'WHERE artikel = metro_artikel.id ORDER BY datum DESC LIMIT 1)',
+                                           'visible' => false,
+                                           ),
                              'hersteller' => array(
                                            'name' => 'Hersteller',
                                            'width' => 100,
@@ -206,6 +223,12 @@ $mask = array(
                                            'size' => 21,
                                            'required' => true,
                                            ),
+                             'hinweis' => array(
+                                           'name' => 'Hinweis',
+                                           'type' => 'text',
+                                           'size' => 21,
+                                           'null' => true,
+                                           ),
                              'hersteller' => array(
                                            'name' => 'Hersteller',
                                            'type' => 'text',
@@ -218,6 +241,46 @@ $mask = array(
                                            'sql' => false,
                                            ),
                              ),
+             'second' => array(
+                               'title' => 'Preisverlauf',
+                               'rows' => 5,
+                               'table' => 'metro_artikel_preis',
+                               'where' => 'artikel = {id} ORDER BY datum DESC',
+                               'list' => array(
+                                               'id' => array(
+                                                             'name' => 'ID',
+                                                             'visible' => false,
+                                                             ),
+                                               'datum' => array(
+                                                             'name' => 'Datum',
+                                                             'width' => 180,
+                                                             ),
+                                               'steuersatz' => array(
+                                                             'name' => 'Steuer',
+                                                             'width' => 60,
+                                                             'type' => 'number',
+                                                             'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
+                                                             ),
+                                               'preis' => array(
+                                                             'name' => 'netto',
+                                                             'width' => 60,
+                                                             'type' => 'number',
+                                                             'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
+                                                             ),
+                                               'brutto' => array(
+                                                             'name' => 'Preis',
+                                                             'width' => 60,
+                                                             'type' => 'number',
+                                                             'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
+                                                             'sql' => 'preis * ((100 + steuersatz)/100)',
+                                                             ),
+                                               'empty' => array(
+                                                             'name' => '',
+                                                             'width' => 10,
+                                                             'sql' => "''",
+                                                             ),
+                                               ),
+                               ),
              'callbacks' => array(
                                   'price' => cb_price,
                                ),
@@ -231,6 +294,7 @@ function cb_price()
     return array('error' => 'Nicht ausreichend Daten übermittelt');
 
   $date = format_date($_POST['datum']);
+  $_POST['preis'] = str_replace(',','.',$_POST['preis']);
 
   $sql = sprintf("INSERT INTO metro_artikel_preis (artikel,preis,steuersatz,datum,sys_user,sys_edit) " .
                 "VALUES (%d,%.3f,%d,'%s',%s,now())",