Migliorata gestione residenti all'estero

git-svn-id: svn://10.65.10.50/branches/R_10_00@22935 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2014-05-14 08:26:11 +00:00
parent 858ae87f12
commit a0c6d081f1
4 changed files with 210 additions and 83 deletions

View File

@ -175,20 +175,23 @@ TExclusion_mode TSpesometro_msk::validate_clifo(const TRectype& mov)
TString8 key; key.format("%c|%ld", tipocf, codcf);
const TRectype& rec_clifo = cache().get(LF_CLIFO, key);
const int alleg = rec_clifo.get_int(CLI_ALLEG);
TString4 stato = rec_clifo.get(CLI_STATOCF); // Può cambiare per occasionali
if (alleg == 4)
{
const long codalleg = rec_clifo.get_long(CLI_CODALLEG);
key; key.format("%c|%ld", tipocf, codalleg);
const TRectype& rec_alleg = cache().get(LF_CLIFO, key);
if (!rec_alleg.empty())
if (codalleg > 0L)
{
((TRectype&)mov).put(MOV_CODCF, codalleg);
return validate_clifo(mov);
key.format("%c|%ld", tipocf, codalleg);
const TRectype& rec_alleg = cache().get(LF_CLIFO, key);
if (!rec_alleg.empty())
{
((TRectype&)mov).put(MOV_CODCF, codalleg);
return validate_clifo(mov);
}
}
}
TString4 stato;
if (ocfpi.full())
{
const TRectype& rec_occas = cache().get(LF_OCCAS, ocfpi);
@ -202,8 +205,6 @@ TExclusion_mode TSpesometro_msk::validate_clifo(const TRectype& mov)
if (alleg == 5)
return segnala_movimento(mov, em_intra);
stato = rec_clifo.get(CLI_STATOCF);
if (stato.blank() && alleg == 9) // Flag extra CEE incoerente
return segnala_movimento(mov, em_estero);
}
@ -228,38 +229,40 @@ TExclusion_mode TSpesometro_msk::validate_mov(const TRectype& mov)
// Ignora eventuale vecchio movimento IVA (ANNOIVA < 2012)
const int anno = mov.get_int(MOV_ANNOIVA);
if (anno < 2012)
return segnala_movimento(mov, em_data_limite);
return segnala_movimento(mov, em_data_limite);
if (mov.get_long(MOV_NUMREG) == 57503)
int cazzone = 1;
TExclusion_mode em = validate_clifo(mov);
if (em != em_normale)
return em;
// Trova i movimenti INTRA
if (!mov.get_real(MOV_CORRLIRE).is_zero() ||
!mov.get_real(MOV_CORRVALUTA).is_zero())
return segnala_movimento(mov, em_intra);
const TString& keytok = mov.get(MOV_NUMREG);
const char tipocf = mov.get_char(MOV_TIPO);
TRecord_array righe_iva(keytok, LF_RMOVIVA);
real tot_imponibile, tot_imposta;
//calcolo di imponibile ed imposta di tutte le righe iva del movimento
for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r))
if (!mov.get_real(MOV_CORRLIRE).is_zero() || !mov.get_real(MOV_CORRVALUTA).is_zero())
em = segnala_movimento(mov, em_intra);
else
{
const TRectype& rmi = righe_iva.row(r);
const TCodiceIVA ci(rmi.get(RMI_CODIVA));
const int natura_operazione = ci.allegato(tipocf);
if (natura_operazione <= 0 || natura_operazione > 5)
continue;
tot_imponibile += rmi.get_real(RMI_IMPONIBILE);
tot_imposta += rmi.get_real(RMI_IMPOSTA);
}
if (tot_imponibile.is_zero() && tot_imposta.is_zero())
{
TExclusion_mode em = validate_clifo(mov);
if (em == em_normale)
const TString& keytok = mov.get(MOV_NUMREG);
const char tipocf = mov.get_char(MOV_TIPO);
TRecord_array righe_iva(keytok, LF_RMOVIVA);
real tot_imponibile, tot_imposta;
//calcolo di imponibile ed imposta di tutte le righe iva del movimento
for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r))
{
const TRectype& rmi = righe_iva.row(r);
const TCodiceIVA ci(rmi.get(RMI_CODIVA));
const int natura_operazione = ci.allegato(tipocf);
if (natura_operazione <= 0 || natura_operazione > 5)
continue;
tot_imponibile += rmi.get_real(RMI_IMPONIBILE);
tot_imposta += rmi.get_real(RMI_IMPOSTA);
}
if (tot_imponibile.is_zero() && tot_imposta.is_zero())
em = segnala_movimento(mov, em_importo_limite);
return em;
}
return validate_clifo(mov);
return em;
}
TExclusion_mode TSpesometro_msk::elabora_movimento(const TRectype& mov, TBaseisamfile& falleg)
@ -370,7 +373,7 @@ TExclusion_mode TSpesometro_msk::elabora_movimento(const TRectype& mov, TBaseisa
tot_imponibile = tot_imposta.sign();
}
}
if (mov.get_int(MOV_UPROTIVA) > 0)
if (mov.get_int(MOV_UPROTIVA) > mov.get_int(MOV_PROTIVA))
falleg.put(ALL_RIEPILOG, true);
}
}
@ -433,9 +436,14 @@ TExclusion_mode TSpesometro_msk::elabora_movimento(const TRectype& mov, TBaseisa
}
if (!good)
{
falleg.put(ALL_AUTOFATT, true);
if (tot_imponibile.is_zero() && !tot_imposta.is_zero())
tot_imponibile = tot_imposta.sign();
TString8 key; key << tipocf << '|' << codcf;
const TRectype& clifo = cache().get(LF_CLIFO, key);
if (clifo.get_int(CLI_ALLEG) == 9) // Extra CEE con dati anagrafici insufficienti
{
falleg.put(ALL_AUTOFATT, true);
if (tot_imponibile.is_zero() && !tot_imposta.is_zero())
tot_imponibile = tot_imposta.sign();
}
}
}
@ -657,7 +665,7 @@ bool TSpesometro_msk::send_estero(const TRectype& alleg, const TAnagrafica& anag
if (is_nota) // Le istruzioni dicono di ignorarla, ma Sirio non ha ancora deciso
send_nota_variazione(alleg, anag, operaz); // Imposta solamente il campo 11 a ND o NC
const char cayman = anag.is_black_list();
const char cayman = anag.is_black_list(alleg.get_date(ALL_DATAREG));
const bool servizi = tipocf == 'F' && alleg.get_bool(ALL_SERVIZI);
if (servizi && alleg.get_bool(ALL_AUTOFATT))
@ -1254,6 +1262,15 @@ bool TSpesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jo
return false;
}
break;
case DLG_LINK: // Ditta
if (e == fe_button)
{
TRectype ndt(LF_NDITTE);
ndt.put(NDT_CODDITTA, prefix().get_codditta());
if (ndt.edit(LF_NDITTE, NULL, "ba4 -2"))
prefix().notify_change(LF_NDITTE);
}
break;
case DLG_SAVEREC:
if (e == fe_button)
save_if_dirty();
@ -1324,7 +1341,7 @@ bool TSpesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jo
if (e == fe_init || e == fe_modify)
{
int anno = atoi(o.get());
if (anno < 2013)
if (anno < 2012)
{
anno = TDate(TODAY).year()-1;
o.set(anno);

View File

@ -15,43 +15,49 @@ BEGIN
FLAGS "D"
END
BUTTON DLG_CANCEL 2 2,
BUTTON DLG_CANCEL 2 2
BEGIN
PROMPT 1 2 "Annulla"
END
BUTTON DLG_LINK 2 2
BEGIN
PROMPT 1 3 "Ditta"
PICTURE TOOL_LINK
END
BUTTON DLG_NULL 2 2
BEGIN
END
BUTTON DLG_RECALC 2 2
BEGIN
PROMPT 1 3 "Ricalcola"
PROMPT 1 5 "Ricalcola"
PICTURE TOOL_RECALC
END
BUTTON DLG_EXPORT 2 2
BEGIN
PROMPT 1 4 "Excel"
PROMPT 1 6 "Excel"
PICTURE TOOL_EXCEL
MODULE rs
END
BUTTON DLG_ELABORA 2 2
BEGIN
PROMPT 1 5 "Invia"
PROMPT 1 7 "Invia"
PICTURE TOOL_EXPORT
END
BUTTON DLG_DELREC 2 2
BEGIN
PROMPT 1 6 "Azzera Invio"
PROMPT 1 8 "Azzera Invio"
PICTURE TOOL_RESET
END
BUTTON DLG_PREVIEW 2 2
BEGIN
PROMPT 1 7 "Anteprima"
PROMPT 1 9 "Anteprima"
PICTURE TOOL_PREVIEW
END

View File

@ -49,7 +49,7 @@ bool fe_is_nota_variazione(const TRectype& mov)
if (logicnum == LF_ALLEG)
{
const TString& tipo = mov.get(ALL_TIPOPE);
if (tipo.len() == 2)
if (tipo.len() == 2 && tipo != "BL")
return tipo == "NE" || tipo == "NR";
const real importo = mov.get_real(ALL_IMPORTO);
@ -97,6 +97,9 @@ bool fe_is_nota_variazione(const TRectype& mov)
// TAnagrafica
///////////////////////////////////////////////////////////
static bool is_stato_estero(const TString& codcom)
{ return codcom.full() && codcom.match("Z[0-9][0-9][0-9]"); }
static const TString& comune_di(const TString& codcom, int stato)
{
if (codcom.blank() || codcom.len() != 4)
@ -114,8 +117,8 @@ static const TString& provincia_di(const TString& codcom)
if (codcom.blank() || codcom.len() != 4)
return EMPTY_STRING;
TString& prov = get_tmp_string();
if (codcom.starts_with("Z"))
prov == "EE";
if (is_stato_estero(codcom))
prov = "EE";
else
{
TString8 key; key << '|' << codcom;
@ -126,10 +129,29 @@ static const TString& provincia_di(const TString& codcom)
}
const TString& TAnagrafica::comune_nascita() const
{ return comune_di(_com_nasc, 0); }
{
if (is_stato_estero(_com_nasc))
{
const TString& c = comune_di(_com_nasc, 0);
if (c.full())
return c;
}
if (_stato_nasc > 0)
{
TString4 u; u.format("%03d", _stato_nasc);
const TString& s = cache().get("%STA", u, "S0");
if (s.full())
return s;
}
return comune_di(_com_nasc, _stato_nasc);
}
const TString& TAnagrafica::provincia_nascita() const
{ return provincia_di(_com_nasc); }
{
if (_stato_nasc > 0 || is_stato_estero(_com_nasc))
return get_tmp_string() = "EE";
return provincia_di(_com_nasc);
}
const TString& TAnagrafica::comune_residenza() const
{
@ -158,6 +180,29 @@ void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char
TParagraph_string s(indirizzo, 40);
_ind_res = s.get(0);
}
// Sistema persone senza stato ma con comune estero
if (_stato_estero <= 0 && is_stato_estero(_com_res))
{
const TString80 naz = comune_di(_com_res, 0);
TString query; query.format("USE %%STA KEY 2\nFROM S0=%c\nTO S0=%c", naz[0], naz[0]);
TISAM_recordset sta(query);
double dBest = 0;
int nBest = 0;
for (bool ok = sta.move_first(); ok; ok = sta.move_next())
{
const double s = xvt_str_fuzzy_compare(naz, sta.get("S0").as_string());
if (s > dBest)
{
nBest = sta.get("CODTAB").as_int();
dBest = s;
if (dBest >= 1.0)
break;
}
}
if (dBest > 0.8)
_stato_estero = nBest;
}
}
const TString& TAnagrafica::cognome() const
@ -173,21 +218,21 @@ const TString& TAnagrafica::nome() const
}
bool TAnagrafica::italiano() const
{ return _stato_estero == 0; }
{ return _stato_estero == 0 && !is_stato_estero(_com_res); }
const TString& TAnagrafica::stato_estero_UNICO() const
{
if (_stato_estero <= 0)
return EMPTY_STRING;
TString4 u;
u.format("%03d", _stato_estero);
TString4 u; u.format("%03d", _stato_estero);
const TString& cod = cache().get("%STA", u, "S8"); // S8=UNICO S9=ISTAT
if (cod.len() == 3)
return cod;
return get_tmp_string() = u;
}
char TAnagrafica::is_black_list() const
char TAnagrafica::is_black_list(const TDate& datareg) const
{
char is_black = ' ';
if (_stato_estero > 0)
@ -196,9 +241,15 @@ char TAnagrafica::is_black_list() const
const TRectype& sta = cache().get("%STA", u);
if (sta.get_bool("B1")) // San Marino
is_black = 'M'; else
if (sta.get_bool("B0")) // Black List
is_black = 'S';
{
if (datareg.date2ansi() < TDate(24,2,2014))
is_black = 'M';
}
else
{
if (sta.get_bool("B0")) // Black List
is_black = 'S';
}
}
return is_black;
}
@ -221,12 +272,13 @@ void TAnagrafica::split_ragsoc()
}
else
_ragsoc.strip_double_spaces();
_ragsoc.replace('"', '\''); // gli " creano casini nel csv
}
bool TAnagrafica::init(const TRectype& rec)
{
_tipo = '\0';
_stato_estero = 0;
_stato_estero = _stato_nasc = 0;
_allegato = 0;
_ragsoc.cut(0);
if (rec.empty())
@ -247,11 +299,12 @@ bool TAnagrafica::init(const TRectype& rec)
}
_ragsoc = rec.get(OCC_RAGSOC);
_data_nasc = rec.get(OCC_DNASC);
_stato_nasc = rec.get_int(OCC_STATONASC);
_com_nasc = rec.get(OCC_COMNASC);
_stato_estero = rec.get_int(OCC_STATO);
_com_res = rec.get(OCC_COM);
_loc_res = rec.get(OCC_LOCALITA);
build_ind_res(rec, OCC_INDIR, OCC_CIV);
_stato_estero = rec.get_int(OCC_STATO);
if (_com_nasc.full() || (!_stato_estero && !real::is_natural(_cofi) || cf_check("", _cofi)))
_tipo = 'F';
else
@ -265,18 +318,23 @@ bool TAnagrafica::init(const TRectype& rec)
_paiv = rec.get(ANA_PAIV);
// Comune di residenza fiscale o domicilio
_stato_estero = rec.get_int(ANA_STATORES);
_com_res = rec.get(ANA_COMRF);
if (_com_res.empty())
_com_res = rec.get(ANA_COMRES);
build_ind_res(rec, ANA_INDRES, ANA_CIVRES);
_stato_estero = rec.get_int(ANA_STATORES);
// Dati di nascita persone fisiche
if (_tipo == 'F')
{
const TRectype& anafis = cache().get(LF_ANAGFIS, rec.get_long(ANA_CODANAGR));
_data_nasc = anafis.get(ANF_DATANASC);
_com_nasc = anafis.get(ANF_COMNASC);
const long codana = rec.get_long(ANA_CODANAGR);
if (codana > 0)
{
const TRectype& anafis = cache().get(LF_ANAGFIS, codana);
_data_nasc = anafis.get(ANF_DATANASC);
_stato_nasc = anafis.get_int(ANF_STATONASC);
_com_nasc = anafis.get(ANF_COMNASC);
}
}
else
_tipo = 'G';
@ -284,7 +342,8 @@ bool TAnagrafica::init(const TRectype& rec)
case LF_NDITTE:
{
const char tipoa = rec.get_char(NDT_TIPOA);
const bool good = init(LF_ANAG, tipoa, rec.get_long(NDT_CODANAGR));
const long codana = rec.get_long(NDT_CODANAGR);
const bool good = init(LF_ANAG, tipoa, codana);
if (tipoa == 'G')
_ragsoc = rec.get(NDT_RAGSOC);
return good;
@ -307,18 +366,27 @@ bool TAnagrafica::init(const TRectype& rec)
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';
#ifdef DBG
if (rec.get(CLI_RAGSOC).starts_with("ACAR"))
int cazzone_estero = 1;
#endif
}
if (rec.get(CLI_COMNASC).not_empty())
if (_com_nasc.blank())
_com_nasc = rec.get(CLI_COMNASC);
if (_com_nasc.empty() && rec.get(CLI_STATONASC).not_empty())
if (_stato_nasc <= 0)
_stato_nasc = rec.get_int(CLI_STATONASC);
if (_com_nasc.blank() && _stato_nasc > 0)
{
const TString80 stato = cache().get("%STA", rec.get(CLI_STATONASC), "S0");
TISAM_recordset comuni("USE COMUNI\nFROM CODCOM=Z");
double best = 0.75;
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();
@ -326,7 +394,10 @@ bool TAnagrafica::init(const TRectype& rec)
if (score > best)
{
best = score;
_stato_nasc = 0;
_com_nasc = comuni.get(COM_COM).as_string();
if (best >= 1.0)
break;
}
}
}
@ -356,16 +427,15 @@ bool TAnagrafica::init(const TRectype& rec)
}
}
build_ind_res(rec, CLI_INDCF, CLI_CIVCF);
// 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);
_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')
{
@ -505,6 +575,42 @@ void TSpesometro_set::add_header_data(int n, const TString& value)
set(1, value);
}
const TString& TSpesometro_set::get_recapito(const TRectype& ndt, const char* numero, const char* prefisso) const
{
if (ndt.exist(numero))
{
TString& tel = get_tmp_string();
if (prefisso && *prefisso)
tel = ndt.get(prefisso);
tel << ndt.get(numero);
if (tel.full())
return tel;
}
if (ndt.num() == LF_NDITTE)
{
TString16 key;
key.format("%c|%ld", ndt.get_char(NDT_TIPOA), ndt.get_long(NDT_CODANAGR));
const TRectype& anag = cache().get(LF_ANAG, key);
if (prefisso)
{
if (strcmp(numero, "TEL") == 0)
{
numero = "TELRF";
prefisso = "PTELRF";
} else
if (strcmp(numero, "FAX") == 0)
{
numero = "FAXRF";
prefisso = "PFAXRF";
}
}
return get_recapito(anag, numero, prefisso);
}
return EMPTY_STRING;
}
bool TSpesometro_set::add_header(const TMask& msk)
{
const long codditta = prefix().get_codditta();
@ -522,13 +628,10 @@ bool TSpesometro_set::add_header(const TMask& msk)
const TString8 ateco = att.get(ATT_CODATECO);
add_header_data(3, ateco);
TString80 tel;
tel << ndt.get(NDT_PTEL) << ndt.get(NDT_TEL);
add_header_data(4, tel);
add_header_data(4, get_recapito(ndt, NDT_TEL, NDT_PTEL));
add_header_data(5, get_recapito(ndt, NDT_FAX, NDT_PFAX));
add_header_data(6, get_recapito(ndt, "MAIL", NULL));
tel.cut(0) << ndt.get(NDT_PFAX) << ndt.get(NDT_FAX);
add_header_data(5, tel);
add_header_data(6, EMPTY_STRING);
if (ditta.fisica())
{
add_header_data( 7, ditta.cognome());
@ -621,7 +724,7 @@ void TSpesometro_set::init()
create_column("IndirEsteroSede", _alfafld);
create_column("CodiceIVAEstero", _alfafld);
create_column("BlackList", _boolfld); // 27
create_column("BlackList", _alfafld); // 27 S o M o blank
create_column("NonResidente", _boolfld);
create_column("AcquistoDaNonRes", _boolfld);
create_column("TipoImponibile", _alfafld);

View File

@ -21,7 +21,7 @@ class TAnagrafica : public TObject
TString4 _com_nasc, _com_res;
TString80 _loc_res, _ind_res;
TDate _data_nasc;
int _allegato, _stato_estero;
int _allegato, _stato_estero, _stato_nasc;
TAnagrafica& operator =(const TAnagrafica&) { CHECK(false, "Can't copy TAnagrafica"); }
TAnagrafica(const TAnagrafica&) { CHECK(false, "Can't copy TAnagrafica"); }
@ -47,7 +47,7 @@ public:
bool estero() const { return !italiano(); }
const TString& stato_estero_UNICO() const;
int inserimento_in_allegato() const { return _allegato; }
char is_black_list() const;
char is_black_list(const TDate& datareg) const;
const TString& comune_nascita() const;
const TString& provincia_nascita() const;
@ -81,6 +81,7 @@ protected:
void init();
void add_header_data(int n, const TString& value);
const TString& get_recapito(const TRectype& ndt, const char* numero, const char* prefisso) const;
public:
virtual const TVariant& get(unsigned int column) const;