monthly budget, monthly report, unified report calculation (#2684)
This commit is contained in:
116
src/Entity/BudgetTrait.php
Normal file
116
src/Entity/BudgetTrait.php
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user