diff --git a/database.js b/database.js index f14f721..4cf55a5 100644 --- a/database.js +++ b/database.js @@ -74,19 +74,35 @@ function initDatabase() { UNIQUE(anbieter_id, gueltig_ab) )`); + // Vertriebspartner-Nummern (VOs) per Anbieter. Each tariff is assigned to + // exactly one VO (nullable for legacy rows that pre-date this column). + db.run(`CREATE TABLE IF NOT EXISTS vos ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + anbieter_id INTEGER NOT NULL, + nummer TEXT NOT NULL, + bezeichnung TEXT, + aktiv INTEGER NOT NULL DEFAULT 1, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (anbieter_id) REFERENCES anbieter (id), + UNIQUE(anbieter_id, nummer) + )`); + // Tarife db.run(`CREATE TABLE IF NOT EXISTS tarife ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, anbieter_id INTEGER, + vo_id INTEGER, provision_euro DECIMAL(10,2) DEFAULT 0, mitarbeiter_provision DECIMAL(10,2) DEFAULT 0, beschreibung TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (anbieter_id) REFERENCES anbieter (id), + FOREIGN KEY (vo_id) REFERENCES vos (id), UNIQUE(name, anbieter_id) )`); addColumnIfMissing(db, 'tarife', 'mitarbeiter_provision DECIMAL(10,2) DEFAULT 0'); + addColumnIfMissing(db, 'tarife', 'vo_id INTEGER'); // Tariff-specific commission rules. basis_euro: base amount for percent calculation. db.run(`CREATE TABLE IF NOT EXISTS provisionsregeln ( @@ -124,7 +140,9 @@ function initDatabase() { )`); addColumnIfMissing(db, 'anbieter_provisionsregeln', 'basis_euro DECIMAL(10,2)'); - // Schaltungen + // Schaltungen. rufnummer is nullable on new installs (the application + // also accepts NULL on existing DBs with NOT NULL columns since we just + // pass empty string when missing). vo_id captures which VO was used. db.run(`CREATE TABLE IF NOT EXISTS schaltungen ( id INTEGER PRIMARY KEY AUTOINCREMENT, schaltungs_id TEXT NOT NULL UNIQUE, @@ -133,8 +151,9 @@ function initDatabase() { vorname TEXT NOT NULL, nachname TEXT NOT NULL, firma TEXT, - rufnummer TEXT NOT NULL, + rufnummer TEXT, anbieter_id INTEGER NOT NULL, + vo_id INTEGER, tarif_id INTEGER NOT NULL, hardware TEXT, hardware_ek DECIMAL(10,2), @@ -145,6 +164,7 @@ function initDatabase() { )`); addColumnIfMissing(db, 'schaltungen', 'hardware_ek DECIMAL(10,2)'); addColumnIfMissing(db, 'schaltungen', 'kundenverkaufspreis_netto DECIMAL(10,2)'); + addColumnIfMissing(db, 'schaltungen', 'vo_id INTEGER'); // Dokumente (note: ON DELETE CASCADE only applied to new DBs - existing DBs // handled via explicit DELETE in server.js) diff --git a/public/index.html b/public/index.html index 1dec492..98a89d1 100644 --- a/public/index.html +++ b/public/index.html @@ -881,105 +881,130 @@ - +
-

Neue Schaltung erfassen

-
-
-
- - -
-
- - -
-
- -
- - -
- -
-
- - -
-
- - -
-
- - -
-
- -
- - -
- -
-
- - -
-
- - -
-
- - - - -
- - + +
+

Neue Schaltung — Schritt 1 von 2

+

Wählen Sie einen Anbieter.

+
+
+ + +