<?php
	require_once("../config/connect.php");
	require_once("../config/pageConfig.php");
	require_once("../global_functions.php");
	//require_once("../ajax_funktionen.php");
	
	$tisch_id=1;
	if (isset($_REQUEST['tisch_id']))
	{
		$tisch_id=$_REQUEST['tisch_id'];
	}
	
	$page = $_SERVER['PHP_SELF']."?tisch_id=$tisch_id";
	$sec = "2";
	
	#echo "<p>".print_r($_SESSION)."</p>";
?>
<html> 
<head> 

    <meta charset="UTF-8"> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="refresh" content="<?php  echo $sec; ?>;URL='<?php echo $page; ?>'">
	
	<style type="text/css">
	<?php include '../include/main.css'; 
	
			# extract CSS 
		preg_match('/\s([0-9]{1,3})px/', KUNDENMONITOR_FONT_BASIC, $fontSize);
		preg_match('/\/(.*?)[0-9]{1,3}[a-zA-Z%]{1,3}\s{1}/', KUNDENMONITOR_FONT_BASIC, $elemHeight);
		
		preg_match('/bold/', strtolower(KUNDENMONITOR_FONT_BASIC), $fontWeight);
		
		
		
		$pat=array('/\//', '/%/', '/px/');
		$elementHeight=preg_replace($pat, '', $elemHeight[0]);
		$fontSize=preg_replace('/px/', '', $fontSize[0]);
		$fontSize = ceil($fontSize/1.25) .'px';		# für Artikel Zeile
		$elementHeight = ceil($elementHeight/1.25).'%';
		
		if($fontWeight[0] == 'bold'){
			$fontWeight='font-weight:bold;';
		}
		else $fontWeight='font-weight:normal;';
		

	?>
		.bon_anzeige {text-align:left; position:relative; float:right;  height:98%; width:98%; margin:0; margin:0; padding:1px 0; 
				border:1px solid gray; border-bottom:1px solid gray; border-left:none; }
		#bon_content_sum_div {height:40px;}
		#bon_content_sum_div div {font-size:2em;height:40px;}
		#bonContent {bottom:42px;}
	
		.bon_summe_gesamtsummeKdMonitor{ font-weight:900;			}
	
			/*   font: font-style font-variant font-weight font-size/line-height font-family;			*/
		.kdMonFontBasic{  font:<?php echo KUNDENMONITOR_FONT_BASIC; ?>; height:55px !important;		}
		.kdMonFontBasicArtikel{  font-size:<?php echo $fontSize ?>!important; line-height:<?php echo $elementHeight ?>!important; <?php echo $fontWeight; ?>	}
		.kdMonFontBasicHeadElem{ position:relative; float:right;						}
		
		.artikelLine{  box-shadow:inset 0 -1px 2px -1px rgba(0,0,0,0.4); font-weight:bold;			}
		.rowSum{ width:14.5%; padding-right:.5%; text-align:right; float:right;				}
		.rowQty{ width:10%; text-align:center; float:right;				}
		.rowPrice{ width:12%; text-align:right; float:right;				}
		.rowName{  width:49%; padding-left:1%; font-weight:normal; overflow:hidden; text-align:left; float:left;				}
		.rowTotalSum{ width:24.5%; padding-right:.5%; text-align:right; float:right;				}
		
	</style>
	
</head>
<?php
		
	function zeige_kundenmonitor($tisch_id){
		
		global $fontSize, $elementHeight;
		
		$validBonId=mysql_fetch_array(mysql_query("SELECT bon_id FROM `offener_bon` order by update_ts DESC LIMIT 1"));
		if(isset($validBonId['bon_id']) && $validBonId['bon_id'] > 0) $valOpenBonId = $validBonId['bon_id'];
		else  $valOpenBonId = $tisch_id;
		
		$sql=mysql_query("SELECT * FROM offener_bon WHERE bon_id = ". $valOpenBonId." ORDER by ID ASC");
			
			# äusseres div
		echo 	'<div class="" style="position:relative; width:98%; height:95%; margin:2% auto 0; " >';
					# header Zeile
		echo 	'<div id="" class="orange" style="position:relative; width:100%; height:60px;" >
					<div id="" class="rowSum kdMonFontBasic kdMonFontBasicHeadElem" >Summe</div>
					<div id="bon_stk" class="rowQty kdMonFontBasic kdMonFontBasicHeadElem" >Stk</div>
					<div id="bon_einzelpreis" class="rowPrice kdMonFontBasic kdMonFontBasicHeadElem" >Einzel</div>
					<div id="bon_name"  class="rowName kdMonFontBasic kdMonFontBasicHeadElem" >Name</div>
					<div class="cclear"></div>
				
				</div>';	# header Zeile Ende 
				
							#  Artikel Zeilen 
		echo 	'<div id="artikelContainer" class="" style="position:relative; width:100%; height:calc(100% - 120px);  overflow-y:auto; overflow: -moz-scrollbars-none;"     >';
				$summe=0;
					if (!$sql) echo mysql_error();
					while ($row=mysql_fetch_assoc($sql)){
						$stueck=$row['stueck'];
						$netto=$row['PRICESELL'];
						$steuersatz=$row['tax_rate'];
						$brutto=$netto*(1+$steuersatz);
						$brutto_gesamt=$brutto*$stueck;
						$brutto_anz=number_format($brutto,2,",",".");
						$brutto_gesamt_anz=number_format($brutto_gesamt,2,",",".");
						$stueck_anz=number_format($stueck,1,",",".");
						$summe+=$brutto_gesamt;
						
						if(strlen($row['printname']) >= 1) $bonName=$row['printname'];
						else $bonName=$row['name'];
						
						echo '<div class="artikelLine" style=""	>
								<div class="cclear"></div>
								<div id="bon_summe" class="rowSum kdMonFontBasicArtikel" style="" >'.$brutto_gesamt_anz.'</div>
								<div id="bon_stk" class="rowQty kdMonFontBasicArtikel" style="" >'.$stueck_anz.'</div>
								<div id="bon_einzelpreis" class="rowPrice kdMonFontBasicArtikel" style="" >'.$brutto_anz.'</div>
								<div id="bon_name" class="rowName kdMonFontBasicArtikel" style="" >'.$bonName.'</div>';
						
						
						echo '</div>';
						
					}
		
		echo 	'</div>';
		
		$summe_anz=number_format($summe,2,",",".");
		
		
				# Summen Zeile			
		echo 	'<div id="" class="orange" style="position:relative; width:100%; height:60px;" >
					<div id="bon_summe" class="rowTotalSum kdMonFontBasic" style="" >'.$summe_anz.'</div>
					<div id="" class="kdMonFontBasic kdMonFontBasicHeadElem" >Gesamt:</div>
					<div class="cclear"></div>
				</div>';	# Summen Zeile Ende
				

				# äusseres div ende
		echo '</div>';
	}
	
	

	zeige_kundenmonitor($tisch_id);
?>
	<script>
		var objDiv = document.getElementById("artikelContainer");
		objDiv.scrollTop = objDiv.scrollHeight;
	</script>

