From 286b2087cd01b6711ee82e6d74b49b1921d62a00 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 8 Aug 2024 17:48:24 +1000 Subject: [PATCH] Updated URL for trouble shooting --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- app/Models/Invoice.php | 8 +- .../EDocument/Gateway/Storecove/Storecove.php | 15 +- app/Services/EDocument/Standards/Peppol.php | 55 +++-- .../Einvoice/Storecove/StorecoveTest.php | 225 ++++++++++-------- 5 files changed, 171 insertions(+), 134 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index badbdef1d55d..6feefd261a06 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,7 +8,7 @@ assignees: '' --- +https://invoiceninja.github.io/en/self-host-troubleshooting/ --> ## Setup - Version: diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 2383c0f42af0..fe2b1222f391 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -614,17 +614,17 @@ class Invoice extends BaseModel event(new InvoiceWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $template)); break; case 'reminder1': - event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $template)); + event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $reminder_template)); break; case 'reminder2': - event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $template)); + event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $reminder_template)); break; case 'reminder3': - event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $template)); + event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $reminder_template)); break; case 'reminder_endless': case 'endless_reminder': - event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $template)); + event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), $reminder_template)); break; case 'custom1': case 'custom2': diff --git a/app/Services/EDocument/Gateway/Storecove/Storecove.php b/app/Services/EDocument/Gateway/Storecove/Storecove.php index ede48f486e8e..9734abfa587e 100644 --- a/app/Services/EDocument/Gateway/Storecove/Storecove.php +++ b/app/Services/EDocument/Gateway/Storecove/Storecove.php @@ -148,17 +148,20 @@ class Storecove { "emails" => ["david@invoiceninja.com"] ], "document"=> [ - 'documentType' => 'invoice', - "rawDocumentData"=> [ - "document" => base64_encode($document), - "parse" => true, - "parseStrategy"=> "ubl", - ], + ], ]; $payload = array_merge($payload, $override_payload); + + $payload['document']['documentType'] = 'invoice'; + $payload['document']["rawDocumentData"] = [ + "document" => base64_encode($document), + "parse" => true, + "parseStrategy"=> "ubl", + ]; + $uri = "document_submissions"; nlog($payload); diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index c01d6f7c23ce..8540e214802e 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -862,15 +862,17 @@ class Peppol extends AbstractService $this->p_invoice->OrderReference = $order_reference; - $this->setStorecoveMeta(["document" => [ - "invoice" => [ - "references" => [ - "documentType" => "purchase_order", - "documentId" => $this->invoice->po_number, - ], - ], - ] - ]); + // $this->setStorecoveMeta(["document" => [ + // "invoice" => [ + // [ + // "references" => [ + // "documentType" => "purchase_order", + // "documentId" => $this->invoice->po_number, + // ], + // ], + // ], + // ] + // ]); return $this; } @@ -952,7 +954,25 @@ class Peppol extends AbstractService ]; } + /** + * setStorecoveMeta + * + * updates the storecove payload for sending documents + * + * @param array $meta + * @return self + */ + private function setStorecoveMeta(array $meta): self + { + $this->storecove_meta = array_merge($this->storecove_meta, $meta); + + return $this; + } + public function getStorecoveMeta(): array + { + return $this->storecove_meta; + } @@ -977,21 +997,7 @@ class Peppol extends AbstractService return $this; } - - /** - * setStorecoveMeta - * - * updates the storecove payload for sending documents - * - * @param array $meta - * @return self - */ - private function setStorecoveMeta(array $meta): self - { - $this->storecove_meta = array_merge($this->storecove_meta, $meta); - - return $this; - } + /** * CH * @@ -1109,7 +1115,6 @@ class Peppol extends AbstractService $this->setCustomerAssignedAccountId(true); } - if(strlen($this->invoice->client->id_number ?? '') == 9) { //SIREN diff --git a/tests/Integration/Einvoice/Storecove/StorecoveTest.php b/tests/Integration/Einvoice/Storecove/StorecoveTest.php index fa7408d52291..e6e619dd8e39 100644 --- a/tests/Integration/Einvoice/Storecove/StorecoveTest.php +++ b/tests/Integration/Einvoice/Storecove/StorecoveTest.php @@ -509,113 +509,110 @@ $x = ' { $this->routing_id = 293338; + $settings = CompanySettings::defaults(); + $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; + $settings->website = 'www.invoiceninja.de'; -$settings = CompanySettings::defaults(); -$settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; -$settings->website = 'www.invoiceninja.de'; + $settings->address1 = '10 Rue de la Paix'; + $settings->address2 = 'Bâtiment A, Bureau 5'; + $settings->city = 'Paris'; + $settings->state = 'Île-de-France'; + $settings->postal_code = '75002'; + $settings->phone = '01 23456789'; + $settings->email = $this->faker->unique()->safeEmail(); + $settings->country_id = '250'; // France's ISO country code + $settings->vat_number = 'FR82345678911'; + $settings->id_number = '12345678900010'; + $settings->classification = 'business'; + $settings->use_credits_payment = 'always'; + $settings->timezone_id = '1'; // CET (Central European Time) + $settings->entity_send_time = 0; + $settings->e_invoice_type = 'PEPPOL'; + $settings->currency_id = '3'; -$settings->address1 = '10 Rue de la Paix'; -$settings->address2 = 'Bâtiment A, Bureau 5'; -$settings->city = 'Paris'; -$settings->state = 'Île-de-France'; -$settings->postal_code = '75002'; -$settings->phone = '01 23456789'; -$settings->email = $this->faker->unique()->safeEmail(); -$settings->country_id = '250'; // France's ISO country code -$settings->vat_number = 'FR12345678901'; -$settings->id_number = '12345678900010'; + $company = Company::factory()->create([ + 'account_id' => $this->account->id, + 'settings' => $settings, + ]); -$settings->use_credits_payment = 'always'; -$settings->timezone_id = '1'; // CET (Central European Time) -$settings->entity_send_time = 0; -$settings->e_invoice_type = 'PEPPOL'; -$settings->currency_id = '3'; + $this->user->companies()->attach($company->id, [ + 'account_id' => $this->account->id, + 'is_owner' => true, + 'is_admin' => 1, + 'is_locked' => 0, + 'permissions' => '', + 'notifications' => CompanySettings::notificationAdminDefaults(), + 'settings' => null, + ]); -$company = Company::factory()->create([ - 'account_id' => $this->account->id, - 'settings' => $settings, -]); + Client::unguard(); -$this->user->companies()->attach($company->id, [ - 'account_id' => $this->account->id, - 'is_owner' => true, - 'is_admin' => 1, - 'is_locked' => 0, - 'permissions' => '', - 'notifications' => CompanySettings::notificationAdminDefaults(), - 'settings' => null, -]); - -Client::unguard(); - -$c = -Client::create([ - 'company_id' => $company->id, - 'user_id' => $this->user->id, - 'name' => 'Beispiel Firma GmbH', - 'website' => 'https://www.beispiel-firma.de', - 'private_notes' => 'Dies sind private Notizen zum Testkunden.', - 'balance' => 0, - 'paid_to_date' => 0, - 'vat_number' => 'DE654321987', - 'id_number' => 'HRB 12345', // Typical format for German company registration numbers - 'custom_value1' => '2024-07-22 10:00:00', - 'custom_value2' => 'blau', - 'custom_value3' => 'musterwort', - 'custom_value4' => 'test@example.com', - 'address1' => 'Musterstraße 123', - 'address2' => '2. Etage, Büro 45', - 'city' => 'München', - 'state' => 'Bayern', - 'postal_code' => '80331', - 'country_id' => '276', // Germany - 'shipping_address1' => 'Musterstraße 123', - 'shipping_address2' => '2. Etage, Büro 45', - 'shipping_city' => 'München', - 'shipping_state' => 'Bayern', - 'shipping_postal_code' => '80331', - 'shipping_country_id' => '276', // Germany - 'settings' => ClientSettings::Defaults(), - 'client_hash' => \Illuminate\Support\Str::random(32), - 'routing_id' => '', -]); + $c = + Client::create([ + 'company_id' => $company->id, + 'user_id' => $this->user->id, + 'name' => 'Exemple Société S.A.', + 'website' => 'https://www.exemple-societe.fr', + 'private_notes' => 'Ceci est une note privée pour le client test.', + 'balance' => 0, + 'paid_to_date' => 0, + 'vat_number' => 'FR12345678901', + 'id_number' => '12345678900010', // Typical format for French company registration numbers + 'custom_value1' => '2024-07-22 10:00:00', + 'custom_value2' => 'bleu', + 'custom_value3' => 'motexemple', + 'custom_value4' => 'test@example.com', + 'address1' => '123 Rue de l\'Exemple', + 'address2' => '2ème étage, Bureau 45', + 'city' => 'Paris', + 'state' => 'Île-de-France', + 'postal_code' => '75001', + 'country_id' => '250', // France + 'shipping_address1' => '123 Rue de l\'Exemple', + 'shipping_address2' => '2ème étage, Bureau 45', + 'shipping_city' => 'Paris', + 'shipping_state' => 'Île-de-France', + 'shipping_postal_code' => '75001', + 'shipping_country_id' => '250', // France + 'classification' => 'business', + 'settings' => ClientSettings::Defaults(), + 'client_hash' => \Illuminate\Support\Str::random(32), + 'routing_id' => '', + ]); -$item = new InvoiceItem(); -$item->product_key = "Product Key"; -$item->notes = "Product Description"; -$item->cost = 10; -$item->quantity = 10; -$item->tax_rate1 = 19; -$item->tax_name1 = 'mwst'; + $item = new InvoiceItem(); + $item->product_key = "Product Key"; + $item->notes = "Product Description"; + $item->cost = 10; + $item->quantity = 10; + $item->tax_rate1 = 20; + $item->tax_name1 = 'VAT'; -$invoice = Invoice::factory()->create([ - 'company_id' => $company->id, - 'user_id' => $this->user->id, - 'client_id' => $c->id, - 'discount' => 0, - 'uses_inclusive_taxes' => false, - 'status_id' => 1, - 'tax_rate1' => 0, - 'tax_name1' => '', - 'tax_rate2' => 0, - 'tax_rate3' => 0, - 'tax_name2' => '', - 'tax_name3' => '', - 'line_items' => [$item], - 'number' => 'DE-'.rand(1000, 100000), - 'date' => now()->format('Y-m-d'), - 'due_date' => now()->addDays(14)->format('Y-m-d'), -]); + $invoice = Invoice::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $this->user->id, + 'client_id' => $c->id, + 'discount' => 0, + 'uses_inclusive_taxes' => false, + 'status_id' => 1, + 'tax_rate1' => 0, + 'tax_name1' => '', + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'tax_name2' => '', + 'tax_name3' => '', + 'line_items' => [$item], + 'number' => 'DE-'.rand(1000, 100000), + 'date' => now()->format('Y-m-d'), + 'due_date' => now()->addDays(14)->format('Y-m-d'), + ]); -$invoice = $invoice->calc()->getInvoice(); -$invoice->service()->markSent()->save(); - - -return $invoice; - + $invoice = $invoice->calc()->getInvoice(); + $invoice->service()->markSent()->save(); + return $invoice; } @@ -728,7 +725,39 @@ return $invoice; } - public function testEsRules() + public function testFrRules() + { + + $invoice = $this->createFRData(); + + $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); + + $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); + foreach($stub as $key => $value) { + $e_invoice->{$key} = $value; + } + + $invoice->e_invoice = $e_invoice; + $invoice->save(); + + $this->assertInstanceOf(Invoice::class, $invoice); + $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); + + $p = new Peppol($invoice); + + $p->run(); + $xml = $p->toXml(); + nlog($xml); + + $identifiers = $p->getStorecoveMeta(); + + $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); + $sc->sendDocument($xml, $this->routing_id, $identifiers); + + } + + + public function RtestEsRules() { $invoice = $this->createESData(); @@ -768,7 +797,7 @@ return $invoice; } - public function testDeRules() + public function RtestDeRules() { $invoice = $this->createDEData();