Introduzione validazione p.iva

This commit is contained in:
Luca 2018-03-01 22:05:54 +01:00
parent eec00ab614
commit 97bc123997
5 changed files with 95 additions and 32 deletions

View File

@ -13,8 +13,8 @@ switch (post('op')) {
$dbo->update('an_anagrafiche', [
'ragione_sociale' => $post['ragione_sociale'],
'tipo' => $post['tipo'],
'piva' => $post['piva'],
'codice_fiscale' => $post['codice_fiscale'],
'piva' => trim(strtoupper($post['piva'])),
'codice_fiscale' => trim(strtoupper($post['codice_fiscale'])),
'data_nascita' => $post['data_nascita'],
'luogo_nascita' => $post['luogo_nascita'],
'sesso' => $post['sesso'],
@ -68,6 +68,21 @@ switch (post('op')) {
$_SESSION['infos'][] = str_replace('_NAME_', '"'.$post['ragione_sociale'].'"', "Informazioni per l'anagrafica _NAME_ salvate correttamente!");
//validazione piva.
$check_vat_number = Validate::isValidVatNumber(strtoupper($post['piva']));
//print_r($check_vat_number);
//exit();
//se $check_vat_number non è null e la riposta è negativa --> mostro il messaggio di avviso.
if ((!is_null($check_vat_number)) and (!$check_vat_number->valid)){
if (!empty($check_vat_number->error->info)){
$_SESSION['errors'][] = $check_vat_number->error->info;
}else{
$_SESSION['errors'][] = tr('Attenzione questa partita IVA non sembra essere valida: ').strtoupper($post['piva']);
}
}
// Aggiorno il codice anagrafica se non è già presente, altrimenti lo ignoro
$esiste = $dbo->fetchNum('SELECT idanagrafica FROM an_anagrafiche WHERE codice='.prepare($post['codice']).' AND NOT idanagrafica='.prepare($id_record));

View File

@ -47,11 +47,11 @@ if (!$cliente) {
<div class="row">
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Partita IVA'); ?>", "maxlength": 13, "name": "piva", "class": "text-center", "value": "$piva$" ]}
{[ "type": "text", "label": "<?php echo tr('Partita IVA'); ?>", "maxlength": 13, "name": "piva", "class": "text-center text-uppercase", "value": "$piva$" ]}
</div>
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Codice fiscale'); ?>", "maxlength": 16, "name": "codice_fiscale", "class": "text-center", "value": "$codice_fiscale$" ]}
{[ "type": "text", "label": "<?php echo tr('Codice fiscale'); ?>", "maxlength": 16, "name": "codice_fiscale", "class": "text-center text-uppercase", "value": "$codice_fiscale$" ]}
</div>
<div class="col-md-4">

View File

@ -41,9 +41,14 @@ switch (post('op')) {
$check_email = Validate::isValidEmail($post['from_address'],1,1);
//print_r($check_email);
//exit();
//se $check_email non è null, l'indirizzo email è settato e la riposta è negativa --> mostro il messaggio di avviso.
if ((!is_null($check_email)) and (!$check_email->smtp_check) and (!empty($post['from_address']))){
$_SESSION['errors'][] = tr('Attenzione questo indirizzo non sembra essere valido: ').$post['from_address'];
//se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
if ((!is_null($check_email)) and (!$check_email->smtp_check)){
if (!empty($check_email->error->info)){
$_SESSION['errors'][] = $check_email->error->info;
}else{
$_SESSION['errors'][] = tr('Attenzione questo indirizzo non sembra essere valido: ').$post['from_address'];
}
}

View File

@ -7,6 +7,60 @@
*/
class VALIDATE
{
/**
* Controlla se la partita iva inserita è valida.
*
* @param string $vat_number
*
* @return object
*/
public static function isValidVatNumber($vat_number)
{
$access_key = Settings::get('apilayer API key for VAT number');
if ((!empty($vat_number)) and (!empty($access_key))){
if (strpos($vat_number, 'IT') === false) {
$vat_number = 'IT'.$vat_number;
}
$ch = curl_init();
$qs = "&vat_number=" . urlencode(strtoupper($vat_number));
$url = "http://apilayer.net/api/validate?access_key=$access_key" . $qs;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = json_decode(curl_exec($ch));
curl_close($ch);
/*se la riposta è null imposto la relativa proprietà dell'oggetto a 0*/
if ($data->valid==null)
$data->valid = 0;
//$data->url = $url;
//$data->json_last_error = json_last_error();
//$data->json_last_error_msg = json_last_error_msg();
}
return $data;
}
/**
* Controlla se l'email inserita è valida.
*
@ -19,7 +73,7 @@ class VALIDATE
public static function isValidEmail($email, $format = 1, $smtp = 0)
{
$access_key = Settings::get('apilayer API key');
$access_key = Settings::get('apilayer API key for Email');
/*$data = (object) [
'format_valid' => NULL,
@ -44,7 +98,7 @@ class VALIDATE
$data = json_decode(curl_exec($ch));
curl_close($ch);
/*se la riposta è null verficando il formato, il record mx o il server smtp imposto a false*/
/*se la riposta è null verficando il formato, il record mx o il server smtp imposto la relativa proprietà dell'oggetto a 0*/
if (($data->format_valid==null)and($format))
$data->format_valid = 0;
@ -64,31 +118,17 @@ class VALIDATE
*/
/* --- */
/*echo "format_valid: ".$data->format_valid;
echo "<br>\n";
echo "smtp_check: ".$data->smtp_check;
echo "<br>\n";
echo "mx_found: ".$data->mx_found;*/
//echo json_last_error();
//echo json_last_error_msg();
$data->json_last_error = json_last_error();
$data->json_last_error_msg = json_last_error_msg();
}
/*return [
'email' => $email,
'format_valid' => $data->format_valid,
'smtp_check' => $data->smtp_check,
'mx_found' => $data->mx_found,
'json_last_error_msg' => json_last_error_msg(),
'json_last_error' => json_last_error(),
];*/
return $data;
return $data;
}
}

View File

@ -269,5 +269,8 @@ INSERT INTO `zz_email_print` (`id`, `id_email`, `id_print`) VALUES
(NULL, (SELECT `id` FROM `zz_emails` WHERE `name` = 'Consuntivo' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Contratti')), (SELECT `id` FROM `zz_prints` WHERE `name` = 'Consuntivo contratto')),
(NULL, (SELECT `id` FROM `zz_emails` WHERE `name` = 'Consuntivo' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Preventivi')), (SELECT `id` FROM `zz_prints` WHERE `name` = 'Consuntivo preventivo'));
-- apilayer API key (per validazione email, piva, indirizzo ecc...)
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`) VALUES (NULL, 'apilayer API key', '', 'string', '1', 'Generali');
-- apilayer API key (per validazione email)
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`) VALUES (NULL, 'apilayer API key for Email', '', 'string', '1', 'Generali');
-- apilayer API key (per validazione piva)
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`) VALUES (NULL, 'apilayer API key for VAT number', '', 'string', '1', 'Generali');