added start and stop entries

enhanced administration of activities/projects/customers
added navbar for active records and recent activities
added edit timesheet entry form
added translation packages for errors and flashmessages
upgraded composer packages
This commit is contained in:
Kevin Papst
2018-01-04 14:06:07 +01:00
parent 3f429a3663
commit c9c82e767f
50 changed files with 973 additions and 405 deletions

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TimesheetBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Repository\ActivityRepository;
/**
* Controller used to manage activity contents in the public part of the site.
*
* @Route("/activity")
* @Security("has_role('ROLE_USER')")
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityController extends Controller
{
/**
* @return ActivityRepository
*/
protected function getRepository()
{
return $this->getDoctrine()->getRepository(Activity::class);
}
/**
* The flyout to render recent activities and quick-start new recordings.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function recentActivitiesAction()
{
$user = $this->getUser();
$activeEntries = $this->getRepository()->getRecentActivities($user, new \DateTime('-30 days')); // TODO make days configurable
return $this->render(
'TimesheetBundle:Navbar:recent-activities.html.twig',
['activities' => $activeEntries]
);
}
}

View File

@@ -11,10 +11,11 @@
namespace TimesheetBundle\Controller\Admin;
use AppBundle\Controller\AbstractController;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use TimesheetBundle\Entity\Activity;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -30,7 +31,7 @@ use TimesheetBundle\Repository\ActivityRepository;
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityController extends Controller
class ActivityController extends AbstractController
{
/**
* @Route("/", defaults={"page": 1}, name="admin_activity")
@@ -50,9 +51,8 @@ class ActivityController extends Controller
* @Route("/{id}/edit", name="admin_activity_edit")
* @Method({"GET", "POST"})
*/
public function editAction($id, Request $request)
public function editAction(Activity $activity, Request $request)
{
$activity = $this->getById($id);
$editForm = $this->createEditForm($activity);
$editForm->handleRequest($request);
@@ -62,7 +62,7 @@ class ActivityController extends Controller
$entityManager->persist($activity);
$entityManager->flush();
$this->addFlash('success', 'action.updated_successfully');
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute(
'admin_activity', ['id' => $activity->getId()]
@@ -78,21 +78,6 @@ class ActivityController extends Controller
);
}
/**
* @param $id
* @return null|Activity
*/
protected function getById($id)
{
/* @var $repo ActivityRepository */
$repo = $this->getDoctrine()->getRepository(Activity::class);
$activity = $repo->getById($id);
if (null === $activity) {
throw new NotFoundHttpException('Activity "'.$id.'" does not exist');
}
return $activity;
}
/**
* @param Activity $activity
* @return \Symfony\Component\Form\Form

View File

@@ -11,10 +11,11 @@
namespace TimesheetBundle\Controller\Admin;
use AppBundle\Controller\AbstractController;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use TimesheetBundle\Entity\Customer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -30,7 +31,7 @@ use TimesheetBundle\Repository\CustomerRepository;
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerController extends Controller
class CustomerController extends AbstractController
{
/**
* @Route("/", defaults={"page": 1}, name="admin_customer")
@@ -49,50 +50,38 @@ class CustomerController extends Controller
/**
* @Route("/{id}/edit", name="admin_customer_edit")
* @Method({"GET", "POST"})
*
* @param Customer $customer
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction($id, Request $request)
public function editAction(Customer $customer, Request $request)
{
$entity = $this->getById($id);
$editForm = $this->createEditForm($entity);
$editForm = $this->createEditForm($customer);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($entity);
$entityManager->persist($customer);
$entityManager->flush();
$this->addFlash('success', 'action.updated_successfully');
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute(
'admin_customer', ['id' => $entity->getId()]
'admin_customer', ['id' => $customer->getId()]
);
}
return $this->render(
'TimesheetBundle:admin:customer_edit.html.twig',
[
'customer' => $entity,
'customer' => $customer,
'form' => $editForm->createView()
]
);
}
/**
* @param $id
* @return null|Customer
*/
protected function getById($id)
{
/* @var $repo CustomerRepository */
$repo = $this->getDoctrine()->getRepository(Customer::class);
$activity = $repo->getById($id);
if (null === $activity) {
throw new NotFoundHttpException('Customer "'.$id.'" does not exist');
}
return $activity;
}
/**
* @param Customer $customer
* @return \Symfony\Component\Form\Form

View File

@@ -11,10 +11,10 @@
namespace TimesheetBundle\Controller\Admin;
use AppBundle\Controller\AbstractController;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use TimesheetBundle\Entity\Project;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -30,7 +30,7 @@ use TimesheetBundle\Repository\ProjectRepository;
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProjectController extends Controller
class ProjectController extends AbstractController
{
/**
* @Route("/", defaults={"page": 1}, name="admin_project")
@@ -53,13 +53,12 @@ class ProjectController extends Controller
* @Route("/{id}/edit", name="admin_project_edit")
* @Method({"GET", "POST"})
*
* @param $id
* @param Project $project
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction($id, Request $request)
public function editAction(Project $project, Request $request)
{
$project = $this->getById($id);
$editForm = $this->createEditForm($project);
$editForm->handleRequest($request);
@@ -69,7 +68,7 @@ class ProjectController extends Controller
$entityManager->persist($project);
$entityManager->flush();
$this->addFlash('success', 'action.updated_successfully');
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute(
'admin_project', ['id' => $project->getId()]
@@ -85,24 +84,9 @@ class ProjectController extends Controller
);
}
/**
* @param $id
* @return null|Project
*/
protected function getById($id)
{
/* @var $repo ProjectRepository */
$repo = $this->getDoctrine()->getRepository(Project::class);
$activity = $repo->getById($id);
if (null === $activity) {
throw new NotFoundHttpException('Project "'.$id.'" does not exist');
}
return $activity;
}
/**
* @param Project $project
* @return \Symfony\Component\Form\Form
* @return \Symfony\Component\Form\FormInterface
*/
private function createEditForm(Project $project)
{
@@ -112,7 +96,7 @@ class ProjectController extends Controller
[
'action' => $this->generateUrl('admin_project_edit', ['id' => $project->getId()]),
'method' => 'POST',
'currency' => $project->getCurrency()
'currency' => $project->getCustomer()->getCurrency()
]
);
}

View File

@@ -11,12 +11,17 @@
namespace TimesheetBundle\Controller;
use AppBundle\Controller\AbstractController;
use Pagerfanta\Pagerfanta;
use TimesheetBundle\Entity\Activity;
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;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use TimesheetBundle\Form\TimesheetEditForm;
use TimesheetBundle\Repository\TimesheetRepository;
/**
* Controller used to manage timesheet contents in the public part of the site.
@@ -26,8 +31,16 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetController extends Controller
class TimesheetController extends AbstractController
{
/**
* @return TimesheetRepository
*/
protected function getRepository()
{
return $this->getDoctrine()->getRepository(Timesheet::class);
}
/**
* @Route("/", defaults={"page": 1}, name="timesheet")
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated")
@@ -38,20 +51,144 @@ class TimesheetController extends Controller
{
$user = $this->getUser();
/* @var $entries Pagerfanta */
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findLatest($user, $page);
$entries = $this->getRepository()->findLatest($user, $page);
return $this->render('TimesheetBundle:timesheet:index.html.twig', ['entries' => $entries]);
return $this->render('TimesheetBundle:timesheet:index.html.twig', [
'entries' => $entries,
'page' => $page
]);
}
public function statusEntryAction()
/**
* The "main button and flyout" for displaying (and stopping) active entries.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function activeEntriesAction()
{
$user = $this->getUser();
$activeEntry = $this->getDoctrine()->getRepository(Timesheet::class)->getActiveEntry($user);
$activeEntries = $this->getRepository()->getActiveEntries($user);
$activeEntry = null;
return $this->render(
'TimesheetBundle:Sidebar:navbar-panel.html.twig',
['entry' => $activeEntry]
'TimesheetBundle:Navbar:active-entries.html.twig',
['entries' => $activeEntries]
);
}
/**
* The route to stop a running entry.
*
* @Route("/{id}/stop", name="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)
{
$user = $this->getUser();
// make sure only ADMIN can stop other users entries
if ($user->getId() !== $entry->getUser()->getId()) {
$this->denyUnlessGranted('ROLE_ADMIN', null, 'timesheet.access.denied', ['%user%' => $user->getId(), '%entry%' => $entry->getId()]);
}
try {
$this->getRepository()->stopRecording($entry);
$this->flashSuccess('timesheet.stop.success');
} catch (\Exception $ex) {
$this->flashError('timesheet.stop.error', ['%reason%' => $ex->getMessage()]);
}
return $this->redirectToRoute('timesheet');
}
/**
* The route to stop a running entry.
*
* @Route("/start/{id}", name="timesheet_start", requirements={"id" = "\d+"})
* @Method({"GET", "POST"})
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function startAction(Activity $activity, Request $request)
{
$user = $this->getUser();
try {
$this->getRepository()->startRecording($user, $activity);
$this->flashSuccess('timesheet.start.success');
} catch (\Exception $ex) {
$this->flashError('timesheet.start.error', ['%reason%' => $ex->getMessage()]);
}
return $this->redirectToRoute('timesheet');
}
/**
* The route to edit an existing entry or to create a complete new entry.
*
* @Route("/{id}/edit", name="timesheet_edit")
* @Method({"GET", "POST"})
*
* @param Timesheet $entry
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction(Timesheet $entry, Request $request)
{
$user = $this->getUser();
// make sure only ADMIN can edit other users entries
if ($user->getId() !== $entry->getUser()->getId()) {
$this->denyUnlessGranted('ROLE_ADMIN', null, 'timesheet.access.denied', ['%user%' => $user->getId(), '%entry%' => $entry->getId()]);
}
$editForm = $this->createEditForm($entry, $request->get('page'));
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($entry);
$entityManager->flush();
$this->flashSuccess('action.updated_successfully');
return $this->redirectToRoute(
'timesheet_paginated', ['page' => $request->get('page')]
);
}
return $this->render(
'TimesheetBundle:timesheet:edit.html.twig',
[
'entry' => $entry,
'form' => $editForm->createView(),
]
);
}
/**
* @param Timesheet $entry
* @param string $page
* @return \Symfony\Component\Form\Form
*/
private function createEditForm(Timesheet $entry, $page)
{
return $this->createForm(
TimesheetEditForm::class,
$entry,
[
'action' => $this->generateUrl('timesheet_edit', [
'id' => $entry->getId(),
'page' => $page
]),
'method' => 'POST',
'currency' => $entry->getActivity()->getProject()->getCustomer()->getCurrency(),
]
);
}
}

View File

@@ -152,15 +152,17 @@ class LoadFixtures extends AppBundleLoadFixtures
$rate = rand(self::RATE_MIN, self::RATE_MAX);
$entry = new Timesheet();
$entry->setActivity($activity);
$entry->setDescription($this->getRandomPhrase());
$entry->setUser($user);
$entry->setRate(round(($duration / 3600) * $rate));
$entry->setBegin($start);
$entry
->setActivity($activity)
->setDescription($this->getRandomPhrase())
->setUser($user)
->setRate(round(($duration / 3600) * $rate))
->setBegin($start);
if ($setEndDate) {
$entry->setEnd($end);
$entry->setDuration($duration);
$entry
->setEnd($end)
->setDuration($duration);
}
return $entry;
@@ -176,11 +178,14 @@ class LoadFixtures extends AppBundleLoadFixtures
for ($i = 0; $i < $amountCustomer; $i++) {
$entry = new Customer();
$entry->setName($allCustomer[$i]);
$entry->setCity($this->getRandomLocation());
$entry->setComment($this->getRandomPhrase());
$entry->setVisible($i % 3 != 0);
$entry->setTimezone($allTimezones[rand(1, $amountTimezone)]);
$entry
->setCurrency($this->getRandomCurrency())
->setVat(rand(0, 30))
->setName($allCustomer[$i])
->setAddress($this->getRandomLocation())
->setComment($this->getRandomPhrase())
->setVisible($i % 3 != 0)
->setTimezone($allTimezones[rand(1, $amountTimezone)]);
$manager->persist($entry);
}
@@ -195,12 +200,12 @@ class LoadFixtures extends AppBundleLoadFixtures
for ($i = 0; $i < $amountCustomer * 2; $i++) {
$entry = new Project();
$entry->setName($this->getRandomProject());
$entry->setCurrency($this->getRandomCurrency());
$entry->setBudget(rand(1000, 100000));
$entry->setComment($this->getRandomPhrase());
$entry->setCustomer($allCustomer[($i % $amountCustomer) + 1]);
$entry->setVisible($i % 3 != 0);
$entry
->setName($this->getRandomProject())
->setBudget(rand(1000, 100000))
->setComment($this->getRandomPhrase())
->setCustomer($allCustomer[($i % $amountCustomer) + 1])
->setVisible($i % 3 != 0);
$manager->persist($entry);
}
@@ -215,10 +220,11 @@ class LoadFixtures extends AppBundleLoadFixtures
$activityCount = rand(1, self::AMOUNT_ACTIVITIES);
for ($i = 0; $i < $activityCount; $i++) {
$entry = new Activity();
$entry->setProject($project);
$entry->setName($this->getRandomActivity());
$entry->setComment($this->getRandomPhrase());
$entry->setVisible($i % 3 != 0);
$entry
->setProject($project)
->setName($this->getRandomActivity())
->setComment($this->getRandomPhrase())
->setVisible($i % 3 != 0);
$manager->persist($entry);
}

View File

@@ -70,18 +70,20 @@ class Activity
}
/**
* @param int $project
* @param Project $project
* @return Activity
*/
public function setProject($project)
{
$this->project = $project;
return $this;
}
/**
* Set name
*
* @param string $name
*
* @return Activity
*/
public function setName($name)
@@ -105,13 +107,11 @@ class Activity
* Set comment
*
* @param string $comment
*
* @return Activity
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
@@ -150,7 +150,7 @@ class Activity
}
/**
* Get activityid
* Get activity id
*
* @return integer
*/

View File

@@ -25,6 +25,8 @@ use Symfony\Component\Validator\Constraints as Assert;
class Customer
{
const DEFAULT_CURRENCY = 'EUR';
/**
* @var integer
*
@@ -100,6 +102,13 @@ class Customer
*/
private $country;
/**
* @var string
*
* @ORM\Column(name="currency", type="string", length=3, nullable=false)
*/
private $currency = self::DEFAULT_CURRENCY;
/**
* @var string
*
@@ -339,6 +348,25 @@ class Customer
return $this->country;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
* @return $this
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* Set phone
*

View File

@@ -64,17 +64,10 @@ class Project
/**
* @var string
*
* @ORM\Column(name="budget", type="decimal", precision=10, scale=2, nullable=true)
* @ORM\Column(name="budget", type="decimal", precision=10, scale=2, nullable=false)
*/
private $budget = 0.00;
/**
* @var string
*
* @ORM\Column(name="currency", type="string", length=3, nullable=false)
*/
private $currency = 'EUR';
/**
* @var Activity[]
*
@@ -92,25 +85,6 @@ class Project
return $this->id;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
* @return $this
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* @return Customer
*/

View File

@@ -64,7 +64,7 @@ class Timesheet
private $user;
/**
* @var integer
* @var Activity
*
* @ORM\ManyToOne(targetEntity="TimesheetBundle\Entity\Activity")
* @ORM\JoinColumn(name="activity", referencedColumnName="id")
@@ -128,6 +128,10 @@ class Timesheet
public function setEnd($end)
{
$this->end = $end;
if ($end === null) {
$this->duration = 0;
}
return $this;
}
@@ -151,12 +155,16 @@ class Timesheet
*/
public function getDuration()
{
if ($this->duration !== 0 || $this->begin === null) {
return $this->duration;
if ($this->begin === null) {
return 0;
}
$current = new \DateTime();
return $current->getTimestamp() - $this->begin->getTimestamp();
if ($this->end === null) {
$current = new \DateTime();
return $current->getTimestamp() - $this->begin->getTimestamp();
}
return $this->duration;
}
/**
@@ -183,9 +191,9 @@ class Timesheet
}
/**
* Set activityid
* Set activity
*
* @param integer $activity
* @param Activity $activity
*
* @return Timesheet
*/
@@ -196,9 +204,9 @@ class Timesheet
}
/**
* Get activityid
* Get Activity
*
* @return integer
* @return Activity
*/
public function getActivity()
{

View File

@@ -14,6 +14,7 @@ namespace TimesheetBundle\Form;
use AppBundle\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
@@ -83,10 +84,14 @@ class CustomerEditForm extends AbstractType
'label' => 'label.address',
'required' => false,
])
// TODO string - length 2
// string - length 2
->add('country', CountryType::class, [
'label' => 'label.country',
])
// string - length 3
->add('currency', CurrencyType::class, [
'label' => 'label.currency',
])
// string - length 255
->add('phone', TelType::class, [
'label' => 'label.phone',

View File

@@ -12,18 +12,18 @@
namespace TimesheetBundle\Form;
use AppBundle\Form\Type\YesNoType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Customer;
use TimesheetBundle\Entity\Project;
use TimesheetBundle\Form\Type\CustomerType;
/**
* Defines the form used to manipulate Projects.
* Defines the form used to edit Projects.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
@@ -37,7 +37,7 @@ class ProjectEditForm extends AbstractType
{
$builder
// string - length 255
->add('name', null, [
->add('name', TextType::class, [
'label' => 'label.name',
])
// text
@@ -57,7 +57,6 @@ class ProjectEditForm extends AbstractType
'label' => 'label.budget',
'currency' => $builder->getOption('currency'),
])
// FIXME add budget
// do not allow activity selection as this causes headaches:
// 1. it is a bad UX
// 2. what should happen if they are detached?
@@ -82,7 +81,7 @@ class ProjectEditForm extends AbstractType
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_activity_edit',
'currency' => 'EUR,'
'currency' => Customer::DEFAULT_CURRENCY,
]);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TimesheetBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Customer;
use TimesheetBundle\Entity\Timesheet;
/**
* Defines the form used to manipulate Timesheet entries.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// datetime
->add('begin', DateTimeType::class, [
'label' => 'label.begin',
'date_widget' => 'single_text',
])
// datetime
->add('end', DateTimeType::class, [
'label' => 'label.end',
'date_widget' => 'single_text',
'required' => false,
])
// integer
/*
->add('duration', RangeType::class, [
'label' => 'label.duration',
])
// User
->add('user', UserType::class, [
'label' => 'label.user',
])
// Activity
->add('activity', ActivityType::class, [
'label' => 'label.activity',
])
*/
// customer
->add('description', TextareaType::class, [
'label' => 'label.description',
'required' => false,
])
// string
->add('rate', MoneyType::class, [
'label' => 'label.rate',
'currency' => $builder->getOption('currency'),
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Timesheet::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_timsheet_edit',
'currency' => Customer::DEFAULT_CURRENCY,
]);
}
}

View File

@@ -12,10 +12,10 @@
namespace TimesheetBundle\Repository;
use AppBundle\Entity\User;
use Doctrine\ORM\Query;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Entity\Timesheet;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use TimesheetBundle\Model\ActivityStatistic;
@@ -36,11 +36,53 @@ class ActivityRepository extends EntityRepository
{
return $this->find($id);
}
/**
* @param User|null $user
* @param \DateTime|null $startFrom
* @return mixed
*/
public function getRecentActivities(User $user = null, \DateTime $startFrom = null)
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('t', 'a', 'p', 'c')
->from('TimesheetBundle:Timesheet', 't')
->join('t.activity', 'a')
->join('a.project', 'p')
->join('p.customer', 'c')
->where($qb->expr()->isNotNull('t.end'))
->groupBy('a.id')
->orderBy('t.end', 'DESC')
->setMaxResults(10)
;
if ($user !== null) {
$qb->andWhere('t.user = :user')
->setParameter('user', $user);
}
if ($startFrom !== null) {
$qb->andWhere($qb->expr()->gt('t.begin', ':begin'))
->setParameter('begin', $startFrom);
}
$results = $qb->getQuery()->getResult();
$activities = [];
/* @var Timesheet $entry */
foreach($results as $entry) {
$activities[] = $entry->getActivity();
}
return $activities;
}
/**
* Return statistic data for all user.
*
* @return ActivityStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getGlobalStatistics()
{

View File

@@ -12,6 +12,7 @@
namespace TimesheetBundle\Repository;
use AppBundle\Entity\User;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Entity\Timesheet;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
@@ -32,6 +33,51 @@ use DateTime;
class TimesheetRepository extends EntityRepository
{
/**
* @param Timesheet $entry
* @return bool
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function stopRecording(Timesheet $entry)
{
$end = new DateTime();
$begin = $entry->getBegin();
$entry->setEnd($end);
$entry->setDuration($end->getTimestamp() - $begin->getTimestamp());
// TODO calculate rate by users hourly rate
$entityManager = $this->getEntityManager();
$entityManager->persist($entry);
$entityManager->flush();
return true;
}
/**
* @param User $user
* @param Activity $activity
* @return bool
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function startRecording(User $user, Activity $activity)
{
$entry = new Timesheet();
$entry
->setBegin(new DateTime())
->setUser($user)
->setActivity($activity);
$entityManager = $this->getEntityManager();
$entityManager->persist($entry);
$entityManager->flush();
return true;
}
/**
* @param $select
* @param User|null $user
@@ -78,6 +124,7 @@ class TimesheetRepository extends EntityRepository
*
* @param User $user
* @return TimesheetStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getUserStatistics(User $user)
{
@@ -159,7 +206,8 @@ class TimesheetRepository extends EntityRepository
/**
* Fetch statistic data for all user.
*
* @return TimesheetStatistic
* @return TimesheetGlobalStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getGlobalStatistics()
{
@@ -172,7 +220,7 @@ class TimesheetRepository extends EntityRepository
$userTotal = $this->getEntityManager()
->createQuery('SELECT COUNT(DISTINCT(t.user)) FROM TimesheetBundle:Timesheet t')
->getSingleScalarResult();
$activeNow = $this->getActiveEntry();
$activeNow = $this->getActiveEntries();
$amountMonth = $this->queryThisMonth('SUM(t.rate)')
->getQuery()
->getSingleScalarResult();
@@ -197,16 +245,20 @@ class TimesheetRepository extends EntityRepository
/**
* @param User $user
* @return Query
* @return Timesheet[]|null
*/
public function getActiveEntry(User $user = null)
public function getActiveEntries(User $user = null)
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('t')
$qb->select('t', 'a', 'p', 'c')
->from('TimesheetBundle:Timesheet', 't')
->join('t.activity', 'a')
->join('a.project', 'p')
->join('p.customer', 'c')
->where($qb->expr()->gt('t.begin', '0'))
->andWhere($qb->expr()->isNull('t.end'));
->andWhere($qb->expr()->isNull('t.end'))
->orderBy('t.begin', 'DESC');
$params = [];
@@ -226,8 +278,9 @@ class TimesheetRepository extends EntityRepository
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('t')
$qb->select('t', 'a')
->from('TimesheetBundle:Timesheet', 't')
->join('t.activity', 'a')
->orderBy('t.begin', 'DESC');
if (null !== $user) {

View File

@@ -0,0 +1,31 @@
<li class="dropdown messages-menu">
<a href="#" class="dropdown-toggle ddt-large ticktac" data-toggle="dropdown">
<i class="fa fa-play-circle fa-2x"></i>
{% if entries is not empty %}<span class="label label-{% if entries|length >= kimai_context.active_warning %}warning{% else %}success{% endif %}">{{ entries|length }}</span>{% endif %}
</a>
<ul class="dropdown-menu">
<li class="header">
{{ 'active.entries'|transchoice(entries|length) }}
</li>
<li>
<ul class="menu">
{% for entry in entries %}
<li>
<a href="{{ path('timesheet_stop', {'id' : entry.id}) }}">
<div class="pull-left">
<i class="fa fa-stop-circle fa-2x"></i>
</div>
<h4>
{{ entry.activity.name }}
<small><i class="fa fa-clock-o"></i> {{ entry|durationForEntry }}</small>
</h4>
<p>{{ entry.activity.project.name }} ({{ entry.activity.project.customer.name }})</p>
</a>
</li>
{% endfor %}
</ul>
</li>
<li class="footer"><a href="#">{{ 'timesheet.start'|trans }}</a></li>
</ul>
</li>

View File

@@ -0,0 +1,23 @@
{% if activities is not empty %}
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle ddt-large" data-toggle="dropdown">
<i class="fa fa-tasks fa-2x"></i>
<span class="label label-success">{{ activities|length }}</span>
</a>
<ul class="dropdown-menu">
<li class="header">{{ 'recent.activities'|transchoice(activities|length) }}</li>
<li>
<ul class="menu">
{% for activity in activities %}
<li>
<a href="{{ path('timesheet_start', {'id' : activity.id}) }}">
<i class="fa fa-play-circle text-green"></i> {{ 'recent.activities.format'|trans({'%activity%': activity.name, '%project%': activity.project.name, '%customer%': activity.project.customer.name}) }}
</a>
</li>
{% endfor %}
</ul>
</li>
<li class="footer"><a href="{{ url('timesheet') }}">{{ 'timesheet.all'|trans }}</a></li>
</ul>
</li>
{% endif %}

View File

@@ -6,8 +6,6 @@
{% block page_subtitle %}{{ 'admin_activity.subtitle'|trans }} {{ 'subtitle.amount'|trans({'%count%': entries.count}) }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{% if entries.count > 0 %}
{{ tables.data_table_header({
'label.id': 'hidden-xs',

View File

@@ -6,7 +6,6 @@
{% block page_subtitle %}{{ 'admin_activity.subtitle'|trans }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{{ include('default/_form.html.twig', {
'title': activity.name,
'form': form,

View File

@@ -6,22 +6,7 @@
{% block page_subtitle %}{{ 'admin_customer.subtitle'|trans }} {{ 'subtitle.amount'|trans({'%count%': entries.count}) }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{#
private $vat;
private $contact;
private $street;
private $zipcode;
private $city;
private $country;
private $phone;
private $fax;
private $mobile;
private $mail;
private $homepage;
private $timezone;
#}
{# Available fields: vat; contact; address; country; phone; fax; mobile; mail; homepage; timezone; #}
{% if entries.count > 0 %}
{{ tables.data_table_header({
@@ -29,6 +14,8 @@
'label.name': '',
'label.project': '',
'label.comment': 'hidden-xs',
'label.country': 'hidden-xs',
'label.currency': 'hidden-xs',
'label.visible': '',
'label.actions': '',
}) }}
@@ -43,6 +30,8 @@
{% endfor %}
</td>
<td class="hidden-xs">{{ entry.comment }}</td>
<td class="hidden-xs">{{ entry.country|country }}</td>
<td class="hidden-xs">{{ entry.currency }} {{ entry.currency|currency }}</td>
<td>{{ widgets.label_visible(entry.visible) }}</td>
<td>
{{ widgets.button_group({

View File

@@ -6,7 +6,6 @@
{% block page_subtitle %}{{ 'admin_customer.subtitle'|trans }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{{ include('default/_form.html.twig', {
'title': customer.name,
'form': form,

View File

@@ -6,8 +6,6 @@
{% block page_subtitle %}{{ 'admin_project.subtitle'|trans }} {{ 'subtitle.amount'|trans({'%count%': entries.count}) }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{% if entries.count > 0 %}
{{ tables.data_table_header({
'label.id': 'hidden-xs',
@@ -29,7 +27,7 @@
</td>
<td class="hidden-xs hidden-sm">{{ entry.comment }}</td>
<td class="hidden-xs hidden-sm">{{ widgets.badge_counter(entry.activities.count) }}</td>
<td class="hidden-xs">{{ entry.budget|money(entry.currency) }}</td>
<td class="hidden-xs">{{ entry.budget|money(entry.customer.currency) }}</td>
<td>{{ widgets.label_visible(entry.visible) }}</td>
<td>
{{ widgets.button_group({

View File

@@ -6,7 +6,6 @@
{% block page_subtitle %}{{ 'admin_project.subtitle'|trans }}{% endblock %}
{% block main %}
{{ include('default/_flash_messages.html.twig') }}
{{ include('default/_form.html.twig', {
'title': project.name,
'form': form,

View File

@@ -0,0 +1,14 @@
{% extends 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}
{% block page_title %}{{ 'timesheet.title'|trans }}{% endblock %}
{% block page_subtitle %}{{ 'timesheet.subtitle'|trans }}{% endblock %}
{% block main %}
{{ include('default/_form.html.twig', {
'title': 'timesheet.edit'|trans,
'form': form,
'back': path('timesheet')
}) }}
{% endblock %}

View File

@@ -13,6 +13,7 @@
'label.endtime': '',
'label.duration': 'hidden-xs',
'label.rate': 'hidden-xs',
'label.activity': 'hidden-xs hidden-sm',
'label.description': 'hidden-xs hidden-sm',
'label.actions': '',
}) }}
@@ -27,12 +28,17 @@
<td class="hidden-xs">{{ entry.rate|money }}</td>
{% else %}
<td>&dash;</td>
<td class="hidden-xs">&dash;</td>
<td class="hidden-xs"><i>{{ entry.duration|duration }}</i></td>
<td class="hidden-xs">&dash;</td>
{% endif %}
<td class="hidden-xs hidden-sm">{{ entry.activity.name }}</td>
<td class="hidden-xs hidden-sm">{{ entry.description }}</td>
<td>
{{ widgets.button_group({'repeat': '#', 'edit': '#', 'trash': '#'}) }}
{% if entry.end %}
{{ widgets.button_group({'repeat': '#', 'edit': path('timesheet_edit', {'id' : entry.id, 'page': page}), 'trash': '#'}) }}
{% else %}
{{ widgets.button_group({'stop': path('timesheet_stop', {'id' : entry.id}), 'edit': path('timesheet_edit', {'id' : entry.id, 'page': page}), 'trash': '#'}) }}
{% endif %}
</td>
</tr>
{% endfor %}