Skip to content

Commit

Permalink
Added dividends to chart
Browse files Browse the repository at this point in the history
  • Loading branch information
simba77 committed Aug 1, 2024
1 parent e8719f9 commit 925463d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Services/Deals/ClosedDealsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Entity\User;
use App\Repository\DealRepository;
use App\Repository\DividendRepository;
use App\Request\DTO\Deals\DealsFilterRequestDTO;
use App\Response\DTO\Deals\SummaryForClosedDealsDTO;
use App\Services\MarketData\Currencies\CurrencyService;
Expand All @@ -15,6 +16,7 @@ class ClosedDealsService
public function __construct(
private readonly DealRepository $dealRepository,
private readonly CurrencyService $currencyService,
private readonly DividendRepository $dividendRepository,
) {
}

Expand Down Expand Up @@ -72,6 +74,16 @@ public function getMonthlyDealsStat(User $user, ?DealsFilterRequestDTO $filterRe
}
}

$dividends = $this->dividendRepository->findAll();
foreach ($dividends as $dividend) {
$date = $dividend->getDate()?->format('Y.m') ?? '0';
if (isset($profitByMonths[$date])) {
$profitByMonths[$date] = bcadd($profitByMonths[$date], $dividend->getAmount(), 2);
} else {
$profitByMonths[$date] = $dividend->getAmount();
}
}

ksort($profitByMonths);

return ['profitByMonths' => $profitByMonths];
Expand Down

0 comments on commit 925463d

Please sign in to comment.