Skip to content

Commit 92fa666

Browse files
committed
Add year and month support to invoice sequence configuration
1 parent d4636b4 commit 92fa666

File tree

8 files changed

+72
-15
lines changed

8 files changed

+72
-15
lines changed

CHANGELOG-2.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
### v2.0.3 (2025-10-21)
4+
5+
- [#373](https://github.com/Sylius/InvoicingPlugin/pull/373) Add configurable invoice sequence scope (`monthly`/`annually`/`global`)
6+
via SYLIUS_INVOICING_SEQUENCE_SCOPE ENV ([@tomkalon](https://github.com/tomkalon))
7+
38
### v2.0.2 (2025-07-03)
49

510
- [#373](https://github.com/Sylius/InvoicingPlugin/pull/373) Add sylius/test-application ([@Wojdylak](https://github.com/Wojdylak))

UPGRADE-2.0.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# UPGRADE FROM 2.0.2 TO 2.0.3
2+
3+
## Changes
4+
5+
1. Added support for configurable invoice sequence scoping via the SYLIUS_INVOICING_SEQUENCE_SCOPE environment variable:
6+
7+
- monthly: resets invoice numbering each month
8+
- annually: resets invoice numbering each year
9+
- global or unset (default): uses a single global sequence (as previously)
10+
11+
## Deprecations
12+
13+
1. Not passing the $scope argument (of type InvoiceSequenceScopeEnum) to the constructor of SequentialInvoiceNumberGenerator is deprecated and will be required starting from version 3.0.
14+
115
# UPGRADE FROM 1.X TO 2.0
216

317
1. Support for Sylius 2.0 has been added, it is now the recommended Sylius version to use with InvoicingPlugin.

config/doctrine/InvoiceSequence.orm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
</id>
1212
<field name="index" column="idx" type="integer" />
1313
<field name="version" type="integer" version="true" />
14+
<field name="year" type="integer" nullable="true"/>
15+
<field name="month" type="integer"/>
16+
1417
</mapped-superclass>
1518

1619
</doctrine-mapping>

config/services/generators.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<argument type="service" id="sylius_invoicing.factory.invoice_sequence" />
2323
<argument type="service" id="sylius_invoicing.manager.invoice_sequence" />
2424
<argument type="service" id="clock" />
25-
<argument type="string">%sylius_invoicing.sequence_scope%</argument>
25+
<argument key="$scope">%sylius_invoicing.sequence_scope%</argument>
2626
</service>
2727

2828
<service id="sylius_invoicing.generator.invoice_identifier" class="Sylius\InvoicingPlugin\Generator\UuidInvoiceIdentifierGenerator" />

src/Entity/InvoiceSequence.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class InvoiceSequence implements InvoiceSequenceInterface
2323

2424
protected ?int $version = 1;
2525

26-
protected int $year;
26+
protected ?int $year;
2727

28-
protected int $month;
28+
protected ?int $month;
2929

3030
/** @return mixed */
3131
public function getId()
@@ -53,22 +53,22 @@ public function setVersion(?int $version): void
5353
$this->version = $version;
5454
}
5555

56-
public function getYear(): int
56+
public function getYear(): ?int
5757
{
5858
return $this->year;
5959
}
6060

61-
public function getMonth(): int
61+
public function setYear(?int $year): void
6262
{
63-
return $this->month;
63+
$this->year = $year;
6464
}
6565

66-
public function setYear(int $year): void
66+
public function getMonth(): ?int
6767
{
68-
$this->year = $year;
68+
return $this->month;
6969
}
7070

71-
public function setMonth(int $month): void
71+
public function setMonth(?int $month): void
7272
{
7373
$this->month = $month;
7474
}

src/Entity/InvoiceSequenceInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function getIndex(): int;
2222

2323
public function incrementIndex(): void;
2424

25-
public function getYear(): int;
25+
public function getYear(): ?int;
2626

27-
public function getMonth(): int;
27+
public function getMonth(): ?int;
2828

29-
public function setYear(int $year): void;
29+
public function setYear(?int $year): void;
3030

31-
public function setMonth(int $month): void;
31+
public function setMonth(?int $month): void;
3232
}

src/Generator/SequentialInvoiceNumberGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function __construct(
3636
trigger_deprecation(
3737
'sylius/invoicing-plugin',
3838
'2.1',
39-
'Not passing a "%s" to "%s" is deprecated and will be required in SyliusInvoicingPlugin 3.0.',
40-
InvoiceSequenceScopeEnum::class,
39+
'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").',
40+
'scope',
4141
self::class,
4242
);
4343
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\InvoicingPlugin\Migrations;
15+
16+
use Doctrine\DBAL\Schema\Schema;
17+
use Doctrine\Migrations\AbstractMigration;
18+
19+
final class Version20251021074051 extends AbstractMigration
20+
{
21+
public function getDescription(): string
22+
{
23+
return 'Add year and month columns to sylius_invoicing_plugin_sequence table';
24+
}
25+
26+
public function up(Schema $schema): void
27+
{
28+
$this->addSql('ALTER TABLE sylius_invoicing_plugin_sequence ADD year INT DEFAULT NULL, ADD month INT NOT NULL');
29+
}
30+
31+
public function down(Schema $schema): void
32+
{
33+
$this->addSql('ALTER TABLE sylius_invoicing_plugin_sequence DROP year, DROP month');
34+
}
35+
}

0 commit comments

Comments
 (0)