Verbesserte EÜR-Abrechnung
This commit is contained in:
@@ -172,9 +172,13 @@ class CostUnitRepository {
|
||||
* damit immer dieselbe Gliederung, und eine fehlende Zeile lässt sich nicht mit einer vergessenen
|
||||
* verwechseln.
|
||||
*
|
||||
* Gespendete Auslagen zählen hier mit: Für die Einnahmen-Überschuss-Rechnung ist die Spende eine Ausgabe
|
||||
* ihres Typs und zugleich eine Einnahme. Mit `$donationsOnly` liefert die Methode genau diesen Spendenanteil
|
||||
* in derselben Gliederung -- die Gegenbuchungen lassen sich so ihrer Ausgabenkategorie zuordnen.
|
||||
*
|
||||
* @return array<string, array{type: InvoiceType, invoices: array<int, Invoice>, sum: Amount}>
|
||||
*/
|
||||
public function groupExpensesByType(CostUnit $costUnit) : array {
|
||||
public function groupExpensesByType(CostUnit $costUnit, bool $donationsOnly = false) : array {
|
||||
$groups = [];
|
||||
|
||||
foreach (InvoiceType::countingAsExpense() as $invoiceType) {
|
||||
@@ -186,7 +190,11 @@ class CostUnitRepository {
|
||||
}
|
||||
|
||||
foreach ($costUnit->invoices()->orderBy('invoice_number')->get() as $invoice) {
|
||||
if (!self::countsAsExpense($invoice) || !isset($groups[$invoice->type])) {
|
||||
if (
|
||||
!self::isBooked($invoice) ||
|
||||
!isset($groups[$invoice->type]) ||
|
||||
($donationsOnly && !$invoice->donation)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -201,14 +209,22 @@ class CostUnitRepository {
|
||||
* Ob ein Beleg als Ausgabe zählt.
|
||||
*
|
||||
* Abgelehnt und gelöscht sind keine Ausgabe, weil kein Geld fließt. Dasselbe gilt für eine gespendete
|
||||
* Auslage: Auf die Auszahlung wurde verzichtet, die Kostenstelle gibt nichts aus.
|
||||
* Auslage: Auf die Auszahlung wurde verzichtet, die Kostenstelle gibt nichts aus. Die Einnahmen-Überschuss-
|
||||
* Rechnung sieht das anders und bucht die Spende als Ausgabe und Einnahme, siehe
|
||||
* {@see self::groupExpensesByType()}.
|
||||
*/
|
||||
private static function countsAsExpense(Invoice $invoice) : bool {
|
||||
return self::isBooked($invoice) && !$invoice->donation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob ein Beleg überhaupt gebucht ist -- abgelehnt und gelöscht sind es nicht.
|
||||
*/
|
||||
private static function isBooked(Invoice $invoice) : bool {
|
||||
return !in_array($invoice->status, [
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED,
|
||||
InvoiceStatus::INVOICE_STATUS_DELETED,
|
||||
], true)
|
||||
&& !$invoice->donation;
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED,
|
||||
InvoiceStatus::INVOICE_STATUS_DELETED,
|
||||
], true);
|
||||
}
|
||||
|
||||
public function sumupEstimatedByInvoiceType(CostUnit $costUnit, InvoiceType $invoiceType) : Amount {
|
||||
|
||||
Reference in New Issue
Block a user