search and export from invoice archive (#2408)
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user