Implemented Event Budget

This commit is contained in:
2026-05-26 18:12:42 +02:00
parent 575fb27018
commit 28ffbdb696
17 changed files with 422 additions and 143 deletions
+28
View File
@@ -3,6 +3,8 @@
namespace App\Repositories;
use App\Models\CostUnit;
use App\Models\CostUnitEstimate;
use App\ValueObjects\Amount;
class EstimatesRepository {
public function getEstimates(CostUnit $costUnit, string $estimateType) : array {
@@ -13,4 +15,30 @@ class EstimatesRepository {
return $return;
}
public function getById(int $estimateId, bool $accessCheck = true) : ?CostUnitEstimate {
$estimate = CostUnitEstimate::find($estimateId);
if ($estimate === null) {
return null;
}
if ($accessCheck) {
$costUnitRepository = new CostUnitRepository();
if (null === $costUnitRepository->getById($estimate->cost_unit_id)) {
return null;
}
}
return $estimate;
}
public function getTotalAmount(CostUnit $costUnit, string $estimateType) : Amount {
$total = new Amount(0, 'Euro');
foreach ($costUnit->estimates()->where('type', $estimateType)->get() as $estimate) {
$total->addAmount($estimate->calculateAmount());
}
return $total;
}
}