helper for handling billable fields (#1900)

This commit is contained in:
Kevin Papst
2020-08-20 15:03:57 +02:00
committed by GitHub
parent 7a1dada9dc
commit b9ee811cbf
12 changed files with 213 additions and 44 deletions

View File

@@ -0,0 +1,48 @@
<?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\Repository\Query;
interface BillableInterface
{
/**
* Returns the internal value (null = ignore billable, true = is billable, false = is not billable).
*
* @return bool|null
*/
public function getBillable(): ?bool;
/**
* Returns true if the billable flag should be used and should match true.
*
* @return bool
*/
public function isBillable(): bool;
/**
* Returns true if the billable flag should be used and should match false.
*
* @return bool
*/
public function isNotBillable(): bool;
/**
* Returns true if the billable flag should NOT be used.
*
* @return bool
*/
public function isIgnoreBillable(): bool;
/**
* Pas null if you want to ignore the billable flag.
*
* @param bool|null $isBillable
*/
public function setBillable(?bool $isBillable): void;
}

View File

@@ -0,0 +1,43 @@
<?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\Repository\Query;
trait BillableTrait
{
/**
* @var bool|null
*/
private $billable = null;
public function getBillable(): ?bool
{
return $this->billable;
}
public function isBillable(): bool
{
return $this->billable === true;
}
public function isNotBillable(): bool
{
return $this->billable === false;
}
public function isIgnoreBillable(): bool
{
return $this->billable === null;
}
public function setBillable(?bool $isBillable): void
{
$this->billable = $isBillable;
}
}

View File

@@ -25,7 +25,7 @@ class InvoiceQuery extends TimesheetQuery
public function __construct()
{
parent::__construct();
$this->setBillable(InvoiceQuery::STATE_BILLABLE);
$this->setBillable(true);
}
public function getTemplate(): ?InvoiceTemplate

View File

@@ -17,15 +17,15 @@ use App\Form\Model\DateRange;
/**
* Can be used for advanced timesheet repository queries.
*/
class TimesheetQuery extends ActivityQuery
class TimesheetQuery extends ActivityQuery implements BillableInterface
{
use BillableTrait;
public const STATE_ALL = 1;
public const STATE_RUNNING = 2;
public const STATE_STOPPED = 3;
public const STATE_EXPORTED = 4;
public const STATE_NOT_EXPORTED = 5;
public const STATE_BILLABLE = 6;
public const STATE_NOT_BILLABLE = 7;
public const TIMESHEET_ORDER_ALLOWED = ['begin', 'end', 'duration', 'rate', 'customer', 'project', 'activity', 'description'];
@@ -45,10 +45,6 @@ class TimesheetQuery extends ActivityQuery
* @var int
*/
protected $exported = self::STATE_ALL;
/**
* @var int
*/
private $billable = self::STATE_ALL;
/**
* @var \DateTime|null
*/
@@ -295,30 +291,6 @@ class TimesheetQuery extends ActivityQuery
return $this;
}
public function getBillable(): int
{
return $this->billable;
}
public function isBillable(): bool
{
return $this->billable === self::STATE_BILLABLE;
}
public function isNotBillable(): bool
{
return $this->billable === self::STATE_NOT_BILLABLE;
}
public function setBillable(int $billable): TimesheetQuery
{
if (\in_array($billable, [self::STATE_ALL, self::STATE_BILLABLE, self::STATE_NOT_BILLABLE], true)) {
$this->billable = $billable;
}
return $this;
}
public function getModifiedAfter(): ?\DateTime
{
return $this->modifiedAfter;