$year."-01-01", ":to" => $year."-12-31"]); $types = []; $data_by_type = []; $sum_by_type = []; $investment_types = []; while ($t = $typeresult->fetch()) { $types[$t['id']] = $t['description']; $data_by_type[$t['id']] = []; $sum_by_type[$t['id']] = 0.0; if ($t['investment'] == 1) { $investment_types[$t['id']] = $t; } } 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); DEBUG($investment_types); $net_by_type = [0 => [-1 => [], 0 => [], 19 => []]]; $umsatzsteuer = 0.0; $ustbetraege = []; $vorsteuer = 0.0; foreach ($types as $id => $t) { if (count($data_by_type[$id]) == 0 || $t == 'Privatentnahme') { 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) { if (!isset($ustbetraege[$line['tax_rate']])) { $ustbetraege[$line['tax_rate']] = 0; } $ustbetraege[$line['tax_rate']] += $ust; $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."".$line['tax_rate']."%".$ust."".$gross."
Summe $t:$netsum$ustsum
'); } output("

Summen

"); output(''); $einnahmensumme = 0.0; output(""); $einnahmensumme += $net_by_type[0][19]; output(""); $einnahmensumme += $ustbetraege[19]; output(""); $einnahmensumme += $net_by_type[0][0]; output(""); $einnahmensumme += $net_by_type[0][-1]; $einzelust = ''; foreach ($ustbetraege as $satz => $ust) { if ($satz == 0 || $satz == 19) { continue; } output(""); $einnahmensumme += $ust; } output(""); output(""); $ausgabensumme = 0.0; foreach ($types as $id => $t) { if ($t == 'Gewerbesteuer') { continue; } if ($id == 0 || !isset($net_by_type[$id]) || array_key_exists($id, $investment_types)) { continue; } $ausgabensumme -= round($net_by_type[$id], 2); output(""); } output(""); $ausgabensumme -= $vorsteuer; output(""); output(""); output(""); output('
Einnahmen 19% USt netto".number_format($net_by_type[0][19], 2, ',', '.')." €
Einnahme Umsatzsteuer 19%".number_format($ustbetraege[19], 2, ',', '.')." €
Einnahmen innergem. Lieferung (steuerfrei §4/1b UStG)".number_format($net_by_type[0][0], 2, ',', '.')." €
Einnahmen andere Steuersätze".number_format($net_by_type[0][-1], 2, ',', '.')." €
- Umsatzsteuer $satz%".number_format($ust, 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, ',', '.')." €
'); foreach ($investment_types as $id => $type) { if (isset($net_by_type[$id])) { output('

Neue Anlagegüter '.$type['description'].': '.number_format(-$net_by_type[$id], 2, ',', '.')." €

"); } }