Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/Demo/DemoSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Modules\EInvoicing\Demo;

use Illuminate\Database\Seeder;
use Modules\EInvoicing\Application\EInvoicingSettings;

/**
* E-invoicing switched on for the public demo, with the bank details and
* payment terms an e-invoice asks for, so the demo's invoices show the
* module at work as soon as it opens.
*
* The host's demo reset calls run() once the demo company exists, passing
* the company to fill. A company that already has an IBAN is left alone.
*/
final class DemoSeeder extends Seeder
{
/** The IBAN and BIC used as examples everywhere, not a real account. */
public const IBAN = 'DE89370400440532013000';

public const BIC = 'COBADEFFXXX';

public const PAYMENT_TERMS = 'Payable within 14 days without deduction.';

public function run(int $companyId, EInvoicingSettings $settings): void
{
if ($settings->iban($companyId) !== null) {
return;
}

$settings->save($companyId, [
'enabled' => true,
'iban' => self::IBAN,
'bic' => self::BIC,
'payment_terms' => self::PAYMENT_TERMS,
]);
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"requires": {},
"schema_version": 2,
"slug": "e-invoicing",
"version": "0.1.0",
"version": "0.1.1",
"license": "AGPL-3.0-only",
"compatibility": {
"invoiceshelf": ">=3.0.0-alpha.13 <4.0.0",
Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/DemoSeederTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Modules\EInvoicing\Tests\Unit;

use Modules\EInvoicing\Application\EInvoicingSettings;
use Modules\EInvoicing\Demo\DemoSeeder;
use Modules\EInvoicing\Tests\TestCase;

final class DemoSeederTest extends TestCase
{
public function test_the_demo_reset_switches_e_invoicing_on_with_bank_details_and_terms(): void
{
// The call the host's DemoReset makes for each pinned module.
app(DemoSeeder::class)->setContainer(app())->__invoke(['companyId' => self::COMPANY]);

self::assertSame([
'enabled' => true,
'iban' => DemoSeeder::IBAN,
'bic' => DemoSeeder::BIC,
'payment_terms' => DemoSeeder::PAYMENT_TERMS,
], app(EInvoicingSettings::class)->forCompany(self::COMPANY));
}

public function test_a_company_that_already_has_an_iban_is_left_alone(): void
{
$settings = app(EInvoicingSettings::class);
$settings->save(self::COMPANY, ['enabled' => false, 'iban' => self::IBAN]);

app(DemoSeeder::class)->setContainer(app())->__invoke(['companyId' => self::COMPANY]);

self::assertSame(['enabled' => false, 'iban' => self::IBAN, 'bic' => null, 'payment_terms' => null], $settings->forCompany(self::COMPANY));
}
}
Loading