Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2617: Project forecast report #175

Merged
merged 43 commits into from
Oct 28, 2024

Conversation

jeppekroghitk
Copy link
Contributor

@jeppekroghitk jeppekroghitk commented Oct 9, 2024

Link to ticket

2617

Description

A report showing invoiced versus recorded hours for projects specified

Screenshot of the result

N/A

Checklist

  • My code is covered by test cases.
  • My code passes our test (all our tests).
  • My code passes our static analysis suite.
  • My code passes our continuous integration process.

jeppekroghitk and others added 24 commits October 9, 2024 10:37
@jeppekroghitk jeppekroghitk requested a review from tuj October 9, 2024 14:50
Copy link
Contributor

@tuj tuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major.

Can we add a file docs/reports.md that describe the different reports?

$forecastReportData->projects[$projectId] = new ForecastReportProjectData($projectId);
}

if (is_object($forecastReportData->projects[$projectId])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primarily because psalm i worried that $forecastReportData->projects[$projectId] is possible null. I rewrote it to check if it is an instance of ForecastReportProjectData, to make it feel a bit more cohesive.


// Get version details from issue
$issueVersions = $worklog->getIssue()->getVersions();
$issueVersion = count($issueVersions) > 0 ? implode('', array_map(function ($version) { return $version->getName(); }, $issueVersions->toArray())) : '[no version]';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the versions string be separated with ', ' instead of '' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. With Leantime as the data source, issues can only contain a single version, so i didn't think any of it.

I changed this.


public function buildForm(FormBuilderInterface $builder, array $options): void
{
$dataProviders = $this->dataProviderRepository->findAll();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need data providers?
Shouldn't we just show data from all or is there a need for this filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to keep. I removed it.

$from = new \DateTimeImmutable($periodStart->format('Y-m-d').' 00:00:00');
$to = new \DateTimeImmutable($periodEnd->format('Y-m-d').' 23:59:59');

return $this->createQueryBuilder('worklog')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you have 1000 invoices and 1000000 worklogs?
This should be paginated and processed in pages.
Otherwise, there will be memory issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something bad. I implemented this.

@jeppekroghitk jeppekroghitk requested review from tuj and removed request for tuj October 24, 2024 09:03
src/Service/ForecastReportService.php Show resolved Hide resolved
// Get worklog details
$worklogId = $worklog->getId();
$workerEmail = $worklog->getWorker();
$worker = $this->workerRepository->findOneBy(['email' => $workerEmail]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract alle worker email -> name mappings out of the loops to avoid unnecessary db lookups.

$totalItemCount = count($paginator);
$pagesCount = ceil($totalItemCount / $pageSize);

$items = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just return the paginator instead of this conversion to array? This results in unnecessary iterations.

return [
    'total_count' => $totalItemCount,
    'pages_count' => $pagesCount,
    'current_page' => $page,
    'page_size' => $pageSize,
    'paginator' => $paginator,
];

you can iterate it the same way as an array

foreach ($invoiceAttachedWorklogs['paginator'] as $worklog) {

src/Service/ForecastReportService.php Show resolved Hide resolved
public function getForecastReport(\DateTimeInterface $fromDate, \DateTimeInterface $toDate): ForecastReportData
{
$page = 1;
$pageSize = 200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to class constant

private const int PAGE_SIZE = 200;

@jeppekroghitk jeppekroghitk merged commit c13a72b into develop Oct 28, 2024
9 checks passed
@jeppekroghitk jeppekroghitk deleted the feature/2617-project-forecast-report branch October 28, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants