From c22e2ef0e3d36b715e4a9b89c39d6a5eedd4084b Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Thu, 20 Mar 2025 14:42:12 +0100 Subject: [PATCH] gestione calendario --- Controllers/GiriController.cs | 56 +++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index 3329a8f..324c228 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -329,7 +329,12 @@ namespace ApiSoftway.Controllers 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; + string nota= "*****" + newData.ToString() + d.Brnote; + if(nota.Length>50) + { + nota = nota.Substring(0, 50); + } + d.Brnote = nota; using (var transactionDest = _sbrordTable_context.Database.BeginTransaction()) { @@ -552,39 +557,52 @@ namespace ApiSoftway.Controllers string usr = getClaimValueByToken(token, "codice"); bool btnChiudiVisible = true; bool btnNonChiudiVisible = true; + List lstDest=new List(); + List lst = new List(); + 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; - var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr) && t.DataCarico != null && t.DataCarico == data - && !string.IsNullOrEmpty(t.serialeGiro) - - ).OrderBy(t => t.serialeGiro).ToListAsync(); + if (data != DateTime.Today) + { + //Sto visualizzando le destinazioni FUTURE che non posso consegnare + //la data è diversa dalla data odierna: disabilito i bottoni e cerco le destinazioni tra quelle che che NON sono state validate + //e che quindi NON hanno caricato i bancali (serialeGiro nullo) + btnChiudiVisible = false; + btnNonChiudiVisible = false; + _destinazioni = _daCreareDest_context.GiriDaCreare; + lstDest = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr) + && t.DataCarico != null && t.DataCarico == dataGiro).OrderByDescending(t => t.DataCarico).ToListAsync(); + + string serFake = DateTime.Now.ToString("yyyyMMddHHmmss"); + //devo valorizzare un seriale giro fake per rispettare l'ordinamento/filtro che faccio sotto + foreach (Destinazioni d in lstDest) + { + + d.serialeGiro = serFake; + } + } + else + { + //Sto visualizzando le destinazioni di OGGI che devo lavorare + // sono nella data odierna: devo far vedere SOLO le destinazioni validate con i bancali caricati (serialeGiro NON nullo) + _destinazioni = _destinazioni_context.Destinazioni; + lstDest = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr) && t.DataCarico != null && t.DataCarico == data + && !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) + foreach (Destinazioni d in lstDest) { if(giro==0) {