<?php
$sql = "SELECT Count(*) AS Anzahl, SUM(Auftrag_Preis) AS Summe, SUM(Auftrag_Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Auftraege WHERE (YEAR(CURDATE()) = Jahr);";
$result = $db->query($sql);
$ntbj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Auftrag_Preis) AS Summe, SUM(Auftrag_Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Auftraege WHERE (YEAR(CURDATE()) = Jahr AND (QUARTER(CURDATE()) = QUARTER(Datum)));";
$result = $db->query($sql);
$ntbq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Auftrag_Preis) AS Summe, SUM(Auftrag_Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Auftraege WHERE (YEAR(CURDATE()) = Jahr AND (MONTH(CURDATE()) = MONTH(Datum)));";
$result = $db->query($sql);
$ntbm = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (YEAR(CURDATE()) = Jahr);";
$result = $db->query($sql);
$ntrj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (YEAR(CURDATE()) = Jahr AND (QUARTER(CURDATE()) = QUARTER(Datum)));";
$result = $db->query($sql);
$ntrq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (YEAR(CURDATE()) = Jahr AND (MONTH(CURDATE()) = MONTH(Datum)));";
$result = $db->query($sql);
$ntrm = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Gutschriften WHERE (YEAR(CURDATE()) = Jahr);";
$result = $db->query($sql);
$ntgj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Gutschriften WHERE (YEAR(CURDATE()) = Jahr AND (QUARTER(CURDATE()) = QUARTER(Datum)));";
$result = $db->query($sql);
$ntgq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Gutschriften WHERE (YEAR(CURDATE()) = Jahr AND (MONTH(CURDATE()) = MONTH(Datum)));";
$result = $db->query($sql);
$ntgm = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE Bezahlt = 0;";
$result = $db->query($sql);
$nto = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr);";
$result = $db->query($sql);
$ntoj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr AND QUARTER(CURDATE()) = QUARTER(Datum));";
$result = $db->query($sql);
$ntoq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr AND MONTH(CURDATE()) = MONTH(Datum));";
$result = $db->query($sql);
$ntom = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND DATE_ADD(Datum, INTERVAL " . $_SESSION['Firma']['Z_Bis'] . " DAY) < CURDATE());";
$result = $db->query($sql);
$ntf = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr AND DATE_ADD(Datum, INTERVAL " . $_SESSION['Firma']['Z_Bis'] . " DAY) < CURDATE());";
$result = $db->query($sql);
$ntfj = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr AND QUARTER(CURDATE()) = QUARTER(Datum) AND DATE_ADD(Datum, INTERVAL " . $_SESSION['Firma']['Z_Bis'] . " DAY) < CURDATE());";
$result = $db->query($sql);
$ntfq = $result->fetch_assoc();
$sql = "SELECT Count(*) AS Anzahl, SUM(Preis) AS Summe, SUM(Preis * (1 + MwSt / 100)) AS Mwst FROM " . PREFIX . "_Rechnungen WHERE (Bezahlt = 0 AND YEAR(CURDATE()) = Jahr AND MONTH(CURDATE()) = MONTH(Datum) AND DATE_ADD(Datum, INTERVAL " . $_SESSION['Firma']['Z_Bis'] . " DAY) < CURDATE());";
$result = $db->query($sql);
$ntfm = $result->fetch_assoc();
?>
<div id="left">
	<fieldset>
		<legend>Auftragsbestätigungen</legend>
		<label><b>erstellte Auftragsbestätigungen</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntbm['Anzahl']; ?></label>
		<label><?php echo number_format($ntbm['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntbm['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntbq['Anzahl']; ?></label>
		<label><?php echo number_format($ntbq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntbq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntbj['Anzahl']; ?></label>
		<label><?php echo number_format($ntbj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntbj['Mwst'], '2', ',', '.'); ?> €</label>
	</fieldset>
	<fieldset>
		<legend>Rechnungen</legend>
		<label><b>erstellte Rechnungen</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntrm['Anzahl']; ?></label>
		<label><?php echo number_format($ntrm['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntrm['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntrq['Anzahl']; ?></label>
		<label><?php echo number_format($ntrq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntrq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntrj['Anzahl']; ?></label>
		<label><?php echo number_format($ntrj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntrj['Mwst'], '2', ',', '.'); ?> €</label>
	</fieldset>
	<fieldset>
		<legend>Gutschriften</legend>
		<label><b>erstellte Gutschriften</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntgm['Anzahl']; ?></label>
		<label><?php echo number_format($ntgm['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntgm['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntgq['Anzahl']; ?></label>
		<label><?php echo number_format($ntgq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntgq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntgj['Anzahl']; ?></label>
		<label><?php echo number_format($ntgj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntgj['Mwst'], '2', ',', '.'); ?> €</label>
	</fieldset>
</div>
<div id="right">
	<fieldset>
		<legend>Offene Posten</legend>
		<label><b>offene Posten</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntom['Anzahl']; ?></label>
		<label><?php echo number_format($ntom['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntom['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntoq['Anzahl']; ?></label>
		<label><?php echo number_format($ntoq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntoq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntoj['Anzahl']; ?></label>
		<label><?php echo number_format($ntoj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntoj['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Gesamt</label>
		<label><?php echo $nto['Anzahl']; ?></label>
		<label><?php echo number_format($nto['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($nto['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label><b>Fälligkeiten</b></label>
		<br class="fix"/>
		<label>Diesen Monat</label>
		<label><?php echo $ntfm['Anzahl']; ?></label>
		<label><?php echo number_format($ntfm['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntfm['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Quartal</label>
		<label><?php echo $ntfq['Anzahl']; ?></label>
		<label><?php echo number_format($ntfq['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntfq['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Dieses Jahr</label>
		<label><?php echo $ntfj['Anzahl']; ?></label>
		<label><?php echo number_format($ntfj['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntfj['Mwst'], '2', ',', '.'); ?> €</label>
		<br class="fix"/>
		<label>Gesamt</label>
		<label><?php echo $ntf['Anzahl']; ?></label>
		<label><?php echo number_format($ntf['Summe'], '2', ',', '.'); ?> €</label>
		<label><?php echo number_format($ntf['Mwst'], '2', ',', '.'); ?> €</label>
	</fieldset>
</div>
