use configured language for non-twig invoice templates (#1924)
This commit is contained in:
@@ -23,6 +23,7 @@ use App\Repository\InvoiceTemplateRepository;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
use Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\SubmitButton;
|
||||
@@ -83,7 +84,6 @@ final class InvoiceController extends AbstractController
|
||||
$this->flashWarning('invoice.first_template');
|
||||
}
|
||||
|
||||
$showPreview = false;
|
||||
$model = null;
|
||||
|
||||
$query = $this->getDefaultQuery();
|
||||
@@ -92,6 +92,11 @@ final class InvoiceController extends AbstractController
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($this->isGranted('create_invoice') && $form->isValid()) {
|
||||
// use the current request locale as fallback, if no translation was configured
|
||||
if (null !== $query->getTemplate() && null === $query->getTemplate()->getLanguage()) {
|
||||
$query->getTemplate()->setLanguage($request->getLocale());
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var SubmitButton $createButton */
|
||||
$createButton = $form->get('create');
|
||||
@@ -104,7 +109,7 @@ final class InvoiceController extends AbstractController
|
||||
if ($printButton->isClicked()) {
|
||||
return $this->service->renderInvoice($query, $this->dispatcher);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->logException($ex);
|
||||
$this->flashError('action.update.error', ['%reason%' => 'check doctor/logs']);
|
||||
}
|
||||
@@ -112,29 +117,23 @@ final class InvoiceController extends AbstractController
|
||||
/** @var SubmitButton $previewButton */
|
||||
$previewButton = $form->get('preview');
|
||||
if ($previewButton->isClicked()) {
|
||||
$showPreview = true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$model = $this->service->createModel($query);
|
||||
if ($showPreview) {
|
||||
$entries = $this->service->findInvoiceItems($query);
|
||||
if (!empty($entries)) {
|
||||
$model->addEntries($entries);
|
||||
try {
|
||||
$model = $this->service->createModel($query);
|
||||
$entries = $this->service->findInvoiceItems($query);
|
||||
if (!empty($entries)) {
|
||||
$model->addEntries($entries);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
$this->logException($ex);
|
||||
$this->flashError($ex->getMessage());
|
||||
}
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->logException($ex);
|
||||
$this->flashError($ex->getMessage());
|
||||
$showPreview = false;
|
||||
}
|
||||
|
||||
return $this->render('invoice/index.html.twig', [
|
||||
'query' => $query,
|
||||
'model' => $model,
|
||||
'form' => $form->createView(),
|
||||
'preview' => $showPreview,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -174,7 +173,7 @@ final class InvoiceController extends AbstractController
|
||||
$file = $this->service->getInvoiceFile($invoice);
|
||||
|
||||
return $this->file($file->getRealPath(), $file->getBasename());
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->flashError($ex->getMessage());
|
||||
}
|
||||
|
||||
@@ -190,7 +189,7 @@ final class InvoiceController extends AbstractController
|
||||
try {
|
||||
$this->service->changeInvoiceStatus($invoice, $status);
|
||||
$this->flashSuccess('action.update.success');
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->flashError('action.update.error');
|
||||
}
|
||||
|
||||
@@ -206,7 +205,7 @@ final class InvoiceController extends AbstractController
|
||||
try {
|
||||
$this->service->deleteInvoice($invoice);
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->flashError('action.delete.error');
|
||||
}
|
||||
|
||||
@@ -330,7 +329,7 @@ final class InvoiceController extends AbstractController
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_invoice_document_upload');
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->flashError(
|
||||
sprintf('Failed uploading invoice document: %e', $e->getMessage())
|
||||
);
|
||||
@@ -375,7 +374,7 @@ final class InvoiceController extends AbstractController
|
||||
try {
|
||||
$this->templateRepository->removeTemplate($template);
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
@@ -394,7 +393,7 @@ final class InvoiceController extends AbstractController
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_invoice_template');
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user