Feature: Rechnungsnummernformat auf PPPYYYYMM-nn umgestellt
This commit is contained in:
parent
09eea17c4e
commit
3954e8a4b0
3 changed files with 23 additions and 11 deletions
|
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 2026-04-27 – Feature: Neues Rechnungsnummernformat (PPPYYYYMM-nn)
|
||||||
|
|
||||||
|
### Geändert
|
||||||
|
- `src/Models/Invoice.php`: `generateRechnungsNr()` erzeugt jetzt das Format `PPPYYYYMM-nn` (Prefix + Jahr + Monat + zweistellige Sequenz, die bei Bedarf wächst); Zähler wird monatlich zurückgesetzt
|
||||||
|
- `migrations/038_invoice_nr_month.sql`: Neue Spalte `invoice_nr_month` in `company_settings`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 2026-04-26 – Fix: Eigenanteil-Buchung als Einnahme statt Ausgabe
|
## 2026-04-26 – Fix: Eigenanteil-Buchung als Einnahme statt Ausgabe
|
||||||
|
|
||||||
### Geändert
|
### Geändert
|
||||||
|
|
|
||||||
2
migrations/038_invoice_nr_month.sql
Normal file
2
migrations/038_invoice_nr_month.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE company_settings
|
||||||
|
ADD COLUMN IF NOT EXISTS invoice_nr_month TINYINT UNSIGNED NOT NULL DEFAULT 0;
|
||||||
|
|
@ -262,24 +262,26 @@ class Invoice
|
||||||
|
|
||||||
public static function generateRechnungsNr(): string
|
public static function generateRechnungsNr(): string
|
||||||
{
|
{
|
||||||
$settings = Database::fetchOne(
|
$settings = Database::fetchOne(
|
||||||
'SELECT invoice_nr_prefix, invoice_nr_next, invoice_nr_year FROM company_settings WHERE id=1'
|
'SELECT invoice_nr_prefix, invoice_nr_next, invoice_nr_year, invoice_nr_month FROM company_settings WHERE id=1'
|
||||||
);
|
);
|
||||||
$prefix = $settings['invoice_nr_prefix'] ?? 'AR';
|
$prefix = $settings['invoice_nr_prefix'] ?? 'AR';
|
||||||
$next = (int)($settings['invoice_nr_next'] ?? 1);
|
$next = (int)($settings['invoice_nr_next'] ?? 1);
|
||||||
$savedYear = (int)($settings['invoice_nr_year'] ?? 0);
|
$savedYear = (int)($settings['invoice_nr_year'] ?? 0);
|
||||||
$year = (int)date('Y');
|
$savedMonth = (int)($settings['invoice_nr_month'] ?? 0);
|
||||||
|
$year = (int)date('Y');
|
||||||
|
$month = (int)date('n');
|
||||||
|
|
||||||
// Reset counter on new year
|
if ($savedYear !== $year || $savedMonth !== $month) {
|
||||||
if ($savedYear !== $year) {
|
|
||||||
$next = 1;
|
$next = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nr = sprintf('%s-%s-%04d', $prefix, $year, $next);
|
$digits = max(2, strlen((string)$next));
|
||||||
|
$nr = sprintf('%s%04d%02d-%0' . $digits . 'd', $prefix, $year, $month, $next);
|
||||||
|
|
||||||
Database::execute(
|
Database::execute(
|
||||||
'UPDATE company_settings SET invoice_nr_next=?, invoice_nr_year=? WHERE id=1',
|
'UPDATE company_settings SET invoice_nr_next=?, invoice_nr_year=?, invoice_nr_month=? WHERE id=1',
|
||||||
[$next + 1, $year]
|
[$next + 1, $year, $month]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $nr;
|
return $nr;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue