From 1da535c397c550979db8484086c8a043f15bcd94 Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Wed, 19 Mar 2025 17:41:15 +0100 Subject: [PATCH] gestione note e selezione giri per data --- Controllers/GiriController.cs | 109 +++++++++++++-- Models/Consegna.cs | 3 + Models/ConsegnaTable.cs | 3 + Models/Consegna_out.cs | 3 + Models/Destinazioni_out.cs | 2 + .../GESA_SBR_ORD_TABLE_DbContext.cs | 23 +++ Models/Sbr_ordTable.cs | 131 ++++++++++++++++++ Program.cs | 3 + 8 files changed, 269 insertions(+), 8 deletions(-) create mode 100644 Models/Gesa_DbContext/GESA_SBR_ORD_TABLE_DbContext.cs create mode 100644 Models/Sbr_ordTable.cs diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index 0d44406..3329a8f 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -36,6 +36,7 @@ namespace ApiSoftway.Controllers private readonly GESA_GIRICONSEGNEDACREARE_DESTINAZIONI_DbContext _daCreareDest_context; private readonly GESA_DESTINAZIONI_WEB_DbContext _destinazioni_web_context; private readonly GESA_GIRI_TESTATE_DbContext _giri_testate_context; + private readonly GESA_SBR_ORD_TABLE_DbContext _sbrordTable_context; private DbSet? _giri; private DbSet? _giriCons; @@ -48,11 +49,12 @@ namespace ApiSoftway.Controllers private DbSet? _GiriDaCreare; private DbSet? _testate; private DbSet? _GiriDaCreareDest; + private DbSet? _sbrordTable; public GiriController(ILogger logger, IConfiguration? configuration, GESA_GIRI_DbContext giri_context, GESA_DESTINAZIONI_DbContext destinazioni_context , GESA_CONSEGNE_DbContext consegne_context, GESA_GIRICONSEGNE_DbContext giricons_context, GESA_GIRICONSEGNEVISTA_DbContext consegnevista_context, GESA_SBR_ORD_DbContext sbrord_context , GESA_PERSONALE_DbContext personale_context, GESA_AUTOMEZZI_DbContext automezzi_context, GESA_GIRICONSEGNEDACREARE_DbContext daCreare_context , GESA_CONSEGNE_M_DbContext consegne_m_context, GESA_PI_GIRI_SERIALI_DbContext giriseriali_context, GESA_GIRICONSEGNEDACREARE_DESTINAZIONI_DbContext daCreareDest_context - , GESA_DESTINAZIONI_WEB_DbContext destinazioni_web_context,GESA_GIRI_TESTATE_DbContext giri_testate_context) + , GESA_DESTINAZIONI_WEB_DbContext destinazioni_web_context,GESA_GIRI_TESTATE_DbContext giri_testate_context, GESA_SBR_ORD_TABLE_DbContext sbrordTable_context) { _logger = logger; _configuration = configuration; @@ -70,6 +72,7 @@ namespace ApiSoftway.Controllers _daCreareDest_context = daCreareDest_context; _destinazioni_web_context = destinazioni_web_context; _giri_testate_context = giri_testate_context; + _sbrordTable_context = sbrordTable_context; } [HttpGet("listaGiri")] @@ -287,6 +290,72 @@ namespace ApiSoftway.Controllers } } + + [HttpPost] + [Route("addBrogliaccio")] + public async Task> addBrogliaccio(string token, DateTime? oldData,DateTime? newData) + { + string msg = string.Empty; + + try + { + string usr = getClaimValueByToken(token, "codice"); + if (!string.IsNullOrEmpty(usr) && usr.Trim().Equals("TEST")) + { + //step 1 : prendo gli ultimi 1000 record della tabella SBR_ORD + _sbrordTable = _sbrordTable_context.Cons; + int tot = _sbrordTable.Count(); + msg = tot.ToString(); + + var bro = await _sbrordTable.Where(t => t.Brdatcar == oldData + && !string.IsNullOrEmpty(t.Brautist.Trim()) + && (t.Brqtacol != null && t.Brqtacol > 0 + || (t.Brqtavol != null && t.Brqtavol > 0) + || (t.Brcolprev != null && t.Brcolprev > 0) + || (t.Brconspr != null && t.Brconspr > 0) + || (t.Bruovapr != null && t.Bruovapr > 0) + || (t.Brcistpr != null && t.Brcistpr > 0) + || (!string.IsNullOrEmpty(t.Brnote)) + ) + ).ToListAsync(); + + int counter = 0; + foreach (Sbr_ordTable d in bro) + { + string newSerial = getCpccchk(10); + d.Brserial = newSerial; + d.cpccchk = newSerial; + d.Brdatcar = newData; + d.BRDATINS = newData != null ? newData.Value.AddDays(-1) : DateTime.Now; + d.BRDATVAR = newData != null ? newData.Value.AddDays(-1) : DateTime.Now; + d.BRDATSCA = newData; + d.Brnote = "*****"+newData.ToString() + d.Brnote; + + using (var transactionDest = _sbrordTable_context.Database.BeginTransaction()) + { + await _sbrordTable_context.Cons.AddAsync(d); + await _sbrordTable_context.SaveChangesAsync(); + transactionDest.Commit(); + } + counter++; + } + msg = "Inseriti " + counter.ToString() + " record"; + return StatusCode(StatusCodes.Status200OK, msg); + } + else + { + return StatusCode(StatusCodes.Status200OK, "Impossibile procedere al caricamento. Utente non abilitato all'operazione"); + } + + } + catch (Exception ex) + { + msg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, msg); + } + + } + [HttpPost] [Route("closeGiro")] public async Task> closeGiro(string? serialeGiro, int? bancaliRecuperati, decimal? importoRecuperato) @@ -475,15 +544,33 @@ namespace ApiSoftway.Controllers } } + //metodo app [HttpGet("listaDestinazioni")] - public async Task>> listaDestinazioni2(string token) + public async Task>> listaDestinazioni2(string token,DateTime? dataGiro) { - //step 1: ricavo la data a partire dal login + DateTime? data; string usr = getClaimValueByToken(token, "codice"); - _giri = _giri_context.Giri; - var g = await _giri.Where(t => t.Brautist != null && t.Brautist.Equals(usr)).OrderByDescending(t => t.Brdatcar).Take(1).ToListAsync(); - DateTime? data = g.First().Brdatcar; + bool btnChiudiVisible = true; + bool btnNonChiudiVisible = true; + if (dataGiro == null) + { + //step 1: ricavo la data a partire dal login + //_giri = _giri_context.Giri; + //var g = await _giri.Where(t => t.Brautist != null && t.Brautist.Equals(usr)).OrderByDescending(t => t.Brdatcar).Take(1).ToListAsync(); + //data = g.First().Brdatcar; + data = DateTime.Today; + } + else + { + data= dataGiro; + if(data!=DateTime.Today) + { + btnChiudiVisible = false; + btnNonChiudiVisible = false; + } + + } List lst = new List(); _destinazioni = _destinazioni_context.Destinazioni; @@ -551,6 +638,11 @@ namespace ApiSoftway.Controllers o.Seq = d.Seq; o.Prog = d.Prog; + //2025-03.19 - flag pulsanti visibili: se data passata = data odierna pulsanti visibili altrimenti no + o.BtnChiudiVisible= btnChiudiVisible; + o.BtnNonChiudiVisible = btnNonChiudiVisible; + + if (!string.IsNullOrEmpty(d.consFattaSerial)) { ConsegnaFatta cf=new ConsegnaFatta(); @@ -1235,7 +1327,7 @@ namespace ApiSoftway.Controllers r.Pimezzo = i.Pimezzo; r.Piimport= i.Piimport; r.Serial=i.Serial; - + r.Pinotcon = i.Pinotcon; return r; @@ -1278,6 +1370,7 @@ namespace ApiSoftway.Controllers r.Pimezzo = i.Pimezzo; r.Piimport = i.Piimport; r.Serial=i.Serial; + r.Pinotcon=i.Pinotcon; @@ -1320,7 +1413,7 @@ namespace ApiSoftway.Controllers r.Piconseg = i.Piconseg; r.Pimezzo = i.Pimezzo; r.Piimport = i.Piimport; - + r.Pinotcon = i.Pinotcon; return r; diff --git a/Models/Consegna.cs b/Models/Consegna.cs index a1e2668..01d7006 100644 --- a/Models/Consegna.cs +++ b/Models/Consegna.cs @@ -33,5 +33,8 @@ namespace ApiSoftway.Models public decimal? Piimport { get; set; } public string? Pinotimp { get; set; } public string? Pinotban { get; set; } + + //nota consegna (nel caso di consegna non possibile) + public string? Pinotcon { get; set; } } } diff --git a/Models/ConsegnaTable.cs b/Models/ConsegnaTable.cs index 44d7d39..f67ec95 100644 --- a/Models/ConsegnaTable.cs +++ b/Models/ConsegnaTable.cs @@ -36,5 +36,8 @@ namespace ApiSoftway.Models public string? Pinotimp { get; set; } public string? Pinotban { get; set; } public string? Serial { get; set; } + + //nota consegna (nel caso di consegna non possibile) + public string? Pinotcon { get; set; } } } diff --git a/Models/Consegna_out.cs b/Models/Consegna_out.cs index b2ee41f..132a95b 100644 --- a/Models/Consegna_out.cs +++ b/Models/Consegna_out.cs @@ -33,6 +33,9 @@ namespace ApiSoftway.Models public string? Pinotimp { get; set; } public string? Pinotban { get; set; } + //nota consegna (nel caso di consegna non possibile) + public string? Pinotcon { get; set; } + public string? Serial { get; set; } /// errore titolo diff --git a/Models/Destinazioni_out.cs b/Models/Destinazioni_out.cs index 5671e35..50c31e9 100644 --- a/Models/Destinazioni_out.cs +++ b/Models/Destinazioni_out.cs @@ -40,6 +40,8 @@ namespace ApiSoftway.Models //progressivo- chiave tabella pimodgir public string? Prog { get; set; } + public bool? BtnChiudiVisible { get; set; } + public bool? BtnNonChiudiVisible { get; set; } } public class ConsegnaFatta { diff --git a/Models/Gesa_DbContext/GESA_SBR_ORD_TABLE_DbContext.cs b/Models/Gesa_DbContext/GESA_SBR_ORD_TABLE_DbContext.cs new file mode 100644 index 0000000..bc87a95 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_SBR_ORD_TABLE_DbContext.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_SBR_ORD_TABLE_DbContext : DbContext + { + public DbSet? Cons { get; set; } + + /// + public GESA_SBR_ORD_TABLE_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("GESASBR_ORD"); + modelBuilder.Entity().HasKey(table => new { + table.Brserial + }); + } + } +} diff --git a/Models/Sbr_ordTable.cs b/Models/Sbr_ordTable.cs new file mode 100644 index 0000000..c38078b --- /dev/null +++ b/Models/Sbr_ordTable.cs @@ -0,0 +1,131 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class Sbr_ordTable + { + [Key] + public string? Brserial { get; set; } + public string? Brcodcom { get; set; } + public string? Brclifat { get; set; } + public int? Brnumseq { get; set; } + public string? Brcodsed { get; set; } + public DateTime? Brdatcar { get; set; } + + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? Brqtacol { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? Brqtavol { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? Brcolprev { get; set; } + public int? Brconspr { get; set; } + public int? Bruovapr { get; set; } + public int? Brcistpr { get; set; } + public string? Brnote { get; set; } + //BRTARTRA,BRAUTIST, CATNOME, CAUDESC + public string? Brtartra { get; set; } + public string? Brautist { get; set; } + + public string? BRTIPORD { get; set; } + public int? BRORACAR { get; set; } + public string? BRCARPRI { get; set; } + public string? BRTARRIM { get; set; } + public int? BRUTEINS { get; set; } + public DateTime? BRDATINS { get; set; } + public int? BRUTEVAR { get; set; } + public DateTime? BRDATVAR { get; set; } + public int? BRNUMERO { get; set; } + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRQTAPES { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRQTAKM { get; set; } + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRIMPFOR { get; set; } + public string? BRMERCE { get; set; } + + public DateTime? BRDATSCA { get; set; } + public int? BRORASCA { get; set; } + public string? BRSCAPRI { get; set; } + public int? BRPALLET { get; set; } + public int? BRNUMBOL { get; set; } + + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRPESEFF { get; set; } + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRCOLEFF { get; set; } + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRVOLEFF { get; set; } + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRKMEFF { get; set; } + + + + //,[BRESERCI] + + //,[BRQTAVOL] + //,[BRQTACOL] + + //,[BRRIFORD]null + + + //,[BRDATBOL]null + + //,[BRCODCTR] null + //,[BRRIGCTR]null + //,[BRCLIFAT]null + //,[BRCODESI]null + + public string? BRTIPCLI { get; set; } + + public string? cpccchk { get; set; } + public string? BRDESSEDE { get; set; } + //,[] + + + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 4)")] + public decimal? BRPEDEF { get; set; } + + public int? BRCONSEF { get; set; } + + //,[BRSERBOL]null + + + public int? BRUOVAEF { get; set; } + public int? BRCISTEF { get; set; } + + public string? BRTEST { get; set; } + + public string? BRCOSAUT { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(6, 2)")] + public decimal? BRPERAUT { get; set; } + //,[BRCOSBIL]null + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(6, 2)")] + public decimal? BRPERBIL { get; set; } + + public string? BRCOSSTR { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(6, 2)")] + public decimal? BRPERSTR { get; set; } + + public string? BRCOSPED { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(6, 2)")] + public decimal? BRPERPED { get; set; } + //,[BRCHKBIL] + public string? BRCHKBIL { get; set; } + //,[BRAUTBIL]null + + public int? BRSEQUE { get; set; } + //,[PISERGIR]null + + + + } +} diff --git a/Program.cs b/Program.cs index 9942855..8d8319c 100644 --- a/Program.cs +++ b/Program.cs @@ -67,6 +67,9 @@ builder.Services.AddDbContext(options => option builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); #endregion