refactored invoice and export screens (#1046)
This commit is contained in:
@@ -50,7 +50,7 @@ class BaseQuery
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
private $currentUser;
|
||||
/**
|
||||
* @var Team[]
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ class BaseQuery
|
||||
|
||||
public function getCurrentUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
return $this->currentUser;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ class BaseQuery
|
||||
*/
|
||||
public function setCurrentUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->currentUser = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -15,23 +15,32 @@ class ExportQuery extends TimesheetQuery
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @var bool
|
||||
*/
|
||||
private $markAsExported = false;
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return ExportQuery
|
||||
*/
|
||||
public function setType(string $type)
|
||||
public function setType(string $type): ExportQuery
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isMarkAsExported(): bool
|
||||
{
|
||||
return $this->markAsExported;
|
||||
}
|
||||
|
||||
public function setMarkAsExported(bool $markAsExported): ExportQuery
|
||||
{
|
||||
$this->markAsExported = $markAsExported;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,32 +11,38 @@ namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
|
||||
/**
|
||||
* Can be used for invoice queries.
|
||||
*/
|
||||
class InvoiceQuery extends TimesheetQuery
|
||||
{
|
||||
/**
|
||||
* @var InvoiceTemplate
|
||||
*/
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* @return InvoiceTemplate
|
||||
* @var bool
|
||||
*/
|
||||
public function getTemplate()
|
||||
private $markAsExported = false;
|
||||
|
||||
public function getTemplate(): ?InvoiceTemplate
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceTemplate $template
|
||||
* @return InvoiceQuery
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
public function setTemplate(InvoiceTemplate $template): InvoiceQuery
|
||||
{
|
||||
$this->template = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isMarkAsExported(): bool
|
||||
{
|
||||
return $this->markAsExported;
|
||||
}
|
||||
|
||||
public function setMarkAsExported(bool $markAsExported): InvoiceQuery
|
||||
{
|
||||
$this->markAsExported = $markAsExported;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ class TimesheetQuery extends ActivityQuery
|
||||
* @var iterable
|
||||
*/
|
||||
protected $tags = [];
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private $users = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -58,6 +62,30 @@ class TimesheetQuery extends ActivityQuery
|
||||
$this->dateRange = new DateRange();
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
$this->users[$user->getId()] = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if (isset($this->users[$user->getId()])) {
|
||||
unset($this->users[$user->getId()]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function getUsers(): array
|
||||
{
|
||||
return array_values($this->users);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User|null
|
||||
*/
|
||||
|
||||
@@ -538,7 +538,9 @@ class TimesheetRepository extends EntityRepository
|
||||
$user[] = $query->getUser();
|
||||
}
|
||||
|
||||
if (null === $query->getUser() && null !== $query->getCurrentUser()) {
|
||||
$user = array_merge($user, $query->getUsers());
|
||||
|
||||
if (empty($user) && null !== $query->getCurrentUser()) {
|
||||
$currentUser = $query->getCurrentUser();
|
||||
|
||||
if (!$currentUser->isSuperAdmin() && !$currentUser->isAdmin()) {
|
||||
@@ -678,4 +680,25 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
*/
|
||||
public function setExported(array $timesheets)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->beginTransaction();
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb
|
||||
->update(Timesheet::class, 't')
|
||||
->set('t.exported', ':exported')
|
||||
->where($qb->expr()->in('t.id', ':ids'))
|
||||
->setParameter('exported', true, \PDO::PARAM_BOOL)
|
||||
->setParameter('ids', $timesheets)
|
||||
->getQuery()
|
||||
->execute();
|
||||
|
||||
$em->commit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user