added user-specific rates (#1455)
This commit is contained in:
62
src/Repository/ActivityRateRepository.php
Normal file
62
src/Repository/ActivityRateRepository.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\ActivityRate;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
|
||||
class ActivityRateRepository extends EntityRepository
|
||||
{
|
||||
public function saveRate(ActivityRate $rate)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($rate);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteRate(ActivityRate $rate)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
$em->remove($rate);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (ORMException $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @return ActivityRate[]
|
||||
*/
|
||||
public function getRatesForActivity(Activity $activity): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('r, u, a')
|
||||
->from(ActivityRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.activity', 'a')
|
||||
->andWhere(
|
||||
$qb->expr()->eq('r.activity', ':activity')
|
||||
)
|
||||
->addOrderBy('u.alias')
|
||||
->setParameter('activity', $activity)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
62
src/Repository/CustomerRateRepository.php
Normal file
62
src/Repository/CustomerRateRepository.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerRate;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
|
||||
class CustomerRateRepository extends EntityRepository
|
||||
{
|
||||
public function saveRate(CustomerRate $rate)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($rate);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteRate(CustomerRate $rate)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
$em->remove($rate);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (ORMException $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
* @return CustomerRate[]
|
||||
*/
|
||||
public function getRatesForCustomer(Customer $customer): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('r, u, c')
|
||||
->from(CustomerRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.customer', 'c')
|
||||
->andWhere(
|
||||
$qb->expr()->eq('r.customer', ':customer')
|
||||
)
|
||||
->addOrderBy('u.alias')
|
||||
->setParameter('customer', $customer)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
62
src/Repository/ProjectRateRepository.php
Normal file
62
src/Repository/ProjectRateRepository.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectRate;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
|
||||
class ProjectRateRepository extends EntityRepository
|
||||
{
|
||||
public function saveRate(ProjectRate $rate)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($rate);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteRate(ProjectRate $rate)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
$em->remove($rate);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (ORMException $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project $project
|
||||
* @return ProjectRate[]
|
||||
*/
|
||||
public function getRatesForProject(Project $project): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('r, u, p')
|
||||
->from(ProjectRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.project', 'p')
|
||||
->andWhere(
|
||||
$qb->expr()->eq('r.project', ':project')
|
||||
)
|
||||
->addOrderBy('u.alias')
|
||||
->setParameter('project', $project)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,10 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\ActivityRate;
|
||||
use App\Entity\CustomerRate;
|
||||
use App\Entity\ProjectRate;
|
||||
use App\Entity\RateInterface;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Model\Statistic\Day;
|
||||
@@ -834,4 +838,73 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $timesheet
|
||||
* @return RateInterface[]
|
||||
*/
|
||||
public function findMatchingRates(Timesheet $timesheet): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('r, u, a')
|
||||
->from(ActivityRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.activity', 'a')
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.user', ':user'),
|
||||
$qb->expr()->isNull('r.user')
|
||||
),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.activity', ':activity'),
|
||||
$qb->expr()->isNull('r.activity')
|
||||
)
|
||||
)
|
||||
->setParameter('user', $timesheet->getUser())
|
||||
->setParameter('activity', $timesheet->getActivity())
|
||||
;
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('r, u, p')
|
||||
->from(ProjectRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.project', 'p')
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.user', ':user'),
|
||||
$qb->expr()->isNull('r.user')
|
||||
),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.project', ':project'),
|
||||
$qb->expr()->isNull('r.project')
|
||||
)
|
||||
)
|
||||
->setParameter('user', $timesheet->getUser())
|
||||
->setParameter('project', $timesheet->getProject())
|
||||
;
|
||||
$results = array_merge($results, $qb->getQuery()->getResult());
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('r, u, c')
|
||||
->from(CustomerRate::class, 'r')
|
||||
->leftJoin('r.user', 'u')
|
||||
->leftJoin('r.customer', 'c')
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.user', ':user'),
|
||||
$qb->expr()->isNull('r.user')
|
||||
),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.customer', ':customer'),
|
||||
$qb->expr()->isNull('r.customer')
|
||||
)
|
||||
)
|
||||
->setParameter('user', $timesheet->getUser())
|
||||
->setParameter('customer', $timesheet->getProject()->getCustomer())
|
||||
;
|
||||
$results = array_merge($results, $qb->getQuery()->getResult());
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user