@@ -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 <kevin@kevinpapst.de>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@
|
||||
|
||||
{% block page_title %}{{ 'admin_timesheet.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_timesheet.subtitle'|trans }}{% endblock %}
|
||||
{% block javascript_imports %}<script src="{{ asset('js/timesheet.js') }}"></script>{% 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 %}
|
||||
<td class="hidden-xs">{{ entry.end|date("H:i") }}</td>
|
||||
<td>{{ entry.duration|duration }}</td>
|
||||
<td>{{ entry.rate|money }}</td>
|
||||
<td>{{ entry.rate|money(entry.activity.project.customer.currency) }}</td>
|
||||
{% else %}
|
||||
<td class="hidden-xs">‐</td>
|
||||
<td>‐</td>
|
||||
@@ -34,7 +39,12 @@
|
||||
<td class="hidden-xs"><a href="{{ path('profile'|route_alias, {'username' : entry.user.username}) }}">{{ entry.user.username }}</a></td>
|
||||
<td class="hidden-xs hidden-sm">{{ entry.description }}</td>
|
||||
<td>
|
||||
{{ 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 %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
{% if entry.end %}
|
||||
<td>{{ entry.end|date("H:i") }}</td>
|
||||
<td class="hidden-xs">{{ entry.duration|duration }}</td>
|
||||
<td class="hidden-xs">{{ entry.rate|money }}</td>
|
||||
<td class="hidden-xs">{{ entry.rate|money(entry.activity.project.customer.currency) }}</td>
|
||||
{% else %}
|
||||
<td>‐</td>
|
||||
<td class="hidden-xs"><i>{{ entry.duration|duration }}</i></td>
|
||||
|
||||
Reference in New Issue
Block a user