monthly budget, monthly report, unified report calculation (#2684)

This commit is contained in:
Kevin Papst
2021-08-06 18:38:41 +02:00
committed by GitHub
parent 21f785638c
commit cefd747e91
196 changed files with 5031 additions and 2167 deletions

View File

@@ -114,11 +114,12 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
}
try {
$user = null;
if (true === $this->queryWithUser) {
return $this->repository->getStatistic($this->query, $begin, $end, $this->user);
} else {
return $this->repository->getStatistic($this->query, $begin, $end, null);
$user = $this->user;
}
return $this->repository->getStatistic($this->query, $begin, $end, $user);
} catch (\Exception $ex) {
throw new WidgetException(
'Failed loading widget data: ' . $ex->getMessage()

View File

@@ -13,17 +13,22 @@ use App\Entity\Project;
use App\Entity\Team;
use App\Entity\User;
use App\Project\ProjectStatisticService;
use App\Repository\Loader\ProjectLoader;
use App\Repository\Loader\TeamLoader;
use Doctrine\ORM\EntityManagerInterface;
class UserTeamProjects extends SimpleWidget implements AuthorizedWidget, UserWidget
{
private $statisticService;
private $entityManager;
public function __construct(ProjectStatisticService $statisticService)
public function __construct(ProjectStatisticService $statisticService, EntityManagerInterface $entityManager)
{
$this->setId('UserTeamProjects');
$this->setTitle('label.my_team_projects');
$this->setOption('id', '');
$this->statisticService = $statisticService;
$this->entityManager = $entityManager;
}
public function getOptions(array $options = []): array
@@ -42,32 +47,35 @@ class UserTeamProjects extends SimpleWidget implements AuthorizedWidget, UserWid
$options = $this->getOptions($options);
/** @var User $user */
$user = $options['user'];
$projects = [];
$now = new \DateTime('now', new \DateTimeZone($user->getTimezone()));
$loader = new TeamLoader($this->entityManager);
$loader->loadResults($user->getTeams()->toArray());
$teamProjects = [];
$projects = [];
/** @var Team $team */
foreach ($user->getTeams() as $team) {
/** @var Project $project */
foreach ($team->getProjects() as $project) {
if (!$project->isVisibleAtDate($now)) {
continue;
if (!isset($projects[$project->getId()])) {
$teamProjects[$project->getId()] = $project;
}
$projects[$project->getId()] = $project;
}
}
$stats = [];
$loader = new ProjectLoader($this->entityManager);
$loader->loadResults($teamProjects);
foreach ($projects as $id => $project) {
if ($project->getBudget() > 0 || $project->getTimeBudget() > 0) {
$stats[] = [
'project' => $project,
'stats' => $this->statisticService->getProjectStatistics($project),
];
foreach ($teamProjects as $id => $project) {
if (!$project->isVisibleAtDate($now) || !$project->hasBudgets()) {
continue;
}
$projects[$project->getId()] = $project;
}
return $stats;
return $this->statisticService->getBudgetStatisticModelForProjects($projects, $now);
}
/**