helper for handling billable fields (#1900)
This commit is contained in:
@@ -346,4 +346,13 @@ abstract class AbstractToolbarForm extends AbstractType
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function addBillableChoice(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder->add('billable', BillableType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'placeholder' => null,
|
||||||
|
'search' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/Form/Toolbar/BillableType.php
Normal file
40
src/Form/Toolbar/BillableType.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?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\Form\Toolbar;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class BillableType extends AbstractType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'label' => 'label.billable',
|
||||||
|
'choices' => [
|
||||||
|
'entryState.all' => null,
|
||||||
|
'yes' => true,
|
||||||
|
'no' => false,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return ChoiceType::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/Form/Type/BillableType.php
Normal file
38
src/Form/Type/BillableType.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?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\Form\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom form field type to select if something is billable.
|
||||||
|
* To be used in combination with the invoicing system.
|
||||||
|
*/
|
||||||
|
class BillableType extends AbstractType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'label' => 'label.billable',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return YesNoType::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/Repository/Query/BillableInterface.php
Normal file
48
src/Repository/Query/BillableInterface.php
Normal 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;
|
||||||
|
}
|
||||||
43
src/Repository/Query/BillableTrait.php
Normal file
43
src/Repository/Query/BillableTrait.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ class InvoiceQuery extends TimesheetQuery
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->setBillable(InvoiceQuery::STATE_BILLABLE);
|
$this->setBillable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplate(): ?InvoiceTemplate
|
public function getTemplate(): ?InvoiceTemplate
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ use App\Form\Model\DateRange;
|
|||||||
/**
|
/**
|
||||||
* Can be used for advanced timesheet repository queries.
|
* 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_ALL = 1;
|
||||||
public const STATE_RUNNING = 2;
|
public const STATE_RUNNING = 2;
|
||||||
public const STATE_STOPPED = 3;
|
public const STATE_STOPPED = 3;
|
||||||
public const STATE_EXPORTED = 4;
|
public const STATE_EXPORTED = 4;
|
||||||
public const STATE_NOT_EXPORTED = 5;
|
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'];
|
public const TIMESHEET_ORDER_ALLOWED = ['begin', 'end', 'duration', 'rate', 'customer', 'project', 'activity', 'description'];
|
||||||
|
|
||||||
@@ -45,10 +45,6 @@ class TimesheetQuery extends ActivityQuery
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $exported = self::STATE_ALL;
|
protected $exported = self::STATE_ALL;
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $billable = self::STATE_ALL;
|
|
||||||
/**
|
/**
|
||||||
* @var \DateTime|null
|
* @var \DateTime|null
|
||||||
*/
|
*/
|
||||||
@@ -295,30 +291,6 @@ class TimesheetQuery extends ActivityQuery
|
|||||||
return $this;
|
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
|
public function getModifiedAfter(): ?\DateTime
|
||||||
{
|
{
|
||||||
return $this->modifiedAfter;
|
return $this->modifiedAfter;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
namespace App\Tests\Repository\Query;
|
namespace App\Tests\Repository\Query;
|
||||||
|
|
||||||
use App\Repository\Query\InvoiceQuery;
|
use App\Repository\Query\InvoiceQuery;
|
||||||
use App\Repository\Query\TimesheetQuery;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \App\Repository\Query\InvoiceQuery
|
* @covers \App\Repository\Query\InvoiceQuery
|
||||||
@@ -36,7 +35,11 @@ class InvoiceQueryTest extends TimesheetQueryTest
|
|||||||
$this->assertMarkAsExported($sut);
|
$this->assertMarkAsExported($sut);
|
||||||
$this->assertModifiedAfter($sut);
|
$this->assertModifiedAfter($sut);
|
||||||
|
|
||||||
self::assertEquals(TimesheetQuery::STATE_BILLABLE, $sut->getBillable());
|
self::assertTrue($sut->getBillable());
|
||||||
|
self::assertTrue($sut->isBillable());
|
||||||
|
self::assertFalse($sut->isNotBillable());
|
||||||
|
self::assertFalse($sut->isIgnoreBillable());
|
||||||
|
|
||||||
self::assertTrue($sut->isBillable());
|
self::assertTrue($sut->isBillable());
|
||||||
self::assertFalse($sut->isNotBillable());
|
self::assertFalse($sut->isNotBillable());
|
||||||
$this->assertBillable($sut);
|
$this->assertBillable($sut);
|
||||||
|
|||||||
@@ -37,7 +37,11 @@ class TimesheetQueryTest extends BaseQueryTest
|
|||||||
$this->assertSearchTerm($sut);
|
$this->assertSearchTerm($sut);
|
||||||
$this->assertModifiedAfter($sut);
|
$this->assertModifiedAfter($sut);
|
||||||
|
|
||||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getBillable());
|
self::assertNull($sut->getBillable());
|
||||||
|
self::assertFalse($sut->isBillable());
|
||||||
|
self::assertFalse($sut->isNotBillable());
|
||||||
|
self::assertTrue($sut->isIgnoreBillable());
|
||||||
|
|
||||||
self::assertFalse($sut->isBillable());
|
self::assertFalse($sut->isBillable());
|
||||||
self::assertFalse($sut->isNotBillable());
|
self::assertFalse($sut->isNotBillable());
|
||||||
$this->assertBillable($sut);
|
$this->assertBillable($sut);
|
||||||
@@ -140,22 +144,22 @@ class TimesheetQueryTest extends BaseQueryTest
|
|||||||
|
|
||||||
protected function assertBillable(TimesheetQuery $sut)
|
protected function assertBillable(TimesheetQuery $sut)
|
||||||
{
|
{
|
||||||
self::assertInstanceOf(TimesheetQuery::class, $sut->setBillable(TimesheetQuery::STATE_ALL));
|
$sut->setBillable(null);
|
||||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getBillable());
|
self::assertNull($sut->getBillable());
|
||||||
self::assertFalse($sut->isBillable());
|
self::assertFalse($sut->isBillable());
|
||||||
self::assertFalse($sut->isNotBillable());
|
self::assertFalse($sut->isNotBillable());
|
||||||
|
self::assertTrue($sut->isIgnoreBillable());
|
||||||
|
|
||||||
$sut->setBillable(PHP_INT_MAX);
|
$sut->setBillable(true);
|
||||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getBillable());
|
self::assertTrue($sut->getBillable());
|
||||||
|
|
||||||
$sut->setBillable(TimesheetQuery::STATE_BILLABLE);
|
|
||||||
self::assertEquals(TimesheetQuery::STATE_BILLABLE, $sut->getBillable());
|
|
||||||
self::assertTrue($sut->isBillable());
|
self::assertTrue($sut->isBillable());
|
||||||
self::assertFalse($sut->isNotBillable());
|
self::assertFalse($sut->isNotBillable());
|
||||||
|
self::assertFalse($sut->isIgnoreBillable());
|
||||||
|
|
||||||
$sut->setBillable(TimesheetQuery::STATE_NOT_BILLABLE);
|
$sut->setBillable(false);
|
||||||
self::assertEquals(TimesheetQuery::STATE_NOT_BILLABLE, $sut->getBillable());
|
self::assertFalse($sut->getBillable());
|
||||||
self::assertFalse($sut->isBillable());
|
self::assertFalse($sut->isBillable());
|
||||||
self::assertTrue($sut->isNotBillable());
|
self::assertTrue($sut->isNotBillable());
|
||||||
|
self::assertFalse($sut->isIgnoreBillable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,6 +340,10 @@
|
|||||||
<source>placeholder.type_message</source>
|
<source>placeholder.type_message</source>
|
||||||
<target>Schreibe Deine Nachricht...</target>
|
<target>Schreibe Deine Nachricht...</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="label.billable">
|
||||||
|
<source>label.billable</source>
|
||||||
|
<target>Abrechenbar</target>
|
||||||
|
</trans-unit>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Buttons & Actions
|
Buttons & Actions
|
||||||
|
|||||||
@@ -340,6 +340,10 @@
|
|||||||
<source>placeholder.type_message</source>
|
<source>placeholder.type_message</source>
|
||||||
<target>Type your message...</target>
|
<target>Type your message...</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="label.billable">
|
||||||
|
<source>label.billable</source>
|
||||||
|
<target>Billable</target>
|
||||||
|
</trans-unit>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Buttons & Actions
|
Buttons & Actions
|
||||||
|
|||||||
@@ -312,6 +312,10 @@
|
|||||||
<source>label.create_more</source>
|
<source>label.create_more</source>
|
||||||
<target>צור רשומות נוספות</target>
|
<target>צור רשומות נוספות</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="label.billable">
|
||||||
|
<source>label.billable</source>
|
||||||
|
<target>להחזר</target>
|
||||||
|
</trans-unit>
|
||||||
<trans-unit id="zldXQq6" resname="label.actions">
|
<trans-unit id="zldXQq6" resname="label.actions">
|
||||||
<source>label.actions</source>
|
<source>label.actions</source>
|
||||||
<target>פעולות</target>
|
<target>פעולות</target>
|
||||||
|
|||||||
Reference in New Issue
Block a user