Logic to update e_invoice

This commit is contained in:
David Bomba 2024-08-30 15:00:25 +10:00
parent c52bc3dae7
commit 94da1d9ded
4 changed files with 21 additions and 6 deletions

View File

@ -298,7 +298,7 @@ class BaseModel extends Model
} }
// special catch here for einvoicing eventing // special catch here for einvoicing eventing
if($event_id == Webhook::EVENT_SENT_INVOICE && ($this instanceof Invoice) && is_null($this->backup)){ if($event_id == Webhook::EVENT_SENT_INVOICE && ($this instanceof Invoice) && is_null($this->backup) && $this->client->getSetting('e_invoice_type') == 'PEPPOL'){
\App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($this), $this->id, $this->company->db); \App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($this), $this->id, $this->company->db);
} }

View File

@ -320,6 +320,17 @@ class BaseRepository
UpdateTaxData::dispatch($client, $client->company); UpdateTaxData::dispatch($client, $client->company);
} }
/** If Peppol is enabled - we will save the e_invoice document here at this point, document will not update after being sent */
if(strlen($model->backup ?? '') == 0 && $client->getSetting('e_invoice_type') == 'PEPPOL' && $model->company->legal_entity_id)
{
try{
$model->service()->getEInvoice();
}
catch(\Exception $e){
nlog("EXCEPTION:: BASEREPOSITORY:: Error generating e_invoice for model {$model->id}");
nlog($e->getMessage());
}
}
} }
if ($model instanceof Credit) { if ($model instanceof Credit) {

View File

@ -50,10 +50,11 @@ class SendEDocument implements ShouldQueue
MultiDB::setDB($this->db); MultiDB::setDB($this->db);
$model = $this->entity::find($this->id); $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') // $e_invoice_standard = $model->client ? $model->client->getSetting('e_invoice_type') : $model->company->getSetting('e_invoice_type');
return;
// if($e_invoice_standard != 'PEPPOL')
// return;
if(Ninja::isSelfHost() && ($model instanceof Invoice) && $model->company->legal_entity_id) if(Ninja::isSelfHost() && ($model instanceof Invoice) && $model->company->legal_entity_id)
{ {

View File

@ -287,8 +287,11 @@ class Peppol extends AbstractService
$this->senderSpecificLevelMutators() $this->senderSpecificLevelMutators()
->receiverSpecificLevelMutators(); ->receiverSpecificLevelMutators();
$this->invoice->e_invoice = $this->toObject(); if(strlen($this->invoice->backup ?? '') == 0)
$this->invoice->save(); {
$this->invoice->e_invoice = $this->toObject();
$this->invoice->save();
}
return $this; return $this;