Rimappatura di consegne dopo master/detail.
Filtro destinazioni per esporre un giro alla volta
This commit is contained in:
parent
86d7c6349e
commit
8ab01eb1bd
@ -36,7 +36,7 @@ namespace ApiSoftway.Controllers
|
||||
private DbSet<GiriConsegna>? _giriCons;
|
||||
private DbSet<GiriConsegnaView>? _giriConsView;
|
||||
private DbSet<Destinazioni>? _destinazioni;
|
||||
private DbSet<Consegna>? _consegne;
|
||||
private DbSet<ConsegnaTable>? _consegne;
|
||||
private DbSet<Sbr_ord>? _sbrord;
|
||||
private DbSet<Personale>? _personale;
|
||||
private DbSet<Automezzi>? _automezzi;
|
||||
@ -431,74 +431,89 @@ namespace ApiSoftway.Controllers
|
||||
List<Destinazioni_out> lst = new List<Destinazioni_out>();
|
||||
_destinazioni = _destinazioni_context.Destinazioni;
|
||||
var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr) && t.DataCarico != null && t.DataCarico == data
|
||||
//&& !string.IsNullOrEmpty(t.serialeGiro)
|
||||
).OrderByDescending(t => t.DataCarico).ToListAsync();
|
||||
&& !string.IsNullOrEmpty(t.serialeGiro)
|
||||
).OrderBy(t => t.serialeGiro).ToListAsync();
|
||||
|
||||
|
||||
//2024-07-29: se un autista ha due o più giri da fare nello stesso giorno li devo separare. li ho ordinati per seriale giro e gli do quelli del primo
|
||||
// giro disponibile che non sia chiuso (PIDATCHI di GESAPIGIRCON deve essere nulla)
|
||||
int giro = 0;
|
||||
string seriale_attuale = string.Empty;
|
||||
foreach (Destinazioni d in r)
|
||||
{
|
||||
Destinazioni_out o = new Destinazioni_out();
|
||||
string _aut= !string.IsNullOrEmpty(d.Autista) ? d.Autista.Trim() : string.Empty;
|
||||
o.Autista = _aut;
|
||||
|
||||
string _autCod = !string.IsNullOrEmpty(d.CodAutista) ? d.CodAutista.Trim() : string.Empty;
|
||||
o.CodAutista = _autCod;
|
||||
|
||||
string _automezzo = !string.IsNullOrEmpty(d.DescAutomezzo) ? d.DescAutomezzo.Trim() : string.Empty;
|
||||
o.DescAutomezzo = _automezzo;
|
||||
|
||||
string _automezzoCod = !string.IsNullOrEmpty(d.CodAutomezzo) ? d.CodAutomezzo.Trim() : string.Empty;
|
||||
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.Cprownum=d.Cprownum;
|
||||
|
||||
string _sedeInd = !string.IsNullOrEmpty(d.IndirizzoSede) ? d.IndirizzoSede.Trim() : string.Empty;
|
||||
o.IndirizzoSede = _sedeInd;
|
||||
|
||||
string _sede = !string.IsNullOrEmpty(d.Sede) ? d.Sede.Trim() : string.Empty;
|
||||
o.Sede = _sede;
|
||||
o.CodCommittente = d.CodCommittente;
|
||||
|
||||
string _committente = !string.IsNullOrEmpty(d.Committente) ? d.Committente.Trim() : string.Empty;
|
||||
o.Committente = _committente;
|
||||
|
||||
o.CodSede = d.CodSede;
|
||||
o.ItemList = formattaDestinazione(d);
|
||||
o.ImportoDaRitirare = d.ImportoDaRitirare;
|
||||
o.serialeGiro=d.serialeGiro;
|
||||
o.Casse = d.Casse;
|
||||
o.Trasf=d.Trasf;
|
||||
o.Colli=d.Colli;
|
||||
o.num_cons = d.num_cons;
|
||||
o.Uova=d.Uova;
|
||||
o.Cist=d.Cist;
|
||||
o.Note = d.Note;
|
||||
o.Seq = d.Seq;
|
||||
o.Prog = d.Prog;
|
||||
|
||||
if (!string.IsNullOrEmpty(d.consFattaSerial))
|
||||
if(giro==0)
|
||||
{
|
||||
ConsegnaFatta cf=new ConsegnaFatta();
|
||||
cf.consFattaSerial= d.consFattaSerial;
|
||||
cf.consFattaRow= d.consFattaRow;
|
||||
cf.consFattaAut= d.consFattaAut;
|
||||
cf.consFattaBanSca = d.consFattaBanSca;
|
||||
cf.consFattaBanCar= d.consFattaBanCar;
|
||||
string nota = !string.IsNullOrEmpty(d.consFattaNotBan) ? d.consFattaNotBan.Trim() : string.Empty;
|
||||
cf.consFattaNotBan= nota;
|
||||
cf.consFattaImpor=d.consFattaImpor;
|
||||
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;
|
||||
seriale_attuale = d.serialeGiro;
|
||||
}
|
||||
giro++;
|
||||
|
||||
lst.Add(o);
|
||||
if(d.serialeGiro.Equals(seriale_attuale))
|
||||
{
|
||||
Destinazioni_out o = new Destinazioni_out();
|
||||
string _aut= !string.IsNullOrEmpty(d.Autista) ? d.Autista.Trim() : string.Empty;
|
||||
o.Autista = _aut;
|
||||
|
||||
string _autCod = !string.IsNullOrEmpty(d.CodAutista) ? d.CodAutista.Trim() : string.Empty;
|
||||
o.CodAutista = _autCod;
|
||||
|
||||
string _automezzo = !string.IsNullOrEmpty(d.DescAutomezzo) ? d.DescAutomezzo.Trim() : string.Empty;
|
||||
o.DescAutomezzo = _automezzo;
|
||||
|
||||
string _automezzoCod = !string.IsNullOrEmpty(d.CodAutomezzo) ? d.CodAutomezzo.Trim() : string.Empty;
|
||||
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.Cprownum=d.Cprownum;
|
||||
|
||||
string _sedeInd = !string.IsNullOrEmpty(d.IndirizzoSede) ? d.IndirizzoSede.Trim() : string.Empty;
|
||||
o.IndirizzoSede = _sedeInd;
|
||||
|
||||
string _sede = !string.IsNullOrEmpty(d.Sede) ? d.Sede.Trim() : string.Empty;
|
||||
o.Sede = _sede;
|
||||
o.CodCommittente = d.CodCommittente;
|
||||
|
||||
string _committente = !string.IsNullOrEmpty(d.Committente) ? d.Committente.Trim() : string.Empty;
|
||||
o.Committente = _committente;
|
||||
|
||||
o.CodSede = d.CodSede;
|
||||
o.ItemList = formattaDestinazione(d);
|
||||
o.ImportoDaRitirare = d.ImportoDaRitirare;
|
||||
o.serialeGiro=d.serialeGiro;
|
||||
o.Casse = d.Casse;
|
||||
o.Trasf=d.Trasf;
|
||||
o.Colli=d.Colli;
|
||||
o.num_cons = d.num_cons;
|
||||
o.Uova=d.Uova;
|
||||
o.Cist=d.Cist;
|
||||
o.Note = d.Note;
|
||||
o.Seq = d.Seq;
|
||||
o.Prog = d.Prog;
|
||||
|
||||
if (!string.IsNullOrEmpty(d.consFattaSerial))
|
||||
{
|
||||
ConsegnaFatta cf=new ConsegnaFatta();
|
||||
cf.consFattaSerial= d.consFattaSerial;
|
||||
cf.consFattaRow= d.consFattaRow;
|
||||
cf.consFattaAut= d.consFattaAut;
|
||||
cf.consFattaBanSca = d.consFattaBanSca;
|
||||
cf.consFattaBanCar= d.consFattaBanCar;
|
||||
string nota = !string.IsNullOrEmpty(d.consFattaNotBan) ? d.consFattaNotBan.Trim() : string.Empty;
|
||||
cf.consFattaNotBan= nota;
|
||||
cf.consFattaImpor=d.consFattaImpor;
|
||||
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;
|
||||
}
|
||||
|
||||
lst.Add(o);
|
||||
}
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
@ -668,13 +683,13 @@ namespace ApiSoftway.Controllers
|
||||
string usr = getClaimValueByToken(token, "codice");
|
||||
try
|
||||
{
|
||||
|
||||
ConsegnaTable ct = fillConsegna(model, token,DateTime.Now);
|
||||
//string tecnico = getClaimValueByToken(token, "tccodice");
|
||||
if (await checkConsegnaPresente(token, model) == 0)
|
||||
if (await checkConsegnaPresente(token, ct) == 0)
|
||||
{
|
||||
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Consegna t = fillConsegna(model, token, dateTime);
|
||||
ConsegnaTable t = fillConsegna(model, token, dateTime);
|
||||
//Step 1: mi calcolo il nuovo seriale
|
||||
|
||||
_consegne = _consegne_context.Cons;
|
||||
@ -693,10 +708,12 @@ namespace ApiSoftway.Controllers
|
||||
var ti = await _sbrord.Where(t => t.Brserial.Equals(model.Serial)).FirstAsync();
|
||||
string _committente = ti.Brcodcom;
|
||||
string _cliFatturazione = ti.Brclifat;
|
||||
int seque = ti.Brnumseq.Value;
|
||||
t.Cca = _committente;
|
||||
t.Ccda=_cliFatturazione;
|
||||
t.Tcda = "C";
|
||||
t.Tca = "C";
|
||||
t.Cprownum = seque;
|
||||
|
||||
|
||||
|
||||
//Step 3 : testata
|
||||
Consegna_m m = new Consegna_m();
|
||||
@ -749,10 +766,49 @@ namespace ApiSoftway.Controllers
|
||||
try
|
||||
{
|
||||
|
||||
ConsegnaTable ct = fillConsegna(model, token, DateTime.Now);
|
||||
//string tecnico = getClaimValueByToken(token, "tccodice");
|
||||
if (await checkConsegnaPresente(token, model) == 0)
|
||||
if (await checkConsegnaPresente(token, ct) == 0)
|
||||
{
|
||||
Consegna t = fillConsegnaNonEffettuata(model, token);
|
||||
DateTime dateTime = DateTime.Now;
|
||||
ConsegnaTable t = fillConsegnaNonEffettuata(model, token);
|
||||
|
||||
//Step 1: mi calcolo il nuovo seriale
|
||||
_consegne = _consegne_context.Cons;
|
||||
var ser = await _consegne.Take(1).OrderByDescending(t => t.Pisergir).ToListAsync();
|
||||
string ultSer = "0";
|
||||
if (ser != null && ser.Count > 0)
|
||||
{
|
||||
ultSer = ser.First().Pisergir;
|
||||
}
|
||||
|
||||
string newSer = calcolaNuovoSeriale(ultSer);
|
||||
t.Pisergir = newSer;
|
||||
|
||||
//Steo 2: mi ricavo i dati da inserire i GESASMOVIB. Li leggo dalla GESASBR_ORD
|
||||
_sbrord = _sbrord_context.Cons;
|
||||
var ti = await _sbrord.Where(t => t.Brserial.Equals(model.Serial)).FirstAsync();
|
||||
string _committente = ti.Brcodcom;
|
||||
string _cliFatturazione = ti.Brclifat;
|
||||
int seque = ti.Brnumseq.Value;
|
||||
t.Cca = _committente;
|
||||
t.Ccda = _cliFatturazione;
|
||||
t.Cprownum = seque;
|
||||
|
||||
|
||||
//Step 3 : testata
|
||||
Consegna_m m = new Consegna_m();
|
||||
m.Pisergir = t.Pisergir;
|
||||
m.Data = dateTime;
|
||||
m.Cpccchk = getCpccchk(10);
|
||||
using (var transactionM = _consegne_m_context.Database.BeginTransaction())
|
||||
{
|
||||
await _consegne_m_context.Cons.AddAsync(m);
|
||||
await _consegne_m_context.SaveChangesAsync();
|
||||
transactionM.Commit();
|
||||
}
|
||||
|
||||
//step 4 : riga (è sempre e solo una)
|
||||
using (var transaction = _consegne_context.Database.BeginTransaction())
|
||||
{
|
||||
await _consegne_context.Cons.AddAsync(t);
|
||||
@ -782,7 +838,7 @@ namespace ApiSoftway.Controllers
|
||||
}
|
||||
|
||||
|
||||
private async Task<int> checkConsegnaPresente(string token, Consegna model)
|
||||
private async Task<int> checkConsegnaPresente(string token, ConsegnaTable model)
|
||||
{
|
||||
int trovati = 0;
|
||||
_consegne = _consegne_context.Cons;
|
||||
@ -884,9 +940,9 @@ namespace ApiSoftway.Controllers
|
||||
|
||||
return item;
|
||||
}
|
||||
private Consegna fillConsegna(Consegna i, string token, DateTime d)
|
||||
private ConsegnaTable fillConsegna(Consegna i, string token, DateTime d)
|
||||
{
|
||||
Consegna r = new Consegna();
|
||||
ConsegnaTable r = new ConsegnaTable();
|
||||
|
||||
string usr = getClaimValueByToken(token, "codice");
|
||||
|
||||
@ -894,7 +950,7 @@ namespace ApiSoftway.Controllers
|
||||
r.Cprownum = i.Cprownum;
|
||||
r.Cprownum=i.Cprownum;
|
||||
r.Ccddd = i.Ccddd;
|
||||
r.cpccchk = i.cpccchk;
|
||||
r.cpccchk = getCpccchk(10);
|
||||
r.Ccda = i.Ccda;
|
||||
r.Dcda = i.Dcda;
|
||||
r.Pinotban = i.Pinotban;
|
||||
@ -913,8 +969,8 @@ namespace ApiSoftway.Controllers
|
||||
r.Tipob2 = i.Tipob2;
|
||||
r.Tipob =i.Tipob;
|
||||
r.Sdoc = i.Sdoc;
|
||||
r.Pisergir = i.Pisergir;
|
||||
r.Tcda=i.Tcda;
|
||||
r.Pisergir = i.Serial;
|
||||
r.Tcda="S";
|
||||
r.Tca = i.Tca;
|
||||
r.Cca = i.Cca;
|
||||
r.Dca = i.Dca;
|
||||
@ -927,16 +983,16 @@ namespace ApiSoftway.Controllers
|
||||
|
||||
return r;
|
||||
}
|
||||
private Consegna fillConsegnaNonEffettuata(Consegna i, string token)
|
||||
private ConsegnaTable fillConsegnaNonEffettuata(Consegna i, string token)
|
||||
{
|
||||
Consegna r = new Consegna();
|
||||
ConsegnaTable r = new ConsegnaTable();
|
||||
|
||||
string usr = getClaimValueByToken(token, "codice");
|
||||
|
||||
r.Piautist = usr;
|
||||
r.Cprownum = i.Cprownum;
|
||||
r.Ccddd = i.Ccddd;
|
||||
r.cpccchk = i.cpccchk;
|
||||
r.cpccchk = getCpccchk(10);
|
||||
r.Ccda = i.Ccda;
|
||||
r.Dcda = i.Dcda;
|
||||
r.Pinotban = i.Pinotban;
|
||||
@ -955,7 +1011,7 @@ namespace ApiSoftway.Controllers
|
||||
r.Tipob2 = i.Tipob2;
|
||||
r.Tipob = i.Tipob;
|
||||
r.Sdoc = i.Sdoc;
|
||||
r.Pisergir = i.Pisergir;
|
||||
r.Pisergir = i.Serial;
|
||||
//r.Tcda=i.Tcda;
|
||||
r.Tcda = "N";
|
||||
r.Tca = i.Tca;
|
||||
@ -964,6 +1020,7 @@ namespace ApiSoftway.Controllers
|
||||
r.Piconseg = i.Piconseg;
|
||||
r.Pimezzo = i.Pimezzo;
|
||||
r.Piimport = i.Piimport;
|
||||
r.Serial=i.Serial;
|
||||
|
||||
|
||||
|
||||
@ -998,7 +1055,7 @@ namespace ApiSoftway.Controllers
|
||||
r.Tipob2 = i.Tipob2;
|
||||
r.Tipob = i.Tipob;
|
||||
r.Sdoc = i.Sdoc;
|
||||
r.Pisergir = i.Pisergir;
|
||||
r.Pisergir = i.Serial;
|
||||
r.Tcda = i.Tcda;
|
||||
r.Tca = i.Tca;
|
||||
r.Cca = i.Cca;
|
||||
|
||||
@ -4,10 +4,8 @@ namespace ApiSoftway.Models
|
||||
{
|
||||
public class Consegna
|
||||
{
|
||||
[Key]
|
||||
public string? Pisergir { get; set; }
|
||||
|
||||
[Key]
|
||||
//versione iniziale
|
||||
public string? Serial { get; set; }
|
||||
public int? Cprownum { get; set; }
|
||||
public string? Tcda { get; set; }
|
||||
public string? Ccda { get; set; }
|
||||
@ -35,7 +33,5 @@ namespace ApiSoftway.Models
|
||||
public decimal? Piimport { get; set; }
|
||||
public string? Pinotimp { get; set; }
|
||||
public string? Pinotban { get; set; }
|
||||
public string? Serial { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
40
Models/ConsegnaTable.cs
Normal file
40
Models/ConsegnaTable.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ApiSoftway.Models
|
||||
{
|
||||
public class ConsegnaTable
|
||||
{
|
||||
[Key]
|
||||
public string? Pisergir { get; set; }
|
||||
|
||||
[Key]
|
||||
public int? Cprownum { get; set; }
|
||||
public string? Tcda { get; set; }
|
||||
public string? Ccda { get; set; }
|
||||
public string? Dcda { get; set; }
|
||||
public string? Tca { get; set; }
|
||||
public string? Cca { get; set; }
|
||||
public string? Dca { get; set; }
|
||||
public string? Tipob { get; set; }
|
||||
public int? Nbanc { get; set; }
|
||||
public string? Descb { get; set; }
|
||||
public string? Tipob1 { get; set; }
|
||||
public string? Tipob2 { get; set; }
|
||||
public string? Ccddd { get; set; }
|
||||
public string? Ccadd { get; set; }
|
||||
public string? Ndoc { get; set; }
|
||||
public string? Sdoc { get; set; }
|
||||
public DateTime? Datdoc { get; set; }
|
||||
public string? cpccchk { get; set; }
|
||||
public string? Piconseg { get; set; }
|
||||
public string? Pimezzo { get; set; }
|
||||
public string? Piautist { get; set; }
|
||||
public int? Pibansca { get; set; }
|
||||
|
||||
[System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")]
|
||||
public decimal? Piimport { get; set; }
|
||||
public string? Pinotimp { get; set; }
|
||||
public string? Pinotban { get; set; }
|
||||
public string? Serial { get; set; }
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ namespace ApiSoftway.Models.Gesa_DbContext
|
||||
public class GESA_CONSEGNE_DbContext : DbContext
|
||||
{
|
||||
/// <summary></summary>
|
||||
public DbSet<Consegna>? Cons { get; set; }
|
||||
public DbSet<ConsegnaTable>? Cons { get; set; }
|
||||
|
||||
/// <summary></summary>
|
||||
public GESA_CONSEGNE_DbContext(DbContextOptions<GESA_CONSEGNE_DbContext> options) : base(options)
|
||||
@ -15,8 +15,8 @@ namespace ApiSoftway.Models.Gesa_DbContext
|
||||
/// <summary></summary>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Consegna>().ToTable("GESASMOVIB");
|
||||
modelBuilder.Entity<Consegna>().HasKey(table => new {
|
||||
modelBuilder.Entity<ConsegnaTable>().ToTable("GESASMOVIB");
|
||||
modelBuilder.Entity<ConsegnaTable>().HasKey(table => new {
|
||||
table.Pisergir,
|
||||
table.Cprownum
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user