diff --git a/src/Configuration/StringAccessibleConfigTrait.php b/src/Configuration/StringAccessibleConfigTrait.php index 0e35b9ca..161edd65 100644 --- a/src/Configuration/StringAccessibleConfigTrait.php +++ b/src/Configuration/StringAccessibleConfigTrait.php @@ -105,7 +105,7 @@ trait StringAccessibleConfigTrait /** * @param string $key - * @return mixed + * @return string|int|bool|float|null|array */ public function find(string $key) { diff --git a/src/Export/ExportFilename.php b/src/Export/ExportFilename.php index da9c5a6d..7fbb51bd 100644 --- a/src/Export/ExportFilename.php +++ b/src/Export/ExportFilename.php @@ -10,6 +10,8 @@ namespace App\Export; use App\Entity\Customer; +use App\Entity\Project; +use App\Entity\User; use App\Repository\Query\TimesheetQuery; use App\Utils\FileHelper; @@ -19,40 +21,35 @@ final class ExportFilename * @var string */ private $filename; + /** + * @var Customer|null + */ + private $customer; + /** + * @var Project|null + */ + private $project; + /** + * @var User|null + */ + private $user; public function __construct(TimesheetQuery $query) { - $filename = date('Ymd'); - $hasName = false; - $customers = $query->getCustomers(); if (\count($customers) === 1) { - $filename .= '-' . $this->convert($this->getCustomerName($customers[0])); - $hasName = true; + $this->customer = $customers[0]; } $projects = $query->getProjects(); if (\count($projects) === 1) { - if (!$hasName) { - $filename .= '-' . $this->convert($this->getCustomerName($projects[0]->getCustomer())); - } - $filename .= '-' . $this->convert($projects[0]->getName()); - $hasName = true; + $this->project = $projects[0]; } $users = $query->getUsers(); if (\count($users) === 1) { - $filename .= '-' . $this->convert($users[0]->getDisplayName()); - $hasName = true; + $this->user = $users[0]; } - - if (!$hasName) { - $filename .= '-kimai-export'; - } - - $filename = str_replace(['/', '\\'], '-', $filename); - - $this->filename = $filename; } private function getCustomerName(Customer $customer): string @@ -72,6 +69,37 @@ final class ExportFilename public function getFilename() { + if ($this->filename === null) { + $filename = date('Ymd'); + $hasName = false; + + if ($this->customer !== null) { + $filename .= '-' . $this->convert($this->getCustomerName($this->customer)); + $hasName = true; + } + + if ($this->project !== null) { + if (!$hasName) { + $filename .= '-' . $this->convert($this->getCustomerName($this->project->getCustomer())); + } + $filename .= '-' . $this->convert($this->project->getName()); + $hasName = true; + } + + if ($this->user !== null) { + $filename .= '-' . $this->convert($this->user->getDisplayName()); + $hasName = true; + } + + if (!$hasName) { + $filename .= '-kimai-export'; + } + + $filename = str_replace(['/', '\\'], '-', $filename); + + $this->filename = $filename; + } + return $this->filename; } diff --git a/src/Repository/ConfigurationRepository.php b/src/Repository/ConfigurationRepository.php index de249746..d4c5536a 100644 --- a/src/Repository/ConfigurationRepository.php +++ b/src/Repository/ConfigurationRepository.php @@ -51,6 +51,11 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn self::$initialized = true; } + public function getConfigurationByName(string $name): ?Configuration + { + return $this->findOneBy(['name' => $name]); + } + public function saveConfiguration(Configuration $configuration) { $entityManager = $this->getEntityManager(); @@ -59,6 +64,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn $this->clearCache(); } + public function deleteConfiguration(Configuration $configuration) + { + $entityManager = $this->getEntityManager(); + $entityManager->remove($configuration); + $entityManager->flush(); + $this->clearCache(); + } + /** * @param string $prefix * @return Configuration[] diff --git a/templates/reporting/project_details.html.twig b/templates/reporting/project_details.html.twig index 2c91df73..633877ad 100644 --- a/templates/reporting/project_details.html.twig +++ b/templates/reporting/project_details.html.twig @@ -6,8 +6,8 @@ {% set tableName = tableName|default('project_details_reporting') %} {% set tableId = 'project-details-form' %} -{% set view_revenue_tab = project_details is not null and is_granted('budget', project_details.project) %} -{% set view_revenue_user = project_details is not null and is_granted('view_rate_other_timesheet') %} +{% set view_budget = project_details is not null and is_granted('budget', project_details.project) %} +{% set view_revenue = project_details is not null and is_granted('view_rate_other_timesheet') %} {% set see_users = is_granted('view_other_timesheet') or is_granted('view_other_reporting') %} {% block stylesheets %} @@ -23,7 +23,7 @@ {% block javascripts %} {{ parent() }} {% set options = {'label': 'duration', 'title': 'name', 'legend': 'false'} %} - {% if view_revenue_user and view_revenue_tab %} + {% if view_revenue %} {% set options = options|merge({'footer': 'rate'}) %} {% endif %} {{ charts.doughnut_javascript(options) }} @@ -79,17 +79,17 @@ {% endif %} {% if hasData %} - {{ _self.project_details(project, project_view, project_details, view_revenue_tab, view_revenue_user, see_users) }} + {{ _self.project_details(project, project_view, project_details, view_budget, view_revenue, see_users) }} {% set currency = project.customer.currency %} {%- for yearStat in project_details.years|reverse %} {% set year = yearStat.year %} - {{ _self.duration_stat(year, year, year, month_names(), yearStat, project_details.getYearActivities(year), project_details.userYears(year), currency, view_revenue_tab, see_users) }} + {{ _self.duration_stat(year, year, year, month_names(), yearStat, project_details.getYearActivities(year), project_details.userYears(year), currency, view_revenue, see_users) }} {% endfor %} {% endif %} {% endblock %} -{% macro duration_stat(id, title, year, labels, yearStat, activities, users, currency, view_revenue_tab, see_users) %} +{% macro duration_stat(id, title, year, labels, yearStat, activities, users, currency, view_revenue, see_users) %} {% set rates = [] %} {% set durations = [] %} {% set chartPrefix = 'chart' ~ id %} @@ -111,11 +111,11 @@