Overview
The DonaSF API uses theWSDonaciones SQL Server database to manage donations, missionaries, administrators, and receipt (talon) tracking. The schema is designed to support a donation management system with multi-level tracking and delivery confirmation.
Database Schema
The database consists of several interconnected entity groups:Administration
Administrators and missionaries who manage the donation system
Donations
Donation keys (amounts), donors, and donation records
Receipts (Talones)
Receipt tracking across editions with state management
Delivery Tracking
Cash delivery records and delivery state management
Core Entities
Administration Entities
administrador
Administrators who oversee the donation system.| Column | Type | Description |
|---|---|---|
idadmin | INT IDENTITY | Primary key |
nombre | NVARCHAR(150) | Administrator name |
correo | NVARCHAR(150) | Email (unique) |
telefono | NVARCHAR(20) | Phone number |
activo | BIT | Active status (default: 1) |
fechacreacion | DATETIME | Creation date (default: GETDATE()) |
- Email must be unique
- Soft delete via
activoflag - Automatic timestamp on creation
misionero
Missionaries who collect donations and manage receipts.| Column | Type | Description |
|---|---|---|
idmisionero | INT IDENTITY | Primary key |
nombre | NVARCHAR(150) | Missionary name |
correo | NVARCHAR(150) | |
telefono | NVARCHAR(50) | Phone number |
activo | BIT | Active status (default: 1) |
idadmin | INT | Foreign key to administrador |
fecharegistro | DATETIME | Registration date (default: GETDATE()) |
- Each missionary belongs to one administrator
- Constraint:
fk_misionero_admin→administrador(idadmin)
Donation Configuration
clavedonativo
Predefined donation amounts with unique codes.| Column | Type | Description |
|---|---|---|
idclave | INT IDENTITY | Primary key |
codigo | NVARCHAR(10) | Unique donation code (e.g., “X”, “V”) |
cantidad | DECIMAL(10,2) | Donation amount |
uq_codigo- Ensures each code is unique
estado
Receipt/donation states (e.g., “Pending”, “Collected”, “Delivered”).| Column | Type | Description |
|---|---|---|
idestado | INT IDENTITY | Primary key |
descripcion | NVARCHAR(100) | State description |
estadoentrega
Delivery states for tracking cash delivery progress.| Column | Type | Description |
|---|---|---|
idestadoentrega | INT IDENTITY | Primary key |
descripcionentrega | NVARCHAR(100) | Delivery state description |
Edition Management
edicion
Receipt editions with folio number ranges.| Column | Type | Description |
|---|---|---|
idedicion | INT IDENTITY | Primary key |
nombre | NVARCHAR(100) | Edition name |
folio_inicio | INT | Starting folio number |
folio_fin | INT | Ending folio number |
fechacreacion | DATETIME | Creation date (default: GETDATE()) |
ck_rango_folio- Ensuresfolio_inicio < folio_fin
Receipt (Talon) Management
talon
Receipts assigned to missionaries for donation collection.| Column | Type | Description |
|---|---|---|
idtalon | INT IDENTITY | Primary key |
folio | INT | Receipt folio number |
idclave | INT | Foreign key to clavedonativo |
idestado | INT | Foreign key to estado |
idmisionero | INT | Foreign key to misionero |
idedicion | INT | Foreign key to edicion |
fecharegistro | DATETIME | Registration date (default: GETDATE()) |
uq_folio_clave- Unique combination of folio and donation keyck_folio_positivo- Folio must be positive- Foreign keys to:
clavedonativo,estado,misionero,edicion
- Folio numbers must fall within the edition’s range
- Each folio + clave combination is unique
- Tracks receipt lifecycle through estado
Donation Tracking
donante
Donors who make donations.| Column | Type | Description |
|---|---|---|
iddonante | INT IDENTITY | Primary key |
nombredonante | NVARCHAR(150) | Donor name |
domicilio | NVARCHAR(150) | Donor address |
donacion
Actual donation records linking missionaries, receipts, donors, and amounts.| Column | Type | Description |
|---|---|---|
iddonacion | INT IDENTITY | Primary key |
idmisionero | INT | Foreign key to misionero |
idtalon | INT | Foreign key to talon |
iddonante | INT | Foreign key to donante |
idclave | INT | Foreign key to clavedonativo |
idestado | INT | Foreign key to estado |
idestadoentrega | INT | Foreign key to estadoentrega |
- Six foreign key constraints linking to all related entities
- Tracks both donation state and delivery state independently
Delivery Management
entregaefectivo
Cash delivery records tracking when donations are delivered.| Column | Type | Description |
|---|---|---|
identrega | INT IDENTITY | Primary key |
idonacion | INT | Donation ID (note: typo in schema, no FK) |
idedicion | INT | Foreign key to edicion |
idtalon | INT | Foreign key to talon |
idmisionero | INT | Foreign key to misionero |
idestadoentrega | INT | Foreign key to estadoentrega |
fechaentrega | DATETIME | Delivery date (default: GETDATE()) |
Entity Relationships
Primary Relationships
Workflow Relationships
Administrator Creates Missionary
An administrator (
administrador) creates a missionary account (misionero) with idadmin linking them.Edition and Receipts Created
An edition (
edicion) is created with a folio range. Receipts (talon) are generated within this range, assigned to missionaries with specific donation keys (clavedonativo).Donation Collected
A missionary collects a donation from a donor (
donante). A donacion record is created linking the missionary, receipt, donor, donation key, and states.Data Access Patterns
Stored Procedures
The API uses stored procedures for data operations, located in:Database/ScriptDonaciones/Procedimientos/Procedimientos almacenados Donaciones.sqlDatabase/Stored Procedures/Procedimientos.sql
DataTable Returns
Data layer methods returnDataTable objects that are processed in the business layer:
Result Handling
Stored procedures typically return results with:Resultado(BIT) - Success/failure flagresultados(NVARCHAR) - Message or error description- Additional columns with entity data
Key Design Decisions
Soft Deletes
Soft Deletes
The
administrador and misionero tables use activo flags instead of hard deletes, preserving historical data and relationships.Dual State Tracking
Dual State Tracking
Donations track both donation state (
idestado) and delivery state (idestadoentrega) independently, allowing granular workflow control.Edition-Based Organization
Edition-Based Organization
Receipts are organized into editions with folio ranges, enabling batch management and reporting.
Unique Folio + Key Combination
Unique Folio + Key Combination
The
uq_folio_clave constraint ensures each receipt can only be used once per donation amount, preventing duplicate entries.Related Documentation
- System Architecture - Three-tier architecture overview
- Error Handling - Database error patterns
- Donations API - Donation operations