* fixed delete project #69 * fixed delete activity form csrf token name #71 * added delete customer action # 68 * import customer with country #68
This commit is contained in:
@@ -396,7 +396,7 @@
|
||||
</trans-unit>
|
||||
<trans-unit id="admin_project.delete_confirm">
|
||||
<source>admin_project.delete_confirm</source>
|
||||
<target>Momentan existieren für das Projekt %project% des Kunden %customer% insgesamt %activities% Aktivitäten und %records% Zeiteinträge, welche sich auf eine Gesamtdauer von %duration% belaufen. Alle Aktivitäten und Zeiteinträge werden ebenfalls mit gelöscht!</target>
|
||||
<target>Momentan existieren für das Projekt %project% des Kunden %customer% insgesamt %activities% Aktivitäten und %records% Zeiteinträge, welche sich auf eine Gesamtdauer von %duration% belaufen. Diese Aktivitäten und Zeiteinträge werden ebenfalls mit gelöscht!</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
@@ -412,7 +412,7 @@
|
||||
</trans-unit>
|
||||
<trans-unit id="admin_activity.delete_confirm">
|
||||
<source>admin_activity.delete_confirm</source>
|
||||
<target>Momentan existieren für die Aktivität %activity% im Projekt %project% für den Kunden %customer% insgesamt %records% Zeiteinträge, welche sich auf eine Gesamtdauer von %duration% belaufen. Alle Zeiteinträge werden ebenfalls mit gelöscht!</target>
|
||||
<target>Momentan existieren für die Aktivität %activity% im Projekt %project% für den Kunden %customer% insgesamt %records% Zeiteinträge, welche sich auf eine Gesamtdauer von %duration% belaufen. Diese Zeiteinträge werden ebenfalls mit gelöscht!</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
@@ -470,6 +470,10 @@
|
||||
<source>label.currency</source>
|
||||
<target>Währung</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="admin_customer.delete_confirm">
|
||||
<source>admin_customer.delete_confirm</source>
|
||||
<target>Momentan existieren für den Kunden %customer% insgesamt %project% Projekte mit %activity% Aktivitäten, die sich in %records% Zeiteinträgen auf eine Gesamtdauer von %duration% belaufen. Diese Projekte, Aktivitäten und Zeiteinträge werden ebenfalls mit gelöscht!</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
Admin: User
|
||||
|
||||
@@ -131,7 +131,7 @@ class DashboardController extends Controller
|
||||
'header' => 'dashboard.admin',
|
||||
'widgets' => [
|
||||
"{{ widgets.info_box_more('stats.userTotal', user.totalAmount, ' ', path('admin_user'), 'user') }}",
|
||||
"{{ widgets.info_box_more('stats.customerTotal', customer.totalAmount, '', path('admin_customer'), 'users', 'blue') }}",
|
||||
"{{ widgets.info_box_more('stats.customerTotal', customer.count, '', path('admin_customer'), 'users', 'blue') }}",
|
||||
"{{ widgets.info_box_more('stats.projectsTotal', project.count, '', path('admin_project'), 'book', 'yellow') }}",
|
||||
"{{ widgets.info_box_more('stats.activitiesTotal', activity.count, '', path('admin_activity'), 'tasks', 'purple') }}",
|
||||
],
|
||||
|
||||
@@ -19,6 +19,7 @@ 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 TimesheetBundle\Form\CustomerDeleteForm;
|
||||
use TimesheetBundle\Form\CustomerEditForm;
|
||||
use TimesheetBundle\Form\Toolbar\CustomerToolbarForm;
|
||||
use TimesheetBundle\Repository\Query\CustomerQuery;
|
||||
@@ -34,6 +35,14 @@ use TimesheetBundle\Repository\Query\CustomerQuery;
|
||||
class CustomerController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \TimesheetBundle\Repository\CustomerRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Customer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return CustomerQuery
|
||||
@@ -66,7 +75,7 @@ class CustomerController extends AbstractController
|
||||
$query->setPage($page);
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Customer::class)->findByQuery($query);
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('TimesheetBundle:admin:customer.html.twig', [
|
||||
'entries' => $entries,
|
||||
@@ -115,13 +124,49 @@ class CustomerController extends AbstractController
|
||||
return $this->redirectToRoute('admin_customer', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'TimesheetBundle:admin:customer_edit.html.twig',
|
||||
[
|
||||
'customer' => $customer,
|
||||
'form' => $editForm->createView()
|
||||
]
|
||||
);
|
||||
return $this->render('TimesheetBundle:admin:customer_edit.html.twig', [
|
||||
'customer' => $customer,
|
||||
'form' => $editForm->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The route to delete an existing entry.
|
||||
*
|
||||
* @Route("/{id}/delete", name="admin_customer_delete")
|
||||
* @Method({"GET", "POST"})
|
||||
* @Security("is_granted('delete', customer)")
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteAction(Customer $customer, Request $request)
|
||||
{
|
||||
$stats = $this->getRepository()->getCustomerStatistics($customer);
|
||||
|
||||
$deleteForm = $this->createForm(CustomerDeleteForm::class, $customer, [
|
||||
'action' => $this->generateUrl('admin_customer_delete', ['id' => $customer->getId()]),
|
||||
'method' => 'POST'
|
||||
]);
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if ($stats->getRecordAmount() == 0 || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($customer);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.deleted_successfully');
|
||||
|
||||
return $this->redirectToRoute('admin_customer', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('TimesheetBundle:admin:customer_delete.html.twig', [
|
||||
'customer' => $customer,
|
||||
'stats' => $stats,
|
||||
'form' => $deleteForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,16 +175,12 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
protected function getToolbarForm(CustomerQuery $query)
|
||||
{
|
||||
return $this->createForm(
|
||||
CustomerToolbarForm::class,
|
||||
$query,
|
||||
[
|
||||
'action' => $this->generateUrl('admin_customer_paginated', [
|
||||
'page' => $query->getPage(),
|
||||
]),
|
||||
'method' => 'GET',
|
||||
]
|
||||
);
|
||||
return $this->createForm(CustomerToolbarForm::class, $query, [
|
||||
'action' => $this->generateUrl('admin_customer_paginated', [
|
||||
'page' => $query->getPage(),
|
||||
]),
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,13 +195,9 @@ class CustomerController extends AbstractController
|
||||
$url = $this->generateUrl('admin_customer_edit', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
return $this->createForm(
|
||||
CustomerEditForm::class,
|
||||
$customer,
|
||||
[
|
||||
'action' => $url,
|
||||
'method' => 'POST'
|
||||
]
|
||||
);
|
||||
return $this->createForm(CustomerEditForm::class, $customer, [
|
||||
'action' => $url,
|
||||
'method' => 'POST'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ProjectController extends AbstractController
|
||||
$customer = !empty(trim($customer)) ? trim($customer) : null;
|
||||
|
||||
if ($customer !== null) {
|
||||
$repo = $this->getRepository();
|
||||
$repo = $this->getDoctrine()->getRepository(Customer::class);
|
||||
$customer = $repo->getById($customer);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +191,7 @@ class LoadFixtures extends AppBundleLoadFixtures
|
||||
->setAddress($this->getRandomLocation())
|
||||
->setComment($this->getRandomPhrase())
|
||||
->setVisible($visible)
|
||||
->setCountry('Germany') // TODO randomize country ?
|
||||
->setTimezone($allTimezones[rand(1, $amountTimezone)]);
|
||||
|
||||
$manager->persist($entry);
|
||||
|
||||
@@ -32,7 +32,7 @@ class ActivityDeleteForm extends AbstractType
|
||||
'data_class' => Activity::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_activity_edit',
|
||||
'csrf_token_id' => 'admin_activity_delete',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
38
src/TimesheetBundle/Form/CustomerDeleteForm.php
Normal file
38
src/TimesheetBundle/Form/CustomerDeleteForm.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
|
||||
/**
|
||||
* The form used to delete Customers.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class CustomerDeleteForm extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Customer::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_customer_delete',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,117 @@ class CustomerStatistic
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $totalAmount = 0;
|
||||
protected $count = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordDuration = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $activityAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $projectAmount = 0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordAmount()
|
||||
{
|
||||
return $this->recordAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordAmount($recordAmount)
|
||||
{
|
||||
$this->recordAmount = (int) $recordAmount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordDuration()
|
||||
{
|
||||
return $this->recordDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordDuration
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordDuration($recordDuration)
|
||||
{
|
||||
$this->recordDuration = (int) $recordDuration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of activities that are included in the statistic result.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return $this
|
||||
*/
|
||||
public function setCount($count)
|
||||
{
|
||||
$this->count = (int) $count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAmount()
|
||||
public function getActivityAmount()
|
||||
{
|
||||
return $this->totalAmount;
|
||||
return $this->activityAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $totalAmount
|
||||
* @param int $activityAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setTotalAmount($totalAmount)
|
||||
public function setActivityAmount($activityAmount)
|
||||
{
|
||||
$this->totalAmount = $totalAmount;
|
||||
$this->activityAmount = (int) $activityAmount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getProjectAmount()
|
||||
{
|
||||
return $this->projectAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setProjectAmount($projectAmount)
|
||||
{
|
||||
$this->projectAmount = (int) $projectAmount;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace TimesheetBundle\Repository;
|
||||
|
||||
use AppBundle\Repository\AbstractRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
use TimesheetBundle\Model\CustomerStatistic;
|
||||
use TimesheetBundle\Repository\Query\CustomerQuery;
|
||||
@@ -46,7 +47,47 @@ class CustomerRepository extends AbstractRepository
|
||||
->getSingleScalarResult();
|
||||
|
||||
$stats = new CustomerStatistic();
|
||||
$stats->setTotalAmount($countAll);
|
||||
$stats->setCount($countAll);
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves statistics for one customer.
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return CustomerStatistic
|
||||
*/
|
||||
public function getCustomerStatistics(Customer $customer)
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('COUNT(t.id) as recordAmount', 'SUM(t.duration) as recordDuration, COUNT(DISTINCT(a.id)) as activityAmount, COUNT(DISTINCT(p.id)) as projectAmount')
|
||||
->from('TimesheetBundle:Timesheet', 't')
|
||||
->join('TimesheetBundle:Activity', 'a')
|
||||
->join('TimesheetBundle:Project', 'p')
|
||||
->join('TimesheetBundle:Customer', 'c')
|
||||
->andWhere('t.activity = a.id')
|
||||
->andWhere('a.project = p.id')
|
||||
->andWhere('p.customer = c.id')
|
||||
->andWhere('c.id = :customer')
|
||||
;
|
||||
|
||||
// dump($qb->getQuery()->getSQL());exit;
|
||||
|
||||
$result = $qb->getQuery()->execute(['customer' => $customer], Query::HYDRATE_ARRAY);
|
||||
|
||||
$stats = new CustomerStatistic();
|
||||
|
||||
if (isset($result[0])) {
|
||||
$dbStats = $result[0];
|
||||
|
||||
$stats->setCount(1);
|
||||
$stats->setRecordAmount($dbStats['recordAmount']);
|
||||
$stats->setRecordDuration($dbStats['recordDuration']);
|
||||
$stats->setActivityAmount($dbStats['activityAmount']);
|
||||
$stats->setProjectAmount($dbStats['projectAmount']);
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,14 @@
|
||||
<td class="hidden-xs">{{ entry.currency }} {{ entry.currency|currency }}</td>
|
||||
<td>{{ widgets.label_visible(entry.visible) }}</td>
|
||||
<td>
|
||||
{{ widgets.button_group({
|
||||
'edit': path('admin_customer_edit', {'id': entry.id}),
|
||||
'trash': '#'
|
||||
}) }}
|
||||
{% set actionButtons = {} %}
|
||||
{% if is_granted('edit', entry) %}
|
||||
{% set actionButtons = {'edit': path('admin_customer_edit', {'id': entry.id})}|merge(actionButtons) %}
|
||||
{% endif %}
|
||||
{% if is_granted('delete', entry) %}
|
||||
{% set actionButtons = actionButtons|merge({'trash': path('admin_customer_delete', {'id': entry.id})}) %}
|
||||
{% endif %}
|
||||
{{ widgets.button_group(actionButtons) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
|
||||
{% block page_title %}{{ 'admin_customer.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_customer.subtitle'|trans }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
{% set params = {
|
||||
'%activity%': '<strong>' ~ stats.activityAmount ~ '</strong>',
|
||||
'%project%': '<strong>' ~ stats.projectAmount ~ '</strong>',
|
||||
'%customer%': '<strong>' ~ customer.name ~ '</strong>',
|
||||
'%records%': '<strong>' ~ stats.recordAmount ~ '</strong>',
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{{ include('default/_form_delete.html.twig', {
|
||||
'message': "admin_customer.delete_confirm"|trans(params)|raw,
|
||||
'form': form,
|
||||
'back': path('admin_customer')
|
||||
}) }}
|
||||
|
||||
{% endblock %}
|
||||
@@ -16,7 +16,6 @@
|
||||
'label.name': '',
|
||||
'label.customer': '',
|
||||
'label.comment': 'hidden-xs hidden-sm',
|
||||
'label.activity': 'hidden-xs hidden-sm',
|
||||
'label.budget': 'hidden-xs',
|
||||
'label.visible': '',
|
||||
'label.actions': '',
|
||||
@@ -30,7 +29,6 @@
|
||||
<a href="{{ path('admin_customer_edit', {'id' : entry.customer.id}) }}">{{ widgets.label_customer(entry.customer) }}</a>
|
||||
</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.customer.currency) }}</td>
|
||||
<td>{{ widgets.label_visible(entry.visible) }}</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user