controllo partita iva e codice fiscale
This commit is contained in:
parent
3a537c8e8e
commit
780ba2aec5
@ -97,32 +97,72 @@ namespace VirtualTask.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Create(Anag model)
|
public IActionResult Create(Anag model)
|
||||||
{
|
{
|
||||||
SessionHelper helper = new SessionHelper(this);
|
|
||||||
|
|
||||||
token = helper.GetStringValue("tok");
|
if (ModelState.IsValid)
|
||||||
tenant = helper.GetStringValue("tenant");
|
|
||||||
model.ancodazi=tenant;
|
|
||||||
apiUrl = helper.GetStringValue("apiUrl");
|
|
||||||
urlBase = apiUrl + "anagrafiche/add";
|
|
||||||
urlBase = urlBase + "?token=" + token;
|
|
||||||
Uri baseAddress = new Uri(urlBase);
|
|
||||||
client = new HttpClient();
|
|
||||||
client.BaseAddress = baseAddress;
|
|
||||||
model.ancodice = getNewSeriale();
|
|
||||||
string data = JsonConvert.SerializeObject(model);
|
|
||||||
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
||||||
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
return RedirectToAction("Index");
|
bool bcodfiscOK = false;
|
||||||
|
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 (!bcodfiscOK)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("andescri", "Codice Fiscale non corretto");
|
||||||
|
}
|
||||||
|
if (!bparivaOK)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("anpariva", "Partita Iva non corretta");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bcodfiscOK)
|
||||||
|
{
|
||||||
|
SessionHelper helper = new SessionHelper(this);
|
||||||
|
|
||||||
|
token = helper.GetStringValue("tok");
|
||||||
|
tenant = helper.GetStringValue("tenant");
|
||||||
|
model.ancodazi = tenant;
|
||||||
|
apiUrl = helper.GetStringValue("apiUrl");
|
||||||
|
urlBase = apiUrl + "anagrafiche/add";
|
||||||
|
urlBase = urlBase + "?token=" + token;
|
||||||
|
Uri baseAddress = new Uri(urlBase);
|
||||||
|
client = new HttpClient();
|
||||||
|
client.BaseAddress = baseAddress;
|
||||||
|
model.ancodice = getNewSeriale();
|
||||||
|
string data = JsonConvert.SerializeObject(model);
|
||||||
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
||||||
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errMes = response.Content.ReadAsStringAsync().Result;
|
||||||
|
helper.SetStringValue("errMsg", errMes);
|
||||||
|
return RedirectToAction("Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return View("Create", model);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errMes = response.Content.ReadAsStringAsync().Result;
|
foreach (var Elemento in ModelState.Values)
|
||||||
helper.SetStringValue("errMsg", errMes);
|
{
|
||||||
return RedirectToAction("Error");
|
foreach (var Errore in Elemento.Errors)
|
||||||
|
{
|
||||||
|
string ErroreRilevato = Errore.ErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return RedirectToAction("Create");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion CREATE
|
#endregion CREATE
|
||||||
@ -368,5 +408,289 @@ namespace VirtualTask.Controllers
|
|||||||
var responseContent = await httpResponse.Content.ReadAsStringAsync();
|
var responseContent = await httpResponse.Content.ReadAsStringAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CodiceFiscale
|
||||||
|
{
|
||||||
|
public static bool VerificaCodiceFiscale(string Codice)
|
||||||
|
{
|
||||||
|
// Dato un Codice Fiscale verifica il codice di controllo
|
||||||
|
// Input: il Codice Fiscale da verificare, 16 caratteri
|
||||||
|
// Output: true/false
|
||||||
|
// 2010.12.05
|
||||||
|
Codice = Codice.ToUpper();
|
||||||
|
if (Codice.Length != 16)
|
||||||
|
return false; // errore
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Codice.Substring(15, 1) ==
|
||||||
|
CalcolaCodiceControllo(Codice.Substring(0, 15)))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static string CalcolaCodiceControllo(string Codice)
|
||||||
|
{
|
||||||
|
// Calcola il codice di controllo del Codice Fiscale
|
||||||
|
// Input: i primi 15 caratteri del Codice Fiscale
|
||||||
|
// Output: il codice di controllo
|
||||||
|
// 2010.12.05
|
||||||
|
int Contatore = 0;
|
||||||
|
Codice = Codice.ToUpper();
|
||||||
|
if (Codice.Length != 15)
|
||||||
|
return "0"; // zero: errore
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Codice.Length; i++)
|
||||||
|
{
|
||||||
|
Contatore += ValoreDelCarattere(Codice.Substring(i, 1), i);
|
||||||
|
}
|
||||||
|
Contatore %= 26; // si considera il resto
|
||||||
|
return Convert.ToChar(Contatore + 65).ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static int ValoreDelCarattere(string Carattere, int Posizione)
|
||||||
|
{
|
||||||
|
int Valore = 0;
|
||||||
|
switch (Carattere)
|
||||||
|
{
|
||||||
|
case "A":
|
||||||
|
case "0":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 1;
|
||||||
|
else
|
||||||
|
Valore = 0;
|
||||||
|
break;
|
||||||
|
case "B":
|
||||||
|
case "1":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 0;
|
||||||
|
else
|
||||||
|
Valore = 1;
|
||||||
|
break;
|
||||||
|
case "C":
|
||||||
|
case "2":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 5;
|
||||||
|
else
|
||||||
|
Valore = 2;
|
||||||
|
break;
|
||||||
|
case "D":
|
||||||
|
case "3":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 7;
|
||||||
|
else
|
||||||
|
Valore = 3;
|
||||||
|
break;
|
||||||
|
case "E":
|
||||||
|
case "4":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 9;
|
||||||
|
else
|
||||||
|
Valore = 4;
|
||||||
|
break;
|
||||||
|
case "F":
|
||||||
|
case "5":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 13;
|
||||||
|
else
|
||||||
|
Valore = 5;
|
||||||
|
break;
|
||||||
|
case "G":
|
||||||
|
case "6":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 15;
|
||||||
|
else
|
||||||
|
Valore = 6;
|
||||||
|
break;
|
||||||
|
case "H":
|
||||||
|
case "7":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 17;
|
||||||
|
else
|
||||||
|
Valore = 7;
|
||||||
|
break;
|
||||||
|
case "I":
|
||||||
|
case "8":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 19;
|
||||||
|
else
|
||||||
|
Valore = 8;
|
||||||
|
break;
|
||||||
|
case "J":
|
||||||
|
case "9":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 21;
|
||||||
|
else
|
||||||
|
Valore = 9;
|
||||||
|
break;
|
||||||
|
case "K":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 2;
|
||||||
|
else
|
||||||
|
Valore = 10;
|
||||||
|
break;
|
||||||
|
case "L":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 4;
|
||||||
|
else
|
||||||
|
Valore = 11;
|
||||||
|
break;
|
||||||
|
case "M":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 18;
|
||||||
|
else
|
||||||
|
Valore = 12;
|
||||||
|
break;
|
||||||
|
case "N":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 20;
|
||||||
|
else
|
||||||
|
Valore = 13;
|
||||||
|
break;
|
||||||
|
case "O":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 11;
|
||||||
|
else
|
||||||
|
Valore = 14;
|
||||||
|
break;
|
||||||
|
case "P":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 3;
|
||||||
|
else
|
||||||
|
Valore = 15;
|
||||||
|
break;
|
||||||
|
case "Q":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 6;
|
||||||
|
else
|
||||||
|
Valore = 16;
|
||||||
|
break;
|
||||||
|
case "R":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 8;
|
||||||
|
else
|
||||||
|
Valore = 17;
|
||||||
|
break;
|
||||||
|
case "S":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 12;
|
||||||
|
else
|
||||||
|
Valore = 18;
|
||||||
|
break;
|
||||||
|
case "T":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 14;
|
||||||
|
else
|
||||||
|
Valore = 19;
|
||||||
|
break;
|
||||||
|
case "U":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 16;
|
||||||
|
else
|
||||||
|
Valore = 20;
|
||||||
|
break;
|
||||||
|
case "V":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 10;
|
||||||
|
else
|
||||||
|
Valore = 21;
|
||||||
|
break;
|
||||||
|
case "W":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 22;
|
||||||
|
else
|
||||||
|
Valore = 22;
|
||||||
|
break;
|
||||||
|
case "X":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 25;
|
||||||
|
else
|
||||||
|
Valore = 23;
|
||||||
|
break;
|
||||||
|
case "Y":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 24;
|
||||||
|
else
|
||||||
|
Valore = 24;
|
||||||
|
break;
|
||||||
|
case "Z":
|
||||||
|
if ((Posizione % 2) == 0)
|
||||||
|
Valore = 23;
|
||||||
|
else
|
||||||
|
Valore = 25;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Valore = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Valore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _checkVatItaFormale(string _myCountry, string _myVatNumber)
|
||||||
|
{
|
||||||
|
bool _isValid = false;
|
||||||
|
Int16 _ris;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_myCountry.CompareTo("IT") == 0)
|
||||||
|
{
|
||||||
|
if (_myVatNumber.Length == 11)
|
||||||
|
{
|
||||||
|
Int32 s = 0;
|
||||||
|
int n = 1;
|
||||||
|
|
||||||
|
// sommare ad s le cifre di posto dispari (dalla prima alla nona)
|
||||||
|
while (n <= 9)
|
||||||
|
{
|
||||||
|
_ris = Convert.ToInt16(_myVatNumber.Substring(n - 1, 1));
|
||||||
|
|
||||||
|
s = s + _ris;
|
||||||
|
|
||||||
|
n = n + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// per ogni cifra di posto pari (dalla seconda alla decima),
|
||||||
|
// moltiplicare la cifra per due e, se risulta piu' di 9, sottrarre 9;
|
||||||
|
// quindi aggiungere il risultato a s;
|
||||||
|
n = 2;
|
||||||
|
|
||||||
|
while (n <= 10)
|
||||||
|
{
|
||||||
|
_ris = Convert.ToInt16(_myVatNumber.Substring(n - 1, 1));
|
||||||
|
_ris = Convert.ToInt16(_ris * 2);
|
||||||
|
|
||||||
|
if (_ris > 9)
|
||||||
|
{
|
||||||
|
_ris = Convert.ToInt16(_ris - 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s + _ris;
|
||||||
|
|
||||||
|
n = n + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// si calcola il resto della divisione di s per 10
|
||||||
|
var _resto = s % 10;
|
||||||
|
|
||||||
|
// calcolo ultima cifra della partita iva
|
||||||
|
Int16 c = Convert.ToInt16((_resto == 0) ? 0 : 10 - _resto);
|
||||||
|
|
||||||
|
_isValid = Convert.ToInt16(_myVatNumber.Substring(10, 1)) == c ? true : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// noop
|
||||||
|
_isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ namespace VirtualTask.Models
|
|||||||
/// <summary>pec</summary>
|
/// <summary>pec</summary>
|
||||||
public string? an_empec { get; set; }
|
public string? an_empec { get; set; }
|
||||||
|
|
||||||
[Display(Name = "RAGIONE SOCIALE")]
|
[Display(Name = "RAGIONE SOCIALE"), Required(ErrorMessage = "Ragione sociale obbligatoria")]
|
||||||
/// <summary>descrizione </summary>
|
/// <summary>descrizione </summary>
|
||||||
public string? andescri { get; set; }
|
public string? andescri { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<form asp-action="Create">
|
<form asp-action="Create">
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
@Html.ValidationSummary(false, "", new { @class = "text-danger" })
|
||||||
|
|
||||||
<input type="hidden" id="antipcon" value="C" name="antipcon" />
|
<input type="hidden" id="antipcon" value="C" name="antipcon" />
|
||||||
@Html.HiddenFor(x => x.andtobso)
|
@Html.HiddenFor(x => x.andtobso)
|
||||||
@Html.HiddenFor(x => x.annumlis)
|
@Html.HiddenFor(x => x.annumlis)
|
||||||
@ -20,43 +22,42 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="andescri" class="control-label"></label>
|
<label asp-for="andescri" class="control-label"></label>
|
||||||
<input asp-for="andescri" class="form-control" />
|
<input asp-for="andescri" class="form-control" />
|
||||||
<span asp-validation-for="andescri" class="text-danger"></span>
|
@* <span asp-validation-for="andescri" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="ancodfis" class="control-label"></label>
|
<label asp-for="ancodfis" class="control-label"></label>
|
||||||
<input asp-for="ancodfis" class="form-control" />
|
<input asp-for="ancodfis" class="form-control" />
|
||||||
<span asp-validation-for="ancodfis" class="text-danger"></span>
|
@* <span asp-validation-for="ancodfis" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="anpariva" class="control-label"></label>
|
<label asp-for="anpariva" class="control-label"></label>
|
||||||
<input asp-for="anpariva" class="form-control" />
|
<input asp-for="anpariva" class="form-control" />
|
||||||
<span asp-validation-for="anpariva" class="text-danger"></span>
|
@* <span asp-validation-for="anpariva" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="anindiri" class="control-label"></label>
|
<label asp-for="anindiri" class="control-label"></label>
|
||||||
<input asp-for="anindiri" class="form-control" />
|
<input asp-for="anindiri" class="form-control" />
|
||||||
<span asp-validation-for="anindiri" class="text-danger"></span>
|
@* <span asp-validation-for="anindiri" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="antelefo" class="control-label"></label>
|
<label asp-for="antelefo" class="control-label"></label>
|
||||||
<input asp-for="antelefo" class="form-control" />
|
<input asp-for="antelefo" class="form-control" />
|
||||||
<span asp-validation-for="antelefo" class="text-danger"></span>
|
@* <span asp-validation-for="antelefo" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="annumcel" class="control-label"></label>
|
<label asp-for="annumcel" class="control-label"></label>
|
||||||
<input asp-for="annumcel" class="form-control" />
|
<input asp-for="annumcel" class="form-control" />
|
||||||
<span asp-validation-for="annumcel" class="text-danger"></span>
|
@* <span asp-validation-for="annumcel" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="an_email" class="control-label"></label>
|
<label asp-for="an_email" class="control-label"></label>
|
||||||
<input asp-for="an_email" class="form-control" />
|
<input asp-for="an_email" class="form-control" />
|
||||||
<span asp-validation-for="an_email" class="text-danger"></span>
|
@* <span asp-validation-for="an_email" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="an_empec" class="control-label"></label>
|
<label asp-for="an_empec" class="control-label"></label>
|
||||||
<input asp-for="an_empec" class="form-control" />
|
<input asp-for="an_empec" class="form-control" />
|
||||||
<span asp-validation-for="an_empec" class="text-danger"></span>
|
@* <span asp-validation-for="an_empec" class="text-danger"></span>*@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user