Migliore gestione dati persone fisiche con codice fiscale

git-svn-id: svn://10.65.10.50/branches/R_10_00@23137 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2015-11-30 16:15:33 +00:00
parent 88467f8086
commit 9b4d556bea
2 changed files with 128 additions and 41 deletions

View File

@ -1,8 +1,7 @@
#include <diction.h>
#include <lffiles.h>
#include <progind.h>
#include <recarray.h>
#include <relation.h>
#include <mask.h>
#include <validate.h>
#include "fe0100a.h"
@ -93,6 +92,31 @@ bool fe_is_nota_variazione(const TRectype& mov)
return false;
}
bool fe_decode_cofi(const TString& cofi, char& sex_nasc, TDate& dt_nasc, TString& com_nasc)
{
if (cofi.len() != 16 || !cf_check("", cofi))
return false;
const TFixed_string wm = "ABCDEHLMPRST"; // Controllo data di nascita
int anno = atoi(cofi.mid(6,2));
anno += anno < 25? 2000 : 1900;
const int mese = wm.find(cofi[8])+1;
int giorno = atoi(cofi.mid(9,2));
if (giorno > 40)
{
giorno -= 40;
sex_nasc = 'F';
}
else
sex_nasc = 'M';
com_nasc = cofi.mid(11,4);
return true;
}
///////////////////////////////////////////////////////////
// TAnagrafica
///////////////////////////////////////////////////////////
@ -247,6 +271,18 @@ const TString& TAnagrafica::stato_estero_UNICO() const
return get_tmp_string() = u;
}
const TString& TAnagrafica::stato_ISO_3166() const
{
TString& str = get_tmp_string();
if (_stato_estero <= 0)
str = "IT";
else
{
}
return str;
}
char TAnagrafica::is_black_list(const TDate& datareg) const
{
char is_black = ' ';
@ -299,6 +335,8 @@ bool TAnagrafica::init(const TRectype& rec)
if (rec.empty())
return false;
bool is_firm = false;
switch (rec.num())
{
case LF_OCCAS:
@ -322,7 +360,14 @@ bool TAnagrafica::init(const TRectype& rec)
_cap_res = rec.get(OCC_CAP);
build_ind_res(rec, OCC_INDIR, OCC_CIV);
if (_com_nasc.full() || (!_stato_estero && !real::is_natural(_cofi) || cf_check("", _cofi)))
{
_tipo = 'F';
if (_cofi.full() && (!_data_nasc.ok()) || _com_nasc.blank())
{
char sex = 'X';
fe_decode_cofi(_cofi, sex, _data_nasc, _com_nasc);
}
}
else
_tipo = 'G';
_allegato = _tipo == 'F' ? 6 : 2;
@ -340,9 +385,9 @@ bool TAnagrafica::init(const TRectype& rec)
_com_res = rec.get(ANA_COMRES);
build_ind_res(rec, ANA_INDRES, ANA_CIVRES);
_cap_res = rec.get(ANA_CAPRES);
// Dati di nascita persone fisiche
if (_tipo == 'F')
if (_tipo == 'F' || (italiano() && isalpha(_cofi[0])))
{
const long codana = rec.get_long(ANA_CODANAGR);
if (codana > 0)
@ -351,6 +396,11 @@ bool TAnagrafica::init(const TRectype& rec)
_data_nasc = anafis.get(ANF_DATANASC);
_stato_nasc = anafis.get_int(ANF_STATONASC);
_com_nasc = anafis.get(ANF_COMNASC);
if ((!_data_nasc.ok() || _com_nasc.blank()) && cf_check("", _cofi))
{
char sex = 'X';
fe_decode_cofi(_cofi, sex, _data_nasc, _com_nasc);
}
}
}
else
@ -361,8 +411,11 @@ bool TAnagrafica::init(const TRectype& rec)
const char tipoa = rec.get_char(NDT_TIPOA);
const long codana = rec.get_long(NDT_CODANAGR);
const bool good = init(LF_ANAG, tipoa, codana);
if (tipoa == 'G')
if (_tipo == 'G')
{
_ragsoc = rec.get(NDT_RAGSOC);
split_ragsoc();
}
return good;
}
break;
@ -377,49 +430,78 @@ bool TAnagrafica::init(const TRectype& rec)
_tipo = ' '; // Non faccio assunzioni sulla persona fisica
// Persona Fisica?
if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get(CLI_DATANASC).not_empty())
is_firm = (rec.get_char(CLI_TIPOAPER) == 'G' || _allegato==7) && (_allegato != 6);
if (!is_firm && rec.get(CLI_PAIV).full())
{
const long cod = rec.get_long(CLI_CODANAGPER);
if (cod > 0)
init(LF_ANAG, 'F', cod);
if (rec.get(CLI_DATANASC).not_empty())
{
_data_nasc = rec.get(CLI_DATANASC);
_tipo = 'F';
}
TString80 rs = rec.get(CLI_RAGSOC); rs.lower();
const char* soc[] = { "&", "azienda ", " sas ", " s.a.s.", " snc", " s.n.c.", " srl", " s.r.l.",
"coop.", "cooperativa", " s.n.c.", " srl", " s.r.l.", " s.p.a", " s.a.", NULL };
for (int s = 0; soc[s] && !is_firm; s++)
is_firm = rs.find(soc[s]) > 0;
if (!is_firm)
is_firm = rs.ends_with(" spa") || (rs.find(" di ") > 15); // Shopping Point di Karoline Reiner
}
if (!is_firm)
{
bool has_cofi = false; // Codice fiscale alfanumerico?
const TString& cli_cofi = rec.get(CLI_COFI);
if (cli_cofi.full() && isalpha(cli_cofi[0]))
has_cofi = cf_check(rec.get(CLI_STATOPAIV), cli_cofi);
if (_com_nasc.blank())
_com_nasc = rec.get(CLI_COMNASC);
if (_stato_nasc <= 0)
_stato_nasc = rec.get_int(CLI_STATONASC);
if (_com_nasc.blank() && _stato_nasc > 0)
// Persona Fisica?
if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get_date(CLI_DATANASC).ok() || has_cofi || _allegato == 6)
{
TString4 sn; sn.format("%03d", _stato_nasc);
const TString80 stato = cache().get("%STA", sn, "S0");
TISAM_recordset comuni("USE COMUNI\nFROM COM=Z\nTO STATO=\"0~\"");
double best = 0.8;
for (bool ok = comuni.move_first(); ok; ok = comuni.move_next())
const long cod = rec.get_long(CLI_CODANAGPER); // Percipiente?
if (cod > 0)
init(LF_ANAG, 'F', cod);
_tipo = 'F';
_data_nasc = rec.get_date(CLI_DATANASC);
if (!_data_nasc.ok() && has_cofi)
{
const TString& desc = comuni.get(COM_DENCOM).as_string();
const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato);
if (score > best)
char sex = 'X';
fe_decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc);
}
if (_com_nasc.blank())
{
_com_nasc = rec.get(CLI_COMNASC);
if (_com_nasc.blank() && has_cofi)
{
best = score;
_stato_nasc = 0;
_com_nasc = comuni.get(COM_COM).as_string();
if (best >= 1.0)
break;
char sex = 'X';
fe_decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc);
}
}
if (_stato_nasc <= 0)
_stato_nasc = rec.get_int(CLI_STATONASC);
if (_com_nasc.blank() && _stato_nasc > 0)
{
TString4 sn; sn.format("%03d", _stato_nasc);
const TString80 stato = cache().get("%STA", sn, "S0");
TISAM_recordset comuni("USE COMUNI\nFROM COM=Z\nTO STATO=\"0~\"");
double best = 0.8;
for (bool ok = comuni.move_first(); ok; ok = comuni.move_next())
{
const TString& desc = comuni.get(COM_DENCOM).as_string();
const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato);
if (score > best)
{
best = score;
_stato_nasc = 0;
_com_nasc = comuni.get(COM_COM).as_string();
if (best >= 1.0)
break;
}
}
}
}
}
// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
if (rec.get(CLI_COFI).not_empty())
if (rec.get(CLI_COFI).full())
_cofi = rec.get(CLI_COFI);
if (rec.get(CLI_PAIV).not_empty())
if (rec.get(CLI_PAIV).full())
_paiv = rec.get(CLI_PAIV);
if (_allegato != 5 && _allegato != 9)
@ -441,7 +523,8 @@ bool TAnagrafica::init(const TRectype& rec)
}
// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
_ragsoc = rec.get(CLI_RAGSOC);
_ragsoc = rec.get(CLI_RAGSOC);
_loc_res = rec.get(CLI_LOCCF);
_cap_res = rec.get(CLI_CAPCF);
_stato_estero = rec.get_int(CLI_STATOCF);
@ -463,12 +546,14 @@ bool TAnagrafica::init(const TRectype& rec)
else
{
_tipo = rec.get_char(CLI_TIPOPERS);
if (_tipo != 'F')
if (_tipo != 'F' || is_firm)
_tipo = 'G';
}
break;
}
}
if (_tipo == 'G' || _ragsoc.len() <= 30)
split_ragsoc();
break;
case LF_MOV:
return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI));
@ -607,12 +692,12 @@ const TString& TSpesometro_set::get_recapito(const TRectype& ndt, const char* nu
const TRectype& anag = cache().get(LF_ANAG, key);
if (prefisso)
{
if (strcmp(numero, "TEL") == 0)
if (xvt_str_same(numero, "TEL"))
{
numero = "TELRF";
prefisso = "PTELRF";
} else
if (strcmp(numero, "FAX") == 0)
if (xvt_str_same(numero, "FAX"))
{
numero = "FAXRF";
prefisso = "PFAXRF";

View File

@ -60,7 +60,8 @@ public:
const TString& via_residenza() const { return _via_res; }
const TString& civico_residenza() const { return _civ_res; }
const TString& CAP_residenza() const { return _cap_res; }
const TString& stato_ISO_3166() const; // Alpha-2 code
bool init(const TRectype& rec);
bool init(int num, const TString& codice);
bool init(int num, long codice);
@ -141,5 +142,6 @@ public:
// Utility
bool fe_is_nota_variazione(const TRectype& rec);
bool fe_decode_cofi(const TString& cofi, char& sex_nasc, TDate& dt_nasc, TString& com_nasc);
#endif