import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer'; const styles = StyleSheet.create({ page: { padding: 50, fontSize: 10, color: '#333', fontFamily: 'Helvetica', }, header: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 40, }, companyInfo: { textAlign: 'right', }, title: { fontSize: 24, color: '#000', marginBottom: 20, }, section: { marginBottom: 20, }, label: { fontSize: 8, color: '#999', textTransform: 'uppercase', marginBottom: 2, }, table: { width: 'auto', borderStyle: 'solid', borderWidth: 1, borderColor: '#eee', borderRightWidth: 0, borderBottomWidth: 0, marginBottom: 20, }, tableRow: { margin: 'auto', flexDirection: 'row', }, tableCol: { width: '60%', borderStyle: 'solid', borderWidth: 1, borderColor: '#eee', borderLeftWidth: 0, borderTopWidth: 0, padding: 8, }, tableColPrice: { width: '40%', borderStyle: 'solid', borderWidth: 1, borderColor: '#eee', borderLeftWidth: 0, borderTopWidth: 0, padding: 8, textAlign: 'right', }, total: { flexDirection: 'row', justifyContent: 'flex-end', marginTop: 20, borderTopWidth: 1, borderColor: '#000', paddingTop: 10, }, totalLabel: { fontSize: 11, fontWeight: 'bold', }, footer: { position: 'absolute', bottom: 30, left: 50, right: 50, textAlign: 'center', color: '#999', fontSize: 8, borderTopWidth: 1, borderColor: '#eee', paddingTop: 10, }, sepaBox: { marginTop: 15, padding: 10, backgroundColor: '#f9f9f9', borderWidth: 1, borderColor: '#ddd', } }); export const InvoicePDF = ({ order, orderSnapshot, customer }: any) => { const items = orderSnapshot?.items ?? []; const taxRate = orderSnapshot?.tax_rate ?? 19; const isSubscription = order?.type === 'subscription' || orderSnapshot?.billing_cycle === 'monthly'; const totalNet = items.reduce((sum: number, item: any) => sum + (item.item_total || 0), 0); const totalTax = Math.round(totalNet * (taxRate / 100) * 100) / 100; const totalGross = Math.round((totalNet + totalTax) * 100) / 100; const formattedPrice = (val: number) => new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(val); return ( CASPOS Die Kasse CASPOS Computerabrechnungssysteme GmbH Alte Bundesstraße 16 76846 Hauenstein Deutschland {isSubscription ? 'Vertragsbestätigung (Abonnement)' : 'B2B-Rechnung'} Kunde {customer.company_name} {customer.first_name} {customer.last_name} {customer.address} {customer.zip_code} {customer.city} USt-IdNr: {customer.vat_id} Bestelldetails Bestellnummer: {order.order_number || order.id} Zahlungsart: {isSubscription ? 'SEPA-Lastschrift' : 'Rechnung'} Datum: {new Date(order.created_at || Date.now()).toLocaleDateString('de-DE')} Beschreibung Preis (netto) {items.map((item: any, idx: number) => ( {item.product_name} ({item.category_name}) {formattedPrice(item.base_price)} {isSubscription ? 'mtl.' : 'einmalig'} {item.selected_modules?.map((mod: any, mIdx: number) => { const qty = mod.quantity || 1; const price = mod.total_price ?? (mod.price * qty); return ( + {mod.module_name} {qty > 1 ? `(x${qty})` : ''} +{formattedPrice(price)} ); })} ))} Netto-Zwischensumme: {formattedPrice(totalNet)}{isSubscription ? ' / mtl.' : ''} zzgl. {taxRate}% USt: {formattedPrice(totalTax)}{isSubscription ? ' / mtl.' : ''} Gesamtbetrag (brutto): {formattedPrice(totalGross)}{isSubscription ? ' / mtl.' : ''} {isSubscription ? ( SEPA-Lastschriftmandat Ich ermächtige die CASPOS GmbH, Zahlungen von meinem Konto mittels Lastschrift einzuziehen. Zugleich weise ich mein Kreditinstitut an, die von der CASPOS GmbH auf mein Konto gezogenen Lastschriften einzulösen. {customer.bank_iban && ( IBAN: {customer.bank_iban.replace(/(.{4})/g, '$1 ')} · Inhaber: {customer.bank_owner || 'Kunde'} )} ) : ( Zahlungsziel Zahlbar innerhalb von 14 Tagen nach Erhalt dieser Rechnung ohne Abzug. )} CASPOS Computerabrechnungssysteme GmbH · Amtsgericht Zweibrücken HRB 12345 Dies ist ein automatisch erzeugtes Dokument. ); };