<?php
+$style[] = <<<EOC
+div#form_price {
+ padding-left: 10px;
+ padding-right: 10px;
+ font-size: 90%;
+ color: #555;
+}
+EOC;
+
+$form = '
+<div id="form_price">
+<form>
+<input id="form_artikel" name="artikel" type="hidden" />
+<label for="form_datum">Rechnungsdatum</label><br>
+<input id="form_datum" name="datum" size="8"> <img class="calendar" src="images/icons/calendar.gif" onclick="calendar(\\\'form_datum\\\',event)" />
+<br>
+<label for="form_steuer">Steuersatz</label><br>
+<input id="form_steuer" name="steuer" size="10">
+<br>
+<label for="form_preis">Preis</label><br>
+<input id="form_preis" name="preis" size="10">
+<div class="buttons" style="margin-top: 15px;">
+<button onclick="return add_price(this);">Hinzufügen</button>
+</div>
+</form>
+</div>
+';
+
+$javascript = <<<EOC
+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.Popup(options, false, false);
+ price_popup.createWindow('<strong>Verbinden</strong>',content,'auto','130px');
+ }
+
+ price_popup.titleDiv.childNodes[0].innerHTML = 'Preis hinzufügen';
+
+ var form_id = document.getElementById('edit_id');
+ var artikel = document.getElementById('form_artikel');
+ artikel.value = form_id.value;
+
+ price_popup.openPopup(100,300);
+
+ var datum = document.getElementById('form_datum');
+ datum.activate();
+}
+
+function open_popup()
+{
+ var eid = document.getElementById('edit_id');
+ if (!eid || !eid.value.length) return false;
+
+ price_popup_open();
+ return false;
+}
+
+function add_price_callback(data)
+{
+ info('Preis gespeichert');
+ grid_update(grid);
+}
+
+function add_price(obj)
+{
+ price_popup.closePopup();
+
+ 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 source = document.getElementById('source');
+ if (!source) return false;
+
+ var parms = 'source=' + source.innerHTML + '&callback=price&';
+ ajax_request('function', parms+Form.serialize(obj.form), add_price_callback);
+
+ preis.value = '';
+
+ return false;
+}
+
+EOC;
+
+$jscode[] = str_replace('CONTENT_FORM', str_replace(array("\n"),
+ array("\\\n"), $form), $javascript);
+
+
+$buttons = <<<EOC
+<p style="margin-top: 5px; margin-bottom: 4px; text-align: center;">
+<button onclick="return open_popup()">Preis hinzufügen</button>
+</p>
+EOC;
+
$mask = array(
'table' => 'metro_artikel',
'title' => 'Artikelstammdaten',
'menge' => array(
'name' => 'Menge',
'width' => 60,
- 'specs' => "ClassName: 'alignrightpad', filterUI: 't'",
+ 'specs' => "ClassName: 'alignrightpad'",
),
'bezeichnung' => array(
'name' => 'Bezeichnung',
- 'width' => 345,
+ 'width' => 300,
'specs' => "filterUI: 't'",
),
+ 'netto' => array(
+ 'name' => 'netto',
+ 'width' => 60,
+ 'type' => 'number',
+ 'specs' => "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' => "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)',
+ ),
'hersteller' => array(
'name' => 'Hersteller',
'width' => 100,
'specs' => "filterUI: 't'",
- 'visible' => false,
),
'abteilung' => array(
'name' => 'Abteilung',
'artnr' => array(
'name' => 'Artikelnummer',
'type' => 'number',
- 'size' => 25,
+ 'size' => 15,
'required' => true,
),
'abteilung' => array(
'bezeichnung' => array(
'name' => 'Bezeichnung',
'type' => 'text',
- 'size' => 25,
+ 'size' => 21,
'required' => true,
),
'hersteller' => array(
'name' => 'Hersteller',
'type' => 'text',
- 'size' => 25,
+ 'size' => 21,
'null' => true,
),
+ 'buttons' => array(
+ 'type' => 'html',
+ 'code' => $buttons,
+ 'sql' => false,
+ ),
),
+ 'callbacks' => array(
+ 'price' => cb_price,
+ ),
);
+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;
+}
+
?>