using MisIngredientesVue.Core.Services; using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text; using System.Linq; using MisIngredientesVue.Core.Attributes; using System.Text.Json.Serialization; namespace MisIngredientesVue.Core.Models { public class Order : RepositoryEntityWithTenantId { [DisplayName("Folio")] public string Folio { get { return NumFolio.ToString().PadLeft(4, '0'); } } public int NumFolio { get; set; } public int? TemplateId { get; set; } //Este es nullable ya que se puede dar el caso de que un pedido se haya creado desde una cotización (sin plantilla) public OrderTemplate Template { get; set; } public int ClientId { get; set; } [DisplayName("Cliente")] public Client Client { get; set; } public int BranchId { get; set; } //Sucursal de entrega [DisplayName("Sucursal")] public ClientBranch Branch { get; set; } [DisplayName("Fecha de Entrega")] public DateTime DeliveryDate { get; set; } //No se usa [DisplayName("Subtotal")] public decimal Subtotal { get; set; } [DisplayName("Total")] public decimal Total { get; set; } [DisplayName("Estatus de Entrega")] public DeliveryStatus DeliveryStatus { get; set; } [DisplayName("Factura")] [NotMapped] public string InvoiceStatus { get; set; } public int? InvoiceId { get; set; } public Cfdi Invoice { get; set; } //public int? ProofOfPaymentId { get; set; } //public Cfdi ProofOfPayment { get; set; } [DisplayName("Complemento de Pago")] public string ProofOfPaymentStatus { get { return null; } } [DisplayName("Estatus de Pago")] public PaymentStatus PaymentStatus { get; set; } [DisplayName("Feche Pago Programada")] public DateTime? PromisedPaymentDate { get; set; } [DisplayName("Fecha Pago Real")] public DateTime? ActualPaymentDate { get; set; } public List Products { get; set; } //El descuento se calcula en base al total sin impuestos (cantidad * precio) [DisplayName("Descuento")] public decimal? Discount { get; set; } [DisplayName("Tipo de descuento")] public DiscountType? DiscountType { get; set; } [DisplayName("Tiene descuento fijo")] public bool HasFixedDiscount { get; set; } public string Email { get; set; } [NotMapped] [DisplayName("Tiene precios fijos")] public bool HasFixedPrices { get { return Products?.Any(x => x.FixedPrice != null) ?? false; } } [DoNotUpdate] public int? CanceledById { get; set; } [DoNotUpdate] [DisplayName("Cancelado por")] public User CanceledBy { get; set; } [NotMapped] public int TotalRows { get; set; } public decimal? IvaTotal { get; set; } public decimal? IepsTotal { get; set; } public int? AccessedById { get; set; } [NotMapped] public string AccessedBy { get; set; } public DateTime? LastAccessed { get; set; } //Usado en los pedidos de restaurantes para los pedidos hechos con proveedores locales //No se usan constraints aquí [IgnoreRelationship] public int? SupplierId { get; set; } //Usado para saber de que plantilla general viene este pedido, este valor es 0 para indicar que //es una plantilla general, y mayor a 0 para indicar que es una plantilla general de proveedor //No se usan constraints aqui [IgnoreRelationship] public int? TemplateSupplierId { get; set; } ////Usado en los pedidos de restaurantes para los pedidos hechos con proveedores locales, se guarda en la base de datos //public string SupplierName { get; set; } ////Usado en los pedidos de restaurantes para los pedidos hechos con proveedores locales, se guarda en la base de datos //public string SupplierLegalName { get; set; } public string Comments { get; set; } [NotMapped] public OrderAllowedDates AllowedDates { get; set; } public bool IsAccessExpired { get { if (LastAccessed == null) return false; return (DateTime.UtcNow - LastAccessed.Value) > TimeSpan.FromMinutes(5); } } } public class TableClientOrder : RepositoryEntity { [DisplayName("Folio")] public string Folio { get => NumFolio.ToString().PadLeft(4, '0') + (IsVerified ? " (P)" : ""); } public int NumFolio { get; set; } [DisplayName("Marca")] public string Brand { get; set; } [DisplayName("Sucursal")] public string Branch { get; set; } //Este no se guarda en la base de datos, se toma del proveedor [DisplayName("Nombre Comercial Proveedor")] public string Name { get; set; } //Este no se guarda en la base de datos, se toma del proveedor [DisplayName("Razón Social Proveedor")] public string LegalName { get; set; } [DisplayName("Fecha de entrega")] public DateTime DeliveryDate { get; set; } [DisplayName("Monto Total")] public decimal Total { get; set; } [DisplayName("Estatus de Entrega")] public DeliveryStatus DeliveryStatus { get; set; } [DisplayName("Factura")] public string InvoiceStatus { get; set; } public int? InvoiceId { get; set; } [DisplayName("Estatus de Pago")] public PaymentStatus PaymentStatus { get; set; } [DisplayName("Fecha Pago Programada")] public DateTime? PromisedPaymentDate { get; set; } [DisplayName("Fecha Pago Real")] public DateTime? ActualPaymentDate { get; set; } [DisplayName("Cancelado por")] public string CanceledByName { get; set; } [DisplayName("Creado")] public DateTime Created { get; set; } [DisplayName("Creado por")] public string CreatedByName { get; set; } [DisplayName("Modificado")] public DateTime Modified { get; set; } [DisplayName("Modificado por")] public string ModifiedByName { get; set; } [DisplayName("Descuento")] public decimal? Discount { get; set; } [DisplayName("Tipo de descuento")] public DiscountType? DiscountType { get; set; } public int? CanceledById { get; set; } [JsonIgnore] public string ModifiedByTenantId { get; set; } [JsonIgnore] public string CreatedByTenantId { get; set; } [JsonIgnore] public string CanceledTenantId { get; set; } public string SupplierName { get; set; } public string SupplierLegalName { get; set; } public bool IsActive { get; set; } public int TotalRows { get; set; } public bool IsVerified { get; set; } } public class TableOrder : RepositoryEntity { [DisplayName("Folio")] public string Folio { get => NumFolio.ToString().PadLeft(4, '0'); } public int NumFolio { get; set; } public int ClientId { get; set; } [DisplayName("Cliente")] public string ClientName { get; set; } [DisplayName("Marca")] public string BrandName { get; set; } [DisplayName("Sucursal")] public string BranchName { get; set; } public string TaxPayerIdNo { get; set; } public string TaxPayerPaymentMethod { get; set; } public string TaxPayerPaymentForm { get; set; } public string TaxPayerUsoCfdi { get; set; } [DisplayName("Fecha de entrega")] public DateTime DeliveryDate { get; set; } [DisplayName("Total")] public decimal Total { get; set; } [DisplayName("Estatus de Entrega")] public DeliveryStatus DeliveryStatus { get; set; } [DisplayName("Factura")] public string InvoiceStatus { get; set; } public int? InvoiceId { get; set; } [DisplayName("Estatus de Pago")] public PaymentStatus PaymentStatus { get; set; } [DisplayName("Fecha promesa de pago")] public DateTime? PromisedPaymentDate { get; set; } [DisplayName("Fecha real de pago")] public DateTime? ActualPaymentDate { get; set; } [DisplayName("Creado")] public DateTime Created { get; set; } [DisplayName("Modificado")] public DateTime Modified { get; set; } [DisplayName("Descuento")] public decimal? Discount { get; set; } [DisplayName("Tipo de descuento")] public DiscountType? DiscountType { get; set; } public int? CanceledById { get; set; } [DisplayName("Cancelado")] public string CanceledByName { get; set; } [DisplayName("Creado por")] public string CreatedByName { get; set; } [DisplayName("Modificado por")] public string ModifiedByName { get; set; } public bool IsActive { get; set; } public int TotalRows { get; set; } public bool IsVerified { get; set; } } //public class TableOrderProduct //{ // public int Id { get; set; } // public decimal Qty { get; set; } // public decimal SalePrice { get; set; } // public decimal Iva { get; set; } // public decimal Ieps { get; set; } //} public class OrderProduct : RepositoryEntityWithTenantId { public int OrderId { get; set; } public int ProductId { get; set; } public Product Product { get; set; } public decimal Qty { get; set; } public decimal? FixedPrice { get; set; } [MaxLength(300)] public string Specification { get; set; } public decimal Subtotal { get; set; } //Propiedades para congelar los datos del producto al momento de crear el pedido //Para congelar la ausencia de valor en IVA o IEPS (por ejemplo un producto que no tiene IVA), se usa 0 public decimal? SupplierCost { get; set; } public decimal? SalePrice { get; set; } public decimal? Iva { get; set; } public decimal? Ieps { get; set; } } public class TaxCalculations { public string Type { get; set; } public decimal Value { get; set; } public decimal Pc { get; set; } } public class ProductCalculations { public OrderProduct Product { get; set; } public decimal Discount { get; set; } public decimal Price { get; set; } public decimal Subtotal { get; set; } public decimal Iva { get; set; } public decimal IvaPc { get; set; } public decimal Ieps { get; set; } public decimal IepsPc { get; set; } public decimal Taxes { get; set; } } public class OrderCalculations { public decimal Total { get; set; } public decimal Discount { get; set; } public decimal Subtotal { get; set; } public TaxCalculations[] Taxes { get; set; } public decimal TotalIva { get; set; } public decimal TotalIeps { get; set; } public decimal TotalTaxes { get; set; } public ProductCalculations[] Products { get; set; } } public class PrintableOrder { public Order Order { get; set; } public OrderCalculations Totals { get; set; } public string LogoImage { get; set; } } //public class OrderBranch : RepositoryEntityWithTenantId //{ // public int OrderId { get; set; } // public int BranchId { get; set; } // public ClientBranch Branch { get; set; } //} public enum DeliveryStatus { [Display(Name = "Pendiente")] Pending = 0, [Display(Name = "En Ruta")] InRoute = 1, [Display(Name = "Entregado")] Delivered = 2, [Display(Name = "Solicitado")] Requested = 3, [Display(Name = "Rechazado")] Rejected = 4 } public enum PaymentStatus { [Display(Name = "Pendiente")] Pending = 0, [Display(Name = "Pagado")] Paid = 1, [Display(Name = "Pendiente Parcial")] PartiallyPaid = 2, [Display(Name = "Vencido")] Due = 3 } }