Skip to content

Commit

Permalink
Merge pull request #321 from ucdavis/JCS/OrderingSystem
Browse files Browse the repository at this point in the history
Jcs/ordering system
  • Loading branch information
jSylvestre authored Jul 25, 2024
2 parents 4087f57 + e4fb1b4 commit 7c0e3ab
Show file tree
Hide file tree
Showing 135 changed files with 42,024 additions and 32 deletions.
13 changes: 12 additions & 1 deletion Hippo.Core/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -41,6 +41,12 @@ protected AppDbContext(DbContextOptions options) : base(options)
public virtual DbSet<TempKerberos> TempKerberos { get; set; }
public virtual DbSet<QueuedEvent> QueuedEvents { get; set; }
public virtual DbSet<AccessType> AccessTypes { get; set; }
public virtual DbSet<FinancialDetail> FinancialDetails { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<Billing> Billings { get; set; }
public virtual DbSet<OrderMetaData> MetaData { get; set; }
public virtual DbSet<Payment> Payments { get; set; }

protected override void OnModelCreating(ModelBuilder builder)
{
Expand All @@ -57,6 +63,11 @@ protected override void OnModelCreating(ModelBuilder builder)
Domain.GroupMemberAccount.OnModelCreating(builder);
QueuedEvent.OnModelCreating(builder, this);
AccessType.OnModelCreating(builder);
FinancialDetail.OnModelCreating(builder);
Product.OnModelCreating(builder);
OrderMetaData.OnModelCreating(builder);
Order.OnModelCreating(builder);
Payment.OnModelCreating(builder);
TempGroup.OnModelCreating(builder);
Domain.TempKerberos.OnModelCreating(builder);
}
Expand Down
5 changes: 4 additions & 1 deletion Hippo.Core/Domain/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public Account()

[JsonIgnore]
public List<AccessType> AccessTypes { get; set; } = new();


[JsonIgnore]
public List<Order> Orders { get; set; } = new();

internal static void OnModelCreating(ModelBuilder modelBuilder, DbContext dbContext)
{
modelBuilder.Entity<Account>().HasQueryFilter(a => a.Cluster.IsActive);
Expand Down
20 changes: 20 additions & 0 deletions Hippo.Core/Domain/Billing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace Hippo.Core.Domain
{
public class Billing
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(128)]
public string ChartString { get; set; }
public decimal Percentage { get; set; } = 100;
[Required]
public int OrderId { get; set; }
[JsonIgnore]
public Order Order { get; set; }
public DateTime Updated { get; set; } = DateTime.UtcNow;
}
}
27 changes: 27 additions & 0 deletions Hippo.Core/Domain/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public class Cluster
[MinLength(1)]
public List<AccessType> AccessTypes { get; set; } = new();

[JsonIgnore]
public FinancialDetail FinancialDetail { get; set; }

[JsonIgnore]
public List<Product> Products { get; set; } = new();

[JsonIgnore]
public List<Order> Orders { get; set; } = new();

internal static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Cluster>().HasQueryFilter(a => a.IsActive);
Expand All @@ -67,6 +76,24 @@ internal static void OnModelCreating(ModelBuilder modelBuilder)
.WithMany()
.HasForeignKey(p => p.ClusterId)
.OnDelete(DeleteBehavior.Restrict);

// Cluster has a one to one relationship with FinancialDetail where the financial detail is nullable
modelBuilder.Entity<Cluster>()
.HasOne(c => c.FinancialDetail)
.WithOne(c => c.Cluster)
.HasForeignKey<FinancialDetail>(fd => fd.ClusterId)
.OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity<Product>()
.HasOne(p => p.Cluster)
.WithMany(c => c.Products)
.HasForeignKey(p => p.ClusterId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Order>()
.HasOne(o => o.Cluster)
.WithMany(c => c.Orders)
.HasForeignKey(o => o.ClusterId)
.OnDelete(DeleteBehavior.Restrict);
}
}
}
27 changes: 27 additions & 0 deletions Hippo.Core/Domain/FinancialDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;

namespace Hippo.Core.Domain
{
public class FinancialDetail
{
[Key]
public int Id { get; set; }
[MaxLength(200)]
public string SecretAccessKey { get; set; } //Used to get the FinancialSystemApiKey from the secret service
[Required]
[MaxLength(50)]
public string FinancialSystemApiSource { get; set; }
[MaxLength(128)]
public string ChartString { get; set; }
public bool AutoApprove { get; set; }
[Required]
public int ClusterId { get; set; }
public Cluster Cluster { get; set; }

internal static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<FinancialDetail>().Property(a => a.AutoApprove).HasDefaultValue(true);
}
}
}
51 changes: 51 additions & 0 deletions Hippo.Core/Domain/History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,26 @@ public History()
public int? ClusterId { get; set; } //When we have a cluster identifier
public Cluster Cluster { get; set; }

public int? OrderId { get; set; }
public Order Order { get; set; }

[MaxLength(50)]
public string Status { get; set; }

[MaxLength(50)]
public string Type { get; set; } = HistoryTypes.Detail;

internal static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<History>().HasQueryFilter(h => h.Cluster == null || h.Cluster.IsActive);
modelBuilder.Entity<History>().HasIndex(h => h.ActedDate);
modelBuilder.Entity<History>().HasIndex(h => h.Action);
modelBuilder.Entity<History>().HasIndex(h => h.ClusterId);
modelBuilder.Entity<History>().HasIndex(h => h.Type);
modelBuilder.Entity<History>().HasIndex(h => h.OrderId);
modelBuilder.Entity<History>().HasOne(h => h.ActedBy).WithMany().HasForeignKey(a => a.ActedById).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<History>().HasOne(h => h.Cluster).WithMany().HasForeignKey(a => a.ClusterId).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<History>().HasOne(h => h.Order).WithMany(o => o.History).HasForeignKey(a => a.OrderId).OnDelete(DeleteBehavior.Restrict);
}

public class Actions
Expand Down Expand Up @@ -75,5 +84,47 @@ public class Actions
}.ToList();

}

public class OrderActions
{
public const string Created = "Created";
public const string Updated = "Updated";
public const string Submitted = "Submitted";
public const string Processing = "Processing";
public const string Cancelled = "Cancelled";
public const string Active = "Active";
public const string Rejected = "Rejected";
public const string Completed = "Completed";
public const string AdhocPayment = "Adhoc Payment";
public const string ChartStringUpdated = "Chart String Updated";
public const string PaymentFailed = "Payment Failed";

public static List<string> OrderActionList = new List<string>
{
Created,
Updated,
Submitted,
Processing,
Cancelled,
Active,
Rejected,
Completed,
AdhocPayment,
ChartStringUpdated,
PaymentFailed
}.ToList();
}

public class HistoryTypes
{
public const string Primary = "Primary";
public const string Detail = "Detail";

public static List<string> TypeList = new List<string>
{
Primary,
Detail
}.ToList();
}
}
}
111 changes: 111 additions & 0 deletions Hippo.Core/Domain/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using static Hippo.Core.Domain.Product;

namespace Hippo.Core.Domain
{
public class Order :ProductBase
{

[Required]
[MaxLength(50)]
public string ProductName { get; set; }

[MaxLength(150)]
public string ExternalReference { get; set; }

[Required]
[Range(0.0001, double.MaxValue)]
public decimal Quantity { get; set; }

public decimal Adjustment { get; set; }
public string AdjustmentReason { get; set; }
public decimal SubTotal { get; set; }
public decimal Total { get; set; }
public decimal BalanceRemaining { get; set; } //We will also calculate this when we do a payment
public string Notes { get; set; }
public string AdminNotes { get; set; }
[MaxLength(20)]
public string Status { get; set; }

public DateTime? InstallmentDate { get; set; }
public DateTime? ExpirationDate { get; set; } //This would default to InstallmentDate + LifeCycle Months

public DateTime? NextPaymentDate { get; set; } //When we start payments, this will be set to trigger the auto creation of a payment. Onetime=tomorrow, Monthly=1st of next month, yearly= jan 1st of next year.

public DateTime? NextNotificationDate { get; set; } //This will be used to send notification to the sponsor once the ExpirationDate is reached. This will be set to ExpirationDate - 30 days?

public decimal InstallmentAmount => Math.Round(Total / Installments, 2);

[Required]
public int ClusterId { get; set; }
[JsonIgnore]
public Cluster Cluster { get; set; }


[Required]
public int PrincipalInvestigatorId { get; set; }
public Account PrincipalInvestigator { get; set; }

public DateTime CreatedOn { get; set; } = DateTime.UtcNow;

public List<Billing> Billings { get; set; } = new();

public List<OrderMetaData> MetaData { get; set; } = new();

public void AddMetaData(string key, string value)
{
MetaData.Add(new OrderMetaData { Name = key, Value = value, Order = this });
}
[JsonIgnore]
public List<Payment> Payments { get; set; } = new();

[JsonIgnore]
public List<History> History { get; set; } = new();

public class Statuses
{
public const string Created = "Created";
public const string Submitted = "Submitted";
public const string Processing = "Processing";
public const string Cancelled = "Cancelled";
public const string Active = "Active";
public const string Rejected = "Rejected"; //Not sure if we need this
public const string Completed = "Completed";

public static List<string> StatusTypes = new List<string>
{
Created,
Submitted,
Processing,
Cancelled,
Active,
Rejected,
Completed
};
}
internal static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>().HasQueryFilter(o => o.Cluster.IsActive);
modelBuilder.Entity<Order>().HasIndex(o => o.PrincipalInvestigatorId);
modelBuilder.Entity<Order>().HasIndex(o => o.ClusterId);
modelBuilder.Entity<Order>().HasIndex(o => o.Status);
modelBuilder.Entity<Order>().HasIndex(o => o.ExpirationDate);
modelBuilder.Entity<Order>().HasIndex(o => o.NextNotificationDate);
modelBuilder.Entity<Billing>().HasOne(o => o.Order).WithMany(o => o.Billings).HasForeignKey(o => o.OrderId).OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<OrderMetaData>().HasOne(o => o.Order).WithMany(o => o.MetaData).HasForeignKey(o => o.OrderId).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Payment>().HasOne(o => o.Order).WithMany(o => o.Payments).HasForeignKey(o => o.OrderId).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Order>()
.HasOne(o => o.PrincipalInvestigator)
.WithMany(u => u.Orders)
.HasForeignKey(o => o.PrincipalInvestigatorId)
.OnDelete(DeleteBehavior.Restrict);
}
}
}
34 changes: 34 additions & 0 deletions Hippo.Core/Domain/OrderMetaData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Hippo.Core.Domain
{
public class OrderMetaData
{
[Key]
public int Id { get; set; }
[Required]
public int OrderId { get; set; }
[JsonIgnore]
public Order Order { get; set; }
[Required]
[MaxLength(128)]
public string Name { get; set; }

[Required]
[MaxLength(450)]
public string Value { get; set; }

internal static void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<OrderMetaData>().HasIndex(a => a.OrderId);
modelBuilder.Entity<OrderMetaData>().HasIndex(a => new {a.OrderId, a.Name, a.Value });
}
}
}
Loading

0 comments on commit 7c0e3ab

Please sign in to comment.