added internal rates (#1591)
This commit is contained in:
@@ -12,8 +12,11 @@ declare(strict_types=1);
|
||||
namespace App\API;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\ActivityRate;
|
||||
use App\Event\ActivityMetaDefinitionEvent;
|
||||
use App\Form\API\ActivityApiEditForm;
|
||||
use App\Form\API\ActivityRateApiForm;
|
||||
use App\Repository\ActivityRateRepository;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use App\Utils\SearchTerm;
|
||||
@@ -32,6 +35,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
/**
|
||||
* @RouteResource("Activity")
|
||||
* @SWG\Tag(name="Activity")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
@@ -49,12 +53,17 @@ class ActivityController extends BaseApiController
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $dispatcher;
|
||||
/**
|
||||
* @var ActivityRateRepository
|
||||
*/
|
||||
private $activityRateRepository;
|
||||
|
||||
public function __construct(ViewHandlerInterface $viewHandler, ActivityRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
public function __construct(ViewHandlerInterface $viewHandler, ActivityRepository $repository, EventDispatcherInterface $dispatcher, ActivityRateRepository $activityRateRepository)
|
||||
{
|
||||
$this->viewHandler = $viewHandler;
|
||||
$this->repository = $repository;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->activityRateRepository = $activityRateRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +285,7 @@ class ActivityController extends BaseApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a meta-field for an existing activity.
|
||||
* Sets the value of a meta-field for an existing activity
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
@@ -327,4 +336,166 @@ class ActivityController extends BaseApiController
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of all rates for one activity
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns a collection of activity rate entities",
|
||||
* @SWG\Schema(
|
||||
* type="array",
|
||||
* @SWG\Items(ref="#/definitions/ActivityRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The activity whose rates will be returned",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function getRatesAction(int $id): Response
|
||||
{
|
||||
/** @var Activity|null $activity */
|
||||
$activity = $this->repository->find($id);
|
||||
|
||||
if (null === $activity) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $activity)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rates = $this->activityRateRepository->getRatesForActivity($activity);
|
||||
|
||||
$view = new View($rates, 200);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ActivityRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one rate for an activity
|
||||
*
|
||||
* @SWG\Delete(
|
||||
* @SWG\Response(
|
||||
* response=204,
|
||||
* description="Returns no content: 204 on successful delete"
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The activity whose rate will be removed",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="rateId",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The rate to remove",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function deleteRateAction(string $id, string $rateId): Response
|
||||
{
|
||||
/** @var Activity|null $activity */
|
||||
$activity = $this->repository->find($id);
|
||||
|
||||
if (null === $activity) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $activity)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
/** @var ActivityRate|null $rate */
|
||||
$rate = $this->activityRateRepository->find($rateId);
|
||||
|
||||
if (null === $rate || $rate->getActivity() !== $activity) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$this->activityRateRepository->deleteRate($rate);
|
||||
|
||||
$view = new View(null, Response::HTTP_NO_CONTENT);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new rate to an activity
|
||||
*
|
||||
* @SWG\Post(
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns the new created rate",
|
||||
* @SWG\Schema(ref="#/definitions/ActivityRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The activity to add the rate for",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="body",
|
||||
* in="body",
|
||||
* required=true,
|
||||
* @SWG\Schema(ref="#/definitions/ActivityRateForm")
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function postRateAction(int $id, Request $request): Response
|
||||
{
|
||||
/** @var Activity|null $activity */
|
||||
$activity = $this->repository->find($id);
|
||||
|
||||
if (null === $activity) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $activity)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rate = new ActivityRate();
|
||||
$rate->setActivity($activity);
|
||||
|
||||
$form = $this->createForm(ActivityRateApiForm::class, $rate, [
|
||||
'method' => 'POST',
|
||||
]);
|
||||
|
||||
$form->setData($rate);
|
||||
$form->submit($request->request->all(), false);
|
||||
|
||||
if (false === $form->isValid()) {
|
||||
$view = new View($form, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ActivityRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
$this->activityRateRepository->saveRate($rate);
|
||||
|
||||
$view = new View($rate, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ActivityRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @SWG\Tag(name="Default")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
final class ConfigurationController extends BaseApiController
|
||||
|
||||
@@ -12,9 +12,12 @@ declare(strict_types=1);
|
||||
namespace App\API;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerRate;
|
||||
use App\Entity\User;
|
||||
use App\Event\CustomerMetaDefinitionEvent;
|
||||
use App\Form\API\CustomerApiEditForm;
|
||||
use App\Form\API\CustomerRateApiForm;
|
||||
use App\Repository\CustomerRateRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use App\Utils\SearchTerm;
|
||||
@@ -33,6 +36,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
/**
|
||||
* @RouteResource("Customer")
|
||||
* @SWG\Tag(name="Customer")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
@@ -50,12 +54,17 @@ class CustomerController extends BaseApiController
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $dispatcher;
|
||||
/**
|
||||
* @var CustomerRateRepository
|
||||
*/
|
||||
private $customerRateRepository;
|
||||
|
||||
public function __construct(ViewHandlerInterface $viewHandler, CustomerRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
public function __construct(ViewHandlerInterface $viewHandler, CustomerRepository $repository, EventDispatcherInterface $dispatcher, CustomerRateRepository $customerRateRepository)
|
||||
{
|
||||
$this->viewHandler = $viewHandler;
|
||||
$this->repository = $repository;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->customerRateRepository = $customerRateRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +75,7 @@ class CustomerController extends BaseApiController
|
||||
* description="Returns a collection of customer entities",
|
||||
* @SWG\Schema(
|
||||
* type="array",
|
||||
* @SWG\Items(ref="#/definitions/CustomerCollection")
|
||||
* @SWG\Items(ref="#/definitions/CustomerEntity")
|
||||
* )
|
||||
* )
|
||||
* @Rest\QueryParam(name="visible", requirements="\d+", strict=true, nullable=true, description="Visibility status to filter activities (1=visible, 2=hidden, 3=both)")
|
||||
@@ -249,7 +258,7 @@ class CustomerController extends BaseApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a meta-field for an existing customer.
|
||||
* Sets the value of a meta-field for an existing customer
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
@@ -300,4 +309,166 @@ class CustomerController extends BaseApiController
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of all rates for one customer
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns a collection of customer rate entities",
|
||||
* @SWG\Schema(
|
||||
* type="array",
|
||||
* @SWG\Items(ref="#/definitions/CustomerRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The customer whose rates will be returned",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function getRatesAction(int $id): Response
|
||||
{
|
||||
/** @var Customer|null $customer */
|
||||
$customer = $this->repository->find($id);
|
||||
|
||||
if (null === $customer) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $customer)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rates = $this->customerRateRepository->getRatesForCustomer($customer);
|
||||
|
||||
$view = new View($rates, 200);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'CustomerRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one rate for an customer
|
||||
*
|
||||
* @SWG\Delete(
|
||||
* @SWG\Response(
|
||||
* response=204,
|
||||
* description="Returns no content: 204 on successful delete"
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The customer whose rate will be removed",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="rateId",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The rate to remove",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function deleteRateAction(string $id, string $rateId): Response
|
||||
{
|
||||
/** @var Customer|null $customer */
|
||||
$customer = $this->repository->find($id);
|
||||
|
||||
if (null === $customer) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $customer)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
/** @var CustomerRate|null $rate */
|
||||
$rate = $this->customerRateRepository->find($rateId);
|
||||
|
||||
if (null === $rate || $rate->getCustomer() !== $customer) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$this->customerRateRepository->deleteRate($rate);
|
||||
|
||||
$view = new View(null, Response::HTTP_NO_CONTENT);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new rate to a customer
|
||||
*
|
||||
* @SWG\Post(
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns the new created rate",
|
||||
* @SWG\Schema(ref="#/definitions/CustomerRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The customer to add the rate for",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="body",
|
||||
* in="body",
|
||||
* required=true,
|
||||
* @SWG\Schema(ref="#/definitions/CustomerRateForm")
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function postRateAction(int $id, Request $request): Response
|
||||
{
|
||||
/** @var Customer|null $customer */
|
||||
$customer = $this->repository->find($id);
|
||||
|
||||
if (null === $customer) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $customer)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rate = new CustomerRate();
|
||||
$rate->setCustomer($customer);
|
||||
|
||||
$form = $this->createForm(CustomerRateApiForm::class, $rate, [
|
||||
'method' => 'POST',
|
||||
]);
|
||||
|
||||
$form->setData($rate);
|
||||
$form->submit($request->request->all(), false);
|
||||
|
||||
if (false === $form->isValid()) {
|
||||
$view = new View($form, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'CustomerRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
$this->customerRateRepository->saveRate($rate);
|
||||
|
||||
$view = new View($rate, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'CustomerRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\API;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectRate;
|
||||
use App\Entity\User;
|
||||
use App\Event\ProjectMetaDefinitionEvent;
|
||||
use App\Form\API\ProjectApiEditForm;
|
||||
use App\Form\API\ProjectRateApiForm;
|
||||
use App\Repository\ProjectRateRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
@@ -35,6 +39,7 @@ use Symfony\Component\Validator\Constraints;
|
||||
|
||||
/**
|
||||
* @RouteResource("Project")
|
||||
* @SWG\Tag(name="Project")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
@@ -56,13 +61,18 @@ class ProjectController extends BaseApiController
|
||||
* @var UserDateTimeFactory
|
||||
*/
|
||||
private $dateTime;
|
||||
/**
|
||||
* @var ProjectRateRepository
|
||||
*/
|
||||
private $projectRateRepository;
|
||||
|
||||
public function __construct(ViewHandlerInterface $viewHandler, ProjectRepository $repository, EventDispatcherInterface $dispatcher, UserDateTimeFactory $dateTime)
|
||||
public function __construct(ViewHandlerInterface $viewHandler, ProjectRepository $repository, EventDispatcherInterface $dispatcher, UserDateTimeFactory $dateTime, ProjectRateRepository $projectRateRepository)
|
||||
{
|
||||
$this->viewHandler = $viewHandler;
|
||||
$this->repository = $repository;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dateTime = $dateTime;
|
||||
$this->projectRateRepository = $projectRateRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +309,7 @@ class ProjectController extends BaseApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a meta-field for an existing project.
|
||||
* Sets the value of a meta-field for an existing project
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
@@ -350,4 +360,166 @@ class ProjectController extends BaseApiController
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of all rates for one project
|
||||
*
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns a collection of project rate entities",
|
||||
* @SWG\Schema(
|
||||
* type="array",
|
||||
* @SWG\Items(ref="#/definitions/ProjectRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The project whose rates will be returned",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function getRatesAction(int $id): Response
|
||||
{
|
||||
/** @var Project|null $project */
|
||||
$project = $this->repository->find($id);
|
||||
|
||||
if (null === $project) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $project)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rates = $this->projectRateRepository->getRatesForProject($project);
|
||||
|
||||
$view = new View($rates, 200);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ProjectRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one rate for an project
|
||||
*
|
||||
* @SWG\Delete(
|
||||
* @SWG\Response(
|
||||
* response=204,
|
||||
* description="Returns no content: 204 on successful delete"
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The project whose rate will be removed",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="rateId",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The rate to remove",
|
||||
* required=true,
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function deleteRateAction(string $id, string $rateId): Response
|
||||
{
|
||||
/** @var Project|null $project */
|
||||
$project = $this->repository->find($id);
|
||||
|
||||
if (null === $project) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $project)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
/** @var ProjectRate|null $rate */
|
||||
$rate = $this->projectRateRepository->find($rateId);
|
||||
|
||||
if (null === $rate || $rate->getProject() !== $project) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$this->projectRateRepository->deleteRate($rate);
|
||||
|
||||
$view = new View(null, Response::HTTP_NO_CONTENT);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new rate to an project
|
||||
*
|
||||
* @SWG\Post(
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Returns the new created rate",
|
||||
* @SWG\Schema(ref="#/definitions/ProjectRate")
|
||||
* )
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* type="integer",
|
||||
* description="The project to add the rate for",
|
||||
* required=true,
|
||||
* )
|
||||
* @SWG\Parameter(
|
||||
* name="body",
|
||||
* in="body",
|
||||
* required=true,
|
||||
* @SWG\Schema(ref="#/definitions/ProjectRateForm")
|
||||
* )
|
||||
*
|
||||
* @ApiSecurity(name="apiUser")
|
||||
* @ApiSecurity(name="apiToken")
|
||||
*/
|
||||
public function postRateAction(int $id, Request $request): Response
|
||||
{
|
||||
/** @var Project|null $project */
|
||||
$project = $this->repository->find($id);
|
||||
|
||||
if (null === $project) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (!$this->isGranted('edit', $project)) {
|
||||
throw new AccessDeniedHttpException('Access denied.');
|
||||
}
|
||||
|
||||
$rate = new ProjectRate();
|
||||
$rate->setProject($project);
|
||||
|
||||
$form = $this->createForm(ProjectRateApiForm::class, $rate, [
|
||||
'method' => 'POST',
|
||||
]);
|
||||
|
||||
$form->setData($rate);
|
||||
$form->submit($request->request->all(), false);
|
||||
|
||||
if (false === $form->isValid()) {
|
||||
$view = new View($form, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ProjectRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
|
||||
$this->projectRateRepository->saveRate($rate);
|
||||
|
||||
$view = new View($rate, Response::HTTP_OK);
|
||||
$view->getContext()->setGroups(['Default', 'Entity', 'ProjectRate']);
|
||||
|
||||
return $this->viewHandler->handle($view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ use Nelmio\ApiDocBundle\Annotation\Security as ApiSecurity;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @SWG\Tag(name="Default")
|
||||
*/
|
||||
class StatusController extends BaseApiController
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
/**
|
||||
* @RouteResource("Tag")
|
||||
* @SWG\Tag(name="Tag")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
/**
|
||||
* @RouteResource("Team")
|
||||
* @SWG\Tag(name="Team")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @RouteResource("Timesheet")
|
||||
* @SWG\Tag(name="Timesheet")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
@@ -169,8 +170,9 @@ class TimesheetController extends BaseApiController
|
||||
if (!empty($customers)) {
|
||||
$query->setCustomers($customers);
|
||||
}
|
||||
} elseif (!empty($customer = $paramFetcher->get('customer'))) {
|
||||
@trigger_error('Timesheet API parameter "customer" is deprecated and will be removed with 2.0, use "customers" instead', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!empty($customer = $paramFetcher->get('customer'))) {
|
||||
$query->addCustomer($customer);
|
||||
}
|
||||
|
||||
@@ -181,8 +183,9 @@ class TimesheetController extends BaseApiController
|
||||
if (!empty($projects)) {
|
||||
$query->setProjects($projects);
|
||||
}
|
||||
} elseif (!empty($project = $paramFetcher->get('project'))) {
|
||||
@trigger_error('Timesheet API parameter "project" is deprecated and will be removed with 2.0, use "projects" instead', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!empty($project = $paramFetcher->get('project'))) {
|
||||
$query->addProject($project);
|
||||
}
|
||||
|
||||
@@ -193,8 +196,9 @@ class TimesheetController extends BaseApiController
|
||||
if (!empty($activities)) {
|
||||
$query->setActivities($activities);
|
||||
}
|
||||
} elseif (!empty($activity = $paramFetcher->get('activity'))) {
|
||||
@trigger_error('Timesheet API parameter "activity" is deprecated and will be removed with 2.0, use "activities" instead', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!empty($activity = $paramFetcher->get('activity'))) {
|
||||
$query->addActivity($activity);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
||||
/**
|
||||
* @RouteResource("User")
|
||||
* @SWG\Tag(name="User")
|
||||
*
|
||||
* @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
|
||||
*/
|
||||
|
||||
@@ -125,7 +125,8 @@ class CreateReleaseCommand extends Command
|
||||
'Dockerfile',
|
||||
'phpunit.xml.dist',
|
||||
'webpack.config.js',
|
||||
'assets/',
|
||||
// this seems to be required, see https://github.com/kevinpapst/kimai2/issues/1586
|
||||
//'assets/',
|
||||
'tests/',
|
||||
'var/cache/*',
|
||||
'var/data/kimai_test.sqlite',
|
||||
|
||||
@@ -18,6 +18,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* The abstract base controller.
|
||||
* @method null|User getUser()
|
||||
*/
|
||||
abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface
|
||||
{
|
||||
@@ -42,14 +43,6 @@ abstract class AbstractController extends BaseAbstractController implements Serv
|
||||
return $this->container->get('logger');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser()
|
||||
{
|
||||
return parent::getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a "successful" flash message to the stack.
|
||||
*
|
||||
|
||||
@@ -134,25 +134,6 @@ final class ActivityController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate_delete/{rate}", name="admin_activity_rate_delete", methods={"GET"})
|
||||
* @Security("is_granted('edit', activity)")
|
||||
*/
|
||||
public function deleteRateAction(Activity $activity, ActivityRate $rate, ActivityRateRepository $repository)
|
||||
{
|
||||
if ($rate->getActivity() !== $activity) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => 'Invalid activity']);
|
||||
} else {
|
||||
try {
|
||||
$repository->deleteRate($rate);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('activity_details', ['id' => $activity->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate", name="admin_activity_rate_add", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', activity)")
|
||||
|
||||
@@ -315,25 +315,6 @@ final class CustomerController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate_delete/{rate}", name="admin_customer_rate_delete", methods={"GET"})
|
||||
* @Security("is_granted('edit', customer)")
|
||||
*/
|
||||
public function deleteRateAction(Customer $customer, CustomerRate $rate, CustomerRateRepository $repository)
|
||||
{
|
||||
if ($rate->getCustomer() !== $customer) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => 'Invalid customer']);
|
||||
} else {
|
||||
try {
|
||||
$repository->deleteRate($rate);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate", name="admin_customer_rate_add", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', customer)")
|
||||
|
||||
@@ -58,7 +58,6 @@ class ProfileController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", name="fos_user_profile_show", methods={"GET"})
|
||||
* @Route(path="/", name="my_profile", methods={"GET"})
|
||||
*/
|
||||
public function profileAction()
|
||||
|
||||
@@ -314,25 +314,6 @@ final class ProjectController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate_delete/{rate}", name="admin_project_rate_delete", methods={"GET"})
|
||||
* @Security("is_granted('edit', project)")
|
||||
*/
|
||||
public function deleteRateAction(Project $project, ProjectRate $rate, ProjectRateRepository $repository)
|
||||
{
|
||||
if ($rate->getProject() !== $project) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => 'Invalid project']);
|
||||
} else {
|
||||
try {
|
||||
$repository->deleteRate($rate);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/rate", name="admin_project_rate_add", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', project)")
|
||||
|
||||
@@ -38,7 +38,6 @@ class Activity implements EntityWithMetaFields
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var Project|null
|
||||
*
|
||||
@@ -46,25 +45,20 @@ class Activity implements EntityWithMetaFields
|
||||
* @ORM\JoinColumn(onDelete="CASCADE")
|
||||
*/
|
||||
private $project;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* Do not increase length to more than 190 chars, otherwise "Index column size too large." will be triggered.
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Length(min=2, max=150)
|
||||
* @Assert\Length(min=2, max=150, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="comment", type="text", nullable=true)
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
|
||||
@@ -37,7 +37,8 @@ class Configuration
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=100, nullable=false)
|
||||
* @Assert\Length(min=2, max=100)
|
||||
* @Assert\NotNull()
|
||||
* @Assert\Length(min=2, max=100, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
||||
@@ -36,18 +36,14 @@ class Customer implements EntityWithMetaFields
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* Do not increase length to more than 190 chars, otherwise "Index column size too large." will be triggered.
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Length(min=2, max=150)
|
||||
* @Assert\Length(min=2, max=150, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -55,14 +51,12 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=50)
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="comment", type="text", nullable=true)
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
@@ -70,7 +64,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $visible = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -78,7 +71,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $company;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -86,7 +78,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=50)
|
||||
*/
|
||||
private $vatId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -94,14 +85,12 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $contact;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="address", type="text", nullable=true)
|
||||
*/
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -110,7 +99,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=2)
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -119,7 +107,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=3)
|
||||
*/
|
||||
private $currency = self::DEFAULT_CURRENCY;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -127,7 +114,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $phone;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -135,7 +121,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $fax;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -143,7 +128,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $mobile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -153,7 +137,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=254)
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -161,7 +144,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @Assert\Length(max=255)
|
||||
*/
|
||||
private $homepage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -183,7 +165,6 @@ class Customer implements EntityWithMetaFields
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\CustomerMeta", mappedBy="customer", cascade={"persist"})
|
||||
*/
|
||||
private $meta;
|
||||
|
||||
/**
|
||||
* @var Team[]|ArrayCollection
|
||||
*
|
||||
|
||||
@@ -36,7 +36,7 @@ class InvoiceTemplate
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=60, nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Length(min=1, max=60)
|
||||
* @Assert\Length(min=1, max=60, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ trait MetaTableTypeTrait
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=50, nullable=false)
|
||||
* @Assert\Length(min=2, max=50)
|
||||
* @Assert\NotNull()
|
||||
* @Assert\Length(min=2, max=50, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
||||
@@ -48,11 +48,9 @@ class Project implements EntityWithMetaFields
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* Do not increase length to more than 190 chars, otherwise "Index column size too large." will be triggered.
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @Assert\NotNull()
|
||||
* @Assert\Length(min=2, max=150)
|
||||
* @Assert\Length(min=2, max=150, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
trait Rate
|
||||
@@ -27,6 +28,7 @@ trait Rate
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\User")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
|
||||
* @SWG\Property(ref="#/definitions/User")
|
||||
*/
|
||||
private $user;
|
||||
/**
|
||||
@@ -36,6 +38,12 @@ trait Rate
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $rate = 0.00;
|
||||
/**
|
||||
* @var float|null
|
||||
*
|
||||
* @ORM\Column(name="internal_rate", type="float", nullable=true)
|
||||
*/
|
||||
private $internalRate;
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
@@ -78,6 +86,18 @@ trait Rate
|
||||
return $this->rate;
|
||||
}
|
||||
|
||||
public function setInternalRate(?float $rate): self
|
||||
{
|
||||
$this->internalRate = $rate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInternalRate(): ?float
|
||||
{
|
||||
return $this->internalRate;
|
||||
}
|
||||
|
||||
public function isFixed(): bool
|
||||
{
|
||||
return $this->isFixed;
|
||||
|
||||
@@ -9,12 +9,17 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface RateInterface
|
||||
{
|
||||
public function getUser(): ?User;
|
||||
|
||||
public function getRate(): float;
|
||||
|
||||
public function getInternalRate(): ?float;
|
||||
|
||||
public function isFixed(): bool;
|
||||
|
||||
public function getScore(): int;
|
||||
|
||||
@@ -39,7 +39,7 @@ class Tag
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=100, nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Length(min=2, max=100)
|
||||
* @Assert\Length(min=2, max=100, allowEmptyString=false)
|
||||
* @Assert\Regex(pattern="/,/",match=false,message="Tag name cannot contain comma")
|
||||
*/
|
||||
private $name;
|
||||
|
||||
@@ -39,7 +39,7 @@ class Team
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=100, nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Assert\Length(min=2, max=100)
|
||||
* @Assert\Length(min=2, max=100, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
|
||||
@@ -131,7 +131,14 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
private $rate = 0.00;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @var float|null
|
||||
*
|
||||
* @ORM\Column(name="internal_rate", type="float", nullable=true)
|
||||
*/
|
||||
private $internalRate;
|
||||
|
||||
/**
|
||||
* @var float|null
|
||||
*
|
||||
* @ORM\Column(name="fixed_rate", type="float", nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
@@ -363,6 +370,18 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
return $this->rate;
|
||||
}
|
||||
|
||||
public function setInternalRate(?float $rate): Timesheet
|
||||
{
|
||||
$this->internalRate = $rate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInternalRate(): ?float
|
||||
{
|
||||
return $this->internalRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @return Timesheet
|
||||
|
||||
@@ -27,6 +27,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
class UserPreference
|
||||
{
|
||||
public const HOURLY_RATE = 'hourly_rate';
|
||||
public const INTERNAL_RATE = 'internal_rate';
|
||||
public const SKIN = 'skin';
|
||||
public const LOCALE = 'language';
|
||||
public const TIMEZONE = 'timezone';
|
||||
@@ -51,7 +52,8 @@ class UserPreference
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=50, nullable=false)
|
||||
* @Assert\Length(min=2, max=50)
|
||||
* @Assert\NotNull()
|
||||
* @Assert\Length(min=2, max=50, allowEmptyString=false)
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,7 @@ final class UserPreferenceEvent extends Event
|
||||
foreach ($this->preferences as $pref) {
|
||||
if (strtolower($pref->getName()) === strtolower($preference->getName())) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Cannot add preference, one with the name "' . $preference->getName() . '" is already existing'
|
||||
'Cannot add user preference, one with the name "' . $preference->getName() . '" is already existing'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ use FOS\UserBundle\Event\FormEvent;
|
||||
use FOS\UserBundle\FOSUserEvents;
|
||||
use FOS\UserBundle\Model\UserManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* This class intercepts the registration to make sure:
|
||||
@@ -21,19 +23,21 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
* - the first-ever registered user will get the SUPER_ADMIN role
|
||||
* - the user uses the current request locale as initial language setting
|
||||
*/
|
||||
class RegistrationSubscriber implements EventSubscriberInterface
|
||||
final class RegistrationSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var UserManagerInterface
|
||||
*/
|
||||
protected $userManager;
|
||||
|
||||
private $userManager;
|
||||
/**
|
||||
* @param UserManagerInterface $userManager
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
public function __construct(UserManagerInterface $userManager)
|
||||
private $router;
|
||||
|
||||
public function __construct(UserManagerInterface $userManager, UrlGeneratorInterface $router)
|
||||
{
|
||||
$this->userManager = $userManager;
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +46,8 @@ class RegistrationSubscriber implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
FOSUserEvents::REGISTRATION_SUCCESS => ['onRegistrationSuccess', 200]
|
||||
FOSUserEvents::REGISTRATION_SUCCESS => ['onRegistrationSuccess', 200],
|
||||
FOSUserEvents::RESETTING_RESET_SUCCESS => ['onResettingSuccess', 200],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -62,4 +67,12 @@ class RegistrationSubscriber implements EventSubscriberInterface
|
||||
$user->setLanguage($event->getRequest()->getLocale());
|
||||
$user->setRoles($roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormEvent $event
|
||||
*/
|
||||
public function onResettingSuccess(FormEvent $event)
|
||||
{
|
||||
$event->setResponse(new RedirectResponse($this->router->generate('my_profile')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,15 @@ class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
->setOptions($hourlyRateOptions)
|
||||
->addConstraint(new Range(['min' => 0])),
|
||||
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::INTERNAL_RATE)
|
||||
->setValue(null)
|
||||
->setOrder(101)
|
||||
->setType(MoneyType::class)
|
||||
->setEnabled($enableHourlyRate)
|
||||
->setOptions(array_merge($hourlyRateOptions, ['label' => 'label.rate_internal', 'required' => false]))
|
||||
->addConstraint(new Range(['min' => 0])),
|
||||
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::TIMEZONE)
|
||||
->setValue($this->getDefaultTimezone())
|
||||
|
||||
@@ -70,6 +70,7 @@ abstract class AbstractSpreadsheetRenderer
|
||||
'end' => [],
|
||||
'duration' => [],
|
||||
'rate' => [],
|
||||
'rate_internal' => [],
|
||||
'user' => [],
|
||||
'customer' => [],
|
||||
'project' => [],
|
||||
@@ -226,6 +227,20 @@ abstract class AbstractSpreadsheetRenderer
|
||||
};
|
||||
}
|
||||
|
||||
if ($showRates && isset($columns['rate_internal']) && !isset($columns['rate_internal']['render'])) {
|
||||
$columns['rate_internal']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$currency = '';
|
||||
if (null !== $entity->getProject()) {
|
||||
$currency = $entity->getProject()->getCustomer()->getCurrency();
|
||||
}
|
||||
$rate = $entity->getRate();
|
||||
if (method_exists($entity, 'getInternalRate')) {
|
||||
$rate = $entity->getInternalRate();
|
||||
}
|
||||
$this->setRate($sheet, $column, $row, $rate, $currency);
|
||||
};
|
||||
}
|
||||
|
||||
if (isset($columns['user']) && !isset($columns['user']['render'])) {
|
||||
$columns['user']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) {
|
||||
$user = '';
|
||||
@@ -468,7 +483,7 @@ abstract class AbstractSpreadsheetRenderer
|
||||
}
|
||||
|
||||
if (!$showRates) {
|
||||
$removes = ['rate', 'fixedRate', 'hourlyRate'];
|
||||
$removes = ['rate', 'fixedRate', 'hourlyRate', 'rate_internal'];
|
||||
foreach ($removes as $removeMe) {
|
||||
if (array_key_exists($removeMe, $columns)) {
|
||||
unset($columns[$removeMe]);
|
||||
@@ -514,6 +529,7 @@ abstract class AbstractSpreadsheetRenderer
|
||||
|
||||
$durationColumn = null;
|
||||
$rateColumn = null;
|
||||
$internalRateColumn = null;
|
||||
|
||||
foreach ($exportItems as $exportItem) {
|
||||
$entryHeaderColumn = 1;
|
||||
@@ -523,6 +539,8 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$durationColumn = $entryHeaderColumn;
|
||||
} elseif ($label === 'rate') {
|
||||
$rateColumn = $entryHeaderColumn;
|
||||
} elseif ($label === 'rate_internal') {
|
||||
$internalRateColumn = $entryHeaderColumn;
|
||||
}
|
||||
|
||||
if (!array_key_exists('render', $settings) || !is_callable($settings['render'])) {
|
||||
@@ -554,6 +572,15 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$style->getFont()->setBold(true);
|
||||
}
|
||||
|
||||
if (null !== $internalRateColumn) {
|
||||
$startCoordinate = $sheet->getCellByColumnAndRow($internalRateColumn, 2)->getCoordinate();
|
||||
$endCoordinate = $sheet->getCellByColumnAndRow($internalRateColumn, $entryHeaderRow - 1)->getCoordinate();
|
||||
$this->setRateTotal($sheet, $internalRateColumn, $entryHeaderRow, $startCoordinate, $endCoordinate);
|
||||
$style = $sheet->getStyleByColumnAndRow($internalRateColumn, $entryHeaderRow);
|
||||
$style->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN);
|
||||
$style->getFont()->setBold(true);
|
||||
}
|
||||
|
||||
return $spreadsheet;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ trait RendererTrait
|
||||
'activities' => [],
|
||||
'currency' => $currency,
|
||||
'rate' => 0,
|
||||
'rate_internal' => 0,
|
||||
'duration' => 0,
|
||||
];
|
||||
}
|
||||
@@ -63,6 +64,7 @@ trait RendererTrait
|
||||
'activity' => $activityName,
|
||||
'currency' => $currency,
|
||||
'rate' => 0,
|
||||
'rate_internal' => 0,
|
||||
'duration' => 0,
|
||||
];
|
||||
}
|
||||
@@ -73,6 +75,11 @@ trait RendererTrait
|
||||
}
|
||||
|
||||
$summary[$id]['rate'] += $exportItem->getRate();
|
||||
if (method_exists($exportItem, 'getInternalRate')) {
|
||||
$summary[$id]['rate_internal'] += $exportItem->getInternalRate();
|
||||
} else {
|
||||
$summary[$id]['rate_internal'] += $exportItem->getRate();
|
||||
}
|
||||
$summary[$id]['duration'] += $duration;
|
||||
$summary[$id]['activities'][$activityId]['rate'] += $exportItem->getRate();
|
||||
$summary[$id]['activities'][$activityId]['duration'] += $duration;
|
||||
|
||||
28
src/Form/API/ActivityRateApiForm.php
Normal file
28
src/Form/API/ActivityRateApiForm.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\API;
|
||||
|
||||
use App\Form\ActivityRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ActivityRateApiForm extends ActivityRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
src/Form/API/CustomerRateApiForm.php
Normal file
28
src/Form/API/CustomerRateApiForm.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\API;
|
||||
|
||||
use App\Form\CustomerRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CustomerRateApiForm extends CustomerRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
src/Form/API/ProjectRateApiForm.php
Normal file
28
src/Form/API/ProjectRateApiForm.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\API;
|
||||
|
||||
use App\Form\ProjectRateForm;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectRateApiForm extends ProjectRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
56
src/Form/AbstractRateForm.php
Normal file
56
src/Form/AbstractRateForm.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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;
|
||||
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
abstract class AbstractRateForm extends AbstractType
|
||||
{
|
||||
protected function addFields(FormBuilderInterface $builder, ?string $currency)
|
||||
{
|
||||
$builder
|
||||
->add('user', UserType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('rate', MoneyType::class, [
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'number',
|
||||
'description' => 'Rate',
|
||||
],
|
||||
'label' => 'label.rate',
|
||||
'attr' => [
|
||||
'autofocus' => 'autofocus'
|
||||
],
|
||||
'currency' => $currency,
|
||||
'help' => 'help.rate',
|
||||
])
|
||||
->add('internalRate', MoneyType::class, [
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'number',
|
||||
'description' => 'Internal rate',
|
||||
],
|
||||
'label' => 'label.rate_internal',
|
||||
'currency' => $currency,
|
||||
'required' => false,
|
||||
'help' => 'help.rate_internal',
|
||||
])
|
||||
->add('isFixed', YesNoType::class, [
|
||||
'label' => 'label.fixedRate',
|
||||
'help' => 'help.fixedRate',
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,10 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\ActivityRate;
|
||||
use App\Entity\Rate;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ActivityRateForm extends AbstractType
|
||||
class ActivityRateForm extends AbstractRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -27,7 +23,7 @@ class ActivityRateForm extends AbstractType
|
||||
{
|
||||
$currency = null;
|
||||
|
||||
if ($options['data']) {
|
||||
if (!empty($options['data'])) {
|
||||
/** @var ActivityRate $rate */
|
||||
$rate = $options['data'];
|
||||
|
||||
@@ -36,21 +32,7 @@ class ActivityRateForm extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('user', UserType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('rate', MoneyType::class, [
|
||||
'label' => 'label.rate',
|
||||
'attr' => [
|
||||
'autofocus' => 'autofocus'
|
||||
],
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('isFixed', YesNoType::class, [
|
||||
'label' => 'label.fixedRate'
|
||||
])
|
||||
;
|
||||
$this->addFields($builder, $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,14 +11,10 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\CustomerRate;
|
||||
use App\Entity\Rate;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CustomerRateForm extends AbstractType
|
||||
class CustomerRateForm extends AbstractRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -26,7 +22,8 @@ class CustomerRateForm extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$currency = null;
|
||||
if ($options['data']) {
|
||||
|
||||
if (!empty($options['data'])) {
|
||||
/** @var CustomerRate $rate */
|
||||
$rate = $options['data'];
|
||||
|
||||
@@ -35,21 +32,7 @@ class CustomerRateForm extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('user', UserType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('rate', MoneyType::class, [
|
||||
'label' => 'label.rate',
|
||||
'attr' => [
|
||||
'autofocus' => 'autofocus'
|
||||
],
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('isFixed', YesNoType::class, [
|
||||
'label' => 'label.fixedRate'
|
||||
])
|
||||
;
|
||||
$this->addFields($builder, $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,14 +11,10 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\ProjectRate;
|
||||
use App\Entity\Rate;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectRateForm extends AbstractType
|
||||
class ProjectRateForm extends AbstractRateForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -26,7 +22,8 @@ class ProjectRateForm extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$currency = null;
|
||||
if ($options['data']) {
|
||||
|
||||
if (!empty($options['data'])) {
|
||||
/** @var ProjectRate $rate */
|
||||
$rate = $options['data'];
|
||||
|
||||
@@ -35,21 +32,7 @@ class ProjectRateForm extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('user', UserType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('rate', MoneyType::class, [
|
||||
'label' => 'label.rate',
|
||||
'attr' => [
|
||||
'autofocus' => 'autofocus'
|
||||
],
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('isFixed', YesNoType::class, [
|
||||
'label' => 'label.fixedRate'
|
||||
])
|
||||
;
|
||||
$this->addFields($builder, $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,6 +57,11 @@ abstract class AbstractMergedCalculator extends AbstractCalculator
|
||||
$invoiceItem->setAmount($invoiceItem->getAmount() + $amount);
|
||||
$invoiceItem->setUser($entry->getUser());
|
||||
$invoiceItem->setRate($invoiceItem->getRate() + $entry->getRate());
|
||||
if (method_exists($entry, 'getInternalRate')) {
|
||||
$invoiceItem->setInternalRate($invoiceItem->getInternalRate() + $entry->getInternalRate());
|
||||
} else {
|
||||
$invoiceItem->setInternalRate($invoiceItem->getInternalRate() + $entry->getRate());
|
||||
}
|
||||
$invoiceItem->setDuration($duration);
|
||||
|
||||
if (null !== $entry->getFixedRate()) {
|
||||
|
||||
@@ -53,17 +53,11 @@ abstract class AbstractSumInvoiceCalculator extends AbstractMergedCalculator imp
|
||||
return array_values($invoiceItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.9 - use mergeSumInvoiceItem() instead
|
||||
*/
|
||||
protected function mergeSumTimesheet(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
}
|
||||
|
||||
protected function mergeSumInvoiceItem(InvoiceItem $invoiceItem, InvoiceItemInterface $entry)
|
||||
{
|
||||
@trigger_error('mergeSumTimesheet() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
|
||||
|
||||
$this->mergeSumTimesheet($invoiceItem, $entry);
|
||||
if (method_exists($this, 'mergeSumTimesheet')) {
|
||||
@trigger_error('mergeSumTimesheet() is deprecated and will be removed with 2.0 - use mergeSumInvoiceItem() instead', E_USER_DEPRECATED);
|
||||
$this->mergeSumTimesheet($invoiceItem, $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
|
||||
$formatter = $this->model->getFormatter();
|
||||
|
||||
$rate = $item->getRate();
|
||||
$internalRate = $item->getInternalRate();
|
||||
$appliedRate = $item->getHourlyRate();
|
||||
$amount = $formatter->getFormattedDuration($item->getDuration());
|
||||
$description = $item->getDescription();
|
||||
@@ -65,6 +66,9 @@ class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
|
||||
'entry.rate' => $formatter->getFormattedMoney($appliedRate, $currency),
|
||||
'entry.rate_nc' => $formatter->getFormattedMoney($appliedRate, null),
|
||||
'entry.rate_plain' => $appliedRate,
|
||||
'entry.rate_internal' => $formatter->getFormattedMoney($internalRate, $currency),
|
||||
'entry.rate_internal_nc' => $formatter->getFormattedMoney($internalRate, null),
|
||||
'entry.rate_internal_plain' => $internalRate,
|
||||
'entry.total' => $formatter->getFormattedMoney($rate, $currency),
|
||||
'entry.total_nc' => $formatter->getFormattedMoney($rate, null),
|
||||
'entry.total_plain' => $rate,
|
||||
|
||||
@@ -30,6 +30,10 @@ final class InvoiceItem
|
||||
* @var float
|
||||
*/
|
||||
private $rate = 0.00;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $rateInternal = 0.00;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
@@ -152,6 +156,18 @@ final class InvoiceItem
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInternalRate(): float
|
||||
{
|
||||
return $this->rateInternal;
|
||||
}
|
||||
|
||||
public function setInternalRate(float $rateInternal): InvoiceItem
|
||||
{
|
||||
$this->rateInternal = $rateInternal;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
|
||||
@@ -14,6 +14,9 @@ use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
|
||||
/**
|
||||
* @method float|null getInternalRate()
|
||||
*/
|
||||
interface InvoiceItemInterface
|
||||
{
|
||||
public function getActivity(): ?Activity;
|
||||
@@ -26,6 +29,11 @@ interface InvoiceItemInterface
|
||||
|
||||
public function getRate(): float;
|
||||
|
||||
// will be activated with 2.0
|
||||
/*
|
||||
public function getInternalRate(): ?float;
|
||||
*/
|
||||
|
||||
public function getUser(): ?User;
|
||||
|
||||
public function getBegin(): ?\DateTime;
|
||||
|
||||
@@ -25,14 +25,14 @@ final class ConfigurableNumberGenerator implements NumberGeneratorInterface
|
||||
*/
|
||||
private $repository;
|
||||
/**
|
||||
* @var string
|
||||
* @var SystemConfiguration
|
||||
*/
|
||||
private $format;
|
||||
private $configuration;
|
||||
|
||||
public function __construct(InvoiceRepository $repository, SystemConfiguration $configuration)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->format = $configuration->find('invoice.number_format');
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,9 +56,8 @@ final class ConfigurableNumberGenerator implements NumberGeneratorInterface
|
||||
*/
|
||||
public function getInvoiceNumber(): string
|
||||
{
|
||||
$format = $this->format;
|
||||
$format = $this->configuration->find('invoice.number_format');
|
||||
$invoiceDate = $this->model->getInvoiceDate();
|
||||
$timestamp = $invoiceDate->getTimestamp();
|
||||
$result = $format;
|
||||
|
||||
preg_match_all('/{[^}]*?}/', $format, $matches);
|
||||
|
||||
42
src/Migrations/Version20200323163038.php
Normal file
42
src/Migrations/Version20200323163038.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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 DoctrineMigrations;
|
||||
|
||||
use App\Doctrine\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* @version 1.9
|
||||
*/
|
||||
final class Version20200323163038 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Adds the internal_rate column to all rate tables';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$schema->getTable('kimai2_activities_rates')->addColumn('internal_rate', 'float', ['notnull' => false]);
|
||||
$schema->getTable('kimai2_projects_rates')->addColumn('internal_rate', 'float', ['notnull' => false]);
|
||||
$schema->getTable('kimai2_customers_rates')->addColumn('internal_rate', 'float', ['notnull' => false]);
|
||||
$schema->getTable('kimai2_timesheet')->addColumn('internal_rate', 'float', ['notnull' => false]);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$schema->getTable('kimai2_timesheet')->dropColumn('internal_rate');
|
||||
$schema->getTable('kimai2_activities_rates')->dropColumn('internal_rate');
|
||||
$schema->getTable('kimai2_projects_rates')->dropColumn('internal_rate');
|
||||
$schema->getTable('kimai2_customers_rates')->dropColumn('internal_rate');
|
||||
}
|
||||
}
|
||||
35
src/Migrations/Version20200323163039.php
Normal file
35
src/Migrations/Version20200323163039.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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 DoctrineMigrations;
|
||||
|
||||
use App\Doctrine\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* @version 1.9
|
||||
*/
|
||||
final class Version20200323163039 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Set internal-rate from rate for existing timesheet entries';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('UPDATE kimai2_timesheet SET internal_rate = rate');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ class TimesheetCountedStatistic
|
||||
* @var float
|
||||
*/
|
||||
protected $recordRate = 0.0;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $recordInternalRate = 0.0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
@@ -86,4 +90,25 @@ class TimesheetCountedStatistic
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total internal rate of all included timesheet records.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRecordInternalRate()
|
||||
{
|
||||
return $this->recordInternalRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $recordInternalRate
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordInternalRate($recordInternalRate)
|
||||
{
|
||||
$this->recordInternalRate = (float) $recordInternalRate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ class ActivityRepository extends EntityRepository
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->addSelect('SUM(t.internalRate) as recordInternalRate')
|
||||
->from(Timesheet::class, 't')
|
||||
->where('t.activity = :activity')
|
||||
;
|
||||
@@ -107,6 +108,7 @@ class ActivityRepository extends EntityRepository
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
$stats->setRecordInternalRate($timesheetResult[0]['recordInternalRate']);
|
||||
}
|
||||
|
||||
return $stats;
|
||||
|
||||
@@ -89,6 +89,7 @@ class CustomerRepository extends EntityRepository
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->addSelect('SUM(t.internalRate) as recordInternalRate')
|
||||
->from(Timesheet::class, 't')
|
||||
->join(Project::class, 'p', Query\Expr\Join::WITH, 't.project = p.id')
|
||||
->andWhere('p.customer = :customer')
|
||||
@@ -99,6 +100,7 @@ class CustomerRepository extends EntityRepository
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
$stats->setRecordInternalRate($timesheetResult[0]['recordInternalRate']);
|
||||
}
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -84,6 +84,7 @@ class ProjectRepository extends EntityRepository
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->addSelect('SUM(t.internalRate) as recordInternalRate')
|
||||
->andWhere('t.project = :project')
|
||||
->setParameter('project', $project)
|
||||
;
|
||||
@@ -103,6 +104,7 @@ class ProjectRepository extends EntityRepository
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
$stats->setRecordInternalRate($timesheetResult[0]['recordInternalRate']);
|
||||
}
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -44,45 +44,70 @@ class RateCalculator implements CalculatorInterface
|
||||
{
|
||||
if (null === $record->getEnd()) {
|
||||
$record->setRate(0);
|
||||
$record->setInternalRate(0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fixedRate = $record->getFixedRate();
|
||||
$hourlyRate = $record->getHourlyRate();
|
||||
$fixedInternalRate = null;
|
||||
$internalRate = null;
|
||||
|
||||
if (null === $fixedRate && null === $hourlyRate) {
|
||||
$rate = $this->getBestFittingRate($record);
|
||||
$rate = $this->getBestFittingRate($record);
|
||||
|
||||
if (null !== $rate) {
|
||||
if ($rate->isFixed()) {
|
||||
$fixedRate = $rate->getRate();
|
||||
} else {
|
||||
$hourlyRate = $rate->getRate();
|
||||
if (null !== $rate) {
|
||||
if ($rate->isFixed()) {
|
||||
$fixedRate = $fixedRate ?? $rate->getRate();
|
||||
$fixedInternalRate = $rate->getRate();
|
||||
if (null !== $rate->getInternalRate()) {
|
||||
$fixedInternalRate = $rate->getInternalRate();
|
||||
}
|
||||
} else {
|
||||
$hourlyRate = $hourlyRate ?? $rate->getRate();
|
||||
$internalRate = $rate->getRate();
|
||||
if (null !== $rate->getInternalRate()) {
|
||||
$internalRate = $rate->getInternalRate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $fixedRate) {
|
||||
$record->setRate($fixedRate);
|
||||
$record->setFixedRate($fixedRate);
|
||||
$record->setRate($fixedRate);
|
||||
if (null === $fixedInternalRate) {
|
||||
$fixedInternalRate = (float) $record->getUser()->getPreferenceValue(UserPreference::INTERNAL_RATE, $fixedRate);
|
||||
}
|
||||
$record->setInternalRate($fixedInternalRate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// user preferences => fallback if nothing else was configured
|
||||
if (null === $hourlyRate) {
|
||||
$hourlyRate = (float) $record->getUser()->getPreferenceValue(UserPreference::HOURLY_RATE, 0.00);
|
||||
}
|
||||
if (null === $internalRate) {
|
||||
$internalRate = $record->getUser()->getPreferenceValue(UserPreference::INTERNAL_RATE, 0.00);
|
||||
if (null === $internalRate) {
|
||||
$internalRate = $hourlyRate;
|
||||
} else {
|
||||
$internalRate = (float) $internalRate;
|
||||
}
|
||||
}
|
||||
|
||||
$factor = $this->getRateFactor($record);
|
||||
|
||||
$hourlyRate = (float) ($hourlyRate * $factor);
|
||||
$factoredHourlyRate = (float) ($hourlyRate * $factor);
|
||||
$factoredInternalRate = (float) ($internalRate * $factor);
|
||||
$totalRate = 0;
|
||||
$totalInternalRate = 0;
|
||||
if (null !== $record->getDuration()) {
|
||||
$totalRate = Util::calculateRate($hourlyRate, $record->getDuration());
|
||||
$totalRate = Util::calculateRate($factoredHourlyRate, $record->getDuration());
|
||||
$totalInternalRate = Util::calculateRate($factoredInternalRate, $record->getDuration());
|
||||
}
|
||||
|
||||
$record->setHourlyRate($hourlyRate);
|
||||
$record->setHourlyRate($factoredHourlyRate);
|
||||
$record->setInternalRate($totalInternalRate);
|
||||
$record->setRate($totalRate);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user