search and export from invoice archive (#2408)
This commit is contained in:
58
src/Repository/Query/DateRangeTrait.php
Normal file
58
src/Repository/Query/DateRangeTrait.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
|
||||
use App\Form\Model\DateRange;
|
||||
|
||||
trait DateRangeTrait
|
||||
{
|
||||
/**
|
||||
* @var DateRange
|
||||
*/
|
||||
protected $dateRange;
|
||||
|
||||
public function getBegin(): ?\DateTime
|
||||
{
|
||||
if (null === $this->dateRange) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->dateRange->getBegin();
|
||||
}
|
||||
|
||||
public function setBegin(\DateTime $begin): void
|
||||
{
|
||||
$this->dateRange->setBegin($begin);
|
||||
}
|
||||
|
||||
public function getEnd(): ?\DateTime
|
||||
{
|
||||
if (null === $this->dateRange) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->dateRange->getEnd();
|
||||
}
|
||||
|
||||
public function setEnd(\DateTime $end): void
|
||||
{
|
||||
$this->dateRange->setEnd($end);
|
||||
}
|
||||
|
||||
public function getDateRange(): ?DateRange
|
||||
{
|
||||
return $this->dateRange;
|
||||
}
|
||||
|
||||
public function setDateRange(DateRange $dateRange): void
|
||||
{
|
||||
$this->dateRange = $dateRange;
|
||||
}
|
||||
}
|
||||
101
src/Repository/Query/InvoiceArchiveQuery.php
Normal file
101
src/Repository/Query/InvoiceArchiveQuery.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Invoice;
|
||||
use App\Form\Model\DateRange;
|
||||
|
||||
/**
|
||||
* Query for created invoices.
|
||||
*/
|
||||
class InvoiceArchiveQuery extends BaseQuery
|
||||
{
|
||||
use DateRangeTrait;
|
||||
|
||||
public const INVOICE_ARCHIVE_ORDER_ALLOWED = [
|
||||
'date', 'customer', 'total'
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter for invoice status (by default all)
|
||||
* @var string[]
|
||||
*/
|
||||
private $status = [];
|
||||
/**
|
||||
* @var Customer[]
|
||||
*/
|
||||
private $customers = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'date',
|
||||
'order' => self::ORDER_DESC,
|
||||
'dateRange' => new DateRange(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function addCustomer(Customer $customer): void
|
||||
{
|
||||
$this->customers[] = $customer;
|
||||
}
|
||||
|
||||
public function setCustomers(array $customers): void
|
||||
{
|
||||
foreach ($customers as $customer) {
|
||||
$this->addCustomer($customer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer[]
|
||||
*/
|
||||
public function getCustomers(): array
|
||||
{
|
||||
return $this->customers;
|
||||
}
|
||||
|
||||
public function hasCustomers(): bool
|
||||
{
|
||||
return !empty($this->customers);
|
||||
}
|
||||
|
||||
public function hasStatus(): bool
|
||||
{
|
||||
return !empty($this->status);
|
||||
}
|
||||
|
||||
public function getStatus(): array
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $status
|
||||
*/
|
||||
public function setStatus(array $status): void
|
||||
{
|
||||
foreach ($status as $s) {
|
||||
$this->addStatus($s);
|
||||
}
|
||||
}
|
||||
|
||||
public function addStatus(string $status): void
|
||||
{
|
||||
if (!\in_array($status, [Invoice::STATUS_NEW, Invoice::STATUS_PENDING, Invoice::STATUS_PAID])) {
|
||||
throw new \InvalidArgumentException('Unknown invoice status given.');
|
||||
}
|
||||
|
||||
if (!\in_array($status, $this->status)) {
|
||||
$this->status[] = $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,9 @@ namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
|
||||
/**
|
||||
* Find items (eg timesheets) for creating a new invoice.
|
||||
*/
|
||||
class InvoiceQuery extends TimesheetQuery
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ use App\Form\Model\DateRange;
|
||||
class TimesheetQuery extends ActivityQuery implements BillableInterface
|
||||
{
|
||||
use BillableTrait;
|
||||
use DateRangeTrait;
|
||||
|
||||
public const STATE_ALL = 1;
|
||||
public const STATE_RUNNING = 2;
|
||||
@@ -49,10 +50,6 @@ class TimesheetQuery extends ActivityQuery implements BillableInterface
|
||||
* @var \DateTime|null
|
||||
*/
|
||||
private $modifiedAfter;
|
||||
/**
|
||||
* @var DateRange
|
||||
*/
|
||||
protected $dateRange;
|
||||
/**
|
||||
* @var iterable
|
||||
*/
|
||||
@@ -230,42 +227,6 @@ class TimesheetQuery extends ActivityQuery implements BillableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBegin(): ?\DateTime
|
||||
{
|
||||
return $this->dateRange->getBegin();
|
||||
}
|
||||
|
||||
public function setBegin(\DateTime $begin): TimesheetQuery
|
||||
{
|
||||
$this->dateRange->setBegin($begin);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEnd(): ?\DateTime
|
||||
{
|
||||
return $this->dateRange->getEnd();
|
||||
}
|
||||
|
||||
public function setEnd(\DateTime $end): TimesheetQuery
|
||||
{
|
||||
$this->dateRange->setEnd($end);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateRange(): DateRange
|
||||
{
|
||||
return $this->dateRange;
|
||||
}
|
||||
|
||||
public function setDateRange(DateRange $dateRange): TimesheetQuery
|
||||
{
|
||||
$this->dateRange = $dateRange;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTags(bool $allowUnknown = false): iterable
|
||||
{
|
||||
if (empty($this->tags)) {
|
||||
|
||||
Reference in New Issue
Block a user