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

This commit is contained in:
michele 2025-02-27 09:58:39 +01:00
parent e7a44e5682
commit 01eecd707d
5 changed files with 320 additions and 56 deletions

View File

@ -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<Buoni>? _VT_buo;
private DbSet<Rapp_New_View>? _rapp_new_view;
private DbSet<Articoli>? _articoliTable;
private DbSet<Vt_Mag_New>? _magNewVT;
private DbSet<CommessaDesc>? _commDesc;
private DbSet<CommessaDescSiet>? _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<Compo_Impia> getComponentiByTenant(string tenant)
{
DbSet<Compo_Impia>? _compon;
@ -3040,6 +3051,28 @@ namespace ApiPolo.Controllers
return mn;
}
/// <summary>trasforma un Saldiart in un Vt_Mag_New</summary>
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;
}
/// <summary>trasforma un Compi_Impia in un Mag_New</summary>
private Mag_New compo_ImpiaToMag_New(Compo_Impia co, int riga, string newSerial, string tecnico)
{
@ -3068,6 +3101,35 @@ namespace ApiPolo.Controllers
return mn;
}
/// <summary>trasforma un Compi_Impia in un Vt_Mag_New</summary>
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();
/// <summary>crea un cpccchk</summary>
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<Articoli>();
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<Saldiart> listaSaldiArt = new List<Saldiart>();
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<Saldiart> lista = new List<Saldiart>();
//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<Saldiart> lista = new List<Saldiart>();
//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
}
}
/// <summary>VIRTUAL TASK: lista mag_new per azienda</summary>
[HttpGet("VTMagNewList")]
public async Task<ActionResult<IEnumerable<Vt_Mag_New>>> VTMagNewList(string token)
{
try
{
List<Vt_Mag_New> mnlist = new List<Vt_Mag_New>();
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

View File

@ -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<Vt_Mag_New> MagNewVt { get; set; }
public VT_MAG_NEW_DbContext(DbContextOptions<VT_MAG_NEW_DbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Vt_Mag_New>().ToTable("MAG_NEW_VT");
modelBuilder.Entity<Vt_Mag_New>()
.HasKey(Table => new {
Table.Azienda,
Table.Seriale_Rapportino,
Table.Riga
});
}
}
}

View File

@ -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<Articoli>? SaldiArt_VT { get; set; }
public VT_SALDIART_DbContext(DbContextOptions<VT_SALDIART_DbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Articoli>().ToView("API_SALDIART_PREZZI");
}
}
}

View File

@ -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; }
}
}

View File

@ -752,6 +752,13 @@ namespace ApiPolo
services.AddDbContext<VT_ARTICOLI_TABLE_DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK")
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
));
services.AddDbContext<VT_MAG_NEW_DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK")
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
));
services.AddDbContext<VT_SALDIART_DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK")
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
));
#endregion
#region LIFT_WEB