MICHELE: creazione impianto generico/commessa generica quando creo nuovo cliente

This commit is contained in:
michele 2023-11-28 12:42:53 +01:00
parent 58f0c2f3c6
commit 1bcdf3fb1a
4 changed files with 126 additions and 17 deletions

View File

@ -24,6 +24,8 @@ namespace VirtualTask.Controllers
HttpClient client; HttpClient client;
string _serchiam = "SER_ANAGRA"; string _serchiam = "SER_ANAGRA";
string admin = string.Empty; string admin = string.Empty;
//seriale commessa
string _sercomm = "SER_COMMES";
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
@ -108,6 +110,7 @@ namespace VirtualTask.Controllers
[HttpPost] [HttpPost]
public IActionResult Create(Anag model) public IActionResult Create(Anag model)
{ {
AnagCommImp anagCommImp = new AnagCommImp();
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
@ -115,8 +118,25 @@ namespace VirtualTask.Controllers
bool bparivaOK = false; bool bparivaOK = false;
string sCodFis = !string.IsNullOrEmpty(model.ancodfis) ? model.ancodfis : string.Empty; string sCodFis = !string.IsNullOrEmpty(model.ancodfis) ? model.ancodfis : string.Empty;
string sParIva = !string.IsNullOrEmpty(model.anpariva) ? model.anpariva : string.Empty; string sParIva = !string.IsNullOrEmpty(model.anpariva) ? model.anpariva : string.Empty;
bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis);
if (string.IsNullOrEmpty(sParIva))
{
bparivaOK = true;
}
else
{
bparivaOK = _checkVatItaFormale("IT", sParIva); bparivaOK = _checkVatItaFormale("IT", sParIva);
}
if (string.IsNullOrEmpty(sCodFis))
{
bparivaOK = true;
}
else
{
bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis);
}
if (!bcodfiscOK) if (!bcodfiscOK)
{ {
@ -137,15 +157,41 @@ namespace VirtualTask.Controllers
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
ViewBag.Admin = admin; ViewBag.Admin = admin;
urlBase = apiUrl + "anagrafiche/add"; //urlBase = apiUrl + "anagrafiche/add";
urlBase = apiUrl + "anagrafiche/addcommImp";
urlBase = urlBase + "?token=" + token; urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase); Uri baseAddress = new Uri(urlBase);
client = new HttpClient(); client = new HttpClient();
client.BaseAddress = baseAddress; client.BaseAddress = baseAddress;
model.ancodice = getNewSeriale(); 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"); StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
return RedirectToAction("Index"); return RedirectToAction("Index");
@ -371,6 +417,8 @@ namespace VirtualTask.Controllers
#endregion DELETE #endregion DELETE
#region metodi interni
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
@ -703,7 +751,6 @@ namespace VirtualTask.Controllers
} }
} }
} }
catch catch
{ {
// noop // noop
@ -713,5 +760,62 @@ namespace VirtualTask.Controllers
return _isValid; 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> progressivo = new List<Progressivo>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
progressivo = JsonConvert.DeserializeObject<List<Progressivo>>(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
} }
} }

View File

@ -209,8 +209,8 @@ namespace VirtualTask.Controllers
client.BaseAddress = baseAddress; client.BaseAddress = baseAddress;
ViewBag.Impianti = getImpianti(); //ViewBag.Impianti = getImpianti();
ViewBag.Anag = getClienti(); //ViewBag.Anag = getClienti();
//urlBase = "http://10.0.0.187:8000/api/Polo" //urlBase = "http://10.0.0.187:8000/api/Polo"
//Uri baseAddress = new Uri(urlBase); //Uri baseAddress = new Uri(urlBase);
//client = new HttpClient(); //client = new HttpClient();
@ -234,6 +234,8 @@ namespace VirtualTask.Controllers
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
ViewBag.Impianti = getImpianti();
ViewBag.Anag = getClienti();
return View(commessa); return View(commessa);
} }
@ -326,7 +328,7 @@ namespace VirtualTask.Controllers
model.lacodazi = tenant; model.lacodazi = tenant;
model.ladatchi = DateTime.Now; model.ladatchi = DateTime.Now;
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "commesse/del"; urlBase = apiUrl + "commesseVT/del";
urlBase = urlBase + "?token=" + token; urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase); Uri baseAddress = new Uri(urlBase);
client = new HttpClient(); client = new HttpClient();

View File

@ -355,20 +355,12 @@ namespace VirtualTask.Controllers
{ {
SelectListItem listItem = new SelectListItem(); SelectListItem listItem = new SelectListItem();
//if (role == modelList.First())
//{
// listItem.Value = string.Empty;
// listItem.Text = "";
// selectItems.Add(listItem);
//}
//else
//{
listItem.Value = role.ancodice; listItem.Value = role.ancodice;
listItem.Text = role.andescri; listItem.Text = role.andescri;
selectItems.Add(listItem); selectItems.Add(listItem);
//}
} }
} }
return selectItems; return selectItems;
} }

11
Models/AnagCommImp.cs Normal file
View File

@ -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; }
}
}