From 9f7ff7dc597475b6f44807ad6b76e9aa455a36f1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Aug 2024 11:17:38 +1000 Subject: [PATCH] Stubs for sending edocs --- app/Jobs/Mail/NinjaMailerJob.php | 1 + app/Models/BaseModel.php | 11 +++ app/Services/EDocument/Jobs/SendEDocument.php | 68 +++++++++++++++++++ app/Services/Email/Email.php | 2 +- 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/Services/EDocument/Jobs/SendEDocument.php diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 7f2cac34585c..2cf7563ea483 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -48,6 +48,7 @@ class NinjaMailerJob implements ShouldQueue use MakesHash; public $tries = 4; //number of retries + public $deleteWhenMissingModels = true; /** @var null|\App\Models\Company $company **/ diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index fa06c90c60a3..186058f241d7 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -294,6 +294,17 @@ class BaseModel extends Model if ($subscriptions) { WebhookHandler::dispatch($event_id, $this->withoutRelations(), $this->company, $additional_data); } + + // special catch here for einvoicing eventing + if($event_id == Webhook::EVENT_SENT_INVOICE && $this->e_invoice){ + $this->handleEinvoiceSending(); + } + + } + + private function handleEinvoiceSending() + { + } /** diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php new file mode 100644 index 000000000000..687b47beb5ef --- /dev/null +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -0,0 +1,68 @@ +db); + + $model = $this->entity::find($this->id); + $e_invoice_standard = $model->client ? $model->client->getSetting('e_invoice_type') : $model->company->getSetting('e_invoice_type'); + + if($e_invoice_standard != 'PEPPOL') + return; + + } + + public function failed($exception = null) + { + if ($exception) { + nlog("EXCEPTION:: SENDEDOCUMENT::"); + nlog($exception->getMessage()); + } + + config(['queue.failed.driver' => null]); + } + + public function middleware() + { + return [new WithoutOverlapping($this->entity.$this->id.$this->db)]; + } +} diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index c3e0909824cc..2e21bb8b4af7 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -646,7 +646,7 @@ class Email implements ShouldQueue $user = $this->resolveSendingUser(); - $sending_email = (isset($this->email_object->settings->custom_sending_email) && stripos($this->email_object->settings->custom_sending_email, "@")) ? $this->email_object->settings->custom_sending_email : $user->email; + $sending_email = (isset($this->email_object->settings->custom_sending_email) && (stripos($this->email_object->settings->custom_sending_email, "@")) !== false) ? $this->email_object->settings->custom_sending_email : $user->email; $sending_user = (isset($this->email_object->settings->email_from_name) && strlen($this->email_object->settings->email_from_name) > 2) ? $this->email_object->settings->email_from_name : $user->name(); $this->mailable