Sending einvoices

This commit is contained in:
David Bomba 2024-08-29 15:51:48 +10:00
parent 73ed01a9bc
commit 52630f06e3
4 changed files with 17 additions and 5 deletions

View File

@ -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":

View File

@ -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);
}
}

View File

@ -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();
}
/**

View File

@ -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;
}