file('lib/rico3/minsrc/ricoLiveGridControls.js'); JavaScript::instance()->add("Hallinta.closeDialogAfterInsert = false;"); JavaScript::instance()->add("Hallinta.postFetch = function(data){\$('#edit_artnr').select();};"); Styles::instance()->add(" div#form_price { padding-left: 10px; padding-right: 10px; font-size: 90%; color: #555; }"); $form = '

 



'; $jscode = << 0) { var text = "Diese Artikelnummer ist bereits " + data.count + " mal vorhanden.\\nSoll der Artikel trotzdem gespeichert werden?"; if (confirm(text)) form_save(custom_this); } else { form_save(custom_this); } } function custom_save(obj) { custom_this = obj; var id = document.getElementById('edit_id'); if (!id.value.length) return custom_insert(obj); var artnr = document.getElementById('edit_artnr'); if (artnr.value == 0) return form_save(custom_this); var parms = 'callback=artnr'; parms += '&artnr=' + artnr.value; parms += '&artikel=' + id.value; ajax_request('function', parms, custom_save_callback); return false; } function custom_insert_callback(data) { if (data.count > 0) { var text = "Diese Artikelnummer ist bereits " + data.count + " mal vorhanden.\\nSoll der Artikel trotzdem hinzugefügt werden?"; if (confirm(text)) form_insert(custom_this); } else { form_insert(custom_this); } } function custom_insert(obj) { custom_this = obj; var artnr = document.getElementById('edit_artnr'); if (artnr.value == 0) return form_insert(custom_this); var parms = 'callback=artnr'; parms += '&artnr=' + artnr.value; ajax_request('function', parms, custom_insert_callback); return false; } var price_popup = false; function price_popup_open() { if (!price_popup) { var options = { hideOnClick: false, canDragFunc: true }; var content = 'CONTENT_FORM'; price_popup = new Rico.Window('Preis hinzufügen', options); price_popup.contentDiv.innerHTML = content; price_popup.centerPopup(); } else price_popup.openPopup(); var form_id = document.getElementById('edit_id'); var artikel = document.getElementById('form_artikel'); artikel.value = form_id.value; if ($('#form_datum').val().length) $('#form_preis').select(); else $('#form_datum').select(); } function open_popup() { if (!$('#edit_id').val().length) return false; price_popup_open(); return false; } function add_price_callback(data) { info('Preis gespeichert'); grid_update(Hallinta.grid); } function add_price(obj) { var datum = document.getElementById('form_datum'); if (!datum.value.length) { error('Kein Rechnungsdatum angegeben'); return false; } var steuer = document.getElementById('form_steuer'); if (!steuer.value.length) { error('Kein Steuersatz angegeben'); return false; } var preis = document.getElementById('form_preis'); if (!preis.value.length) { error('Kein Preis angegeben'); return false; } var parms = 'callback=price&' + $(obj.form).serialize(); ajax_request('function', parms, add_price_callback); price_popup.closePopup(); preis.value = ''; return false; } EOC; $jscode = str_replace('CONTENT_FORM', str_replace(array("\n"), array("\\\n"), $form), $jscode); JavaScript::instance()->add($jscode); JavaScript::instance()->onLoad("\$('#button_save').click(function () {return custom_save(this);});"); JavaScript::instance()->onLoad("\$('#button_insert').click(function () {return custom_insert(this);});"); $buttons = <<

EOC; $mask = array( 'table' => 'metro_artikel', 'title' => 'Artikelstammdaten', 'join' => array('metro_abteilung ON abteilung = metro_abteilung.id'), 'list' => array( 'id' => array( 'name' => 'ID', 'visible' => false, 'sql' => 'metro_artikel.id', ), 'artnr' => array( 'name' => 'ArtNr', 'sqltype' => 'int', 'width' => 60, 'type' => 'number', 'filter' => 't=3', 'specs' => array('decPlaces' => 0, 'thouSep' => ''), ), 'menge' => array( 'name' => 'Menge', 'width' => 60, 'filter' => 't3', 'specs' => array('ClassName' => 'alignrightpad'), ), 'bezeichnung' => array( 'name' => 'Bezeichnung', 'width' => 300, 'filter' => 't', ), 'netto' => array( 'name' => 'netto', 'width' => 60, 'type' => 'number', 'specs' => array('decPlaces' => 2, 'ClassName' => 'alignrightpad'), 'sql' => '(SELECT preis FROM metro_artikel_preis ' . 'WHERE artikel = metro_artikel.id ORDER BY datum DESC LIMIT 1)', ), 'preis' => array( 'name' => 'Preis', 'width' => 60, 'type' => 'number', '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' => 100, 'filter' => 't4', ), 'abteilung' => array( 'name' => 'Abteilung', 'sqltype' => 'int', 'width' => 200, 'filter' => 's', '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', 'width' => 50, 'filter' => 's', 'specs' => array('ClassName' => 'aligncenter'), 'visible' => false, ), 'vpe' => array( 'name' => 'Einheit', 'sqltype' => 'int', 'width' => 70, '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", ), ), 'edit' => array( 'artnr' => array( 'name' => 'Artikelnummer', 'type' => 'number', 'size' => 15, 'required' => true, ), 'abteilung' => array( 'name' => 'Abteilung', 'type' => 'select', 'options' => 'SELECT id,name AS text FROM metro_abteilung ORDER BY name', 'option_empty' => '-- select --', 'required' => true, ), 'vpe' => array( 'name' => 'Verpackungseinheit', 'type' => 'select', 'options' => 'SELECT id,name AS text FROM metro_vpe ORDER BY name', 'option_empty' => '-- select --', 'required' => true, ), 'menge' => array( 'name' => 'Menge', 'type' => 'text', 'size' => 15, 'null' => true, ), 'bezeichnung' => array( 'name' => 'Bezeichnung', 'type' => 'text', 'size' => 21, 'required' => true, ), 'hinweis' => array( 'name' => 'Hinweis', 'type' => 'text', 'size' => 21, 'null' => true, ), 'hersteller' => array( 'name' => 'Hersteller', 'type' => 'text', 'size' => 21, 'null' => true, ), 'removed' => array( 'name' => 'Artikel nicht mehr im Programm', 'type' => 'boolean', ), 'buttons' => array( 'type' => 'html', 'code' => $buttons, 'sql' => false, ), ), 'second' => array( 'pricelist' => array( 'title' => 'Preisverlauf', 'rows' => 5, 'table' => 'metro_artikel_preis', 'table_edit' => 'metro_artikel_preis', 'where' => 'artikel = {id} ORDER BY datum DESC', 'list' => array( 'id' => array( 'name' => 'ID', 'edit' => array('Writeable' => false, 'EntryType' => 'H', 'Length' => 4, 'isKey' => true), 'visible' => false, ), 'datum' => array( 'name' => 'Datum', 'width' => 180, 'edit' => array('EntryType' => 'T', 'isNullable' => false, 'Writeable' => true), ), 'steuersatz' => array( 'name' => 'Steuer', 'width' => 60, 'type' => 'number', 'specs' => array('decPlaces' => 2, 'ClassName' => 'alignrightpad'), 'edit' => array('EntryType' => 'T', 'isNullable' => false, 'Writeable' => true), ), 'preis' => array( 'name' => 'netto', 'width' => 60, 'type' => 'number', 'specs' => array('decPlaces' => 2, 'ClassName' => 'alignrightpad'), 'edit' => array('EntryType' => 'T', 'isNullable' => false, 'Writeable' => true), ), 'brutto' => array( 'name' => 'Preis', 'width' => 60, 'type' => 'number', 'specs' => array('decPlaces' => 2, 'ClassName' => 'alignrightpad'), 'sql' => 'preis * ((100 + steuersatz)/100)', ), 'empty' => array( 'name' => '', 'width' => 20, 'sql' => "''", ), ), ), ), 'callbacks' => array( 'price' => cb_price, 'artnr' => cb_artnr, ), ); function cb_price() { global $db; if (empty($_POST['artikel']) || empty($_POST['datum']) || empty($_POST['preis'])) 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())", $_POST['artikel'], $_POST['preis'], $_POST['steuer'], $date, $db->quote($_SESSION['sys']['login']), $row['id']); $sth = $db->query($sql); return true; } function cb_artnr() { global $db; if (empty($_POST['artnr'])) return array('error' => 'Nicht ausreichend Daten übermittelt'); $sql = sprintf("SELECT count(*) AS count FROM metro_artikel WHERE artnr = %d", $_POST['artnr']); if (!empty($_POST['artikel'])) $sql .= sprintf(" AND id <> %d", $_POST['artikel']); $sth = $db->query($sql); $row = $sth->fetch(); return array('count' => $row['count']); } ?>