diff --git a/Controllers/AnagController.cs b/Controllers/AnagController.cs index 4b8f35b..b6ab9fd 100644 --- a/Controllers/AnagController.cs +++ b/Controllers/AnagController.cs @@ -24,6 +24,8 @@ namespace VirtualTask.Controllers HttpClient client; string _serchiam = "SER_ANAGRA"; string admin = string.Empty; + //seriale commessa + string _sercomm = "SER_COMMES"; private readonly IConfiguration _configuration; @@ -108,6 +110,7 @@ namespace VirtualTask.Controllers [HttpPost] public IActionResult Create(Anag model) { + AnagCommImp anagCommImp = new AnagCommImp(); if (ModelState.IsValid) { @@ -115,8 +118,25 @@ namespace VirtualTask.Controllers bool bparivaOK = false; string sCodFis = !string.IsNullOrEmpty(model.ancodfis) ? model.ancodfis : string.Empty; string sParIva = !string.IsNullOrEmpty(model.anpariva) ? model.anpariva : string.Empty; - bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis); - bparivaOK = _checkVatItaFormale("IT", sParIva); + + if (string.IsNullOrEmpty(sParIva)) + { + bparivaOK = true; + } + else + { + bparivaOK = _checkVatItaFormale("IT", sParIva); + } + + if (string.IsNullOrEmpty(sCodFis)) + { + bparivaOK = true; + } + else + { + bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis); + + } if (!bcodfiscOK) { @@ -137,15 +157,41 @@ namespace VirtualTask.Controllers apiUrl = helper.GetStringValue("apiUrl"); admin = helper.GetStringValue("admin"); ViewBag.Admin = admin; - urlBase = apiUrl + "anagrafiche/add"; + //urlBase = apiUrl + "anagrafiche/add"; + urlBase = apiUrl + "anagrafiche/addcommImp"; urlBase = urlBase + "?token=" + token; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); client.BaseAddress = baseAddress; model.ancodice = getNewSeriale(); - string data = JsonConvert.SerializeObject(model); + + //cliente + anagCommImp.cli = model; + + //impianto generico + Impianto impianto = new Impianto(); + + var codcli = model.ancodice.Substring(model.ancodice.Length - 6, 6); + anagCommImp.imp = impianto; + anagCommImp.imp.imcodimp = "IMP_" + codcli; + anagCommImp.imp.imdescri = "IMP_GEN_" + codcli; + anagCommImp.imp.imultcli = model.ancodice; + anagCommImp.imp.imindiri2 = model.anindiri; + + //commmessa generica + CommesseVT_Table commessa = new CommesseVT_Table(); + + anagCommImp.comm = commessa; + anagCommImp.comm.laserial = GetNewSerialeComm(); + anagCommImp.comm.lacodcom = "COM_" + model.ancodice.Substring(model.ancodice.Length - 6, 6); + anagCommImp.comm.ladeslav = "COMM_GEN_" + model.ancodice; + anagCommImp.comm.lacodcli = model.ancodice; + anagCommImp.comm.lacodimp = anagCommImp.imp.imcodimp; + + string data = JsonConvert.SerializeObject(anagCommImp); StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; + if (response.IsSuccessStatusCode) { return RedirectToAction("Index"); @@ -371,6 +417,8 @@ namespace VirtualTask.Controllers #endregion DELETE + #region metodi interni + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { @@ -703,7 +751,6 @@ namespace VirtualTask.Controllers } } } - catch { // noop @@ -713,5 +760,62 @@ namespace VirtualTask.Controllers return _isValid; } + //per aggiornare seriale commessa tabella progressivi + private string GetNewSerialeComm() + { + int p = -1; + string seriale = string.Empty; + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "progressiviList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + List progressivo = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + progressivo = JsonConvert.DeserializeObject>(data); + var last = progressivo.Where(x => x.tipo_prog.Equals(_sercomm)).First(); + p = last.val_prog; + p++; + seriale = Convert.ToString(p); + seriale = seriale.PadLeft(10, '0'); + Progressivo update = new Progressivo(); + update.val_prog = p; + update.tipo_prog = _sercomm; + update.azienda = tenant; + UpdateSeriale(update); + } + return seriale; + } + + private async void UpdateSeriale(Progressivo p) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + apiUrl = helper.GetStringValue("apiUrl"); + tenant = helper.GetStringValue("tenant"); + urlBase = apiUrl + "progressivo/mod"; + urlBase = urlBase + "?token=" + token; + + client = new HttpClient(); + + var stringPayload = JsonConvert.SerializeObject(p); + var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); + var httpResponse = await client.PostAsync(urlBase, httpContent); + + if (httpResponse.Content != null) + { + var responseContent = await httpResponse.Content.ReadAsStringAsync(); + } + } + + #endregion altri metodi + } } diff --git a/Controllers/CommesseVTController.cs b/Controllers/CommesseVTController.cs index c146795..ac4cb74 100644 --- a/Controllers/CommesseVTController.cs +++ b/Controllers/CommesseVTController.cs @@ -209,8 +209,8 @@ namespace VirtualTask.Controllers client.BaseAddress = baseAddress; - ViewBag.Impianti = getImpianti(); - ViewBag.Anag = getClienti(); + //ViewBag.Impianti = getImpianti(); + //ViewBag.Anag = getClienti(); //urlBase = "http://10.0.0.187:8000/api/Polo" //Uri baseAddress = new Uri(urlBase); //client = new HttpClient(); @@ -234,6 +234,8 @@ namespace VirtualTask.Controllers return RedirectToAction("Error"); } + ViewBag.Impianti = getImpianti(); + ViewBag.Anag = getClienti(); return View(commessa); } @@ -326,7 +328,7 @@ namespace VirtualTask.Controllers model.lacodazi = tenant; model.ladatchi = DateTime.Now; apiUrl = helper.GetStringValue("apiUrl"); - urlBase = apiUrl + "commesse/del"; + urlBase = apiUrl + "commesseVT/del"; urlBase = urlBase + "?token=" + token; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); diff --git a/Controllers/ImpiantiController.cs b/Controllers/ImpiantiController.cs index cbc5654..b52c266 100644 --- a/Controllers/ImpiantiController.cs +++ b/Controllers/ImpiantiController.cs @@ -355,20 +355,12 @@ namespace VirtualTask.Controllers { SelectListItem listItem = new SelectListItem(); - //if (role == modelList.First()) - //{ - // listItem.Value = string.Empty; - // listItem.Text = ""; - // selectItems.Add(listItem); - //} - //else - //{ listItem.Value = role.ancodice; listItem.Text = role.andescri; selectItems.Add(listItem); - //} } } + return selectItems; } diff --git a/Models/AnagCommImp.cs b/Models/AnagCommImp.cs new file mode 100644 index 0000000..885410e --- /dev/null +++ b/Models/AnagCommImp.cs @@ -0,0 +1,11 @@ +namespace VirtualTask.Models +{ + public class AnagCommImp + { + public Anag? cli { get; set; } + + public CommesseVT_Table? comm { get; set; } + + public Impianto? imp { get; set; } + } +}