Implemented Event Budget
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user