Skip to content

Commit

Permalink
Possibility to generate PDFa invoice documents
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
  • Loading branch information
Sieg committed Oct 1, 2023
1 parent a3b89b6 commit 99514dc
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- Php 8.1 and Mysql 8.0 supported
- Possibility to generate PDFA format invoice documents

### Changed
- Inverted dependencies on most of the classes to extracted interfaces
Expand Down
6 changes: 6 additions & 0 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
'type' => 'str',
'value' => 'invoice-'
],
[
'group' => 'fa_invoice_main',
'name' => \FreshAdvance\Invoice\Service\ModuleSettings::SETTING_DOCUMENT_IS_FOR_ARCHIVE,
'type' => 'bool',
'value' => false
],
],
'events' => [
'onActivate' => '\FreshAdvance\Invoice\Transition\Core\Events::onActivate',
Expand Down
6 changes: 5 additions & 1 deletion src/Document/MpdfDocument/MpdfFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@

namespace FreshAdvance\Invoice\Document\MpdfDocument;

use FreshAdvance\Invoice\Service\ModuleSettingsInterface;
use Mpdf\Mpdf;

class MpdfFactory
{
public function __construct(
private ModuleSettingsInterface $moduleSettings
) {
}

public function create(): Mpdf
{
return new Mpdf();
return new Mpdf([
'PDFA' => $this->moduleSettings->isForArchive()
]);
}
}
9 changes: 9 additions & 0 deletions src/Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ModuleSettings implements ModuleSettingsInterface
{
public const SETTING_DOCUMENT_FOOTER = 'fa_invoice_DocumentFooter';
public const SETTING_DOCUMENT_FILENAME_PREFIX = 'fa_invoice_FilenamePrefix';
public const SETTING_DOCUMENT_IS_FOR_ARCHIVE = 'fa_invoice_IsForArchive';

public function __construct(
private ModuleSettingServiceInterface $moduleSettingService
Expand All @@ -32,6 +33,14 @@ public function getFilePrefix(): string
return $this->getStringSetting(self::SETTING_DOCUMENT_FILENAME_PREFIX);
}

public function isForArchive(): bool
{
return $this->moduleSettingService->getBoolean(
self::SETTING_DOCUMENT_IS_FOR_ARCHIVE,
Module::MODULE_ID
);
}

private function getStringSetting(string $key): string
{
return $this->moduleSettingService
Expand Down
2 changes: 2 additions & 0 deletions src/Service/ModuleSettingsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface ModuleSettingsInterface
public function getDocumentFooter(): string;

public function getFilePrefix(): string;

public function isForArchive(): bool;
}
18 changes: 17 additions & 1 deletion tests/Integration/Document/MpdfDocument/MpdfFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Document\MpdfDocument;

use FreshAdvance\Invoice\Document\MpdfDocument\MpdfFactory;
use FreshAdvance\Invoice\Service\ModuleSettingsInterface;
use Mpdf\Mpdf;
use PHPUnit\Framework\TestCase;

Expand All @@ -20,7 +21,22 @@ class MpdfFactoryTest extends TestCase
{
public function testCreate(): void
{
$sut = new MpdfFactory();
$sut = new MpdfFactory(
moduleSettings: $this->createStub(ModuleSettingsInterface::class)
);
$this->assertInstanceOf(Mpdf::class, $sut->create());
}

public function testArchiveFlagConfigured(): void
{
$settingsStub = $this->createMock(ModuleSettingsInterface::class);
$settingsStub->method('isForArchive')->willReturn(true);

$sut = new MpdfFactory(
moduleSettings: $settingsStub
);
$object = $sut->create();

$this->assertSame(true, $object->PDFA);
}
}
22 changes: 22 additions & 0 deletions tests/Unit/Service/ModuleSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ public function testGetFilenamePrefix(): void
$sut = new ModuleSettings($mssMock);
$this->assertSame($value, $sut->getFilePrefix());
}

/**
* @dataProvider booleanDataProvider
*/
public function testIsForArchive(bool $value): void
{
$mssMock = $this->createPartialMock(ModuleSettingService::class, ['getBoolean']);
$mssMock->method('getBoolean')->willReturnMap([
[ModuleSettings::SETTING_DOCUMENT_IS_FOR_ARCHIVE, Module::MODULE_ID, $value]
]);

$sut = new ModuleSettings($mssMock);
$this->assertSame($value, $sut->isForArchive());
}

public function booleanDataProvider(): array
{
return [
[true],
[false]
];
}
}
1 change: 1 addition & 0 deletions views/admin_twig/de/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
'SHOP_MODULE_GROUP_fa_invoice_main' => 'Invoice document',
'SHOP_MODULE_fa_invoice_DocumentFooter' => 'Document Footer',
'SHOP_MODULE_fa_invoice_FilenamePrefix' => 'Filename Prefix',
'SHOP_MODULE_fa_invoice_IsForArchive' => 'Document is for archive (PDFA)',
];
1 change: 1 addition & 0 deletions views/admin_twig/en/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
'SHOP_MODULE_GROUP_fa_invoice_main' => 'Invoice document',
'SHOP_MODULE_fa_invoice_DocumentFooter' => 'Document Footer',
'SHOP_MODULE_fa_invoice_FilenamePrefix' => 'Filename Prefix',
'SHOP_MODULE_fa_invoice_IsForArchive' => 'Document is for archive (PDFA)',
];
1 change: 1 addition & 0 deletions views/admin_twig/lt/fainvoice_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
'SHOP_MODULE_GROUP_fa_invoice_main' => 'Invoice document',
'SHOP_MODULE_fa_invoice_DocumentFooter' => 'Document Footer',
'SHOP_MODULE_fa_invoice_FilenamePrefix' => 'Filename Prefix',
'SHOP_MODULE_fa_invoice_IsForArchive' => 'Document is for archive (PDFA)',
];

0 comments on commit 99514dc

Please sign in to comment.