added invoice delete event (#3096)

This commit is contained in:
Kevin Papst
2022-01-24 21:33:13 +01:00
committed by GitHub
parent 9e320674c1
commit 8694a3bfe4
4 changed files with 65 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ use App\Constants;
use App\Entity\Invoice;
use App\Entity\InvoiceDocument;
use App\Event\InvoiceCreatedEvent;
use App\Event\InvoiceDeleteEvent;
use App\Event\InvoicePostRenderEvent;
use App\Event\InvoicePreRenderEvent;
use App\Repository\InvoiceDocumentRepository;
@@ -418,12 +419,17 @@ final class ServiceInvoice
return $this->createInvoiceFromModel($model, $dispatcher);
}
public function deleteInvoice(Invoice $invoice)
public function deleteInvoice(Invoice $invoice, EventDispatcherInterface $dispatcher)
{
$invoiceDirectory = $this->getInvoicesDirectory();
if (is_file($invoiceDirectory . $invoice->getInvoiceFilename())) {
$this->fileHelper->removeFile($invoiceDirectory . $invoice->getInvoiceFilename());
}
$event = new InvoiceDeleteEvent($invoice);
$dispatcher->dispatch($event);
$this->invoiceRepository->deleteInvoice($invoice);
}