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

@@ -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>

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,