Gutschriften Phase 3a: Firmenstammdaten (Absender) fuer PDF/ZUGFeRD
Neues CompanyProfile-Modell (Einzel-Zeile) + Migration (IF NOT EXISTS): Firmenname, Anschrift, USt-IdNr, Steuernummer, Handelsregister, Geschaeftsfuehrer, Kontakt, IBAN/BIC/Bank. Fliesst spaeter in Gutschrift-PDF + ZUGFeRD-Verkaeuferdaten ein. Backend: Service (getOrCreate/update mit Feld-Whitelist), Controller, Routes GET/PUT /api/company-profile (settings:read/update), auditiert. Frontend: Settings-Seite 'Firmenstammdaten (Absender)' (/settings/company-profile) mit Firma/Anschrift, Steuer/Register, Kontakt/Bank. Typ + companyProfileApi + Menue-Eintrag. Phase 3b (PDF + ZUGFeRD-Erzeugung) folgt darauf auf. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
-- Absender-/Firmenstammdaten (Einzel-Zeile) fuer Gutschrift-PDF + ZUGFeRD.
|
||||
CREATE TABLE IF NOT EXISTS `CompanyProfile` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`street` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`houseNumber` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`postalCode` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`city` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`country` VARCHAR(191) NOT NULL DEFAULT 'DE',
|
||||
`vatId` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`taxNumber` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`commercialRegister` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`managingDirector` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`email` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`phone` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`website` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`iban` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`bic` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`bankName` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
`logoPath` VARCHAR(191) NULL,
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
@@ -1021,6 +1021,30 @@ model CreditNote {
|
||||
@@index([contractId])
|
||||
}
|
||||
|
||||
// Absender-/Firmenstammdaten (Einzel-Zeile). Fließen in Gutschrift-PDF und
|
||||
// ZUGFeRD-XML (Verkäufer/Seller-Party) sowie in die Bankangaben ein.
|
||||
model CompanyProfile {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @default("")
|
||||
street String @default("")
|
||||
houseNumber String @default("")
|
||||
postalCode String @default("")
|
||||
city String @default("")
|
||||
country String @default("DE") // ISO-2, für ZUGFeRD countryID
|
||||
vatId String @default("") // USt-IdNr (DE...)
|
||||
taxNumber String @default("") // Steuernummer
|
||||
commercialRegister String @default("") // z.B. HRB 12345, Amtsgericht
|
||||
managingDirector String @default("") // Geschäftsführer/Inhaber
|
||||
email String @default("")
|
||||
phone String @default("")
|
||||
website String @default("")
|
||||
iban String @default("")
|
||||
bic String @default("")
|
||||
bankName String @default("")
|
||||
logoPath String?
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
// Nummernkreis für Gutschriften (Einzel-Zeile, in den Einstellungen
|
||||
// verwaltbar). Nummer wird transaktional vergeben, damit keine Lücken/
|
||||
// Doppelvergaben entstehen.
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Response } from 'express';
|
||||
import { ApiResponse, AuthRequest } from '../types/index.js';
|
||||
import { logChange } from '../services/audit.service.js';
|
||||
import * as companyProfileService from '../services/companyProfile.service.js';
|
||||
|
||||
export async function getProfile(_req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const data = await companyProfileService.getOrCreateProfile();
|
||||
res.json({ success: true, data } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Laden der Firmendaten' } as ApiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateProfile(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const updated = await companyProfileService.updateProfile(req.body ?? {});
|
||||
await logChange({
|
||||
req,
|
||||
action: 'UPDATE',
|
||||
resourceType: 'CompanyProfile',
|
||||
resourceId: updated.id.toString(),
|
||||
label: 'Firmenstammdaten (Absender) geändert',
|
||||
});
|
||||
res.json({ success: true, data: updated } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Speichern der Firmendaten' } as ApiResponse);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import meterRoutes from './routes/meter.routes.js';
|
||||
import stressfreiEmailRoutes from './routes/stressfreiEmail.routes.js';
|
||||
import contractRoutes from './routes/contract.routes.js';
|
||||
import creditNoteRoutes from './routes/creditNote.routes.js';
|
||||
import companyProfileRoutes from './routes/companyProfile.routes.js';
|
||||
import platformRoutes from './routes/platform.routes.js';
|
||||
import cancellationPeriodRoutes from './routes/cancellation-period.routes.js';
|
||||
import contractDurationRoutes from './routes/contract-duration.routes.js';
|
||||
@@ -357,6 +358,7 @@ app.use('/api/meters', meterRoutes);
|
||||
app.use('/api/stressfrei-emails', stressfreiEmailRoutes);
|
||||
app.use('/api/contracts', contractRoutes);
|
||||
app.use('/api/credit-notes', creditNoteRoutes);
|
||||
app.use('/api/company-profile', companyProfileRoutes);
|
||||
app.use('/api/platforms', platformRoutes);
|
||||
app.use('/api/cancellation-periods', cancellationPeriodRoutes);
|
||||
app.use('/api/contract-durations', contractDurationRoutes);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Router } from 'express';
|
||||
import * as companyProfileController from '../controllers/companyProfile.controller.js';
|
||||
import { authenticate, requirePermission } from '../middleware/auth.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/', authenticate, requirePermission('settings:read'), companyProfileController.getProfile);
|
||||
router.put('/', authenticate, requirePermission('settings:update'), companyProfileController.updateProfile);
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,28 @@
|
||||
// ==================== FIRMENSTAMMDATEN (ABSENDER) ====================
|
||||
// Einzel-Zeile. Fließt in Gutschrift-PDF + ZUGFeRD-XML (Verkäufer) ein.
|
||||
|
||||
import prisma from '../lib/prisma.js';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
const EDITABLE_STRING_FIELDS = [
|
||||
'name', 'street', 'houseNumber', 'postalCode', 'city', 'country',
|
||||
'vatId', 'taxNumber', 'commercialRegister', 'managingDirector',
|
||||
'email', 'phone', 'website', 'iban', 'bic', 'bankName',
|
||||
] as const;
|
||||
|
||||
export async function getOrCreateProfile() {
|
||||
const existing = await prisma.companyProfile.findFirst();
|
||||
if (existing) return existing;
|
||||
return prisma.companyProfile.create({ data: {} });
|
||||
}
|
||||
|
||||
export async function updateProfile(input: Record<string, unknown>) {
|
||||
const profile = await getOrCreateProfile();
|
||||
const data: Prisma.CompanyProfileUpdateInput = {};
|
||||
for (const field of EDITABLE_STRING_FIELDS) {
|
||||
if (typeof input[field] === 'string') {
|
||||
(data as Record<string, unknown>)[field] = (input[field] as string).slice(0, 191).trim();
|
||||
}
|
||||
}
|
||||
return prisma.companyProfile.update({ where: { id: profile.id }, data });
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import ContractDurationList from './pages/settings/ContractDurationList';
|
||||
import ProviderList from './pages/settings/ProviderList';
|
||||
import ContractCategoryList from './pages/settings/ContractCategoryList';
|
||||
import CreditNoteNumberRange from './pages/settings/CreditNoteNumberRange';
|
||||
import CompanyProfileSettings from './pages/settings/CompanyProfileSettings';
|
||||
import ViewSettings from './pages/settings/ViewSettings';
|
||||
import PortalSettings from './pages/settings/PortalSettings';
|
||||
import DeadlineSettings from './pages/settings/DeadlineSettings';
|
||||
@@ -224,6 +225,7 @@ function App() {
|
||||
<Route path="settings/providers" element={<ProviderList />} />
|
||||
<Route path="settings/contract-categories" element={<ContractCategoryList />} />
|
||||
<Route path="settings/credit-note-number-range" element={<CreditNoteNumberRange />} />
|
||||
<Route path="settings/company-profile" element={<CompanyProfileSettings />} />
|
||||
<Route path="settings/view" element={<ViewSettings />} />
|
||||
<Route path="settings/portal" element={<PortalSettings />} />
|
||||
<Route path="settings/deadlines" element={<DeadlineSettings />} />
|
||||
|
||||
@@ -56,6 +56,13 @@ export default function Settings() {
|
||||
description: 'Präfix, Jahr und Zähler für die fortlaufende Nummerierung von Gutschriften.',
|
||||
show: hasPermission('settings:read'),
|
||||
},
|
||||
{
|
||||
to: '/settings/company-profile',
|
||||
icon: Building2,
|
||||
title: 'Firmenstammdaten (Absender)',
|
||||
description: 'Absenderdaten für Gutschrift-PDF und ZUGFeRD (Name, Anschrift, USt-IdNr, Bank).',
|
||||
show: hasPermission('settings:read'),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { ArrowLeft, Building2 } from 'lucide-react';
|
||||
import toast from 'react-hot-toast';
|
||||
import Button from '../../components/ui/Button';
|
||||
import Input from '../../components/ui/Input';
|
||||
import { companyProfileApi } from '../../services/api';
|
||||
import type { CompanyProfile } from '../../types';
|
||||
import { useAuth } from '../../context/AuthContext';
|
||||
|
||||
type Form = Omit<CompanyProfile, 'id' | 'logoPath'>;
|
||||
|
||||
const EMPTY: Form = {
|
||||
name: '', street: '', houseNumber: '', postalCode: '', city: '', country: 'DE',
|
||||
vatId: '', taxNumber: '', commercialRegister: '', managingDirector: '',
|
||||
email: '', phone: '', website: '', iban: '', bic: '', bankName: '',
|
||||
};
|
||||
|
||||
export default function CompanyProfileSettings() {
|
||||
const { hasPermission } = useAuth();
|
||||
const canEdit = hasPermission('settings:update');
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['company-profile'],
|
||||
queryFn: () => companyProfileApi.get(),
|
||||
});
|
||||
|
||||
const [form, setForm] = useState<Form>(EMPTY);
|
||||
const set = <K extends keyof Form>(k: K, v: Form[K]) => setForm((f) => ({ ...f, [k]: v }));
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.data) {
|
||||
const { id, logoPath, ...rest } = data.data;
|
||||
void id; void logoPath;
|
||||
setForm({ ...EMPTY, ...rest });
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: () => companyProfileApi.update(form),
|
||||
onSuccess: () => {
|
||||
toast.success('Firmendaten gespeichert');
|
||||
queryClient.invalidateQueries({ queryKey: ['company-profile'] });
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message || 'Speichern fehlgeschlagen'),
|
||||
});
|
||||
|
||||
if (isLoading) return <div className="p-6 text-gray-500">Laden …</div>;
|
||||
|
||||
const field = (label: string, key: keyof Form, placeholder?: string) => (
|
||||
<Input label={label} value={form[key]} onChange={(e) => set(key, e.target.value)} disabled={!canEdit} placeholder={placeholder} />
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl">
|
||||
<Link to="/settings" className="inline-flex items-center gap-1 text-sm text-gray-500 hover:text-gray-700 mb-4">
|
||||
<ArrowLeft className="w-4 h-4" /> Einstellungen
|
||||
</Link>
|
||||
<h1 className="text-2xl font-bold flex items-center gap-2 mb-1">
|
||||
<Building2 className="w-6 h-6 text-blue-600" /> Firmenstammdaten (Absender)
|
||||
</h1>
|
||||
<p className="text-gray-500 mb-6">
|
||||
Diese Daten erscheinen als Absender auf Gutschrift-PDFs und in der ZUGFeRD-E-Rechnung.
|
||||
</p>
|
||||
|
||||
<div className="space-y-6">
|
||||
<div className="bg-white rounded-lg shadow p-6 space-y-4">
|
||||
<h2 className="font-semibold text-gray-800">Firma & Anschrift</h2>
|
||||
{field('Firmenname', 'name', 'z.B. Hacker-Net Telekommunikation')}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="md:col-span-2">{field('Straße', 'street')}</div>
|
||||
{field('Hausnummer', 'houseNumber')}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
{field('PLZ', 'postalCode')}
|
||||
<div className="md:col-span-1">{field('Ort', 'city')}</div>
|
||||
{field('Land (ISO-2)', 'country', 'DE')}
|
||||
</div>
|
||||
{field('Geschäftsführer/Inhaber', 'managingDirector')}
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg shadow p-6 space-y-4">
|
||||
<h2 className="font-semibold text-gray-800">Steuer & Register</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{field('USt-IdNr', 'vatId', 'DE123456789')}
|
||||
{field('Steuernummer', 'taxNumber')}
|
||||
</div>
|
||||
{field('Handelsregister', 'commercialRegister', 'z.B. HRB 12345, Amtsgericht Oldenburg')}
|
||||
<p className="text-xs text-gray-500">
|
||||
Für ZUGFeRD an Firmenkunden mit USt ist die USt-IdNr erforderlich.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg shadow p-6 space-y-4">
|
||||
<h2 className="font-semibold text-gray-800">Kontakt & Bank</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{field('E-Mail', 'email')}
|
||||
{field('Telefon', 'phone')}
|
||||
</div>
|
||||
{field('Website', 'website')}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
{field('IBAN', 'iban')}
|
||||
{field('BIC', 'bic')}
|
||||
{field('Bank', 'bankName')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canEdit && (
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={() => saveMutation.mutate()} disabled={saveMutation.isPending}>
|
||||
{saveMutation.isPending ? 'Speichern …' : 'Speichern'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import type { ApiResponse, Customer, Contract, ContractTask, ContractTaskSubtask, ContractTaskStatus, SalesPlatform, CancellationPeriod, ContractDuration, ContractCategory, Provider, Tariff, User, Address, BankCard, IdentityDocument, Meter, MeterReading, Invoice, Role, PortalSettings, CustomerRepresentative, CustomerSummary, CustomerReferrals, CreditNote, CreditNoteDefaults, CreditNoteNumberRange, ContractHistoryEntry, AuditLog, AuditSensitivity, AuditRetentionPolicy, CustomerConsent, ConsentType, ConsentStatus, DataDeletionRequest, DeletionRequestStatus, GDPRDashboardStats, RepresentativeAuthorization } from '../types';
|
||||
import type { ApiResponse, Customer, Contract, ContractTask, ContractTaskSubtask, ContractTaskStatus, SalesPlatform, CancellationPeriod, ContractDuration, ContractCategory, Provider, Tariff, User, Address, BankCard, IdentityDocument, Meter, MeterReading, Invoice, Role, PortalSettings, CustomerRepresentative, CustomerSummary, CustomerReferrals, CreditNote, CreditNoteDefaults, CreditNoteNumberRange, CompanyProfile, ContractHistoryEntry, AuditLog, AuditSensitivity, AuditRetentionPolicy, CustomerConsent, ConsentType, ConsentStatus, DataDeletionRequest, DeletionRequestStatus, GDPRDashboardStats, RepresentativeAuthorization } from '../types';
|
||||
|
||||
// ============================================================================
|
||||
// In-Memory-Token-Store
|
||||
@@ -263,6 +263,18 @@ export const referralApi = {
|
||||
},
|
||||
};
|
||||
|
||||
// Firmenstammdaten (Absender für Gutschrift-PDF/ZUGFeRD)
|
||||
export const companyProfileApi = {
|
||||
get: async () => {
|
||||
const res = await api.get<ApiResponse<CompanyProfile>>('/company-profile');
|
||||
return res.data;
|
||||
},
|
||||
update: async (payload: Partial<CompanyProfile>) => {
|
||||
const res = await api.put<ApiResponse<CompanyProfile>>('/company-profile', payload);
|
||||
return res.data;
|
||||
},
|
||||
};
|
||||
|
||||
// Gutschriften (Subventionen am Vertrag)
|
||||
export const creditNoteApi = {
|
||||
listByContract: async (contractId: number) => {
|
||||
|
||||
@@ -107,6 +107,27 @@ export interface CreditNoteNumberRange {
|
||||
preview?: string;
|
||||
}
|
||||
|
||||
export interface CompanyProfile {
|
||||
id: number;
|
||||
name: string;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
vatId: string;
|
||||
taxNumber: string;
|
||||
commercialRegister: string;
|
||||
managingDirector: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
website: string;
|
||||
iban: string;
|
||||
bic: string;
|
||||
bankName: string;
|
||||
logoPath?: string | null;
|
||||
}
|
||||
|
||||
export interface RepresentativeAuthorization {
|
||||
id: number;
|
||||
customerId: number;
|
||||
|
||||
Reference in New Issue
Block a user