<?php
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 1 AND YEAR(CURDATE()) = YEAR(Bezahlt_am));";
$result = $db->query($sql);
$ntaj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 1 AND YEAR(CURDATE()) = YEAR(Bezahlt_am) AND QUARTER(CURDATE()) = QUARTER(Bezahlt_am));";
$result = $db->query($sql);
$ntaq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 1 AND YEAR(CURDATE()) = YEAR(Bezahlt_am) AND MONTH(CURDATE()) = MONTH(Bezahlt_am));";
$result = $db->query($sql);
$ntam = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Eingang WHERE (YEAR(CURDATE()) = YEAR(Bezahlt_am));";
$result = $db->query($sql);
$ntej = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Eingang WHERE (YEAR(CURDATE()) = YEAR(Bezahlt_am) AND QUARTER(CURDATE()) = QUARTER(Bezahlt_am));";
$result = $db->query($sql);
$nteq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Eingang WHERE (YEAR(CURDATE()) = YEAR(Bezahlt_am) AND MONTH(CURDATE()) = MONTH(Bezahlt_am));";
$result = $db->query($sql);
$ntem = $result->fetch_assoc();

$sql = "SELECT Count(*) AS Anzahl FROM " . PREFIX . "_Kontakte;";
$result = $db->query($sql);
$ntk = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl FROM " . PREFIX . "_Artikel;";
$result = $db->query($sql);
$nta = $result->fetch_assoc();
?>
<div id="left">
	<fieldset>
		<legend>Aus- & Eingang</legend>
		<label><b>Ausgangsrechnungen</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntam['Anzahl']; ?></label>
		<label><?php echo number_format($ntam['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntam['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntaq['Anzahl']; ?></label>
		<label><?php echo number_format($ntaq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntaq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntaj['Anzahl']; ?></label>
		<label><?php echo number_format($ntaj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntaj['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label><b>Eingangsrechnungen</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntem['Anzahl']; ?></label>
		<label><?php echo number_format($ntem['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntem['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $nteq['Anzahl']; ?></label>
		<label><?php echo number_format($nteq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($nteq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntej['Anzahl']; ?></label>
		<label><?php echo number_format($ntej['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntej['Mwst'], '2', ',', '.'); ?> €</label>
	</fieldset>
</div>
<div id="right">
	<fieldset>
		<legend>Kunden</legend>
		<label>Kunden in der Datenbank</label>
		<label><?php echo $ntk['Anzahl']; ?></label>
	</fieldset>
	<fieldset>
		<legend>Artikel</legend>
		<label>Artikel in der Datenbank</label>
		<label><?php echo $nta['Anzahl']; ?></label>
	</fieldset>
</div>
