2020-04-01 21:26:49 +02:00
|
|
|
#include "f9lib01.h"
|
|
|
|
#include "f1lib.h"
|
|
|
|
#include "f901tab.h"
|
|
|
|
#include "progind.h"
|
|
|
|
#include "clifo.h"
|
|
|
|
#include <cg2103.h>
|
|
|
|
#include "mov.h"
|
|
|
|
#include "../fp/fplib.h"
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
|
|
|
|
statistics _stats = { 0 };
|
|
|
|
|
2020-04-18 16:00:37 +02:00
|
|
|
// Controlla eventuali apostrofi e li raddoppia
|
2020-04-01 21:26:49 +02:00
|
|
|
const char* check_str(const TString& str);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
// TEstrazione
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const char* TEstrazione::categoria_doc()
|
|
|
|
{
|
|
|
|
return ""; // todo:
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
const char* TEstrazione::caus_sos(const TLocalisamfile& mov, const TipoIVA iva)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
if (iva == iva_acquisti)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
TToken_string keys(mov.get(MOV_KEYFPPRO));
|
|
|
|
fppro_db().set_keys(keys);
|
|
|
|
return fppro_db().get_tipodoc();
|
|
|
|
}
|
2020-05-14 23:38:30 +02:00
|
|
|
if (iva == iva_vendite)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
const TDocumento doc(mov.get(MOV_DPROVV)[0], mov.get_int(MOV_DANNO), mov.get(MOV_DCODNUM), mov.get_int(MOV_DNDOC));
|
|
|
|
static TString tipo_doc_sdi;
|
|
|
|
return tipo_doc_sdi = doc.tipo().tipo_doc_sdi();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
bool TEstrazione::check_documento_vendita(const TLocalisamfile& mov, _Out_ bool& exist_doc)
|
|
|
|
{
|
|
|
|
if (!mov.get(MOV_DPROVV).empty() && !mov.get(MOV_DANNO).empty() && !mov.get(MOV_DCODNUM).empty() && !mov.get(MOV_DNDOC).empty())
|
|
|
|
{
|
|
|
|
TString hfatt(20), bfatt(50), query;
|
|
|
|
const TDocumento doc(mov.get(MOV_DPROVV)[0], mov.get_int(MOV_DANNO), mov.get(MOV_DCODNUM), mov.get_int(MOV_DNDOC));
|
|
|
|
|
|
|
|
exist_doc = true;
|
|
|
|
if (chiave_paf(doc, hfatt, bfatt))
|
|
|
|
{
|
|
|
|
query << "SELECT * FROM PAF0100F WHERE P1_KEYHEADERFATT = '" << hfatt << "' AND P1_KEYBODYFATT = '" << bfatt << "';";
|
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
return fp_db().sq_items() > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
exist_doc = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
state_fppro TEstrazione::check_fppro(int numreg)
|
|
|
|
{
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
|
|
|
if (mov.read() == NOERR && check_causale(mov.get(MOV_CODCAUS)))
|
|
|
|
{
|
|
|
|
// Controllo se ho i riferimenti all'FPPRO e verifico che sia tutto ok
|
|
|
|
const TString& keys_fppro = mov.get(MOV_KEYFPPRO);
|
|
|
|
if (keys_fppro.full())
|
|
|
|
{
|
|
|
|
TToken_string keys(keys_fppro, ';');
|
|
|
|
if (fppro_db().check_reg(keys, numreg))
|
|
|
|
return correct;
|
|
|
|
TString err(fppro_db().get_last_error());
|
|
|
|
if (!err.empty())
|
2020-04-14 10:19:04 +02:00
|
|
|
{
|
2020-04-01 21:26:49 +02:00
|
|
|
error_box(err.cut(0) << "Errore durante il controllo del movimento n. " << numreg << "\n" << err);
|
2020-04-14 10:19:04 +02:00
|
|
|
return err_read_db;
|
|
|
|
}
|
2020-04-01 21:26:49 +02:00
|
|
|
return reg_with_err;
|
|
|
|
}
|
|
|
|
else // Se non ho i riferimenti faccio guessing
|
|
|
|
{
|
|
|
|
if (fppro_db().guess_the_doc(mov))
|
|
|
|
return guessed;
|
|
|
|
return no_guessed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return not_fa;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TEstrazione::check_periodo_def() const
|
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
// Controllo se ci sono estrazioni (definitive) che si sovrappongono di periodo (con lo stesso tipo) e che non siano in stato di errore
|
|
|
|
// Nel caso di stato di errore e' invece possibile la ri-estrazione
|
2020-04-18 16:00:37 +02:00
|
|
|
query << "SELECT *\nFROM " F9_DRD "\n"
|
|
|
|
"WHERE " DRD_CODSOC " = '" << _head.cod_soc << "' AND " DRD_DATAA " >= '" << _head.dal.date2ansi() << "' AND " DRD_DATADA " <= '" <<
|
|
|
|
_head.al.date2ansi() << "' AND " DRD_FLAG_PD " = 'D' AND\n " DRD_STATO " <> '" D_GEST_ERR "' AND " DRD_STATO " <> '" D_WA_ERR "' AND "
|
|
|
|
DRD_STATO " <> '" D_ERR_SOS "' AND " DRD_TIPODOC " = '" << _head.tipo_doc << "';";
|
2020-04-01 21:26:49 +02:00
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
return fp_db().sq_items() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TEstrazione::is_doc_xml(const TLocalisamfile& mov)
|
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
const TString& tipocf = mov.get(MOV_TIPO);
|
|
|
|
const TString& codcf = mov.get(MOV_CODCF);
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
|
|
clifo.put(CLI_TIPOCF, tipocf);
|
|
|
|
clifo.put(CLI_CODCF, codcf);
|
|
|
|
clifo.read();
|
|
|
|
return (clifo.get(CLI_STATOPAIV).empty() || clifo.get(CLI_STATOPAIV) == "IT")
|
|
|
|
&& clifo.get(CLI_COMCF) != "B513"; // Campione d'Italia
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TString& TEstrazione::drd_attr()
|
|
|
|
{
|
|
|
|
static TString attr;
|
|
|
|
attr.cut(0) << DRD_CODSOC ", " DRD_ID_EST ", " DRD_FLAG_PD ", " DRD_DESC
|
|
|
|
", " DRD_TIPODOC ", " DRD_DATADA ", " DRD_DATAA ", " DRD_UTENTE ", " DRD_TIME ", "
|
|
|
|
DRD_STATO ", " DRD_PERC;
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TString& TEstrazione::drd_tovalues() const
|
|
|
|
{
|
|
|
|
static TString str;
|
|
|
|
return str.cut(0) << "'" << _head.cod_soc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "', '" << _head.descr <<
|
|
|
|
"', '" << _head.tipo_doc << "', '" << _head.dal.date2ansi() << "', '" << _head.al.date2ansi() << "', '" << _head.user << "', CURRENT_TIMESTAMP, '" <<
|
|
|
|
_head.stato_estr << "', '" << _head.addr_cart << "'";
|
|
|
|
}
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
bool TEstrazione::insert_into_drd() const
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
query << "INSERT INTO " F9_DRD " ( " << drd_attr() << " ) \nVALUES ( " << drd_tovalues() << " );";
|
|
|
|
bool ok = fp_db().sq_set_exec(query);
|
|
|
|
ok = ok && fp_db().sq_commit();
|
|
|
|
if (!ok)
|
|
|
|
write_errorsql_log(query);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
bool TEstrazione::insert_into_f9movestr() const
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-04-14 10:19:04 +02:00
|
|
|
TString query;
|
2020-04-15 18:01:09 +02:00
|
|
|
bool ok = true;
|
2020-04-14 10:19:04 +02:00
|
|
|
for(auto it = _movs.begin(); it != _movs.end(); ++it)
|
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
query.cut(0) << "INSERT INTO " F9_MOVESTR " (" MES_CODSOC ", IDESTR, NUMREG, DATAREG, ESTRATTO, DESCR_ERR)\nVALUES " <<
|
2020-04-21 18:53:15 +02:00
|
|
|
" ('" << _head.cod_soc << "', '" << _head.id_estr << "', '" << it->numreg << "', '" << it->datareg.date2ansi() << "', " <<
|
2020-04-15 18:01:09 +02:00
|
|
|
(it->estratto ? "1" : "0") << ", '" << check_str(it->get_descr_estr()) << "')";
|
2020-04-14 10:19:04 +02:00
|
|
|
#ifdef DBG
|
|
|
|
if (TString(check_str(it->get_descr_estr())).empty())
|
|
|
|
bool simo = true;
|
|
|
|
#endif
|
2020-04-15 18:01:09 +02:00
|
|
|
ok &= fp_db().sq_set_exec(query) && fp_db().sq_commit();
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
write_errorsql_log(query);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-14 10:19:04 +02:00
|
|
|
}
|
|
|
|
return ok;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TEstrazione::export_error_list() const
|
|
|
|
{
|
|
|
|
TF9_dberr dberr;
|
|
|
|
const vector<movimento_t>& movs = _movs;
|
|
|
|
bool ok = true;
|
|
|
|
int count = 0;
|
2020-04-15 18:01:09 +02:00
|
|
|
TProgress_monitor pg(movs.size(), "Scrittura movimenti in errore");
|
2020-04-01 21:26:49 +02:00
|
|
|
for (auto it = movs.begin(); it != movs.end(); ++it)
|
|
|
|
{
|
2020-04-15 18:01:09 +02:00
|
|
|
if (!pg.add_status())
|
|
|
|
break;
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
if (it->err)
|
|
|
|
{
|
|
|
|
#ifdef DBG
|
|
|
|
if (count == 25)
|
|
|
|
bool simo = true;
|
|
|
|
if (it->numreg == 187680)
|
|
|
|
bool simo = true;
|
|
|
|
#endif
|
2020-04-18 16:00:37 +02:00
|
|
|
|
|
|
|
dberr.add(_head.cod_soc);
|
2020-04-01 21:26:49 +02:00
|
|
|
dberr.add(_head.id_estr);
|
|
|
|
for (int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
TString string(it->get(i));
|
|
|
|
|
|
|
|
if (i == 2 || i == 3) // Sono obbligato a far cosi' per aggiungere le date
|
|
|
|
dberr.add(TDate(it->get(i)));
|
|
|
|
else if (string.full())
|
|
|
|
{
|
|
|
|
string.replace("'", "''");
|
|
|
|
dberr.add(string);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dberr.add(); // Se vuoto metto NULL
|
|
|
|
}
|
|
|
|
if (!(ok &= dberr.send()))
|
|
|
|
break;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
TString TEstrazione::next_estr_today(char tipo) const
|
|
|
|
{
|
|
|
|
char estr[] = { 0,0,0,0,0,0,0,0,0 };
|
|
|
|
TString query;
|
|
|
|
query << "SELECT TOP 1 " DRD_ID_EST " AS IDESTR\n"
|
|
|
|
"FROM " F9_DRD "\n"
|
2020-04-18 16:00:37 +02:00
|
|
|
"WHERE " DRD_CODSOC " = '" << _head.cod_soc << "' AND\n"
|
|
|
|
DRD_ID_EST " LIKE '" << today.date2ansi() << "%'\n" <<
|
2020-04-01 21:26:49 +02:00
|
|
|
"ORDER BY " DRD_ID_EST " DESC";
|
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
|
|
|
|
const int last_estr = fp_db().sq_items() > 0 ? real(fp_db().sq_get("IDESTR").ltrim(10)).integer() : -1;
|
|
|
|
|
|
|
|
if (last_estr < -1 || last_estr == 99999999)
|
|
|
|
{
|
|
|
|
ofstream fout; fout.open("f9err_nextestr.txt");
|
|
|
|
if (fout.is_open())
|
|
|
|
{
|
|
|
|
fout << "Errore progressivo nuova estrazione!\n" << today << "\nn:" << last_estr << "\n" << query << "\n";
|
|
|
|
fout.close();
|
|
|
|
}
|
|
|
|
TString msg;
|
|
|
|
fatal_box(msg << "database error: progressivo nuova estrazione. Ultima estrazione: " << last_estr);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf_s(estr, 9, "%08d", last_estr + 1);
|
|
|
|
return TString(estr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TEstrazione::write_errorsql_log(const TString& query) const
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
msg << query << "\n" <<
|
|
|
|
fp_db().sq_get_string_error() << "\n" <<
|
|
|
|
fp_db().sq_get_text_error();
|
|
|
|
if (_error_sql->is_open())
|
|
|
|
*_error_sql << msg << "\n\n";
|
|
|
|
#ifdef DBG
|
|
|
|
else
|
|
|
|
warning_box("Impossibile aprire il file f9_TEstrazione_error_sql.txt\nper scrivere errori scrittura db.");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Public methods /////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TEstrazione::add_mov(const movimento_t& movimento)
|
|
|
|
{
|
|
|
|
_movs.insert(_movs.end(), movimento);
|
|
|
|
}
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
bool TEstrazione::update_drd_stato_estr() const
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
query << "UPDATE " F9_DRD "\n" \
|
2020-04-18 16:00:37 +02:00
|
|
|
"SET " DRD_STATO " = '" << _head.stato_estr << "'\n"
|
|
|
|
"WHERE " DRD_CODSOC " = '" << _head.cod_soc << "'"
|
|
|
|
" AND " DRD_ID_EST " = '" << _head.id_estr << "'"
|
2020-04-14 10:19:04 +02:00
|
|
|
" AND " DRD_FLAG_PD " = '" << (_head.flag_prov ? "P" : "D") << "'";
|
2020-04-01 21:26:49 +02:00
|
|
|
ok = fp_db().sq_set_exec(query);
|
|
|
|
ok = ok && fp_db().sq_commit();
|
|
|
|
if (!ok)
|
|
|
|
write_errorsql_log(query);
|
|
|
|
} while (!ok && yesno_box("Impossibile aggiornare stato dell'estrazione.\nRiprovare?"));
|
2020-04-14 10:19:04 +02:00
|
|
|
return ok;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* TEstrazione::diagnostica_mov()
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
const TipoIVA tipo = get_tipoiva();
|
2020-05-14 23:38:30 +02:00
|
|
|
_stats.total = _movs.size();
|
2020-04-01 21:26:49 +02:00
|
|
|
if (tipo == iva_acquisti)
|
|
|
|
{
|
|
|
|
// Controlli per le fatture di acquisto
|
|
|
|
TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di acquisto");
|
|
|
|
for (auto it = _movs.begin(); it != _movs.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!bar.add_status())
|
|
|
|
break;
|
2020-04-14 10:19:04 +02:00
|
|
|
#ifdef DBG
|
2020-05-14 23:38:30 +02:00
|
|
|
if (it->numreg == 96153)
|
2020-04-14 10:19:04 +02:00
|
|
|
bool simo = true;
|
|
|
|
#endif
|
|
|
|
// Se escluso passo avanti
|
|
|
|
if (!it->estratto && it->descr_estr == movimento_t::escluso)
|
|
|
|
continue;
|
|
|
|
|
2020-04-21 18:53:15 +02:00
|
|
|
movimento_t& mov_i = *it;
|
|
|
|
const int numreg = mov_i.numreg;
|
|
|
|
const state_fppro res = check_fppro(numreg);
|
2020-04-14 10:19:04 +02:00
|
|
|
switch (res)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-04-14 10:19:04 +02:00
|
|
|
// OK
|
2020-04-01 21:26:49 +02:00
|
|
|
case guessed:
|
|
|
|
ok &= fppro_db().associa_mov(numreg);
|
|
|
|
case correct:
|
2020-04-21 18:53:15 +02:00
|
|
|
ok &= true;
|
|
|
|
mov_i.err = false;
|
2020-04-14 10:19:04 +02:00
|
|
|
mov_i.state = res;
|
2020-04-21 18:53:15 +02:00
|
|
|
break;
|
2020-04-14 10:19:04 +02:00
|
|
|
|
|
|
|
// ERRORS
|
2020-05-14 23:38:30 +02:00
|
|
|
// Errore non bloccante (skip)
|
2020-04-14 10:19:04 +02:00
|
|
|
case not_fa:
|
2020-04-01 21:26:49 +02:00
|
|
|
ok &= true;
|
2020-05-14 23:38:30 +02:00
|
|
|
mov_i.err = false;
|
|
|
|
mov_i.estratto = false;
|
|
|
|
mov_i.descr_estr = movimento_t::no_fa;
|
|
|
|
mov_i.state = res;
|
|
|
|
++_stats.fa_skip;
|
2020-04-01 21:26:49 +02:00
|
|
|
break;
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
// ERRORI BLOCCANTI
|
2020-04-01 21:26:49 +02:00
|
|
|
case reg_with_err:
|
2020-04-14 10:19:04 +02:00
|
|
|
ok &= false;
|
|
|
|
mov_i.err = true;
|
|
|
|
mov_i.estratto = false;
|
|
|
|
mov_i.descr_err = "Errore controllo movimento: associazione movimento con fattura elettronica passiva sbagliato.";
|
|
|
|
mov_i.state = res;
|
|
|
|
break;
|
|
|
|
case err_read_db:
|
|
|
|
ok &= false;
|
|
|
|
mov_i.err = true;
|
|
|
|
mov_i.estratto = false;
|
|
|
|
mov_i.descr_err = "Errore controllo movimento: errore lettura db.";
|
|
|
|
mov_i.state = res;
|
|
|
|
break;
|
2020-04-01 21:26:49 +02:00
|
|
|
case no_guessed:
|
|
|
|
ok &= false;
|
2020-04-14 10:19:04 +02:00
|
|
|
mov_i.err = true;
|
|
|
|
mov_i.estratto = false;
|
2020-04-01 21:26:49 +02:00
|
|
|
mov_i.descr_err = "Non associato a fattura elettr. abbinamento automatico non riuscito. Abbinare manualmente, o escludere";
|
2020-04-14 10:19:04 +02:00
|
|
|
mov_i.state = res;
|
2020-04-01 21:26:49 +02:00
|
|
|
default: break;
|
|
|
|
}
|
2020-05-14 23:38:30 +02:00
|
|
|
#ifdef DBG
|
|
|
|
if (mov_i.numreg == 95954)
|
|
|
|
bool simo = true;
|
|
|
|
#endif
|
|
|
|
if (mov_i.err)
|
|
|
|
++_stats.fa_err;
|
2020-04-14 10:19:04 +02:00
|
|
|
/* Per quelli che hanno passato il primo controllo errori controllo che debba essere estratto
|
|
|
|
* secondo le categorie documentali. */
|
|
|
|
if(!mov_i.err && mov_i.estratto)
|
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
std::shared_ptr<TCategorie_doc::classe_doc> cd = categorie_doc().mov2cat(mov_i.numreg);
|
2020-04-14 10:19:04 +02:00
|
|
|
mov_i.estratto = cd.get();
|
|
|
|
mov_i.descr_estr = cd ? movimento_t::no_err : movimento_t::no_catdoc;
|
|
|
|
mov_i.catdoc = cd;
|
|
|
|
}
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (tipo == iva_vendite)
|
|
|
|
{
|
|
|
|
// Controlli per le fatture di vendita
|
|
|
|
TProgress_monitor bar(_movs.size(), "Controllo stato movimenti di vendita");
|
|
|
|
for (auto it = _movs.begin(); it != _movs.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!bar.add_status())
|
|
|
|
break;
|
|
|
|
//TToken_string& row = *it;
|
2020-04-15 18:01:09 +02:00
|
|
|
movimento_t& mov_i = *it;
|
2020-05-14 23:38:30 +02:00
|
|
|
TString numreg; numreg << mov_i.numreg;
|
2020-04-01 21:26:49 +02:00
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
2020-05-14 23:38:30 +02:00
|
|
|
#ifdef DBG
|
|
|
|
if(mov.read() != NOERR)
|
|
|
|
warning_box("OOOOOOOOOHH! E DICE SIII!!");
|
|
|
|
if (mov_i.numreg == 95677)
|
|
|
|
bool simo = true;
|
|
|
|
#endif
|
|
|
|
/* Controlli per vendite cambiati:
|
|
|
|
* Elettroniche solo quelle agli italiani, tutti gli altri sono cartacei
|
2020-04-21 18:53:15 +02:00
|
|
|
*/
|
2020-04-15 18:01:09 +02:00
|
|
|
if (!mov_i.err && mov_i.estratto)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
const bool cartacea = !is_doc_xml(mov);
|
|
|
|
bool exist_doc;
|
|
|
|
if(!_has_cartacei && cartacea) // Se non devo esportare i cartacei e questa e' cartacea la salto (non errore)
|
|
|
|
{
|
|
|
|
++_stats.fv_cart_skip;
|
|
|
|
mov_i.err = false;
|
|
|
|
mov_i.estratto = false;
|
|
|
|
mov_i.descr_estr = movimento_t::no_cartaceo;
|
|
|
|
}
|
|
|
|
else if(!cartacea && _has_checkvend && !check_documento_vendita(mov, exist_doc))
|
2020-04-15 18:01:09 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
mov_i.err = true;
|
|
|
|
mov_i.estratto = false;
|
|
|
|
mov_i.descr_err = !exist_doc ?
|
|
|
|
"Il movimento non ha un documento generatore. (Escludere? o Rimuovere flag controllo vendite)"
|
|
|
|
: "Non e' stato trovato il documento elettronico nel database delle F.E. (Escludere? o Rimuovere flag controllo vendite)";
|
|
|
|
mov_i.descr_estr = !exist_doc ? movimento_t::no_doc : movimento_t::notfound_elet;
|
2020-04-15 18:01:09 +02:00
|
|
|
}
|
2020-04-21 18:53:15 +02:00
|
|
|
else
|
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
std::shared_ptr<TCategorie_doc::classe_doc> cd = categorie_doc().mov2cat(mov_i.numreg);
|
2020-04-21 18:53:15 +02:00
|
|
|
mov_i.estratto = cd.get();
|
2020-05-14 23:38:30 +02:00
|
|
|
mov_i.err = false;
|
2020-04-21 18:53:15 +02:00
|
|
|
mov_i.descr_estr = cd ? movimento_t::no_err : movimento_t::no_catdoc;
|
|
|
|
mov_i.catdoc = cd;
|
2020-05-14 23:38:30 +02:00
|
|
|
|
|
|
|
if (!mov_i.catdoc)
|
|
|
|
++_stats.fv_nocatdoc;
|
|
|
|
if (mov_i.err)
|
|
|
|
++_stats.fv_err;
|
|
|
|
else if (mov_i.estratto)
|
|
|
|
++_stats.fv_estr;
|
2020-04-21 18:53:15 +02:00
|
|
|
}
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
2020-05-14 23:38:30 +02:00
|
|
|
ok &= !mov_i.err;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_head.stato_estr = ok ? D_GEST_OK : D_GEST_ERR;
|
|
|
|
return _head.stato_estr;
|
|
|
|
}
|
|
|
|
|
|
|
|
result_estr TEstrazione::estrai()
|
|
|
|
{
|
|
|
|
// Se non c'e' nessun movimento non sto nemmeno a scrivere il record di estrazione.
|
|
|
|
// Se estrazione definitiva controllo che il periodo non si sovrapponga alle altre estrazioni def.
|
|
|
|
// Do' errore ed esco subito.
|
|
|
|
if (_movs.empty())
|
|
|
|
{
|
|
|
|
warning_box("Non esistono movimenti estraibili per il periodo selezionato.");
|
|
|
|
return estr_stop;
|
|
|
|
}
|
2020-04-15 18:01:09 +02:00
|
|
|
if (!_escluso && !_head.flag_prov)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-04-15 18:01:09 +02:00
|
|
|
if (!check_periodo_def())
|
|
|
|
{
|
|
|
|
error_box("Attenzione e' stato inserito un periodo che si sovrappone\nad un'estrazione definitiva gia' esistente. Impossibile procedere.");
|
|
|
|
return estr_stop;
|
|
|
|
}
|
|
|
|
if (gap_periodo())
|
|
|
|
{
|
|
|
|
if (!noyes_box("Attenzione, e' stato saltato un periodo rispetto all'ultimo\n"
|
|
|
|
"estratto e quello selezionato, il quale rimarrebbe vuoto.\nContinuare comunque?"))
|
|
|
|
return estr_stop;
|
|
|
|
}
|
|
|
|
// Avviso nel caso in cui si stia facendo un'estrazione definitiva di un periodo di cui non si e' mai fatta
|
|
|
|
// una prova provvisoria.
|
|
|
|
if(!exist_prov())
|
|
|
|
{
|
|
|
|
if (!noyes_box("Attenzione, non e' mai stata fatta alcuna\nestrazione provvisoria per questo periodo.\nContinuare comunque?"))
|
|
|
|
return estr_stop;
|
|
|
|
}
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
// Non so come usare questi 18 caratteri...
|
|
|
|
// Uso dati anche se gia' noti in altri campi (I know..) + un numero incrementale.
|
2020-05-14 23:38:30 +02:00
|
|
|
_head.id_estr.cut(0) << today.date2ansi() << (_head.flag_prov ? "P" : "D") << (!_escluso ? "N" : "X") << next_estr_today(_head.tipo_doc);
|
2020-04-01 21:26:49 +02:00
|
|
|
_head.user = user();
|
|
|
|
// Eseguo controllo sui movimenti e segno in testata lo stato
|
|
|
|
_head.stato_estr = IN_DIAGN; // "01" che verra' quasi subito rimpiazzato dal risultato della diagnostica.
|
|
|
|
if (_escluso)
|
|
|
|
set_dates(); // Se escluso imposto data inizio e fine uguali
|
|
|
|
|
2020-04-14 10:19:04 +02:00
|
|
|
// Scrivo record estrazione (in stato '01': in diagnostica).
|
|
|
|
bool ok = insert_into_drd();
|
2020-04-01 21:26:49 +02:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
msg << "Errore database: impossibile scrivere nuova estrazione.\n"
|
|
|
|
<< fp_db().sq_get_text_error(false);
|
|
|
|
error_box(msg);
|
|
|
|
return estr_err_db_drd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Faccio partire la diagnostica e mi salvo il nuovo stato.
|
|
|
|
diagnostica_mov();
|
2020-04-14 10:19:04 +02:00
|
|
|
ok &= insert_into_f9movestr();
|
|
|
|
ok &= update_drd_stato_estr();
|
2020-04-01 21:26:49 +02:00
|
|
|
|
|
|
|
if (_head.stato_estr == D_GEST_ERR)
|
|
|
|
{
|
|
|
|
warning_box("Attenzione l'estrazione ha prodotto degli errori.\n" \
|
|
|
|
"Controllare e correggere eventuali problemi\ndal Controllo Estrazione.");
|
|
|
|
// Se in errore, esporto lista errori sul db
|
|
|
|
if (!export_error_list())
|
|
|
|
warning_box("Errore scrittura db. Controllare log errori.");
|
2020-04-14 10:19:04 +02:00
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
return estr_diag_err; // Errore diagnostica gestionale
|
|
|
|
}
|
|
|
|
|
|
|
|
// Se va tutto ben fino a qui, posso andare a scrivere nella
|
2020-04-14 10:19:04 +02:00
|
|
|
// tabella IVA i movimenti. F9IVA
|
|
|
|
const result_estr res = estrazione_iva() ? estr_ok : estr_err_db_iva;
|
|
|
|
return res;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TEstrazione::estrazione_iva(bool escluso)
|
|
|
|
{
|
|
|
|
bool stato = true;
|
|
|
|
TString query;
|
|
|
|
|
|
|
|
TProgress_monitor bar(_movs.size(), "Estrazione dati IVA");
|
|
|
|
for (auto it = _movs.begin(); it != _movs.end() && stato; ++it)
|
|
|
|
{
|
|
|
|
if (!bar.add_status())
|
|
|
|
break;
|
2020-05-14 23:38:30 +02:00
|
|
|
if (!it->estratto)
|
|
|
|
continue;
|
2020-04-01 21:26:49 +02:00
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
TLocalisamfile cli(LF_CLIFO);
|
|
|
|
mov.put(MOV_NUMREG, it->numreg);
|
|
|
|
mov.read();
|
|
|
|
cli.put(CLI_TIPOCF, mov.get(MOV_TIPO));
|
|
|
|
cli.put(CLI_CODCF, mov.get(MOV_CODCF));
|
|
|
|
cli.read();
|
|
|
|
TString statopaiv; statopaiv << cli.get(CLI_STATOPAIV);
|
|
|
|
TString idfisc;
|
|
|
|
TString numdoc; numdoc << (mov.get(MOV_NUMDOCEXT).full() ? mov.get(MOV_NUMDOCEXT) : mov.get(MOV_NUMDOC));
|
|
|
|
if (statopaiv == "IT" || statopaiv.empty())
|
|
|
|
{
|
|
|
|
idfisc << "IT";
|
|
|
|
if (cli.get(CLI_PAIV).full()) // Se non ho la partita IVA e' privato quindi non metto niente solo cod. ISO
|
|
|
|
idfisc << cli.get(CLI_PAIV);
|
|
|
|
}
|
|
|
|
else idfisc << statopaiv << cli.get(CLI_COFI); // Esteri
|
|
|
|
|
|
|
|
query.cut(0) << "INSERT INTO " F9_IVA " (\n"
|
|
|
|
IVA_CODSOC ", " IVA_IDLAN ", " IVA_FLAG_PD ",\n"
|
|
|
|
IVA_ANNOES ", " IVA_GIVA ", " IVA_TIPOG ",\n"
|
|
|
|
IVA_DOCXML ", " IVA_TIPOCF ", " IVA_CODCF ",\n"
|
|
|
|
IVA_RAGSOC ", " IVA_IDFISC ", " IVA_PIVA ",\n"
|
|
|
|
IVA_CODFIS ", " IVA_CATDOC ", " IVA_CAUSSOS ",\n"
|
|
|
|
IVA_NUMDOC ", " IVA_DATADOC ", " IVA_SEZIVA ",\n"
|
|
|
|
IVA_TIPOREG ", " IVA_NPROT ", " IVA_DATPROT;
|
|
|
|
/*if(is_autofattura(mov))
|
|
|
|
{
|
|
|
|
query << ",\n"
|
|
|
|
IVA_FORNOR ", " IVA_REGOR ", " IVA_NUMOR ", " IVA_DATAOR;
|
|
|
|
}*/
|
|
|
|
query << ",\n"
|
2020-04-21 18:53:15 +02:00
|
|
|
IVA_CLASDOC ", " IVA_USERELA ", " IVA_TIMEELA ", " IVA_NOMF1;
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
if (_head.tipo_doc == 'A')
|
|
|
|
{
|
|
|
|
query << ",\n"
|
|
|
|
IVA_TIPPROT ", " IVA_NUMPROT ", " IVA_ANNPROT ", " IVA_TIMERIC;
|
|
|
|
}
|
|
|
|
const long datadoc = mov.get_date(MOV_DATADOC).date2ansi();
|
|
|
|
const long datareg = mov.get_date(MOV_DATAREG).date2ansi();
|
|
|
|
|
|
|
|
const TString& name_reg = TRegistro(TCausale(mov.get(MOV_CODCAUS)).reg()).name();
|
2020-04-21 18:53:15 +02:00
|
|
|
const TString classdoc = it->catdoc->class_sost;
|
2020-05-14 23:38:30 +02:00
|
|
|
const TString nomefile = it->is_cartaceo() ? "nomefile.pdf" : ""; // todo:
|
2020-04-21 18:53:15 +02:00
|
|
|
|
|
|
|
// todo usare per categorie documentali caus_sos(mov, get_tipoiva());
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
query << "\n)\n" <<
|
|
|
|
"VALUES (\n" <<
|
2020-04-21 18:53:15 +02:00
|
|
|
"'" << _head.cod_soc << "', '" << _head.id_estr << "', '" << (_head.flag_prov ? "P" : "D") << "',\n" <<
|
|
|
|
"'" << mov.get(MOV_ANNOES) << "', '" << _head.tipo_doc << "', '" << name_reg << "',\n" <<
|
|
|
|
"'" << 'S' << "', '" << mov.get(MOV_TIPO) << "', '" << mov.get(MOV_CODCF) << "',\n" <<
|
|
|
|
"'" << check_str(cli.get(CLI_RAGSOC)) << "', '" << idfisc << "', '" << cli.get(CLI_PAIV) << "',\n" <<
|
|
|
|
"'" << cli.get(CLI_COFI) << "', '" << it->catdoc->catdoc << "', '" << it->catdoc->caus_sost << "',\n" <<
|
|
|
|
"'" << numdoc << "', '" << datadoc << "', '" << mov.get(MOV_REG) << "',\n" <<
|
|
|
|
"'" << "" << "', '" << mov.get(MOV_PROTIVA) << "', '" << datareg << "'";
|
2020-04-01 21:26:49 +02:00
|
|
|
//if (is_autofattura(mov))
|
|
|
|
//{
|
|
|
|
// query << ",\n" <<
|
|
|
|
// "'" << "" << "', '" << "" << "', '" << "N ORI" << "', '" << "20010101" << "'";
|
|
|
|
//}
|
|
|
|
query << ",\n" <<
|
2020-04-21 18:53:15 +02:00
|
|
|
"'" << classdoc << "', '" << user() << "', " << "GETDATE()" << ", '" << nomefile << "'";
|
|
|
|
|
|
|
|
// If cartaceo mettere nome file
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
if (_head.tipo_doc == 'A')
|
|
|
|
{
|
|
|
|
TToken_string keys(mov.get(MOV_KEYFPPRO), ';');
|
|
|
|
fppro_db().set_keys(keys);
|
|
|
|
query << ",\n" <<
|
|
|
|
"'" << fppro_db().get_tipoprot() << "', '" << fppro_db().get_numprot() << "', '" << fppro_db().get_annoprot() << "', '" << fppro_db().get_dataoraric() << "'";
|
|
|
|
}
|
|
|
|
query << "\n)";
|
2020-05-14 23:38:30 +02:00
|
|
|
const bool ok = fp_db().sq_set_exec(query) && fp_db().sq_commit();
|
2020-04-01 21:26:49 +02:00
|
|
|
if (!ok)
|
|
|
|
write_errorsql_log(query);
|
|
|
|
|
|
|
|
stato &= ok;
|
|
|
|
}
|
|
|
|
return stato;
|
|
|
|
}
|
|
|
|
|
2020-04-15 18:01:09 +02:00
|
|
|
bool TEstrazione::exist_prov() const
|
|
|
|
{
|
|
|
|
TString query; query << "SELECT * FROM " F9_DRD "\n" <<
|
2020-04-21 18:53:15 +02:00
|
|
|
"WHERE " DRD_CODSOC " = '" << _head.cod_soc << "' AND " DRD_DATADA " = '" << _head.dal.date2ansi() << "'"
|
|
|
|
" AND " DRD_DATAA " = '" << _head.al.date2ansi() << "' AND " DRD_FLAG_PD " = 'P' AND " DRD_TIPODOC " = '" << _head.tipo_doc << "'";
|
2020-04-15 18:01:09 +02:00
|
|
|
const bool ok = fp_db().sq_set_exec(query);
|
|
|
|
return ok && fp_db().sq_items() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TEstrazione::gap_periodo() const
|
|
|
|
{
|
2020-04-18 16:00:37 +02:00
|
|
|
TString query; query << "SELECT " DRD_ID_EST " AS ID, " DRD_DATAA " AS DATA_A\n"
|
|
|
|
"FROM " F9_DRD "\n"
|
|
|
|
"WHERE " DRD_CODSOC " = '" << _head.cod_soc << "' AND " DRD_ID_EST " LIKE '%N%' AND " // '%N%' = Pacchetto normale
|
|
|
|
DRD_FLAG_PD " = 'D' AND " DRD_TIPODOC " = '" << _head.tipo_doc << "'\n"
|
|
|
|
"ORDER BY " DRD_DATAA " DESC";
|
2020-04-15 18:01:09 +02:00
|
|
|
const bool ok = fp_db().sq_set_exec(query);
|
|
|
|
return ok && fp_db().sq_items() > 0 && _head.dal - fp_db().sq_get_date("DATA_A") > 1;
|
|
|
|
}
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
void TEstrazione::set_dates()
|
|
|
|
{
|
|
|
|
if (_escluso)
|
|
|
|
{
|
|
|
|
set_dataini(_movs[0].datareg);
|
|
|
|
set_dataend(_movs[0].datareg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEstrazione::TEstrazione(const TString& ambiente, const bool flag_prov, const char tipodoc, const TString& descr,
|
2020-05-14 23:38:30 +02:00
|
|
|
const TString& addrcart, const bool escluso, const TDate* const dal, const TDate* const al, const bool has_checkvend, const bool has_cartacei)
|
|
|
|
: _descr(descr), _has_checkvend(has_checkvend), _has_cartacei(has_cartacei)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
2020-04-18 16:00:37 +02:00
|
|
|
_head.cod_soc = ambiente;
|
2020-04-01 21:26:49 +02:00
|
|
|
_head.flag_prov = flag_prov;
|
2020-04-18 16:00:37 +02:00
|
|
|
_head.descr = descr;
|
|
|
|
_head.tipo_doc = tipodoc;
|
2020-04-01 21:26:49 +02:00
|
|
|
if (!escluso && dal != nullptr && al != nullptr)
|
|
|
|
{
|
|
|
|
_head.dal = *dal;
|
2020-04-18 16:00:37 +02:00
|
|
|
_head.al = *al;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
_head.addr_cart = addrcart;
|
|
|
|
|
2020-04-18 16:00:37 +02:00
|
|
|
_escluso = escluso;
|
|
|
|
_error_sql = new ofstream;
|
2020-04-01 21:26:49 +02:00
|
|
|
_error_sql->open("f9_TEstrazione_error_sql.txt");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// TF9_dberr
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TF9_dberr::add_str(const TString& string)
|
|
|
|
{
|
|
|
|
_insert.rtrim(1);
|
|
|
|
if (_insert[_insert.len() - 1] != '(')
|
|
|
|
_insert << ", ";
|
|
|
|
_insert << string << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TF9_dberr::write_sqlerrlog(const TString& query) const
|
|
|
|
{
|
|
|
|
if (_fout->is_open())
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
msg << query << "\n" <<
|
|
|
|
fp_db().sq_get_string_error() << "\n" <<
|
|
|
|
fp_db().sq_get_text_error();
|
|
|
|
*_fout << msg << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TF9_dberr::add(const TString& string)
|
|
|
|
{
|
|
|
|
TString str;
|
|
|
|
add_str(str << "'" << string << "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TF9_dberr::add(const long num)
|
|
|
|
{
|
|
|
|
TString app;
|
|
|
|
app << num;
|
|
|
|
add(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TF9_dberr::send()
|
|
|
|
{
|
2020-04-14 10:19:04 +02:00
|
|
|
const bool ok = fp_db().sq_set_exec(_insert) && fp_db().sq_commit();
|
|
|
|
if(!ok)
|
|
|
|
write_sqlerrlog(_insert);
|
2020-04-18 16:00:37 +02:00
|
|
|
_insert.cut(0) << "INSERT INTO " F9_ERR " ("
|
|
|
|
ERR_CODSOC ", "
|
|
|
|
ERR_IDESTR ", "
|
|
|
|
ERR_NUMREG ", "
|
|
|
|
ERR_DATAREG ", "
|
|
|
|
ERR_DATADOC ", "
|
|
|
|
ERR_CODCAUS ", "
|
|
|
|
ERR_MESELIQ ", "
|
2020-04-21 18:53:15 +02:00
|
|
|
ERR_NUMDOC ", "
|
2020-04-18 16:00:37 +02:00
|
|
|
ERR_IMPTDOC ", "
|
|
|
|
ERR_FORN ", "
|
|
|
|
ERR_RAGSOC ", "
|
|
|
|
ERR_PROTIVA ", "
|
|
|
|
ERR_DESCR ", "
|
|
|
|
ERR_ESCLUDI ", "
|
|
|
|
ERR_ESCLUSO ", "
|
|
|
|
ERR_DESCERR ") VALUES ()";
|
2020-04-14 10:19:04 +02:00
|
|
|
return ok;
|
2020-04-01 21:26:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-18 16:00:37 +02:00
|
|
|
void TF9_dberr::del_err(const TString& codsoc, const TString& id_estr, int numreg)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
TString query;
|
2020-04-18 16:00:37 +02:00
|
|
|
query << "DELETE FROM " F9_ERR
|
|
|
|
"\nWHERE " ERR_CODSOC " = '" << codsoc << "'"
|
|
|
|
"\nAND " ERR_IDESTR " = '" << id_estr << "' AND " ERR_NUMREG " = '" << numreg << "';";
|
2020-04-01 21:26:49 +02:00
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
}
|
|
|
|
|
2020-04-18 16:00:37 +02:00
|
|
|
char TF9_dberr::get_errori(const TString& codsoc, const TString& id_estr, vector<TToken_string>& controllo_mov)
|
2020-04-01 21:26:49 +02:00
|
|
|
{
|
|
|
|
TString query;
|
2020-04-18 16:00:37 +02:00
|
|
|
query << "SELECT * FROM " F9_ERR
|
|
|
|
"\nWHERE " ERR_CODSOC " = '" << codsoc << "' AND "
|
|
|
|
ERR_IDESTR " = '" << id_estr << "';";
|
2020-04-01 21:26:49 +02:00
|
|
|
fp_db().sq_set_exec(query, false);
|
|
|
|
for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next())
|
|
|
|
{
|
|
|
|
TToken_string row("", '|');
|
|
|
|
row.add("X");
|
|
|
|
for (int i = 1; i < 15; i++)
|
|
|
|
{
|
|
|
|
if (fp_db().sq_get_type_field(i) == _datefld)
|
|
|
|
row.add(fp_db().sq_get_date(fp_db().sq_get_name_field(i)));
|
|
|
|
else
|
|
|
|
row.add(fp_db().sq_get(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
controllo_mov.insert(controllo_mov.end(), row);
|
|
|
|
}
|
|
|
|
query.cut(0) << "SELECT " DRD_TIPODOC " FROM " F9_DRD "\n" <<
|
2020-04-18 16:00:37 +02:00
|
|
|
"WHERE " DRD_CODSOC " = '" << codsoc << "' AND " DRD_ID_EST " = '" << id_estr << "'";
|
2020-04-01 21:26:49 +02:00
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
return fp_db().sq_get((unsigned)0)[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
TF9_dberr::TF9_dberr()
|
|
|
|
{
|
2020-04-18 16:00:37 +02:00
|
|
|
_insert.cut(0) << "INSERT INTO " F9_ERR " ("
|
|
|
|
ERR_CODSOC ", "
|
|
|
|
ERR_IDESTR ", "
|
|
|
|
ERR_NUMREG ", "
|
|
|
|
ERR_DATAREG ", "
|
|
|
|
ERR_DATADOC ", "
|
|
|
|
ERR_CODCAUS ", "
|
|
|
|
ERR_MESELIQ ", "
|
2020-04-21 18:53:15 +02:00
|
|
|
ERR_NUMDOC ", "
|
2020-04-18 16:00:37 +02:00
|
|
|
ERR_IMPTDOC ", "
|
|
|
|
ERR_FORN ", "
|
|
|
|
ERR_RAGSOC ", "
|
|
|
|
ERR_PROTIVA ", "
|
|
|
|
ERR_DESCR ", "
|
|
|
|
ERR_ESCLUDI ", "
|
|
|
|
ERR_ESCLUSO ", "
|
|
|
|
ERR_DESCERR ") VALUES ()";
|
2020-04-01 21:26:49 +02:00
|
|
|
_fout = new ofstream;
|
|
|
|
_fout->open("f9_dberr.txt");
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:28:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TCategorie_doc
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
std::shared_ptr<TCategorie_doc::classe_doc> TCategorie_doc::find_causcont(const TString& caus)
|
2020-04-15 18:01:09 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
for (auto it = _rows.begin(); it != _rows.end(); ++it)
|
|
|
|
{
|
|
|
|
if ((*it)->causcont == caus)
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2020-04-15 18:01:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
std::shared_ptr<TCategorie_doc::classe_doc> TCategorie_doc::find_tipodoc(const TString& tipodoc)
|
2020-04-08 14:28:26 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
for (auto it = _rows.begin(); it != _rows.end(); ++it)
|
2020-04-08 14:28:26 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
const std::shared_ptr<classe_doc>& classe = *it;
|
|
|
|
if (classe->causcont.empty() && classe->tipocaus == tipodoc)
|
|
|
|
return *it;
|
2020-04-08 14:28:26 +02:00
|
|
|
}
|
2020-05-14 23:38:30 +02:00
|
|
|
return nullptr;
|
2020-04-08 14:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCategorie_doc::load_all()
|
|
|
|
{
|
|
|
|
int idx = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const TString& appo = ini_get_string(CONFIG_DITTA, "F9", "CATDOC", "", idx++);
|
|
|
|
if (appo == "STOP" || appo.empty()) /* STOP: Riga terminatrice */
|
|
|
|
break;
|
|
|
|
TToken_string row(appo);
|
|
|
|
classe_doc cd = { row.get(1), row.get(), row.get(), row.get(), row.get(), row.get(), row.get(), row.get() };
|
2020-05-14 23:38:30 +02:00
|
|
|
_rows.emplace_back(std::make_shared<classe_doc>(cd));
|
2020-04-08 14:28:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:38:30 +02:00
|
|
|
std::shared_ptr<TCategorie_doc::classe_doc> TCategorie_doc::mov2cat(const int numreg)
|
2020-04-08 14:28:26 +02:00
|
|
|
{
|
2020-05-14 23:38:30 +02:00
|
|
|
// Leggo la causale e cerco la corrispondente nelle categorie documentali, se c'e'.
|
|
|
|
// Guardo le colonne causale cont., tipodoc, class. cat. (opcee)
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
|
|
|
mov.read();
|
|
|
|
|
|
|
|
const TString& caus = mov.get(MOV_CODCAUS);
|
|
|
|
const TCausale c(caus);
|
|
|
|
const TString& tipodoc = c.tipo_doc();
|
|
|
|
|
|
|
|
// Cerco se ho un record che abbia specificata quella caus. contabile
|
|
|
|
std::shared_ptr<classe_doc> cat = find_causcont(caus);
|
|
|
|
if (cat != nullptr)
|
|
|
|
return cat;
|
|
|
|
// Altrimenti cerco per tipo documento
|
|
|
|
return find_tipodoc(tipodoc);
|
2020-04-08 14:28:26 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 21:26:49 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const char* check_str(const TString& str)
|
|
|
|
{
|
|
|
|
static TString n_str; n_str.cut(0) << str;
|
|
|
|
n_str.replace("'", "\'\'");
|
|
|
|
n_str.replace(" ", " ");
|
|
|
|
return (const char*)n_str;
|
|
|
|
}
|