
<?php
// ALA geändert am 28.07.2023 key_type auf bigint, maxlen auf 20 ( ID, CATEGORY) geändert

	require_once("config/connect.php");
	require_once("config/pageConfig.php");
	require_once("global_functions.php");
	check_login('', '', 'ENABLERKEY_ADMIN_PRODUKTE');
?>
<head>
	<title>SITPOS Produkte</title>
	<?php 	echo META_DATA_ADMIN;  ?>
		<script src="jquery/jscolor.min.js"></script>
		<style type="text/css">
		<?php include 'include/main.css'; ?>
		<?php include 'include/menue.css'; ?>
		.pme-key-0-width100{
			background:#dcdcdc;
			font-weight:bold;
		}
		.pme-value-0-width100
		{
			background:#f4f4f4;
		}
		/**/

		</style>
</head>
<body>
	<div id="wrapper_admin" class="wrapper_admin" >
		<?php menue_anzeigen();	?>
<script>

	function brutto_ausrechnen(fieldSelect, zeitprVal=false)
	{
		// unterscheidung von standard preis und zeitpreis -> happy hour
		//Steuer auslesen
					var e = document.getElementsByName("PME_data_TAXCAT")[0];
					var steuer_string = e.options[e.selectedIndex].text;
					steuer=steuer_string.substr(0,6);
										
					if(fieldSelect=='stdPrice')netto=$("input[name='PME_data_PRICESELL']").val();
					else if(fieldSelect=='zeitPrice')netto=zeitprVal;			// vom zeitPrice Field wird das mit �bergeben
					if(netto.indexOf(',') !== -1){
						netto=netto.replace(',', '.');
						if(fieldSelect=='stdPrice')$("input[name='PME_data_PRICESELL']").val(netto);
						else if(fieldSelect=='zeitPrice')$("input[name='PME_data_zeitpreis_netto']").val(netto);
					}
					if (netto.substring(0, 1) == ".") netto=netto.replace('.', '0.');
					brutto=netto*(1+1*steuer);
					brutto=brutto.toFixed(8);
					
					if(fieldSelect=='stdPrice')$("#reini_brutto").val(brutto);
					else if(fieldSelect=='zeitPrice')$("input[name='PME_data_zeitpreis_brutto']").val(brutto);
					//alert(brutto);
	}
	
	$(document).ready(function() {
		// f�ge ein Feld ein, das f�r den Brutto VK zust�ndig ist
		$("input[name='PME_data_PRICESELL']").parent().parent().after("<tr class='pme-row-0'><td class='pme-key-1'>VK Preis brutto</td><td class='pme-value-1'><input id='reini_brutto' class='pme-input-1' type='text' maxlength='12' size='12' value='0.0000' name='reini_brutto'></td></tr>");
		
		if($("input[name='PME_data_PRICESELL']").length){
					// funktion wird nur aufgerufen wenn wir im editier mod sind, ansonsten kann die js funktion das steuerfeld nicht finden Zeile 25
					// und wir bekommen einen Error
				brutto_ausrechnen('stdPrice');
		}
		
		
		// Steuer raussuchen (erster Teil von description z.B. 0.2000 - MwSt 20%   das 0.2000 rausschneiden
		
		// Felder Berechnen
		// Nettopreis
		$("input[name='PME_data_PRICESELL']").keyup(function() {
			brutto_ausrechnen('stdPrice');		
					
		});
		// Bruttopreis - dieses Feld wurde zuvor in die Tabelle eingef�gt
		$("#reini_brutto").keyup(calculateNettPr = function() {
				//Steuer auslesen
				var e = document.getElementsByName("PME_data_TAXCAT")[0];
				var steuer_string = e.options[e.selectedIndex].text;
				steuer=steuer_string.substr(0,6);
			
				brutto=$("#reini_brutto").val();
				brutto=brutto.replace(/,/g,'.');
				netto=brutto/(1+1*steuer);
				netto=netto.toFixed(8);
				$("input[name='PME_data_PRICESELL']").val(netto);
				//alert(netto);
		});
		
		
		
	
			
		$( "select[name='PME_data_VARPRICE']" ).change(function() {
			
			
			//	alert( "Handler for .change() called." );
		});
		
		// lisener to tax option/select -> onchange recalculat nette price on base of brutto price
		
		$("select[name='PME_data_TAXCAT']").change(function() {
			calculateNettPr();
			calculateZeitNettPr($(this).find('option:selected').text());
			// neue funktion gemacht, die f�r den standart preise ist zu sehr auf die felder zugeschnitten, schien mir so einfacher
		});

		$("select[name='PME_data_VARPRICE']").change( function() {
			if (this.value == 1){ 
				setPriceFiledProp();
			}
			else if (this.value == 0){
				$("#reini_brutto").prop('disabled', false).css({'color':'#000', 'background':'#fff'});
				$("input[name='PME_data_PRICESELL'], input[name='PME_data_zeitpreis_netto'], input[name='PME_data_zeitpreis_brutto']").prop('disabled', false).css({'color':'#000', 'background':'#fff'});
			}
		});
		
		if($("select[name='PME_data_VARPRICE'] :selected").val() == 1) setPriceFiledProp();	
		
		// zeitpreis felder
		$("input[name='PME_data_zeitpreis_netto']").keyup(function() {
			brutto_ausrechnen('zeitPrice', $(this).val());
		});
		$("input[name='PME_data_zeitpreis_brutto']").keyup(function() {
			calculateZeitNettPr(false);
		});
			// Color Picker !!!!!
		var currentColor = 'fff';
		if($("input[name='PME_data_bg_color']").length){
			currentColor=$("input[name='PME_data_bg_color']").val().replace("#", "");
		}
		$("input[name='PME_data_bg_color']").after("<button id='farb_auswahl' style='margin:3px 5px;' class=\"button_none_float button_gross orange jscolor {valueElement:'chosen-value', onFineChange:'setTextColor(this)', value:'"+currentColor+"'}\">Farbe w&auml;hlen</button>");

	});
	
	function setPriceFiledProp(){
		$("#reini_brutto").prop('disabled', true).css({'color':'#aaa', 'background':'#ddd'});
		$("input[name='PME_data_PRICESELL'], input[name='PME_data_zeitpreis_netto'], input[name='PME_data_zeitpreis_brutto']").prop('disabled', true).css({'color':'#aaa', 'background':'#ddd'});
	
	}
		
	function calculateZeitNettPr(steuer_string=false){
			// wenn vom steuer select aufgerufen kommt der wert mit, sonst auslesen
		if(steuer_string==false)steuer_string=$("select[name='PME_data_TAXCAT']").find('option:selected').text();
		steuer=steuer_string.substr(0,6);
		brutto=$("input[name='PME_data_zeitpreis_brutto']").val();
		brutto=brutto.replace(/,/g,'.');
		$("input[name='PME_data_zeitpreis_brutto']").val(brutto);
		netto=brutto/(1+1*steuer);
		netto=netto.toFixed(8);
		$("input[name='PME_data_zeitpreis_netto']").val(netto);
	}
	
		// Farben f�r den Color Picker berechnen und einf�gen
	// Farbe aus Picker rauslesen und in die jeweiligen Felder setzen
	function setTextColor(picker) {
			//currentColor=$("input[name='PME_data_bg_color']").val().replace("#", "");
			//console.log(currentColor);
		text_farbe = document.getElementById('farb_auswahl').style.color;
		text_farbe=rgbToHex(text_farbe);

		$("input[name='PME_data_bg_color']").val('#' + picker.toString());
		$("input[name='PME_data_txt_color']").val('#' + text_farbe);	
	}
	
	function rgbToHex(string) {
		var a = string.split("(")[1].split(")")[0];
		a = a.split(",");
		var b = a.map(function(x){             //For each array element
			x = parseInt(x).toString(16);      //Convert to a base16 string
			return (x.length==1) ? "0"+x : x;  //Add zero if we get only one character
		});
		b = b.join("");
		//alert (b);
		return(b);
	}
	
	
	
	
</script>
<?php

function sind_mehr_als_25_produkte_angelegt()
{
	$sql="SELECT id FROM products WHERE geloescht=0";
	$Q1=mysql_query($sql);
	if (!$Q1) echo mysql_error();
	$anz_produkte=mysql_num_rows($Q1);
	if ($anz_produkte>25) return true;
	else return false;
}

/*
 * IMPORTANT NOTE: This generated file contains only a subset of huge amount
 * of options that can be used with phpMyEdit. To get information about all
 * features offered by phpMyEdit, check official documentation. It is available
 * online and also for download on phpMyEdit project management page:
 *
 * http://platon.sk/projects/main_page.php?project_id=5
 *
 * This file was generated by:
 *
 *                    phpMyEdit version: 5.7.1
 *       phpMyEdit.class.php core class: 1.204
 *            phpMyEditSetup.php script: 1.50
 *              generating setup script: 1.50
 */

// MySQL host name, user name, password, database, and table

if (FILIALSYSTEM_IST_FILIALSYSTEM == "ja" && FILIALSYSTEM_UEBERNEHMEN_ZENTRALSYSTEM == "ja" && FILIALSYSTEM_PRODUKTE_ANLEGEN_ANZEIGEN == "ja" && FILIALSYSTEM_ERP_PROGRAMM == "sITPos") 
{
	
	echo '<iframe src="'.FILIALSYSTEM_URL_ZENTRALSYSTEM.'/anlegen_produkte.php?token='.FILIALSYSTEM_TOKEN.'" height="100%" width="100%"></iframe>'; 
}
else
{

if ((defined('BASIS_LIGHT_LIZENZ_VORHANDEN') && strtolower(BASIS_LIGHT_LIZENZ_VORHANDEN) == 'ja' ))
{
	if (sind_mehr_als_25_produkte_angelegt())
	{
		echo "<br>Mehr als 25 Produkte sind angelegt<br>Kaufen Sie eine h&ouml;herwertige Lizenz bei Ihrem Fachh&auml;ndler";
		exit;
	}
}
$opts['hn'] = SQL_HOST;
$opts['un'] = SQL_USER;
$opts['pw'] = SQL_PW;
$opts['db'] = SQL_DB;
$opts['tb'] = 'products';

// Name of field which is the unique key
$opts['key'] = 'ID';

// Type of key field (int/real/string/date etc.)
$opts['key_type'] = 'bigint';

// Sorting field(s)
$opts['sort_field'] = array('ID');

// Number of records to display on the screen
// Value of -1 lists all records in a table
$opts['inc'] = 15;

// Options you wish to give the users
// A - add,  C - change, P - copy, V - view, D - delete,
// F - filter, I - initial sort suppressed
$opts['options'] = 'ACPVDF';

if (defined('FILIALSYSTEM_IST_FILIALSYSTEM') && FILIALSYSTEM_IST_FILIALSYSTEM == "ja" && defined('FILIALSYSTEM_UEBERNEHMEN_ZENTRALSYSTEM') && FILIALSYSTEM_UEBERNEHMEN_ZENTRALSYSTEM == "ja" && FILIALSYSTEM_ERP_PROGRAMM == "sITPos") {
	$opts['options'] = 'PVF';
}

$opts['triggers']['delete']['before'] = 'anlegen_mark_as_deleted.TR.php';

// Number of lines to display on multiple selection filters
$opts['multiple'] = '4';

// Navigation style: B - buttons (default), T - text links, G - graphic links
// Buttons position: U - up, D - down (default)
	$opts['navigation'] = 'UDG';

	$opts['buttons']['L']['up'] = array('<<','<','add','>','>>','goto_combo');
	$opts['buttons']['F']['up'] = $opts['buttons']['L']['up'];
	
	$opts['buttons']['L']['down'] = $opts['buttons']['L']['up']; 
	$opts['buttons']['V']['down'] = false;
	$opts['buttons']['C']['down'] = false;

// Display special page elements
$opts['display'] = array(
	'form'  => true,
	'query' => true,
	'sort'  => true,
	'time'  => true,
	'tabs'  => true
);

// Set default prefixes for variables
$opts['js']['prefix']               = 'PME_js_';
$opts['dhtml']['prefix']            = 'PME_dhtml_';
$opts['cgi']['prefix']['operation'] = 'PME_op_';
$opts['cgi']['prefix']['sys']       = 'PME_sys_';
$opts['cgi']['prefix']['data']      = 'PME_data_';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
$opts['language'] = 'DE-UTF8';

/* Table-level filter capability. If set, it is included in the WHERE clause
   of any generated SELECT statement in SQL query. This gives you ability to
   work only with subset of data from table.

$opts['filters'] = "column1 like '%11%' AND column2<17";
$opts['filters'] = "section_id = 9";
$opts['filters'] = "PMEtable0.sessions_count > 200";
*/

$opts['filters'] = "PMEtable0.geloescht = 0";

/* Field definitions
   
Fields will be displayed left to right on the screen in the order in which they
appear in generated list. Here are some most used field options documented.

['name'] is the title used for column headings, etc.;
['maxlen'] maximum length to display add/edit/search input boxes
['trimlen'] maximum length of string content to display in row listing
['width'] is an optional display width specification for the column
          e.g.  ['width'] = '100px';
['mask'] a string that is used by sprintf() to format field output
['sort'] true or false; means the users may sort the display on this column
['strip_tags'] true or false; whether to strip tags from content
['nowrap'] true or false; whether this field should get a NOWRAP
['select'] T - text, N - numeric, D - drop-down, M - multiple selection
['options'] optional parameter to control whether a field is displayed
  L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view
            Another flags are:
            R - indicates that a field is read only
            W - indicates that a field is a password field
            H - indicates that a field is to be hidden and marked as hidden
['URL'] is used to make a field 'clickable' in the display
        e.g.: 'mailto:$value', 'http://$value' or '$page?stuff';
['URLtarget']  HTML target link specification (for example: _blank)
['textarea']['rows'] and/or ['textarea']['cols']
  specifies a textarea is to be used to give multi-line input
  e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10
['values'] restricts user input to the specified constants,
           e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99)
['values']['table'] and ['values']['column'] restricts user input
  to the values found in the specified column of another table
['values']['description'] = 'desc_column'
  The optional ['values']['description'] field allows the value(s) displayed
  to the user to be different to those in the ['values']['column'] field.
  This is useful for giving more meaning to column values. Multiple
  descriptions fields are also possible. Check documentation for this.
*/

$opts['fdd']['ID'] = array(
  'name'     => 'ID',
  'select'   => 'T',
  //'options'  => 'AVCPDR', // auto increment
  'options'  => '',
  'maxlen'   => 20,
  'default'  => '0',
  'sort'     => true
);
$opts['fdd']['ID']['help'] = '';
$opts['fdd']['REFERENCE'] = array(
  'name'     => 'Artikel Nr.',
  'select'   => 'T',
  'maxlen'   => 255,
  'olattrs'  => 'align="center"',
  'sort'     => true
);
$opts['fdd']['CODE'] = array(
  'name'     => 'Barcode',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['NAME'] = array(
  'name'     => 'Artikelname',
  'select'   => 'T',
  'js'   	 => array('required' => 'true'),
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['PRINTNAME'] = array(
  'name'     => 'Name Ausdruck',
  'select'   => 'T',
  'maxlen'   => 50,
  'sort'     => true
);
$opts['fdd']['printname_kueche'] = array(
  'name'     => 'Name Ausdruck Küche',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);

$opts['fdd']['TAXCAT'] = array(
  'name'     => 'Steuer',
  'select'   => 'D',
  'maxlen'   => 11,
  'values'	 => array(
					'table' => 'taxes',
					'column' => 'id',
					'description' => 'rate',
					'sort'     => true
					)
);

$opts['fdd']['VARPRICE'] = array(
  'name'     => 'variabler Preis',
  'select'   => 'D',
  'maxlen'   => 1,
  'values2'   => array('0'=>'Nein','1'=>'Ja'),
  'default'  => '',
  'sort'     => true
);
	$opts['fdd']['PRICESELL'] = array(
	  'name'     => 'VK Preis netto',
	  'select'   => 'TF',
	  'maxlen'   => 12,
	  'sort'     => true
	);

	# 'sqlw'	 => 'REPLACE($val_qas, ",", ".")',	  'css'		 =>	array('postfix' => ' sitPos_replaceComma'),
$opts['fdd']['CATEGORY'] = array(
  'name'     => 'Warengruppe',
  'select'   => 'D',
  'maxlen'   => 20,
  'css'		 =>	array('postfix' => 'width100'),
    'values'	 => array(
					'table' => 'categories',
					'column' => 'id',
					'description' => 'name',
					'filters' => 'geloescht = 0'
				),
  'sort'     => true

);
	$opts['fdd']['PRICEBUY'] = array(
	  'name'     => 'EK Preis netto',
	  'select'   => 'TF',
	  'options'  => 'ACPVD',
	  'sqlw'	 => 'REPLACE($val_qas, ",", ".")',
	  'maxlen'   => 12,
	  'sort'     => true
	);
	
	if(defined('GASTRO_VERSION') && strtolower(GASTRO_VERSION) == 'ja' && defined('BASIS_LIZENZ_VORHANDEN') && strtolower(BASIS_LIZENZ_VORHANDEN) == 'ja'){
		$opts['fdd']['ist_beilage'] = array(
		  'name'     => 'Ist Beilage',
		  'select'   => 'D',
		  'maxlen'   => 1,
		  'values2'   => array('0'=>'Nein','1'=>'Ja'),
		  'default'  => '',
		  'sort'     => true
		);
		
		$opts['fdd']['beilage_basispreis_aendern'] = array(
		  'name'     => 'Beilage Basispreis ändern',
		  'select'   => 'D',
		  'maxlen'   => 1,
		  'values2'   => array('0'=>'Nein','1'=>'Ja'),
		  'default'  => '',
		  'sort'     => true
		);

		
		$opts['fdd']['artikel_art'] = array(
		  'name'     => 'Speisen Art',
		  'select'   => 'D',
		  'maxlen'   => 32,
		  'values2'  => array("" => "- keine -"),
		  'values'	 => array(
					'table' => 'artikel_art',
					'column' => 'id',
					'description' => 'bezeichnung',
				),
		  
		);
	}

	$opts['fdd']['supplyprint'] = array(
	  'name'     => 'Drucker Bestellung',
	  'select'   => 'D',
	  'maxlen'   => 11,
	  'default'    => '',
	  'values2'  => array("" => "--- keiner ---"), 
		'values'	 => array(
						'table' => 'drucker',
						'column' => 'drucker_id',
						'description' => 'funktion'
					),
	 'css'		 =>	array('postfix' => ' sitPos_tableCol_left_150'),				
	  'sort'     => true
	);
		
	$opts['fdd']['NEGATIVEPRICE'] = array(
	  'name'     => 'negativer Preis',
	  'select'   => 'D',
	  'maxlen'   => 1,
	  'values2'   => array('0'=>'Nein','1'=>'Ja'),
	  'default'  => '',
	  'sort'     => true
	);
	
	$opts['fdd']['rabattierbar'] = array(
	  'name'     => 'Rabatt zugelassen',
	  'select'   => 'D',
	  'maxlen'   => 1,
	  'values2'   => array('0'=>'Ja','1'=>'Nein'),
	  'default'  => 0
	);
	
	$opts['fdd']['bg_color'] = array(
	  'name'     => 'Kachel Hintergrund Farbe',
	  'select'   => 'T',
	  'maxlen'   => 11
	);
	$opts['fdd']['txt_color'] = array(
	  'name'     => 'Kachel Text Farbe',
	  'select'   => 'T',
	  'maxlen'   => 11
	);

	$opts['fdd']['PRODUKTORDER'] = array(
	  'name'     => 'Sortierung',
	  'select'   => 'T',
	  'maxlen'   => 11,
	  'default'  => '99',
	  'sort'     => true
	);
	$opts['fdd']['SICHTBAR'] = array(
	  'name'     => 'Im Katalog anzeigen',
	  'select'   => 'D',
	  'maxlen'   => 1,
	  'values2'   => array(0=>'Nein',1=>'Ja'),
	  'default'  => '1',
	  'sort'     => true
	);
	$opts['fdd']['kassenabschluss_anzeigen'] = array(
	  'name'     => 'Im Kassenabschluss auflisten',
	  'select'   => 'D',
	  'maxlen'   => 1,
	  'values2'   => array(0=>'Nein',1=>'Ja'),
	  'default'  => '1',
	  'sort'     => true
	);
	$opts['fdd']['ist_favorit'] = array(
	  'name'     => 'Produkt ist Favorit',
	  'select'   => 'D',
	  'maxlen'   => 1,
	  'values2'   => array(0=>'Nein',1=>'Ja'),
	  'default'  => '0',
	  'sort'     => true
	);
	
	
		$opts['fdd']['auftragsschein_print'] = array(
	  'name'     => 'Auf Auftragsschein drucken',
	  'select'   => 'D',
	  'values2'   => array('category'=>'Wie Warengruppe', 'nein'=>'Nein','ja'=>'Ja'),
	  'default'  => ''
	);
	$opts['fdd']['anz_refbons'] = array(
	  'name'     => 'Anz. Referenzbons',
	  'select'   => 'T',
	  'maxlen'   => 5,
	  'default'  => ''
	);
	if(defined('BASIS_LIZENZ_VORHANDEN') && strtolower(BASIS_LIZENZ_VORHANDEN) == 'ja'){
		$opts['fdd']['zeitpreis_netto'] = array(
		  'name'     => 'Zeitabh&auml;ngiger Preis netto',
		  'select'   => 'TF',
		  'maxlen'   => 14,
		  'sort'     => true
		);
		$opts['fdd']['zeitpreis_brutto'] = array(
		  'name'     => 'Zeitabh&auml;ngiger Preis brutto',
		  'select'   => 'TF',
		  'maxlen'   => 14,
		  'sort'     => true
		);
	}
	
			// add class by adding a postfix. phpMyEdit does not have a add class function. we do this by adding a postfix with leading " " (space), this will !!!'
			//	 $opts['fdd']['css'] example to manipulate all classes of this page, css options are, prefix, postfix, seperator, ...   see doc's
		$opts['fdd']['bg_color']['css'] = array( 'postfix' => ' sitPos_doColor' );

// Now important call to phpMyEdit
require_once 'phpmyedit/phpMyEdit.class.php';
new phpMyEdit($opts);

}
?>
</div>  <!-- end of wrapper div -->
</body>