0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-04-03 13:05:24 +00:00

prevent that items will be marked as exported if invoice can not be generated, check for existing invoice number to prevent that invalid invoices will be generated

This commit is contained in:
Kevin Papst 2021-11-15 10:44:26 +01:00
parent 8978c181ee
commit e832fe57c4
2 changed files with 26 additions and 4 deletions

View file

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Invoice;
final class DuplicateInvoiceNumberException extends \Exception
{
public function __construct(string $invoiceNumber)
{
parent::__construct('Invoice number "' . $invoiceNumber . '" already existing');
}
}

View file

@ -366,12 +366,12 @@ final class ServiceInvoice
if ($renderer->supports($document)) {
$dispatcher->dispatch(new InvoicePreRenderEvent($model, $document, $renderer));
$response = $renderer->render($document, $model);
if ($model->getQuery()->isMarkAsExported()) {
$this->markEntriesAsExported($model->getEntries());
if ($this->invoiceRepository->hasInvoice($model->getInvoiceNumber())) {
throw new DuplicateInvoiceNumberException($model->getInvoiceNumber());
}
$response = $renderer->render($document, $model);
$event = new InvoicePostRenderEvent($model, $document, $renderer, $response);
$dispatcher->dispatch($event);
@ -382,6 +382,10 @@ final class ServiceInvoice
$invoice->setFilename($invoiceFilename);
$this->invoiceRepository->saveInvoice($invoice);
if ($model->getQuery()->isMarkAsExported()) {
$this->markEntriesAsExported($model->getEntries());
}
$dispatcher->dispatch(new InvoiceCreatedEvent($invoice));
return $invoice;