diff --git a/src/TimesheetBundle/Controller/Admin/TimesheetController.php b/src/TimesheetBundle/Controller/Admin/TimesheetController.php index ee773e52..36454fb5 100644 --- a/src/TimesheetBundle/Controller/Admin/TimesheetController.php +++ b/src/TimesheetBundle/Controller/Admin/TimesheetController.php @@ -11,9 +11,11 @@ namespace TimesheetBundle\Controller\Admin; +use AppBundle\Controller\AbstractController; use Pagerfanta\Pagerfanta; +use Symfony\Component\HttpFoundation\Request; +use TimesheetBundle\Controller\TimesheetControllerTrait; use TimesheetBundle\Entity\Timesheet; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; @@ -27,19 +29,51 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; * * @author Kevin Papst */ -class TimesheetController extends Controller +class TimesheetController extends AbstractController { + use TimesheetControllerTrait; + /** * @Route("/", defaults={"page": 1}, name="admin_timesheet") * @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_timesheet_paginated") * @Method("GET") * @Cache(smaxage="10") */ - public function indexAction($page) + public function indexAction($page, Request $request) { - /* @var $entries Pagerfanta */ - $entries = $this->getDoctrine()->getRepository(Timesheet::class)->findAll($page); + $query = $this->getQueryForRequest($request); + $query->setPage($page); - return $this->render('TimesheetBundle:admin:timesheet.html.twig', ['entries' => $entries]); + /* @var $entries Pagerfanta */ + $entries = $this->getRepository()->findByQuery($query); + + return $this->render('TimesheetBundle:admin:timesheet.html.twig', [ + 'entries' => $entries, + 'page' => $page, + 'query' => $query, + 'toolbarForm' => $this->getToolbarForm($query, 'admin_timesheet')->createView(), + ]); + } + + /** + * The route to stop a running entry. + * + * @Route("/{id}/stop", name="admin_timesheet_stop") + * @Method({"GET"}) + * + * @param Timesheet $entry + * @param Request $request + * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response + */ + public function stopAction(Timesheet $entry, Request $request) + { + try { + $this->getRepository()->stopRecording($entry); + $this->flashSuccess('timesheet.stop.success'); + } catch (\Exception $ex) { + $this->flashError('timesheet.stop.error', ['%reason%' => $ex->getMessage()]); + } + + return $this->redirectToRoute('admin_timesheet'); } } diff --git a/src/TimesheetBundle/Repository/TimesheetRepository.php b/src/TimesheetBundle/Repository/TimesheetRepository.php index 8e74a2a9..cf5fd1d4 100644 --- a/src/TimesheetBundle/Repository/TimesheetRepository.php +++ b/src/TimesheetBundle/Repository/TimesheetRepository.php @@ -296,9 +296,11 @@ class TimesheetRepository extends EntityRepository { $qb = $this->getEntityManager()->createQueryBuilder(); - $qb->select('t', 'a') + $qb->select('t', 'a', 'p', 'c') ->from('TimesheetBundle:Timesheet', 't') ->join('t.activity', 'a') + ->join('a.project', 'p') + ->join('p.customer', 'c') ->orderBy('t.begin', 'DESC'); if ($query->getUser() !== null) { @@ -319,9 +321,7 @@ class TimesheetRepository extends EntityRepository $qb->andWhere('a.project = :project') ->setParameter('project', $query->getProject()); } elseif ($query->getCustomer() !== null) { - $qb->join('a.project', 'p') - ->join('p.customer', 'c') - ->andWhere('p.customer = :customer') + $qb->andWhere('p.customer = :customer') ->setParameter('customer', $query->getCustomer()); } diff --git a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig index aa7487ea..e6288ae8 100644 --- a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig @@ -4,8 +4,13 @@ {% block page_title %}{{ 'admin_timesheet.title'|trans }}{% endblock %} {% block page_subtitle %}{{ 'admin_timesheet.subtitle'|trans }}{% endblock %} +{% block javascript_imports %}{% endblock %} {% block main %} + {% if toolbarForm %} + {{ include('default/_toolbar_form.html.twig', {'form': toolbarForm}) }} + {% endif %} + {% if entries.count > 0 %} {{ datatables.data_table_header({ 'label.date': '', @@ -25,7 +30,7 @@ {% if entry.end %} {{ entry.end|date("H:i") }} {{ entry.duration|duration }} - {{ entry.rate|money }} + {{ entry.rate|money(entry.activity.project.customer.currency) }} {% else %} ‐ ‐ @@ -34,7 +39,12 @@ {{ entry.user.username }} {{ entry.description }} - {{ widgets.button_group({'edit': '#', 'trash': '#'}) }} + {% if entry.end %} + {{ widgets.button_group({'edit': '#', 'trash': '#'}) }} + {% else %} + {{ widgets.button_group({'stop': path('admin_timesheet_stop', {'id' : entry.id}), 'edit': '#', 'trash': '#'}) }} + {% endif %} + {% endfor %} diff --git a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig index 2a914bcf..26b15d9f 100644 --- a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig +++ b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig @@ -30,7 +30,7 @@ {% if entry.end %} {{ entry.end|date("H:i") }} {{ entry.duration|duration }} - {{ entry.rate|money }} + {{ entry.rate|money(entry.activity.project.customer.currency) }} {% else %} ‐ {{ entry.duration|duration }}