From cee0f7ec95cbf0efb83993c9f16e469943a05e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 22 Nov 2024 17:12:15 +0100 Subject: [PATCH] Update quota when sending einvoice docs --- app/Services/EDocument/Jobs/SendEDocument.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php index 5ff2eb9318..db1fd8a910 100644 --- a/app/Services/EDocument/Jobs/SendEDocument.php +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -95,12 +95,19 @@ class SendEDocument implements ShouldQueue $r = Http::withHeaders([...$this->getHeaders(), 'X-EInvoice-Token' => $model->company->account->e_invoicing_token]) ->post(config('ninja.hosted_ninja_url')."/api/einvoice/submission", $payload); + if ($r->hasHeader('X-EINVOICE-QUOTA')) { + $account = $model->company->account; + + $account->e_invoice_quota = (int) $r->header('X-EINVOICE-QUOTA'); + $account->save(); + } + if ($r->successful()) { nlog("Model {$model->number} was successfully sent for third party processing via hosted Invoice Ninja"); $data = $r->json(); - return $this->writeActivity($model, $data['guid']); + return $this->writeActivity($model, $data['guid']); } if ($r->failed()) {