Patch level : nopatch

Files correlati     :
Commento        :

Implementazione FP
This commit is contained in:
Alessandro Bonazzi 2021-12-20 16:10:53 +01:00
parent cce5377cc4
commit 60a52ab73d

View File

@ -10,6 +10,8 @@
#include "../cg/cfban.h"
#include <alleg.h>
#include <anagr.h>
#include <clifo.h>
#include <cfven.h>
#include <doc.h>
#include <effetti.h>
#include <anafis.h>
@ -385,150 +387,158 @@ bool TAnagrafica::init(const TRectype& rec)
}
_pec = "";
_cod_EORI = rec.get(NDT_CODEORI);
_coddest = rec.get(NDT_CODDEST);
_coddest = rec.get(NDT_PADESTIN);
_pec = rec.get(NDT_PEC);
return good;
}
break;
case LF_CLIFO:
_cod_EORI = rec.get(ANA_CODEORI);
_allegato = rec.get_int(CLI_ALLEG);
if (_allegato == 4)
{
const long ca = rec.get_long(CLI_CODALLEG);
if (ca > 0)
return init(rec.get_char(CLI_TIPOCF), ca, EMPTY_STRING);
}
_tipo = ' '; // Non faccio assunzioni sulla persona fisica
is_firm = (rec.get_char(CLI_TIPOPERS) == 'G' || rec.get_char(CLI_TIPOAPER) == 'G' || _allegato == 7) && (_allegato != 6);
if (!is_firm && rec.get(CLI_PAIV).full())
{
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);
// Persona Fisica?
if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get_date(CLI_DATANASC).ok() || has_cofi || _allegato == 6)
_cod_EORI = rec.get(ANA_CODEORI);
_allegato = rec.get_int(CLI_ALLEG);
if (_allegato == 4)
{
const long cod = rec.get_long(CLI_CODANAGPER); // Percipiente?
if (cod > 0)
init(LF_ANAG, 'F', cod);
const long ca = rec.get_long(CLI_CODALLEG);
if (ca > 0)
return init(rec.get_char(CLI_TIPOCF), ca, EMPTY_STRING);
}
_tipo = 'F';
_data_nasc = rec.get_date(CLI_DATANASC);
if (!_data_nasc.ok() && has_cofi)
{
char sex = 'X';
decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc);
}
_tipo = ' '; // Non faccio assunzioni sulla persona fisica
if (_com_nasc.blank())
is_firm = (rec.get_char(CLI_TIPOPERS) == 'G' || rec.get_char(CLI_TIPOAPER) == 'G' || _allegato == 7) && (_allegato != 6);
if (!is_firm && rec.get(CLI_PAIV).full())
{
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);
// Persona Fisica?
if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get_date(CLI_DATANASC).ok() || has_cofi || _allegato == 6)
{
_com_nasc = rec.get(CLI_COMNASC);
if (_com_nasc.blank() && has_cofi)
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)
{
char sex = 'X';
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())
if (_com_nasc.blank())
{
const TString& desc = comuni.get(COM_DENCOM).as_string();
const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato);
if (score > best)
_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';
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
// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
_cofi = rec.get(CLI_COFI);
_paiv = rec.get(CLI_PAIV);
_stato_paiv = rec.get(CLI_STATOPAIV);
_cofi = rec.get(CLI_COFI);
_paiv = rec.get(CLI_PAIV);
_stato_paiv = rec.get(CLI_STATOPAIV);
if (_allegato != 5 && _allegato != 9)
{
if (_stato_paiv.blank() || _stato_paiv == "IT")
if (_allegato != 5 && _allegato != 9)
{
// Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota!
// I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente.
if (_paiv.blank() && pi_check(_stato_paiv, _cofi) && _cofi[0] < '8')
_paiv = _cofi;
if (_paiv.len() == 11 && pi_check(_stato_paiv, _paiv) && (_paiv[0] == '8' || _paiv[0] == '9'))
if (_stato_paiv.blank() || _stato_paiv == "IT")
{
if (_cofi.blank())
_cofi = _paiv;
_paiv.cut(0);
// Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota!
// I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente.
if (_paiv.blank() && pi_check(_stato_paiv, _cofi) && _cofi[0] < '8')
_paiv = _cofi;
if (_paiv.len() == 11 && pi_check(_stato_paiv, _paiv) && (_paiv[0] == '8' || _paiv[0] == '9'))
{
if (_cofi.blank())
_cofi = _paiv;
_paiv.cut(0);
}
}
}
}
// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
_ragsoc = rec.get(CLI_RAGSOC);
// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
_ragsoc = rec.get(CLI_RAGSOC);
_loc_res = rec.get(CLI_LOCCF);
_cap_res = rec.get(CLI_CAPCF);
_stato_estero = rec.get_int(CLI_STATOCF);
if (_stato_estero <= 0 && (_allegato == 5 || _allegato == 9)) // Estero CEE o extra-CEE
_stato_estero = -1; // Stato estero ignoto
_com_res = rec.get(CLI_COMCF);
build_ind_res(rec, CLI_INDCF, CLI_CIVCF);
_loc_res = rec.get(CLI_LOCCF);
_cap_res = rec.get(CLI_CAPCF);
_stato_estero = rec.get_int(CLI_STATOCF);
if (_stato_estero <= 0 && (_allegato == 5 || _allegato == 9)) // Estero CEE o extra-CEE
_stato_estero = -1; // Stato estero ignoto
_com_res = rec.get(CLI_COMCF);
build_ind_res(rec, CLI_INDCF, CLI_CIVCF);
if (_tipo != 'F' && _tipo != 'G')
{
switch (_allegato)
if (_tipo != 'F' && _tipo != 'G')
{
case 6: _tipo = 'F'; break; // Privato
case 7: _tipo = 'G'; break; // Ente pubblico
case 8: _tipo = 'G'; break; // Fallimento
default:
if (_com_nasc.full())
_tipo = 'F';
else
switch (_allegato)
{
_tipo = rec.get_char(CLI_TIPOPERS);
if (_tipo != 'F' || is_firm)
_tipo = 'G';
case 6: _tipo = 'F'; break; // Privato
case 7: _tipo = 'G'; break; // Ente pubblico
case 8: _tipo = 'G'; break; // Fallimento
default:
if (_com_nasc.full())
_tipo = 'F';
else
{
_tipo = rec.get_char(CLI_TIPOPERS);
if (_tipo != 'F' || is_firm)
_tipo = 'G';
}
break;
}
break;
}
if (_tipo == 'G' || _ragsoc.len() <= 30)
split_ragsoc();
_cod_EORI = rec.get(CLI_CODEORI);
TToken_string key = rec.get(CLI_TIPOCF);
key.add(rec.get(CLI_CODCF));
const TRectype & cfven = cache().get(LF_CFVEN, key);
_coddest = cfven.get(CFV_PADESTIN);
_pec = rec.get(CLI_PEC);
}
if (_tipo == 'G' || _ragsoc.len() <= 30)
split_ragsoc();
_cod_EORI = rec.get(CLI_CODEORI);
_coddest = rec.get(CFV_PADESTIN);
_pec = rec.get(CLI_PEC);
break;
case LF_MOV:
return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI));