Files correlati : fp, cg Commento: Aggiunta: -Aggiunte descrizione differenziata per TD17\TD19 Integrazioni e Autofattura. Campo controlla il flag Stato EU nel code ISO e se il cliente è intacomunitario ci scrive "Integrazione" altrimenti "Autofattura". Bug: -il paf0200 (e molti altri in realtà) non venivano resettati una volta inizializzati. Se si elaboravano più integrazioni contemporaneamente i dati del cedente prestatore della prima integrazione venivano riportati anche sulle altre
934 lines
22 KiB
C++
934 lines
22 KiB
C++
#include <applicat.h>
|
||
#include <lffiles.h>
|
||
#include <modaut.h>
|
||
#include <recarray.h>
|
||
#include <validate.h>
|
||
|
||
#include "cglib.h"
|
||
#include "../ve/condv.h"
|
||
#include "../li/letint.h"
|
||
#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>
|
||
#include <comuni.h>
|
||
#
|
||
#include <nditte.h>
|
||
|
||
bool 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
|
||
///////////////////////////////////////////////////////////
|
||
|
||
static bool is_stato_estero(const TString& codcom)
|
||
{
|
||
return codcom.full() && codcom.match("Z[0-9][0-9][0-9]");
|
||
}
|
||
|
||
static const TString& comune(const TString& codcom, int stato)
|
||
{
|
||
if (codcom.blank() || codcom.len() != 4)
|
||
return EMPTY_STRING;
|
||
|
||
TString8 key;
|
||
if (stato > 0)
|
||
key.format("%03d", stato);
|
||
key << '|' << codcom;
|
||
return cache().get(LF_COMUNI, key, COM_DENCOM);
|
||
}
|
||
|
||
static const TString& provincia(const TString& codcom)
|
||
{
|
||
if (codcom.blank() || codcom.len() != 4)
|
||
return EMPTY_STRING;
|
||
TString& prov = get_tmp_string();
|
||
if (is_stato_estero(codcom))
|
||
prov = "EE";
|
||
else
|
||
{
|
||
TString8 key; key << '|' << codcom;
|
||
prov = cache().get(LF_COMUNI, key, COM_PROVCOM);
|
||
if (prov.len() > 2) prov = "RM";
|
||
}
|
||
return prov;
|
||
}
|
||
|
||
const TString& TAnagrafica::comune_nascita() const
|
||
{
|
||
if (is_stato_estero(_com_nasc))
|
||
{
|
||
const TString& c = comune(_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(_com_nasc, _stato_nasc);
|
||
}
|
||
|
||
const TString& TAnagrafica::provincia_nascita() const
|
||
{
|
||
if (_stato_nasc > 0 || is_stato_estero(_com_nasc))
|
||
return get_tmp_string() = "EE";
|
||
return provincia(_com_nasc);
|
||
}
|
||
|
||
const TString& TAnagrafica::comune_residenza() const
|
||
{
|
||
const TString& cr = comune(_com_res, _stato_estero);
|
||
if (cr.full())
|
||
return cr;
|
||
return _loc_res;
|
||
}
|
||
|
||
const TString& TAnagrafica::provincia_residenza() const
|
||
{
|
||
if (estero())
|
||
return get_tmp_string() = "EE";
|
||
return provincia(_com_res);
|
||
}
|
||
|
||
const TString& TAnagrafica::stato_residenza_ISO() const
|
||
{
|
||
if (italiano())
|
||
return get_tmp_string() = "IT";
|
||
else
|
||
{
|
||
TString4 u; u.format("%03d", _stato_estero);
|
||
return cache().get("%STA", u, "S10");
|
||
}
|
||
}
|
||
|
||
void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char* civ)
|
||
{
|
||
_via_res = _ind_res = rec.get(ind);
|
||
_civ_res = rec.get(civ);
|
||
|
||
if (_civ_res.blank())
|
||
{
|
||
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();
|
||
}
|
||
}
|
||
|
||
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
|
||
if (_stato_estero <= 0 && is_stato_estero(_com_res))
|
||
{
|
||
const TString80 naz = comune(_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::ragione_sociale() const
|
||
{
|
||
if (fisica())
|
||
{
|
||
TString& rs = get_tmp_string();
|
||
rs = _ragsoc;
|
||
return rs.strip_double_spaces();
|
||
}
|
||
return _ragsoc;
|
||
}
|
||
|
||
const TString& TAnagrafica::cognome() const
|
||
{
|
||
TString& c = get_tmp_string();
|
||
c = _ragsoc.left(30);
|
||
return c.trim();
|
||
}
|
||
|
||
const TString& TAnagrafica::nome() const
|
||
{
|
||
//CHECK(fisica(), "Non chiedere nome giuridico!");
|
||
TString& c = get_tmp_string();
|
||
c = _ragsoc.mid(30, 20);
|
||
return c.trim();
|
||
}
|
||
|
||
bool TAnagrafica::italiano() const
|
||
{
|
||
return _stato_estero == 0 && !is_stato_estero(_com_res);
|
||
}
|
||
|
||
bool TAnagrafica::estero_CEE() const
|
||
{
|
||
return estero() && cache().get_bool("%SCE", stato_residenza_ISO(), "B0") ;
|
||
}
|
||
|
||
const TString& TAnagrafica::stato_estero_UNICO() const
|
||
{
|
||
if (_stato_estero <= 0)
|
||
return EMPTY_STRING;
|
||
|
||
TString4 u; u.format("%03d", _stato_estero);
|
||
const TString& cod = cache().get("%STA", u, "S8"); // S8=UNICO S9=ISTAT S10=ISO
|
||
if (cod.len() == 3)
|
||
return cod;
|
||
return get_tmp_string() = u;
|
||
}
|
||
|
||
const TString& TAnagrafica::stato_partita_IVA() const
|
||
{
|
||
TString& str = get_tmp_string();
|
||
if (_stato_paiv.full())
|
||
str = _stato_paiv;
|
||
else if (italiano())
|
||
{
|
||
str = "IT";
|
||
}
|
||
return str;
|
||
}
|
||
|
||
char TAnagrafica::is_black_list(const TDate& datareg) const
|
||
{
|
||
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
|
||
{
|
||
if (datareg.date2ansi() < TDate(24, 2, 2014))
|
||
is_black = 'M';
|
||
}
|
||
else
|
||
{
|
||
if (sta.get_bool("B0")) // Black List
|
||
is_black = 'S';
|
||
}
|
||
}
|
||
return is_black;
|
||
}
|
||
|
||
void TAnagrafica::split_ragsoc()
|
||
{
|
||
if (_tipo == 'F')
|
||
{
|
||
if (nome().blank())
|
||
{
|
||
const int space = _ragsoc.find(' ');
|
||
if (space >= 4)
|
||
{
|
||
TString80 nom = _ragsoc.mid(space + 1);
|
||
nom.cut(20);
|
||
_ragsoc.cut(space);
|
||
_ragsoc.insert(nom, 30);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
_ragsoc.strip_double_spaces();
|
||
_ragsoc.replace('"', '\''); // gli " creano casini nel csv
|
||
}
|
||
|
||
bool TAnagrafica::init(const TRectype& rec)
|
||
{
|
||
_tipo = '\0';
|
||
_sociounico = '\0';
|
||
_stato_estero = _stato_nasc = 0;
|
||
_allegato = 0;
|
||
_ragsoc.cut(0);
|
||
|
||
if (rec.empty())
|
||
return false;
|
||
|
||
bool is_firm = 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;
|
||
}
|
||
_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);
|
||
_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';
|
||
decode_cofi(_cofi, sex, _data_nasc, _com_nasc);
|
||
}
|
||
}
|
||
else
|
||
_tipo = 'G';
|
||
_allegato = _tipo == 'F' ? 6 : 2;
|
||
_pec = "";
|
||
_coddest = "0000000";
|
||
break;
|
||
case LF_ANAG:
|
||
_tipo = rec.get_char(ANA_TIPOA);
|
||
_ragsoc = rec.get(ANA_RAGSOC);
|
||
_cofi = rec.get(ANA_COFI);
|
||
_cofiest = rec.get(ANA_COFIEST);
|
||
_paiv = rec.get(ANA_PAIV);
|
||
_stato_paiv = rec.get(ANA_STATOPAIV);
|
||
|
||
if (_ragsoc.starts_with("EYCK"))
|
||
int zingara = 1;
|
||
|
||
// Comune di residenza fiscale o domicilio
|
||
_stato_estero = rec.get_int(ANA_STATORES);
|
||
_com_res = rec.get(ANA_COMRES);
|
||
//if (_com_res.empty())
|
||
// _com_res = rec.get(ANA_COMRF);
|
||
build_ind_res(rec, ANA_INDRES, ANA_CIVRES);
|
||
_cap_res = rec.get(ANA_CAPRES);
|
||
|
||
// Dati di nascita persone fisiche
|
||
if (_tipo == 'F' || (italiano() && isalpha(_cofi[0])))
|
||
{
|
||
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);
|
||
if ((!_data_nasc.ok() || _com_nasc.blank()) && cf_check("", _cofi))
|
||
{
|
||
char sex = 'X';
|
||
decode_cofi(_cofi, sex, _data_nasc, _com_nasc);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
_tipo = 'G';
|
||
_pec = "";
|
||
_coddest = "0000000";
|
||
break;
|
||
case LF_NDITTE:
|
||
{
|
||
const char tipoa = rec.get_char(NDT_TIPOA);
|
||
const long codana = rec.get_long(NDT_CODANAGR);
|
||
const bool good = init(LF_ANAG, tipoa, codana);
|
||
_sociounico = rec.get_char(NDT_SOCIOUNICO);
|
||
if (_tipo == 'G')
|
||
{
|
||
_ragsoc = rec.get(NDT_RAGSOC);
|
||
split_ragsoc();
|
||
}
|
||
_pec = "";
|
||
_cod_EORI = rec.get(NDT_CODEORI);
|
||
_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)
|
||
{
|
||
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 (_com_nasc.blank())
|
||
{
|
||
_com_nasc = rec.get(CLI_COMNASC);
|
||
if (_com_nasc.blank() && 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())
|
||
{
|
||
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
|
||
|
||
_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")
|
||
{
|
||
// 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);
|
||
|
||
_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)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
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));
|
||
case LF_EFFETTI:
|
||
return init(rec.get_char(EFF_TIPOCF), rec.get_long(EFF_CODCF), EMPTY_STRING);
|
||
case LF_PERC:
|
||
return init(LF_ANAG, rec.get_char("TIPOA"), rec.get_long("CODANAGR"));
|
||
default:
|
||
CHECKD(false, "Record non valido per TAnagrafica ", rec.num());
|
||
break;
|
||
}
|
||
split_ragsoc();
|
||
|
||
return _tipo == 'F' || _tipo == 'G';
|
||
}
|
||
|
||
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));
|
||
}
|
||
|
||
bool TAnagrafica::init(int num, char tipo, long codice)
|
||
{
|
||
TString8 key; key.format("%c|%ld", tipo, codice);
|
||
return init(cache().get(num, key));
|
||
}
|
||
|
||
bool TAnagrafica::init(char tipocf, long codice, const TString& ocfpi)
|
||
{
|
||
bool done = false;
|
||
if (ocfpi.full())
|
||
done = init(LF_OCCAS, ocfpi);
|
||
if (!done)
|
||
{
|
||
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);
|
||
}
|
||
return done;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TCache_clifor
|
||
///////////////////////////////////////////////////////////
|
||
class TCache_clifor : public TCache
|
||
{
|
||
protected:
|
||
virtual TObject* key2obj(const char* key);
|
||
|
||
public:
|
||
const TCli_for & clifor(const char tipo, const long codice);
|
||
|
||
TCache_clifor() : TCache() { }
|
||
virtual ~TCache_clifor() { }
|
||
};
|
||
|
||
TObject* TCache_clifor::key2obj(const char* key)
|
||
{
|
||
TToken_string k(key);
|
||
TString4 tipo;
|
||
long codice;
|
||
|
||
k.get(0, tipo);
|
||
k.get(1, codice);
|
||
return new TCli_for(tipo[0], codice);
|
||
}
|
||
|
||
const TCli_for & TCache_clifor::clifor(const char tipo, const long codice)
|
||
{
|
||
TToken_string k; k << tipo;
|
||
k.add(codice);
|
||
return (const TCli_for &)*objptr(k);
|
||
}
|
||
|
||
const TCli_for & cached_clifor(const char tipo, long codice)
|
||
{
|
||
HIDDEN TCache_clifor __cache_clifor;
|
||
|
||
return __cache_clifor.clifor(tipo, codice);
|
||
}
|
||
|
||
const TCli_for & cached_clifor(int file, const TRectype & rec)
|
||
{
|
||
char tipo = ' ';
|
||
long codice = 0L;
|
||
|
||
switch (file)
|
||
{
|
||
case LF_MOV:
|
||
tipo = rec.get_char(MOV_TIPO);
|
||
codice = rec.get_long(MOV_CODCF);
|
||
break;
|
||
case LF_DOC:
|
||
tipo = rec.get_char(DOC_TIPOCF);
|
||
codice = rec.get_long(DOC_CODCF);
|
||
break;
|
||
default:
|
||
tipo = rec.get_char(CLI_TIPOCF);
|
||
codice = rec.get_long(CLI_CODCF);
|
||
break;
|
||
}
|
||
return cached_clifor(tipo, codice);
|
||
}
|
||
|
||
TOccasionale::TOccasionale() : TRectype(LF_OCCAS)
|
||
{ }
|
||
|
||
TOccasionale::TOccasionale(const TRectype& r) : TRectype(r)
|
||
{ }
|
||
|
||
TOccasionale::TOccasionale(const TOccasionale& r) : TRectype(r)
|
||
{ }
|
||
|
||
TRectype& TOccasionale::operator=(const TRectype& r)
|
||
{
|
||
return TRectype::operator=(r);
|
||
}
|
||
|
||
TOccasionale& TOccasionale::operator=(const TOccasionale& r)
|
||
{
|
||
TRectype::operator=(r);
|
||
return *this;
|
||
}
|
||
|
||
TOccasionale::~TOccasionale()
|
||
{ }
|
||
|
||
int TCli_for::write_rewrite(TBaseisamfile& f, bool re) const
|
||
{
|
||
int err = TMultiple_rectype::write_rewrite(f, re);
|
||
|
||
if (err == NOERR)
|
||
{
|
||
TLocalisamfile v(LF_CFVEN);
|
||
const TRectype& v_rec = vendite();
|
||
err = v.write(v_rec);
|
||
if (err == _isreinsert)
|
||
err = v.write(v_rec);
|
||
}
|
||
return err;
|
||
}
|
||
|
||
TRectype& TCli_for::vendite() const
|
||
{
|
||
const char t = tipo();
|
||
const long c = codice();
|
||
|
||
if (_ven_rec.empty() || t != _ven_rec.get_char(CFV_TIPOCF) || c != _ven_rec.get_long(CFV_CODCF))
|
||
{
|
||
TLocalisamfile v(LF_CFVEN);
|
||
v.put(CFV_TIPOCF,t);
|
||
v.put(CFV_CODCF, c);
|
||
if (v.read() == NOERR)
|
||
((TCli_for*)this)->_ven_rec = v.curr();
|
||
}
|
||
return (TRectype &) _ven_rec;
|
||
}
|
||
|
||
bool TCli_for::read_lettera(const TDate& data, bool extended)
|
||
{
|
||
if (use_lettere())
|
||
{
|
||
if (data != _last_data || _extended != extended)
|
||
{
|
||
_letint.zero();
|
||
TRelation r(LF_LETINT);
|
||
|
||
TRectype to(r.curr());
|
||
to.put(LETINT_CODCLI, codice());
|
||
to.put(LETINT_ANNO, data.year());
|
||
|
||
TRectype from(to);
|
||
from.put(LETINT_ANNO, data.year() - 1);
|
||
|
||
TCursor c(&r, "", 2, &from, &to);
|
||
const int items = c.items();
|
||
if (items > 0)
|
||
{
|
||
TDate dal;
|
||
TDate al(31, 12, data.year());
|
||
|
||
for (long pos = items - 1; pos >= 0L; pos--)
|
||
{
|
||
c = pos;
|
||
|
||
const int tipo = c.curr().get_int(LETINT_TIPOOP);
|
||
|
||
if (tipo == 3) // Nel periodo
|
||
{
|
||
dal = c.curr().get_date(LETINT_DAL);
|
||
al = c.curr().get_date(LETINT_AL);
|
||
}
|
||
else if(tipo == 2)
|
||
{
|
||
dal = c.curr().get_date(LETINT_DAL);
|
||
if (c.pos() < items - 1)
|
||
{
|
||
++c;
|
||
const int tipo_next = c.curr().get_int(LETINT_TIPOOP);
|
||
if (tipo_next == 3 || tipo_next == 2)
|
||
al = c.curr().get_date(LETINT_DAL);
|
||
else
|
||
al = c.curr().get_date(LETINT_VSDATA);
|
||
--c;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
dal = c.curr().get_date(LETINT_VSDATA);
|
||
if (c.pos() < items - 1)
|
||
{
|
||
++c;
|
||
const int tipo_next = c.curr().get_int(LETINT_TIPOOP);
|
||
if (tipo_next == 3)
|
||
al = c.curr().get_date(LETINT_DAL);
|
||
else
|
||
al = c.curr().get_date(LETINT_VSDATA);
|
||
--c;
|
||
}
|
||
}
|
||
if (dal <= data)
|
||
{
|
||
_letint = c.curr();
|
||
break;
|
||
}
|
||
}
|
||
_lettera_found = !_letint.empty();
|
||
if (_lettera_found && !extended)
|
||
_lettera_found = data <= al;
|
||
}
|
||
_last_data = data;
|
||
_extended = extended;
|
||
}
|
||
}
|
||
return _lettera_found;
|
||
}
|
||
const TRectype & TCli_for::indsp(const int codindsp) const
|
||
{
|
||
TToken_string key = tipo();
|
||
|
||
key.add(codice());
|
||
key.add(codindsp);
|
||
const TRectype & recindsp = cache().get(LF_INDSP, key);
|
||
|
||
return recindsp;
|
||
}
|
||
|
||
int TCli_for::read(const TRectype & rec, word op, word lockop)
|
||
{
|
||
_ven_rec.zero();
|
||
int err = TMultiple_rectype::read(rec, op, lockop);
|
||
_last_data = botime;
|
||
return err;
|
||
}
|
||
|
||
int TCli_for::read(char tipo, long codice, word op, word lockop)
|
||
{
|
||
int err = NOERR;
|
||
_ven_rec.zero();
|
||
zero();
|
||
if (tipo > ' ' && codice > 0L)
|
||
{
|
||
put(CLI_TIPOCF, tipo);
|
||
put(CLI_CODCF, codice);
|
||
err = TMultiple_rectype::read(op, lockop);
|
||
}
|
||
_last_data = botime;
|
||
return err;
|
||
}
|
||
|
||
int TCli_for::remove(TBaseisamfile& f) const
|
||
{
|
||
TLocalisamfile v(LF_CFVEN);
|
||
const int err = vendite().remove(v);
|
||
if (err != NOERR && err != _iskeynotfound)
|
||
return err;
|
||
return TMultiple_rectype::remove(f);
|
||
}
|
||
|
||
void TCli_for::init()
|
||
{
|
||
_use_lettere = main_app().has_module(LIAUT, CHK_DONGLE);
|
||
}
|
||
|
||
const TString& TCli_for::find_listino_al(const TDate& datadoc) const
|
||
{
|
||
const bool gest_list_catven = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV", false, 1);
|
||
const TRectype& v = vendite();
|
||
TString4 listino = v.get(CFV_CODLIST);
|
||
|
||
TToken_string key_condv;
|
||
key_condv = "L";
|
||
if (gest_list_catven)
|
||
key_condv.add(v.get(CFV_CATVEN));
|
||
|
||
//se il cliente ha un listino specificato -> va usato (previo controllo validit<69>)
|
||
while (listino.full())
|
||
{
|
||
key_condv.add(listino, 4);
|
||
|
||
const TRectype& rec_condv = cache().get(LF_CONDV, key_condv);
|
||
const TDate inizio_validita = rec_condv.get_date(CONDV_VALIN);
|
||
const TDate fine_validita = rec_condv.get_date(CONDV_VALFIN);
|
||
|
||
// usa il listino indicato sul cliente solo se <20> valido per la data del documento
|
||
if (datadoc >= inizio_validita && (datadoc <= fine_validita || !fine_validita.ok()))
|
||
break;
|
||
|
||
listino = rec_condv.get(CONDV_CODLISSUCC);
|
||
}
|
||
return get_tmp_string() = listino;
|
||
}
|
||
|
||
const TString& TCli_for::get_iban()
|
||
{
|
||
TString & iban = get_tmp_string(30);
|
||
TToken_string key;
|
||
|
||
key.add(tipo());
|
||
key.add(codice());
|
||
key.add("V");
|
||
key.add(1);
|
||
|
||
const TRectype& cfban = cache().get(LF_CFBAN, key);
|
||
|
||
if (!cfban.empty())
|
||
{
|
||
const TString& abi_cf = cfban.get(CFBAN_ABI);
|
||
const TString& cab_cf = cfban.get(CFBAN_CAB);
|
||
iban = cfban.get(CFBAN_IBAN);
|
||
}
|
||
return iban;
|
||
}
|
||
|
||
TToken_string& TCli_for::get_ban_pres(int nprog)
|
||
{
|
||
TToken_string & ban = get_tmp_string(30);
|
||
TToken_string key;
|
||
|
||
key.add(tipo());
|
||
key.add(codice());
|
||
key.add("N");
|
||
key.add(nprog);
|
||
|
||
const TRectype& cfban = cache().get(LF_CFBAN, key);
|
||
|
||
if (!cfban.empty())
|
||
{
|
||
ban.add(cfban.get(CFBAN_ABI));
|
||
ban.add(cfban.get(CFBAN_CAB));
|
||
ban.add(cfban.get(CFBAN_PROGPR));
|
||
}
|
||
return ban;
|
||
}
|
||
|
||
TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN),
|
||
_letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false)
|
||
{
|
||
init();
|
||
add_file(LF_INDSP, IND_CODIND);
|
||
if (tipo > ' ' && codice > 0L)
|
||
read(tipo, codice);
|
||
_anagr.init(LF_CLIFO, tipo, codice);
|
||
}
|
||
|
||
|
||
TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN),
|
||
_letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false)
|
||
{
|
||
init();
|
||
add_file(LF_INDSP, IND_CODIND);
|
||
read(rec);
|
||
_anagr.init(LF_CLIFO, tipo(), codice());
|
||
}
|
||
|
||
TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec),
|
||
_letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false)
|
||
{
|
||
init();
|
||
_anagr.init(LF_CLIFO, tipo(), codice());
|
||
}
|
||
|
||
TCli_for::~TCli_for()
|
||
{ }
|
||
|