code improvements (#3088)
This commit is contained in:
@@ -105,7 +105,7 @@ trait StringAccessibleConfigTrait
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return mixed
|
* @return string|int|bool|float|null|array
|
||||||
*/
|
*/
|
||||||
public function find(string $key)
|
public function find(string $key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
namespace App\Export;
|
namespace App\Export;
|
||||||
|
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
use App\Entity\Project;
|
||||||
|
use App\Entity\User;
|
||||||
use App\Repository\Query\TimesheetQuery;
|
use App\Repository\Query\TimesheetQuery;
|
||||||
use App\Utils\FileHelper;
|
use App\Utils\FileHelper;
|
||||||
|
|
||||||
@@ -19,40 +21,35 @@ final class ExportFilename
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $filename;
|
private $filename;
|
||||||
|
/**
|
||||||
|
* @var Customer|null
|
||||||
|
*/
|
||||||
|
private $customer;
|
||||||
|
/**
|
||||||
|
* @var Project|null
|
||||||
|
*/
|
||||||
|
private $project;
|
||||||
|
/**
|
||||||
|
* @var User|null
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
public function __construct(TimesheetQuery $query)
|
public function __construct(TimesheetQuery $query)
|
||||||
{
|
{
|
||||||
$filename = date('Ymd');
|
|
||||||
$hasName = false;
|
|
||||||
|
|
||||||
$customers = $query->getCustomers();
|
$customers = $query->getCustomers();
|
||||||
if (\count($customers) === 1) {
|
if (\count($customers) === 1) {
|
||||||
$filename .= '-' . $this->convert($this->getCustomerName($customers[0]));
|
$this->customer = $customers[0];
|
||||||
$hasName = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$projects = $query->getProjects();
|
$projects = $query->getProjects();
|
||||||
if (\count($projects) === 1) {
|
if (\count($projects) === 1) {
|
||||||
if (!$hasName) {
|
$this->project = $projects[0];
|
||||||
$filename .= '-' . $this->convert($this->getCustomerName($projects[0]->getCustomer()));
|
|
||||||
}
|
|
||||||
$filename .= '-' . $this->convert($projects[0]->getName());
|
|
||||||
$hasName = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = $query->getUsers();
|
$users = $query->getUsers();
|
||||||
if (\count($users) === 1) {
|
if (\count($users) === 1) {
|
||||||
$filename .= '-' . $this->convert($users[0]->getDisplayName());
|
$this->user = $users[0];
|
||||||
$hasName = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$hasName) {
|
|
||||||
$filename .= '-kimai-export';
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = str_replace(['/', '\\'], '-', $filename);
|
|
||||||
|
|
||||||
$this->filename = $filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCustomerName(Customer $customer): string
|
private function getCustomerName(Customer $customer): string
|
||||||
@@ -72,6 +69,37 @@ final class ExportFilename
|
|||||||
|
|
||||||
public function getFilename()
|
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;
|
return $this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
|
|||||||
self::$initialized = true;
|
self::$initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getConfigurationByName(string $name): ?Configuration
|
||||||
|
{
|
||||||
|
return $this->findOneBy(['name' => $name]);
|
||||||
|
}
|
||||||
|
|
||||||
public function saveConfiguration(Configuration $configuration)
|
public function saveConfiguration(Configuration $configuration)
|
||||||
{
|
{
|
||||||
$entityManager = $this->getEntityManager();
|
$entityManager = $this->getEntityManager();
|
||||||
@@ -59,6 +64,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
|
|||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteConfiguration(Configuration $configuration)
|
||||||
|
{
|
||||||
|
$entityManager = $this->getEntityManager();
|
||||||
|
$entityManager->remove($configuration);
|
||||||
|
$entityManager->flush();
|
||||||
|
$this->clearCache();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $prefix
|
* @param string $prefix
|
||||||
* @return Configuration[]
|
* @return Configuration[]
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
{% set tableName = tableName|default('project_details_reporting') %}
|
{% set tableName = tableName|default('project_details_reporting') %}
|
||||||
{% set tableId = 'project-details-form' %}
|
{% set tableId = 'project-details-form' %}
|
||||||
{% set view_revenue_tab = project_details is not null and is_granted('budget', project_details.project) %}
|
{% set view_budget = 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_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') %}
|
{% set see_users = is_granted('view_other_timesheet') or is_granted('view_other_reporting') %}
|
||||||
|
|
||||||
{% block stylesheets %}
|
{% block stylesheets %}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
{% block javascripts %}
|
{% block javascripts %}
|
||||||
{{ parent() }}
|
{{ parent() }}
|
||||||
{% set options = {'label': 'duration', 'title': 'name', 'legend': 'false'} %}
|
{% 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'}) %}
|
{% set options = options|merge({'footer': 'rate'}) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ charts.doughnut_javascript(options) }}
|
{{ charts.doughnut_javascript(options) }}
|
||||||
@@ -79,17 +79,17 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if hasData %}
|
{% 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 %}
|
{% set currency = project.customer.currency %}
|
||||||
|
|
||||||
{%- for yearStat in project_details.years|reverse %}
|
{%- for yearStat in project_details.years|reverse %}
|
||||||
{% set year = yearStat.year %}
|
{% 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 %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% 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 rates = [] %}
|
||||||
{% set durations = [] %}
|
{% set durations = [] %}
|
||||||
{% set chartPrefix = 'chart' ~ id %}
|
{% set chartPrefix = 'chart' ~ id %}
|
||||||
@@ -111,11 +111,11 @@
|
|||||||
<li><a data-chart="{{ chartPrefix }}User" href="#user-chart-{{ id}}" data-toggle="tab">{{ 'label.user'|trans }}</a></li>
|
<li><a data-chart="{{ chartPrefix }}User" href="#user-chart-{{ id}}" data-toggle="tab">{{ 'label.user'|trans }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart-{{ id}}" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
|
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart-{{ id}}" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
|
||||||
{% if view_revenue_tab %}
|
{% if view_revenue %}
|
||||||
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart-{{ id }}" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
|
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart-{{ id }}" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="active"><a data-chart="{{ chartPrefix }}Duration" href="#time-chart-{{ id }}" data-toggle="tab">{{ 'stats.workingTime'|trans }}</a></li>
|
<li class="active"><a data-chart="{{ chartPrefix }}Duration" href="#time-chart-{{ id }}" data-toggle="tab">{{ 'stats.workingTime'|trans }}</a></li>
|
||||||
<li class="pull-left header">{{ title }} {{ widgets.label(yearStat.duration|duration, 'gray') }} {{ widgets.label(yearStat.rate|money(currency), 'gray') }}</small></li>
|
<li class="pull-left header">{{ title }} {{ widgets.label(yearStat.duration|duration, 'gray') }}{% if view_revenue %} {{ widgets.label(yearStat.rate|money(currency), 'gray') }}{% endif %}</small></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content no-padding">
|
<div class="tab-content no-padding">
|
||||||
<div class="chart tab-pane active" id="time-chart-{{ id }}">
|
<div class="chart tab-pane active" id="time-chart-{{ id }}">
|
||||||
@@ -125,7 +125,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if view_revenue_tab %}
|
{% if view_revenue %}
|
||||||
<div class="chart tab-pane" id="revenue-chart-{{ id }}">
|
<div class="chart tab-pane" id="revenue-chart-{{ id }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="chart tab-pane" id="activity-chart-{{ id }}">
|
<div class="chart tab-pane" id="activity-chart-{{ id }}">
|
||||||
{{ _self.activity_tab(activities, yearStat.duration, currency, chartPrefix, view_revenue_tab) }}
|
{{ _self.activity_tab(activities, yearStat.duration, currency, chartPrefix, view_revenue) }}
|
||||||
</div>
|
</div>
|
||||||
{% if see_users %}
|
{% if see_users %}
|
||||||
<div class="chart tab-pane" id="user-chart-{{ id }}">
|
<div class="chart tab-pane" id="user-chart-{{ id }}">
|
||||||
@@ -208,9 +208,9 @@
|
|||||||
totalDuration = int
|
totalDuration = int
|
||||||
currency = string
|
currency = string
|
||||||
chartPrefix = string
|
chartPrefix = string
|
||||||
view_revenue_tab = boolean
|
view_revenue = boolean
|
||||||
#}
|
#}
|
||||||
{% macro activity_tab(activities, totalDuration, currency, chartPrefix, view_revenue_tab) %}
|
{% macro activity_tab(activities, totalDuration, currency, chartPrefix, view_revenue) %}
|
||||||
{% set dataset = [] %}
|
{% set dataset = [] %}
|
||||||
{% set labels = [] %}
|
{% set labels = [] %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -225,7 +225,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ widgets.label_activity(stat.activity, {'inherit': false, 'random': true}) }}</td>
|
<td>{{ widgets.label_activity(stat.activity, {'inherit': false, 'random': true}) }}</td>
|
||||||
<td class="text-nowrap text-right">{{ stat.duration|duration }}</td>
|
<td class="text-nowrap text-right">{{ stat.duration|duration }}</td>
|
||||||
{% if view_revenue_tab %}
|
{% if view_revenue %}
|
||||||
<td class="text-nowrap text-right">{{ stat.rate|money(currency) }}</td>
|
<td class="text-nowrap text-right">{{ stat.rate|money(currency) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="text-nowrap text-right">{{ percentage|number_format(1) }} %</td>
|
<td class="text-nowrap text-right">{{ percentage|number_format(1) }} %</td>
|
||||||
@@ -245,7 +245,7 @@
|
|||||||
project_view = ProjectViewModel
|
project_view = ProjectViewModel
|
||||||
project_details = ProjectDetailsModel
|
project_details = ProjectDetailsModel
|
||||||
#}
|
#}
|
||||||
{% macro project_details(project, project_view, project_details, view_revenue_tab, view_revenue_user, see_users) %}
|
{% macro project_details(project, project_view, project_details, view_budget, view_revenue, see_users) %}
|
||||||
{% set activities = project_details.activities %}
|
{% set activities = project_details.activities %}
|
||||||
{% set years = project_details.years %}
|
{% set years = project_details.years %}
|
||||||
{% import "macros/progressbar.html.twig" as progress %}
|
{% import "macros/progressbar.html.twig" as progress %}
|
||||||
@@ -271,7 +271,7 @@
|
|||||||
{% if activities is not empty %}
|
{% if activities is not empty %}
|
||||||
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
|
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if view_revenue_tab and project_view.rateTotal > 0 %}
|
{% if view_revenue and project_view.rateTotal > 0 %}
|
||||||
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
|
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if project_view.durationTotal > 0 %}
|
{% if project_view.durationTotal > 0 %}
|
||||||
@@ -301,7 +301,7 @@
|
|||||||
</th>
|
</th>
|
||||||
<td>{{ project_view.durationTotal|duration }}</td>
|
<td>{{ project_view.durationTotal|duration }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if view_revenue_tab %}
|
{% if view_revenue %}
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-min">
|
<th class="w-min">
|
||||||
{{ 'stats.amountTotal'|trans }}
|
{{ 'stats.amountTotal'|trans }}
|
||||||
@@ -352,7 +352,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if view_revenue_tab and (project.timeBudget > 0 or project.budget > 0) %}
|
{% if view_budget and (project.timeBudget > 0 or project.budget > 0) %}
|
||||||
{% set budgetStats = project_details.budgetStatisticModel %}
|
{% set budgetStats = project_details.budgetStatisticModel %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
@@ -389,7 +389,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% if view_revenue_tab and project_view.rateTotal > 0 %}
|
{% if view_revenue and project_view.rateTotal > 0 %}
|
||||||
<div class="chart tab-pane" id="revenue-chart">
|
<div class="chart tab-pane" id="revenue-chart">
|
||||||
{{ charts.bar_chart(chartPrefix ~ 'Rate', labels, [rates], {'height': '300px', 'renderEvent': 'render.' ~ chartPrefix ~ 'Rate'}) }}
|
{{ charts.bar_chart(chartPrefix ~ 'Rate', labels, [rates], {'height': '300px', 'renderEvent': 'render.' ~ chartPrefix ~ 'Rate'}) }}
|
||||||
</div>
|
</div>
|
||||||
@@ -401,7 +401,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if activities is not empty %}
|
{% if activities is not empty %}
|
||||||
<div class="chart tab-pane" id="activity-chart">
|
<div class="chart tab-pane" id="activity-chart">
|
||||||
{{ _self.activity_tab(activities, project_view.durationTotal, project.customer.currency, chartPrefix, view_revenue_tab) }}
|
{{ _self.activity_tab(activities, project_view.durationTotal, project.customer.currency, chartPrefix, view_revenue) }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if see_users and project_details.userStats|length > 0 %}
|
{% if see_users and project_details.userStats|length > 0 %}
|
||||||
@@ -430,7 +430,7 @@
|
|||||||
<td class="text-nowrap text-right">
|
<td class="text-nowrap text-right">
|
||||||
{{ userStat.duration|duration }}
|
{{ userStat.duration|duration }}
|
||||||
</td>
|
</td>
|
||||||
{% if view_revenue_user %}
|
{% if view_revenue %}
|
||||||
<td class="text-nowrap text-right">
|
<td class="text-nowrap text-right">
|
||||||
{{ userStat.rate|money(currency) }}
|
{{ userStat.rate|money(currency) }}
|
||||||
</td>
|
</td>
|
||||||
@@ -443,7 +443,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<th class="text-nowrap text-right total">{{ totalDuration|duration }}</th>
|
<th class="text-nowrap text-right total">{{ totalDuration|duration }}</th>
|
||||||
{% if view_revenue_user %}
|
{% if view_revenue %}
|
||||||
<th class="text-nowrap text-right total">{{ rateTotal|money(currency) }}</th>
|
<th class="text-nowrap text-right total">{{ rateTotal|money(currency) }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|||||||
Reference in New Issue
Block a user