change data filter on project month report (#2911)

This commit is contained in:
Kevin Papst
2021-11-05 09:45:12 +01:00
committed by GitHub
parent 042c119058
commit c8854b0775
15 changed files with 199 additions and 36 deletions

View File

@@ -33,7 +33,7 @@ final class ProjectDateRangeController extends AbstractController
$form = $this->createForm(ProjectDateRangeForm::class, $query, [
'timezone' => $user->getTimezone()
]);
$form->submit($request->query->all(), false);
$form->handleRequest($request);
$dateRange = new DateRange(true);
$dateRange->setBegin($query->getMonth());

View File

@@ -18,6 +18,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
class BudgetType extends AbstractType
{
public const TYPE_MONTH = 'month';
/**
* {@inheritdoc}
*/
@@ -25,9 +27,12 @@ class BudgetType extends AbstractType
{
$resolver->setDefaults([
'label' => 'label.budgetType',
// not yet translated in enough languages
//'placeholder' => 'label.budgetType_full',
'required' => false,
'search' => false,
'choices' => [
'label.budgetType_month' => 'month',
'label.budgetType_month' => self::TYPE_MONTH,
],
]);
}

View File

@@ -152,7 +152,7 @@ class ProjectStatisticService
->setParameter('end', $end, Types::DATETIME_MUTABLE)
;
if ($query->isOnlyWithRecords()) {
if (!$query->isIncludeNoWork()) {
$qb2 = $this->repository->createQueryBuilder('t1');
$qb2
->select('1')
@@ -163,15 +163,28 @@ class ProjectStatisticService
$qb->andWhere($qb->expr()->exists($qb2));
}
if (!$query->isIncludeNoBudget()) {
$qb
->andWhere(
$qb->expr()->orX(
$qb->expr()->gt('p.budget', 0.0),
$qb->expr()->gt('p.timeBudget', 0)
)
if ($query->isIncludeNoBudget()) {
$qb->andWhere(
$qb->expr()->eq('p.budget', 0.0),
$qb->expr()->eq('p.timeBudget', 0)
);
} else {
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->gt('p.budget', 0.0),
$qb->expr()->gt('p.timeBudget', 0)
)
;
);
if ($query->isBudgetTypeMonthly()) {
$qb->andWhere(
$qb->expr()->eq('p.budgetType', ':typeMonth')
);
$qb->setParameter('typeMonth', 'month');
} else {
$qb->andWhere(
$qb->expr()->isNull('p.budgetType')
);
}
}
if ($query->getCustomer() !== null) {

View File

@@ -13,6 +13,7 @@ use App\Form\Type\CustomerType;
use App\Form\Type\MonthPickerType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -45,9 +46,20 @@ class ProjectDateRangeForm extends AbstractType
'model_timezone' => $options['timezone'],
]);
$builder->add('includeNoBudget', CheckboxType::class, [
$builder->add('includeNoWork', CheckboxType::class, [
'required' => false,
'label' => 'label.includeNoBudget',
'label' => 'label.includeNoWork',
]);
$builder->add('budgetType', ChoiceType::class, [
'required' => true,
'multiple' => false,
'expanded' => true,
'choices' => [
'label.includeNoBudget' => 'none',
'label.includeBudgetType_full' => 'full',
'label.includeBudgetType_month' => 'month',
],
]);
}

View File

@@ -27,8 +27,8 @@ final class ProjectDateRangeQuery
*/
private $customer;
private $includeNoBudget = false;
private $onlyWithRecords = false;
private $includeNoWork = true;
private $budgetType = 'month';
public function __construct(\DateTime $month, User $user)
{
@@ -38,22 +38,17 @@ final class ProjectDateRangeQuery
public function isIncludeNoBudget(): bool
{
return $this->includeNoBudget;
return $this->budgetType === 'none';
}
public function setIncludeNoBudget(bool $includeNoBudget): void
public function isIncludeNoWork(): bool
{
$this->includeNoBudget = $includeNoBudget;
return $this->includeNoWork;
}
public function isOnlyWithRecords(): bool
public function setIncludeNoWork(bool $includeNoWork): void
{
return $this->onlyWithRecords;
}
public function setOnlyWithRecords(bool $onlyWithRecords): void
{
$this->onlyWithRecords = $onlyWithRecords;
$this->includeNoWork = $includeNoWork;
}
public function getUser(): ?User
@@ -61,12 +56,12 @@ final class ProjectDateRangeQuery
return $this->user;
}
public function getMonth(): \DateTime
public function getMonth(): ?\DateTime
{
return $this->month;
}
public function setMonth(\DateTime $month): void
public function setMonth(?\DateTime $month): void
{
$this->month = $month;
}
@@ -80,4 +75,19 @@ final class ProjectDateRangeQuery
{
$this->customer = $customer;
}
public function isBudgetTypeMonthly(): bool
{
return $this->budgetType === 'month';
}
public function getBudgetType(): ?string
{
return $this->budgetType;
}
public function setBudgetType(?string $budgetType): void
{
$this->budgetType = $budgetType;
}
}