save email as pdf likae attachment version 2

This commit is contained in:
2026-02-04 19:49:09 +01:00
parent 8c65fecef0
commit f33d157b9b
21 changed files with 1143 additions and 151 deletions
+107
View File
@@ -67,6 +67,19 @@ export declare function getAllContracts(filters: ContractFilters): Promise<{
color: string | null;
sortOrder: number;
} | null;
billingAddress: {
id: number;
customerId: number;
createdAt: Date;
updatedAt: Date;
type: import(".prisma/client").$Enums.AddressType;
isDefault: boolean;
street: string;
houseNumber: string;
postalCode: string;
city: string;
country: string;
} | null;
cancellationPeriod: {
id: number;
isActive: boolean;
@@ -99,6 +112,7 @@ export declare function getAllContracts(filters: ContractFilters): Promise<{
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -354,6 +368,19 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
color: string | null;
sortOrder: number;
} | null;
billingAddress: {
id: number;
customerId: number;
createdAt: Date;
updatedAt: Date;
type: import(".prisma/client").$Enums.AddressType;
isDefault: boolean;
street: string;
houseNumber: string;
postalCode: string;
city: string;
country: string;
} | null;
cancellationPeriod: {
id: number;
isActive: boolean;
@@ -490,6 +517,7 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -534,6 +562,7 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -563,6 +592,7 @@ interface ContractCreateData {
contractCategoryId?: number;
status?: ContractStatus;
addressId?: number;
billingAddressId?: number;
bankCardId?: number;
identityDocumentId?: number;
salesPlatformId?: number;
@@ -786,6 +816,19 @@ export declare function createContract(data: ContractCreateData): Promise<{
internetUsername: string | null;
internetPasswordEncrypted: string | null;
}) | null;
billingAddress: {
id: number;
customerId: number;
createdAt: Date;
updatedAt: Date;
type: import(".prisma/client").$Enums.AddressType;
isDefault: boolean;
street: string;
houseNumber: string;
postalCode: string;
city: string;
country: string;
} | null;
} & {
id: number;
customerId: number;
@@ -802,6 +845,7 @@ export declare function createContract(data: ContractCreateData): Promise<{
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -1050,6 +1094,19 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
color: string | null;
sortOrder: number;
} | null;
billingAddress: {
id: number;
customerId: number;
createdAt: Date;
updatedAt: Date;
type: import(".prisma/client").$Enums.AddressType;
isDefault: boolean;
street: string;
houseNumber: string;
postalCode: string;
city: string;
country: string;
} | null;
cancellationPeriod: {
id: number;
isActive: boolean;
@@ -1186,6 +1243,7 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -1230,6 +1288,7 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -1269,6 +1328,7 @@ export declare function deleteContract(id: number): Promise<{
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -1424,6 +1484,19 @@ export declare function createFollowUpContract(previousContractId: number): Prom
internetUsername: string | null;
internetPasswordEncrypted: string | null;
}) | null;
billingAddress: {
id: number;
customerId: number;
createdAt: Date;
updatedAt: Date;
type: import(".prisma/client").$Enums.AddressType;
isDefault: boolean;
street: string;
houseNumber: string;
postalCode: string;
city: string;
country: string;
} | null;
} & {
id: number;
customerId: number;
@@ -1440,6 +1513,7 @@ export declare function createFollowUpContract(previousContractId: number): Prom
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
@@ -1474,5 +1548,38 @@ export declare function getInternetCredentials(contractId: number): Promise<{
export declare function getSipCredentials(phoneNumberId: number): Promise<{
password: string | null;
}>;
export interface ContractTreeNode {
contract: {
id: number;
contractNumber: string;
type: ContractType;
status: ContractStatus;
startDate: Date | null;
endDate: Date | null;
providerName: string | null;
tariffName: string | null;
previousContractId: number | null;
provider?: {
id: number;
name: string;
} | null;
tariff?: {
id: number;
name: string;
} | null;
contractCategory?: {
id: number;
name: string;
} | null;
};
predecessors: ContractTreeNode[];
hasHistory: boolean;
}
/**
* Verträge eines Kunden als Baumstruktur abrufen.
* Wurzelknoten = Verträge ohne Nachfolger (aktuellste Verträge)
* Vorgänger werden rekursiv eingebettet.
*/
export declare function getContractTreeForCustomer(customerId: number): Promise<ContractTreeNode[]>;
export {};
//# sourceMappingURL=contract.service.d.ts.map
File diff suppressed because one or more lines are too long
+67 -1
View File
@@ -10,6 +10,7 @@ exports.getContractPassword = getContractPassword;
exports.getSimCardCredentials = getSimCardCredentials;
exports.getInternetCredentials = getInternetCredentials;
exports.getSipCredentials = getSipCredentials;
exports.getContractTreeForCustomer = getContractTreeForCustomer;
const client_1 = require("@prisma/client");
const helpers_js_1 = require("../utils/helpers.js");
const encryption_js_1 = require("../utils/encryption.js");
@@ -75,7 +76,7 @@ async function getAllContracts(filters) {
where,
skip,
take,
orderBy: [{ startDate: 'desc' }, { createdAt: 'desc' }],
orderBy: [{ createdAt: 'desc' }],
include: {
customer: {
select: {
@@ -87,6 +88,7 @@ async function getAllContracts(filters) {
},
},
address: true,
billingAddress: true,
salesPlatform: true,
cancellationPeriod: true,
contractDuration: true,
@@ -108,6 +110,7 @@ async function getContractById(id, decryptPassword = false) {
include: {
customer: true,
address: true,
billingAddress: true,
bankCard: true,
identityDocument: true,
salesPlatform: true,
@@ -233,6 +236,7 @@ async function createContract(data) {
include: {
customer: true,
address: true,
billingAddress: true,
salesPlatform: true,
energyDetails: true,
internetDetails: { include: { phoneNumbers: true } },
@@ -598,4 +602,66 @@ async function getSipCredentials(phoneNumberId) {
return { password: null };
}
}
/**
* Verträge eines Kunden als Baumstruktur abrufen.
* Wurzelknoten = Verträge ohne Nachfolger (aktuellste Verträge)
* Vorgänger werden rekursiv eingebettet.
*/
async function getContractTreeForCustomer(customerId) {
// Alle Verträge des Kunden laden (außer DEACTIVATED)
const allContracts = await prisma.contract.findMany({
where: {
customerId,
status: { not: client_1.ContractStatus.DEACTIVATED },
},
select: {
id: true,
contractNumber: true,
type: true,
status: true,
startDate: true,
endDate: true,
providerName: true,
tariffName: true,
previousContractId: true,
provider: { select: { id: true, name: true } },
tariff: { select: { id: true, name: true } },
contractCategory: { select: { id: true, name: true } },
},
orderBy: [{ startDate: 'desc' }, { createdAt: 'desc' }],
});
// Map für schnellen Zugriff: contractId -> contract
const contractMap = new Map(allContracts.map(c => [c.id, c]));
// Set der IDs die als Vorgänger referenziert werden
const predecessorIds = new Set(allContracts
.filter(c => c.previousContractId !== null)
.map(c => c.previousContractId));
// Wurzelverträge = Verträge die keinen Nachfolger haben
// (werden von keinem anderen Vertrag als previousContractId referenziert)
const rootContracts = allContracts.filter(c => !predecessorIds.has(c.id));
// Rekursive Funktion um Vorgängerkette aufzubauen
function buildPredecessorChain(contractId) {
if (contractId === null)
return [];
const contract = contractMap.get(contractId);
if (!contract)
return [];
const predecessors = buildPredecessorChain(contract.previousContractId);
return [{
contract,
predecessors,
hasHistory: predecessors.length > 0,
}];
}
// Baumstruktur für jeden Wurzelvertrag aufbauen
const tree = rootContracts.map(contract => {
const predecessors = buildPredecessorChain(contract.previousContractId);
return {
contract,
predecessors,
hasHistory: predecessors.length > 0,
};
});
return tree;
}
//# sourceMappingURL=contract.service.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -173,6 +173,7 @@ export declare function getCustomerById(id: number): Promise<({
contractNumber: string;
contractCategoryId: number | null;
addressId: number | null;
billingAddressId: number | null;
bankCardId: number | null;
identityDocumentId: number | null;
salesPlatformId: number | null;
File diff suppressed because one or more lines are too long