diff --git a/RS_system.sln.DotSettings.user b/RS_system.sln.DotSettings.user
index 9013190..a767a8a 100644
--- a/RS_system.sln.DotSettings.user
+++ b/RS_system.sln.DotSettings.user
@@ -2,4 +2,6 @@
ForceIncluded
ForceIncluded
ForceIncluded
- ForceIncluded
\ No newline at end of file
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
\ No newline at end of file
diff --git a/RS_system/Data/ApplicationDbContext.cs b/RS_system/Data/ApplicationDbContext.cs
index 6cf0448..6a47e55 100644
--- a/RS_system/Data/ApplicationDbContext.cs
+++ b/RS_system/Data/ApplicationDbContext.cs
@@ -28,9 +28,19 @@ public class ApplicationDbContext : DbContext
public DbSet Ofrendas { get; set; }
public DbSet DescuentosOfrenda { get; set; }
+
// Church Members module
public DbSet GruposTrabajo { get; set; }
public DbSet Miembros { get; set; }
+ public DbSet ContabilidadRegistros { get; set; }
+ public DbSet ReportesMensualesContables { get; set; }
+
+ // General church accounting module
+ public DbSet CategoriasIngreso { get; set; }
+ public DbSet CategoriasEgreso { get; set; }
+ public DbSet MovimientosGenerales { get; set; }
+ public DbSet MovimientosGeneralesAdjuntos { get; set; }
+ public DbSet ReportesMensualesGenerales { get; set; }
// Inventory module
public DbSet Categorias { get; set; }
@@ -39,10 +49,26 @@ public class ApplicationDbContext : DbContext
public DbSet Existencias { get; set; }
public DbSet Articulos { get; set; }
public DbSet MovimientosInventario { get; set; }
+ public DbSet Prestamos { get; set; }
+ public DbSet PrestamoDetalles { get; set; }
+
+ // Collaborations module
+ public DbSet TiposColaboracion { get; set; }
+ public DbSet Colaboraciones { get; set; }
+ public DbSet DetalleColaboraciones { get; set; }
+
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
+
+ // 1. Registrar el enum de PostgreSQL
+ modelBuilder.HasPostgresEnum("tipo_movimiento_general");
+
+ // 2. Asegurar que la propiedad use ese tipo
+ modelBuilder.Entity()
+ .Property(e => e.Tipo)
+ .HasColumnType("tipo_movimiento_general");
base.OnModelCreating(modelBuilder);
// Configure composite key for RolUsuario
@@ -97,7 +123,101 @@ public class ApplicationDbContext : DbContext
.HasForeignKey(m => m.PersonaId)
.OnDelete(DeleteBehavior.Restrict);
+ modelBuilder.Entity()
+ .HasOne(c => c.GrupoTrabajo)
+ .WithMany()
+ .HasForeignKey(c => c.GrupoTrabajoId)
+ .OnDelete(DeleteBehavior.Restrict);
+ modelBuilder.Entity()
+ .HasOne(r => r.GrupoTrabajo)
+ .WithMany()
+ .HasForeignKey(r => r.GrupoTrabajoId)
+ .OnDelete(DeleteBehavior.Restrict);
+
+ modelBuilder.Entity()
+ .HasMany(r => r.Registros)
+ .WithOne(c => c.ReporteMensual)
+ .HasForeignKey(c => c.ReporteMensualId)
+ .OnDelete(DeleteBehavior.Cascade);
+
+ // General accounting module relationships
+ modelBuilder.Entity()
+ .HasMany(r => r.Movimientos)
+ .WithOne(m => m.ReporteMensualGeneral)
+ .HasForeignKey(m => m.ReporteMensualGeneralId)
+ .OnDelete(DeleteBehavior.Cascade);
+
+ modelBuilder.Entity()
+ .HasIndex(r => new { r.Mes, r.Anio })
+ .IsUnique();
+
+ modelBuilder.Entity()
+ .HasOne(m => m.CategoriaIngreso)
+ .WithMany(c => c.Movimientos)
+ .HasForeignKey(m => m.CategoriaIngresoId)
+ .OnDelete(DeleteBehavior.Restrict);
+
+ modelBuilder.Entity()
+ .HasOne(m => m.CategoriaEgreso)
+ .WithMany(c => c.Movimientos)
+ .HasForeignKey(m => m.CategoriaEgresoId)
+ .OnDelete(DeleteBehavior.Restrict);
+
+ modelBuilder.Entity()
+ .HasMany(m => m.Adjuntos)
+ .WithOne(a => a.MovimientoGeneral)
+ .HasForeignKey(a => a.MovimientoGeneralId)
+ .OnDelete(DeleteBehavior.Cascade);
+
+ modelBuilder.HasPostgresEnum("tipo_movimiento");
+
+ modelBuilder.Entity()
+ .Property(e => e.TipoMovimiento)
+ .HasColumnType("tipo_movimiento");
+
+ // Collaborations module configuration
+ modelBuilder.Entity(entity =>
+ {
+ entity.ToTable("tipos_colaboracion", "public");
+ entity.HasKey(e => e.Id);
+ entity.Property(e => e.Nombre).HasMaxLength(100).IsRequired();
+ entity.Property(e => e.MontoSugerido).HasColumnType("decimal(10,2)");
+ });
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.ToTable("colaboraciones", "public");
+ entity.HasKey(e => e.Id);
+ entity.Property(e => e.MontoTotal).HasColumnType("decimal(10,2)");
+
+ entity.HasOne(e => e.Miembro)
+ .WithMany()
+ .HasForeignKey(e => e.MiembroId)
+ .OnDelete(DeleteBehavior.Restrict);
+
+ entity.HasMany(e => e.Detalles)
+ .WithOne(d => d.Colaboracion)
+ .HasForeignKey(d => d.ColaboracionId)
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.ToTable("detalle_colaboraciones", "public");
+ entity.HasKey(e => e.Id);
+ entity.Property(e => e.Monto).HasColumnType("decimal(10,2)");
+
+ entity.HasOne(e => e.TipoColaboracion)
+ .WithMany(t => t.Detalles)
+ .HasForeignKey(e => e.TipoColaboracionId)
+ .OnDelete(DeleteBehavior.Restrict);
+
+ entity.HasIndex(e => new { e.ColaboracionId, e.TipoColaboracionId, e.Mes, e.Anio })
+ .IsUnique();
+ });
+
+
// Global configuration: Convert all dates to UTC when saving
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
diff --git a/RS_system/Program.cs b/RS_system/Program.cs
index 4c86cda..ea63614 100644
--- a/RS_system/Program.cs
+++ b/RS_system/Program.cs
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.EntityFrameworkCore;
+using Npgsql;
using Rs_system.Data;
+using Rs_system.Models;
using Rs_system.Services;
var builder = WebApplication.CreateBuilder(args);
@@ -8,10 +10,17 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("PostgreSQL") ??
throw new InvalidOperationException("Connection string 'PostgreSQL' not found.");
+var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
+dataSourceBuilder.MapEnum("tipo_movimiento_new");
+
+var dataSource = dataSourceBuilder.Build();
+// ⚠️ HABILITA enums no mapeados
+dataSourceBuilder.EnableUnmappedTypes();
builder.Services.AddDbContext(options =>
- options.UseNpgsql(connectionString, npgsqlOptions =>
+ options.UseNpgsql(dataSource, npgsqlOptions =>
{
+ npgsqlOptions.MapEnum("tipo_movimiento_general");
npgsqlOptions.EnableRetryOnFailure(
maxRetryCount: 3,
maxRetryDelay: TimeSpan.FromSeconds(5),
@@ -36,6 +45,10 @@ builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
builder.Services.AddSingleton();
builder.Services.AddMemoryCache(options =>
{
diff --git a/RS_system/Views/Account/Login.cshtml b/RS_system/Views/Account/Login.cshtml
index c424e0b..652aed5 100644
--- a/RS_system/Views/Account/Login.cshtml
+++ b/RS_system/Views/Account/Login.cshtml
@@ -74,6 +74,6 @@
-
+