lista giri e aggiunta di un nuovo giro
This commit is contained in:
parent
035b081ff2
commit
0f1853c6bd
@ -7,6 +7,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Diagnostics;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
@ -18,69 +19,108 @@ namespace ApiSoftway.Controllers
|
||||
{
|
||||
private readonly ILogger<LoginController> _logger;
|
||||
private readonly GESA_GIRI_DbContext _giri_context;
|
||||
private readonly GESA_GIRICONSEGNE_DbContext _giricons_context;
|
||||
private readonly GESA_DESTINAZIONI_DbContext _destinazioni_context;
|
||||
private readonly GESA_CONSEGNE_DbContext _consegne_context;
|
||||
private readonly GESA_GIRICONSEGNEVISTA_DbContext _consegnevista_context;
|
||||
private readonly GESA_SBR_ORD_DbContext _sbrord_context;
|
||||
private readonly IConfiguration? _configuration;
|
||||
private DbSet<Giri>? _giri;
|
||||
private DbSet<GiriConsegna>? _giriCons;
|
||||
private DbSet<GiriConsegnaView>? _giriConsView;
|
||||
private DbSet<Destinazioni>? _destinazioni;
|
||||
private DbSet<Consegna>? _consegne;
|
||||
private DbSet<Sbr_ord>? _sbrord;
|
||||
public GiriController(ILogger<LoginController> logger, IConfiguration? configuration, GESA_GIRI_DbContext giri_context, GESA_DESTINAZIONI_DbContext destinazioni_context
|
||||
, GESA_CONSEGNE_DbContext consegne_context)
|
||||
, GESA_CONSEGNE_DbContext consegne_context, GESA_GIRICONSEGNE_DbContext giricons_context, GESA_GIRICONSEGNEVISTA_DbContext consegnevista_context, GESA_SBR_ORD_DbContext sbrord_context)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_giri_context = giri_context;
|
||||
_destinazioni_context = destinazioni_context;
|
||||
_consegne_context = consegne_context;
|
||||
_giricons_context = giricons_context;
|
||||
_consegnevista_context = consegnevista_context;
|
||||
_sbrord_context = sbrord_context;
|
||||
|
||||
}
|
||||
|
||||
//[HttpGet("listaGiri")]
|
||||
//public async Task<ActionResult<IEnumerable<Giri_out>>> listaGiri(string token)
|
||||
//{
|
||||
[HttpGet("listaGiri")]
|
||||
public async Task<ActionResult<IEnumerable<GiriConsegnaView>>> listaGiri(string? autista, DateTime? data, bool aperto=true)
|
||||
{
|
||||
|
||||
// List<Giri_out> lst = new List<Giri_out>();
|
||||
// string usr = getClaimValueByToken(token, "codice");
|
||||
// _giri = _giri_context.Giri;
|
||||
// var r= await _giri.Where(t => t.Brautist != null && t.Brautist.Equals(usr)).OrderByDescending(t=>t.Brdatcar).Take(1).ToListAsync();
|
||||
// foreach(Giri giri in r)
|
||||
// {
|
||||
// Giri_out o=new Giri_out();
|
||||
// o.Autista = giri.Autista;
|
||||
// o.Brdatcar = giri.Brdatcar;
|
||||
// o.Brautist = giri.Brautist;
|
||||
// o.num_dest=giri.num_dest;
|
||||
// o.ItemList = formattaGiro(giri);
|
||||
// lst.Add(o);
|
||||
// }
|
||||
// return lst;
|
||||
//}
|
||||
//[HttpGet("listaDestinazioni")]
|
||||
//public async Task<ActionResult<IEnumerable<Destinazioni_out>>> listaDestinazioni(string token, DateTime data)
|
||||
//{
|
||||
List<GiriConsegnaView> lst = new List<GiriConsegnaView>();
|
||||
_giriConsView = _consegnevista_context.GiriView;
|
||||
|
||||
if(aperto)
|
||||
{
|
||||
lst = await _giriConsView.Where(t => t.CodAutista != null && t.CodAutista.Equals(autista) && t.DataGiro != null && t.DataGiro == data && t.DataChiusura==null).OrderByDescending(t => t.DataGiro).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
lst = await _giriConsView.Where(t => t.CodAutista != null && t.CodAutista.Equals(autista) && t.DataGiro != null && t.DataGiro == data && t.DataChiusura != null).OrderByDescending(t => t.DataGiro).ToListAsync();
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
/// <summary>Salva i dati della consegna</summary>
|
||||
[HttpPost]
|
||||
[Route("addGiro")]
|
||||
public async Task<ActionResult<GiriConsegna_out>> addGiro(string? autista,int? bancali, decimal? importo, DateTime? data)
|
||||
{
|
||||
GiriConsegna_out tOut = new GiriConsegna_out();
|
||||
//string usr = getClaimValueByToken(token, "codice");
|
||||
try
|
||||
{
|
||||
//step 1 : calcolo il nuovo seriale
|
||||
_giriConsView = _consegnevista_context.GiriView;
|
||||
var ser= await _giriConsView.Take(1).OrderByDescending(t => t.SerialeGiro).ToListAsync();
|
||||
string ultSer = ser.First().SerialeGiro;
|
||||
string newSer = calcolaNuovoSeriale(ultSer);
|
||||
|
||||
//step 2 : inserisco in PIGIRCON
|
||||
GiriConsegna gc=new GiriConsegna();
|
||||
gc.Piautist = autista;
|
||||
gc.Pitbancar = bancali;
|
||||
gc.Pidata = data;
|
||||
gc.Pisergir = newSer;
|
||||
gc.Pidarecu = importo;
|
||||
using (var transactionGiri = _giricons_context.Database.BeginTransaction())
|
||||
{
|
||||
await _giricons_context.GiriCons.AddAsync(gc);
|
||||
await _giricons_context.SaveChangesAsync();
|
||||
transactionGiri.Commit();
|
||||
}
|
||||
|
||||
//step 3 aggiorno con il seriale le righe delle destinazioni
|
||||
_destinazioni = _destinazioni_context.Destinazioni;
|
||||
var dest = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(autista) && t.DataCarico != null && t.DataCarico == data && t.serialeGiro==null).OrderByDescending(t => t.DataCarico).ToListAsync();
|
||||
foreach(Destinazioni d in dest)
|
||||
{
|
||||
Sbr_ord sbr_Ord = new Sbr_ord();
|
||||
sbr_Ord.Brserial = d.Brserial;
|
||||
sbr_Ord.Pisergir = newSer;
|
||||
using (var transactionDest = _sbrord_context.Database.BeginTransaction())
|
||||
{
|
||||
_sbrord_context.Entry(sbr_Ord).State = EntityState.Modified;
|
||||
await _sbrord_context.SaveChangesAsync();
|
||||
transactionDest.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
var giro = await _giriConsView.Where(t=>t.SerialeGiro.Equals(newSer)).ToListAsync();
|
||||
return StatusCode(StatusCodes.Status200OK, giro.First());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
|
||||
tOut.err_title = ex.Message;
|
||||
tOut.err_detail = errmsg;
|
||||
tOut.err_status_code = "500";
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, tOut);
|
||||
}
|
||||
}
|
||||
|
||||
// List<Destinazioni_out> lst = new List<Destinazioni_out>();
|
||||
// string usr = getClaimValueByToken(token, "codice");
|
||||
// _destinazioni = _destinazioni_context.Destinazioni;
|
||||
// var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr)&& t.DataCarico != null && t.DataCarico == data).OrderByDescending(t => t.DataCarico).ToListAsync();
|
||||
// foreach(Destinazioni d in r)
|
||||
// {
|
||||
// Destinazioni_out o = new Destinazioni_out();
|
||||
// o.Autista = d.Autista;
|
||||
// o.CodAutista = d.CodAutista;
|
||||
// o.DescAutomezzo = d.DescAutomezzo;
|
||||
// o.CodAutomezzo=d.CodAutomezzo;
|
||||
// o.DataCarico = d.DataCarico;
|
||||
// o.Brserial=d.Brserial;
|
||||
// o.Brmerce=d.Brmerce;
|
||||
// o.Brnote=d.Brnote;
|
||||
// o.Cproword=d.Cproword;
|
||||
// o.IndirizzoSede=d.IndirizzoSede;
|
||||
// o.Sede=d.Sede;
|
||||
// o.ItemList = formattaDestinazione(d);
|
||||
// lst.Add(o);
|
||||
// }
|
||||
// return lst;
|
||||
//}
|
||||
|
||||
[HttpGet("listaDestinazioni")]
|
||||
public async Task<ActionResult<IEnumerable<Destinazioni_out>>> listaDestinazioni2(string token)
|
||||
@ -130,6 +170,7 @@ namespace ApiSoftway.Controllers
|
||||
o.CodSede = d.CodSede;
|
||||
o.ItemList = formattaDestinazione(d);
|
||||
o.ImportoDaRitirare = d.ImportoDaRitirare;
|
||||
o.serialeGiro=d.serialeGiro;
|
||||
if (!string.IsNullOrEmpty(d.consFattaSerial))
|
||||
{
|
||||
ConsegnaFatta cf=new ConsegnaFatta();
|
||||
@ -144,6 +185,7 @@ namespace ApiSoftway.Controllers
|
||||
cf.consFattaMezzo= d.consFattaMezzo;
|
||||
string nota2 = !string.IsNullOrEmpty(d.consFattaNotImp) ? d.consFattaNotImp.Trim() : string.Empty;
|
||||
cf.consFattaNotImp=nota2;
|
||||
cf.consFattaFlagCons=d.consFattaFlagCons;
|
||||
|
||||
o.ConsFatta=cf;
|
||||
}
|
||||
@ -344,7 +386,6 @@ namespace ApiSoftway.Controllers
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private Consegna fillConsegnaNonEffettuata(Consegna i, string token)
|
||||
{
|
||||
Consegna r = new Consegna();
|
||||
@ -429,6 +470,21 @@ namespace ApiSoftway.Controllers
|
||||
|
||||
return r;
|
||||
}
|
||||
private string calcolaNuovoSeriale(string ultSer)
|
||||
{
|
||||
string newSer = string.Empty;
|
||||
|
||||
int ser=Convert.ToInt32(ultSer);
|
||||
ser++;
|
||||
newSer=Convert.ToString(ser);
|
||||
|
||||
if (ser > 0)
|
||||
{
|
||||
newSer = newSer.PadLeft(10, '0');
|
||||
}
|
||||
|
||||
return newSer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,9 @@ namespace ApiSoftway.Models
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? ImportoDaRitirare { get; set; }
|
||||
public string? consFattaFlagCons { get; set; }
|
||||
|
||||
public string? serialeGiro { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ namespace ApiSoftway.Models
|
||||
public decimal? ImportoDaRitirare { get; set; }
|
||||
public string? ItemList { get; set; }
|
||||
public ConsegnaFatta? ConsFatta { get; set; }
|
||||
public string? serialeGiro { get; set; }
|
||||
}
|
||||
public class ConsegnaFatta
|
||||
{
|
||||
@ -38,7 +39,8 @@ namespace ApiSoftway.Models
|
||||
public decimal? consFattaImpor { get; set; }
|
||||
public string? consFattaNotImp { get; set; }
|
||||
public string? consFattaNotBan { get; set; }
|
||||
|
||||
|
||||
public string? consFattaFlagCons { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
16
Models/Gesa_DbContext/GESA_GIRICONSEGNEVISTA_DbContext.cs
Normal file
16
Models/Gesa_DbContext/GESA_GIRICONSEGNEVISTA_DbContext.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models.Gesa_DbContext
|
||||
{
|
||||
public class GESA_GIRICONSEGNEVISTA_DbContext : DbContext
|
||||
{
|
||||
public DbSet<GiriConsegnaView>? GiriView { get; set; }
|
||||
public GESA_GIRICONSEGNEVISTA_DbContext(DbContextOptions<GESA_GIRICONSEGNEVISTA_DbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<GiriConsegnaView>().ToView("API_GIRICONSEGNA");
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Models/Gesa_DbContext/GESA_GIRICONSEGNE_DbContext.cs
Normal file
24
Models/Gesa_DbContext/GESA_GIRICONSEGNE_DbContext.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models.Gesa_DbContext
|
||||
{
|
||||
public class GESA_GIRICONSEGNE_DbContext: DbContext
|
||||
{
|
||||
/// <summary></summary>
|
||||
public DbSet<GiriConsegna>? GiriCons { get; set; }
|
||||
|
||||
/// <summary></summary>
|
||||
public GESA_GIRICONSEGNE_DbContext(DbContextOptions<GESA_GIRICONSEGNE_DbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary></summary>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<GiriConsegna>().ToTable("GESAPIGIRCON");
|
||||
modelBuilder.Entity<GiriConsegna>().HasKey(table => new {
|
||||
table.Pisergir
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Models/Gesa_DbContext/GESA_SBR_ORD_DbContext.cs
Normal file
23
Models/Gesa_DbContext/GESA_SBR_ORD_DbContext.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models.Gesa_DbContext
|
||||
{
|
||||
public class GESA_SBR_ORD_DbContext: DbContext
|
||||
{
|
||||
public DbSet<Sbr_ord>? Cons { get; set; }
|
||||
|
||||
/// <summary></summary>
|
||||
public GESA_SBR_ORD_DbContext(DbContextOptions<GESA_SBR_ORD_DbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary></summary>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Sbr_ord>().ToTable("GESASBR_ORD");
|
||||
modelBuilder.Entity<Sbr_ord>().HasKey(table => new {
|
||||
table.Brserial
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Models/GiriConsegna.cs
Normal file
23
Models/GiriConsegna.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ApiSoftway.Models
|
||||
{
|
||||
public class GiriConsegna
|
||||
{
|
||||
[Key]
|
||||
public string? Pisergir { get; set; }
|
||||
public DateTime? Pidata { get; set; }
|
||||
public string? Piautist { get; set; }
|
||||
public int? Pitbancar { get; set; }
|
||||
public int? Pitbanrec { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? Pidarecu { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? Pirecupe { get; set; }
|
||||
|
||||
public DateTime? Pidatchi { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
23
Models/GiriConsegnaView.cs
Normal file
23
Models/GiriConsegnaView.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models
|
||||
{
|
||||
[Keyless]
|
||||
public class GiriConsegnaView
|
||||
{
|
||||
public string? SerialeGiro { get; set; }
|
||||
public DateTime? DataGiro { get; set; }
|
||||
public string? CodAutista { get; set; }
|
||||
public string? Autista { get; set; }
|
||||
public int? BancaliCaricati { get; set; }
|
||||
public int? BancaliRecuperati { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? ImportoDaRecuperare { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? ImportoRecuperato { get; set; }
|
||||
public DateTime? DataChiusura { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
28
Models/GiriConsegna_out.cs
Normal file
28
Models/GiriConsegna_out.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models
|
||||
{
|
||||
[Keyless]
|
||||
public class GiriConsegna_out
|
||||
{
|
||||
public string? Pisergir { get; set; }
|
||||
public DateTime? Pidata { get; set; }
|
||||
public string? Piautist { get; set; }
|
||||
public int? Pitbancar { get; set; }
|
||||
public int? Pitbanrec { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? Pidarecu { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? Pirecupe { get; set; }
|
||||
public DateTime? Pidatchi { get; set; }
|
||||
|
||||
/// <summary>errore titolo</summary>
|
||||
public string? err_title { get; set; }
|
||||
/// <summary>errore dettaglio</summary>
|
||||
public string? err_detail { get; set; }
|
||||
/// <summary>errore status code (200, 500)</summary>
|
||||
public string? err_status_code { get; set; }
|
||||
}
|
||||
}
|
||||
11
Models/Sbr_ord.cs
Normal file
11
Models/Sbr_ord.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ApiSoftway.Models
|
||||
{
|
||||
public class Sbr_ord
|
||||
{
|
||||
[Key]
|
||||
public string? Brserial { get; set; }
|
||||
public string? Pisergir { get; set; }
|
||||
}
|
||||
}
|
||||
16
Program.cs
16
Program.cs
@ -27,12 +27,18 @@ builder.Services.AddDbContext<GESA_DESTINAZIONI_DbContext>(options => options.Us
|
||||
builder.Services.AddDbContext<GESA_CONSEGNE_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
|
||||
builder.Services.AddDbContext<GESA_CLIENTI_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
|
||||
|
||||
builder.Services.AddDbContext<GESA_GIRICONSEGNE_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
builder.Services.AddDbContext<GESA_GIRICONSEGNEVISTA_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
builder.Services.AddDbContext<GESA_SBR_ORD_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
#endregion
|
||||
|
||||
|
||||
@ -55,5 +61,5 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
//app.Run("http://localhost:6000");
|
||||
//app.Run();
|
||||
app.Run("http://localhost:6000");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user