diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 40c7ab9208cc..175940b1f6eb 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -304,6 +304,31 @@ class BaseModel extends Model } + + /** + * arrayFilterRecursive + * + * Removes null properties from an array + * + * @param array $array + * @return array + */ + public function arrayFilterRecursive(array $array): array + { + foreach ($array as $key => $value) { + if (is_array($value)) { + // Recursively filter the nested array + $array[$key] = $this->arrayFilterRecursive($value); + } + // Remove null values + if (is_null($array[$key])) { + unset($array[$key]); + } + } + + return $array; + } + /** * Returns the base64 encoded PDF string of the entity * @deprecated - unused implementation diff --git a/app/Models/Client.php b/app/Models/Client.php index c5ef8c20849e..26c8ee79e6ab 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -50,7 +50,7 @@ use Laracasts\Presenter\PresentableTrait; * @property int|null $last_login * @property int|null $industry_id * @property int|null $size_id - * @property object|null $e_invoice + * @property object|array|null $e_invoice * @property string|null $address1 * @property string|null $address2 * @property string|null $city diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index 8c52b83f9572..dc77bb4827e9 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -76,6 +76,13 @@ class ClientRepository extends BaseRepository $client->country_id = $company->settings->country_id; } + if(isset($data['e_invoice']) && is_array($data['e_invoice'])) { + //ensure it is normalized first! + $data['e_invoice'] = $client->arrayFilterRecursive($data['e_invoice']); + + $client->e_invoice = $data['e_invoice']; + } + $client->save(); if (! isset($client->number) || empty($client->number) || strlen($client->number) == 0) { @@ -106,6 +113,7 @@ class ClientRepository extends BaseRepository if (array_key_exists('contacts', $contact_data) || $client->contacts()->count() == 0) { $this->contact_repo->save($contact_data, $client); } + return $client; } diff --git a/app/Repositories/CompanyRepository.php b/app/Repositories/CompanyRepository.php index a2a2195d3b85..44bf6b2cbe9b 100644 --- a/app/Repositories/CompanyRepository.php +++ b/app/Repositories/CompanyRepository.php @@ -60,7 +60,7 @@ class CompanyRepository extends BaseRepository if(isset($data['e_invoice']) && is_array($data['e_invoice'])){ //ensure it is normalized first! - $data['e_invoice'] = $this->arrayFilterRecursive($data['e_invoice']); + $data['e_invoice'] = $company->arrayFilterRecursive($data['e_invoice']); $company->e_invoice = $data['e_invoice']; } @@ -70,24 +70,6 @@ class CompanyRepository extends BaseRepository return $company; } - - private function arrayFilterRecursive(array $array): array - { - foreach ($array as $key => $value) { - if (is_array($value)) { - // Recursively filter the nested array - $array[$key] = $this->arrayFilterRecursive($value); - } - // Remove null values - if (is_null($array[$key])) { - unset($array[$key]); - } - } - - return $array; - } - - /** * parseCustomFields * diff --git a/app/Services/EDocument/Jobs/SendEDocument.php b/app/Services/EDocument/Jobs/SendEDocument.php index 16c021510edf..7528fc227a42 100644 --- a/app/Services/EDocument/Jobs/SendEDocument.php +++ b/app/Services/EDocument/Jobs/SendEDocument.php @@ -123,10 +123,11 @@ class SendEDocument implements ShouldQueue $activity->company_id = $model->company_id; $activity->activity_type_id = Activity::EMAIL_EINVOICE_SUCCESS; $activity->invoice_id = $model->id; - $activity->notes = $guid; + $activity->notes = str_replace('"', '', $guid); + $activity->save(); - $model->backup = $guid; + $model->backup = str_replace('"', '', $guid); $model->saveQuietly(); } diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index d97bc3be0d5f..bce608b94c48 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -276,7 +276,7 @@ class Peppol extends AbstractService $this->p_invoice->DueDate = new \DateTime($this->invoice->due_date); } - $this->p_invoice->InvoiceTypeCode = 380; // + $this->p_invoice->InvoiceTypeCode = ($this->invoice->amount >= 0) ? 380 : 381; // $this->p_invoice->AccountingSupplierParty = $this->getAccountingSupplierParty(); $this->p_invoice->AccountingCustomerParty = $this->getAccountingCustomerParty(); $this->p_invoice->InvoiceLine = $this->getInvoiceLines(); diff --git a/composer.json b/composer.json index 4fac873d9d2f..34db308abd13 100644 --- a/composer.json +++ b/composer.json @@ -201,8 +201,8 @@ "url": "https://github.com/turbo124/snappdf" }, { - "type":"vcs", - "url":"https://github.com/karneaud/QuickBooks-V3-PHP-SDK.git" + "type": "vcs", + "url": "https://github.com/karneaud/QuickBooks-V3-PHP-SDK.git" } ], "minimum-stability": "dev", diff --git a/tests/Integration/Einvoice/Fact1Test.php b/tests/Integration/Einvoice/Fact1Test.php index 2b611cc3f474..35b5da22d334 100644 --- a/tests/Integration/Einvoice/Fact1Test.php +++ b/tests/Integration/Einvoice/Fact1Test.php @@ -67,7 +67,7 @@ use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory; /** * @test */ -class FACT1Test extends TestCase +class Fact1Test extends TestCase { use MockAccountData; use DatabaseTransactions; diff --git a/tests/Unit/EInvoiceTest.php b/tests/Unit/EInvoiceTest.php index 218676c64043..42004703692c 100644 --- a/tests/Unit/EInvoiceTest.php +++ b/tests/Unit/EInvoiceTest.php @@ -9,6 +9,8 @@ * @license https://www.elastic.co/licensing/elastic-license */ +namespace Tests\Unit; + use App\Jobs\EDocument\CreateEDocument; use App\Jobs\Entity\CreateRawPdf; use horstoeko\zugferd\ZugferdDocumentReader;