-
-
Notifications
You must be signed in to change notification settings - Fork 94
Add support for configurable invoice sequence scopes #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomkalon
wants to merge
5
commits into
Sylius:2.1
Choose a base branch
from
tomkalon:feature/sequence-number
base: 2.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4636b4
Add support for configurable invoice sequence scopes (global, monthly…
tomkalon 92fa666
Add year and month support to invoice sequence configuration
tomkalon 3353c9a
Extend GLOBAL invoice sequence scope with null year and month fields
tomkalon ff5ed37
Add tests for monthly and annual invoice sequence scopes
tomkalon efd462a
Add `type` field to invoice sequences and update related logic
tomkalon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /var/ | ||
| /vendor/ | ||
| /node_modules/ | ||
| /composer.lock | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\InvoicingPlugin\Enum; | ||
|
|
||
| enum InvoiceSequenceScopeEnum: string | ||
| { | ||
| case GLOBAL = 'global'; | ||
| case MONTHLY = 'monthly'; | ||
| case ANNUALLY = 'annually'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| use Sylius\Component\Resource\Factory\FactoryInterface; | ||
| use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
| use Sylius\InvoicingPlugin\Entity\InvoiceSequenceInterface; | ||
| use Sylius\InvoicingPlugin\Enum\InvoiceSequenceScopeEnum; | ||
| use Symfony\Component\Clock\ClockInterface; | ||
|
|
||
| final class SequentialInvoiceNumberGenerator implements InvoiceNumberGenerator | ||
|
|
@@ -29,7 +30,17 @@ public function __construct( | |
| private readonly ClockInterface $clock, | ||
| private readonly int $startNumber = 1, | ||
| private readonly int $numberLength = 9, | ||
| private readonly ?string $scope = null, | ||
| ) { | ||
| if (null === $this->scope) { | ||
| trigger_deprecation( | ||
| 'sylius/invoicing-plugin', | ||
| '2.1', | ||
| 'Not passing the "%s" argument to "%s::__construct()" is deprecated and will be required in version 3.0. Pass a valid scope explicitly (e.g. "monthly", "annually", or "global").', | ||
| 'scope', | ||
| self::class, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public function generate(): string | ||
|
|
@@ -56,15 +67,47 @@ private function generateNumber(int $index): string | |
|
|
||
| private function getSequence(): InvoiceSequenceInterface | ||
| { | ||
| /** @var InvoiceSequenceInterface $sequence */ | ||
| $sequence = $this->sequenceRepository->findOneBy([]); | ||
|
|
||
| if (null != $sequence) { | ||
| $now = $this->clock->now(); | ||
| $scope = InvoiceSequenceScopeEnum::tryFrom($this->scope ?? '') ?? InvoiceSequenceScopeEnum::GLOBAL; | ||
|
|
||
| $criteria = match ($scope) { | ||
| InvoiceSequenceScopeEnum::MONTHLY => [ | ||
| 'year' => (int) $now->format('Y'), | ||
| 'month' => (int) $now->format('m'), | ||
|
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get why you have values here. You wrote "monthly" or "yearly". You didn't specify that we could chose when it happens precisely. |
||
| 'type' => $scope, | ||
| ], | ||
| InvoiceSequenceScopeEnum::ANNUALLY => [ | ||
| 'year' => (int) $now->format('Y'), | ||
| 'type' => $scope, | ||
| ], | ||
| InvoiceSequenceScopeEnum::GLOBAL => [ | ||
| 'year' => null, | ||
| 'month' => null, | ||
| ], | ||
| }; | ||
|
|
||
| /** @var InvoiceSequenceInterface|null $sequence */ | ||
| $sequence = $this->sequenceRepository->findOneBy($criteria); | ||
|
|
||
| if (null !== $sequence) { | ||
| return $sequence; | ||
| } | ||
|
|
||
| /** @var InvoiceSequenceInterface $sequence */ | ||
| $sequence = $this->sequenceFactory->createNew(); | ||
|
|
||
| if (isset($criteria['year'])) { | ||
| $sequence->setYear($criteria['year']); | ||
| } | ||
|
|
||
| if (isset($criteria['month'])) { | ||
| $sequence->setMonth($criteria['month']); | ||
| } | ||
|
|
||
| if (isset($criteria['type'])) { | ||
| $sequence->setType($criteria['type']); | ||
| } | ||
|
|
||
| $this->sequenceManager->persist($sequence); | ||
|
|
||
| return $sequence; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\InvoicingPlugin\Migrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| final class Version20251021074051 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Add year, month and type columns to sylius_invoicing_plugin_sequence table'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $this->addSql('ALTER TABLE sylius_invoicing_plugin_sequence ADD year INT DEFAULT NULL, ADD month INT DEFAULT NULL, ADD type VARCHAR(255) DEFAULT NULL'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $this->addSql('ALTER TABLE sylius_invoicing_plugin_sequence DROP year, DROP month, DROP type'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with the
(anything else or empty): one global sequence.Either it's
globalor empty, but "anything else" could lead to future issues with custom developments.