// // This is here so CodeMaid doesn't reorganize this document // namespace EgwCoreLib.Lux.Data.DbModel.Sales { /// /// Classe delle offerte commerciali /// [Table("sales_offer")] public class OfferModel { /// /// ID del record /// [Key] public int OfferID { get; set; } /// /// Environment della richiesta /// public EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS Envir { get; set; } = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; /// /// Anno rif offerta /// public int RefYear { get; set; } = DateTime.Today.Year; /// /// Numero prog offerta nell'anno (da calcolare) /// public int RefNum { get; set; } = 0; /// /// Indice revisione /// public int RefRev { get; set; } = 1; /// /// Codice calcolato offerta ANNO.NUMERO.REV /// inizia per SO = SalesOffer /// [NotMapped] public string OfferCode { get => $"SO.{RefYear:00}.{RefNum:000000}.{RefRev:000}"; } /// /// Descrizione generale /// public string Description { get; set; } = ""; /// /// ID Cliente /// public int CustomerID { get; set; } /// /// ID Dealer /// public int DealerID { get; set; } /// /// Dizionario serializzato delle preselezioni (opzionale) /// public string DictPresel { get; set; } = ""; /// /// Dizionario valorizzato dei parametri attivi /// [NotMapped] public Dictionary DictParameter { get { Dictionary answ = new(); if (!string.IsNullOrEmpty(DictPresel)) { answ = JsonConvert.DeserializeObject>(DictPresel) ?? new Dictionary(); } return answ; } //set //{ // DictPresel = JsonConvert.SerializeObject(value); //} } /// /// Validità Offerta /// public DateTime ValidUntil { get; set; } = DateTime.Now.AddMonths(1); /// /// DataOra inserimento /// public DateTime Inserted { get; set; } /// /// DataOra ultima modifica /// public DateTime Modified { get; set; } /// /// DataOra richiesta per il completamento dell'ordine /// public DateTime DueDateReq { get; set; } = DateTime.Today.AddDays(30); /// /// DataOra promessa per il completamento dell'ordine /// public DateTime DueDateProm { get; set; } = DateTime.Today.AddDays(60); /// /// note di consegna (opzionali) /// public string ConsNote { get; set; } = ""; /// /// Enum stato offerta /// public OfferStates OffertState { get; set; } = OfferStates.Open; /// /// Sconto applicato (deve essere < del MAX) /// public double Discount { get; set; } = 0; /// /// Numero Item compresi /// [NotMapped] public double NumItems { get => OfferRowNav?.Sum(x => x.Qty) ?? 0; } /// /// Numero ProdItem compresi /// [NotMapped] public double NumProdItems { get => OfferRowNav?.Sum(x => x.ProdItemQtyTot) ?? 0; } /// /// Numero Item compresi /// [NotMapped] public int NumRows { get => OfferRowNav?.Count ?? 0; } /// /// Costo totale offerta (rock bottom) /// [NotMapped] public double TotalCost { get => OfferRowNav?.Sum(x => x.TotalCost) ?? 0; } /// /// Prezzo totale offerta (compreso di amrginalità) /// [NotMapped] public double TotalPrice { get => OfferRowNav?.Sum(x => x.TotalPrice) ?? 0; } /// /// Sconto massimo applicabile /// [NotMapped] public double MaxDiscount { get => (TotalCost > 0 && TotalPrice > TotalCost) ? (TotalPrice - TotalCost) / TotalPrice : 0; } /// /// Navigazione Customer /// [ForeignKey("CustomerID")] public virtual CustomerModel CustomerNav { get; set; } = null!; /// /// Navigazione Dealer /// [ForeignKey("DealerID")] public virtual DealerModel DealerNav { get; set; } = null!; /// /// Navigazione alle righe offerta /// public virtual ICollection OfferRowNav { get; set; } = new List(); } }