Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -21,12 +21,7 @@ trait BudgetHydratorTrait
$budgetOpen = $statistic->getBudgetOpenRelative();
$budgetTimeOpen = $statistic->getTimeBudgetOpenRelative();
if ($model->getTemplate()->isDecimalDuration()) {
$budgetOpenDuration = $formatter->getFormattedDecimalDuration($budgetTimeOpen);
} else {
$budgetOpenDuration = $formatter->getFormattedDuration($budgetTimeOpen);
}
$budgetOpenDuration = $formatter->getFormattedDecimalDuration($budgetTimeOpen);
return [
$prefix . 'budget_open' => $formatter->getFormattedMoney($budgetOpen, $currency),

View File

@@ -13,12 +13,9 @@ use App\Invoice\InvoiceItem;
use App\Invoice\InvoiceItemHydrator;
use App\Invoice\InvoiceModel;
class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
final class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
{
/**
* @var InvoiceModel
*/
private $model;
private InvoiceModel $model;
public function setInvoiceModel(InvoiceModel $model)
{
@@ -32,11 +29,7 @@ class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
$rate = $item->getRate();
$internalRate = $item->getInternalRate();
$appliedRate = $item->getHourlyRate();
if ($this->model->getTemplate()->isDecimalDuration()) {
$amount = $formatter->getFormattedDecimalDuration($item->getDuration());
} else {
$amount = $formatter->getFormattedDuration($item->getDuration());
}
$amount = $formatter->getFormattedDecimalDuration($item->getDuration());
$description = $item->getDescription();
if ($item->isFixedRate()) {
@@ -63,11 +56,11 @@ class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
$values = [
'entry.row' => '',
'entry.description' => $description,
'entry.description' => $description ?? '',
'entry.amount' => $amount,
'entry.type' => $item->getType(),
'entry.tags' => implode(', ', $item->getTags()),
'entry.category' => $item->getCategory(),
'entry.category' => $item->getCategory() ?? '',
'entry.rate' => $formatter->getFormattedMoney($appliedRate, $currency),
'entry.rate_nc' => $formatter->getFormattedMoney($appliedRate, $currency, false),
'entry.rate_plain' => $appliedRate,
@@ -91,9 +84,9 @@ class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
'entry.week' => \intval($begin->format('W')),
'entry.weekyear' => $begin->format('o'),
'entry.user_id' => $user->getId(),
'entry.user_name' => $user->getUsername(),
'entry.user_title' => $user->getTitle(),
'entry.user_alias' => $user->getAlias(),
'entry.user_name' => $user->getUserIdentifier(),
'entry.user_title' => $user->getTitle() ?? '',
'entry.user_alias' => $user->getAlias() ?? '',
];
if (null !== $activity) {

View File

@@ -14,31 +14,39 @@ use App\Entity\Activity;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelActivityHydrator implements InvoiceModelHydrator
final class InvoiceModelActivityHydrator implements InvoiceModelHydrator
{
use BudgetHydratorTrait;
private $activityStatistic;
public function __construct(ActivityStatisticService $activityStatistic)
public function __construct(private ActivityStatisticService $activityStatistic)
{
$this->activityStatistic = $activityStatistic;
}
public function hydrate(InvoiceModel $model): array
{
if (!$model->getQuery()->hasActivities()) {
$activities = [];
foreach ($model->getEntries() as $entry) {
if ($entry->getActivity() === null) {
continue;
}
$key = 'A_' . $entry->getActivity()->getId();
if (!\array_key_exists($key, $activities)) {
$activities[$key] = $entry->getActivity();
}
}
if (\count($activities) === 0) {
return [];
}
$activities = array_values($activities);
$values = [];
$i = 0;
if (\count($model->getQuery()->getActivities()) === 1) {
$values['activity'] = $model->getQuery()->getActivities()[0]->getName();
}
foreach ($model->getQuery()->getActivities() as $activity) {
foreach ($activities as $activity) {
$prefix = '';
if ($i > 0) {
$prefix = $i . '.';
@@ -56,15 +64,17 @@ class InvoiceModelActivityHydrator implements InvoiceModelHydrator
$values = [
$prefix . 'id' => $activity->getId(),
$prefix . 'name' => $activity->getName(),
$prefix . 'comment' => $activity->getComment(),
$prefix . 'name' => $activity->getName() ?? '',
$prefix . 'comment' => $activity->getComment() ?? '',
];
$statistic = $this->activityStatistic->getBudgetStatisticModel($activity, $model->getQuery()->getEnd());
if ($model->getQuery()?->getEnd() !== null) {
$statistic = $this->activityStatistic->getBudgetStatisticModel($activity, $model->getQuery()->getEnd());
$values = array_merge($values, $this->getBudgetValues($prefix, $statistic, $model));
$values = array_merge($values, $this->getBudgetValues($prefix, $statistic, $model));
}
foreach ($activity->getVisibleMetaFields() as $metaField) {
foreach ($activity->getMetaFields() as $metaField) {
$values = array_merge($values, [
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
]);

View File

@@ -13,15 +13,12 @@ use App\Customer\CustomerStatisticService;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
final class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
{
use BudgetHydratorTrait;
private $customerStatistic;
public function __construct(CustomerStatisticService $customerStatistic)
public function __construct(private CustomerStatisticService $customerStatisticService)
{
$this->customerStatistic = $customerStatistic;
}
public function hydrate(InvoiceModel $model): array
@@ -34,22 +31,23 @@ class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
$values = [
'customer.id' => $customer->getId(),
'customer.address' => $customer->getAddress(),
'customer.name' => $customer->getName(),
'customer.contact' => $customer->getContact(),
'customer.company' => $customer->getCompany(),
'customer.vat' => $customer->getVatId(),
'customer.number' => $customer->getNumber(),
'customer.address' => $customer->getAddress() ?? '',
'customer.name' => $customer->getName() ?? '',
'customer.contact' => $customer->getContact() ?? '',
'customer.company' => $customer->getCompany() ?? '',
'customer.vat' => $customer->getVatId() ?? '',
'customer.number' => $customer->getNumber() ?? '',
'customer.country' => $customer->getCountry(),
'customer.homepage' => $customer->getHomepage(),
'customer.comment' => $customer->getComment(),
'customer.email' => $customer->getEmail(),
'customer.fax' => $customer->getFax(),
'customer.phone' => $customer->getPhone(),
'customer.mobile' => $customer->getMobile(),
'customer.homepage' => $customer->getHomepage() ?? '',
'customer.comment' => $customer->getComment() ?? '',
'customer.email' => $customer->getEmail() ?? '',
'customer.fax' => $customer->getFax() ?? '',
'customer.phone' => $customer->getPhone() ?? '',
'customer.mobile' => $customer->getMobile() ?? '',
'customer.invoice_text' => $customer->getInvoiceText() ?? '',
];
$statistic = $this->customerStatistic->getBudgetStatisticModel($customer, $model->getQuery()->getEnd());
$statistic = $this->customerStatisticService->getBudgetStatisticModel($customer, $model->getQuery()->getEnd());
$values = array_merge($values, $this->getBudgetValues('customer.', $statistic, $model));

View File

@@ -12,7 +12,7 @@ namespace App\Invoice\Hydrator;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelDefaultHydrator implements InvoiceModelHydrator
final class InvoiceModelDefaultHydrator implements InvoiceModelHydrator
{
public function hydrate(InvoiceModel $model): array
{
@@ -45,21 +45,17 @@ class InvoiceModelDefaultHydrator implements InvoiceModelHydrator
'invoice.subtotal_nc' => $formatter->getFormattedMoney($subtotal, $currency, false),
'invoice.subtotal_plain' => $subtotal,
'template.name' => $model->getTemplate()->getName(),
'template.company' => $model->getTemplate()->getCompany(),
'template.address' => $model->getTemplate()->getAddress(),
'template.title' => $model->getTemplate()->getTitle(),
'template.payment_terms' => $model->getTemplate()->getPaymentTerms(),
'template.name' => $model->getTemplate()->getName() ?? '',
'template.company' => $model->getTemplate()->getCompany() ?? '',
'template.address' => $model->getTemplate()->getAddress() ?? '',
'template.title' => $model->getTemplate()->getTitle() ?? '',
'template.payment_terms' => $model->getTemplate()->getPaymentTerms() ?? '',
'template.due_days' => $model->getTemplate()->getDueDays(),
'template.vat_id' => $model->getTemplate()->getVatId(),
'template.contact' => $model->getTemplate()->getContact(),
'template.payment_details' => $model->getTemplate()->getPaymentDetails(),
'template.vat_id' => $model->getTemplate()->getVatId() ?? '',
'template.contact' => $model->getTemplate()->getContact() ?? '',
'template.payment_details' => $model->getTemplate()->getPaymentDetails() ?? '',
'query.begin' => '',
'query.day' => '', // @deprecated
'query.month' => '', // @deprecated
'query.month_number' => '', // @deprecated
'query.year' => '', // @deprecated
'query.begin_day' => '',
'query.begin_month' => '',
'query.begin_month_number' => '',
@@ -73,11 +69,11 @@ class InvoiceModelDefaultHydrator implements InvoiceModelHydrator
if ($begin !== null) {
$values = array_merge($values, [
'query.day' => $begin->format('d'), // @deprecated - but impossible to delete
'query.month' => $formatter->getFormattedMonthName($begin), // @deprecated - but impossible to delete
'query.month_number' => $begin->format('m'), // @deprecated - but impossible to delete
'query.year' => $begin->format('Y'), // @deprecated - but impossible to delete
'query.begin' => $formatter->getFormattedDateTime($begin),
'query.day' => $begin->format('d'), // @deprecated
'query.month' => $formatter->getFormattedMonthName($begin), // @deprecated
'query.month_number' => $begin->format('m'), // @deprecated
'query.year' => $begin->format('Y'), // @deprecated
'query.begin_day' => $begin->format('d'),
'query.begin_month' => $formatter->getFormattedMonthName($begin),
'query.begin_month_number' => $begin->format('m'),

View File

@@ -14,31 +14,39 @@ use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
use App\Project\ProjectStatisticService;
class InvoiceModelProjectHydrator implements InvoiceModelHydrator
final class InvoiceModelProjectHydrator implements InvoiceModelHydrator
{
use BudgetHydratorTrait;
private $projectStatistic;
public function __construct(ProjectStatisticService $projectStatistic)
public function __construct(private ProjectStatisticService $projectStatistic)
{
$this->projectStatistic = $projectStatistic;
}
public function hydrate(InvoiceModel $model): array
{
if (!$model->getQuery()->hasProjects()) {
$projects = [];
foreach ($model->getEntries() as $entry) {
if ($entry->getProject() === null) {
continue;
}
$key = 'P_' . $entry->getProject()->getId();
if (!\array_key_exists($key, $projects)) {
$projects[$key] = $entry->getProject();
}
}
if (\count($projects) === 0) {
return [];
}
$projects = array_values($projects);
$values = [];
$i = 0;
if (\count($model->getQuery()->getProjects()) === 1) {
$values['project'] = $model->getQuery()->getProjects()[0]->getName();
}
foreach ($model->getQuery()->getProjects() as $project) {
foreach ($projects as $project) {
$prefix = '';
if ($i > 0) {
$prefix = $i . '.';
@@ -59,8 +67,8 @@ class InvoiceModelProjectHydrator implements InvoiceModelHydrator
$values = [
$prefix . 'id' => $project->getId(),
$prefix . 'name' => $project->getName(),
$prefix . 'comment' => $project->getComment(),
$prefix . 'name' => $project->getName() ?? '',
$prefix . 'comment' => $project->getComment() ?? '',
$prefix . 'order_number' => $project->getOrderNumber(),
$prefix . 'start_date' => null !== $project->getStart() ? $formatter->getFormattedDateTime($project->getStart()) : '',
$prefix . 'end_date' => null !== $project->getEnd() ? $formatter->getFormattedDateTime($project->getEnd()) : '',
@@ -73,11 +81,13 @@ class InvoiceModelProjectHydrator implements InvoiceModelHydrator
$prefix . 'budget_time_minutes' => (int) ($project->getTimeBudget() / 60),
];
$statistic = $this->projectStatistic->getBudgetStatisticModel($project, $model->getQuery()->getEnd());
if ($model->getQuery()?->getEnd() !== null) {
$statistic = $this->projectStatistic->getBudgetStatisticModel($project, $model->getQuery()->getEnd());
$values = array_merge($values, $this->getBudgetValues($prefix, $statistic, $model));
$values = array_merge($values, $this->getBudgetValues($prefix, $statistic, $model));
}
foreach ($project->getVisibleMetaFields() as $metaField) {
foreach ($project->getMetaFields() as $metaField) {
$values = array_merge($values, [
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
]);

View File

@@ -13,7 +13,7 @@ use App\Entity\UserPreference;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelUserHydrator implements InvoiceModelHydrator
final class InvoiceModelUserHydrator implements InvoiceModelHydrator
{
public function hydrate(InvoiceModel $model): array
{
@@ -24,10 +24,10 @@ class InvoiceModelUserHydrator implements InvoiceModelHydrator
}
$values = [
'user.name' => $user->getUsername(),
'user.name' => $user->getUserIdentifier(),
'user.email' => $user->getEmail(),
'user.title' => $user->getTitle(),
'user.alias' => $user->getAlias(),
'user.title' => $user->getTitle() ?? '',
'user.alias' => $user->getAlias() ?? '',
];
/** @var UserPreference $metaField */