2011-11-14 17:29:27 +00:00
|
|
|
|
#include <diction.h>
|
|
|
|
|
#include <lffiles.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <recarray.h>
|
2012-01-23 16:33:13 +00:00
|
|
|
|
#include <relation.h>
|
2011-11-14 17:29:27 +00:00
|
|
|
|
#include <validate.h>
|
|
|
|
|
|
|
|
|
|
#include "fe0100a.h"
|
|
|
|
|
#include "felib.h"
|
|
|
|
|
|
2012-01-23 16:33:13 +00:00
|
|
|
|
#include "../cg/cg2103.h"
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
#include <alleg.h>
|
|
|
|
|
#include <anafis.h>
|
|
|
|
|
#include <anagr.h>
|
2013-12-13 09:28:16 +00:00
|
|
|
|
#include <attiv.h>
|
2011-11-14 17:29:27 +00:00
|
|
|
|
#include <clifo.h>
|
|
|
|
|
#include <comuni.h>
|
2012-01-23 16:33:13 +00:00
|
|
|
|
#include <doc.h>
|
2011-11-14 17:29:27 +00:00
|
|
|
|
#include <mov.h>
|
|
|
|
|
#include <nditte.h>
|
|
|
|
|
#include <occas.h>
|
|
|
|
|
|
2012-01-23 16:33:13 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Utility
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
bool fe_is_nota_variazione(const TRectype& mov)
|
|
|
|
|
{
|
|
|
|
|
const int logicnum = mov.num();
|
|
|
|
|
|
|
|
|
|
if (logicnum == LF_MOV)
|
|
|
|
|
{
|
|
|
|
|
const real totdoc = mov.get_real(MOV_TOTDOC);
|
|
|
|
|
if (totdoc < ZERO)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
const int tipomov = mov.get_int(MOV_TIPOMOV);
|
|
|
|
|
if (tipomov == 2) // Nota di credito/debito per saldaconto
|
2012-03-09 15:51:40 +00:00
|
|
|
|
return true;
|
2012-01-23 16:33:13 +00:00
|
|
|
|
|
2012-03-09 15:51:40 +00:00
|
|
|
|
if (tipomov <= 1)
|
|
|
|
|
{
|
|
|
|
|
const TString& tipodoc = mov.get(MOV_TIPODOC);
|
|
|
|
|
if (tipodoc == "NC" || tipodoc == "ND") // Nota di credito/debito senza saldaconto
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-01-23 16:33:13 +00:00
|
|
|
|
} else
|
|
|
|
|
if (logicnum == LF_ALLEG)
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TString& tipo = mov.get(ALL_TIPOPE);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
if (tipo.len() == 2 && tipo != "BL")
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return tipo == "NE" || tipo == "NR";
|
2012-01-23 16:33:13 +00:00
|
|
|
|
|
|
|
|
|
const real importo = mov.get_real(ALL_IMPORTO);
|
|
|
|
|
const real imposta = mov.get_real(ALL_IMPOSTA);
|
2012-05-23 14:33:58 +00:00
|
|
|
|
if (importo < ZERO || (importo.is_zero() && imposta < ZERO))
|
2012-01-23 16:33:13 +00:00
|
|
|
|
return true;
|
2012-03-09 15:51:40 +00:00
|
|
|
|
|
|
|
|
|
const long numreg = mov.get_long(ALL_PROGR);
|
|
|
|
|
if (numreg < 900000L)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& pn = cache().get(LF_MOV, numreg);
|
|
|
|
|
if (!pn.empty())
|
|
|
|
|
return fe_is_nota_variazione(pn);
|
|
|
|
|
}
|
2012-01-23 16:33:13 +00:00
|
|
|
|
} else
|
|
|
|
|
if (logicnum == LF_DOC)
|
|
|
|
|
{
|
|
|
|
|
const TString& tipodoc = mov.get(DOC_TIPODOC);
|
|
|
|
|
const TRectype& td = cache().get("%TIP", tipodoc);
|
|
|
|
|
|
|
|
|
|
bool yes = td.get_bool("B7");
|
|
|
|
|
if (!yes)
|
|
|
|
|
{
|
|
|
|
|
const TString4 codcaus(td.get("S6"));
|
|
|
|
|
if (codcaus.full())
|
|
|
|
|
{
|
2012-05-23 14:33:58 +00:00
|
|
|
|
const TCausale c(codcaus, mov.get_int(DOC_ANNO));
|
2012-01-23 16:33:13 +00:00
|
|
|
|
const char sez = c.sezione_clifo();
|
|
|
|
|
//controllo ulteriore sull'iva
|
|
|
|
|
TipoIVA tiva = c.reg().iva();
|
|
|
|
|
const char tcf = mov.get_char(DOC_TIPOCF);
|
|
|
|
|
if (tiva == nessuna_iva && tcf > ' ')
|
|
|
|
|
tiva = tcf == 'C' ? iva_vendite : iva_acquisti;
|
|
|
|
|
if (tiva != nessuna_iva)
|
|
|
|
|
yes = ((tiva == iva_vendite) ^ (sez == 'D'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TAnagrafica
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2014-05-14 08:26:11 +00:00
|
|
|
|
static bool is_stato_estero(const TString& codcom)
|
|
|
|
|
{ return codcom.full() && codcom.match("Z[0-9][0-9][0-9]"); }
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
static const TString& comune_di(const TString& codcom, int stato)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (codcom.blank() || codcom.len() != 4)
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TString8 key;
|
|
|
|
|
if (stato > 0)
|
|
|
|
|
key.format("%03d", stato);
|
|
|
|
|
key << '|' << codcom;
|
|
|
|
|
return cache().get(LF_COMUNI, key, COM_DENCOM);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const TString& provincia_di(const TString& codcom)
|
|
|
|
|
{
|
|
|
|
|
if (codcom.blank() || codcom.len() != 4)
|
|
|
|
|
return EMPTY_STRING;
|
2011-12-20 13:20:00 +00:00
|
|
|
|
TString& prov = get_tmp_string();
|
2014-05-14 08:26:11 +00:00
|
|
|
|
if (is_stato_estero(codcom))
|
|
|
|
|
prov = "EE";
|
2013-12-13 09:28:16 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TString8 key; key << '|' << codcom;
|
|
|
|
|
prov = cache().get(LF_COMUNI, key, COM_PROVCOM);
|
|
|
|
|
if (prov.len() > 2) prov = "RM";
|
|
|
|
|
}
|
2011-12-20 13:20:00 +00:00
|
|
|
|
return prov;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::comune_nascita() const
|
2014-05-14 08:26:11 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::provincia_nascita() const
|
2014-05-14 08:26:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (_stato_nasc > 0 || is_stato_estero(_com_nasc))
|
|
|
|
|
return get_tmp_string() = "EE";
|
|
|
|
|
return provincia_di(_com_nasc);
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::comune_residenza() const
|
2013-12-13 09:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
const TString& cr = comune_di(_com_res, _stato_estero);
|
|
|
|
|
if (cr.full())
|
|
|
|
|
return cr;
|
|
|
|
|
return _loc_res;
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::provincia_residenza() const
|
2013-12-13 09:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (estero())
|
|
|
|
|
return get_tmp_string() = "EE";
|
|
|
|
|
return provincia_di(_com_res);
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char* civ)
|
|
|
|
|
{
|
2014-07-30 12:56:02 +00:00
|
|
|
|
_via_res = _ind_res = rec.get(ind);
|
|
|
|
|
_civ_res = rec.get(civ);
|
|
|
|
|
|
|
|
|
|
if (_civ_res.blank())
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2014-07-30 12:56:02 +00:00
|
|
|
|
const int comma = _via_res.rfind(',');
|
|
|
|
|
if (comma > 0 && _via_res.len()-comma <= 8)
|
|
|
|
|
{
|
|
|
|
|
_civ_res = _via_res.mid(comma+1); _civ_res.trim();
|
|
|
|
|
_via_res.cut(comma); _via_res.trim();
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
2014-05-14 08:26:11 +00:00
|
|
|
|
|
2014-07-30 12:56:02 +00:00
|
|
|
|
if (_via_res.full())
|
|
|
|
|
{
|
|
|
|
|
TString80 ind = _via_res;
|
|
|
|
|
if (_civ_res.full())
|
|
|
|
|
ind << ", " << _civ_res;
|
|
|
|
|
ind.strip_double_spaces();
|
|
|
|
|
TParagraph_string s(ind, 40);
|
|
|
|
|
_ind_res = s.get(0); // prende solo i primi 40 caratteri dell'indirizzo completo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sistema persone senza codice stato, ma residenti in comune estero
|
2014-05-14 08:26:11 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TString& TAnagrafica::cognome() const
|
|
|
|
|
{
|
2015-02-24 08:27:41 +00:00
|
|
|
|
TString& c = get_tmp_string();
|
|
|
|
|
c = _ragsoc.left(30);
|
|
|
|
|
return c.trim();
|
2013-12-13 09:28:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::nome() const
|
|
|
|
|
{
|
|
|
|
|
CHECK(fisica(), "Non chiedere nome giuridico!");
|
2015-02-24 08:27:41 +00:00
|
|
|
|
TString& c = get_tmp_string();
|
|
|
|
|
c = _ragsoc.mid(30,20);
|
|
|
|
|
return c.trim();
|
2013-12-13 09:28:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-23 10:15:42 +00:00
|
|
|
|
bool TAnagrafica::italiano() const
|
2014-05-14 08:26:11 +00:00
|
|
|
|
{ return _stato_estero == 0 && !is_stato_estero(_com_res); }
|
2011-12-23 10:15:42 +00:00
|
|
|
|
|
|
|
|
|
const TString& TAnagrafica::stato_estero_UNICO() const
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (_stato_estero <= 0)
|
2011-12-23 10:15:42 +00:00
|
|
|
|
return EMPTY_STRING;
|
2014-05-14 08:26:11 +00:00
|
|
|
|
|
|
|
|
|
TString4 u; u.format("%03d", _stato_estero);
|
2011-12-23 10:15:42 +00:00
|
|
|
|
const TString& cod = cache().get("%STA", u, "S8"); // S8=UNICO S9=ISTAT
|
|
|
|
|
if (cod.len() == 3)
|
2012-01-26 11:37:01 +00:00
|
|
|
|
return cod;
|
2011-12-23 10:15:42 +00:00
|
|
|
|
return get_tmp_string() = u;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 08:26:11 +00:00
|
|
|
|
char TAnagrafica::is_black_list(const TDate& datareg) const
|
2013-12-13 09:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
char is_black = ' ';
|
|
|
|
|
if (_stato_estero > 0)
|
|
|
|
|
{
|
|
|
|
|
TString4 u; u.format("%03d", _stato_estero);
|
|
|
|
|
const TRectype& sta = cache().get("%STA", u);
|
|
|
|
|
|
|
|
|
|
if (sta.get_bool("B1")) // San Marino
|
2014-05-14 08:26:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (datareg.date2ansi() < TDate(24,2,2014))
|
|
|
|
|
is_black = 'M';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (sta.get_bool("B0")) // Black List
|
|
|
|
|
is_black = 'S';
|
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
}
|
|
|
|
|
return is_black;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-27 11:48:39 +00:00
|
|
|
|
void TAnagrafica::split_ragsoc()
|
|
|
|
|
{
|
|
|
|
|
if (_tipo == 'F')
|
|
|
|
|
{
|
|
|
|
|
if (nome().blank())
|
|
|
|
|
{
|
|
|
|
|
const int space = _ragsoc.find(' ');
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (space >= 4)
|
2011-12-27 11:48:39 +00:00
|
|
|
|
{
|
|
|
|
|
TString80 nom = _ragsoc.mid(space+1);
|
|
|
|
|
nom.cut(20);
|
|
|
|
|
_ragsoc.cut(space);
|
|
|
|
|
_ragsoc.insert(nom, 30);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_ragsoc.strip_double_spaces();
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_ragsoc.replace('"', '\''); // gli " creano casini nel csv
|
2011-12-27 11:48:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
bool TAnagrafica::init(const TRectype& rec)
|
|
|
|
|
{
|
|
|
|
|
_tipo = '\0';
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_stato_estero = _stato_nasc = 0;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_allegato = 0;
|
2013-12-13 09:28:16 +00:00
|
|
|
|
_ragsoc.cut(0);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
if (rec.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (rec.num())
|
|
|
|
|
{
|
|
|
|
|
case LF_OCCAS:
|
|
|
|
|
_cofi = rec.get(OCC_COFI);
|
|
|
|
|
_paiv = rec.get(OCC_PAIV);
|
|
|
|
|
if (_cofi.blank() || _paiv.blank())
|
|
|
|
|
{
|
|
|
|
|
const TString& codice = rec.get(OCC_CFPI);
|
|
|
|
|
if (_cofi.blank() && cf_check("", codice))
|
|
|
|
|
_cofi = codice;
|
|
|
|
|
if (_paiv.blank() && pi_check("", codice))
|
|
|
|
|
_paiv = codice;
|
|
|
|
|
}
|
2011-11-22 13:47:21 +00:00
|
|
|
|
_ragsoc = rec.get(OCC_RAGSOC);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_data_nasc = rec.get(OCC_DNASC);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_stato_nasc = rec.get_int(OCC_STATONASC);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_com_nasc = rec.get(OCC_COMNASC);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_stato_estero = rec.get_int(OCC_STATO);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_com_res = rec.get(OCC_COM);
|
|
|
|
|
_loc_res = rec.get(OCC_LOCALITA);
|
2014-07-30 12:56:02 +00:00
|
|
|
|
_cap_res = rec.get(OCC_CAP);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
build_ind_res(rec, OCC_INDIR, OCC_CIV);
|
2011-12-27 11:48:39 +00:00
|
|
|
|
if (_com_nasc.full() || (!_stato_estero && !real::is_natural(_cofi) || cf_check("", _cofi)))
|
|
|
|
|
_tipo = 'F';
|
|
|
|
|
else
|
|
|
|
|
_tipo = 'G';
|
|
|
|
|
_allegato = _tipo == 'F' ? 6 : 2;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case LF_ANAG:
|
|
|
|
|
_tipo = rec.get_char(ANA_TIPOA);
|
2011-11-22 13:47:21 +00:00
|
|
|
|
_ragsoc = rec.get(ANA_RAGSOC);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_cofi = rec.get(ANA_COFI);
|
|
|
|
|
_paiv = rec.get(ANA_PAIV);
|
|
|
|
|
|
|
|
|
|
// Comune di residenza fiscale o domicilio
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_stato_estero = rec.get_int(ANA_STATORES);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_com_res = rec.get(ANA_COMRF);
|
|
|
|
|
if (_com_res.empty())
|
|
|
|
|
_com_res = rec.get(ANA_COMRES);
|
|
|
|
|
build_ind_res(rec, ANA_INDRES, ANA_CIVRES);
|
2014-07-30 12:56:02 +00:00
|
|
|
|
_cap_res = rec.get(ANA_CAPRES);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
// Dati di nascita persone fisiche
|
|
|
|
|
if (_tipo == 'F')
|
|
|
|
|
{
|
2014-05-14 08:26:11 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_tipo = 'G';
|
|
|
|
|
break;
|
|
|
|
|
case LF_NDITTE:
|
|
|
|
|
{
|
2011-12-14 17:05:25 +00:00
|
|
|
|
const char tipoa = rec.get_char(NDT_TIPOA);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
const long codana = rec.get_long(NDT_CODANAGR);
|
|
|
|
|
const bool good = init(LF_ANAG, tipoa, codana);
|
2011-12-14 17:05:25 +00:00
|
|
|
|
if (tipoa == 'G')
|
|
|
|
|
_ragsoc = rec.get(NDT_RAGSOC);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return good;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LF_CLIFO:
|
2011-11-15 16:55:19 +00:00
|
|
|
|
_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);
|
|
|
|
|
}
|
2011-12-27 11:48:39 +00:00
|
|
|
|
|
|
|
|
|
_tipo = ' '; // Non faccio assunzioni sulla persona fisica
|
2012-04-24 10:21:12 +00:00
|
|
|
|
|
2012-01-26 11:37:01 +00:00
|
|
|
|
// Persona Fisica?
|
|
|
|
|
if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get(CLI_DATANASC).not_empty())
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
const long cod = rec.get_long(CLI_CODANAGPER);
|
2011-12-27 11:48:39 +00:00
|
|
|
|
if (cod > 0)
|
|
|
|
|
init(LF_ANAG, 'F', cod);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
|
2011-12-27 11:48:39 +00:00
|
|
|
|
if (rec.get(CLI_DATANASC).not_empty())
|
2012-01-26 11:37:01 +00:00
|
|
|
|
{
|
2011-12-27 11:48:39 +00:00
|
|
|
|
_data_nasc = rec.get(CLI_DATANASC);
|
2012-01-26 11:37:01 +00:00
|
|
|
|
_tipo = 'F';
|
|
|
|
|
}
|
2014-05-14 08:26:11 +00:00
|
|
|
|
|
|
|
|
|
if (_com_nasc.blank())
|
2012-01-26 11:37:01 +00:00
|
|
|
|
_com_nasc = rec.get(CLI_COMNASC);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
if (_stato_nasc <= 0)
|
|
|
|
|
_stato_nasc = rec.get_int(CLI_STATONASC);
|
|
|
|
|
if (_com_nasc.blank() && _stato_nasc > 0)
|
2012-01-26 11:37:01 +00:00
|
|
|
|
{
|
2014-05-14 08:26:11 +00:00
|
|
|
|
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;
|
2012-01-26 11:37:01 +00:00
|
|
|
|
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;
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_stato_nasc = 0;
|
2012-01-26 11:37:01 +00:00
|
|
|
|
_com_nasc = comuni.get(COM_COM).as_string();
|
2014-05-14 08:26:11 +00:00
|
|
|
|
if (best >= 1.0)
|
|
|
|
|
break;
|
2012-01-26 11:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
2011-12-27 11:48:39 +00:00
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
|
|
|
|
|
if (rec.get(CLI_COFI).not_empty())
|
|
|
|
|
_cofi = rec.get(CLI_COFI);
|
|
|
|
|
if (rec.get(CLI_PAIV).not_empty())
|
|
|
|
|
_paiv = rec.get(CLI_PAIV);
|
2012-04-24 10:21:12 +00:00
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (_allegato != 5 && _allegato != 9)
|
|
|
|
|
{
|
|
|
|
|
const TString4 stato_paiv = rec.get(CLI_STATOPAIV);
|
|
|
|
|
if (stato_paiv.blank() || stato_paiv == "IT")
|
|
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-24 10:21:12 +00:00
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
|
2014-05-14 08:26:11 +00:00
|
|
|
|
_ragsoc = rec.get(CLI_RAGSOC);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_loc_res = rec.get(CLI_LOCCF);
|
2014-07-30 12:56:02 +00:00
|
|
|
|
_cap_res = rec.get(CLI_CAPCF);
|
2013-12-13 09:28:16 +00:00
|
|
|
|
_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);
|
2014-05-14 08:26:11 +00:00
|
|
|
|
build_ind_res(rec, CLI_INDCF, CLI_CIVCF);
|
2013-12-13 09:28:16 +00:00
|
|
|
|
|
2011-12-27 11:48:39 +00:00
|
|
|
|
if (_tipo != 'F' && _tipo != 'G')
|
|
|
|
|
{
|
|
|
|
|
switch (_allegato)
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
case 6: _tipo = 'F'; break; // Privato
|
|
|
|
|
case 7: _tipo = 'G'; break; // Ente pubblico
|
|
|
|
|
case 8: _tipo = 'G'; break; // Fallimento
|
2011-12-27 11:48:39 +00:00
|
|
|
|
default:
|
|
|
|
|
if (_com_nasc.full())
|
|
|
|
|
_tipo = 'F';
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_tipo = rec.get_char(CLI_TIPOPERS);
|
|
|
|
|
if (_tipo != 'F')
|
|
|
|
|
_tipo = 'G';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case LF_MOV:
|
|
|
|
|
return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI));
|
|
|
|
|
case LF_ALLEG:
|
|
|
|
|
return init(rec.get_char(ALL_TIPOCF), rec.get_long(ALL_CODCF), rec.get(ALL_OCFPI));
|
|
|
|
|
default:
|
|
|
|
|
CHECKD(false, "Record non valido per TAnagrafica ", rec.num());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-12-27 11:48:39 +00:00
|
|
|
|
split_ragsoc();
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
return _tipo == 'F' || _tipo == 'G';
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-17 14:10:29 +00:00
|
|
|
|
bool TAnagrafica::init(int num, const TString& codice)
|
|
|
|
|
{ return init(cache().get(num, codice)); }
|
|
|
|
|
|
|
|
|
|
bool TAnagrafica::init(int num, long codice)
|
|
|
|
|
{ return init(cache().get(num, codice)); }
|
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
bool TAnagrafica::init(int num, char tipo, long codice)
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TString8 key; key.format("%c|%ld", tipo, codice);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return init(cache().get(num, key));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:55:19 +00:00
|
|
|
|
bool TAnagrafica::init(char tipocf, long codice, const TString& ocfpi)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
bool done = false;
|
|
|
|
|
if (ocfpi.full())
|
|
|
|
|
done = init(LF_OCCAS, ocfpi);
|
|
|
|
|
if (!done)
|
2011-11-15 16:55:19 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK(tipocf == 'C' || tipocf == 'F', "Tipo cli/for non valido");
|
|
|
|
|
CHECKD(codice > 0, "Codice cli/for non valido", codice);
|
|
|
|
|
done = init(LF_CLIFO, tipocf, codice);
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return done;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-23 16:33:13 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
2013-12-13 09:28:16 +00:00
|
|
|
|
// TSpesometro_set
|
2012-01-23 16:33:13 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TVariant& TSpesometro_set::get(unsigned int column) const
|
2012-01-23 16:33:13 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TRecordset_column_info& info = column_info(column);
|
|
|
|
|
if (info._type == _realfld || info._type == _datefld)
|
2012-01-23 16:33:13 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TString80 val = row().get(column);
|
|
|
|
|
TVariant& var = get_tmp_var();
|
|
|
|
|
if (info._type == _realfld)
|
2012-01-23 16:33:13 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
val.replace(',', '.');
|
|
|
|
|
var = real(val);
|
2012-01-23 16:33:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (val.len() == 8)
|
2012-01-23 16:33:13 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
val.insert("-", 2);
|
|
|
|
|
val.insert("-", 5);
|
2012-01-23 16:33:13 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
var = TDate(val);
|
2012-01-23 16:33:13 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return var;
|
2012-01-23 16:33:13 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return TCSV_recordset::get(column);
|
2012-01-23 16:33:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
bool TSpesometro_set::set(unsigned int fld, const TVariant& var)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TRecordset_column_info& fi = column_info(fld);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
// Salva le date in formato GGMMAAAA invece dello standard ANSI AAAAMMGG
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (fi._type == _datefld)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
const TDate d = var.as_date();
|
|
|
|
|
if (d.ok())
|
|
|
|
|
{
|
|
|
|
|
TFixed_string str = d.string(full, '\0', full, full, gma_date);
|
2013-12-13 09:28:16 +00:00
|
|
|
|
row().add(str, fld);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-12-13 09:28:16 +00:00
|
|
|
|
row().add("", fld);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return true;
|
|
|
|
|
} else
|
2013-12-13 09:28:16 +00:00
|
|
|
|
// Salva gli importi in italiano (non possono essere negativi)
|
|
|
|
|
if (fi._type == _realfld)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
real r = var.as_real();
|
|
|
|
|
row().add(r.stringa(0, 2), fld);
|
2011-11-22 13:47:21 +00:00
|
|
|
|
} else
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (fi._type == _boolfld)
|
|
|
|
|
{
|
|
|
|
|
row().add(var.as_bool() ? "S" : " ", fld);
|
|
|
|
|
}
|
|
|
|
|
else
|
2011-11-22 13:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
TString256 str = var.as_string();
|
|
|
|
|
str.upper();
|
|
|
|
|
str.replace('<EFBFBD>', 'A');
|
2012-04-13 15:05:13 +00:00
|
|
|
|
str.replace('<EFBFBD>', 'N');
|
2011-11-22 13:47:21 +00:00
|
|
|
|
str.replace('<EFBFBD>', 'O');
|
|
|
|
|
str.replace('<EFBFBD>', 'U');
|
2013-12-13 09:28:16 +00:00
|
|
|
|
row().add(str, fld);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return true;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
void TSpesometro_set::add_header_data(int n, const TString& value)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
CHECKD(n > 0 && n <= 16, "Bad SO record type ", n);
|
|
|
|
|
TString8 fld; fld.format("SO%03d", n);
|
|
|
|
|
new_rec(fld);
|
|
|
|
|
set(1, value);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 08:26:11 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
bool TSpesometro_set::add_header(const TMask& msk)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const long codditta = prefix().get_codditta();
|
|
|
|
|
const TAnagrafica ditta(LF_NDITTE, codditta);
|
|
|
|
|
|
|
|
|
|
add_header_data(1, ditta.codice_fiscale());
|
|
|
|
|
add_header_data(2, ditta.partita_IVA());
|
|
|
|
|
|
|
|
|
|
TString16 key;
|
|
|
|
|
key.format("%ld", codditta);
|
|
|
|
|
const TRectype& ndt = cache().get(LF_NDITTE, key);
|
|
|
|
|
const char* codatt = ndt.get(NDT_CODATTPREV);
|
|
|
|
|
key.format("%ld|%s", codditta, codatt);
|
|
|
|
|
const TRectype& att = cache().get(LF_ATTIV, key);
|
|
|
|
|
const TString8 ateco = att.get(ATT_CODATECO);
|
|
|
|
|
add_header_data(3, ateco);
|
|
|
|
|
|
2014-05-14 08:26:11 +00:00
|
|
|
|
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));
|
2013-12-13 09:28:16 +00:00
|
|
|
|
|
|
|
|
|
if (ditta.fisica())
|
|
|
|
|
{
|
|
|
|
|
add_header_data( 7, ditta.cognome());
|
|
|
|
|
add_header_data( 8, ditta.nome());
|
|
|
|
|
add_header_data( 9, ditta.sesso() == 'F' ? "F" : "M");
|
|
|
|
|
add_header_data(10, ditta.data_nascita().string(full, '\0', full, full, gma_date));
|
|
|
|
|
add_header_data(11, ditta.comune_nascita());
|
|
|
|
|
add_header_data(12, ditta.provincia_nascita());
|
|
|
|
|
add_header_data(13, EMPTY_STRING);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
add_header_data( 7, EMPTY_STRING);
|
|
|
|
|
add_header_data( 8, EMPTY_STRING);
|
|
|
|
|
add_header_data( 9, EMPTY_STRING);
|
|
|
|
|
add_header_data(10, EMPTY_STRING);
|
|
|
|
|
add_header_data(11, EMPTY_STRING);
|
|
|
|
|
add_header_data(12, EMPTY_STRING);
|
|
|
|
|
add_header_data(13, ditta.ragione_sociale());
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
add_header_data(14, msk.get(F_ANNO));
|
2015-03-31 06:06:33 +00:00
|
|
|
|
add_header_data(15, EMPTY_STRING);
|
2013-12-13 09:28:16 +00:00
|
|
|
|
add_header_data(16, TFixed_string("04879210963"));
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
if (ateco.blank())
|
|
|
|
|
return error_box("Manca il codice attivit<69> ATECO nell'anagrafica della ditta %ld", codditta);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return true;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
bool TSpesometro_set::add_footer(const TMask& /*msk*/)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
// Elimina elementi composti da un solo spazio
|
|
|
|
|
for (TRecnotype i = items()-1; i >= 0; i--)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TToken_string& r = row(i);
|
|
|
|
|
if (r.empty_items())
|
|
|
|
|
{
|
|
|
|
|
destroy(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
for (;;)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const int p = r.find("| |");
|
|
|
|
|
if (p > 0)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
r.overwrite(r.mid(p+2), p+1);
|
|
|
|
|
r.rtrim(1);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
else
|
|
|
|
|
break;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
r.rtrim();
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
2013-12-13 09:28:16 +00:00
|
|
|
|
return true;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
void TSpesometro_set::init()
|
|
|
|
|
{
|
|
|
|
|
create_column("Tipo", _alfafld); // 0
|
|
|
|
|
create_column("PartitaIVA", _alfafld);
|
|
|
|
|
create_column("CodiceFiscale", _alfafld);
|
|
|
|
|
create_column("IVANonEsposta", _boolfld);
|
|
|
|
|
create_column("Noleggio", _alfafld);
|
|
|
|
|
create_column("Autofattura", _boolfld); // 5
|
|
|
|
|
create_column("ReverseCharge", _boolfld);
|
|
|
|
|
create_column("DataDoc", _datefld);
|
|
|
|
|
create_column("DataReg", _datefld);
|
|
|
|
|
create_column("NumDoc", _alfafld);
|
|
|
|
|
create_column("TipoOperazione", _alfafld); // 10
|
|
|
|
|
create_column("TipoDocumento", _alfafld);
|
|
|
|
|
create_column("Imponibile", _realfld); // 12
|
|
|
|
|
create_column("Imposta", _realfld);
|
|
|
|
|
|
|
|
|
|
create_column("Cognome", _alfafld); // 14
|
|
|
|
|
create_column("Nome", _alfafld);
|
|
|
|
|
create_column("DataNasc", _datefld);
|
|
|
|
|
create_column("ComNasc", _alfafld);
|
|
|
|
|
create_column("Provincia", _alfafld);
|
|
|
|
|
create_column("StatoEstero", _alfafld); // 19
|
|
|
|
|
create_column("CittaEstera", _alfafld);
|
|
|
|
|
create_column("IndirEstero", _alfafld);
|
|
|
|
|
|
|
|
|
|
create_column("RagSoc", _alfafld); // 22
|
|
|
|
|
create_column("CittaEsteraSede", _alfafld);
|
|
|
|
|
create_column("StatoEsteroSede", _alfafld);
|
|
|
|
|
create_column("IndirEsteroSede", _alfafld);
|
|
|
|
|
create_column("CodiceIVAEstero", _alfafld);
|
|
|
|
|
|
2014-05-14 08:26:11 +00:00
|
|
|
|
create_column("BlackList", _alfafld); // 27 S o M o blank
|
2013-12-13 09:28:16 +00:00
|
|
|
|
create_column("NonResidente", _boolfld);
|
|
|
|
|
create_column("AcquistoDaNonRes", _boolfld);
|
|
|
|
|
create_column("TipoImponibile", _alfafld);
|
|
|
|
|
|
|
|
|
|
create_column("OperazAggAttive", _intfld); // 31
|
|
|
|
|
create_column("OperazAggPassive", _intfld);
|
|
|
|
|
|
|
|
|
|
create_column("FatturaRiepilogativa", _boolfld);
|
|
|
|
|
create_column("SchedaCarburante", _boolfld); // 34
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSpesometro_set::TSpesometro_set(const TFilename& file) : TCSV_recordset("CSV(|)")
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
2013-12-13 09:28:16 +00:00
|
|
|
|
load_file(file);
|
|
|
|
|
move_first();
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TSpesometro_set::TSpesometro_set() : TCSV_recordset("CSV(|)")
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TCofi_cache
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-11-15 16:55:19 +00:00
|
|
|
|
TObject* TCofi_cache::find_ragsoc(bool piva, char tipocf, const TString& code)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
2011-11-15 16:55:19 +00:00
|
|
|
|
const int fkey = piva ? 5 : 4;
|
|
|
|
|
const char* kfield = piva ? CLI_PAIV : CLI_COFI;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
_clifo.setkey(fkey);
|
|
|
|
|
_clifo.zero();
|
|
|
|
|
_clifo.put(CLI_TIPOCF, tipocf);
|
2011-11-15 16:55:19 +00:00
|
|
|
|
_clifo.put(kfield, code);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
int err = _clifo.read();
|
2011-11-15 16:55:19 +00:00
|
|
|
|
|
|
|
|
|
if (err == NOERR && _clifo.get_int(CLI_ALLEG) == 4) // Codice Fiscale o Partita IVA doppia
|
|
|
|
|
{
|
|
|
|
|
const long codall = _clifo.get_long(CLI_CODALLEG);
|
|
|
|
|
if (codall > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRecnotype recno = _clifo.recno();
|
|
|
|
|
_clifo.setkey(1);
|
|
|
|
|
_clifo.put(CLI_TIPOCF, tipocf);
|
|
|
|
|
_clifo.put(CLI_CODCF, codall);
|
|
|
|
|
err = _clifo.read();
|
|
|
|
|
if (err != NOERR || _clifo.get(kfield) != code)
|
|
|
|
|
err = _clifo.readat(recno);
|
|
|
|
|
_clifo.setkey(fkey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err != NOERR && piva && pi_check("IT", code))
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
_clifo.put(CLI_TIPOCF, tipocf);
|
|
|
|
|
_clifo.put(CLI_STATOPAIV, "IT");
|
|
|
|
|
_clifo.put(CLI_PAIV, code);
|
|
|
|
|
err = _clifo.read();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
return new TString80(_clifo.get(CLI_RAGSOC));
|
|
|
|
|
|
2011-11-15 16:55:19 +00:00
|
|
|
|
if (piva && !pi_check("IT", code)) // cerco partite IVA estere
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
TString query;
|
|
|
|
|
query << "USE CLIFO SELECT PAIV=\"" << code << '"'
|
|
|
|
|
<< "\nFROM TIPOCF=" << tipocf
|
|
|
|
|
<< "\nTO TIPOCF=" << tipocf;
|
|
|
|
|
TISAM_recordset clifo(query);
|
|
|
|
|
if (clifo.move_first())
|
|
|
|
|
return new TString80(clifo.get(CLI_RAGSOC).as_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_occas.put(OCC_CFPI, code);
|
|
|
|
|
if (_occas.read() == NOERR)
|
|
|
|
|
{
|
2011-11-15 16:55:19 +00:00
|
|
|
|
const TString& cfpi = _occas.get(piva ? OCC_PAIV : OCC_COFI);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
if (code == cfpi || cfpi.empty())
|
|
|
|
|
return new TString80(_occas.get(OCC_RAGSOC));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString query;
|
|
|
|
|
query << "USE OCCAS SELECT ";
|
2011-11-15 16:55:19 +00:00
|
|
|
|
if (piva)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
query << "PAIV=\"" << code << '"';
|
2011-11-15 16:55:19 +00:00
|
|
|
|
else
|
|
|
|
|
query << "COFI=\"" << code << '"';
|
2011-11-14 17:29:27 +00:00
|
|
|
|
TISAM_recordset occas(query);
|
|
|
|
|
if (occas.move_first())
|
|
|
|
|
return new TString80(occas.get(OCC_RAGSOC).as_string());
|
2012-01-20 11:51:26 +00:00
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:55:19 +00:00
|
|
|
|
TObject* TCofi_cache::key2obj(const char* key)
|
|
|
|
|
{
|
|
|
|
|
TToken_string chiave(key);
|
|
|
|
|
const bool paiv = chiave.get_char(0)=='P';
|
|
|
|
|
const char tipocf = chiave.get_char(1);
|
|
|
|
|
TString16 code; chiave.get(2, code);
|
|
|
|
|
|
|
|
|
|
TObject* ragsoc = NULL;
|
|
|
|
|
if (code.full())
|
|
|
|
|
{
|
|
|
|
|
if (tipocf != 'C' && tipocf != 'F')
|
|
|
|
|
{
|
|
|
|
|
ragsoc = find_ragsoc(paiv, 'C', code);
|
|
|
|
|
if (ragsoc == NULL)
|
|
|
|
|
ragsoc = find_ragsoc(paiv, 'F', code);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ragsoc = find_ragsoc(paiv, tipocf, code);
|
|
|
|
|
}
|
|
|
|
|
return ragsoc;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 17:29:27 +00:00
|
|
|
|
const TString& TCofi_cache::cofi2ragsoc(char tipocf, const TString& cofi)
|
|
|
|
|
{
|
2012-01-20 11:51:26 +00:00
|
|
|
|
const TString* ragsoc = NULL;
|
2011-11-15 16:55:19 +00:00
|
|
|
|
if (cofi.full())
|
|
|
|
|
{
|
|
|
|
|
TString80 key;
|
|
|
|
|
key.format("CF|%c|%s", tipocf, (const char*)cofi);
|
|
|
|
|
ragsoc = (const TString*)objptr(key);
|
|
|
|
|
}
|
2012-01-20 11:51:26 +00:00
|
|
|
|
if (ragsoc == NULL)
|
|
|
|
|
{
|
|
|
|
|
TString& str = get_tmp_string();
|
|
|
|
|
str << TR("C.F. sconosciuto ") << cofi;
|
|
|
|
|
ragsoc = &str;
|
|
|
|
|
}
|
2011-12-20 13:20:00 +00:00
|
|
|
|
return *ragsoc;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TCofi_cache::paiv2ragsoc(char tipocf, const TString& paiv)
|
|
|
|
|
{
|
2012-01-20 11:51:26 +00:00
|
|
|
|
const TString* ragsoc = NULL;
|
2011-11-15 16:55:19 +00:00
|
|
|
|
if (paiv.full())
|
|
|
|
|
{
|
|
|
|
|
TString80 key;
|
|
|
|
|
key.format("PI|%c|%s", tipocf, (const char*)paiv);
|
|
|
|
|
ragsoc = (const TString*)objptr(key);
|
|
|
|
|
}
|
2012-01-20 11:51:26 +00:00
|
|
|
|
if (ragsoc == NULL)
|
|
|
|
|
{
|
|
|
|
|
TString& str = get_tmp_string();
|
|
|
|
|
str << TR("P.I. sconosciuta ") << paiv;
|
|
|
|
|
ragsoc = &str;
|
|
|
|
|
}
|
2011-12-20 13:20:00 +00:00
|
|
|
|
return *ragsoc;
|
2011-11-14 17:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2013-12-13 09:28:16 +00:00
|
|
|
|
// TSpesometro_rep
|
2011-11-14 17:29:27 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
bool TSpesometro_rep::get_usr_val(const TString& name, TVariant& var) const
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (name == "ANNO")
|
|
|
|
|
{
|
2013-12-13 09:28:16 +00:00
|
|
|
|
const TFixed_string d("DataReg");
|
|
|
|
|
TVariant var;
|
|
|
|
|
if (!get_record_field(d, var))
|
|
|
|
|
var = "2013";
|
|
|
|
|
else
|
|
|
|
|
var = var.as_string().right(4);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
return true;
|
2013-12-13 09:28:16 +00:00
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
return TReport::get_usr_val(name, var);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TSpesometro_rep::TSpesometro_rep(const TFilename& file)
|
2011-11-14 17:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
load("fe0100");
|
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
TSpesometro_set* set = new TSpesometro_set(file);
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
2013-12-13 09:28:16 +00:00
|
|
|
|
// Elimina dati di testata e coda
|
|
|
|
|
for (TRecnotype i = set->items()-1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (set->move_to(i))
|
|
|
|
|
{
|
|
|
|
|
const TString& t = set->get(0).as_string();
|
|
|
|
|
if (t.blank() || t.starts_with("SO"))
|
|
|
|
|
set->destroy(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-11-14 17:29:27 +00:00
|
|
|
|
|
|
|
|
|
set_recordset(set);
|
|
|
|
|
}
|