Compare commits

..

3 Commits

Author SHA1 Message Date
DanielS
98c030cd82 fix(end-customers): allow admin to create end customers without company_id
All checks were successful
Staging Build / build (push) Successful in 2m38s
2026-07-07 12:32:11 +02:00
DanielS
8e91b3e810 fix(email): remove duplicate pdf download button 2026-07-07 10:30:34 +02:00
DanielS
dd5d1295a7 fix(invoice): update subtitle from Software Solutions to Die Kasse 2026-07-07 10:30:21 +02:00
3 changed files with 16 additions and 12 deletions

View File

@@ -115,7 +115,7 @@ export const InvoicePDF = ({ order, orderSnapshot, customer }: any) => {
<View style={styles.header}>
<View>
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>CASPOS</Text>
<Text>Software Solutions</Text>
<Text>Die Kasse</Text>
</View>
<View style={styles.companyInfo}>
<Text>CASPOS Computerabrechnungssysteme GmbH</Text>

View File

@@ -12,10 +12,10 @@ export function getOrderEmailTemplate(
isUpdate: boolean = false
) {
const title = isUpdate ? 'Anfrage geändert' : 'Anfrage erhalten'
const intro = isUpdate
const intro = isUpdate
? `Deine Anfrage ${details.orderNumber} wurde aktualisiert.`
: `Deine Anfrage ${details.orderNumber} ist bei uns eingegangen und wird bearbeitet.`
const text = `Hallo,\n\n${isUpdate ? 'Deine Anfrage wurde aktualisiert.' : 'Deine Anfrage ist bei uns eingegangen.'}\n\nDetails:\n- Nummer: ${details.orderNumber}\n- Datum: ${details.formattedDate}\n- Kunde: ${details.customerCompanyName}\n${details.totalDetailsText}\n\nDeine Anfragebestätigung findest du im Anhang als PDF.\n\nPDF-Link: ${siteUrl}/api/orders/${details.orderNumber}/download\n\nViele Grüße,\nDein CASPOS Team`
const html = `
@@ -42,8 +42,6 @@ export function getOrderEmailTemplate(
</table>
</div>
<p style="color: #475569; font-size: 16px; line-height: 1.5;">Die Bestätigung liegt als PDF im Anhang.</p>
<div style="text-align: center; margin: 24px 0;">
<a href="${siteUrl}" style="display: inline-block; background-color: #3b82f6; color: #ffffff; text-decoration: none; padding: 12px 24px; border-radius: 6px; font-weight: bold; font-size: 14px;">📄 PDF herunterladen</a>
</div>
<p style="color: #475569; font-size: 16px; line-height: 1.5; margin-top: 24px;">Viele Grüße,<br>Dein CASPOS Team</p>
</div>
@@ -54,7 +52,7 @@ export function getOrderEmailTemplate(
export function getStatusEmailTemplate(orderNumber: string, oldLabel: string, newLabel: string) {
const text = `Hallo,\n\nder Status deiner Anfrage ${orderNumber} hat sich geändert.\n\nStatus: ${newLabel} (vorher: ${oldLabel})\n\nViele Grüße,\nDein CASPOS Team`
const html = `
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e2e8f0; border-radius: 8px;">
<h2 style="color: #0f172a; margin-bottom: 16px;">Statusänderung</h2>

View File

@@ -74,26 +74,32 @@ export async function getEndCustomer(id: string): Promise<EndCustomer | null> {
* Legt einen neuen Endkunden für den eingeloggten Partner an.
* partner_id wird serverseitig aus der Session gesetzt (kein Client-Trust).
*/
export async function createEndCustomer(formData: EndCustomerFormData): Promise<EndCustomer> {
export async function createEndCustomer(formData: EndCustomerFormData, companyId?: string): Promise<EndCustomer> {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) throw new Error('Not authenticated')
const { data: dbUser, error: dbUserError } = await supabase
const { data: dbUser } = await supabase
.from('users')
.select('company_id')
.select('role, company_id')
.eq('id', user.id)
.single()
if (dbUserError || !dbUser || !dbUser.company_id) {
const isAdmin = dbUser?.role === 'admin'
const resolvedCompanyId = dbUser?.company_id || companyId
if (!isAdmin && !resolvedCompanyId) {
throw new Error('Kein Unternehmen zugewiesen.')
}
const { data, error } = await supabase
// Admin ohne company_id braucht adminClient (RLS erlaubt kein INSERT ohne passende partner_id)
const client = (!dbUser?.company_id && isAdmin) ? createAdminClient() : supabase
const { data, error } = await client
.from('end_customers')
.insert([{
partner_id: dbUser.company_id,
partner_id: resolvedCompanyId || user.id,
company_name: formData.company_name,
vat_id: formData.vat_id || null,
first_name: formData.first_name || null,