Improved handling for new invoices
This commit is contained in:
@@ -132,7 +132,7 @@ class CostUnitRepository {
|
||||
if (strlen($costUnit->name) > 15) {
|
||||
$costUnit->name = substr($costUnit->name, 8, 13) . '...';
|
||||
}
|
||||
$costUnit->totalAmount = $this->sumupAmounts($costUnit)->toString();
|
||||
$costUnit->totalAmount = $this->sumupUnhandledAmounts($costUnit)->toString();
|
||||
$returnData[] = $costUnit;
|
||||
}
|
||||
|
||||
@@ -174,8 +174,27 @@ class CostUnitRepository {
|
||||
$amount->addAmount(Amount::fromString($invoice->amount));
|
||||
}
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function sumupUnhandledAmounts(CostUnit $costUnit, bool $donatedAmount = false) : Amount {
|
||||
$amount = new Amount(0, '');
|
||||
|
||||
foreach ($costUnit->invoices()->get() as $invoice) {
|
||||
if (!in_array($invoice->status,
|
||||
[InvoiceStatus::INVOICE_STATUS_NEW, InvoiceStatus::INVOICE_STATUS_APPROVED])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
($donatedAmount && !$invoice->donation) ||
|
||||
(!$donatedAmount && $invoice->donation)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount->addAmount(Amount::fromString($invoice->amount));
|
||||
}
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function countInvoices(CostUnit $costUnit) : array {
|
||||
|
||||
Reference in New Issue
Block a user