using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using Newtonsoft.Json; using tsUtilidades.Extensiones; namespace bdGrupoSanchoToro.db { public partial class facturas { [NotMapped] public virtual string RazonSocialEmpresa { get { if (this.idSerieFacturaNavigation == null) { return ""; } else { return this.idSerieFacturaNavigation.idEmpresaNavigation.RazonSocial; } } } [NotMapped] public virtual string DomicilioEmpresa { get { if (this.idSerieFacturaNavigation == null) { return ""; } else { return this.idSerieFacturaNavigation.idEmpresaNavigation.Domicilio; } } } [NotMapped] public virtual string PoblacionEmpresa { get { if (this.idSerieFacturaNavigation == null) { return ""; } else { return this.idSerieFacturaNavigation.idEmpresaNavigation.Poblacion; } } } [NotMapped] public virtual string CIFEmpresa { get { if (this.idSerieFacturaNavigation == null) { return ""; } else { return this.idSerieFacturaNavigation.idEmpresaNavigation.CIF; } } } [NotMapped] public virtual int? idSerieFactura_Nulable { get { if (this.idSerieFactura == 0) { return default; } else { return this.idSerieFactura; } } set { if (value.HasValue) { this.idSerieFactura = value.Value; } // this.OnPropertyChanged("idSerieFactura_Nulable"); } } [NotMapped] public virtual int? idCliente_Nulable { get { if (this.idCliente == 0) { return default; } else { return this.idCliente; } } set { if (value.HasValue) { this.idCliente = value.Value; } // this.OnPropertyChanged("idCliente_Nulable"); } } //[NotMapped] //public virtual double ImportePagado //{ // get // { // if (this.movimientoscaja.Any()) // { // return this.movimientoscaja.Sum(x => x.Importe); // } // else // { // return 0d; // } // } //} //[NotMapped] //public virtual DateTime? FechaPago //{ // get // { // if (ImportePendiente == 0d & this.movimientoscaja.Any()) // { // return this.movimientoscaja.OrderByDescending(x => x.Fecha).First().Fecha; // } // else // { // return default; // } // } //} [NotMapped] public virtual double ImportePendiente { get { return Math.Round(this.TotalFactura - ImportePagado, 2, MidpointRounding.AwayFromZero); } } //public event PropertyChangedEventHandler? PropertyChanged; //protected void OnPropertyChanged([CallerMemberName] string name = null) //{ // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); //} public void EstableceNumeroFactura(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd) { seriesfacturas sf = this.idSerieFacturaNavigation; var ts = (bdGrupoSanchoToro.db.seriesfacturas.TipoSerieFacturaEnum)sf.Tipo; if (ts != bdGrupoSanchoToro.db.seriesfacturas.TipoSerieFacturaEnum.EMITIDA_POR_CLIENTE) { string serie = sf.Serie; if (ts == seriesfacturas.TipoSerieFacturaEnum.AUTOMÁTICA_CON_AÑO) serie += (this.FechaFactura.Year % 100).ToString(); serie += "/"; string sNumeroFactura; var bdtmp = tscGrupoSanchoToro.NuevoContexto(); var uf = bdtmp.facturas.Where(x => x.idSerieFactura == sf.idSerieFactura && x.NumeroFactura.StartsWith(serie)).OrderByDescending(x => x.NumeroFactura).FirstOrDefault(); int nf = 0; if (uf != null) nf = int.Parse(uf.NumeroFactura.Split("/")[1]); do { nf += 1; sNumeroFactura = serie + nf.ToString().PadLeft(sf.NumeroDigitos, '0'); } while (bdtmp.facturas.Any(X => X.NumeroFactura == sNumeroFactura && X.idSerieFactura == sf.idSerieFactura)); this.NumeroFactura = sNumeroFactura; } } public virtual string ListaNumeroRecibos { get { string sLista = ""; var mvs = this.movimientoscaja.OrderBy(x => x.Fecha).ThenBy(x => x.idMovimiento).ToList(); foreach (var m in mvs) sLista += m.NumeroRecibo + Environment.NewLine; return sLista; } } public virtual string ListaFechaPagoRecibos { get { string sLista = ""; var mvs = this.movimientoscaja.OrderBy(x => x.Fecha).ThenBy(x => x.idMovimiento).ToList(); foreach (var m in mvs) sLista += m.Fecha.ToString("dd/MM/yyyy") + Environment.NewLine; return sLista; } } public virtual string ListaFormaPago { get { string sLista = ""; var mvs = this.movimientoscaja.OrderBy(x => x.Fecha).ThenBy(x => x.idMovimiento).ToList(); foreach (var m in mvs) sLista += m.idCajaNavigation.Descripcion + Environment.NewLine; return sLista; } } public string ListaImporteRecibos { get { string sLista = ""; var mvs = this.movimientoscaja.OrderBy(x => x.Fecha).ThenBy(x => x.idMovimiento).ToList(); foreach (var m in mvs) sLista += m.Importe.ToString("c2") + Environment.NewLine; return sLista; } } [NotMapped] public virtual bool Marca_TMP { get; set; } [NotMapped] public virtual string? NIF_TMP { get; set; } [NotMapped] public virtual string? Obra_TMP { get; set; } [NotMapped] public virtual string? RazonSocial_TMP { get; set; } [NotMapped] public virtual string? Email_TMP { get; set; } [NotMapped] public virtual string? Email2_TMP { get; set; } [NotMapped] public virtual bool EnviarEmail_TMP { get; set; } #region Eventos [NotMapped] public string ProvinciaEvento { get { if (this.idEvento == null || this.idEventoNavigation.CodigoMunicipioNavigation == null) return ""; else return this.idEventoNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation.Nombre; } } [NotMapped] public string PoblacionEvento { get { if (this.idEvento == null || this.idEventoNavigation.CodigoMunicipioNavigation == null) return ""; else return this.idEventoNavigation.CodigoMunicipioNavigation.Nombre; } } [NotMapped] public string DireccionEvento { get { if (this.idEvento == null) return ""; else return this.idEventoNavigation.DireccionCompleta; } } #endregion public static void GuardandoCambios(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd, string Aplicacion, bool SuperUsuario = false) { //try //{ // var bdtmp = tscGrupoSanchoToro.NuevoContexto(); // var os = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize }; // var fras = bd.ChangeTracker.Entries().Where(x => x.State == Microsoft.EntityFrameworkCore.EntityState.Modified && x.Metadata.GetTableName() == "facturas"); // foreach (var e in fras) // { // var f = (facturas)e.Entity; // var reant = bdtmp.facturas.First(x => x.idFactura == f.idFactura); // var lr = bdGrupoSanchoToro.db.logs.GeneraLog(bdtmp, "FACTURAS", Aplicacion, reant.idFactura, null, "REGISTRO_COMPLETO", JsonConvert.SerializeObject(reant, os), SuperUsuario); // foreach (var it in f.detallesfacturas) // { // bdGrupoSanchoToro.db.logs.GeneraLog(bdtmp, "DETALLESFACTURAS", Aplicacion, reant.idFactura, lr, "REGISTRO_COMPLETO", JsonConvert.SerializeObject(it, os), SuperUsuario); // } // foreach (var it in f.movimientoscaja) // { // bdGrupoSanchoToro.db.logs.GeneraLog(bdtmp, "MOVIMIENTOSCAJA", Aplicacion, reant.idFactura, lr, "REGISTRO_COMPLETO", JsonConvert.SerializeObject(it, os), SuperUsuario); // } // foreach (var it in f.documentosfacturas) // { // bdGrupoSanchoToro.db.logs.GeneraLog(bdtmp, "DOCUMENTOSFACTURAS", Aplicacion, reant.idFactura, lr, "REGISTRO_COMPLETO", JsonConvert.SerializeObject(reant, os), SuperUsuario); // } // } //} //catch (Exception ex) //{ // Debug.WriteLine(ex.Message); //} } } }