From 01eecd707dfb5d95b98d911db5d7c533eb506d55 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 27 Feb 2025 09:58:39 +0100 Subject: [PATCH 1/3] Michele: Model vtMAgNew + dbcontext e dbset Vt_magnew VtSaldiart + modifiche polo controller, aggiunti chiamata api Vt_mag new list e modifiche a chiamate/chiudi e saldi articolo --- ApiPolo/Controllers/PoloController.cs | 291 ++++++++++++++---- .../VT_dbcontext/VT_MAG_NEW_DbContext.cs | 25 ++ .../VT_dbcontext/VT_SALDIART_DbContext.cs | 19 ++ ApiPolo/Models/Vt_Mag_New.cs | 34 ++ ApiPolo/Startup.cs | 7 + 5 files changed, 320 insertions(+), 56 deletions(-) create mode 100644 ApiPolo/Models/VT_dbcontext/VT_MAG_NEW_DbContext.cs create mode 100644 ApiPolo/Models/VT_dbcontext/VT_SALDIART_DbContext.cs create mode 100644 ApiPolo/Models/Vt_Mag_New.cs diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index 471795a..b822295 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -52,6 +52,7 @@ using System.Linq; using Microsoft.Extensions.Primitives; using System.Text.RegularExpressions; using System.Runtime.CompilerServices; +using System.Diagnostics; namespace ApiPolo.Controllers { @@ -459,6 +460,10 @@ namespace ApiPolo.Controllers private readonly VT_ARTICOLI_TABLE_DbContext _VT_articoliTable; #endregion + #region VT-MAG_NEW + private readonly VT_MAG_NEW_DbContext _VT_MagNew; + #endregion + #region Commesse desc private readonly SIET_COMMESSE_DESC_DbContext _Siet_commDesc; private readonly MARRO_COMMESSE_TABLE_DbContext _Marro_commDesc; @@ -511,6 +516,7 @@ namespace ApiPolo.Controllers private DbSet? _VT_buo; private DbSet? _rapp_new_view; private DbSet? _articoliTable; + private DbSet? _magNewVT; private DbSet? _commDesc; private DbSet? _commDescSiet; @@ -880,8 +886,11 @@ namespace ApiPolo.Controllers VT_Buoni_DbContext VT_Buoni, VT_STO_RAPP_DbContext VT_StoRapp, VT_TIMBRATURE_DbContext VT_timbr, - VT_ARTICOLI_TABLE_DbContext VT_artTable + VT_ARTICOLI_TABLE_DbContext VT_artTable, + VT_MAG_NEW_DbContext VT_MagNew + #endregion + ) { _configuration = configuration; @@ -1226,6 +1235,7 @@ namespace ApiPolo.Controllers _VT_Buoni = VT_Buoni; _VT_StoRapp = VT_StoRapp; _VT_articoliTable = VT_artTable; + _VT_MagNew = VT_MagNew; #endregion #region Commesse desc @@ -1879,6 +1889,7 @@ namespace ApiPolo.Controllers } return _sa; } + private DbSet getComponentiByTenant(string tenant) { DbSet? _compon; @@ -3040,6 +3051,28 @@ namespace ApiPolo.Controllers return mn; } + /// trasforma un Saldiart in un Vt_Mag_New + private Vt_Mag_New SaldiArtToVtMag_New(Saldiart co, int riga, string newSerial, string tecnico, string azienda) + { + Vt_Mag_New vtmn = new Vt_Mag_New(); + vtmn.Azienda = azienda; + vtmn.Seriale_Rapportino = newSerial; + vtmn.Riga = riga; + vtmn.Magazzino = co.slcodmag; + vtmn.Articolo = co.slcodice; + vtmn.Tipo_Movimento = "A"; + vtmn.Quantita = co.slqtaper; + vtmn.Prezzo = co.liprezzo; + vtmn.Codice_Tecnico = tecnico; + vtmn.CodLotto = co.locodice; + vtmn.Matricola = co.amcodice; + vtmn.Desc_Art = co.ardesart; + vtmn.Cpccchk = getCpccchk(10); + vtmn.Desc_Sup = co.desc_sup; + return vtmn; + + } + /// trasforma un Compi_Impia in un Mag_New private Mag_New compo_ImpiaToMag_New(Compo_Impia co, int riga, string newSerial, string tecnico) { @@ -3068,6 +3101,35 @@ namespace ApiPolo.Controllers return mn; } + /// trasforma un Compi_Impia in un Vt_Mag_New + private Vt_Mag_New compo_ImpiaToVt_Mag_New(Compo_Impia co, int riga, string newSerial, string tecnico, string azienda) + { + + Vt_Mag_New vtmn = new Vt_Mag_New(); + vtmn.Azienda = azienda; + vtmn.Seriale_Rapportino = newSerial; + vtmn.Riga = riga; + vtmn.Matricola = "001"; + vtmn.Articolo = co.cocodart; + vtmn.Tipo_Movimento = "E"; + vtmn.Quantita = co.coqtaart; + vtmn.Prezzo = 0; + vtmn.Codice_Tecnico = tecnico; + vtmn.CodLotto = co.lotto; + vtmn.Matricola = co.matricola; + vtmn.Cprownum = co.cprownum; + vtmn.CodImp = co.cocodimp; + vtmn.Desc_Art = co.ardesart; + vtmn.Cpccchk = getCpccchk(10); + vtmn.Desc_Sup = co.desc_sup; + + + string appoNote = string.Empty; + appoNote = (co.co__note != null && co.co__note.Length>254) ? co.co__note.Substring(0, 254) : co.co__note; + vtmn.Note = appoNote; + return vtmn; + } + private static Random random = new Random(); /// crea un cpccchk public static string getCpccchk(int length) @@ -6296,6 +6358,39 @@ namespace ApiPolo.Controllers await _VT_rapptable.SaveChangesAsync(); transactionVT.Commit(); } + riga = 0; + if (model.compo_add != null && model.compo_add.Count() > 0) + { + using (var transactionVT2 = _VT_rapptable.Database.BeginTransaction()) + { + foreach (Saldiart co in model.compo_add) + { + Vt_Mag_New vtmn = new Vt_Mag_New(); + riga = riga + 1; + vtmn = SaldiArtToVtMag_New(co, riga, newSerial, tecnico, ten2); + + await _VT_MagNew.MagNewVt.AddAsync(vtmn); + await _VT_MagNew.SaveChangesAsync(); + } + transactionVT2.Commit(); + } + } + if (model.compo_del != null && model.compo_del.Count() > 0) + { + using (var transactionVt3 = _VT_rapptable.Database.BeginTransaction()) + { + foreach (Compo_Impia co in model.compo_del) + { + Vt_Mag_New vtmn = new Vt_Mag_New(); + riga = riga + 1; + vtmn = compo_ImpiaToVt_Mag_New(co, riga, newSerial, tecnico, ten2); + + await _VT_MagNew.MagNewVt.AddAsync(vtmn); + await _VT_MagNew.SaveChangesAsync(); + } + transactionVt3.Commit(); + } + } break; case Clienti.LW: @@ -8703,70 +8798,129 @@ namespace ApiPolo.Controllers try { string ten = getClaimValueByToken(token, "tenant"); + string ten2 = getClaimValueByToken(token, "tenant2"); string tenConf = getClaimValueByToken(token, "tenantConfigurazioni"); - _saldi = getSaldiartByTenant(ten); - Configurazioni conf = await readConf(tenConf); - int max_record = 0; - max_record = conf.max_record!=null? conf.max_record.Value:0; - string codlis = string.Empty; - _clienti = getClientiByTenant(ten); - var a = await _clienti.Where(t => t.ancodice == codcli).ToListAsync(); - if (a != null && a.Count() == 0) + if (tenConf.Equals(Clienti.VT)) { - codlis = conf.listino; + _articoliTable = _VT_articoliTable.Articoli; + + var listaFiltro = new List(); + + listaFiltro = await _articoliTable.Where(x => x.Azienda.Equals(ten2)).ToListAsync(); + + if (!string.IsNullOrEmpty(art)) + { + listaFiltro = await _articoliTable.Where(x => x.SlCodice.Contains(art)).ToListAsync(); + } + + if (!string.IsNullOrEmpty(desart)) + { + listaFiltro = await _articoliTable.Where(x => x.ArDesArt.Contains(desart)).ToListAsync(); + } + + if (!string.IsNullOrEmpty(maga)) + { + listaFiltro = await _articoliTable.Where(x => x.SlCodMag.Contains(maga)).ToListAsync(); + } + + List listaSaldiArt = new List(); + + foreach (Articoli a in listaFiltro) + { + Saldiart saldo = new Saldiart(); + + saldo.slcodice = a.SlCodice; + saldo.slcodice = a.SlCodice; + saldo.ardesart = a.ArDesArt; + saldo.slcodmag = a.SlCodMag; + saldo.slqtaper = a.SlQtAper; + saldo.amcodice = a.AmCodice; + saldo.locodice = a.LoCodice; + saldo.licodlis = a.LiCodLis; + saldo.licodart = a.LiCodArt; + saldo.lidatatt = a.LiDatAtt; + saldo.liquanti = a.LiQuanti; + saldo.liprezzo = a.LiPrezzo; + saldo.liscont1 = a.LiScont1; + saldo.liscont2 = a.LiScont2; + saldo.liscont3 = a.LiScont3; + saldo.liscont4 = a.LiScont4; + saldo.gest_matr = a.Gest_Matr; + saldo.gest_lotti = a.Gest_Lotti; + saldo.desc_sup = a.Desc_sup; + + listaSaldiArt.Add(saldo); + } + + return StatusCode(StatusCodes.Status200OK, listaFiltro); } else { - codlis = string.IsNullOrEmpty(a.First().annumlis) ? conf.listino : a.First().annumlis; - } - var co = await _saldi.Where(t => t.slcodmag != null && t.slcodmag.Equals(maga) && t.licodlis != null && t.licodlis.Equals(codlis)).ToListAsync(); - - if (!string.IsNullOrEmpty(art)) - { - co = co.Where(t => t.slcodice != null && t.slcodice.ToUpper().Contains(art.ToUpper())).ToList(); - } - if (!string.IsNullOrEmpty(desart)) - { - co = co.Where(t => t.ardesart != null && t.ardesart.ToUpper().Contains(desart.ToUpper())).ToList(); - } - if (!string.IsNullOrEmpty(matric)) - { - //List lista = new List(); - //var codart = co.Where(m => m.amcodice != null && m.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); - //var query = co.Where(p => codart.Any(kw => p..StartsWith(kw))); - //if (codart != null && codart.Count() > 0) - //{ - // foreach(Saldiart sa in codart) - // { - // string artTrovato = sa.slcodice; - // co= co.Where(t => t.slcodice != null && t.slcodice.ToUpper().Contains(artTrovato.ToUpper()) - // && t.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); - // } - //} - //else - //{ - // // devo svuotare l'elenco articoli - // co = co.Take(0).ToList(); - //} - co = co.Where(t => t.amcodice != null && t.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); - - } - //2024-02-19: se l'articolo è gestito a matricole, la query restituisce tutte le righe splittate, - //in questo caso forzo la quantità a 1 - if (co != null && co.Count() > 0) - { - foreach (Saldiart s in co) + _saldi = getSaldiartByTenant(ten); + Configurazioni conf = await readConf(tenConf); + int max_record = 0; + max_record = conf.max_record != null ? conf.max_record.Value : 0; + string codlis = string.Empty; + _clienti = getClientiByTenant(ten); + var a = await _clienti.Where(t => t.ancodice == codcli).ToListAsync(); + if (a != null && a.Count() == 0) { - if (s.gest_matr!=null && s.gest_matr.Equals("S")) - { - s.slqtaper = 1; - } - + codlis = conf.listino; } + else + { + codlis = string.IsNullOrEmpty(a.First().annumlis) ? conf.listino : a.First().annumlis; + } + var co = await _saldi.Where(t => t.slcodmag != null && t.slcodmag.Equals(maga) && t.licodlis != null && t.licodlis.Equals(codlis)).ToListAsync(); + + if (!string.IsNullOrEmpty(art)) + { + co = co.Where(t => t.slcodice != null && t.slcodice.ToUpper().Contains(art.ToUpper())).ToList(); + } + if (!string.IsNullOrEmpty(desart)) + { + co = co.Where(t => t.ardesart != null && t.ardesart.ToUpper().Contains(desart.ToUpper())).ToList(); + } + if (!string.IsNullOrEmpty(matric)) + { + //List lista = new List(); + //var codart = co.Where(m => m.amcodice != null && m.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); + //var query = co.Where(p => codart.Any(kw => p..StartsWith(kw))); + //if (codart != null && codart.Count() > 0) + //{ + // foreach(Saldiart sa in codart) + // { + // string artTrovato = sa.slcodice; + // co= co.Where(t => t.slcodice != null && t.slcodice.ToUpper().Contains(artTrovato.ToUpper()) + // && t.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); + // } + //} + //else + //{ + // // devo svuotare l'elenco articoli + // co = co.Take(0).ToList(); + //} + co = co.Where(t => t.amcodice != null && t.amcodice.ToUpper().Contains(matric.ToUpper())).ToList(); + + } + //2024-02-19: se l'articolo è gestito a matricole, la query restituisce tutte le righe splittate, + //in questo caso forzo la quantità a 1 + if (co != null && co.Count() > 0) + { + foreach (Saldiart s in co) + { + if (s.gest_matr != null && s.gest_matr.Equals("S")) + { + s.slqtaper = 1; + } + + } + } + co = co.Take(max_record).ToList(); + return StatusCode(StatusCodes.Status200OK, co); } - co = co.Take(max_record).ToList(); - return StatusCode(StatusCodes.Status200OK, co); + } catch (Exception ex) { @@ -15561,6 +15715,31 @@ namespace ApiPolo.Controllers } } + /// VIRTUAL TASK: lista mag_new per azienda + [HttpGet("VTMagNewList")] + public async Task>> VTMagNewList(string token) + { + try + { + List mnlist = new List(); + string ten = getClaimValueByToken(token, "tenant2"); + string tecnico = getClaimValueByToken(token, "tccodice"); + _magNewVT = _VT_MagNew.MagNewVt; + + var listaMn = await _magNewVT.Where(x => x.Azienda.Equals(ten)).ToListAsync(); + foreach (Vt_Mag_New mg in listaMn) + { + mnlist.Add(mg); + } + return StatusCode(StatusCodes.Status200OK, mnlist); + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, err); ; + } + } + #endregion #region Logging diff --git a/ApiPolo/Models/VT_dbcontext/VT_MAG_NEW_DbContext.cs b/ApiPolo/Models/VT_dbcontext/VT_MAG_NEW_DbContext.cs new file mode 100644 index 0000000..967266a --- /dev/null +++ b/ApiPolo/Models/VT_dbcontext/VT_MAG_NEW_DbContext.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace ApiPolo.Models.VT_dbcontext +{ + public class VT_MAG_NEW_DbContext : DbContext + { + public DbSet MagNewVt { get; set; } + + public VT_MAG_NEW_DbContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("MAG_NEW_VT"); + modelBuilder.Entity() + .HasKey(Table => new { + Table.Azienda, + Table.Seriale_Rapportino, + Table.Riga + }); + } + } +} diff --git a/ApiPolo/Models/VT_dbcontext/VT_SALDIART_DbContext.cs b/ApiPolo/Models/VT_dbcontext/VT_SALDIART_DbContext.cs new file mode 100644 index 0000000..fa2b70c --- /dev/null +++ b/ApiPolo/Models/VT_dbcontext/VT_SALDIART_DbContext.cs @@ -0,0 +1,19 @@ +using ApiPolo.Models.PMS_dbcontext; +using Microsoft.EntityFrameworkCore; + +namespace ApiPolo.Models.VT_dbcontext +{ + public class VT_SALDIART_DbContext : DbContext + { + public DbSet? SaldiArt_VT { get; set; } + + public VT_SALDIART_DbContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_SALDIART_PREZZI"); + } + } +} diff --git a/ApiPolo/Models/Vt_Mag_New.cs b/ApiPolo/Models/Vt_Mag_New.cs new file mode 100644 index 0000000..98317b6 --- /dev/null +++ b/ApiPolo/Models/Vt_Mag_New.cs @@ -0,0 +1,34 @@ +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace ApiPolo.Models +{ + public class Vt_Mag_New + { + [Key] + [Required] + public string Azienda { get; set; } + [Key] + [Required] + public string Seriale_Rapportino { get; set; } + [Key] + [Required] + public int Riga { get; set; } + public string Magazzino { get; set; } + public string Articolo { get; set; } + public string Tipo_Movimento { get; set; } + public decimal? Quantita { get; set; } + public decimal? Prezzo { get; set; } + public string Codice_Tecnico { get; set; } + public string Generato { get; set; } + public string Note { get; set; } + public string CodLotto { get; set; } + public string Matricola { get; set; } + public int? Cprownum { get; set; } + public string Desc_Art { get; set; } + public string CodImp { get; set; } + public string Desc_Sup { get; set; } + public string? Cpccchk { get; set; } + + } +} diff --git a/ApiPolo/Startup.cs b/ApiPolo/Startup.cs index 046c40d..c20ac76 100644 --- a/ApiPolo/Startup.cs +++ b/ApiPolo/Startup.cs @@ -752,6 +752,13 @@ namespace ApiPolo services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); + #endregion #region LIFT_WEB From 47d479ca7e2a3fd70951a4fa3c0ed68b4d546393 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 27 Feb 2025 09:59:12 +0100 Subject: [PATCH 2/3] michele:aggiunti commenti --- ApiPolo/Controllers/PoloController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index b822295..01c1b03 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -6358,6 +6358,7 @@ namespace ApiPolo.Controllers await _VT_rapptable.SaveChangesAsync(); transactionVT.Commit(); } + // 27/02/2025 agggiunta gestione Vt_MagNew riga = 0; if (model.compo_add != null && model.compo_add.Count() > 0) { @@ -8801,6 +8802,7 @@ namespace ApiPolo.Controllers string ten2 = getClaimValueByToken(token, "tenant2"); string tenConf = getClaimValueByToken(token, "tenantConfigurazioni"); + //27/02/2025 aggiunta gestione Articoli if (tenConf.Equals(Clienti.VT)) { _articoliTable = _VT_articoliTable.Articoli; From 9bb354e1075379136eb7fd0500bcc29df248d790 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 27 Feb 2025 16:13:20 +0100 Subject: [PATCH 3/3] Michele: metodi crud per MagazziniVT e messo controllo in Login (magazzini) per magazziniVT --- ApiPolo/Controllers/PoloController.cs | 153 ++++++++++++++++-- ApiPolo/Models/MagazziniVT.cs | 29 ++++ .../VT_dbcontext/VT_MAGAZZINI_DbContext.cs | 25 +++ ApiPolo/Startup.cs | 3 + 4 files changed, 194 insertions(+), 16 deletions(-) create mode 100644 ApiPolo/Models/MagazziniVT.cs create mode 100644 ApiPolo/Models/VT_dbcontext/VT_MAGAZZINI_DbContext.cs diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index f17caa9..faf6e77 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -464,6 +464,10 @@ namespace ApiPolo.Controllers private readonly VT_MAG_NEW_DbContext _VT_MagNew; #endregion + #region VT-MAGAZZINI + private readonly VT_MAGAZZINI_DbContext _VT_Magazzini; + #endregion + #region Commesse desc private readonly SIET_COMMESSE_DESC_DbContext _Siet_commDesc; private readonly MARRO_COMMESSE_TABLE_DbContext _Marro_commDesc; @@ -517,6 +521,7 @@ namespace ApiPolo.Controllers private DbSet? _rapp_new_view; private DbSet? _articoliTable; private DbSet? _magNewVT; + private DbSet? _magazziniVT; private DbSet? _commDesc; private DbSet? _commDescSiet; @@ -887,7 +892,8 @@ namespace ApiPolo.Controllers VT_STO_RAPP_DbContext VT_StoRapp, VT_TIMBRATURE_DbContext VT_timbr, VT_ARTICOLI_TABLE_DbContext VT_artTable, - VT_MAG_NEW_DbContext VT_MagNew + VT_MAG_NEW_DbContext VT_MagNew, + VT_MAGAZZINI_DbContext VT_Magazzini #endregion @@ -1236,6 +1242,7 @@ namespace ApiPolo.Controllers _VT_StoRapp = VT_StoRapp; _VT_articoliTable = VT_artTable; _VT_MagNew = VT_MagNew; + _VT_Magazzini = VT_Magazzini; #endregion #region Commesse desc @@ -3861,8 +3868,7 @@ namespace ApiPolo.Controllers [HttpGet("magazzini")] public async Task>> magazzini(string token) { - - List < Magazzini > lst= new List(); + List lst= new List(); string ten = getClaimValueByToken(token, "tenant"); string ten2 = getClaimValueByToken(token, "tenant2"); string tenAdhoc = getClaimValueByToken(token, "tenantConfigurazioni"); @@ -3874,6 +3880,19 @@ namespace ApiPolo.Controllers if (ten.Equals(Clienti.VT)) { + _magazziniVT = _VT_Magazzini.Magazzini; + + List magaVTList = new List(); + magaVTList = await _magazziniVT.Where(x => x.Azienda.Equals(ten2)).ToListAsync(); + + foreach (var magVT in magaVTList) + { + Magazzini maga = new Magazzini(); + maga.mgcodmag = magVT.Mgcodmag.TrimEnd(); + maga.mgdesmag = magVT.Mgdesmag.TrimEnd(); + + lst.Add(maga); + } return lst; } else @@ -6350,7 +6369,6 @@ namespace ApiPolo.Controllers } } break; - case Clienti.VT: using (var transactionVT = _VT_rapptable.Database.BeginTransaction()) { @@ -8832,15 +8850,14 @@ namespace ApiPolo.Controllers { Saldiart saldo = new Saldiart(); - saldo.slcodice = a.SlCodice; - saldo.slcodice = a.SlCodice; - saldo.ardesart = a.ArDesArt; - saldo.slcodmag = a.SlCodMag; + saldo.slcodice = a.SlCodice.TrimEnd(); + saldo.ardesart = a.ArDesArt.TrimEnd(); + saldo.slcodmag = a.SlCodMag.TrimEnd(); saldo.slqtaper = a.SlQtAper; - saldo.amcodice = a.AmCodice; - saldo.locodice = a.LoCodice; - saldo.licodlis = a.LiCodLis; - saldo.licodart = a.LiCodArt; + saldo.amcodice = a.AmCodice.TrimEnd(); + saldo.locodice = a.LoCodice.TrimEnd(); + saldo.licodlis = a.LiCodLis.TrimEnd(); + saldo.licodart = a.LiCodArt.TrimEnd(); saldo.lidatatt = a.LiDatAtt; saldo.liquanti = a.LiQuanti; saldo.liprezzo = a.LiPrezzo; @@ -8848,10 +8865,10 @@ namespace ApiPolo.Controllers saldo.liscont2 = a.LiScont2; saldo.liscont3 = a.LiScont3; saldo.liscont4 = a.LiScont4; - saldo.gest_matr = a.Gest_Matr; - saldo.gest_lotti = a.Gest_Lotti; - saldo.desc_sup = a.Desc_sup; - + saldo.gest_matr = a.Gest_Matr.TrimEnd(); + saldo.gest_lotti = a.Gest_Lotti.TrimEnd(); + saldo.desc_sup = a.Desc_sup.TrimEnd(); + listaSaldiArt.Add(saldo); } @@ -15793,6 +15810,110 @@ namespace ApiPolo.Controllers } } + /// VIRTUAL TASK: lista Magazzini per azienda + [HttpGet("magazziniVTList")] + public async Task>> MagazziniVTList(string token) + { + try + { + List maglist = new List(); + string ten = getClaimValueByToken(token, "tenant2"); + string tecnico = getClaimValueByToken(token, "tccodice"); + _magazziniVT = _VT_Magazzini.Magazzini; + + var magazziniList = await _magazziniVT.Where(x => x.Azienda.Equals(ten)).ToListAsync(); + foreach (MagazziniVT magaz in magazziniList) + { + maglist.Add(magaz); + } + return StatusCode(StatusCodes.Status200OK, maglist); + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, err); ; + } + } + + /// VIRTUAL TASK : crea nuovo magazzino return: ActionResult + [HttpPost] + [Route("magazziniVT/add")] + public async Task> addMagazzinoVT([FromBody] MagazziniVT model, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + model.Azienda = ten; + try + { + using (var transaction = _VT_Magazzini.Database.BeginTransaction()) + { + await _VT_Magazzini.Magazzini.AddAsync(model); + await _VT_Magazzini.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); ; + } + } + + /// VIRTUAL TASK : modifica magazzino return: ActionResult + [HttpPost] + [Route("magazziniVT/mod")] + public async Task> modMagazzino([FromBody] MagazziniVT model, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + model.Azienda = ten; + + try + { + using (var transaction = _VT_Magazzini.Database.BeginTransaction()) + { + _VT_Magazzini.Entry(model).State = EntityState.Modified; + await _VT_Magazzini.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); + } + } + + /// VIRTUAL TASK: cancella un magazzino return:ActionResult + [HttpPost] + [Route("magazziniVT/del")] + public async Task> delMagazzino(string magCodice, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + _magazziniVT = _VT_Magazzini.Magazzini; + var art = await _magazziniVT.Where(a => a.Mgcodmag.Equals(magCodice) && a.Azienda.Equals(ten)).ToListAsync(); + + MagazziniVT model = art.First(); + model.DataObso = DateTime.Now; + + try + { + using (var transaction = _VT_Magazzini.Database.BeginTransaction()) + { + _VT_Magazzini.Entry(model).State = EntityState.Modified; + await _VT_Magazzini.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); + } + } + #endregion #region Logging diff --git a/ApiPolo/Models/MagazziniVT.cs b/ApiPolo/Models/MagazziniVT.cs new file mode 100644 index 0000000..a989d50 --- /dev/null +++ b/ApiPolo/Models/MagazziniVT.cs @@ -0,0 +1,29 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApiPolo.Models +{ + public class MagazziniVT + { + /// + /// Azienda + /// + [Key] + public string? Azienda { get; set; } + + /// + /// codice magazzino + /// + [Key] + public string? Mgcodmag { get; set; } + + /// + /// descrizione + /// + public string? Mgdesmag { get; set; } + + /// + /// descrizione + /// + public DateTime? DataObso { get; set; } + } +} diff --git a/ApiPolo/Models/VT_dbcontext/VT_MAGAZZINI_DbContext.cs b/ApiPolo/Models/VT_dbcontext/VT_MAGAZZINI_DbContext.cs new file mode 100644 index 0000000..4b81a3e --- /dev/null +++ b/ApiPolo/Models/VT_dbcontext/VT_MAGAZZINI_DbContext.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiPolo.Models.VT_dbcontext +{ + public class VT_MAGAZZINI_DbContext :DbContext + { + public DbSet Magazzini { get; set; } + + + public VT_MAGAZZINI_DbContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("MAGAZZINI"); + modelBuilder.Entity().HasKey(Table => new + { + Table.Azienda, + Table.Mgcodmag + }); // Definizione della chiave primaria composta + //base.OnModelCreating(modelBuilder); + } + } +} diff --git a/ApiPolo/Startup.cs b/ApiPolo/Startup.cs index c20ac76..20d2a89 100644 --- a/ApiPolo/Startup.cs +++ b/ApiPolo/Startup.cs @@ -758,6 +758,9 @@ namespace ApiPolo services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); #endregion