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
|
||||
|
||||
### 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;
|
||||
|
|
@ -263,23 +263,25 @@ class Invoice
|
|||
public static function generateRechnungsNr(): string
|
||||
{
|
||||
$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';
|
||||
$next = (int)($settings['invoice_nr_next'] ?? 1);
|
||||
$savedYear = (int)($settings['invoice_nr_year'] ?? 0);
|
||||
$savedMonth = (int)($settings['invoice_nr_month'] ?? 0);
|
||||
$year = (int)date('Y');
|
||||
$month = (int)date('n');
|
||||
|
||||
// Reset counter on new year
|
||||
if ($savedYear !== $year) {
|
||||
if ($savedYear !== $year || $savedMonth !== $month) {
|
||||
$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(
|
||||
'UPDATE company_settings SET invoice_nr_next=?, invoice_nr_year=? WHERE id=1',
|
||||
[$next + 1, $year]
|
||||
'UPDATE company_settings SET invoice_nr_next=?, invoice_nr_year=?, invoice_nr_month=? WHERE id=1',
|
||||
[$next + 1, $year, $month]
|
||||
);
|
||||
|
||||
return $nr;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue