Update for new Hallinta
[misc/hallinta-metro] / ordersatz_pos.php
index ace0584..0c9cbdd 100644 (file)
@@ -14,12 +14,28 @@ include_once($_SESSION['sys']['basedir'].'masks/metro/utils.php');
 include_once($_SESSION['sys']['basedir'].'lib/mail.php');
 
 if (substr($_SERVER["SCRIPT_FILENAME"],-10) == '/index.php' &&
-    !empty($_GET['id']))
+    !empty($_GET['id'])) {
   $_SESSION['ordersatz'] = $_GET['id'];
+  $done = is_done($_GET['id']);
+}
 
-$jscode[] = <<<EOC
-grid_column_edit[1] = {
-    default_menu: false,
+if (!$done) {
+  Actions::instance()->addLink(new Link(array('id' => 'btn_import',
+                                               'icon' => 'masks/metro/import.png',
+                                               'title' => 'Neue Artikel importieren',
+                                               'function' => 'import_articles')));
+  Actions::instance()->addLink(new Link(array('id' => 'btn_pdf',
+                                               'icon' => 'masks/metro/pdf_document.png',
+                                               'title' => 'PDF Vorschau',
+                                               'function' => 'build_pdf')));
+  Actions::instance()->addLink(new Link(array('id' => 'btn_finish',
+                                               'icon' => 'masks/metro/hp_folder_finished.png',
+                                               'title' => 'Ordersatz Abschließen und Versenden',
+                                               'function' => 'confirm_finish')));
+
+  $jscode = <<<EOC
+Hallinta.registerGridMenu('main', 1, {
+    defaultMenu: false,
     width: '9em',
     values: [
             ['löschen', '', 0],
@@ -35,21 +51,17 @@ grid_column_edit[1] = {
             ['12 mal bestellen', '12', 12],
             ['Wert eingeben', 'Bitte geben Sie die gewünschte Menge ein', 'prompt']
             ]
-};
+      });
 
 function build_pdf_callback(data)
 {
     info('PDF erstellt');
-    window.open('ajax/ajax.php?tmpdir='+data.tmpdir+'&source=metro__ordersatz_pos&func=file&name=download','_blank');
+    window.open('ajax/ajax.php?tmpdir='+data.tmpdir+'&source='+Hallinta.pageSource+'&func=file&name=download','_blank');
 }
 
 function build_pdf()
 {
-  var source = document.getElementById('source');
-  if (!source) return false;
-
-  var parms = 'source=' + source.innerHTML + '&callback=pdf';
-  ajax_request('function', parms, build_pdf_callback);
+  ajax_request('function', 'callback=pdf', build_pdf_callback);
   return false;
 }
 
@@ -63,50 +75,34 @@ function finish_callback(data)
   }
 }
 
-function finish()
+function confirm_finish()
 {
-  var source = document.getElementById('source');
-  if (!source) return false;
-
-  var parms = 'source=' + source.innerHTML + '&callback=send';
-  ajax_request('function', parms, finish_callback);
+  if (confirm("Bei Abschluß wird ein Fax zu Metro und eine Kopie per Mail an den Koch geschickt."))
+    ajax_request('function', 'callback=send', finish_callback);
   return false;
 }
 
-function import_callback(data)
+function import_articles_callback(data)
 {
   if (data.status == true) {
     info('Ordersatz aktualisiert');
 
     if (data.count > 0)
-      grid_update(grid);
+      grid_update(Hallinta.grid);
 
     confirm(data.count + ' Artikel zum Ordersatz hinzugefügt.');
   }
 }
 
-function import()
+function import_articles()
 {
-  var source = document.getElementById('source');
-  if (!source) return false;
-
-  var parms = 'source=' + source.innerHTML + '&callback=import';
-  ajax_request('function', parms, import_callback);
+  ajax_request('function', 'callback=import', import_articles_callback);
   return false;
 }
 
 EOC;
-
-$buttons = <<<EOC
-<p style="margin-top: 0px; margin-bottom: 4px; text-align: center;">
-<button onclick="return import()">Artikel importieren</button>
-&nbsp;
-<button onclick="return build_pdf()">PDF erstellen</button>
-&nbsp;
-<button onclick="return finish()">Abschließen</button>
-<br>Bei Abschluß wird ein Fax zu Metro und eine Kopie per Mail an den Koch geschickt.
-</p>
-EOC;
+  JavaScript::instance()->add($jscode);
+}
 
 function get_title($id)
 {
@@ -124,10 +120,10 @@ function get_title($id)
 $mask = array(
              'table' => 'metro_ordersatz',
              'join' => array('metro_ordersatz_pos ON ordersatz = metro_ordersatz.id',
-                             'metro_artikel ON artikel = metro_artikel.id'),
+                             'metro_artikel ON artikel = metro_artikel.id AND removed = 0'),
              'title' => get_title($_SESSION['ordersatz']),
              'edit_title' => 'Ordersatz',
-             'where' => sprintf('ordersatz = %d AND owner = %d AND done IS NULL', $_SESSION['ordersatz'], $_SESSION['sys']['uid']),
+             'where' => sprintf('ordersatz = %d AND owner = %d', $_SESSION['ordersatz'], $_SESSION['sys']['uid']),
              'list' => array(
                              'id' => array(
                                            'name' => 'ID',
@@ -137,66 +133,76 @@ $mask = array(
                              'anzahl' => array(
                                            'name' => 'Anzahl',
                                            'width' => 60,
-                                           'specs' => "ClassName: 'alignrightpad'",
+                                           'specs' => array('ClassName' => 'alignrightpad'),
                                            ),
                              'artnr' => array(
                                            'name' => 'Artnr',
                                            'width' => 60,
-                                           'specs' => "filterUI: 't'",
                                            'visible' => false,
                                            ),
                              'menge' => array(
                                            'name' => 'Menge',
                                            'width' => 60,
-                                           'specs' => "ClassName: 'alignrightpad', filterUI: 't'",
+                                           'filter' => 't2',
+                                           'specs' => array('ClassName' => 'alignrightpad'),
                                            ),
                              'bezeichnung' => array(
                                            'name' => 'Bezeichnung',
                                            'width' => 300,
-                                           'specs' => "filterUI: 't'",
+                                           'filter' => 't',
                                            ),
                              'preis' => array(
                                            'name' => 'Preis',
                                            'width' => 60,
                                            'type' => 'number',
-                                           'specs' => "decPlaces: 2, ClassName: 'alignrightpad'",
+                                           'specs' => array('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' => 80,
-                                           'specs' => "filterUI: 't'",
+                                           'filter' => 't4',
                                            ),
                              'vpe' => array(
                                            'name' => 'Einheit',
+                                           'sqltype' => 'int',
                                            'width' => 70,
-                                           'specs' => "ClassName: 'aligncenter', filterUI: 's'",
+                                           'filter' => 's',
+                                           'specs' => array('ClassName' => 'aligncenter'),
                                            'control' => "new Rico.TableColumn.lookup(".grid_lookup_sql('metro_vpe','id','name').", 0, '')",
+                                           'distinct' => "SELECT DISTINCT vpe,metro_vpe.name FROM metro_artikel JOIN metro_vpe ON vpe = metro_vpe.id ORDER BY name",
                                            ),
                              'abteilung' => array(
                                            'name' => 'Abteilung',
+                                           'sqltype' => 'int',
                                            'width' => 80,
-                                           'specs' => "ClassName: 'aligncenter', filterUI: 's'",
+                                           'filter' => 's',
+                                           'specs' => array('ClassName' => 'aligncenter'),
                                            'control' => "new Rico.TableColumn.lookup(".grid_lookup_sql('metro_abteilung','id','name').", 0, '')",
+                                           'distinct' => "SELECT DISTINCT abteilung,metro_abteilung.name FROM metro_artikel JOIN metro_abteilung ON abteilung = metro_abteilung.id ORDER BY name",
                                            'visible' => false,
                                            ),
                              'gang' => array(
                                            'name' => 'Gang',
+                                           'sqltype' => 'int',
                                            'width' => 50,
                                            'sql' => 'abteilung',
-                                           'specs' => "ClassName: 'aligncenter', filterUI: 's'",
+                                           'filter' => 's',
+                                           'specs' => array('ClassName' => 'aligncenter'),
                                            'control' => "new Rico.TableColumn.lookup(".grid_lookup_sql('metro_abteilung','id','gang').", 0, '')",
+                                           'distinct' => "SELECT DISTINCT abteilung,metro_abteilung.gang FROM metro_artikel JOIN metro_abteilung ON abteilung = metro_abteilung.id ORDER BY gang",
                                            'visible' => false,
                                            ),
                              ),
-             'edit' => array(
-                             'buttons' => array(
-                                           'type' => 'html',
-                                           'code' => $buttons,
-                                           'sql' => false,
-                                           ),
-                             ),
              'callbacks' => array(
                                   'cellsave' => cb_cellsave,
                                   'pdf' => cb_pdf,
@@ -214,6 +220,11 @@ $mask = array(
                                 ),
              );
 
+if ($done) {
+  unset($mask['edit']);
+  $mask['join'] = str_replace(' AND removed = 0','',$mask['join']);
+}
+
 function cb_cellsave()
 {
   global $db;
@@ -237,7 +248,8 @@ function cb_pdf()
   $result = ordersatz_write($_SESSION['ordersatz'], $tmpdir, false);
 
   if ($result !== true) {
-    rm_tempdir($tmpdir);
+    error_log($tmpdir);
+    error_log($result);
     return array('error' => $result);
   }