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

@@ -50,8 +50,11 @@ use Symfony\Component\Validator\Constraints as Assert;
* @Exporter\Order({"id", "name", "project", "budget", "timeBudget", "color", "visible", "comment"})
* @Exporter\Expose("project", label="label.project", exp="object.getProject() === null ? null : object.getProject().getName()")
*/
class Activity implements EntityWithMetaFields
class Activity implements EntityWithMetaFields, EntityWithBudget
{
use BudgetTrait;
use ColorTrait;
/**
* Internal ID
*
@@ -120,40 +123,6 @@ class Activity implements EntityWithMetaFields
* @Assert\NotNull()
*/
private $visible = true;
// keep the traits here, for placing the column at the "correct" position
use ColorTrait;
/**
* The total monetary budget, will be zero if unconfigured.
*
* @var float
*
* @Serializer\Expose()
* @Serializer\Groups({"Activity_Entity"})
*
* @ Exporter\Expose(label="label.budget")
*
* @ORM\Column(name="budget", type="float", nullable=false)
* @Assert\Range(min=0.00, max=900000000000.00)
* @Assert\NotNull()
*/
private $budget = 0.00;
/**
* The time budget in seconds, will be zero if unconfigured.
*
* @var int
*
* @Serializer\Expose()
* @Serializer\Groups({"Activity_Entity"})
*
* @ Exporter\Expose(label="label.timeBudget", type="duration")
*
* @ORM\Column(name="time_budget", type="integer", nullable=false)
* @Assert\Range(min=0, max=2145600000)
* @Assert\NotNull()
*/
private $timeBudget = 0;
/**
* Meta fields
*
@@ -258,40 +227,6 @@ class Activity implements EntityWithMetaFields
return $this->visible;
}
public function setBudget(float $budget): Activity
{
$this->budget = $budget;
return $this;
}
public function getBudget(): float
{
return $this->budget;
}
public function hasBudget(): bool
{
return $this->budget > 0.00;
}
public function setTimeBudget(int $seconds): Activity
{
$this->timeBudget = $seconds;
return $this;
}
public function getTimeBudget(): int
{
return $this->timeBudget;
}
public function hasTimeBudget(): bool
{
return $this->timeBudget > 0;
}
/**
* @return Collection|MetaTableTypeInterface[]
*/

116
src/Entity/BudgetTrait.php Normal file
View File

@@ -0,0 +1,116 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
trait BudgetTrait
{
/**
* The total monetary budget, will be zero if unconfigured.
*
* @var float
*
* @Serializer\Expose()
* @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"})
*
* @ Exporter\Expose(label="label.budget")
*
* @ORM\Column(name="budget", type="float", nullable=false)
* @Assert\Range(min=0.00, max=900000000000.00)
* @Assert\NotNull()
*/
private $budget = 0.00;
/**
* The time budget in seconds, will be zero if unconfigured.
*
* @var int
*
* @Serializer\Expose()
* @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"})
*
* @ Exporter\Expose(label="label.timeBudget", type="duration")
*
* @ORM\Column(name="time_budget", type="integer", nullable=false)
* @Assert\Range(min=0, max=2145600000)
* @Assert\NotNull()
*/
private $timeBudget = 0;
/**
* The type of budget:
* - null = default / full time
* - month = monthly budget
*
* @var string
*
* @Serializer\Expose()
* @Serializer\Groups({"Activity_Entity", "Project_Entity", "Customer_Entity"})
*
* @ Exporter\Expose(label="label.timeBudget", type="duration")
*
* @ORM\Column(name="budget_type", type="string", length=10, nullable=true)
*/
private $budgetType;
public function setBudget(float $budget): void
{
$this->budget = $budget;
}
public function getBudget(): float
{
return $this->budget;
}
public function hasBudget(): bool
{
return $this->budget > 0.00;
}
public function setTimeBudget(int $seconds): void
{
$this->timeBudget = $seconds;
}
public function getTimeBudget(): int
{
return $this->timeBudget;
}
public function hasTimeBudget(): bool
{
return $this->timeBudget > 0;
}
public function setBudgetType(?string $budgetType = null): void
{
if ($budgetType !== null && !\in_array($budgetType, ['month'])) {
throw new \InvalidArgumentException('Unknown budget type: ' . $budgetType);
}
$this->budgetType = $budgetType;
}
public function getBudgetType(): ?string
{
return $this->budgetType;
}
public function isMonthlyBudget(): bool
{
return $this->hasBudgets() && $this->budgetType === 'month';
}
public function hasBudgets(): bool
{
return ($this->hasTimeBudget() || $this->hasBudget());
}
}

View File

@@ -30,10 +30,13 @@ use Symfony\Component\Validator\Constraints as Assert;
* @Exporter\Order({"id", "name", "company", "number", "vatId", "address", "contact","email", "phone", "mobile", "fax", "homepage", "country", "currency", "timezone", "budget", "timeBudget", "color", "visible", "teams", "comment"})
* @ Exporter\Expose("teams", label="label.team", exp="object.getTeams().toArray()", type="array")
*/
class Customer implements EntityWithMetaFields
class Customer implements EntityWithMetaFields, EntityWithBudget
{
public const DEFAULT_CURRENCY = 'EUR';
use BudgetTrait;
use ColorTrait;
/**
* @var int|null
*
@@ -251,40 +254,6 @@ class Customer implements EntityWithMetaFields
* @Assert\Length(max=64)
*/
private $timezone;
// keep the trait include exactly here, for placing the column at the correct position
use ColorTrait;
/**
* The total monetary budget, will be zero if not configured.
*
* @var float
*
* @Serializer\Expose()
* @Serializer\Groups({"Customer_Entity"})
*
* @ Exporter\Expose(label="label.budget")
*
* @ORM\Column(name="budget", type="float", nullable=false)
* @Assert\Range(min=0.00, max=900000000000.00)
* @Assert\NotNull()
*/
private $budget = 0.00;
/**
* The time budget in seconds, will be zero if not configured.
*
* @var int
*
* @Serializer\Expose()
* @Serializer\Groups({"Customer_Entity"})
*
* @ Exporter\Expose(label="label.timeBudget", type="duration")
*
* @ORM\Column(name="time_budget", type="integer", nullable=false)
* @Assert\Range(min=0, max=2145600000)
* @Assert\NotNull()
*/
private $timeBudget = 0;
/**
* Meta fields
*
@@ -528,40 +497,6 @@ class Customer implements EntityWithMetaFields
return $this->timezone;
}
public function setBudget(float $budget): Customer
{
$this->budget = $budget;
return $this;
}
public function getBudget(): float
{
return $this->budget;
}
public function hasBudget(): bool
{
return $this->budget > 0.00;
}
public function setTimeBudget(int $seconds): Customer
{
$this->timeBudget = $seconds;
return $this;
}
public function getTimeBudget(): int
{
return $this->timeBudget;
}
public function hasTimeBudget(): bool
{
return $this->timeBudget > 0;
}
/**
* @return Collection|MetaTableTypeInterface[]
*/

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity;
/**
* @internal
*/
interface EntityWithBudget
{
public function setBudget(float $budget): void;
public function getBudget(): float;
public function hasBudget(): bool;
public function setTimeBudget(int $seconds): void;
public function getTimeBudget(): int;
public function hasTimeBudget(): bool;
public function isMonthlyBudget(): bool;
public function getBudgetType(): ?string;
public function setBudgetType(?string $budgetType = null): void;
}

View File

@@ -52,8 +52,11 @@ use Symfony\Component\Validator\Constraints as Assert;
* @Exporter\Expose("customer", label="label.customer", exp="object.getCustomer() === null ? null : object.getCustomer().getName()")
* @ Exporter\Expose("teams", label="label.team", exp="object.getTeams().toArray()", type="array")
*/
class Project implements EntityWithMetaFields
class Project implements EntityWithMetaFields, EntityWithBudget
{
use BudgetTrait;
use ColorTrait;
/**
* Internal ID
*
@@ -192,40 +195,6 @@ class Project implements EntityWithMetaFields
* @Assert\NotNull()
*/
private $visible = true;
// keep the trait include exactly here, for placing the column at the correct position
use ColorTrait;
/**
* The total monetary budget, will be zero if not configured.
*
* @var float
*
* @Serializer\Expose()
* @Serializer\Groups({"Project_Entity"})
*
* @ Exporter\Expose(label="label.budget")
*
* @ORM\Column(name="budget", type="float", nullable=false)
* @Assert\Range(min=0.00, max=900000000000.00)
* @Assert\NotNull()
*/
private $budget = 0.00;
/**
* The time budget in seconds, will be zero if not configured.
*
* @var int
*
* @Serializer\Expose()
* @Serializer\Groups({"Project_Entity"})
*
* @ Exporter\Expose(label="label.timeBudget", type="duration")
*
* @ORM\Column(name="time_budget", type="integer", nullable=false)
* @Assert\Range(min=0, max=2145600000)
* @Assert\NotNull()
*/
private $timeBudget = 0;
/**
* Meta fields
*
@@ -422,40 +391,6 @@ class Project implements EntityWithMetaFields
return $this;
}
public function setBudget(float $budget): Project
{
$this->budget = $budget;
return $this;
}
public function getBudget(): float
{
return $this->budget;
}
public function hasBudget(): bool
{
return $this->budget > 0.00;
}
public function setTimeBudget(int $seconds): Project
{
$this->timeBudget = $seconds;
return $this;
}
public function getTimeBudget(): int
{
return $this->timeBudget;
}
public function hasTimeBudget(): bool
{
return $this->timeBudget > 0;
}
/**
* @return Collection|MetaTableTypeInterface[]
*/

View File

@@ -30,6 +30,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Index(columns={"start_time"}),
* @ORM\Index(columns={"start_time","end_time"}),
* @ORM\Index(columns={"start_time","end_time","user"}),
* @ORM\Index(columns={"date_tz","user"}),
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\TimesheetRepository")
@@ -108,6 +109,16 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* Reflects the date in the users timezone (not in UTC).
* This value is automatically set through the begin column and ONLY used in statistic queries.
*
* @var \DateTime
*
* @ORM\Column(name="date_tz", type="date", nullable=false)
* @Assert\NotNull()
*/
private $date;
/**
* @var DateTime
*
@@ -360,6 +371,8 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
{
$this->begin = $begin;
$this->timezone = $begin->getTimezone()->getName();
// make sure that the original date is always
$this->date = new DateTime($begin->format('Y-m-d 00:00:00'), new DateTimeZone('UTC'));
return $this;
}
@@ -588,8 +601,8 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
}
/**
* BE WARNED: this method should NOT be used.
* It was ONLY introduced for the command "kimai:import-v1".
* BE WARNED: this method should NOT be used from outside.
* It is reserved for some very rare use-cases.
*
* @internal
* @param string $timezone