diff --git a/Distribution/Models/Order.cs b/Distribution/Models/Order.cs index ef7448f..99ed0e9 100644 --- a/Distribution/Models/Order.cs +++ b/Distribution/Models/Order.cs @@ -1,12 +1,20 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; namespace Distribution.Models { public class Order : Template { - public Guid FK_SaleId { get; set; } + public Guid? FK_SaleId { get; set; } [ForeignKey("FK_SaleId")] - public Sale Sale { get; set; } + public Sale? Sale { get; set; } + + public Guid CreatedByUserId { get; set; } + [ForeignKey("CreatedByUserId")] + public User CreatedByUser { get; set; } + + /// Set once an Invoice is created for this PO (either mode). No DB-level FK + /// constraint — configured explicitly in Fluent API per order_invoice_lifecycle.md. + public Guid? InvoiceId { get; set; } public DateTime OrderDate { get; set; } public Guid FK_StoreId { get; set; } @@ -16,6 +24,15 @@ namespace Distribution.Models public OrderStatus Status { get; set; } = OrderStatus.Pending; public DateTime? FulfilledAt { get; set; } + /// Null = Shop PO (items editable). Set = Confirmed PO (items locked). Not modeled + /// as an explicit field in order_invoice_lifecycle.md's diagram, but required to implement + /// its Business Rule 1 (item edits gated on confirmation) independent of Invoice existing — + /// Mode B confirms a PO with no Invoice at all. + public DateTime? ConfirmedAt { get; set; } + public Guid? ConfirmedByUserId { get; set; } + [ForeignKey("ConfirmedByUserId")] + public User? ConfirmedByUser { get; set; } + public ICollection OrderItems { get; set; } = new List(); } }