diff --git a/app/Jobs/EDocument/CreateEDocument.php b/app/Jobs/EDocument/CreateEDocument.php index 7f96af177a91..be53d0a92a85 100644 --- a/app/Jobs/EDocument/CreateEDocument.php +++ b/app/Jobs/EDocument/CreateEDocument.php @@ -70,7 +70,7 @@ class CreateEDocument implements ShouldQueue if ($this->document instanceof Invoice) { switch ($e_document_type) { case "PEPPOL": - return (new Peppol($this->document))->toXml(); + return (new Peppol($this->document))->run()->toXml(); case "FACT1": return (new RoEInvoice($this->document))->generateXml(); case "FatturaPA": diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 749b4c32e2e9..5ea237f04a7b 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -17,6 +17,7 @@ use App\Utils\Traits\MakesHash; use App\Jobs\Entity\CreateRawPdf; use App\Jobs\Util\WebhookHandler; use App\Models\Traits\Excludable; +use App\Services\EDocument\Jobes\SendEDocument; use App\Services\PdfMaker\PdfMerge; use Illuminate\Database\Eloquent\Model; use App\Utils\Traits\UserSessionAttributes; @@ -297,8 +298,8 @@ class BaseModel extends Model } // special catch here for einvoicing eventing - if($event_id == Webhook::EVENT_SENT_INVOICE && ($this instanceof Invoice) && $this->e_invoice){ - // Einvoice + if($event_id == Webhook::EVENT_SENT_INVOICE && ($this instanceof Invoice) && is_null($this->backup)){ + \App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($this), $this->id, $this->company->db); } } diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php index 3e0409bcac86..a1d6e1d429b2 100644 --- a/app/Services/EDocument/Jobs/SendEDocument.php +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -9,7 +9,7 @@ * @license https://www.elastic.co/licensing/elastic-license */ -namespace App\Services\EDocument\Jobes; +namespace App\Services\EDocument\Jobs; use App\Utils\Ninja; use App\Models\Invoice; @@ -125,6 +125,9 @@ class SendEDocument implements ShouldQueue $activity->notes = $guid; $activity->save(); + $model->backup = $guid; + $model->saveQuietly(); + } /** diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index 4abd16d6dabd..94ad50ccc160 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -272,7 +272,7 @@ class Peppol extends AbstractService if($this->invoice->e_invoice) { - $this->p_invoice = $this->e->decode('Peppol', json_encode($this->invoice->e_invoice->Invoice), 'json'); + $this->p_invoice = $this->e->decode('Peppol', json_encode($this->invoice->e_invoice), 'json'); return $this; @@ -331,6 +331,11 @@ class Peppol extends AbstractService } + public function toObject(): mixed + { + return json_decode($this->toJson()); + } + public function toArray(): array { return json_decode($this->toJson(), true); @@ -356,6 +361,9 @@ class Peppol extends AbstractService $this->senderSpecificLevelMutators() ->receiverSpecificLevelMutators(); + $this->invoice->e_invoice = $this->toObject(); + $this->invoice->save(); + return $this; }