Add VO management, tariff-option assignment, and 2-step schaltung wizard
VOs (Vertriebspartner-Nummern) - New vos table (one row per VO, scoped to a provider). Migrations add tarife.vo_id and schaltungen.vo_id columns (nullable so legacy rows survive). - New /api/vos CRUD (list, create, update, delete with use-checks). - Admin: new "VOs (Vertriebspartner)" sub-tab. List/create with provider dropdown; edit via prompt; delete refuses while used. - /api/tarife?vo_id=X filter for fetching tariffs of a specific VO. Tariff editor - Add-tariff form requires a VO; new dependent VO dropdown that populates after the provider is chosen. - Edit-tariff modal now shows the VO dropdown and a checkbox grid of all anbieter-wide tarifoptionen. Saving the dialog applies the selection via the existing tarifoptionen_tarife table. - New GET /api/tarife/:id/tarifoptionen-multi returns the option set scoped to the tariff's provider, each annotated with whether it is currently assigned to this tariff. - POST/PUT /api/tarife accept vo_id (required for create, validated against the provider) and an optional tarifoption_ids array. Schaltung wizard - The Schaltung-erfassen tab is now a 2-step wizard: step 1 picks a provider from a button row (mirrors the screenshot the user shared); step 2 shows a 2-column form mirroring the Aktivierungs-/Vertragsdaten layout. - Step 2 cascades: VO -> tariffs filtered by VO -> tarifoptionen filtered by tariff. Erfasser is autofilled from the logged-in user (read-only). - Removed customer fields that the user does not need (Kundennummer, Kennwort/Service-PIN never existed; Rufnummer is now optional both in the form and in the API validation). - After saving, the wizard resets to step 1 ready for the next entry. Schema - tarife: vo_id added. - schaltungen: vo_id added; rufnummer is nullable in new DBs. Existing DBs may still have NOT NULL on rufnummer; the schaltungen route now sends an empty string instead of NULL to remain compatible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ea3a3fc12c
commit
f2ab23f261
7 files changed
+768
-212
No files matched your search
+29
-16
@@ -18,13 +18,12 @@ function validateAmount(a) {
|
||||
|
||||
function validateSchaltungBody(body) {
|
||||
const { schaltungs_id, eingabe_datum, schaltungs_datum, vorname, nachname,
|
||||
rufnummer, anbieter_id, tarif_id, hardware, hardware_ek, kundenverkaufspreis_netto } = body || {};
|
||||
anbieter_id, tarif_id, hardware, hardware_ek, kundenverkaufspreis_netto } = body || {};
|
||||
if (!schaltungs_id || !schaltungs_id.trim()) return 'Schaltungs-ID ist erforderlich';
|
||||
if (!validateDate(eingabe_datum)) return 'Ungültiges Eingabe-Datum (Format: YYYY-MM-DD)';
|
||||
if (!validateDate(schaltungs_datum)) return 'Ungültiges Schaltungs-Datum (Format: YYYY-MM-DD)';
|
||||
if (!vorname || !vorname.trim()) return 'Vorname ist erforderlich';
|
||||
if (!nachname || !nachname.trim()) return 'Nachname ist erforderlich';
|
||||
if (!rufnummer || !rufnummer.trim()) return 'Rufnummer ist erforderlich';
|
||||
if (!anbieter_id) return 'Anbieter ist erforderlich';
|
||||
if (!tarif_id) return 'Tarif ist erforderlich';
|
||||
if (!validateHardware(hardware)) return 'Hardware muss genau 15 Zeichen lang sein';
|
||||
@@ -51,19 +50,32 @@ router.post('/', asyncHandler(async (req, res) => {
|
||||
if (err) return res.status(400).json({ error: err });
|
||||
|
||||
const b = req.body;
|
||||
// rufnummer may be empty - existing DBs may have a NOT NULL constraint, so
|
||||
// we pass an empty string rather than NULL.
|
||||
const rufnummerValue = b.rufnummer && String(b.rufnummer).trim() ? String(b.rufnummer).trim() : '';
|
||||
const tarifoptionen = Array.isArray(b.tarifoptionen) ? b.tarifoptionen : [];
|
||||
try {
|
||||
const result = await db.run(
|
||||
`INSERT INTO schaltungen
|
||||
(schaltungs_id, eingabe_datum, schaltungs_datum, vorname, nachname, firma, rufnummer,
|
||||
anbieter_id, tarif_id, hardware, hardware_ek, kundenverkaufspreis_netto)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
b.schaltungs_id, b.eingabe_datum, b.schaltungs_datum, b.vorname, b.nachname,
|
||||
b.firma || null, b.rufnummer, b.anbieter_id, b.tarif_id, b.hardware || null,
|
||||
b.hardware_ek || null, b.kundenverkaufspreis_netto || null,
|
||||
]
|
||||
);
|
||||
res.json({ id: result.lastID, message: 'Schaltung erfolgreich erstellt' });
|
||||
const newId = await db.transaction(async () => {
|
||||
const result = await db.run(
|
||||
`INSERT INTO schaltungen
|
||||
(schaltungs_id, eingabe_datum, schaltungs_datum, vorname, nachname, firma, rufnummer,
|
||||
anbieter_id, vo_id, tarif_id, hardware, hardware_ek, kundenverkaufspreis_netto)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
b.schaltungs_id, b.eingabe_datum, b.schaltungs_datum, b.vorname, b.nachname,
|
||||
b.firma || null, rufnummerValue, b.anbieter_id, b.vo_id || null, b.tarif_id, b.hardware || null,
|
||||
b.hardware_ek || null, b.kundenverkaufspreis_netto || null,
|
||||
]
|
||||
);
|
||||
for (const tarifoptionId of tarifoptionen) {
|
||||
await db.run(
|
||||
'INSERT OR IGNORE INTO schaltungen_tarifoptionen (schaltung_id, tarifoption_id) VALUES (?, ?)',
|
||||
[result.lastID, tarifoptionId]
|
||||
);
|
||||
}
|
||||
return result.lastID;
|
||||
});
|
||||
res.json({ id: newId, message: 'Schaltung erfolgreich erstellt' });
|
||||
} catch (e) {
|
||||
if (/UNIQUE/.test(e.message)) {
|
||||
return res.status(400).json({ error: 'Schaltungs-ID existiert bereits' });
|
||||
@@ -79,17 +91,18 @@ router.put('/:id', asyncHandler(async (req, res) => {
|
||||
|
||||
const b = req.body;
|
||||
const tarifoptionen = Array.isArray(b.tarifoptionen) ? b.tarifoptionen : [];
|
||||
const rufnummerValue = b.rufnummer && String(b.rufnummer).trim() ? String(b.rufnummer).trim() : '';
|
||||
|
||||
await db.transaction(async () => {
|
||||
const upd = await db.run(
|
||||
`UPDATE schaltungen
|
||||
SET schaltungs_id = ?, eingabe_datum = ?, schaltungs_datum = ?, vorname = ?, nachname = ?,
|
||||
firma = ?, rufnummer = ?, anbieter_id = ?, tarif_id = ?, hardware = ?,
|
||||
firma = ?, rufnummer = ?, anbieter_id = ?, vo_id = ?, tarif_id = ?, hardware = ?,
|
||||
hardware_ek = ?, kundenverkaufspreis_netto = ?
|
||||
WHERE id = ?`,
|
||||
[
|
||||
b.schaltungs_id, b.eingabe_datum, b.schaltungs_datum, b.vorname, b.nachname,
|
||||
b.firma || null, b.rufnummer, b.anbieter_id, b.tarif_id, b.hardware || null,
|
||||
b.firma || null, rufnummerValue, b.anbieter_id, b.vo_id || null, b.tarif_id, b.hardware || null,
|
||||
b.hardware_ek || null, b.kundenverkaufspreis_netto || null, id,
|
||||
]
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user