- Schema: isConditional, conditionType, conditionText, conditionThreshold, conditionMet, conditionMetAt on Pledge - Pledge form: 'This is a match pledge' toggle after amount selection - Two modes: threshold (if target is reached) and match (match funding) - Goal amount passed through from event - Auto-trigger: when total raised hits threshold, conditional pledges unlock automatically - WhatsApp notification sent to donor when unlocked - Threshold check runs after every pledge creation AND every status change - Cron: skips conditional pledges until conditionMet=true (no premature reminders) - Dashboard Home: progress bar shows conditional segment (amber), stats grid adds Conditional column - Dashboard Money: conditional/unlocked badge on pledge rows - Dashboard Collect: hero shows conditional total in amber - Dashboard Reports: financial summary shows conditional breakdown - Donor 'My Pledges': conditional card with condition text + activation status - Confirmation step: specialized messaging for match pledges - CRM export: includes is_conditional, condition_type, condition_text, condition_met columns - Status guide: conditional status explained in human language
298 lines
10 KiB
Plaintext
298 lines
10 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
model Organization {
|
|
id String @id @default(cuid())
|
|
name String
|
|
slug String @unique
|
|
orgType String @default("charity") // charity | fundraiser
|
|
country String @default("UK")
|
|
timezone String @default("Europe/London")
|
|
bankName String?
|
|
bankSortCode String?
|
|
bankAccountNo String?
|
|
bankAccountName String?
|
|
refPrefix String @default("PNPL")
|
|
logo String?
|
|
primaryColor String @default("#1e40af")
|
|
gcAccessToken String?
|
|
gcEnvironment String @default("sandbox")
|
|
stripeSecretKey String?
|
|
stripeWebhookSecret String?
|
|
emailProvider String? // resend, sendgrid, smtp
|
|
emailApiKey String?
|
|
emailFromAddress String? // e.g. donations@mymosque.org
|
|
emailFromName String? // e.g. "Al Furqan Mosque"
|
|
smsProvider String? // twilio
|
|
smsAccountSid String?
|
|
smsAuthToken String?
|
|
smsFromNumber String? // e.g. +447123456789
|
|
whatsappConnected Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
users User[]
|
|
events Event[]
|
|
pledges Pledge[]
|
|
imports Import[]
|
|
messageTemplates MessageTemplate[]
|
|
automationConfig AutomationConfig?
|
|
|
|
@@index([slug])
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
name String?
|
|
hashedPassword String?
|
|
role String @default("staff") // super_admin, org_admin, staff, volunteer
|
|
organizationId String
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([organizationId])
|
|
}
|
|
|
|
model Event {
|
|
id String @id @default(cuid())
|
|
name String
|
|
slug String
|
|
description String?
|
|
eventDate DateTime?
|
|
location String?
|
|
goalAmount Int? // in pence
|
|
currency String @default("GBP")
|
|
status String @default("active") // draft, active, closed, archived
|
|
paymentMode String @default("self") // self = we show bank details, external = redirect to URL
|
|
externalUrl String? // e.g. https://launchgood.com/my-campaign
|
|
externalPlatform String? // launchgood, enthuse, justgiving, gofundme, other
|
|
zakatEligible Boolean @default(false) // is this campaign Zakat-eligible?
|
|
organizationId String
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
qrSources QrSource[]
|
|
pledges Pledge[]
|
|
|
|
@@unique([organizationId, slug])
|
|
@@index([organizationId, status])
|
|
}
|
|
|
|
model QrSource {
|
|
id String @id @default(cuid())
|
|
label String // "Table 5", "Volunteer: Ahmed"
|
|
code String @unique // short token for URL
|
|
volunteerName String?
|
|
tableName String?
|
|
eventId String
|
|
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
|
scanCount Int @default(0)
|
|
createdAt DateTime @default(now())
|
|
|
|
pledges Pledge[]
|
|
|
|
@@index([eventId])
|
|
@@index([code])
|
|
}
|
|
|
|
model Pledge {
|
|
id String @id @default(cuid())
|
|
reference String @unique // human-safe bank ref e.g. "PNPL-7K4P-50"
|
|
amountPence Int
|
|
currency String @default("GBP")
|
|
rail String // bank, gocardless, card
|
|
status String @default("new") // new, initiated, paid, overdue, cancelled
|
|
donorName String?
|
|
donorEmail String?
|
|
donorPhone String?
|
|
|
|
// --- Home address (required by HMRC for Gift Aid claims) ---
|
|
donorAddressLine1 String?
|
|
donorPostcode String?
|
|
|
|
// --- Gift Aid (HMRC) ---
|
|
giftAid Boolean @default(false)
|
|
giftAidAt DateTime? // when the declaration was made
|
|
isZakat Boolean @default(false) // donor marked this as Zakat
|
|
|
|
// --- Communication consent (GDPR / PECR) ---
|
|
emailOptIn Boolean @default(false)
|
|
whatsappOptIn Boolean @default(false)
|
|
|
|
// --- Consent audit trail (immutable evidence) ---
|
|
// Stores exact text shown, timestamps, IP, user agent per consent type
|
|
consentMeta Json?
|
|
|
|
iPaidClickedAt DateTime?
|
|
notes String?
|
|
|
|
// --- Conditional / Match Funding ---
|
|
// A conditional pledge activates only when a condition is met.
|
|
// e.g. "I'll give £5,000 if you raise £20,000" or "I'll match up to £5,000"
|
|
isConditional Boolean @default(false)
|
|
conditionType String? // "threshold" | "match" | "custom"
|
|
conditionText String? // Human-readable: "If £20,000 is raised"
|
|
conditionThreshold Int? // pence — when event total reaches this, condition is met
|
|
conditionMet Boolean @default(false)
|
|
conditionMetAt DateTime?
|
|
|
|
// Payment scheduling — the core of "pledge now, pay later"
|
|
dueDate DateTime? // null = pay now, set = promise to pay on this date
|
|
planId String? // groups installments together
|
|
installmentNumber Int? // e.g. 1 (of 4)
|
|
installmentTotal Int? // e.g. 4
|
|
reminderSentForDueDate Boolean @default(false)
|
|
|
|
eventId String
|
|
event Event @relation(fields: [eventId], references: [id])
|
|
qrSourceId String?
|
|
qrSource QrSource? @relation(fields: [qrSourceId], references: [id])
|
|
organizationId String
|
|
organization Organization @relation(fields: [organizationId], references: [id])
|
|
|
|
paymentInstruction PaymentInstruction?
|
|
payments Payment[]
|
|
reminders Reminder[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
paidAt DateTime?
|
|
cancelledAt DateTime?
|
|
|
|
@@index([organizationId, status])
|
|
@@index([reference])
|
|
@@index([eventId, status])
|
|
@@index([donorEmail])
|
|
@@index([donorPhone])
|
|
@@index([dueDate, status])
|
|
@@index([planId])
|
|
}
|
|
|
|
model PaymentInstruction {
|
|
id String @id @default(cuid())
|
|
pledgeId String @unique
|
|
pledge Pledge @relation(fields: [pledgeId], references: [id], onDelete: Cascade)
|
|
bankReference String // the unique ref to use
|
|
bankDetails Json // {sortCode, accountNo, accountName, bankName}
|
|
gcMandateId String?
|
|
gcMandateUrl String?
|
|
sentAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([bankReference])
|
|
}
|
|
|
|
model Payment {
|
|
id String @id @default(cuid())
|
|
pledgeId String
|
|
pledge Pledge @relation(fields: [pledgeId], references: [id], onDelete: Cascade)
|
|
provider String // bank, gocardless, stripe
|
|
providerRef String? // external ID
|
|
amountPence Int
|
|
status String @default("pending") // pending, confirmed, failed
|
|
matchedBy String? // auto, manual
|
|
receivedAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
importId String?
|
|
import Import? @relation(fields: [importId], references: [id])
|
|
|
|
@@index([pledgeId])
|
|
@@index([providerRef])
|
|
}
|
|
|
|
model Reminder {
|
|
id String @id @default(cuid())
|
|
pledgeId String
|
|
pledge Pledge @relation(fields: [pledgeId], references: [id], onDelete: Cascade)
|
|
step Int // 0=instructions, 1=nudge, 2=urgency, 3=final
|
|
channel String @default("email") // email, sms, whatsapp
|
|
scheduledAt DateTime
|
|
sentAt DateTime?
|
|
status String @default("pending") // pending, sent, skipped, failed
|
|
payload Json?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([pledgeId])
|
|
@@index([scheduledAt, status])
|
|
}
|
|
|
|
model Import {
|
|
id String @id @default(cuid())
|
|
organizationId String
|
|
organization Organization @relation(fields: [organizationId], references: [id])
|
|
kind String // bank_statement, gocardless_export, crm_export
|
|
fileName String?
|
|
rowCount Int @default(0)
|
|
matchedCount Int @default(0)
|
|
unmatchedCount Int @default(0)
|
|
mappingConfig Json?
|
|
stats Json?
|
|
status String @default("pending") // pending, processing, completed, failed
|
|
uploadedAt DateTime @default(now())
|
|
|
|
payments Payment[]
|
|
|
|
@@index([organizationId])
|
|
}
|
|
|
|
model MessageTemplate {
|
|
id String @id @default(cuid())
|
|
organizationId String
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
step Int // 0=receipt, 1=day2_gentle, 2=day7_impact, 3=day14_final
|
|
channel String // whatsapp, email, sms
|
|
variant String @default("A") // A, B for A/B testing
|
|
name String // human label: "Gentle reminder", "Impact nudge"
|
|
subject String? // email-only: subject line
|
|
body String // template with {{variables}}
|
|
isActive Boolean @default(true)
|
|
splitPercent Int @default(100) // A/B: e.g. 50 = 50% get this variant
|
|
sentCount Int @default(0)
|
|
convertedCount Int @default(0) // donors who paid after receiving this
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@unique([organizationId, step, channel, variant])
|
|
@@index([organizationId])
|
|
}
|
|
|
|
model AutomationConfig {
|
|
id String @id @default(cuid())
|
|
organizationId String @unique
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
isActive Boolean @default(true)
|
|
step1Delay Int @default(2) // days after pledge for step 1
|
|
step2Delay Int @default(7) // days after pledge for step 2
|
|
step3Delay Int @default(14) // days after pledge for step 3
|
|
strategy String @default("waterfall") // waterfall, parallel, escalation, custom
|
|
channelMatrix Json? // per-step channel config: { "0": ["whatsapp","email"], "1": ["whatsapp"], ... }
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model AnalyticsEvent {
|
|
id String @id @default(cuid())
|
|
eventType String // pledge_start, amount_selected, rail_selected, identity_submitted, pledge_completed, instruction_copy_clicked, i_paid_clicked, payment_matched
|
|
pledgeId String?
|
|
eventId String?
|
|
qrSourceId String?
|
|
metadata Json?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([eventType])
|
|
@@index([pledgeId])
|
|
@@index([eventId])
|
|
@@index([createdAt])
|
|
}
|