$year."-01-01", ":to" => $year."-12-31")); $types = array(); $data_by_type = array(); $sum_by_type = array(); while ($t = $typeresult->fetch()) { $types[$t['id']] = $t['description']; $data_by_type[$t['id']] = array(); $sum_by_type[$t['id']] = 0.0; } while ($line = $dataresult->fetch()) { $data_by_type[$line['type']][] = $line; } output("Journal für $year (01.01.$year-31.12.$year, gruppiert nach Buchungskonten)"); DEBUG($types); $net_by_type = array(0 => array(-1 => array(), 0 => array(), 19 => array())); $umsatzsteuer = 0.0; $vorsteuer = 0.0; foreach ($types as $id => $t) { if (count($data_by_type[$id]) == 0) { continue; } output("

$t

"); output(''); $umsatz19proz = 0.0; $umsatz0proz = 0.0; $umsatzandereproz = 0.0; $netsum = 0.0; $ustsum = 0.0; foreach ($data_by_type[$id] as $line) { $net = $line['amount']; if ($line['gross'] == 1 && $line['tax_rate'] > 0) { $net = $net / (1.0+($line['tax_rate']/100)); } if ($line['direction'] == 'out') { $net = -$net; } $ust = $net * ($line['tax_rate']/100); if ($line['tax_rate'] == 19.0) { $umsatz19proz += $net; } elseif ($line['tax_rate'] == 0.0) { $umsatz0proz += $net; } else { $umsatzandereproz += $net; } $netsum += $net; $ustsum += $ust; if ($id == 0) { $umsatzsteuer += $ust; } else { $vorsteuer += $ust; } $gross = $net + $ust; $net = str_replace('.', ',', sprintf('%.2f €', $net)); $ust = str_replace('.', ',', sprintf('%.2f €', $ust)); $gross = str_replace('.', ',', sprintf('%.2f €', $gross)); output("\n"); } if ($id == 0) { $net_by_type[0][-1] = $umsatzandereproz; $net_by_type[0][0] = $umsatz0proz; $net_by_type[0][19] = $umsatz19proz; } else { $net_by_type[$id] = $netsum; } $netsum = str_replace('.', ',', sprintf('%.2f €', $netsum)); $ustsum = str_replace('.', ',', sprintf('%.2f €', $ustsum)); output("\n"); output('
".$line['date']."".$line['description']."".$net."".$ust."".$gross."
Summe $t:$netsum$ustsum
'); } output("

Summen

"); output(''); $einnahmensumme = 0.0; output(""); $einnahmensumme += $net_by_type[0][19]; output(""); $einnahmensumme += $net_by_type[0][0]; output(""); $einnahmensumme += $net_by_type[0][-1]; output(""); $einnahmensumme += $umsatzsteuer; output(""); output(""); $ausgabensumme = 0.0; foreach ($types as $id => $t) { if ($id == 0 || !isset($net_by_type[$id])) { continue; } $ausgabensumme -= $net_by_type[$id]; output(""); } output(""); $ausgabensumme -= $vorsteuer; output(""); output(""); output(""); output('
Einnahmen 19% USt netto".number_format($net_by_type[0][19], 2, ',', '.')." €
Einnahmen innergem. Lieferung (steuerfrei §4/1b UStG)".number_format($net_by_type[0][0], 2, ',', '.')." €
Einnahmen EU-Ausland (VATMOSS)".number_format($net_by_type[0][-1], 2, ',', '.')." €
Einnahme Umsatzsteuer".number_format($umsatzsteuer, 2, ',', '.')." €
Summe Einnahmen:".number_format($einnahmensumme, 2, ',', '.')." €
".$t."".number_format(-$net_by_type[$id], 2, ',', '.')." €
Vorsteuer".number_format(-$vorsteuer, 2, ',', '.')." €
Summe Ausgaben:".number_format($ausgabensumme, 2, ',', '.')." €
Überschuss aus laufendem Betrieb:".number_format($einnahmensumme-$ausgabensumme, 2, ',', '.')." €
');