2019-08-12 23:45:21 +02:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-08-12 23:45:21 +02:00
|
|
|
namespace App\Controller\AdminPages;
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
use App\Entity\Attachments\CurrencyAttachment;
|
2020-06-07 21:11:09 +02:00
|
|
|
use App\Entity\Base\AbstractNamedDBElement;
|
2020-03-24 21:49:09 +01:00
|
|
|
use App\Entity\Parameters\CurrencyParameter;
|
2019-08-12 23:45:21 +02:00
|
|
|
use App\Entity\PriceInformations\Currency;
|
|
|
|
use App\Form\AdminPages\CurrencyAdminForm;
|
2020-06-07 22:38:10 +02:00
|
|
|
use App\Services\Attachments\AttachmentSubmitHandler;
|
2022-12-18 17:28:42 +01:00
|
|
|
use App\Services\ImportExportSystem\EntityExporter;
|
|
|
|
use App\Services\ImportExportSystem\EntityImporter;
|
|
|
|
use App\Services\Tools\ExchangeRateUpdater;
|
2023-04-03 22:48:52 +02:00
|
|
|
use App\Services\LabelSystem\LabelExampleElementsGenerator;
|
2020-06-07 22:38:10 +02:00
|
|
|
use App\Services\LabelSystem\LabelGenerator;
|
|
|
|
use App\Services\LogSystem\EventCommentHelper;
|
|
|
|
use App\Services\LogSystem\HistoryHelper;
|
|
|
|
use App\Services\LogSystem\TimeTravel;
|
2022-12-18 17:28:42 +01:00
|
|
|
use App\Services\Trees\StructuralElementRecursionHelper;
|
2019-08-12 23:45:21 +02:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2020-06-07 22:38:10 +02:00
|
|
|
use Exchanger\Exception\ChainException;
|
2022-12-11 15:10:16 +01:00
|
|
|
use Exchanger\Exception\Exception;
|
2020-06-07 22:38:10 +02:00
|
|
|
use Exchanger\Exception\UnsupportedCurrencyPairException;
|
|
|
|
use Omines\DataTablesBundle\DataTableFactory;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Symfony\Component\Form\FormInterface;
|
2020-01-05 22:49:00 +01:00
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2019-08-12 23:45:21 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2021-10-02 20:41:14 +02:00
|
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
2019-08-12 23:45:21 +02:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2020-06-07 22:38:10 +02:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-08-12 23:45:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/currency")
|
|
|
|
*
|
|
|
|
* Class CurrencyController
|
|
|
|
*/
|
|
|
|
class CurrencyController extends BaseAdminController
|
|
|
|
{
|
2023-02-03 23:43:44 +01:00
|
|
|
protected string $entity_class = Currency::class;
|
2023-02-04 23:34:39 +01:00
|
|
|
protected string $twig_template = 'admin/currency_admin.html.twig';
|
2023-02-03 23:43:44 +01:00
|
|
|
protected string $form_class = CurrencyAdminForm::class;
|
|
|
|
protected string $route_base = 'currency';
|
|
|
|
protected string $attachment_class = CurrencyAttachment::class;
|
|
|
|
protected ?string $parameter_class = CurrencyParameter::class;
|
2019-08-12 23:45:21 +02:00
|
|
|
|
2022-09-18 22:59:31 +02:00
|
|
|
protected ExchangeRateUpdater $exchangeRateUpdater;
|
2020-06-07 22:38:10 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
TranslatorInterface $translator,
|
2021-10-02 20:41:14 +02:00
|
|
|
UserPasswordHasherInterface $passwordEncoder,
|
2020-06-07 22:38:10 +02:00
|
|
|
AttachmentSubmitHandler $attachmentSubmitHandler,
|
|
|
|
EventCommentHelper $commentHelper,
|
|
|
|
HistoryHelper $historyHelper,
|
|
|
|
TimeTravel $timeTravel,
|
|
|
|
DataTableFactory $dataTableFactory,
|
|
|
|
EventDispatcherInterface $eventDispatcher,
|
2023-04-03 22:48:52 +02:00
|
|
|
LabelExampleElementsGenerator $barcodeExampleGenerator,
|
2020-06-07 22:38:10 +02:00
|
|
|
LabelGenerator $labelGenerator,
|
|
|
|
EntityManagerInterface $entityManager,
|
|
|
|
ExchangeRateUpdater $exchangeRateUpdater
|
|
|
|
) {
|
|
|
|
$this->exchangeRateUpdater = $exchangeRateUpdater;
|
|
|
|
|
|
|
|
parent::__construct(
|
|
|
|
$translator,
|
|
|
|
$passwordEncoder,
|
|
|
|
$attachmentSubmitHandler,
|
|
|
|
$commentHelper,
|
|
|
|
$historyHelper,
|
|
|
|
$timeTravel,
|
|
|
|
$dataTableFactory,
|
|
|
|
$eventDispatcher,
|
|
|
|
$barcodeExampleGenerator,
|
|
|
|
$labelGenerator,
|
|
|
|
$entityManager
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-26 22:27:04 +02:00
|
|
|
/**
|
|
|
|
* @Route("/{id}", name="currency_delete", methods={"DELETE"})
|
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function delete(Request $request, Currency $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
|
2019-10-26 22:27:04 +02:00
|
|
|
{
|
|
|
|
return $this->_delete($request, $entity, $recursionHelper);
|
|
|
|
}
|
|
|
|
|
2020-06-07 22:38:10 +02:00
|
|
|
public function additionalActionEdit(FormInterface $form, AbstractNamedDBElement $entity): bool
|
|
|
|
{
|
|
|
|
if (!$entity instanceof Currency) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:00:27 +02:00
|
|
|
//@phpstan-ignore-next-line
|
2020-06-07 22:38:10 +02:00
|
|
|
if ($form->get('update_exchange_rate')->isClicked()) {
|
|
|
|
$this->denyAccessUnlessGranted('edit', $entity);
|
|
|
|
try {
|
|
|
|
$this->exchangeRateUpdater->update($entity);
|
|
|
|
$this->addFlash('info', 'currency.edit.exchange_rate_updated.success');
|
2022-12-11 15:10:16 +01:00
|
|
|
} catch (Exception $exception) {
|
|
|
|
//$exception = $exception->getExceptions()[0];
|
2020-08-21 21:36:22 +02:00
|
|
|
if ($exception instanceof UnsupportedCurrencyPairException || false !== stripos($exception->getMessage(), 'supported')) {
|
2020-06-07 22:38:10 +02:00
|
|
|
$this->addFlash('error', 'currency.edit.exchange_rate_update.unsupported_currency');
|
|
|
|
} else {
|
|
|
|
$this->addFlash('error', 'currency.edit.exchange_rate_update.generic_error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-12 23:45:21 +02:00
|
|
|
/**
|
2020-03-04 21:54:03 +01:00
|
|
|
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="currency_edit")
|
2019-10-26 22:27:04 +02:00
|
|
|
* @Route("/{id}", requirements={"id"="\d+"})
|
2019-08-12 23:45:21 +02:00
|
|
|
*/
|
2020-03-04 21:54:03 +01:00
|
|
|
public function edit(Currency $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response
|
2019-08-12 23:45:21 +02:00
|
|
|
{
|
2020-03-04 21:54:03 +01:00
|
|
|
return $this->_edit($entity, $request, $em, $timestamp);
|
2019-08-12 23:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/new", name="currency_new")
|
2020-04-06 13:14:47 +02:00
|
|
|
* @Route("/{id}/clone", name="currency_clone")
|
2019-08-12 23:45:21 +02:00
|
|
|
* @Route("/")
|
|
|
|
*/
|
2020-04-06 13:14:47 +02:00
|
|
|
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?Currency $entity = null): Response
|
2019-08-12 23:45:21 +02:00
|
|
|
{
|
2020-04-06 13:14:47 +02:00
|
|
|
return $this->_new($request, $em, $importer, $entity);
|
2019-08-12 23:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/export", name="currency_export_all")
|
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request): Response
|
2019-08-12 23:45:21 +02:00
|
|
|
{
|
|
|
|
return $this->_exportAll($em, $exporter, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/{id}/export", name="currency_export")
|
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function exportEntity(Currency $entity, EntityExporter $exporter, Request $request): Response
|
2019-08-12 23:45:21 +02:00
|
|
|
{
|
|
|
|
return $this->_exportEntity($entity, $exporter, $request);
|
|
|
|
}
|
2020-06-07 21:11:09 +02:00
|
|
|
|
|
|
|
public function deleteCheck(AbstractNamedDBElement $entity): bool
|
|
|
|
{
|
2020-08-21 22:43:37 +02:00
|
|
|
if (($entity instanceof Currency) && $entity->getPricedetails()->count() > 0) {
|
|
|
|
$this->addFlash('error', 'entity.delete.must_not_contain_prices');
|
2020-08-21 21:36:22 +02:00
|
|
|
|
2020-08-21 22:43:37 +02:00
|
|
|
return false;
|
2020-06-07 21:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
}
|